If you want to convert a common Joomla 1.5 or Joomla 2.5 plugin into a Joomla 3.x compatible plugin you will have to make some changes to plugin’s XML and PHP code.
Let’s start with the XML file:
1. The <install> tag is no longer supported, you will have to replace it with <extension> tag.
replace:
<install version="x.x" type="plugin" group="content" method="upgrade"> ..... </install>
with:
<extension version="x.x" type="plugin" group="content" method="upgrade"> ..... </extension>
Let’s continue with the PHP files:
2. Because the DS delimiter was removed, if you use it you will need to replace it with DIRECTORY_SEPARATOR
replace:
.DS.
with:
.DIRECTORY_SEPARATOR.
3. If your plugin uses parameters, you will have use JForm instead of JParameter. From Joomla 1.6 the parameters object is automatically available to you and you won’t need to use Plugin Helper to retrieve the plugin object and then JParameter to retrieve the parameters object.
The simplest approach is to remove this line from plugin’s PHP file:
jimport( 'joomla.html.parameter' );
replace this code:
parent::__construct($subject, $params); $this->plugin = &JPluginHelper::getPlugin('content', 'PLUGIN_NAME'); $this->params = new JParameter($this->plugin->params);
with this:
parent::__construct($subject, $params); $mode = $this->params->def('mode', 1);
By doing this, you will be able to access a parameter in the parameters object like this:
$this->params->get('PARAMETER_NAME')
4. Because Joomla 3.x tends to throw exceptions instead of JError, JException or FALSE, you will have to use a “try-catch” approach. In the example below, if there is no #__ga_dash table, the function will return FALSE in Joomla 1.5 or Joomla 2.5. In Joomla 3.0 this function throws an exception, so i had to replace.
replace:
function get_token (){ $db = JFactory::getDBO(); $query = "SELECT token FROM #__ga_dash"; $db->setQuery($query); $result = $db->loadResult(); return $result; }
with:
function get_token (){ $db = JFactory::getDBO(); try { $query = "SELECT token FROM #__ga_dash"; $db->setQuery($query); $result = $db->loadResult(); } catch(exception $e) { return; } return $result; }
These are the main modifications made to convert my Joomla 1.5 and Joomla 2.5 plugins into Joomla 3.0 plugins, hope it helps.