SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 48

Hybrid View

  1. #1
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Hadoken Formerly Tenji

    Script Name: Hadoken
    Script Author: Ian Gordon
    Script Version: v0.00


    For those who are familar with what Tenji was I have renamed to script and decided to start from scratch, there were various problems with the original code so I decided to start anew.

    Hadoken is a BMS (Blog Management System), its use is to provide a blog interface with familiar blog features and also the powerful features of a content management system. The purpose is to power my own personal website and give me more experience in PHP Programming. Hadoken will be able to create normal blog posts, create categories for the blog posts with comments for each post being able to toggle them on and off. Further, it will have the power of a CMS in that it will be able to create sections (i.e. "About Us") and have pages in that sections (i.e. http://www.domain.com/about/page-title/), the idea is to incorporate features that everyone is used to using and what people want. I also am planning a media/gallery part where you can provide media for people who want to offer music or images, the images will be done with automatic thumbnails.

    What I need to do know is I need to come up with a database structure, however, in order to do that I need help coming up with a dynamic templating system.

    Traditional template systems rely on flat-files stored on the server in some folder that holds them, the problem with this is that is, in my opinion, cluttered and bad. I want to be able to create templates in the MySQL database and then have variables in those templates such as

    PHP Code:
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE html
            PUBLIC "-//W3C//DTD XHTML 1.1//EN"
            "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
          <head>
            <title><?php $page['title']; ?></title>
          </head>
          <body>
                <?php $page['body']; ?>
          </body>
        </html>
    Where "$page['variable']" was replaced with another template or content that a user can specify.

    I don't think this project is particularly hard but, it will take some time and incorporate a vast array of common features seen across multiple blog and CMS scripts.

    Oh, I also want to create clean SEF URLs so: http://www.domain.com/index.php?cate...page=iangordon => http://www.domain.com/about/iangordon

    So, what I am asking is help with the database structure for MySQL and help with how to implement this templating system.

    PLEASE DO NOT TELL ME ABOUT EXISTING TEMPLATE SYSTEMS!!
    I already know about them and I am not interested in them, don't make any posts mentioning them PLEASE!!!

    ******************************************************
    **************** SCRIPT PROCEDURES *********************
    ******************************************************
    1. Connect to Database
    2. If user is administor show AdminCP (http://www.domain.com/admin/index.php)
    3. If user is not admin but tries to login in unseccessfully 3 times lock-out for 30min and log IP Address with failed Username.
    4. If user is admin and logins successfully show frontpage and present options
    5. Fetch page via EventHandler (http://www.domain.com/index.php?page=blah).
    6. If page is in a section fetch section
    (http://www.domain.com/index.php?cat=blah)
    7. If page is in a section, show section then show page (http://www.domain.com/index.php?cat=blah&page=blah)
    8. If page is not found show error (http://www.domain.com/index.php?page=error)

    ******************************************************

    This is where I am at right now, working on gettting this working.
    Last edited by Ian R. Gordon; Feb 12, 2005 at 06:50.
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  2. #2
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll be posting some examples of what I want to accomplish through MySQL with PHP in a few hours.
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Traditional template systems rely on flat-files stored on the server in some folder that holds them, the problem with this is that is, in my opinion, cluttered and bad. I want to be able to create templates in the MySQL database and then have variables in those templates such as ...
    Why is that ? In my view, storing templates in the database is more inconvenient than having them i the filesystem. The advantage of using a DB over filesystem is that you have the ability to search effectively. But I can't see witch use you would have for this ? Even so - you could make a hybrid solution, where you store the actual templates as files, but maintain a table in the DB with the path to the files. Either way - I can't see what storing templates in DB would give you of benifits. I could however see lots of problems related to it. Performance for example.

  4. #4
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    Why is that ? In my view, storing templates in the database is more inconvenient than having them i the filesystem. The advantage of using a DB over filesystem is that you have the ability to search effectively. But I can't see witch use you would have for this ? Even so - you could make a hybrid solution, where you store the actual templates as files, but maintain a table in the DB with the path to the files. Either way - I can't see what storing templates in DB would give you of benifits. I could however see lots of problems related to it. Performance for example.
    It really comes down to a matter of preference, in my opinion its like debating apples and oranges...I want to store my template data in a MySQL database...its as simple as that, I am just asking if you are familar with an existing method or know of a way to create one.

    Thanks,
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  5. #5
    SitePoint Guru OfficeOfTheLaw's Avatar
    Join Date
    Apr 2004
    Location
    Quincy
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ian R. Gordon
    I am just asking if you are familar with an existing method or know of a way to create one.
    Like I said, Xoops does this.

    James Carr, Software Engineer


    assertEquals(newXPJob, you.ask(officeOfTheLaw));

  6. #6
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by Ian R. Gordon
    It really comes down to a matter of preference, in my opinion its like debating apples and oranges...I want to store my template data in a MySQL database...its as simple as that
    Uh?

    I may want to live on a diet of avocados, but as an engineering optimisation it's a pretty poor choice.

    Reading from a file: Pass the filename to the file system O(1), which is converted by a (cached) hash to a file descripter O(1) which is converted by a (cached) hash look-up to an i-node which does a B-tree look-up O(log n) of the disk blocks. Oh yeah, successive disk blocks of the file come faster as it's probably already cached anyway by the SCSI subsystem that has been busy preloading and caching the disk blocks just after the first in anticipation you will want the rest of a probably contiguous file as fast as possible. There is a reason SCSI costs more. You can pipeline this a file line at a time as well.

    Reading from a DB: Wrap the filename in a query, break it up into ethernet packets, reassemble them into a query, which is passed to the SQL parser which then passes it to the query optimiser that (hopefully) uses a B-tree look-up O(log n) through the index pages each one of which is on a disk with i-nodes that have O(log n) responses, having found a pointer to the data from the index pages at O(log index size) so that we can start to look up O(log n) the scattered sort of i-nodes of the diskblocks one after the other because the SCSI controller cannot predict the DB custom file system. Then take each block, break it up into ethernet packets again so that it can be reassembled by the network stack to pass it through the DB module of PHP. As one big lump.

    DB engines are optimised for searching, not data retrieval. That's what file systems are good at. That's why people bolt disk based query caches on to their web sites, to speed them up. I think your system is self defeating, it's as simple as that.

    Anyway, you have already sullied yourself with flat files. Your PHP scripts, your .htaccess files, the httpd.conf and numerous others. Or do you want to run your web server inside your database engine?

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  7. #7
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Who says you have to clutter the file system - you could put them neatly on the file system too
    Hello World

  8. #8
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I am not too concerned with performance, I am not going to have 10,000 pages, at most I might have close to 800 pages of content.

    I just don't want to deal with template files, systems like phpBB and other similar template systems have turned me off to flatfiles.

    I am just wondering if anyone has done this, if so how? what is the best way?

    Let me know, thanks!
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  9. #9
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most people on this forum will invariably advocate for templates as actual files rather than fields in your database.
    Garcia

  10. #10
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I am not too concerned with performance, I am not going to have 10,000 pages, at most I might have close to 800 pages of content.
    the number of unique templates isn't the problem at hand. the number of visitors is.

  11. #11
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Either way, there are much more serious problems with storing templates in your DB than just the sheer performance factor. Templates ARE text files, whether you like it or not, and you are bound to find yourself editing them with a text editor pretty often. I dont know many text editors that allow you to edit fields in a DB similarly to how you would edit a regular file, so you are constraining yourself to editing those templates in the DB directly or building an interface for doing so. What about mass search and replace? what about deployment of new templates? The ease of copying and pasting files goes out the window once you put your templates in a DB.
    Garcia

  12. #12
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ghurtado
    I don't know many text editors that allow you to edit fields in a DB similarly to how you would edit a regular file
    Well.. rather "I don't now how many text editors let me edit files over FTP", though there are still probably more of those than remote database editors (unless you are on MacOS). (EDIT: well... I did say "more" and "over" != "as an FTP client where you save the files locally then upload")

    I see the allure of using a database to store the templates, though I still wouldn't do it

    Storing templates in the db will be much the same as on the HD. Though please don't try and put the images for the templates in the DB too - that would just get insane!

    And if you're not going to put images in the DB, you might as well not put the template files in the DB either...

    Douglas
    Last edited by DougBTX; Feb 3, 2005 at 06:32.
    Hello World

  13. #13
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DougBTX
    Well.. rather "I don't now how many text editors let me edit files over FTP"
    I would say that most of them? Homesite, Dreamweaver, ZDE (just to mention some Ive worked with)
    Garcia

  14. #14
    SitePoint Guru OfficeOfTheLaw's Avatar
    Join Date
    Apr 2004
    Location
    Quincy
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ghurtado
    Either way, there are much more serious problems with storing templates in your DB than just the sheer performance factor. Templates ARE text files, whether you like it or not, and you are bound to find yourself editing them with a text editor pretty often. I dont know many text editors that allow you to edit fields in a DB similarly to how you would edit a regular file, so you are constraining yourself to editing those templates in the DB directly or building an interface for doing so. What about mass search and replace? what about deployment of new templates? The ease of copying and pasting files goes out the window once you put your templates in a DB.
    I'm assuming that you would probably just have an interface in the application to edit the templates, rather than dealing with opening the files in external editors. Still may be an issue for some as I know plenty of designers who hate editing their files in {insert favorite editor here} and then pasting it into textareas.

    Xoops does this already, nothing new to see here folks. Except xoops tends to hide templates from direct editing rather cleverly for the newbie. I had to dig deep before I fiigured out how to edit the templates for different blocks.

    Oh, and I wound up pasting content from vim to textareas, as usual.

    James Carr, Software Engineer


    assertEquals(newXPJob, you.ask(officeOfTheLaw));

  15. #15
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just want to edit code by hand with standard XHTML mark-up via a textarea, then have that saved in a MySQL database, I don't see why that is such a big problem.

    It would be something like:

    Code:
     <textarea>$data</textarea>
    with "$data" being a fielo in a MySQL database.
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  16. #16
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most decent editors have ftp-capabilities built-in.
    Or you could try this nice piece of software, if you run a windows os : http://www.knoware.com/index.php?pg=...ts/inpro/index
    (I'm sure something similar exists to other platforms)

  17. #17
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It really comes down to a matter of preference, in my opinion its like debating apples and oranges...I want to store my template data in a MySQL database...its as simple as that, I am just asking if you are familar with an existing method or know of a way to create one.
    Yeah, except that the apples you insist to eat are treated with DDT.

    However - If you insist, it's merely a matter of using eval() on the data, you pull from the database.
    PHP Code:
    class Template
    {
        function 
    Template($templateId) {
            
    $sql "SELECT `content` FROM `template` WHERE  id='".mysql_escape_string($templateId)."'";
            
    $result mysql_query($sql);
            
    $row mysql_fetch_assoc($result);
            
    $this->_templateContent $row['content'];
        }

        function 
    render($args) {
            
    ob_start();
            eval(
    $row['content']);
            return 
    ob_get_clean();
        }


  18. #18
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    New Jersey, USA
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    Yeah, except that the apples you insist to eat are treated with DDT.
    You should probably have a look at the wikipedia article on DDT: still not shown to be hazardous.

    Perhaps you meant "Alar", which was used to treat apples and has been shown to be harmful?

    =Austin

  19. #19
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks man, i will see how I am properly implement this with my script.
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  20. #20
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Script Help

    I am wondering if anyone could look over this MySQL class and tell me what I could do to improve it or just make it work more effectively.

    PHP Code:
       <?php
       
    /***************************************************************************
                                      /mysql.php
                                  -------------------
           begin                : Monday November 1st 2004
           copyright            : (C) 2004 Ian Gordon
           email                : ian.gordon@gmail.com
       
           $Id: $
       
        ***************************************************************************/
       
       /***************************************************************************
        *
        *   This program is free software; you can redistribute it and/or modify
        *   it under the terms of the GNU General Public License as published by
        *   the Free Software Foundation; either version 2 of the License, or
        *   (at your option) any later version.
        *
        ***************************************************************************/
       
        
    class MySQL {
        
               var 
    $_host;
               var 
    $_user;
               var 
    $_pass;
               var 
    $_dbase;
               
             function 
    MySQL($hostname 'localhost'$username 'root'$password '00000'$database 'example') {
               
                       
    $this->_host  $hostname;
                       
    $this->_user  $username;
                       
    $this->_pass  $password;
                       
    $this->_dbase $database;
       
               }
               
               function 
    Connect() {
               
                  
    $link mysql_connect($this->_host$this->user$this->_pass)
                          or die(
    'Could not connect: ' mysql_error());
                          echo 
    'Connected successfully';
                          
    mysql_select_db($this->_dbase) or die('Could not select database');
       
               
               }
               
               function 
    Query($query) {
               
                       
    $result mysql_query($query)
                          or die(
    'Query Failed: ' mysql_error());
                       
               }
               
               function 
    Result($result) {
               
                       
    mysql_fetch_array($resultMYSQL_ASSOC);
                       
               }
               
        }
       
    ?>
    I think it is mostly right but, feel free to critique it and offer alternatives.
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  21. #21
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well personally, I think you'd be better not storing the database connection details within the class itself, use a loader function to pass in those details.

    You probably need to store any mysql_errors as well rather than having your class 'kill itself with die()'.

    I'd be tempted to suggest you seperate out your database connection function also, it'll make it easier to select other databases with the same authentication details, and as an advantage it'll mean your error checking can be more exact.

    I'm not too sure about the single query() function, classes are about making things more versitile and easier ammoungst other things, so having a simple 'query' function is a little open ended, write up some specific, insert, select, etc functions so you can do things like:

    PHP Code:
    $result_set $class->select('*''tablename'); 
    It's a good start, but it just seems 'lacking' in it's usfulness, maybe have a read through a good db abstraction layer like phpBB's and have a look at some the techniques used.

  22. #22
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That thought about doing it in such a manner crossed my mind. I think I might explore those possbilites as I move further along with my script. Sometimes, this whole process is a bit trying on my patience...
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  23. #23
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Updated MySQL Class

    PHP Code:
     class MySQL {
      
             var 
    $_host;
             var 
    $_user;
             var 
    $_pass;
             var 
    $_dbase;
             
             function 
    MySQL($hostname $_SETTINGS["hostname"], $username $_SETTINGS["username"], $password $_SETTINGS["password"], $database $_SETTINGS["database"]) {
             
                     
    $this->_host  $hostname;
                     
    $this->_user  $username;
                     
    $this->_pass  $password;
                     
    $this->_dbase $database;
     
             }
             
             function 
    Connect() {
             
                     
    $link mysql_connect($this->_host$this->_user$this->_pass)
                             or die(
    "Could Not Connect to MySQL");
                             
    mysql_select_db($this->_dbase);
                             or die(
    "Could Not Select Database");
             
             }
             
             function 
    SelectData($query) {
             
             }
             
             function 
    UpdateData($query) {
             
             }
             
             function 
    AddData($query) {
             
             }
             
             function 
    DeleteData($query) {
             
             }
             
             function 
    CountRows($rows) {
             
             }
             
             function 
    CloseDB() {
             
                     
    mysql_close($link);
             
             }
             
             
      } 
    How about this? Do you think this is much better? I am not trying to create something portable to another script but, just something i can working with within this script itself between objects that have to make MySQL calls and queries.
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  24. #24
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not here to entertain what is best optimized for use. I already know what I want to do. I am simply asking if anyone knows how to do it, if you don't like it, thats inconsequential to me.

    Help me or let me be, I need to make progress with my script, man.
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  25. #25
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by Ian R. Gordon
    Help me or let me be, I need to make progress with my script, man.
    Ok .

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •