You have developed dynamic websites in the past, but a friend of yours told you about Joomla!, so you decide to give it a try. You wish to start a simple website about restaurants after being inspired by the attractive celebrity chefs from the Food Network. The installation goes smoothly and more quickly than attempting to build a content management system from scratch. After finding a delicious template, adding some menus, and banging out a couple of reviews, you begin to think of some of the features that will draw in more visitors and even some cash. Within minutes, you install a shopping cart for selling books, a forum for gathering suggestions of places to review, and some advertising affiliated programs for the sidebars.
However, as you glance through the homepage, you feel something is missing. Then suddenly a brilliant idea hits you for something entirely new. Once it is finished, you know others will want to use it for their sites as well. You look around Joomla!’s source files and start looking for a way of building code that will slide right into place.
Joomla! is not only designed to handle the content articles, but also to allow a number of complex applications to be cleanly integrated. Shopping carts, forums, social networking profiles, job boards, and real estate listings are examples of extensions that the developers have written for Joomla!. All of these can run on a Joomla! site, and only a single database, template, and core need to be maintained. When you build an extension to Joomla!, it will inherit the look and feel of the overall site. Any type of program that can be coded in PHP is a potential component waiting to be written.
Your extensions can also be portable. When coded correctly, you will easily be able to install your code on another copy of Joomla! without having to enter the database logins and other basic configuration information again. Additionally, you will be able to distribute your extensions to others so that they can enjoy them, without any programming or database knowledge.
Joomla! is not only designed to handle the content articles, but also to allow a number of complex applications to be cleanly integrated. Shopping carts, forums, social networking profiles, job boards, and real estate listings are examples of extensions that the developers have written for Joomla!. All of these can run on a Joomla! site, and only a single database, template, and core need to be maintained. When you build an extension to Joomla!, it will inherit the look and feel of the overall site. Any type of program that can be coded in PHP is a potential component waiting to be written.
Your extensions can also be portable. When coded correctly, you will easily be able to install your code on another copy of Joomla! without having to enter the database logins and other basic configuration information again. Additionally, you will be able to distribute your extensions to others so that they can enjoy them, without any programming or database knowledge.
Joomla!’s code is designed to be extended rather than hacked or directly modified. Rather than changing the core code, it is preferable to write an extension. When updates and patches are released for Joomla! itself, the core code will be updated, but your extensions will not be overwritten. These extensions are crafted in a self-contained manner, allowing you to freely develop your own code without disturbing other items present in the Joomla! installation.
Although they are self-contained, extensions do not operate in a completely sealed environment; you can mix different kinds to get the functionalities you desire. Joomla!’s code allows extensions to share resources and sometimes perform actions on each other. Since we can write extensions, we will do this instead of customizing the core.
There are three types of extensions Joomla! supports, each with a specific use.
Of the extensions available, components are the most essential. Components are essentially what you see in the “main” portion of the page. Joomla! is designed to load and run exactly one component for each page generated. Consequently, Joomla!’s core content management functionality is itself a component.
Components frequently have sophisticated back-end controls. The back end is commonly used to create and update records in database tables; also it can do typically anything, provided it is programmed in PHP. For instance, you may have a batch job that typically runs from a UNIX command line, but you can use the back end to provide a link where non-programmers can call it. You can also use it to allow site administrators to upload pictures or videos.
In contrast to components, any number of modules can appear on a page. Modules typically make up the elements of a sidebar or content menus. Modules complement the content contained in a component; they are not intended to be the main substance of a page. Joomla! also supports content modules, which involve no programming and can be displayed alongside coded components. The back-end controls for modules are limited, typically consisting of basic formatting.
When a piece of code is needed throughout the site, it is best implemented as a plug-in (formerly called a Mambot). Plug-ins are commonly used to format the output of a component or module when a page is built. Some examples of plug-ins include keyword highlighting, article comment boxes, and JavaScript-based HTML editors. Plug-ins can also be used to extend the results found in the core search component. The back-end controls are similar to those of modules.
This book will cover the following topics regarding developing extensions for Joomla!.
Joomla! has a standard set of toolbar buttons used throughout the back end. These keep a consistent appearance across components, so users quickly become familiar with the corresponding functions. When necessary, the labeling and functions of these buttons can be changed and new buttons can also be added.
Like the standard toolbars, Joomla! has a certain look for screens that list a set of records from the database. These lists usually have links to edit screens for the individual records and have toggles that change the publishing status of the record. Automatic pagination is also available for lists.
Several standard CSS class names are used to format content and HTML elements within your extensions. This makes it easy for your extensions to seamlessly blend in with the rest of the website. Additionally, Joomla! includes many functions to automate the generation of checkboxes, dropdowns, select lists, and other common elements.
A common database object is used in Joomla! so that only one connection is made during every page request. This object also provides a set of functions to make queries and retrieve results. These functions are database independent and are designed in such a way that you can install multiple copies of Joomla! into the same database when desired.
Besides a common database object, Joomla! has a standard database table class. Records can be created, read, updated, and deleted using the core functions. Logic can also be added so that child records in other tables are deleted when the parent is removed.
Since Joomla! is a web application deployed within public reach, it is necessary to protect it against security vulnerabilities. Joomla! employs a common method of making sure scripts are only called within the framework and not randomly executed.
Besides unintended script behavior, maliciously submitted data can be used by hackers to gain access to your database. Joomla! provides functionalities that prevent attacks of this kind.
A noteworthy feature of Joomla! is that navigation is separated from content. However, if a component is not built to take this into account, it is possible that website administrators will lose their template and module selections. To take advantage of the system, it is necessary to use the intended menu item ID number in generated links.
Also, it is possible to give administrators multiple options for linking to your component. This will allow the choice of different display options for the front end without the need to construct long, confusing URLs by hand. These options can additionally offer admins some simple configuration controls.
The same file is always called when a certain component is loaded, but different functions are called within. Joomla! uses standard variables to determine which function to execute on each request. There are also classes available to automate the flow based on these variables.
At a minimum, components are designed to separate the output from the database and other processing functions. Larger components will separate the logic flow using a controller, the data access methods using a model, and the output using views. These conventions make it easier to maintain the code and help the component perform in a reliable and predictable way.
Rather than creating a separate table to hold the configuration for an extension, Joomla! sets aside a place where short values can be held. These variables are defined through an XML file, which is installed with the extension. The XML file also provides default values and constraints for these parameters. Saving and retrieving of these values is automated; handwritten queries are not needed.
Once all of the code is complete, it is easily packaged for others to use. A listing of all the files involved is added to the XML file. Any queries needed for table creation are also included. All the files are then compressed in an archive. The extension is then ready to be installed on any Joomla!-based website.
We will build extensions to create, find, promote, and cross-link restaurant reviews. A component will handle common data points seen across all reviews such as price range, reservations, cuisine type, and location. Your visitors will be able to search and sort the reviews, add their own criteria to zero in on their dining options for the evening.
Some modules will highlight new reviews, drawing the attention of frequent visitors. Finally, one plug-in will pull pieces of the reviews into feature articles and another will integrate them into searches.
To prepare for this project, install a fresh copy of Joomla! 1.5 on a web server with PHP and a database (preferably MySQL). If you prefer to exclusively use one computer to complete this project and do not have a local web server, it will probably be easier to download and install a bundled and pre-configured package such as XAMPP (http://www.apachefriends.org). In this way you will be able to work with all the files on your local file system.