Archived

Adapting a Joomla 1.5 extension to Joomla 2.5

From Joomla! Documentation

This page has been archived. This page contains information for an unsupported Joomla! version or is no longer relevant. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Quill icon.png
Content is Incomplete

This article or section is incomplete, which means it may be lacking information. You are welcome to assist in its completion by editing it as well. If this article or section has not been edited in several days, please consider helping complete the content.
This article was last edited by Chrishaan (talk| contribs) 12 years ago. (Purge)


This article is written to help developers upgrade their extensions from Joomla 1.5 to Joomla 1.6. If you have any further tips, feel free to add them onto this wiki article.

System setup[edit]

This document assumes that you are running the program eclipse for your development. This will allow you to automate most of the Joomla conversion process. For more instructions on how to setup eclipse, see Setting up your workstation for Joomla! development.

Background reading[edit]

What's new in Joomla 1.6#Developers describes most changes of Joomla 1.6 and how this affect developers. Please note that the API documentation on the joomla wiki is incomplete/inaccurate. Therefore the best way to look at the Joomla 1.6 API is to look directly at the joomla source code.

Updating your Joomla 1.5 language files to work on Joomla 1.6[edit]

Using the native php ini parser for language files has many benefits including much faster performace. Converting your exisiting Joomla 1.5 into the new format is very easy if you use a coding platform like eclipse. Search your file for *.ini in your project of choice. Then use the following search/replace values to automatically, replace exisiting quotes, add quotes to string values and update your comments.

