The Techjoomla Blog

Stay updated with all the latest happenings at Techjoomla. From news about the developments in your favourite extensions to Tips & Tricks about the Joomla CMS, Framework & Development.

Joomla 3.0 conversion changes needed when converting a common installable package for “joomla 1.5.x & 2.5.x” to “joomla 3.0

joomla3.0, Techjoomla.comThis is the first of our Blogs in the Joomla 3.0 Discovery series. Joomla 3.0 is an awesome release & we are discovering new stuff with it as we use it everyday. We hope to share our new found knowledge with the community through this series. The series will cover topics for end users, administrators as well as developers. 

Converting Joomla Extensions to Joomla 3.0

We are working on ‘Converting common installable packages for “joomla 1.5.x & 2.5.x” to “joomla 3.0” ’. Here are the minimal changes we had to make to get it to work on joomla 3.0. Note that, some of the changes mentioned below were ideally should have been made in ‘joomla 1.5 to joomla 1.6’ & ‘joomla 1.7 to joomla 2.5’ conversions BUT as we had to keep single installable package for all joomla versions including 1.5.x, 1.6.x, 1.7.x, 2.5.x  we skipped some of those changes needed during those conversion phases.

1. Changes to the Manifest XML 
1.A Component Manifest 

Changed From

<install type="component" version="1.5.0" method="upgrade">
</install>

Changed to

<extension type="component" version="3.0" method="upgrade">
</extension>

Changed From

<name>JBolo!</name>

Changed to 

<name>com_jbolo</name>

Changed From

<administration>
<menu img="../administrator/components/com_jbolo/images/jbolo_menu.png">COM_JBOLO</menu>

Changed to 

<administration>
<menu link="option=com_jbolo" img="../administrator/components/com_jbolo/images/jbolo_menu.png">com_jbolo</menu>

Changed From

<filename>admin.jbolo.php</filename>

Changed to 

<filename>jbolo.php</filename> 

 Changed From

<installfile>install.jbolo.php</installfile>

Changed to

<scriptfile>install.jbolo.php</scriptfile>

1.B Module Manifest

 Changed From 

<install type="module" version="1.5.0" method="upgrade">
</install>

 Changed to

<extension type="module" version="3.0" method="upgrade">
</extension>

1.C Plugin Manifest

 Changed From 

<install version="1.5" type="plugin" group="system" method="upgrade">
</install>

  Changed to

<extension version="3.0" type="plugin" group="system" method="upgrade">
</extension>

2. Remove strict warnings

These changes are done to remove strict warnings which are shown when we set “Error reporting” to “Development”.

// Changed from
$mainframe=&JFactory::getApplication();
$user=&JFactory::getUser();
$doc=&JFactory::getDocument();
$module=&JModuleHelper::getModule('customjbolo');

// Changed to $mainframe=JFactory::getApplication(); $user=JFactory::getUser(); $doc=JFactory::getDocument(); $module=JModuleHelper::getModule('customjbolo');

// Changed from
JTable::_getAssetParentId($table = NULL, $id = NULL)
// to
JTable::_getAssetParentId(JTable $table = null, $id = null)

3. For directory separator-

You either need to add this code in your component entry file or use ‘DIRECTORY_SEPARATOR’ instead of ‘DS’

We have added this code in system plugin entry file - plg_sys_jbolo_asset/plg_sys_jbolo_asset.php

if(!defined('DS')){
   define('DS',DIRECTORY_SEPARATOR);
}

4. Changes to access module parameters outside module

To access module parameters inside a plugin

//changed code from -
$module=JModuleHelper::getModule('jbolo');
$moduleParams=new JParameter($module->params);
$chatmode=intval($moduleParams->get('modorbar',1));
//to
$module=JModuleHelper::getModule('jbolo');
$moduleParams=json_decode($module->params);
$chatmode=$moduleParams->modorbar;

Component changes in general:

5. Changed class names for ALL models, controllers and views(view.html.php) files

//Changes to model-
//from
class JboloModelSendFile extends JModel
//to
class JboloModelSendFile extends JModelLegacy

//Changes to controller- //from class JboloController extends JController //to class JboloController extends JControllerLegacy
//Changes to view- //from class JboloViewHistory extends JView //to class JboloViewHistory extends JViewLegacy

6. Changed function prototype in all controllers

//from
function display()
//to
public function display($cachable = false, $urlparams = false)  

7. Changes to date formatting function to php like

//changed from
JFactory::getDate()->toFormat;
//to
JFactory::getDate()->Format;

example-

//changed from-
$message=sprintf(JText::_('SENT_AT'),JFactory::getDate($time)->toFormat(JText::_("SENT_AT_FORMAT")));
//to
$message=sprintf(JText::_('SENT_AT'),JFactory::getDate($time)->Format('SENT_AT_FORMAT'));

8. Changed in date formatting- (using it like native php style)

to achieve date format : 6:27PM October 12

// changed from
SENT_AT_FORMAT="%l:%M%p %B %e"
// to
SENT_AT_FORMAT="g:iA F y"

To achieve date format : Wednesday, 03 October 2012 

// changed from
HIST_DATE_FORM="%A %e %B %Y"
// to
HIST_DATE_FORM="l, d F Y"

9. In administrator/components/com_jbolo/

Remove
admin.jbolo.php
Use
jbolo.php
otherwise shows component not found error

10.JFactory::getXMLParser() has been removed, use JFactory::getXML().

//changed from
$parser=JFactory::getXMLParser('Simple');
$xml=JPATH_COMPONENT.DS.'jbolo.xml';
$parser->loadFile($xml);
$doc=$parser->document;
$element=$doc->getElementByPath('version');
$version=$element->data();
//to
$xml=JFactory::getXML(JPATH_COMPONENT.DS.'jbolo.xml');
$version=(string)$xml->version;

11. JDate::toMysql() has been removed. Use JDate::toSql() instead

//changed from
$get_date=JFactory::getDate();   
$date=$get_date->toMysql();
//to
$get_date=JFactory::getDate();   
$date=$get_date->toSql();

12. JHtmlBehavior::mootools() has been removed. Use JHtmlBehavior::framework() instead. 

//changed from
JHTML::_('behavior.mootools');
//to
JHtmlBehavior::framework();

13. JUtility::sendMail() has been removed. Use JMail::sendMail() instead.

To use the new JMail::sendMail() you also need to have the following library imported.

jimport('joomla.mail.mail');

* Thanks Walt for update!

14. JUtility::sendAdminMail() has been removed. Use JMail::sendAdminMail() instead.

15. JDatabase::query() is deprecated, use JDatabaseDriver::execute() instead.

//changed from
$db->query();
//to
$db->execute();

16. JFile::read is deprecated. Use native file_get_contents() syntax. 

//changed from
$smileysfile = JFile::read(JPATH_COMPONENT . DS . 'smileys.txt');
//to
$smileysfile=file_get_contents(JPATH_COMPONENT.DS.'smileys.txt');

17. JRequest is deprecated. Use JFactory::getApplication()->input

http://docs.joomla.org/Retrieving_request_data_using_JInput

//changed from
$post=JRequest::get('post');
JRequest::getVar('badwords');
//to
$input=JFactory::getApplication()->input;
$post=$input->post;
$input->post->get('badwords')

//from $task = JRequest::getVar('task'); //to $task=$input->get('task');
//from $groupid = JRequest::getVar('id'); //to $groupid=$input->get('id');
//from $limitstart=JRequest::getVar('limitstart', 0, '', 'int'); //to $limitstart=$input->get('limitstart','0','INT');
//from $controller=JRequest::getWord('controller'); //to $controller=$input->get('controller');
//from $controller->execute(JRequest::getCmd('action')); //to $controller->execute($input->get('action'));

18. JViewLegacy::assignRef is deprecated. Use native PHP syntax

//changed from
$this->assignRef( 'userlist', $userlist );
//to
$this->userlist=$userlist;

Refer to
http://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_3.0_and_Joomla_Platform_12.1#JHtml

19. JDatabase::loadResultArray() has been removed use JDatabase::loadColumn() instead.

* Thanks Walt for update!

Rate this blog entry:
Developing with Zoo - Programatically creating "Ed...
SocialAds 2.7.7 Bug Fix release is here