Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: CMS Questions - Just Brainstorming.

  1. #1
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default CMS Questions - Just Brainstorming.

    Pretty soon, I'm going to need a CMS (Content Management System) for a client and since it's the first one I'll ever be making, I want to clear some things up.

    My plan is to use an XML document, as the following:

    Code:
    <about1>
    About content here, paragraph 1...
    </about1>
    <about 2>
    About content here, paragraph 2...
    </about2>
    
    <services1>
    Services content here, p1...
    </services1>
    <services2>
    Services, p2
    </services2>
    Except I plan on doing this with several other 'pages', content, links, etc.

    Then, for the CMS, using explode:

    PHP Code:
    if(file_exists('content.xml')){
         
    $edit = @include('content.xml');
         
    $about explode('<about2>',$edit); 
         
    $about1 $about[0]; // About, Paragraph 1
         
    $about explode('<services1>',$about[1]);
         
    $about2 $about[0]; // About, Paragraph 2
         
    $services explode('<services2>',$about[1]);
         
    $services1 $services[0]; // Services, Paragraph 1
         
    $services2 $services[1]; // Services, Paragraph 2
         // And on...

         
    $about1 explode('About',$about1);
         
    $about1 explode('</about1>',$about1[1]);
         
    $about1 $about1[0]; // About, Paragraph 1
         // And on...

        
    echo '<textarea>'.$about1.'</textarea>';

    I left a lot out of the code, but I have you the general idea of what I want to do. Is there some easier way to do this? Then, I'm wondering how I would actually replace the information once the client submits their changes?
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  2. #2
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Alright, I've talked to Twey and I have found out of easier ways to do this, but am unsure about where to start. I'm thinking of using:

    http://us2.php.net/manual/en/functio...nto-struct.php

    Any ideas?
    Then, in reference to my second question, how to then write the edited info back into the XML document?
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Not sure on that function, but seems like a reasonable approach. I'd just play with it, using examples from the page.
    As for writing, just use fopen, fwrite, fclose loops, creating the same structure as before in the xml.

    However, a database might be a better approach if you need to rapidly access chunks.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    I've changed directions. I'm thinking about doing one PHP file, inc.php, that would look like the following:

    PHP Code:
    $about = <<<ABOUT101291
    about content...
    ABOUT101291;

    $services = <<<SERVICES101291
    services content...
    SERVICES101291;

    // And have a variable for each page 
    But, my question is...when I write the edited content back to inc.php from the form, how do I just rewrite one variable without having to rewrite the whole page?! Is this possible, or do I have to go with a different file for each page?

    I'm going to be using a WYSIWYG editor, too.
    Last edited by alexjewell; 07-01-2007 at 09:03 PM.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This is a really poor idea. Writing all the data to a single flat file is inefficient, and greatly increases the possibility that one update will overwrite another.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I would think that either using flat files for every variable, or using a single MySQL database would be the best idea; but that's just my opinion.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Alright, I think I've solved the problem with the help of djr33. Thanks.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  8. #8
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    The code is finally working, and I thought I'd post it here for anyone interested:

    index.php:
    PHP Code:
    <?php

    include('inc.php');
    include(
    'layout.php');

    ?>

    <textarea name="about" readonly><?=$about?></textarea><br />
    <a href="edit.php?edit_file=about">Edit</a>

    <br /><br />

    <textarea name="services" readonly><?=$services?></textarea><br />
    <a href="edit.php?edit_file=services">Edit</a>

    <br /><br />

    <textarea name="links" readonly><?=$links?></textarea><br />
    <a href="edit.php?edit_file=links">Edit</a>
    inc.php:
    PHP Code:
    <?php

    $about 
    = <<<ABOUT101291
    about content
    ABOUT101291;

    $services = <<<SERVICES101291
    services content
    SERVICES101291;

    $links = <<<LINKS101291
    links content
    LINKS101291;

    ?>
    edit.php:
    PHP Code:
    <?php

    include('inc.php');
    include(
    'layout.php');

    $array = array('about','services','links');

    if(@
    $_GET['edit_file']){
        
    $edit_file $_GET['edit_file'];

        if(
    in_array($edit_file,$array)){ ?>

            <form method="post" action="confirm.php?edit_file=<?=$edit_file?>">
                <textarea name="<?=$edit_file?>"><?=$$edit_file?></textarea><br />
                <input type="hidden" name="auth" value="yes" />
                <input type="submit" value="Submit" />
            </form>

    <?php }

        else { echo 
    '<p>The file chosen to edit does not exist.</p>';}

    }

    else { echo 
    '<p>There is no file to edit.</p>';}
        
    ?>
    write.php:
    PHP Code:
    <?php

    include('inc.php');

    echo 
    '<html>
    <head>
    <title>CMS Example</title>'
    ."\n\n";

    $php_file = @file_get_contents('inc.php');
    $success 'http://www.flamehtmlstudios.com/clients/cms/result.php?result=yes';
    $fail 'http://www.flamehtmlstudios.com/clients/cms/result.php?result=no';
    $fail2 'http://www.flamehtmlstudios.com/clients/cms/result.php?result=no2';

    if(@
    $_GET['edit_file']){
        
    $edit_file $_GET['edit_file'];
        
        if(@
    $_POST[$edit_file]){
            
    $page $_POST[$edit_file];
            
    $pageu strtoupper($edit_file);
            
    $newcontent '$'.$edit_file.' = <<<'.$pageu.'101291'."\n".$page."\n".$pageu.'101291;';

            list(
    $a,$b) = explode('$'.$edit_file,$php_file,2);
            list(
    $b,$c) = explode($pageu."101291;",$b,2);
            
    $php_final $a."\n\n".$newcontent."\n\n".$c;
            
            
            
    $file 'inc.php';
            
    $file = @fopen($file,'w+');
            @
    fwrite($file,$php_final);
            @
    fclose($file);

            echo 
    '<meta http-equiv="refresh" content="0;url='.$success.'">';}
        
        else {
    ?> <meta http-equiv="refresh" content="0;url=<?=$fail?>"> <?php }
    }

    else { 
    ?> <meta http-equiv="refresh" content="0;url=<?=$fail2?>"> <?php }

    echo 
    "\n\n".'</head>
    <body>
    </body>
    </html>'
    ;

    ?>
    confirm.php:
    PHP Code:
    <?php

    include('inc.php');
    include(
    'layout.php');

    if(@
    $_GET['edit_file']){
        
    $edit_file $_GET['edit_file'];
        
        if(
    $_POST['auth'] == 'yes'){
            
    $page $_POST[$edit_file]; ?>
            
            <form method="post" action="write.php?edit_file=<?=$edit_file?>">
                <textarea name="<?=$edit_file?>" readonly><?=$page?></textarea><br />
                <input type="button" value="Edit" />
                <input type="submit" value="Submit" />
            </form>
            
    <?php }

        else { echo
    '<p>Please go <a href="edit.php?edit_file='.$edit_file.'">back</a> and fill in the textbox.</p>';}

    }

    else { echo
    '<p>There is no file to edit.</p>';}

    ?>
    result.php:
    PHP Code:
    <?php

    include('layout.php');

    $error '<p>There has been an error in trying to edit the page.</p>';

    if(
    $_GET['result']){
        
    $result $_GET['result'];
        
        if(
    $result == 'yes'){
            echo 
    '<p>The page has been edited successfully.</p>';}
            
        else if (
    $result == 'no' || $result == 'no2'){
            echo 
    $error;}
            
        else{echo 
    $error;} }
        
    else{echo 
    $error;} 

    ?>
    then layout.php just includes some styling.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's still a really bad way to do things. You'd've been far better off with the database or even the XML files.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Why would xml be better than php? PHP is secure, requires formatting, and xml requires formatting and isn't secure. I don't really see how that helps, since both are text.
    A database would be better, if possible (alex said it isn't), but I don't really see the downside to php in this case.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •