Article
eZ publish: PHP's Killer App - Parts 1-3
Going Global
Now you have an idea of how eZ publish fits together, it's time to get down to the nitty gritty of applying your own design (well, mine in fact -- but pretend it's yours!).
Before you start doing anything with eZ publish, you need a "sketch" of how you want your site to look. Subjecting you to my own personal bias, the first thing to do is download a copy of Opera from http://www.opera.com/download/. Why? Because, generally speaking, if your design looks right in Opera, it will look right in any other browser. If you're running Windows, the non-Java version is fine.
I've put together a simple HTML page and a style sheet that I want to "apply" to eZ publish. If you download sampler.zip, you'll find a simple design for how the site should look in HTML, with a CSS file alongside. The site is going to be very simple -- it'll make use of only the eZ article module. What you'll learn here, though, should be applicable to more complicated eZ publish sites. It's worth having sampler.html (from the ZIP) open while you read the rest of this article, to help visualise what's happening.
The Sitedesign Directory
The first move is to find the [ezpublish_root]/sitedesign/standard/ directory and make a copy of it, which you'll need to rename [ezpublish_root]/sitedesign/phppoint/. You'll keep all the design work in the phppoint directory. It's a good idea to leave the original directories untouched, to have examples to work from.
Next, from the administration back end, head to the site manager (second from far right). The default view is the "Section List". Delete the Intranet, Trade and News sections, as you don't need them, then edit the Standard Section, setting the name and Sitedesign to "phpPoint". Further down the edit page, you'll see a section called "columns". The aim is to have four articles appear at once on the "Frontpage", each taking the complete width of the page. So add a row, and then set them all to "1 Column Article" with the Category "All".
Now head to the URLTranslator (third from the right) and rename /section-standard to /section-phppoint, then delete the other three.
Finally, in site.ini, update the following variables:
SiteDesign=phppoint
SiteStyle=ezpublish
SiteTitle=phpPoint
...
EnabledModules=eZArticle;eZImageCatalogue;eZMediaCatalogue;
eZForm;eZStats;eZURLTranslator;eZSiteManager;eZUser
...
URLTranslationKeyword=section-phppoint
Sections=disabled
The SiteDesign variable points eZ publish at the directory I'll be putting my design in. SiteTitle is the title that appears at the top of the browser. SiteStyle I leave untouched, as this applies to the back end admin section. You need to make sure that only the modules you want are available using the EnababledModules variable. URLTranslation and Sections are discussed in more detail under "Sections" in a moment.
Lastly, clear out the cache in [ezpublish_root]/classes/cache/.
You're now ready to start hacking!
frame.php
In your [ezpublish_root]/sitedesign/phppoint/ directory, you'll find a file called frame.php. This file is basically the main template within eZ publish: more or less all your pages are generated by eZ publish through this template.
Before you go any further, if you'll allow me a momentary rant: this is what templating in PHP is really about. As you've seen in this discussion on the SitePoint Forums, any templating system that doesn't use PHP's own language structure and variables is a complete waste of time, memory and processing power. frame.php is a prime example of how templates should be constructed.
Now, looking at the contents of frame.php, you'll see HTML interspersed with PHP. Before you edit it, I'll introduce you to some examples of what you'll see there. First you have:
<title><?php
// set the site title
$SiteTitle = $ini->read_var( "site", "SiteTitle" );
if ( isset( $SiteTitleAppend ) )
print( $SiteTitle . " - " . $SiteTitleAppend );
else
print( $SiteTitle );
?></title>
Here, the code first assigns the $SiteTitle variable, by fetching it from the $ini object using the read_var() method. If you're at all uncertain about the syntax used there, have a look at Kevin Yank's introductory tutorial on Object Oriented PHP.
After that, the code checks for a $SiteTitleAppend variable, which, if it exists, usually contains something like the title of an article. If this variable isn't found, the contents of the <title /> tag will be just the $SiteTitle variable you set in site.ini.
Moving further down the script, you have:
<img src="<? print $GlobalSiteIni->WWWDir; ?>/sitedesign/<?
print ($GlobalSiteDesign); ?>/images/ezpublish-yourcontentmadeeasy.gif"
height="20" width="290" border="0" alt="" />
Here's eZ publish builds an URL, fetching the URL of the site with:
$GlobalSiteIni->WWWDir
It's nice how these eZ publish classes work, isn't it? For anyone who's been looking at the Kevin Yank's articles on the .NET framework, you'll notice a remarkable similarity. As I mentioned in the first part of this series, eZ publish is also a framework designed specifically for building PHP applications. And this is one of the things a good framework is about: making your life easy, by providing a well designed class library you can reuse.