Double quotes are NOT allowed inside the string value, except when using "_QQ_" to represent them. In case of js use, better use html entities or single quotes.

  1. Single quotes are allowed.
  2. Put a closing double quote at end of line if not empty or a comment. Find ^((?!#).+)\R replace with $1"\R
  3. Put an opening double quote at start of translated string if not empty or comment. Find ^((?!#).+?\=)(.+)\R replace with $1"$2\R
  4. Now replace the hash comments with the new semi colon. Find ^# and replace with ;
  5. Remove any illegal strings that can prevent files loading. Find ^(null|yes|no|true|false|on|off|none)=(.+)\R and replace with nothing.

IMPORTANT: never use the escape \" for double quotes. It may work on PHP 5.3 but will break in PHP 5.2.4+

Enabling Debug System in Global configuration will display the parsing errors per file and lines.

If you do not remove the illegal strings, then your language file will load until one of them is reached. The now "illegal" strings in the language file like NO, are handled by adding a 'J' in-front of them. Just make sure you change these language strings in your XML files as well. You can include in your language file:

;forbidden words
JNULL="Null"
JYES="Yes"
JNO="No"
JTRUE="True"
JFALSE="False"
JON="On"
JOFF="Off"
JNONE="None"

Legacy mode removed[edit]

More information needed....

Changes in the XML installer manifest file[edit]

Joomla 1.6 now uses a more streamlined format for the XML file containing installation instructions in ZIP extension package files. All extension types now use very similar formats, allowing each type to access the full power of the Joomla! installer. See Manifest files for details.

Load language in plugins[edit]

On the day of release, the way Language files are loaded for Joomla! 1.6 Plugins was changed. As a result, all Plugins must add the following code:

 public function __construct(& $subject, $config)
        {

                parent::__construct($subject, $config);

                $this->loadLanguage();

        }

change in BuildRoute logic[edit]

In Joomla! 1.6, the router BuildRoute logic for each Component was changed to require a Menu Item in order to build the link.

        // we need a menu item.  Either the one specified in the query, or the current active one if none specified
        if (empty($query['Itemid'])) {
                $menuItem = $menu->getActive();

        }

        else {

                $menuItem = $menu->getItem($query['Itemid']);

        }

There continue to be problems with the router. It is not uncommon to see a URL that bears the existing page URL as the "base" (if you will), followed by it's real URL. Look for these situations and report them on the tracker.

For those who have been around long enough, forcing the Menu Item on the URL was done in 1.0.12 and it turned out poorly.


Accessing component parameters in front-end[edit]

Accessing component parameters in frontend for specific menu item, we will use com_content as example : in 1.5 this was done with

    <?php
    $mycom_params =  JComponentHelper::getParams('com_content');

    echo $mycom_params->get('num_leading_articles');

    ?>


above code in joomla 1.6will output the DEFAULT com_content params , not affected with menu item so the new code for 1.6 would be

    <?php
    $app = JFactory::getApplication('site');

    mycom_params =  & $app->getParams('com_content');

    echo $mycom_params->get('num_leading_articles');

    ?>

Plugin parameters[edit]

In 1.5, you had to use the Plugin Helper to retrieve the Plugin object and then JParameter to retrieve the Parameter Object. Following those steps, you could work with a single parameter.

<?php

$plugin = & JPluginHelper::getPlugin('content', 'emailcloak');

$pluginParams = new JParameter($plugin->params);

$mode = $pluginParams->def('mode', 1);

?>

In 1.6,Joomla makes the parameter object automatically available to you.

<?php

$mode = $this->params->def('mode', 1);

?>

Changing Javascript function overrides[edit]

Joomla now has some of its Javascript functions prefixed with "Joomla". This means the functions are always unique and won't clash with other javascript functions on your server/webpage. However, you now need a different method to override the default Joomla Javascript. The Joomla 1.5 method was:

function submitbutton(pressbutton) {
var form = document.adminForm;
    if (pressbutton == 'applyconfig') {
        //do something unique
        form.action.value = 'apply'
        submitform('saveconfig');
        return;
    }

    submitform(pressbutton);
    return;
}

For Joomla 1.6 you need to copy your exisiting function but modify your top line to:

Joomla.submitbutton = function(pressbutton) {
var form = document.adminForm;
    if (pressbutton == 'applyconfig') {
        //do something unique
        form.action.value = 'apply'
        submitform('saveconfig');
        return;
    }

    submitform(pressbutton);
    return;
}

Changing removed functions[edit]

Some functions were removed for various reasons. You can find a list of them on What's new in Joomla_1.6#Removed_features.

Note that the ADODB compatibility methods included function like $db->Execute($query) which now need a separate $db->setQuery($query);$db->Query();


Renamed events[edit]

A large number of the Joomla 1.5 events have been renamed. Here is the list of renamed events.

  • onContentAfterSave
  • onContentAfterTitle
  • onContentAfterDisplay
  • onContentBeforeDisplay
  • onContentBeforeSave
  • onContentSearch
  • onContentSearchAreas
  • onUserAuthenticate
  • onUserAfterDelete
  • onUserAfterSave
  • onUserBeforeDelete
  • onUserBeforeSave
  • onUserLogin
  • onUserLogout
  • All content events (except for search and search areas) now pass a 'context' as the first argument to alert the plugin as to what type of content is being passed. The plugin event may or may not heed this context.

This means that if you use Joomla events you have two options:
1) rename the event and your extension can only be used on Joomla 1.6
2) create your own "legacy layer" and add the new event function name to your plugin. Here is an example of the user plugin:

    //joomla 1.6 compatibility code 
 	public function onUserLogin($user, $options){
 	    $result = $this->onLoginUser($user, $options);
 	    return $result;
 	}
	public function onUserLogout($user)	{
 	    $result = $this->onLogoutUser($user);
 	    return $result;
	}
	public function onUserAfterDelete($user, $succes, $msg)	{
 	    $result = $this->onAfterDeleteUser($user, $succes, $msg);
 	    return $result;
	}
	public function onUserBeforeSave($user, $isnew, $new){
 	    $result = $this->onBeforeStoreUser($user, $isnew, $new);
 	    return $result;	
	}
	public function onUserAfterSave($user, $isnew, $success, $msg){
 	    $result = $this->onAfterStoreUser($user, $isnew, $success, $msg);
 	    return $result;			
	}

Changing name="adminForm" to id="adminForm"[edit]

To create your own admin forms in joomla you now need to use id="adminForm". This is because the use of the "name" attribute is not valid HTML strict and has compatibility issues when used in XHTML served as XML. Although there is a built-in compatibility check to look for the old name="adminForm" attribute, it is best to add the new id attribute. Depending on the features you want to use you may need to include both, name="adminForm" and id="adminForm" because not all core functionality has been updated to use id's. An example of the new form code is:

<form method="post" action="index.php" name="adminForm" id="adminForm"></form>

Removing references to index2.php and index3.php[edit]

Joomla 1.0 had different index files to serve admin content in different manners. Joomla 1.6 has now got better way to handle this and you need to search your codebase for "index2.php" and "index3.php" to ensure you don't have any Joomla 1.0 style links. If you need to display your component without any of the other Joomla 1.6 admin content (menus, etc) then add the following to the url: "&tmpl=component"

Upgrading core table and field name usage[edit]

Many of the core Joomla tables have been simplified, combined or renamed. This was needed to get rid of some limitation dating back to Joomla 1.0. This means however that if you have code that directly manipulates Joomla tables, that you need to add a function that detects Joomla 1.6 and had different SQL queries based on the joomla version. Plase note that both tables and field names have been renamed or removed. An example is the following function that can find if a plugin is published on both Joomla 1.5 and 1.6:

		
function getPluginStatus($element, $folder) {
    //get joomla specs
    $db = & JFactory::getDBO();		
    $version = new JVersion;
    $joomla = $version->getShortVersion();
    if(substr($joomla,0,3) == '1.6'){
        //Joomla 1.6 code
        $query = 'SELECT enabled FROM #__extensions WHERE element=' . $db->Quote($element) . ' AND folder=' . $db->Quote($folder);
    } else {
        //Joomla 1.0/1.5 code
        $query = 'SELECT published FROM #__plugins WHERE element=' . $db->Quote($element) . ' AND folder=' .   $db->Quote($folder); 
    }
    $db->setQuery($query);
    $result = $db->loadResult();
    return $result;
}

New mootools version[edit]

Most important is that the Ajax class has been deprecated and replaced by the Request class. That means that if you use ajax calls you need to have a version switcher (below a sample code)


$version = new JVersion;
$joomla = $version->getShortVersion();

..... (your code) ....

    /* our ajax istance for starting the sync */
    <?php  if(substr($joomla,0,3) == '1.6'){
 echo 'var ajax = new Request.HTML({
           url: url,';
    } else {
 echo 'var ajax = new Ajax(url, {';
    }?>

.... your code .....

    <?php  if(substr($joomla,0,3) == '1.6'){
     echo 'var ajaxsync = new Request.HTML({
        url: url, ';
    } else {
echo 'var ajaxsync = new Ajax(url, {';
    }?>

.... your code .....

Also another common usage of mootools in Joomla is the popup box. The Joomla 1.5 javascript code to close this box is:

document.getElementById('sbox-window').close();

in Joomla 1.6 you need to use:

window.parent.SqueezeBox.close();

Converting your JParameters to JForms[edit]

Joomla 1.6 now uses the JForms class to handle parameters and it has also changed the way parameters are defined in your XML files. To make menu/component/module/plugin parameters work, first you need to update the XML file. Here is an automated way to handle the bulk of the conversion. (added "" to the examples below so you can see spaces in the search query as well). Use eclipse to search and replace parameters in *.xml files

replace "<params>" with "<config><fields name="params"><fieldset name="basic" label="basic">"
replace "<params*?>" with "<config><fields name="params"><fieldset name="basic">"
replace "</params>" with "</fieldset></fields></config>"
replace "<param " with "<field "
replace "</param>" with </field>"
replace "<install " with "<extension "
replace "</install>" with "</extension>"

Change the "extension" node to add the following attributes:

  • Keep the existing "type" attribute
  • version="1.6.0"
  • client="site"
  • method="upgrade"

Example for a module:

<extension type="module" version="1.6.0" client="site" method="upgrade">

Now if you want to use your joomla extension on both Joomla 1.5 and 1.6 you will need to go to your "team synchronising" view in eclipse. Double click on your changed xml file, which will open the compare editor. Then simply copy-paste back your old Joomla 1.5 params into your new Joomla 1.6 xml file and save.

If you have custom parameter types, you will need to do some additional work. In Joomla 1.5 you would use the following code:

<params addpath="/administrator/components/com_yourname/elements">

In joomla 1.6 JParameter classes won't work and you will need to convert your jparameter fields into JForm fields. Create a new directory and copy your "old elements" into them. Then you need to load these new fields with the individual parameter

<field name="sample" type="sampleField" size="5" default="" label="sampleField"
       description="sampleField" addfieldpath="/administrator/components/com_yourname/fields"/>

Use eclipse to search and replace files in your newly created fields directory. replace "JElement" with "JFormField"
replace "var $_name =" with "public $type ="
replace "function fetchElement($name, $value, &$node, $control_name)" with "protected function getInput()"

Then you still need to replace the references to $control_name and others in your new JForm field, but at least the bulk of the work has been done automatically

Using label tag is needed if you name your fieldset anything other than basic and advanced. Basic and advanced are in com_modules language file and will be translated, but if you use "other" which was in 1.5 or your own name (the number of fieldsets and therefore panes is no longer fixed) then the pane will output COM_MODULES_your fieledset name_FIELDSET_LABEL If you use label="your fieldset name" then it will show the correct label in your pane.

renamed core component names and login form parameters[edit]

A login module for Joomla 1.5 will not work without modifications on Joomla 1.6. Here is a part of the logout module that will work on both Joomla 1.5 and Joomla 1.6. You can compare the two to see the difference in input names.

        $version = new JVersion;
        $joomla = $version->getShortVersion();
        if(substr($joomla,0,3) == '1.5'){
            //joomla 1.5 format          
            $output .= '<input type="hidden" name="task" value="logout" />';
            $output .= '<input type="hidden" name="option" value="com_user" />';
        } else {    
            //joomla 1.6/1.7/2.5 format
            $output .= '<input type="hidden" name="task" value="user.logout" />';
            $output .= '<input type="hidden" name="option" value="com_users" />';            
        }

here is the code for the login module


        $version = new JVersion;
        $joomla = $version->getShortVersion();
        if(substr($joomla,0,3) == '1.5'){        
            //joomla 1.5 format     
            $output .= '<input type="hidden" name="task" value="login" />';
            $output .= '<input type="hidden" name="option" value="com_user" />';
            $output .= '<input id="modlgn_passwd" type="password" name="passwd" class="inputbox" size="18" alt="password" /> ';
        } else {
            //joomla 1.6/1.7/2.5 format
            $output .= '<input type="hidden" name="task" value="user.login" />';
            $output .= '<input type="hidden" name="option" value="com_users" />';     
            $output .= '<input id="modlgn_passwd" type="password" name="password" class="inputbox" size="18" alt="password" /> ';               	
        }

These changes might also apply to front-end forms of other Joomla core components (more information needed)


ACL changes[edit]

Joomla 1.6 now has an advanced ACL system. It is unknown how this affects people that have previously used the ACL API in their extension.

In order to allow your component's Options page to display the ACL settings editor, you need to create a file named access.xml in your component's administrator directory, e.g. administrator/components/com_example/access.xml. The syntax of the file is fairly easy to understand:

<?xml version="1.0" encoding="utf-8"?>
<access component="com_example">
	<section name="component">
		<!-- Joomla! core privileges -->
		<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />
		<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" />
		<!-- Custom privileges -->
		<action name="example.something" title="COM_EXAMPLE_ACL_SOMETHING_TITLE" description="COM_EXAMPLE_ACL_SOMETHING_DESC" />
	</section>
</access>

Important things to notice:

  • The root tag is called access and you must specify the component="com_yourComponentName" attribute
  • The section tag is mandatory
  • No ACL privilege will display on the list unless you explicitly add it. This means that you do have to add the core privileges that concern your component
  • You can create custom privileges! You don't have to register them anywhere except your access.xml file. The name format is liberal, but no two components should use the same key for a different purpose (all components' privileges share the same namespace). As a rule of thumb use the convention componentName.privilegeName. You must NEVER use core.* names as they are reserved by Joomla!.

In order to apply ACLs, you have to override your controller's constructor:

	public function __construct($config = array())
	{
		parent::__construct($config);
		// This conditional lets the ACL check run only on Joomla! 1.6+
		if( version_compare( JVERSION, '1.6.0', 'ge' ) ) {
			$user = JFactory::getUser();
			if (!$user->authorise('example.something', 'com_example')) {
				return JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
			}
		}
		// Place anything else you need in the constructor below this line
	}

The heavy lifting is done by the authorise() method of the JUser class. The first parameter is the privilege name, the second one is the "section", i.e. your component's name. As you can see, this allows for great flexibility. You can check any privilege, for any component, for any user, from anywhere in your code.

Plugin files now in different locations[edit]

Joomla 1.6 now creates a different hierarchy structure for plugins. Files are no longer placed where they used to be, so if your other parts of your application (comp, mods, etc.) expects them to be in a certain position, it won't work. The change has been that now plugins are in an additional subdirectory. If you only load your plugins via the 1.5 API you should be fine.

  • Joomla 1.5 example location
JPATH_SITE . DS . 'plugins' . DS . 'authentication' . DS . 'example.php';
  • Joomla 1.6 example location
JPATH_SITE . DS . 'plugins' . DS . 'authentication' . DS . 'example'. DS . 'example.php';

Changes to view parameters[edit]

J!1.6 has a strict new way of specifying parameters for views. J!1.5 allowed a bit of freedom where the parameters could be defined at the view.html.php level but now ithas to be at the tmpl level. AE believes the view paramters were removed.


Installation process - preflight, postflight, etc[edit]

These are new events that can screw up an existing installlation process. -1 on me for not documenting the process while stepping through xdebug. They should be totally optional access points to the installation process. But if your 1.5 install process is tricky for some reason, then these can be used to do clean up activities.


Admin template changes[edit]

Admin functions that depended on certain functions, naming conventions etc no longer work. Khepri has been removed. Other admin functions/libraries may have changed.

sys.ini language translation file[edit]

This file has 3 purposes:

1. It is used for installation process translations, when a folder language is included in the pack.

pack/language/en-gb/en-gb.extension.ini

pack/language/en-gb/en-gb.extension.sys.ini

In this case, the <description>COM_MYCOMPONENT_XML_DESCRIPTION</description> used in the sys.ini will display on installing/updating the extension.

When editing the extension in administration, it will be the .ini version of COM_MYCOMPONENT_XML_DESCRIPTION which will display.


2. It is used to replace the former .menu.ini


3. It is used to display the translated extension name in many managers.

removed include folders[edit]

Most of the 3rd party libraries (Archive, domit, js, PEAR, etc) in the include folder have been removed in J!1.6.


Use paths defined in defines.php.[edit]

(Note they are different for the site and the administration)


global $option is gone[edit]

The statement 'global $option' that often appears in Joomla 1.5 extension code is no longer supported.

To update the code, you may

  • Replace 'global $option' with
   $option = JRequest::getCmd('option')

If your code is in a controller class derived from JControllerForm, you may prefer:

  • Delete any lines with 'global $option'
  • Replace all occurrences of '$option' with '$this->option'

See: