Archive for January, 2008

Migrating DOCman to Joomla! 1.5


Last week I was at the Dutch Joomla BootCamp, which was organised by our friends from Jira. Johan gave one of his famous unstoppable sessions about the Joomla framework and the MVC model. Jisse talked about templates, and brought along the very first copy of his new book on templates (a rather thorough one I must add, it goes beyond any book on templates I’ve seen — too bad it’s in Dutch only for now).

Finally, I gave a presentation about migrating a Joomla! 1.0 site to Joomla! 1.5, and took the opportunity to announce the migrator plugins for DOCman.

Com_migrator

Com_migrator is a component written by J! Core developer Sam Moffat. The latest version 1.0RC6 was released this week. You install it on your old J!1.0 site (or even Mambo!) and it will take a snapshot of your database. During the installation of J!1.5, you can upload the snapshot (an SQL file). The new site will now contain the contents of the old site. A great feature of com_migrator is the ability to load additional plugins for 3PD extensions, such as DOCman. These plugins expand the snapshot with the data from the extension.
With a little knowledge of phpMyAdmin, you can also use the migrator to copy data from a DOCman installation on a site to an existing J!1.5 installation.

You can download the DOCman migrator plugins at Joomlacode.org, where you can also find the com_migrator component. Extract the plugins’ zip file and read the included README.php file for detailed instructions. We’ve also opened a new forum category where you can discuss DOCman migration.

Good luck migrating!

Joomla! Coding Practices: Tables and Primary Keys

When you’re defining one or more tables to use in your component, it’s always a good idea to put some thought in how you’ll name them. First of all, we have of course the #__ prefix, which Joomla! replaces with the user defined prefix. The default is jos_, which stands for ‘Joomla! Open Source’, a leftover from the Mambo days.

Next, we want to prevent name collisions. Component names in Joomla! are unique, so using that for the first part of your table names will fix that: #__mycomponent_. Don’t use #__com_mycomponent_, that’s unnecessary luggage.

Let’s take a classic example: a component that manages a book collection, called com_library. The table name should reflect the contents of the table. This is always plural: you use a table to store multiple items.

Bad: #__library_book

Good: #__library_books

Even if your component uses only one table, you shouldn’t use #__mycomponent. You might need more tables later, eg #__library_authors and #__library_publishers.

Finally, you always need to define a primary key. Most people simply use id for this, or something like bId for the books table, aId for the authors etc. A better idea is to use the table name, in singular, followed by id.

#__library_books -> library_book_id

#__library_authors -> library_author_id

There are some very important advantages to this naming strategy. It’s easier for you or other people reading your code, what tables belong to what component, and what’s in them. Relations between tables are now very clear as well. #__library_books for example has two additional fields called libray_author_id and library_publisher_id, which of course link an author and a publisher to the book.

But more importantly, it’s easy to write code now that can detect those relations automatically. As your com_library becomes smarter, you could add data mapping functionality that can understand the relations between tables, without the need to hardcode them.

Finally, in most situations, you’ll want to use auto_increment for primary keys. As we’re all moving to PHP5.2 and along with that, hopefully MySQL 4.1 or 5, we can make use of new feature: the SERIAL keyword. SERIAL is just an alias BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE. This allows your primary keys to be as big as possible (and it’s easier to remember as well).

In Joomla!, we’re still stuck with backwards compatibility, but hopefully, these coding conventions will be picked up in a future version. Component developers can already start using them. The possibilities are endless.

Released today: Joomla! 1.5 Stable

Anyone who’s been around in the Joomlasphere for the last couple of days, could feel something was buzzing… And what better time for an announcement like this than right after the DocCamp weekend? So with no further ado, ladies and gentleman, may I present to you…

Joomla! 1.5

Joomla! 1.5 the greatest thing since someone said ‘Hey, what if we connect these two computers to each other?’

Joomla! was born on August 17, 2005, so it’s now 2.4 years old… in human years. Similar to dog years, it is generally accepted that for open source projects, the equivalent of one human year is 8.75 years.

2.4 x 8.75 = 21

So today is Joomla!’s 21st birthday! Our baby’s grown up and is now officially an adult!

For you, the user, this is just the beginning. You can now install Joomla! 1.5 on your sites or migrate your old sites. Developers who haven’t done so already, now have an extra incentive to make sure their components are compatible with 1.5, either using legacy mode or as native extensions. And everyone in the community is invited to write documentation, help spot leftover bugs, and spread the love.

Our plans for 1.5?

I’m working on further improving DOCman, so I’m going to deliver a final release candidate (RC2) soon, followed by DOCman 1.4 Stable.

First on the list however is a migrator plugin, that will help you to easily move your existing DOCman installation to Joomla! 1.5. I’m giving a talk about the migration process next Thursday, with some pointers on how to easily migrate all existing extensions, so make sure to drop by if you’re interested. Keep an eye on this blog, we’ll announce more events like these soon.

Secret project

We are also working on a very ‘secret project’. A J!1.5 extension of course, one that will multiply your website’s audience in the blink of an eye. Excited? So are we.

Now stop reading blogs and go play with Joomla!

Joomla! 1.5 – Generating raw ouput

Can anybody tell me how Joomla! 1.5 will be able to give just raw output so I can generate XML or JSON for my dynamic pages?

This is a common question for developers that are diving a bit deeper into Joomla! 1.5 and want to integrate AJAX functionality into their extensions. They quickly find that index.php always generates code within the XHTML-template and thats not what they need. Instead they want to generate XML for evaluating in JavaScript without any XHTML wrapped around it. Sounds familiar ? Well, here is how you can do this with Joomla! 1.5.

An introduction into JDocument

