Content Management Code

  Home arrow Content Management Code arrow Easy Content Management
CONTENT MANAGEMENT CODE

Easy Content Management
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2002-05-29

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    I developed an easy way to create a templated web site using a template and text files. Then to modify those text files, I developed a simple editor and updater. It is very simple and the user only needs to know HTML. There is no need for a database. This batch of code is for 4 pages. Read teh comments for directions. Check it out....

    By : zensmile

    /* First off, design your template page in your text editor or WYSIWYG editor of choice. Where you want the "content" to show up within the page, include this code: */

    /************************ Begin Code ************************/

    <?php

    $thefile = "data/$page.txt";
    if (file_exists($thefile))
    {
    include("$thefile");
    }
    else
    {
    include("data/error.txt");
    }

    ?>

    /************************ End Code ************************/

    /*All of your links should look like this:

    template.php?page=whatever

    Where the link reads "whatever", replace with a file name without the .txt extension. For example, template.php?page=faq, would include "faq.txt" within your template page.

    Create a "data" directory and put all of your content files within that directory. The .txt files will contain all of the "meat an potatoes" of your site...formatted in HTML *without* the <HTML><HEAD> or <BODY> tags. All of those tags are within your template.php. For example, you might have a contact page, a faq page, and a downloads page. You would have a faq.txt, contact.txt, and a downloads,txt within your data directory. So your links would look like this:

    template.php?page=faq
    template.php?page=contacts
    template.php?page=downloads
    */

    /* this next batch of code should be in a file called update.php within your "data" directory. You use this page to edit your .txt files within "data". You would access it by typing in...

    http://www.whatever.com/data/update.php

    You will then be asked for a login and password. Here is the script for update.php: */

    /************************ Begin Code ************************/

    <?php

    //Check to see if $PHP_AUTH_USER already contains info

    if (!isset($PHP_AUTH_USER)) {
    //If empty send header causing dialog box to appear
    header('WWW-Authenticate: Basic realm="Private Stuff"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization required.';
    exit;
    }

    //If not empty, do something else

    else {

    //Try to validate the values of $PHP_AUTH_USER and
    //$PHP_AUTH_PW against hard-coded values
    //please change login and password to whatever you want

    if (($PHP_AUTH_USER == "login") && ($PHP_AUTH_PW == "password")) {

    echo "
    <html lang=\"en\">
    <head>
    <title>Enter Your Title Here</title>
    </head>
    <body>

    <h3>Header</h3>

    <p>Please be very careful when editing these files. Be particularly careful when editing the PHP files.

    <p>Choose a page to edit and then hit the submit button.

    <p>

    <form action=\"modify.php\" method=\"post\">

    <table width=\"500\" border=\"1\" cellspacing=\"1\" cellpadding=\"5\">\n
    <tr bgcolor=\"#CCCCCC\"><th>Pick</th><th>File Name</th><th>Last Edited or Uploaded</th></tr>\n
    ";
    $handle=opendir('.');
    while (false!==($file = readdir($handle))) {
    if ($file != "." && $file != ".."
    && $file != "update.php" && $file != "write.php" && $file != "modify.php") {
    $filename = str_replace("_"," ",$file);
    $fTime = filemtime($file);
    $today = getdate($fTime);
    $month = $today['month'];
    $mday = $today['mday'];
    $year = $today['year'];
    echo "<tr><td align=\"center\"><input type=\"radio\" value=\"$filename\" name=\"working\"></td><td align=\"center\"><b>$filename</b></td><td align=\"center\">$month $mday,
    $year</td></tr>\n
    ";
    }
    }
    closedir($handle);

    echo "</table>\n";
    echo "<p><input type=\"submit\" value=\"Submit\">";
    echo "</form>";

    echo " </body>
    </html>";

    }

    else {

    echo "You are not authorized!";

    }

    }

    ?>

    /************************ End Code ************************/


    /* Here is the code for "modify.php", which is also located in the "data" directory. Modify.php is the "action" for the upate.php file. You choose a file to modify and then the information is passed to modify.php. Here is the code: */

    /************************ Begin Code ************************/

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html lang="en">
    <head>
    <title>Your Title Here</title>
    </head>
    <body>

    <h3>Modify Data Document</h3>

    <p>Carefully read the text below, edit, and then submit to publish to web site. All changes are final! Please make sure that you have spell checked document and all "curley quotes and apostrophes" have been eliminated.

    <p>You must also use HTML markup in the document. Please, read an HTML manual before getting "freaky" with the editing.

    <form method="post" action="write.php">
    <textarea name="message" rows="20" cols="60">
    <?php

    $contents=file($working);
    for ($i=0; $i<sizeof($contents);$i++){
    echo htmlentities($contents[$i]);
    }
    echo "</textarea>\n";

    echo "<input type=\"hidden\" value=\"$working\" name=\"working\">";
    ?>
    <p>
    <input type="submit">
    </form>

    </body>
    </html>

    /************************ End Code ************************/

    /* Here is the code for "write.php". It is, again, located within the "data" directory. Write.php is the action for "modify.php". After you have made your changes to the .txt file, the changes are written and then you are redirected to the update.php page. Here is the code: */

    /************************ Begin Code ************************/

    <?php

    $writeme=fopen("$working","w");
    fputs($writeme, stripslashes($message));
    fclose($writeme);
    header("Location: http://www.yourdomain.com/data/update.php\n\n");

    ?>

    /************************ End Code ************************/
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Content Management Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    CONTENT MANAGEMENT CODE ARTICLES

    - V2 CMS - Content Management System
    - VSNS Lemon
    - Country List For Forms Using SQL
    - eggblog
    - Table generation class
    - STP Simple Template Parser
    - class Vision_To_Form_Elements
    - Cascade Drop Down
    - Cura - CMS
    - Syntax Desktop
    - 216 color table
    - Simple Mini Poll class library (SimPoll)
    - Regex Generator
    - Siteseed
    - Company WebSite Builder PRO


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap