Administration
  Home arrow Administration arrow Page 5 - Building a Barebones Content Management System: The Yaapi API
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ADMINISTRATION

Building a Barebones Content Management System: The Yaapi API
By: Harish Kamath
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2005-09-21


    Table of Contents:
  • Building a Barebones Content Management System: The Yaapi API
  • Under The Hood
  • yaapi -- Getting Started
  • yaapi -- Listing Articles
  • yaapi -- Display An Article
  • yaapi - Display List Of Categories

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building a Barebones Content Management System: The Yaapi API - yaapi -- Display An Article
    ( Page 5 of 6 )

    After having shown you how to list the articles in a category, I will now demonstrate how to display the contents of an article in the list. You may have noticed that each article title in the previous example was linked to a script titled "article.php" (with the "id" of the article passed in the query string). It's time to review the PHP script.

    <?php

    // the include file
    include_once("./article.class.php");

    // initialize objects
    $article = new article;

    // The $id variable should always have a value
    if(!isset($_GET["id"]) || $_GET["id"] == "") {
     $article_id = $GLOBALS['DEFAULT_ARTICLE_ID']; // Set this to a default article ID
    } else {
     $article_id = $_GET["id"];
    }

    // The $id variable should always have a value
    if(!isset($_GET["current_page"]) || $_GET["current_page"] == "") {
     $current_page = 1; // Set current page value to 1, if not set
    }

    ?>

    <HTML>
    <HEAD>
    <BASEFONT FACE="Arial">
    </HEAD>
    <BODY>
    <TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="5" ALIGN="CENTER" VALIGN="TOP" HEIGHT="450" BORDER="1">
    <TR>
     <TD COLSPAN="2" WIDTH="100%" ALIGN="CENTER">
      <P>&nbsp;</P>
      <H1>BB_CMS - A Barebones Content Management System</H1>
      <P>&nbsp;</P>
     </TD>
    </TR>
    <TR HEIGHT="350">
     <TD WIDTH="25%" ALIGN="MIDDLE" VALIGN="TOP">
      <P><A HREF="#">LINK 1</A></P>
      <P><A HREF="#">LINK 2</A></P>
      <P><A HREF="#">LINK 3</A></P>
      <P><A HREF="#">.. and so on.</A></P>
     </TD>
     <TD WIDTH="50%" ALIGN="LEFT" VALIGN="TOP">
      <P>&nbsp;</P>
      <UL>
      <?php

       // Get the intro for the article
       $current_article = $article->get_article($article_id);

       if(!isset($current_article) || !$current_article) {
        $current_article = $article->get_article($GLOBALS['DEFAULT_ARTICLE_ID']);
       }

       echo "<H2>$current_article->title</H2>";
       echo "<H5>Author: <A HREF=\"
    mailto:$current_article->email\">$current_article->author</A>";
       echo "<BR CLEAR=\"all\">Date Published: $current_article->date</H5>";
       echo "<P>$current_article->content</P>";

      ?>
      </UL>
     </TD>
    </TR>
    <TR>
     <TD COLSPAN="2" WIDTH="100%" ALIGN="CENTER">
      <H5><A HREF="#">Copyright</A> | <A HREF="#">Privacy Policy</A></H5>
      <BR CLEAR="all" />
      <H6>&copy; 2005 BB_CMS Inc.</H6>
    </TD>
    </TR>
    </TABLE>
    </BODY>
    </HTML>

    Click on the title of any article listed by "category.php" script to view the following output:

    Now, let me guide you through the contents of my second PHP script. 

    <?php

    // the include file
    include_once("./article.class.php");

    // initialize objects
    $article = new article;

    // The $id variable should always have a value
    if(!isset($_GET["id"]) || $_GET["id"] == "") {
     $article_id = $GLOBALS['DEFAULT_ARTICLE_ID']; // Set this to a default article ID
    } else {
     $article_id = $_GET["id"];
    }

    // snip
    ?>

    You’ll notice that the first few lines are similar to those in "category.php": after including "article.class.php", I proceed to create an instance of the article() class for use in this script. Next, I assign value to the "$article_id" local variables. If I do not find a value in the query string, I assign the default value stored in the configuration file, as explained in the previous section.

    <%

    // snip

    <?php

    // Get the intro for the article
    $current_article = $article->get_article($article_id);

    if(!isset($current_article) || !$current_article) {
      $current_article = $article->get_article($GLOBALS['DEFAULT_ARTICLE_ID']);
    }

    echo "<H2>$current_article->title</H2>";
    echo "<H5>Author: <A HREF=\"
    mailto:$current_article->email\">$current_article->author</A>";
    echo "<BR CLEAR=\"all\">Date Published: $current_article->date</H5>";
    echo "<P>$current_article->content</P>";

    ?>

    // snip

    %>

    Now that I have an "id" for the article, I proceed to invoke get_article(). This aptly titled method returns the data associated with the article whose "id" is passed as the input to the method. I store the return value in another local variable, "$current_article" and use appropriate properties of the article() object to render the screen, as seen in the output.

    For your reference, I have listed the properties of the article() object below:

    • title: the title of the article; you’ve already seen this property in action in the previous section.
    • author: the author (or authoress).
    • email: the email address entered in the database.
    • date: the data and time when the entry was inserted in the database.
    • content: the actual text for the article.

    With this example behind me, I can safely conclude that I’ve now demonstrated two critical features that any practical CMS should provide: the ability to list the articles in the database, and then retrieve the actual content that constitutes an article.



     
     
    >>> More Administration Articles          >>> More By Harish Kamath
     

       

    ADMINISTRATION ARTICLES

    - Network Booting via PXE: the Basics
    - Scalix: Linux Administrator`s Guide
    - Network Administration with FreeBSD 7
    - Components of an Information Architecture
    - The Anatomy of an Information Architecture
    - Configuring Load-Balanced Clusters
    - Load-Balanced Clusters
    - UNIX Time Format Demystified
    - Making Changes in the CVS
    - Building Your First CVS Repository
    - CVS Quickstart Guide
    - Authorizing Users in Samba
    - Handling User Accounts in Samba
    - Authentication in Samba
    - Accounts, Authentication, and Authorization





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek