Actions

J1.5

Difference between revisions of "Adapting a Joomla 1.0 extension to Joomla 1.5"

From Joomla! Documentation

m
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Development]]
+
{{RightTOC}}
====== Adapting Joomla 1.0 extensions to Joomla 1.5 ======
+
 
//This is a first draft... Please complete or comment so we can complete it...//
+
''This is a first draft... Please complete or comment so we can complete it...''
 +
 
 
Although Joomla 1.5 has been designed with Joomla 1.0 backwards compatibility in mind, there are a very few items which are not backwards compatible, and require minimal adaptations.
 
Although Joomla 1.5 has been designed with Joomla 1.0 backwards compatibility in mind, there are a very few items which are not backwards compatible, and require minimal adaptations.
 
This document sumarizes the changes which need to be made to Joomla 1.0 extensions to make them run in Joomla 1.5.
 
This document sumarizes the changes which need to be made to Joomla 1.0 extensions to make them run in Joomla 1.5.
===== Components =====
 
==== Global scope ====
 
For security enhancement reasons and better encapsulation reasons, the components are not anymore just included from the main index.php, but called from a function. Thus their variables scope is not the global scope anymore.
 
This means that variables created in the main part of a component, which are not declared as "global" before creation belong to the component's main execution, and are not accessible as global from the components functions.
 
The adaptation is trivial: just add one line in the begin of the component: "global ...." enumerating the global variables of the component.
 
  
==== Request/Post parameters ====
+
== General ==
 +
 
 +
=== Denying direct access ===
 +
The Joomla 1.0 way to deny access for a direct external call is:
 +
 
 +
<source lang="php">
 +
defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');
 +
</source>
 +
 
 +
which has been changed into:
 +
 
 +
<source lang="php">
 +
defined( '_JEXEC' ) or die( 'Restricted access' );
 +
</source>
 +
 
 +
=== Request/POST parameters ===
 +
 
 
By default URL parameters are not translated anymore into globals of same name, but should be accessed the standard way.
 
By default URL parameters are not translated anymore into globals of same name, but should be accessed the standard way.
Here too, the change is trivial: instead of looking directly at for instance at $form, do first a:
+
Here too, the change is trivial: instead of looking directly for the variable <code>$reportform</code>, first retrieve it using [[API15:JRequest|JRequest]]. The Joomla 1.0 way of doing this is:
 
<source lang="php">
 
<source lang="php">
 
  $form = mosGetParam( $_REQUEST, 'reportform');
 
  $form = mosGetParam( $_REQUEST, 'reportform');
 
</source>
 
</source>
 +
 +
The only official way is now:
 +
 
<source lang="php">
 
<source lang="php">
 
  $form = JRequest::getVar('reportform');
 
  $form = JRequest::getVar('reportform');
 
</source>
 
</source>
 +
 
This will prevent SQL injection attacks by the way, as both mosGetParam and JRequest escape the variables for malicious SQL code.
 
This will prevent SQL injection attacks by the way, as both mosGetParam and JRequest escape the variables for malicious SQL code.
  
==== Start of changes in ACL ====
+
=== Start of changes in ACL ===
 +
 
 
The tables structure of the used phpGACL has changed slightly, due to an update to latest phpGACL.
 
The tables structure of the used phpGACL has changed slightly, due to an update to latest phpGACL.
The $acl->.... methods remain backwards compatible, so components which do not access ACL tables wildly are ok. Please report incompatibilities, so they can be fixed in the core.
+
The <code>$acl->....</code> methods remain backwards compatible, so extensions which do not access ACL tables wildly are ok. Please report incompatibilities, so they can be fixed in the core.
===== Modules =====
+
 
Modules share most of the Components changes above. In addition:
+
== Components ==
==== Modules path ====
+
 
 +
=== Global scope ===
 +
 
 +
For security enhancement reasons and better encapsulation reasons, the components are not anymore just included from the main index.php, but called from a function. Thus their variables scope is not the global scope anymore.
 +
This means that variables created in the main part of a component, which are not declared as <code>global</code> before creation belong to the component's main execution, and are not accessible as global from the components functions.
 +
The adaptation is trivial: just add one line in the begin of the component: <code>global ....</code> enumerating the global variables of the component.
 +
 
 +
== Modules ==
 +
 
 +
=== Modules path ===
 +
 
 
Each module is installed in its own sub-directory, like components, meaning if they have images or other files, the path changes.
 
Each module is installed in its own sub-directory, like components, meaning if they have images or other files, the path changes.
===== Joomla Plugins (previously Mambots) =====
 
  
==== Change of name ====
+
== Joomla Plugins (previously Mambots) ==
 +
 
 +
=== Change of name ===
 +
 
 
The mambots have been renamed to joomla plugins, as well as the directory, so same remark applies there.
 
The mambots have been renamed to joomla plugins, as well as the directory, so same remark applies there.
\\
 
This remark applies on content plugins vs content mambots\\
 
\\
 
**Remark #1**\\
 
Accordingly with general Joomla changes the old way for deny access for external direct call :\\
 
\\
 
\\
 
<source lang="php">
 
defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');
 
</source>
 
\\
 
<source lang="php">
 
defined( '_JEXEC' ) or die( 'Restricted access' );
 
</source>
 
\\
 
**Remark #2**\\
 
Registering the event\\
 
  
\\
+
=== Event registration ===
<source lang="php">$_MAMBOTS->registerFunction( 'onPrepareContent', 'botMybot' );</source>\\
+
+
  
\\
+
The Joomla 1.0 way of registering a function for an event is:
<source lang="php">$mainframe->registerEvent( 'onPrepareContent', 'botMybot' );</source>\\
+
  
\\
+
<source lang="php">$_MAMBOTS->registerFunction( 'onPrepareContent', 'botMybot' );</source>
  
 +
which has been changed into
 +
 +
<source lang="php">$mainframe->registerEvent( 'onPrepareContent', 'botMybot' );</source>
  
**Remark #3**\\
+
=== Helper class ===
A new core class was developed for helping us to manage plugins, this  class is JPluginHelper.\\
+
  
It can be used (for example) to know if a plugin was published or not \\
+
A new core class was developed for helping us to manage plugins, this class is [[API15:JPluginHelper|JPluginHelper]].
  
<source lang="php">$plugin =& JPluginHelper::getPlugin('content', 'mybot');
+
It can be used (for example) to know if a plugin is published or not.
 +
 
 +
<source lang="php">
 +
$plugin =& JPluginHelper::getPlugin('content', 'mybot');
 
if (!$plugin->published){  
 
if (!$plugin->published){  
//plugin not published  
+
  //plugin not published  
 
}else  {  
 
}else  {  
 
   //plugin published  
 
   //plugin published  
}</source> \\
+
}
 +
</source>
  
\\
+
=== Parameter management class ===
**Remark #4**\\
+
A new core class was developed for helping us to manage plugins ,this  class is JParameter.\\
+
  
It can be used to know plugins paramaters here is an example:\\
+
The new core class [[API15:JParameter|JParameter]] was developed for helping us to manage plugins. It can be used to retrieve plugin paramaters, for example:
\\
+
 
<source lang="php">$pluginParams = new JParameter( $plugin->params );</source>
 
<source lang="php">$pluginParams = new JParameter( $plugin->params );</source>
\\
 
Please note that we pass at the constructor the data of instace prevoiusly declared at remark #3 and the we can manage the plugins paramater, for example we assume  that the Mybot Plugin have 3 parameter : P1,P2,P3 so retriving paramater values is easy ,
 
<source lang="php">$pluginParams->def( 'P1', 0 );</source>
 
  
==== Other changes ====
+
Please note that we pass to the constructor the <code>params</code> member of the plugin instance created using the [[API15:JPluginHelper|JPluginHelper]] (see above).
__There is another section covering the joomla plugins... link?__
+
  
