When I first wrote the Podcast Suite, the idea of podcasting was still pretty new. I started by taking com_syndicate and adding enclosures to the RSS feed generator, then added a backend to help people manage the files. My idea was to keep the code very simple: the first version of the suite didn't even have a database table to keep track of the episodes. Everything was (and still is) built to be a thin layer on top of articles.

As time went on, the needs of podcasters changed and the Suite changed with it. Apple got into the game and started taking podcast subscriptions through iTunes. iTunes in turn required several additional custom tags for the RSS. There was no way around this but to add a database table to the component for handling iTunes metadata.

Another needed change was revealed by they way people used the suite. Although the idea of a podcast is to subscribe so that your portable media player is automatically filled with new episodes, many asked "where's the player on my site?" The suite originally spit out "Download Now!" links to the files, but people wanted to play the episodes on the site. To handle this, I added a freely available Flash-based MP3 player. I also added an option for adding custom HTML so that any player could be used.

Finally, the Joomla! 1.5 release arrived. Even with legacy mode enabled, the Podcast Suite refused to install in 1.5. Although it may have been possible to tweak the existing version of the suite, the code was really due for a rewrite. One frequently requested feature was the ability to create feeds for multiple podcasts. I knew that the Model-View-Controller features in 1.5 would be perfect for this.

While I saw a lot of room for improving the code, my time to write it was short. Fortunately, I received help! Princeton University was interested in a new version of the suite for their UChannel site. They put me in contact with Dan Li, who volunteered his time this summer to help make Podcast Suite 1.5 a reality. Dan was totally new to Joomla!, but jumped straight in and got to work.

Having a fresh set of eyes improved the code and UI quality as well as the speed of developent. It helped to know that another programmer was waiting on my feedback and SVN commits. I was much more motivated to prioritize the Suite over other tasks. I knew that adding more code was helping Dan write more code, which would later motivate me to add yet more code, creating a very fruitful cycle! If you have always coded alone, you'll be amazed at the results when you start coding with someone else!

In addition to features we planned on adding, Joomla! 1.5 presented us with opportunities for more. The preference panel feature combined with Views saved a lot of time in creating multiple configurable feeds. During development, Nicolas Boseret volunteered to translate the component interface into French using the new language features. We also created some code that works with the com_migrator component for users upgrading from the Joomla! 1.0 version. Several of these techniques follow...

Preferences Panels

A very welcome addition to components for 1.5 involves the Parameters toolbar button. How do you get this button? Just add this code where you are building your toolbar:

JToolBarHelper::preferences('com_yourcomponent');

When this toolbar button is clicked, a window will appear on top of the admin screen with the parameters defined in config.xml, along with Save and Cancel buttons.

In older versions of Joomla!, you would have to manually load in the XML file, pass it into some object member functions, then build a screen where the parameters were finally rendered. Then you would have to build a function to handle the saving of parameters. Joomla! 1.5 eliminates all of this with one line of code! If your component has a lot of configuration options, seriously consider using this feature when building for 1.5. Elsewhere in your code, the parameters can be retrieved this way:

$params =& JComponentHelper::getParams('com_yourcomponent');

Then you can get the parameter values with $params->get('parameternameyouwant', 'default');.

 

Migrate Data

If you have users that will be upgrading from Joomla! 1.0 and are patiently awaiting the arrival of your 1.5 extension, reward them with a migration path. In most cases, the database tables associated with your component will be the most important thing to move over.

Sam Pasamio's com_migrator component for Joomla! 1.0 allows your users to migrate the data from their existing installation over to 1.5. It has a plugin system where you can add PHP code that translates the old data into the schema for your new component. Event though it's quite possible that you will be using the same table schema as before, you will still need to write the PHP plugin to handle this.

Fortunately, you can look at existing plugins in the /administrator/com_migrator/plugins folder for some examples. The one in bannerclient.php simply copies everything in the new table. This would be a good one to look at if you aren't changing the schema. The one for Podcast Suite removes a field and adds a new one, which is backfilled with file information for each epsiode.

Finally, you will also need to create a .sql file that will go in /administrator/com_migrator/tables. The migration process needs this because your data will be added to the database when the installation of 1.5 core is done. However, when you create the installation files for your main component package, be sure to use the IF NOT EXISTS clause in your CREATE TABLE statements. Users who migrate will still need to install your component on the 1.5 site finishing the migration, while new users will need to have the table created.

Note that there is no automatic installer for these files: they must be copied into /administrator/com_migrator/tables and /administrator/com_migrator/plugins manually. I simply distribute them together in a .zip and have a note near the download link stating that the files must be copied over manually.

Internationalization

With 1.5, internationalized interfaces are much easier to manage. Joomla! finally has the functionality for managing this built in. You do not have to determine which language the interface should be displaying; this is now done through Joomla! itself. If the preferred language is not available, it will default to English. You can internationalize strings in your interface by doing the following:

echo JText::_('EXTENSION_EXAMPLE');

Then translate the string in the language file. Default language files are located at /administrator/language/en-GB for the backend and /language/en-GB for the frontend.  The name of the file you will need to create will be en-GB.com_nameofyourcomponent, en-GB.mod_nameofyourmodule, or en-GB.plg_nameofyourplugin depending on the extension type. Your translation will look like this:
EXTENSION_EXAMPLE=extension example

For additional languages, first install the Joomla! core language pack. You will then find folders for the new language under /administrator/language and /language. Use the same file format for the other languages:

EXTENSION_EXAMPLE=extension example in another language

Also note that if you're using a phrase that is already translated in Joomla! core, this phrase can be reused in your component. Pass your text into JText::_() and it will handle this for you.

If JText::_() cannot find the text you pass in, it will simply output it. While this is a good default behavior, it can be difficult for verifying that you have all of the definitions in your language file. To do this, you need to turn on Language Debugging. To do this, go to the Global Configuration screen in the backend, click System, set Debug Language to Yes, then click Save. With Language Debugging enabled, you should see dots around text that is being passed through JText. In the cases where the text does not have a definition in your current language file, you will see question marks surrounding it instead. Check each language by changing the language for your user.

 

SVN

If you don't already have your project in an SVN repository, now is a good time to start. Using SVN not only makes it easy for you to track your own changes to the code, but helps immensely when multiple people are working on the extension. Although there is a slight learning curve, the benefits quickly outweigh the time and effort it takes to learn. Once you get comfortable with SVN, committing your code becomes addictive! It is also very satisfying to watch changes stream in from other coders as you merge it together.

Using SVN for module development is the most straightforward: create a folder for mod_nameofyourmodule in the trunk directory of your project, then check this folder out into the /modules directory of your Joomla! installation. As you add files to the mod_nameofyourmodule directory, be sure to also add them through your SVN client, then commit as you make changes to the files.

For components, the process is a bit different. Since there is a frontend in /components and a backend in /administrator/components, you will need to create two folders in your trunk directory: admin and site. When you check out these folders, you will need to check them out as com_nameofyourcomponent instead of 'admin' and 'site'. Check out the frontend into /components and the backend into /administrator/components.

Developing plugins with SVN is the trickiest. The problem is that plugins are handled through single PHP files, while SVN assumes control over an entire folder. To work around this, check out the folder to a location separate from your Joomla! installation, then manually copy the file over. While this unfortunately adds an extra step when you need to commit the code, you still get all of the other benefits of version control.

If you take a look at the SVN repository for Podcast Suite, you'll notice that I could have used some of this advice when I started using it for the project ;). If you click on trunk, you'll notice four folders. The component folder has 'admin' and 'front' (instead of 'site'). When you're building your installation package, it's convention to name the frontend folder code 'site'.

To follow along with the code Dan and I are writing, check out trunk/component/admin to administrator/components/com_podcast and trunk/component/front to components/com_podcast. Check out the module code from trunk/mod_podcast to the modules directory. Finally, check trunk/plugin to a folder outside of the Joomla! core, then copy the files and 'podcast' folder into /plugins/content. You will need to manually make entires into the jos_plugins, jos_components, and jos_modules tables.

Despite the power and organization of version control, SVN is not a panacea; you still need to have frequent communication with everyone you're coding with. The more you communicate, the better the code becomes. Duplicated effort is also lessened.