Verry simple PHP CMS
PHPPublished August 4, 2009 at 10:04 PM 8 CommentsI have some clients who wants simple sites, only to show basic info about them. So, i-ve implemented an simple system to be faster on page building. This are the steps:
1. create basic structure of the site (3 dirs)
+content
+images
+includes
2. we have 4 files to write:
a. index.php
<?php
/**
* @author Cristian Tantar <http://www.tantar.info> <cristian.tantar@gmail.com>
* @copyright 2009
*/
require("config.php");
$parameters=array();
if(MAIN_DIR!=""){
$parameters=explode("/",str_replace(MAIN_DIR."/","",$_SERVER['REQUEST_URI']));
}else{
$parameters=explode("/",$_SERVER['REQUEST_URI']);
if($parameters[0]==""){$temp=array_shift($parameters);}
}
if($parameters[0]==""){$parameters[0]="engine";$parameters[1]="";}
if(!isset($parameters[1])){$parameters[1]="";}
if(file_exists($parameters[0].".php")){
require($parameters[0].".php");
}else{
require("engine.php");
}
?>
b. config.php
<?php
/**
* @author Cristian Tantar <http://www.tantar.info> <cristian.tantar@gmail.com>
* @copyright 2009
*/
define('APP_PATH',dirname(__FILE__).DIRECTORY_SEPARATOR);
if(isset($_SERVER['SCRIPT_NAME']))
{
$main_dir = rtrim(dirname($_SERVER['SCRIPT_NAME']),'/\\');
}
else
{
die('[config.php] MAIN_DIR error, set manual');
}
define('MAIN_DIR', $main_dir);
?>
Here, in config.php, if need, we can include the connection to MySQL or other configs.
c. engine.php
<?php
/**
* @author Cristian Tantar <http://www.tantar.info> <cristian.tantar@gmail.com>
* @copyright 2009
*/
function callback($buffer)
{
Global $tags;
foreach($tags as $key=>$value){
$buffer=str_replace($key, $value, $buffer);
}
return ($buffer);
}
ob_start("callback");
require("includes/header.php");
$includefile="content/default.php";
if(isset($parameters[0])){
if(file_exists("content/".$parameters[0].".php")){
$includefile="content/".$parameters[0].".php";
}
}
require($includefile);
require("includes/footer.php");
ob_end_flush();
?>
and finaly
d. .htaccess
This is an important file, so the site can work
# AddType x-mapp-php5 .php
# AddHandler x-mapp-php5 .php
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
ErrorDocument 404 /page-not-found/
<files ~ "\.tpl$">
order deny,allow
allow from none
deny from all
</files>
3. In [CONTENT] directory, we will put the content pages, offcourse. We need just 1 to begin: default.php
Here is it:
<?php
/**
* @author Cristian Tantar <http://www.tantar.info> <cristian.tantar@gmail.com>
* @copyright 2009
*/
$tags=array();
$tags['{title}']="This is the title of the site";
$tags['{description}']="Here is description of the site";
$tags['{keywords}']="and off course, the keywords";
?>
<div id="content">
<h1>Home</h1>
</div>
Some words on this:
- You can create tags for each page of the site -> useful for SEO
- Replace what is between <div id=”content”> … </div> with your code, HTML or PHP for the page.
4. In [INCLUDES] directory, we will put the header.php and footer.php.
a. header.php<?php /** * @author Cristian Tantar <http://www.tantar.info> <cristian.tantar@gmail.com> * @copyright 2009 */ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="cristian.tantar@gmail.com" /> <meta http-equiv="Description" content="{description}" /> <meta http-equiv="Keywords" content="{keywords}" /> <meta http-equiv="Revisit-after" content="2 Days" /> <link href="<?=MAIN_DIR;?>/style.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="<?=MAIN_DIR;?>/lightbox.js"></script> <style> </style> <title>{title}</title> </head> <body> <div id="divMain"> <div id="logo"><a href="<?=MAIN_DIR;?>"><img src="images/logo.jpg" border="0"/></a></div>This 2 lines:
<link href="<?=MAIN_DIR;?>/style.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="<?=MAIN_DIR;?>/lightbox.js"></script>I use styles from style.css and Lightbox script for my images to popup nice.
(of course, other files are included in main dir, all files required by Lightbox script to run)
b. footer.php<?php /** * @author Cristian Tantar <http://www.tantar.info> <cristian.tantar@gmail.com> * @copyright 2009 */ ?> <div id="footer" > Copyright info here </div> </div> <-- close mainDiv--> </body> </html>This is main configuration.
I need only to take care of design, slice it, save images in [IMAGES] folder, and make the header.php,footer.php and content.php pages.
For other content pages, like Services and Contact, you can create "services.php" and "contact.php".
We will rich to them, by http://siteurl/services or http://siteurl/contact .


Something about rewrite (htaccess):
I wanna use .html instead dir-like for page links, what should I modify?
order deny,allow
allow from none
deny from all
What tpl files?
Anyway, great and lightweight cms.
Not need to change .htaccess .
Just add in engine.php on line 19. $parameters[0]=str_replace(‘.html’,”,$parameters[0]);
And will work.
Cristian
Well, yes, this is the simple way but users can access old version and this can cause duplicate content. Any solution for this issue?
I don’t see why to change htaccess.
If you want separate pages for “/link” and “/link.html” , simple change line 19 in:
$parameters[0]=str_replace(’.html’,’_html’,$parameters[0]);
And make sure that you have the “link_html.php” page in /content dir .
It is ok ?
PS:
order deny,allow
allow from none
deny from all
This is for template files, .tpl . In some versions, I use Smarty for templates.
Yes, I have already renamed content dir files to *.html.php and it works without that php line.
The next stage is working with subdirs, like url.com/category/post.html but I think is a bit hard to do that.
Thanks for your time.
hi nice simple cms.
is there any link where we can download this for us to test and is it ok if ask some example that the content stored on the db.
thanks.
Thank you,
This example is only file-based CMS. I can post an database version if anyone needs.
Some examples with sites using it now: http://www.siteconcept.ro, http://www.pentarom92.ro, etc.
Hey,
Could you share the database version? I’m very much interested in this!
Thanks!