How to write a Joomla! 1.5 module.

May 20, 2008 · Filed Under PHP, joomla · 3 Comments 

A Joomla! module is a simple extension to Joomla!. Many modules are display only or have limited interaction with a user. For more complex extensions or interactions then Joomla! plugins or components are more appropriate. In this post I’ll describe the basics of module development as I understand them.

Written in PHP, at their simplest a module only requires two files, one containing configuration information and the other code. In the best tradition of programming I’ll use a “Hello World” example to demonstrate.

Under the root of your Joomla! installation you will see a directory called modules, unsurprisingly this is where modules are installed to. Each module requires a unique name and although it is not required to be adhered to , a naming convention is in place which notes the module name should begin with “mod_” to denote module, components begin with “com_” (in the component directory) but oddly plugins do not seem to have a naming convention.

I’ll call my module “mod_briaskHello”. Joomla! expects the configuration file to be named the same as the name as the module and the configuration file is XML so I’ll create a file called mod_briaskHello.xml. The configurtaion file can also be considered the installation file as it is this file that Joomla! reads when it is installing the module. The module will be installed into the “mod_briaskHello” directory under the main modules directory.

Although any text editor can be used to create the file, I tend to use Notepad++ . The contents of the file should be as follows:

<?xml version=”1.0″ encoding=”UTF-8″?>
<install type=”module” version=”1.5.0″ >
 <name>mod_briaskHello</name>
 <author>Briask</author>
 <creationDate>May 2008</creationDate>
 <copyright></copyright>
 <license>GNU GPL</license>
 <authorEmail>briask@briask.com</authorEmail>
 <authorUrl>http://www.briask.com</authorUrl>
 <version>1.0</version>
 <description>A HelloWorld example</description>
 <files>
  <filename module=”mod_briaskHello”>mod_briaskHello.php</filename>
 </files>
 <params>
  <param name=”moduleclass_sfx” type=”text” default=”" label=”Module Class Suffix” description=”PARAMMODULECLASSSUFFIX” />
 </params>
</install>

You will need to change the various elements to suit your own details, the following are purely descriptive elements and have no effect on the operation of the module name, author, creationDate, copyright, license, authorEmail, authorUrl, version, description.

The install element and associated attributes type and version detail the type of Joomla! extension (module, component, plugin) and the version of Joomla! that the module is compatible with 1.5.0 meaning J! 1.5 and above

The files element and its child filename elements detail the files that make up the module and will ensure that they are copied to the modules directory. The filename element attribute module indicates the module this file is associated with and the value of the element indicates the actual filename. In the example config file above the module is noted as being “mod_briaskHello” and the file to be installed is called mod_briaskHello.php.

The params element is used to detail the parameters associated with a module, can specify types of parameter, sizes etc. I’ll cover those in a post on more detailed module development. The parameter in the example listed is that for adding the “Module Class Suffix” to a module.

Next we need to create the mod_briaskHello.php file.  As a default template the file needs to contain

<?php
/*
* Any comments or copyright(left) or licensing details
*/
 defined(’_JEXEC’) or die (’Direct Access is not allowed’);
 ?>

The defined(’_JEXEC’) or die (”Direct Access is not allowed’); line should be included as the first line of code to be executed in all modules as it helps to ensure that the module will only be called by Joomla! and not bay any nasty hacker type code.

Now for the exciting part! Add the line ” echo JText::_(’Hello World!’);” after the “defined” statement. When executed that line will output Hello World . The _ method of JText hooks into the translation services that can be installed with J!.

Now that the code is written, it needs to be installed into Joomla! To this we need to create a ZIP file that the Joomla! extension manager can read and use to install the module. Use your favourite compression tool to create the zip file and ensure it is named the same as the module, in this case the file would be named mod_briaskHello.zip. Now just follow the usual steps in Joomla! for installing a module and you’ve written/installed your first Joomla! module. You should see that the module appears in the list of modules and that on the filesystem of your server a new subdirectory of the modules directory has been created for this new module.

Have fun!

 

 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • kick.ie
  • Pownce
  • Slashdot
  • StumbleUpon
  • Technorati
  • Blogosphere News
  • Bumpzee
  • NewsVine
  • Reddit

ImageSlideShow - Issue, publishing ISS module multiple times on Joomla 1.5

March 24, 2008 · Filed Under ImageSlideshow, JavaScript, PHP, joomla · 5 Comments 

Quite a number of people have asked if it is possible to publish mutiple copies of the ImageSlideshow on one Joomla 1.5 page. The answer is, unfortunately, no. Well, not just yet…

To be honest, when the first query came in I thought that it would be very quick and simple to code, but no! it is not.

The problem is, ISS needs to remember which image is being displayed, which image list to use, which image is next in rotation and how to smoothly transition between the two images on the Joomla page etc.

With only one ISS module published you can get away with relatively poor coding but when you start to allow the possbility of 2 or unlimited copies then keeping track of where you are in the sequence becomes more problematic and you can’t really resolve it with poor coding practice.

So this turns out to be a very good coding exercise and precisely what I needed to enable me to learn more about PHP, Javascript and Joomla 1.5 . The resolution is being worked on, I will resolve it and when it is ready it will be published it here and I will update the Joomla extensions site.

As for the other requests, I have finished coding the ability for links, titles, random display of images, resizing images and even the generation of image thumbnails but I am not going to publish that until I can include the resolution to the multiple copies issue.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • kick.ie
  • Pownce
  • Slashdot
  • StumbleUpon
  • Technorati
  • Blogosphere News
  • Bumpzee
  • NewsVine
  • Reddit

Joomla 1.5 Rotating Image SlideShow module

March 13, 2008 · Filed Under ImageSlideshow, JavaScript, PHP, joomla · 38 Comments 

Finally got my act together and got the Joomla 1.5 slideshow module up and running.

Will be writing up a tutorial on how to develop this type of module for Joomla 1.5. Follows the usual J! 1.5 install process and has parameter that can be changed to suit your need.

Works fine with IE 7 and FireFox 2. Don’t have IE6 to test with so if any problems are found please email me at briask@briask.com

Written in PHP and Javascript, it has proved to be a nice introduction to programming in those languages

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • kick.ie
  • Pownce
  • Slashdot
  • StumbleUpon
  • Technorati
  • Blogosphere News
  • Bumpzee
  • NewsVine
  • Reddit