Vincent Reniers | From PHP Guru to Designer!

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

Nov/09

7

New website online!

As you may have noticed, quite some changes have occurred lately on my site. The most important change is the move of the blog from the domain to the subdomain blog.vincentr.be. And instead there now is a good overview of my work on a portfolio. It also includes my latest tweets and blog posts to give a quick overview.

The portfolio is also the first website that goes live on my Nexis CMS ( Yes I renamed the cms from Nexus to Nexis ). On launch I experienced quite some problems. Most of them had to do with the include paths. Since I have set a  BASE path constant which is used in each require or include function. This constant wasn’t correct anymore, because of the fact that I’m on shared hosting and my path isn’t C:\\ anymore. That gave me quite some trouble, but I had everything solved in 1 hour. I also noticed some problems where my localhost should have given an error, but it seems to have ignored it or found a way to solve it.

Anyhow, let me know what you think of the new layout ;-) .

, Hide

A few weeks ago I started reading a Beginner’s Guide to Magento by Willaim Rice. Because during my work at Yappa I discovered how huge and complex this eCommerce system can be. And since it’s one of the most popular CMS at the moment it might be worth getting to know more about it. It is another book published by Packtpublishing, a company which I’ve already read quite some books from so far. So if you know the publisher you should already know that before you start reading it that you can expect it to be of good quality.

The first chapter goes into the installation of Magento. From my own experience I encountered some problems during this installation, which was that Magento sometimes requires extensions such as the cURL library. Which wasn’t enabled on my PC at the time. I was pleased to find that the author had also written a notice about this problem. The rest of the installation is very detailed and includes many many screenshots throughout the entire book.

When you’re installation of Magento is ready, the author discusses the various things you can do with Magento. Such as adding categories, how to manage your tax rules, adding products, etc. This all may seem very easy. But when you’re a beginner and you don’t know a lot about websites. The huge administrator’s panel of Magento might frighten you at first, preventing you from using the great features it provides you. After having read this book I think you can be quite sure that you can tame this beast =).

However I haven’t really read all the chapters, so far only about 40-50 pages since I was trying to find out more about the technical aspects of the system. Such as the MVC framework it runs on and how the templating system works. Thats why I had stopped reading the book. So I would really recommend this book to anyone who wants to get to know more about using the system. But when you’re interested in getting to know more about how the PHP works, you might want to consider another book. But overall I think it’s a very good manual for beginners.

If you’d like to read a sample chapter of this book you can visit the following link:
http://www.packtpub.com/files/magento-sample-chapter-3-categories-and-attributes.pdf

You can find more detailed information about the book and how you can purchase it here:
http://www.packtpub.com/magento-beginners-guide?utm_source=vincentr.be&utm_medium=bookrev&utm_content=blog&utm_campaign=mdb_000800

I’d like to inform you that I’ve received a free copy of this book to review it, but that my opinion while reviewing it wasn’t really affected by this. Just so that you know that this review is as objective as possible. But if you’d like to get to know more about using the Magento system, this book should help you a lot.

, , Hide

Sep/09

23

Internationalization in PHP

Why have such a function?

While working at my CMS I was thinking on what would be the best way to manage the various languages and still make it easy to write the apps. After some thinking and taking the advice of a collegue into consideration I came to the conclusion that it would be best to let all strings go through a function. The internationalization function __(”); why this function? Because it’s pretty much becoming a standard in other CMS. And I don’t want to make it hard for other devs if they need to understand my script.

Now what exactly will this function do?

First of all we want the string that we enter via this function to be translated into other languages. Now so we first need to know some information and ask yourself a few questions before programming. Like what languages has the user set? Are these languages active? Where do we find the translation? What if the translation is incorrect, how can the user change them?

So we could just make the translations hardcoded, but that wouldn’t be quite usable for a normal administrator to change these translations. Thats why we will also put them into the a DB Table. And of course this table will just be a reference for the backend since we do not want to go fetch a translation from the database all the time. Thats why you should store it in a file, this way it will be a lot faster. Ok yes you can cache it, but still if the cache is turned off retrieving them from files is a lot faster than running multiple queries. Now how to save them in files could be done in various ways. They could be stored in an .ini or .txt file and a line can be added each time there is a new translation. But storing them in a .php file would be a lot faster since the .ini, .txt files would have to be parsed each time. While when you would put the translations in an array the data is instantly available for use.

Now if there is a better way to store them in a PHP file then please let me know. But we’re just going to with this method. What the array could look like is this:

array(
'english' => array(
'hello' => 'hello',
'how are you?' => 'how are you?',
),
'french' => array(
'hello' => 'bonjour',
'how are you?' => 'comment ça va?',
),
);

Now when adding a new translation to the PHP file via fwrite it would be hard to put it on X amount of locations ( X = languages ) and than write it back again. Now that would be possible but it’s probably going to coss more load. Now a better (but temporary) way to do it I think could be by simply adding $lang[$language][$text] = $ translation; at the bottom. And then you could create a cronjob that will sort out these language files properly at the end of every day or make a script in the admin area for an administrator to do it. Now adding them directly to the array by finding the correct location could also work well.

Now how would you let the function create the translations for the other languages than the one you wrote it in? One way would be just duplicate the text and wait for an admin to change the values with the correct translations in the DB Table and then let it go to the file again. But a smart way would be to let it go through a Translator API and the generated translation would be ok 90% of the time.

What if the function already found a translation?

In this case you can just select the array of the language you’re currently working and than see if the string has been translated and go fetch it. Otherwise the function would have to do the steps described above.
Anyways, these were my thoughts on how to create a good internationalization function. Now there could definitely be some easier ways to create it, and if you found one please let me know! I hope you learnt a bit on how to create it and I’m going to try and put this idea into code very soon =).

