Vincent Reniers | From PHP Guru to Designer!

TAG | CMS

Jan/10

15

Nexis version 0.7

For the past few months, I’ve continued my work at my content management system. Since the start of the project in April 2009 the software has achieved quite some structure and features. All this with one goal in mind, to make things easier while developing websites. At this point, there only needs some minor functions to be added to the system such as ACL (Access Control List) and more advanced language support. When it comes to performance tweaks I’ve tried to minimize the loops and queries, and with only about 10 000 to 12 000 lines of PHP I’d say this CMS is quite lightweight. Also to maintain optimal performance for more high-traffic website I’m still thinking about improving the cache. Now to decide wether this is the CMS you want to use for your site you would of course want to have a look at it’s features. I’ll try to give a good overview but I might add some new features later on because I could have forgotten about some.

Structure

The aspect is the structure of the CMS, it’s not Module-View-Controller based but it’s something different. There are 8 different directories, but you will only use a few of them most of the time: admin, lang, cache, images, css, templates, modules and system. The first directory contains the admin area, it is expandable but you can do this within your module so there isn’t much need to go in there. Then we have the lang and cache directories. These are maintained by the system and store system files. The images and css directories are just shared directories to be used amongst different templates e.g. error css. I might move that to one single html folder. The system directory contains functions, classes, configuration, imports, the router and database class. Only some of these files are imported by default because they are necessary to operate succesfully. Setting up your template is very easy. It doesn’t require a lot of changes, you just place some {TAGS} such as {MODULE} and {TITLE} which are automaticly filled in.

The module tag is controlled by the modules, these form the core of your application. They load the HTML files necessary to generate the content for the pages. The PHP and HTML is seperated from eachother by my own template engine. An example of a module could be news. This module will have an html, maybe xml (for ajax and rss feeds) directories. And a control.php file. I will go into this more deeply later on since there are also two different types of modules: background processes and display modules. Only one display module can be called at a time and the various background processes may run but these are often very simple such as a log to keep record of users. Now what a display module does is, when an action is called the php will process it. It will import the HTML file and put it on the {MODULE} tag and the html file may also contain its own user-defined tags which may be used to put php variables into or to place another html file. PHP can only be used in the html when it is written with a .phtml extension. The template engine will parse this file when it recognises this extension. So this makes a very clear distinction between PHP and HTML while giving the programmer the freedom of still beeing able to use PHP in the HTML if needed. There is no need to learn a custom template language.

Features

Now that you have a basic overview of the structure a good overview of features may be handy.

  • Templates: seperate PHP from HTML
  • Support for multiple languages
  • Router for when you have mod_rewrite enabled, but this is not necessary
  • Advanced Caching
  • URL and Parameter validation on top-level.
  • Custom Error Handling
  • Database class for MySQL
  • Security for MySQL Injections
  • Admin area
  • User management
  • Access Control List
  • RSS Feed Generator
  • Support for AJAX Requests
  • Custom Template Engine
  • Extensions for Admin Area
  • Multiple templates (public and private)

I’m sure I have forgotten about some functions, but these are the main functions that the system offers you =). Now wether I will make it openSource is still not sure.

Example of a News Module

Ok suppose we would like to create a module that serves news articles. We will create a directory ‘news‘ in modules. This module will contain a html folder with the HTML for the Article page and the HTML for each article.  So we create ‘news.html’ and ‘article.html‘. Now in news module we will also create a ‘display.php‘ file that will handle the actions. So basically what we have got now should look like:

News ModuleFirst of all we will have to tell the system to allow the request. So we open up the router and add this line.

This will tell the Router to allow News and to only accept parameters from article with a numeric value. You can specify extra options for more advanced url and parameter validation but we won’t go into that right now.

Router::setURL('/News/article/*');  

Now we will supply some HTML to work with. An example of what ‘news.html‘ could look like is:

<h1>News Page</h1>

<div id="articles">{ARTICLES}</div>

Second we will create the HTML for the ‘article.html‘.

<div class="article-preview">
<h2>{TITLE}</h2>

