Book Image

Joomla! 1.5x Customization: Make Your Site Adapt to Your Needs

Book Image

Joomla! 1.5x Customization: Make Your Site Adapt to Your Needs

Overview of this book

Setting up a basic Joomla! Web site is easy; what comes next is hard and expensive ñ making the site do exactly what and look exactly how you want. With this book in hand, it is easy to adapt your site to bring your vision fully to life. This book will help you to separate your site from the crowd of other Joomla! sites without having to invest in developers. It will guide you through how to customize different parts and aspects of your site and will also show you how to turn your site into a profitable business via these customizations. You will be able to build a successful, professional web site that will adapt to all your business needs. You will be taken beyond the basics of Joomla!, and given an insight into the techniques and tools used by the professionals to rapidly develop unique, custom sites. This will enable you to develop your own professional-quality Joomla! site without assistance, saving you time and money. You will learn how modules, plugins, components, and templates are constructed, and how to make changes in them, giving you the confidence to make more elaborate changes to your site. On top of this will be a look at common problems Joomla! site developers face and how best to deal with them. You will also learn techniques for building a business with Joomla!, as you step through building a subscription-based web business. Towards the end, you will look at marketing and monetizing this business fully to maximize your return.
Table of Contents (17 chapters)
Joomla! 1.5x Customization
Credits
About the Author
About the Reviewers
Preface
Index

Server-side scripting and PHP


Server-side scripting is a web server technology that replaces the use of static, unchanging HTML pages with dynamically generated HTML pages. The pages are generated by scripts on the server (hence the name) when requested and passed back to the browser.

These dynamically generated pages have a number of significant benefits over static pages:

  • Easier maintenance, because there is usually only a single copy of any site-wide HTML

  • Content can change and react to user preferences or input

  • Content can be added or changed without changing any HTML

  • Sites are often constantly evolving and improving as users and developers alike add content to the site via dynamic communication technologies such as forums or comments

  • Much faster to make updates to the entire site layout

There are many different languages that can be used for server-side scripting, but since Joomla! uses PHP, so we will be focusing our studies there.

A dynamic, PHP powered, site's structure differs from a static web site in several key ways:

  • There is usually only one main file that is ever called from the browser, almost always named index.php, and different pages are generated according to parameters passed to the server from the client.

  • Usually a database or data files of some sort are used to separate the raw data from the HTML, and they are then assembled upon the user's request.

  • A PHP web site only sends generated pages to the client. Pages that do not actually exist on the server as a file in the form that the client receives them. However, most static HTML sites send exact copies of the HTML files that are on the server.

  • Instead of a mass of HTML files, there are usually fewer files, and they contain mainly scripting code, and much less HTML.

Note

Because PHP runs on the server, our client browser only ever downloads the already generated HTML and never sees, nor even knows about, the PHP.

Joomla!, like most PHP sites, uses the file index.php as the primary gateway to a site. This file receives the requests from the browser and then calls the appropriate PHP functions needed to create a page that matches the request. However, please note that we will usually never change any of the code inside a Joomla! site's index.php file because all it does is call other files, many of these are template or extension files. It is the template and extension PHP files that we will usually be editing.

Note

Joomla! templates also include an index.php file. This index.php file and the Joomla! core index.php file are different and serve different purposes. Editing a template's index.php file is a very common practice, unlike the core Joomla! file. Be careful when you start opening any index.php files to make sure you are editing the right one.

As mentioned above, most PHP generated sites, including Joomla! use a database to store their raw data. This makes it much easier, and faster, to retrieve data when it is requested by the user. It also allows powerful data operations and functions to be performed on the data if needed, such as aggregating it, sorting it, or making it easier to read.

The most common database for PHP sites, and the one used by Joomla! is MySQL. It is popular because not only is it open source and requires no cost to download and install, but it is also very reliable and powerful.

PHP code is designed to operate in two main methods. First, it can be run as complete PHP file. Usually these files are used for data processing, function declarations, or other unseen work.

The other method is to embed PHP into HTML code, usually to add loops, conditions, and load data into the otherwise static HTML, and usually these mixed HTML/PHP files are used as templates, or parts of templates, for displaying data on a site.

PHP can be easily recognized by the telltale <?php … ?> tags around sections of code. These tags are needed to complete PHP files and appear at the very start and end of the file. However, in a mixed HTML/PHP file, there are usually many, shorter code sections and tags.

Note

PHP is a detailed and complex language and there is no way we could cover it in any usable detail in this chapter. Instead, it is recommended again that you find some of the many great online and offline resources. One of the best sites to get PHP information is www.php.net, which contains a complete list of the available functions and commands for PHP. You can also pick up one of the great PHP books from Packt Publishing (www.packtpub.com/php-mysql)

The basic operation of a Joomla! site revolves around the index.php file, calling the PHP files for the extensions and template required by the client request, and then assembling the HTML code output by them into a page and then sending it to the client. Extension PHP files usually reside in a /components/com_componentname directory, /modules/mod_modulename, or /plugin/plugintype/plg_pluginname and templates in a /templates/templatename folder.

Note

Plugins were not included in the preceding diagram because they execute at many different times throughout the site.

MVC programming and PHP

From Joomla! 1.5, the PHP code architecture has been converted into what is called a Model-View-Controller (MVC) architecture. MVC is an attempt to separate business logic from data and from the user interface, with the model representing the data, the view representing the user interface, and the controller representing the business logic.

This is easily seen with Joomla! Extensions, which will often have model, view, and controller subfolders containing the relevant MVC PHP files for that extension.

The files in the view folders are most likely to have PHP and embedded HTML files, and the model and controller folders should only contain fully PHP files.

Note

For more information about PHP and MVC within Joomla! extensions, I highly recommend the book Joomla! Extension Development, also from Packt Publishing.

PHP does have limitations though. Its dynamically generated pages still look fairly static by the time they reach the client, and PHP operates on the server, so what do we do if we want some dynamic activities on the client?

This question brings us to client-side scripting, and JavaScript.