, , , , Hide

Aug/09

25

Magento

After 4 awesome days at Pukkelpop, I’m back and working at Yappa :D . The past few days I’ve been assiged a task to design a webshop and implement the design to Magento, a huge and one of the fastest growing eCommerce platforms. Now I can tell you that the template system is quiet complicated and the first few steps you take you better prepare yourself by reading their designer’s guide. Magento offers tons and tons of features. A feature which I really enjoyed seeing was the multiple stores you can manage within one system. You can choose to seperate the stores entirely or just create different stores for different languages, etc. The looks of your website are located in something named an ‘interface’. The interface holds the layout, locale, template folders. There is also a skin directory located in the root. When you’re making a new template for Magento these four directories will be the ones where you will spend most of your time. But a thing I found quite strange about Magento is that it uses XML files to sort the template files onto the correct location and pages. At first sight this might seem incomprehensible or complicated, but trust me once you get to know how it works you’ll find it very interesting and easy to use.

These XML files live inside the layout folder. In the template folder we have the .phtml files wich stand for PHP and HTML I think =). It’s because you can also use PHP syntax inside the HTML. Thank God they didn’t try to reinvent the wheel and make their own PHP HTML syntax kinda like smarty, because I hate learning those. So here it’s a lot easier and u can just use PHP inside the template files. The locale folder simply holds the translations for every text used in the template.

So how exactly do the layout and template files work together? Well, the template files can be divided into three kinds. The first one is the skeleton for example: 2-column.phtml, 3-column.phtml.They contain the main html elements like div=”header”, div=”footer” and inside those we refer to blocks. First comes the structural block, like when we refer to the left sidebar the sidebar will refer to structural blocks like ’subscribe to newsletter’, ‘navigation’, etc. And then these structural blocks will refer to blocks that hold the content. Like inside the header structural block we could refer to the ‘topLinks’, ’search’ blocks.

As you can see I mention the ‘refer’ word a lot :D . This is where the XML Layout files come in place. Magento has its own XML syntax and each template comes along with one xml layout file, but the page template can have multiple files in its directory. And the XML holds the knowledge to figure out where the template files are pointing to when you call ‘topLinks’ for example, you will have specified some lines so the system will know what to fill in there. for example.

<block type=”page/html_topLinks”  name=”topLinks” template=”page/html/top_links.phtml” />

Or something like that, it’s possible that it isn’t correct because I haven’t used it that much so far. I did create the template and that one works very well :D . But when creating a new template I’d advice you to take a copy of the default interface and skin directory and start from there. I pasted my HTML under theirs and just copied the PHP lines which filled in the content. The XML layout files where already there and pointed the correct template file(which I also adjusted), so that can save you a lot of time when making a new Template. Just copy the default ones and work your way from there.

Some Tips for when you get started:
1. Turn on the Template Path Hints (these show you what template file is used and where) very handy.
2. When you’re trying to edit blocks: for example ‘newsletter’ block go look in the newsletter.xml. Also looking in the catalog.xml might help a lot.
Between the <default> tags are shown most of the time.

Thats my review, tips & tricks for Magento so far :D .
It’s a great system,  but it just takes a bit of time to know it properly so you can use all of its potential.

Hide

Aug/09

12

Radio + Google = nice

While I was driving to work today I was listening to StuBru, a belgian radio station. When this quite chill but awesome song came up :D . I tried to memorize some of the lyrics but they sounded pretty strange so I got them wrong. But fortunately enough StuBru’s website has an extensive playlist of the songs they played, so I managed to find it again on Youtube. The video is kinda strange though but I like it. You can find the lyrics here.

Empire of the Sun – We Are The People

, , 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

Aug/09

10

Some smooth electro =)

It’s been a while since my last blog but enuff said, stumbled onto some nice youtube vids again.


Bendj feat. Sushy – Me and Myself ( Wolfgang Gardner UK Edit )



MSTRKRFT feat. John Legend – Heartbreaker

, , , Hide

Jul/09

19

Neobux

One month ago one of my friends told me about Neobux, a website where you can earn money by managing referals and clicking advertisements. Normally I never signup to these type of websites. But since this information was coming from a trusted source I thought “Hey why not, its vacation and I haven’t got that much stuff to do anyways :D .” So I registered, but I soon found out you need to invest money to get more out of it faster. It works as follows. You get a minimum of 4 ads you can click on each day. For each advertisement you get 0.01$. Sometimes there are also extra advertisements you can click on during the day or when you upgrade your membership you get to see more advertisements. But this won’t get you that far. The part where you can make a lot of money are from the Referals. You can rent Referals or you also have your own ones (Direct Referals). Each time a rental clicks on an advertisement you get 50% of what they earn. So if you have a lot of rentals you can get a lot of money each day. So from the start on you need to start collecting lots of referals to improve your daily income.

By clicking on this banner for example you can register on Neobux for free but you will also become one of my referals. If you go to the neobux site manually you actually become a referal from neobux and they will get 50% of your clicks. Now when you rent a referal you will actually rent it from Neobux, those users are users who didn’t got redirected by people like me but signed up themselves.

So why not give it a shot yourself, and register by clicking on the banner =). If you have any more questions on how it works you can always contact me or write a comment here.

Hide

Jul/09

3

Time for some Obama!

Not only does this president bring change but also a good laugh to the press :) . (Btw this is a ninja remix, you can watch the original video here.)

, , Hide

« Previous Entries

Next Page »

Find it!

Theme Design by devolux.org