Here is one:
+
Retrieving parameters is now as simple as:
[[http://forum.joomla.org/index.php/topic,36810.0.html|Fitting Community builder in 1.5 legacy mode, while preserving compatibility to Joomla 1.0 and Mambo 4.5.x]]
+
  
 +
<source lang="php">$pluginParams->get( 'P1', 0 );</source>
  
[[:start|Back to the Startpage]]
+
''JParameter can also be used for components and modules, see the documentation at [[API15:JParameter|JParameter]].''
 +
 
 +
== Other changes ==
 +
 
 +
''There is another section covering the joomla plugins... link?''
 +
 
 +
Here is one:
 +
[[jtopic:36810|Fitting Community builder in 1.5 legacy mode, while preserving compatibility to Joomla 1.0 and Mambo 4.5.x]]
 +
 
 +
[[Category:Development]]
 +
[[Category:Tutorials]]

Revision as of 08:42, 12 July 2011

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

This is a first draft... Please complete or comment so we can complete it...

Although Joomla 1.5 has been designed with Joomla 1.0 backwards compatibility in mind, there are a very few items which are not backwards compatible, and require minimal adaptations. This document sumarizes the changes which need to be made to Joomla 1.0 extensions to make them run in Joomla 1.5.

General

Denying direct access

The Joomla 1.0 way to deny access for a direct external call is:

defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');

which has been changed into:

defined( '_JEXEC' ) or die( 'Restricted access' );

Request/POST parameters

By default URL parameters are not translated anymore into globals of same name, but should be accessed the standard way. Here too, the change is trivial: instead of looking directly for the variable $reportform, first retrieve it using JRequest. The Joomla 1.0 way of doing this is:

 $form = mosGetParam( $_REQUEST, 'reportform');

The only official way is now:

 $form = JRequest::getVar('reportform');

This will prevent SQL injection attacks by the way, as both mosGetParam and JRequest escape the variables for malicious SQL code.

Start of changes in ACL

The tables structure of the used phpGACL has changed slightly, due to an update to latest phpGACL. The $acl->.... methods remain backwards compatible, so extensions which do not access ACL tables wildly are ok. Please report incompatibilities, so they can be fixed in the core.

Components

Global scope

For security enhancement reasons and better encapsulation reasons, the components are not anymore just included from the main index.php, but called from a function. Thus their variables scope is not the global scope anymore. This means that variables created in the main part of a component, which are not declared as global before creation belong to the component's main execution, and are not accessible as global from the components functions. The adaptation is trivial: just add one line in the begin of the component: global .... enumerating the global variables of the component.

Modules

Modules path

Each module is installed in its own sub-directory, like components, meaning if they have images or other files, the path changes.

Joomla Plugins (previously Mambots)

Change of name

The mambots have been renamed to joomla plugins, as well as the directory, so same remark applies there.

Event registration

The Joomla 1.0 way of registering a function for an event is:

$_MAMBOTS->registerFunction( 'onPrepareContent', 'botMybot' );

which has been changed into

$mainframe->registerEvent( 'onPrepareContent', 'botMybot' );

Helper class

A new core class was developed for helping us to manage plugins, this class is JPluginHelper.

It can be used (for example) to know if a plugin is published or not.

$plugin =& JPluginHelper::getPlugin('content', 'mybot');
if (!$plugin->published){ 
  //plugin not published 
}else  { 
  //plugin published 
}

Parameter management class

The new core class JParameter was developed for helping us to manage plugins. It can be used to retrieve plugin paramaters, for example:

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

Please note that we pass to the constructor the params member of the plugin instance created using the JPluginHelper (see above).

Retrieving parameters is now as simple as:

$pluginParams->get( 'P1', 0 );

JParameter can also be used for components and modules, see the documentation at JParameter.

Other changes

There is another section covering the joomla plugins... link?

Here is one: Fitting Community builder in 1.5 legacy mode, while preserving compatibility to Joomla 1.0 and Mambo 4.5.x