<p>{CONTENT}</p>

<a href="/news/article/{ID}">Read More</a>
</div>

Ok enough HTML written! Time to make this code work =). We will now go into the ‘display.php‘:

$db->setQuery('SELECT `title`, `content`, `id` FROM `@__news` LIMIT 5');
$db->fetchList('Articles');

$tpl->loadHTML('news', 'Module');

foreach($Articles as $Article){
$tpl->loadHTML($html = 'article', $tag = 'Articles', true);
$tpl->Replace($Article);
}

$tpl->Delete('Articles');

Only a few lines to make the entire news article work! Now let me explain this line by line because it may seem complicated at first sight. First we load the articles from the database. The @__ is needed if you wish to make use of a table prefix. The results are loaded into the variable $Articles. Then we load in the HTML file and place it where the {MODULE} tag is located. Now this makes the tags in ‘news.html‘ available for use to the template engine. And then it will go through each article one by one and while we do this we will load in ‘article.html‘ each time and replace the tags inside them. And finally we will have to delete the remaining {ARTICLES} tag because we have specified a third parameter true in the loadHTML function which puts the {ARTICLES} tag back in place for use. Making it available for the second article and so on.

The replace function may be unclear right now, but what it does is. It sees that $Article is an array and for each key it tries to find an according tag and then it puts the values of the key on the location of the tag.
Another method to do this would have been:

$tpl->Replace( array( 'title' => $Article['title'], 'content' => $Article['content'] ) ); 

But the example is just to show what kind of magic into some functions =). I hope you have enjoyed reading through this quick introduction. I hope it may provide you with some insight it the possibilities of using a cms. The reason why I think this CMS might be interesting is because it isn’t really based on one model out there, it is more a unique combination of what I thought to be the best solution I encountered each time while programming this system.

, , Hide

Aug/09

10

Nexus v 0.5

Since my last post about the Nexus CMS on July 17th there have been made soo many changes to the system that I thought it would be better to move on 0.3 more versions :D .  First of all. The Main System, RSS system, Ajax Handler and Admin backend are fully operating!

Changelog:

- Added backend admin system
- Added authorization (better roles etc.)
- Added admin core modules (+ override feature)
- Fixxed error handler with buffers activated (all systems: rss, ajax, main and backend)
- Added several core modules ( dashboard, settings, …)
- Base Paths for includes, requires, templates etc. (much more stable when moving the application)
- Created seperation in templates ( private => backend, public => frontend)
- Mod Rewrite feature implented

The admin core modules come standard in the Nexus CMS. But they can be overriden by user modules. They are pretty much the same as site modules but they do not have XML files, rss or ajax request handler which is pretty obvious why =). Also they live in a restricted area, unauthorized users have no access to anything related to the core. When the override feature is activated for a certain module the system will skip scanning for an admin core module but will instantly check if the site module has a control.php file to manage the administration from the site modules. The admin HTML documents are located between the frontend HTML. This override will allow a programmer to keep pretty much every operation of his site in the frontend modules. But if they like they can also create a seperate core module.

You can activate apache’s mod_rewrite from the admin backend (in a core module).  The mod rewrite isn’t actually deactivated so you can still manually type the URL’s more decently when it is turned off. The rewritten URL’s look like this: ?com=News  => /main/News/ or  ?com=Portfolio&offset=3  => /main/Portfolio/offset/3/ . The last rewrite with the variables still has to be implented, but the basic one is already working. You on’t have to define this when you write it in your template, I thought it would be a lot easier not to use some kind of syntax like {LINK=”?com=News” , “/main/News/”} . This syntax was never implented, instead I just created a function in the Template class that runs at the very end before we display. It rewrites all the ?com= links to the correct rewritten links if mod rewrite is turned on.

To do list:

- Implement caching system
- Change language constants and use an internationalisation function instead.
=> These language strings will be stored in the database. The default is hardcoded and in English.
- Add more backend modules

