Building a Barebones Content Management System: An Introduction

How do you keep visitors returning to your website? By updating content regularly. Maintaining this gets out of hand unless you have a content management system. Harish Kamath explains how to put a barebones CMS together using three APIs.  To see the VIDEO TUTORIAL click HERE.

Content Management Demystified

The term “content management” has a very important place in any web master’s dictionary and I am no exception. After all, visitors will only return to a website if they have a compelling reason to do so, and dynamically updated content provides one such reason. However, this would also mean that I have to manually update scores of HTML pages on a regular basis. This did not strike me as very pleasant at all, and I immediately began to explore various options to make my website dynamic.

Initially, the “techie” in me prompted me to dabble with different scripting languages such as Perl and PHP to build a custom application to drive my website. Unfortunately, it became a nightmare to maintain.

Next, I turned my attention to the growing number of “Content Management Systems” (or “CMS” as they are popularly known); in fact, several Open Source CMS software packages such as Typo3, Mambo, PHPNuke and others dot the PHP/Apache/MySQL landscape. A quick test run of these applications on the web server and my joy proved short-lived. I concluded that, while they were versatile, each came with its own set of quirks and shortcomings.

This is when the idea of a cobbling together a “barebones” CMS struck me — one that gave me the flexibility that I yearned for while not sacrificing the advantages that such a system should provide. With these goals in mind, I began my search for the right tools — after all, a carpenter is only as good as his tools. With a little help from the folks at Google, my quest ended with the discovery of several API packages that should make my job of developing a “barebones” CMS easy.

Do you want to know more? Click to the next page to continue!


{mospagebreak title=yaapi and patTemplate and patUser = A barebones CMS}

After numerous cups of coffee, many sleepless nights and endless Google searches, I found three useful APIs — or PHP classes (to be technically correct) — that I could integrate to fructify my “barebones” CMS.

So, how about a quick introduction?

First, I have “yaapi.” According to Paul Gareau (the developer behind the API), yaapi (an acronym for Your Article Application Programming Interface) is a “programming interface that makes displaying articles on your webpage easy.” In other words, this is a no-frills PHP class, equipped with a bunch of useful properties and utility methods that help manage and retrieve content (stored in a MySQL database) in a logical manner.

One of the significant advantages of using a CMS to drive a website is the ability to use templates. This is a simple concept that allows the web master to abstract the creative design from the programming bits. If you take a quick look at any popular website, you will not fail to notice that significant components of a web page are constant. For example, you may have a header with a logo and a banner, a left hand menu of hyperlinks and a footer with legal copyright notices, which leaves only the center — the most dynamic location on a web page — for you to worry about. 
 
This is where a templating engine such as “patTemplate” comes in handy. A part of the very popular PHP Application Tools (or PAT) group of APIs, patTemplate is a versatile templating engine that supports a wide range of features, as you shall find out during the course of this series.

The two — yaapi and patTemplate — working hand in hand should be able to fulfill most of my requirements for building a barebones CMS.

However, one of the major drawbacks of yaapi is the lack of security for its administration module. While I could implement HTTP Authentication to ensure some basic security, I wanted to take this opportunity to get my hands dirty with another useful API developed by the team behind patTemplate — “patUser.” According to the official description at http://www.phptools.de/, patUser is a “user management class that helps you with authentication, group and permission management, statistics and more.” It’s just the tool needed to password-protect the administration module for yaapi!

That was a quick introduction to the three packages that I intend to use. Now, it’s time to start knocking them off the list, one by one.

{mospagebreak title=Getting Started with yaapi}

Before I get started, here is a check list of the prerequisites required for the successful installation and implementation of the packages that I intend to use for my development:

  • a web server, preferably Apache
  • PHP, installed and configured on the server
  • a MySQL database

Fortunately, most Linux-based hosting packages bundle the above software as a part of their standard hosting plan. But, if you have a dedicated box that you manage on your own, you can always download (and install) them from the following websites: 

The next step is to download a copy of yaapi. Point your browser to the following URL: http://xhawk.net/projects/yaapi/. Next, I uncompress the archive file, i.e. yaapi-1.2.1.tar.gz, to a convenient location under my web server root as shown below.

$ tar -xzvf yaapi-1.2.1.tar.gz

$ mv yaapi-1.2.1 yappi

Next, I proceed to create a MySQL database that will be used by yaapi. Start up the MySQL client and fire the following commands, one by one.
Create a new database using the following SQL command (I’ve called mine “bb_cms”).

mysql> CREATE DATABASE bb_cms;

Next, I create a MySQL user with the appropriate rights on the database that I’ve created above.

mysql> GRANT SELECT ,  INSERT ,  UPDATE , DELETE , CREATE , DROP , INDEX , ALTER ON `bb_cms`.* TO  ” bb_cms_user “@”localhost” IDENTIFIED BY “password_comes_here”;
Query OK, 0 rows affected (0.03 sec)

After the database and MySQL user have been created, it is time to set up the required database tables. And fortunately, the yaapi distribution contains a SQL file — titled “yaapi.sql” — with the required SQL instructions. Execute the following command: 

$ mysql -D yaapi -u bb_cmsuser -p < /usr/local/apache/htdocs/yaapi/yaapi.sql

{mospagebreak title=Setting it up}

