Book Image

Learning Joomla! 1.5 Extension Development: Creating Modules, Components, and Plugins with PHP

By : Joseph L. LeBlanc
Book Image

Learning Joomla! 1.5 Extension Development: Creating Modules, Components, and Plugins with PHP

By: Joseph L. LeBlanc

Overview of this book

<p>Joomla! is the world's hottest open-source content management system, and the winner of the 2006 Open Source CMS Prize.<br /><br />While Joomla! is packed with features, its greatest quality is that it is extremely extensible, allowing any number of complex applications to be cleanly integrated. Shopping carts, forums, social networking profiles, job boards, and real estate listings are all examples of extensions developers have written for Joomla!. All of these can run off one Joomla! site, while only one 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!<br /><br />If you're eager to start creating extensions for Joomla!, this book is for you. Walk through the development of complete Joomla! components and modules with this tutorial for PHP programmers. Written for Joomla! version 1.5 and tested against pre-final releases, this book will get you started coding your first extensions as quickly as possible, and adds the features that will make your work look professional!<br /><br />The book builds example extensions to create, find, promote, and cross-link restaurant reviews. A component will handle common data items seen across all reviews such as price range, reservations, cuisine type, and location. Your visitors will be able to search and sort through the reviews; adding their own criteria to zero in on their dining options for the evening. <br /><br />Your modules will highlight new reviews, drawing the attention of frequent visitors. Finally, plugins will pull pieces of the reviews into feature articles and others will integrate them into searches. Even if you don't own a restaurant, you will still find the code applicable to your own development projects, and the skills you develop will make you a Joomla! developer to be reckoned with!</p>
Table of Contents (14 chapters)
Copyright
Credits
About the Author
About the Reviewer
Preface

Preface

Joomla! is an award-winning content management system with a powerful extension system. This makes it easy for third-party developers to build code extending Joomla’s core functionality without hacking or modifying the core code.

Once an extension is developed, it can be packaged into a ZIP file for site administrators to upload and use. The people who manage Joomla!-based websites and want to use extensions need not know any programming at all. Once the ZIP file is uploaded, the extension is installed.

The name Joomla! comes from the Swahili word ‘jumla’, meaning “all together” or “as a whole”. When you install an extension in Joomla!, it blends in with the rest of the site; all the extensions truly appear “all together, as a whole”.

What This Book Covers

Chapter 1 gives an overview of how Joomla! works. The example project used throughout the book is also introduced. The three types of extensions (components, modules, and plug-ins) are covered along with descriptions of how they work together.

Chapter 2 begins the development of the component used in the project. Initial entries are made in the database and toolbars for the back end are built. The general file structure of Joomla! is also introduced.

Chapter 3 walks through the creation of the back-end interface for creating, editing, and deleting records in the project. Database table classes are introduced, as well as common HTML elements used to make the project blend in with other Joomla! extensions.

Chapter 4 builds a front-end interface for listing and viewing records. Additionally, code to generate and interpret search-engine-friendly links is covered. The project is also expanded slightly when a commenting feature is added.

Chapter 5 introduces a module used to list records on every page of the site. The module takes advantage of layouts, where the same data can be formatted differently depending on how the code is called. Some of the code is also separated out into a helper class so that the main code generating the module stays simple.

Chapter 6 rewrites the component developed in Chapters 2, 3, and 4 so that it follows the Model, View, Controller design pattern. Controls over the publishing of records are introduced, in addition to an interface for removing offensive comments. More toolbars are added and the search-engine-friendly URL code is redesigned.

Chapter 7 develops three plug-ins. The first plug-in finds the names of records in the database and turns them in to links to those records. A second plug-in displays a short summary of the record when certain code is added to content articles. Finally, another plug-in is designed so that records are pulled up along with Joomla! content searches.

Chapter 8 adds configuration parameters to the component, module, and plug-ins. These are handled through XML and generate a predictable interface in the back end for setting options. Retrieving the values of these parameters is standardized through built-in functions.

Chapter 9 expands the XML files used for parameters and adds a listing of all the files in each extension. Once this file is compressed along with the rest of the code into a ZIP archive, it is ready to be installed on another copy of Joomla! without any programmer intervention. Custom installation scripts and SQL code are also added to the component.

Note

Code testing was performed using Joomla 1.5 beta 2.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

There are three styles for code. Code words in text are shown as follows: “We can include other contexts through the use of the include directive.”

A block of code will be set as follows:

function showReviews( $option )
{
  $query = "SELECT * FROM #__reviews";
  $db->setQuery( $query );
  $rows = $db->loadObjectList();
  if ($db->getErrorNum()) {
      echo $db->stderr();
      return false;
  }
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be made bold:

switch($task)
{
  case 'add':
  editReview( $option );
    break;
  case 'save':
  saveReview( $option );
    break;
}

Any command-line input and output is written as follows:

INSERT INTO jos_components (name, link, admin_menu_link,
            admin_menu_alt, `option`, admin_menu_img, params)

New terms and important words are introduced in a bold-type font. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: “clicking the Next button moves you to the next screen”.

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader Feedback

Feedback from our readers is always welcome. Let us know what you think about this book, what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to , making sure to mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer Support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the Example Code for the Book

Visit http://www.packtpub.com/support, and select this book from the list of titles to download any example code or extra resources for this book. The files available for download will then be displayed.

Note

The downloadable files contain instructions on how to use them.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing this you can save other readers from frustration, and help to improve subsequent versions of this book. If you find any errata, report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the Submit Errata link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to the list of existing errata. The existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Questions

You can contact us at if you are having a problem with some aspect of the book, and we will do our best to address it.