So thats pretty much my latest changes at the Nexus CMS so far :D . It has been smoothened up a lot, and runs a lot more stable.
So far it’s looking very good and I might release an Alpha version soon.

, , , Hide

Jun/09

17

Nexus version 0.2

I’ve started working on my cms again lately and many improvements have been made to the platform. The basic structure has now been set. One of the improvements made was the addition of an integrated error system which handles every PHP error that occurs inside the system (even non-PHP errors in e.g. DB class) and passes it onto an error handler which writes it safely to an error log just in case the Database has dropped out. Still might need to add a rollback feature to that and then it works like a charm. Also the modules work correctly now which is quiet a unique aspect. It works as follow: Modules are divided into two main groups, Passive and Active ones. The passive modules run in the background and won’t be displayed to the average user.

Passive modules are also again divided into critical and unnecessary ones. Passive modules that are critical for the system will terminate the program when they aren’t executed properly or when they just simply don’t exist but are listed. When the other type of passive module isn’t found the program will just simply continue because it forms no risk. However in both cases an administrator will be alerted.

The active modules are modules that do have displays, they often manage news, forums, users, etc. When these modules aren’t found the user will simply be redirected to the default one. There can only be one active module at a time but several passive. They can be turned on and off in the admin area. I don’t know if there is any system like this out there yet or if this is the best way to do it. But this is just how I do it. And I prefer beeing unique and creative than just simply copying off other people their code. Anyhow, now the coding of the modules can begin and this also means the actual content of the system!

, Hide

Apr/09

19

My CMS

Here is a quick picture of the CMS i am currently developping. You can see the default layout and a part of the template code wich is not yet finished. I still need to implent a way to import modules and widgets. The template class can get quiet complicated. I’m having this idea on how to load in the modules by assign a type to modules. First type is the passive one that is always loaded in and runs in on the back. The second is the type that is permanent and remains like on the sidebar. And the third one comes occasionally. Like a page or a box on the homepage. I’m not sure how this will operate. So i’m figuring the how-to part out first before getting to the coding part because if I don’t think this through it could get fucked up in the mid hehe. ;) Anyways tell me what you think about the default layout so far wich i’m going to use to construct the system on.

Nexus CMS

, , Hide

Apr/09

14

Nexus CMS

Hello lads, it´s been a while since my last post but of course I have a good reason to explain my absence ^^. Right now im writing this post in Tenerife ( Canarian Islands ).  And i´ve been working at my new CMS.

So far i´ve got the basic structure finished it has some nice features. I didn´t really base myself on some other system but I did try to create a template system. It works like this :

First action i define a Constant “In_Site”,  all my scripts are written in an IF statement to see if it is defined otherwise it wont run. Its to prevent messy errors when u go to the script directly. What happends next is I load in the config and functions wich are static and no operation occurs. Next we establish the database connection with the help of my DB class. Im still working on it tough and trying to figure out if there is a way to rollback DB events when an error occurs. I know this is possible with MySQLite so now I have to do some digging in the MySQL documentation because thats the DB im using. If the rollback function exists im going to let occur within custom error handling. The try and catch statement. After the DB class comes the settings wich require the DB connection to fetch the settings. And then we get to the templating part.

The template part loads in the default template if it exists and it then processs the variables it finds inside the tpl. Such as {SITETITLE}. Then the module gets processed for example ´News´ and while this happends u can still make changes to the template and at the end the entire part gets printed.

Or well that´s at least what I will be trying to achieve. Right now I have got the a part of the Template and Database class finished. Ill be figuring out the module part and how it loads into the template part out later.

But so far it already looks nice, I even made a custom layout for the CMS.
Ill upload some screenies soon ^^.

Greets,
Vincent

, , Hide

Mar/09

16

Current Plans : New CMS

At the moment I’m planning on making a new cms. So I’m looking at other applications and how their template engines work. The way they process errors, load modules and error handling etc. So far I’ve already managed to create a smooth looking template. It’s not finished so far, I will put it online as soon as I’ve got it sliced etc. =).

, , Hide

Find it!

Theme Design by devolux.org