Why is it so retro?.. I fixed it up, because I'm having problems getting it to integrate with another plugin. This follows Joomla! style formatting a lot more.
jconnector_server.php:
PHP Code:
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
$parts = explode( DS, dirname(__FILE__) );
array_pop( $parts );
array_pop( $parts );
define( 'JPATH_BASE', implode( DS, $parts ) );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
include_once ( JPATH_BASE .DS.'components'.DS.'com_user'.DS.'controller.php');
include_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'base'.DS.'observable.php');
include_once ( JPATH_BASE .DS.'modules'.DS.'mod_jconnector'.DS.'extension_detector.php');
include_once ( JPATH_BASE .DS.'modules'.DS.'mod_jconnector'.DS.'classes.php');
include_once ( JPATH_BASE .DS.'modules'.DS.'mod_jconnector'.DS.'facebook'.DS.'php'.DS.'facebook.php');
The include for facebook.php was moved up from the middle of the code.
I had problems integrating this module with another plugin (because that plugin changed the way module helper worked), so I removed the module helper include, and manually included it in the classes.php file.
Classes.php:
After the class jconnector_registration, I added the J_ModuleHelper class (J! 1.5 JModuleHelper version renamed):
PHP Code:
/**
* Module helper class
*
* @static
* @package Joomla.Framework
* @subpackage Application
* @since 1.5
*/
class J_ModuleHelper
{
/**
* Get module by name (real, eg 'Breadcrumbs' or folder, eg 'mod_breadcrumbs')
*
* @access public
* @param string $name The name of the module
* @param string $title The title of the module, optional
* @return object The Module object
*/
function &getModule($name, $title = null )
{
$result = null;
$modules =& J_ModuleHelper::_load();
$total = count($modules);
for ($i = 0; $i < $total; $i++)
{
// Match the name of the module
if ($modules[$i]->name == $name)
{
// Match the title if we're looking for a specific instance of the module
if ( ! $title || $modules[$i]->title == $title )
{
$result =& $modules[$i];
break; // Found it
}
}
}
// if we didn't find it, and the name is mod_something, create a dummy object
if (is_null( $result ) && substr( $name, 0, 4 ) == 'mod_')
{
$result = new stdClass;
$result->id = 0;
$result->title = '';
$result->module = $name;
$result->position = '';
$result->content = '';
$result->showtitle = 0;
$result->control = '';
$result->params = '';
$result->user = 0;
}
return $result;
}
/**
* Load published modules
*
* @access private
* @return array
*/
function &_load()
{
global $mainframe, $Itemid;
static $modules;
if (isset($modules)) {
return $modules;
}
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$aid = $user->get('aid', 0);
$modules = array();
$wheremenu = isset( $Itemid ) ? ' AND ( mm.menuid = '. (int) $Itemid .' OR mm.menuid = 0 )' : '';
$query = 'SELECT id, title, module, position, content, showtitle, control, params'
. ' FROM #__modules AS m'
. ' LEFT JOIN #__modules_menu AS mm ON mm.moduleid = m.id'
. ' WHERE m.published = 1'
. ' AND m.access <= '. (int)$aid
. ' AND m.client_id = '. (int)$mainframe->getClientId()
. $wheremenu
. ' ORDER BY position, ordering';
$db->setQuery( $query );
if (null === ($modules = $db->loadObjectList())) {
JError::raiseWarning( 'SOME_ERROR_CODE', JText::_( 'Error Loading Modules' ) . $db->getErrorMsg());
return false;
}
$total = count($modules);
for($i = 0; $i < $total; $i++)
{
//determine if this is a custom module
$file = $modules[$i]->module;
$custom = substr( $file, 0, 4 ) == 'mod_' ? 0 : 1;
$modules[$i]->user = $custom;
// CHECK: custom module name is given by the title field, otherwise it's just 'om' ??
$modules[$i]->name = $custom ? $modules[$i]->title : substr( $file, 4 );
$modules[$i]->style = null;
$modules[$i]->position = strtolower($modules[$i]->position);
}
return $modules;
}
}
With this change, I made sure to change the call to this class in jconnector_server.php to reflect the class name change from JModuleHelper to J_ModuleHelper.
PHP Code:
$module = J_ModuleHelper::getModule('jconnector', '');
I hope a similar change is made in future versions. Thank you, looking forward to it!