After setting up the database in the previous section, I proceed to configure yaapi itself. For starters, I need to configure obvious parameters such as the database server, the database name, and so on, so that yaapi can retrieve information from the database that I’ve just created above.

No sweat; locate a file titled “article.class.php” in the root folder of the application and search for the following code snippet:

<?php

// snip

/**
* object constructor
*/

function article() {

  $this->version = ‘1.2.1’;

  $this->auto_approve_insert = 0; //bool
  $this->auto_approve_update = 0; //bool
  $this->show_approved_only  = 1; //bool
  $this->show_section_only   = 1; //bool
  $this->hide_intro          = 0; //bool
  $this->use_fix_date        = 1; //bool
  $this->section_id          = 0; //int
  $this->word_wrap           = 0; //width, 0 disables
  $this->allowed_tags        =
  ‘<a><b><i><u><ol><ul><li><br><p><blockquote>'; //string
  $this->intro_delim         = ‘#intro#';
  $this->page_delim          = ‘#page#';
  $this->a_table             = ‘article';
  $this->ac_table            = ‘article_content';
  $this->cat_table           = ‘article_category';

  @$this->link_id = mysql_connect(‘localhost’, ‘bb_cmsuser’, ‘password_comes_here’) or die(‘Could not connect’);
  @mysql_select_db(‘bb_cms’) or die(‘Could not select DB’);

}

// snip

?>

As the comment suggests, the above code snippet represents the constructor of the yaapi “article” class. For the uninitiated, the term “constructor” is just a fancy term for a function that gets things moving as far as objects are concerned. It’s obvious that this is where I can configure almost all aspects of the application; for the moment, let’s stick to the default values.

As you might have guessed, the next two of lines of code are of immediate interest as this is where the API initializes a connection to the database. Here I have to specify the server name (i.e. “localhost” in my case), the database username (i.e. “bb_cmsuser”) and password (specified at the time of user creation) as well as the name of the database (i.e. “bb_cms”) that I intend to use.

However, I was not comfortable with the idea of specifying these parameters in this file. After all, it will be cumbersome to modify these values when you move your application to a different server. So, I decided to develop a quick work around for this problem by creating a separate configuration file — titled “inc.config.php” — to store my instance specific information.

<?php

/**
* Configuration file
*
*/


/**
 * Database parameters
 */
$DBHOST = “localhost”;
$DBNAME = “bb_cms”;
$DBUSER = “bb_cms_user”;
$DBPASS = “password_comes_here”;

?>

Next, I update the “article.class.php” file to include this configuration, to ensure that I can access these parameters via the $GLOBALS variable, as demonstrated below.

<?php

// Core library and configuration files
require_once(“config.inc.php”);

// snip

@$this->link_id = mysql_connect($GLOBALS["DBHOST"], $GLOBALS["DBUSER"], $GLOBALS["DBPASS"]) or die(‘Could not connect’);
@mysql_select_db($GLOBALS["DBNAME"]) or die(‘Could not select DB’);

// snip

?>

That’s much better, isn’t it? Time to move on.

{mospagebreak title=First Glance}

Now that I’ve set up the application, it is time to take yaapi for a quick test ride. Well, not so fast; it is pointless to have a CMS without any content.

Time to rectify this little anamoly. I load the yaapi admin module by pointing my browser to the following URL – http://localhost/yaapi/admin/. You should view the following screen in your browser.

Note that you may have to replace “localhost” with the name of the server where you’ve installed the application. For my initial demonstration, I click on the “New” button in the “Categories” section to load the following screen that allows me to add categories and …

…. then, I click the “New” control of the “Articles” section to add an “Article” using the following form:

Note that you have to set the “Approved” flag to “Y,” otherwise the article will not be available for display on the website. With the insertion of content into the database complete, it’s time demonstrate how to display a simple listing of articles using yaapi. And to make things easier — at least, for me — the yaapi distribution contains a set of sample scripts in the “demo” directory.

For example, I can view the article that I’ve just inserted using the following URL: http://localhost/yaapi/demo/intros.php.

You should view something like this:

While the output may not appear fancy at first glance, it does serve the purpose of demonstrating the capabilities of yaapi. Some of you might complain that I breezed through the admin screen. However, there’s no reason to despair because all will be unraveled in due course; that’s a promise.

Same Time, Same Website — Next Week

That’s about it for this first part of my tutorial on building a barebones CMS. I started the article by giving a quick introduction to the different APIs that I intend to use. These are yaapi, a useful API to manage content stored in a MySQL database; patTemplate, a versatile templating engine; and patUser, a nifty tool to manage users and permissions developed by the team behind patTemplate.

Next, I gave you a step-by-step outline of how to install and configure the yaapi application on your web server. Then, I showed you a quick workaround to ensure that you can update your configuration without having to edit the core API files. Finally, I gave you a whirlwind tour of the yaapi admin module, followed by a demonstration of the yaapi APIs.

In the next part, I shall explain the twin concepts of “categories” and “articles” in the context of “yaapi.” It is critical to understand these concepts in order to leverage the capabilities provided by yaapi. Next, I will also demonstrate the true power of yaapi: the properties and methods of the “article” class that help to retreive content from the database and display it on the web page.

Till then, enjoy!

[gp-comments width="770" linklove="off" ]
antalya escort bayan antalya escort bayan