Before we dive into the actual solution we need to talk a bit about JDocument first. JDocument is a completely new framework API that allows developers to render different types of output. JDocument is a very flexible library that handles the loading and rendering of your templates and is made up out of formats and renderers.

Format

A format is the type of document that gets created, for 1.5 the supported formats are html (default), pdf, feed, error and raw.

Renderer

A renderer is responsible for creating the actual output. It can be triggered by a function call or by a placeholder. For example, the html format has renderers for a module, modules, component, head and message. These renderers are triggered by the placeholders in the template files. Like :


The above piece of code will load the all modules assigned to the footer position and wrap them in an xhtml module style.

The feed format on the other hand has renderers for atom1.0 and rss2.0. These renderers are called by specifying the type of renderer in the url of by passing the type to the JDocument constructor.

For example, the following URL will display the rss feeds for the FAQ’s category :

index.php?option=com_content&view=section&id=3&format=feed&type=rss

or with search engine friendly url’s on this becomes :

index.php/faq.feed?type=rss

The JDocument library is very flexible and powerfull. It would take a whole tutorial to explain how to leverage all the power, for now i’ll just stick to explaining how to use it to render only the component and how to render without any html output.

Rendering only the component

Old way Joomla! 1.0 : index2.php and index3.php where used to only output the component without any modules. These two files have been deprecated in Joomla! 1.5. There are only in the package to maintain backwards compatibility and should not be used anymore when developing new extensions.

New way Joomla! 1.5 : index.php?option=com_mycomponent&tmpl=component

How does this work ?

When you render only the component you are loading a special layout file that doesn’t has placeholders for any of the modules. This is exactly what happens here.

The ‘tmpl’ variable, refers to the name of the template file that is being loaded by JDocumentHTML. Instead of loading the ‘index.php’ template (the default layout) JDocumentHTML loads the component.html layout .(You can find the file in templates/_system/component.html.) If you examine this template file closely you will notice that it only renders the component.

Tips and tricks

you can override the _system layouts in your own templates, simply copy the file in your own template root directory and the system will use them instead of the default ones. This allows you to easily style the offline, error, … pages Joomla! 1.5 outputs.

Rendering only the raw component output

Old way Joomla! 1.0 : index.php?option=com_mycomponent&no_html=1

New way Joomla! 1.5 : index.php?option=com_mycomponent&format=raw

How does this work ?

What happens is you are now telling the system to use a different output format called ‘raw’ instead of ‘html’ the default one. The system will load the JDocumentRAW output format to render the document and will only output whatever the component creates.

Tips and tricks

You can use the ‘format’ specifier to make the system use the feed format. The feed format has a renderer for Atom1.0 and RSS2.0. All you need to do is give JDocument the necessary info to create the feed and he will do the rest, allowing you to easily switch between Atom and RSS output.

There is alot more that this baby can do, in a next blog post I’ll try to dive into some of the more advanced uses of JDocument. Have fun coding !

By the way: I’m blogging live from the Joomlatools Doccamp in Brussels!

Joomla! will reach turning point in March 2008.

At the end of 2007 Joomla! passed the 2.5 million download mark, which went by quite silently.

At the moment Joomla! is already on it’s way to the 3 million mark, which will likely be reached somewhere in february.

If you wanna track total downloads for the top 10 Joomla! extensions yourself you can easily do this by checking out the front page on Joomlacode.org. At the right side you will find a small overview of the top 10 projects, ranked by total downloads.

You will notice that our own DOCman is currently listed at 5th place with a total of 300.000 downloads.

Joomlacode has a very nice feature that allows you to create reports from different data sources. In my case I used it to get monthly download statistics for both Joomla! 1.0 and 1.5 in an effort to try and make a prediction about when Joomla! 1.5 will superseed 1.0. This resulted in the below graph.

Remarks :

  • There is no data available from before April 2007 because Joomlacode.org only opened it’s doors mid March 2007.
  • The data for January 2008 is extrapolated from the data available at the moment so it’s not a 100% but a good indication.
  • For October 2008 we are seeing a slightly higher amount of downloads for Joomla! 1.5, this is likely related to the release of Joomla! 1.5 RC3 beginning of that month.

Conclusions :

  • Joomla! 1.0 has been holding pretty steady at 200.000 downloads a month in 2007. Only from december we see a slight decline in downloads.
  • Joomla! 1.5 has slowly been increasing from 70.000 downloads in June towards 120.000 download a month in December.
  • Overall the introduction of 1.5 has increased the total amount of downloads each month from 200.000 for 1.0 only to 300.000 for both.

What does this tell us about the uptake of Joomla! 1.5 ? For that we need another graph that shows us the download percentage share for both :

Remarks :

  • The graph only shows the the percentage shares from the release of 1.5 RC1 and forward.
  • The graph shows a steady 5% increase of 1.5 downloads in regards to 1.0 from November 2007.

Based on this data I would dare to conclude that Joomla! 1.5 will superseed Joomla! 1.0 in March 2008. Exciting times ahead !

Happy New Year from Joomlatools

To our community members, clients, website visitors and friend : We wish all of you a happy new year in 2008!

2007 was an amazing year for us here at Joomlatools. Our thanks go out to everyone in the Joomlatools Community who has contributed in any way. We wanted to send out a special thanks to our most active Joomlatools Forum contributor and DOCman FAQ moderator : X-Ception. Thanks, you’ve made a big difference to so many DOCman users !

May free software and open standards bring joy and growth to all of you !

Our prediction for 2008 ? It is going to be a blast ! We have a few surprises cooking behind the scenes. More information is forthcoming to a newsfeed near you soon. You have been warned !