function displayModules( &$all_mod_array, &$params, $metamod_module, $attribs = array(), $changeObject = null) { if (is_array($all_mod_array) && count($all_mod_array)) { $app =& JFactory::getApplication(); $db = JFactory::getDbo(); $user =& JFactory::getUser(); $aid = $user->get('aid', 0); $quoted_mod_identifiers = modMetaModHelper::quotedEscapedListFromModuleArray( $db, $all_mod_array ); // If we are using the changecache system, then we // select all available modules EVEN IF THEY ARE DISABLED. Then we // trim the list again at the end, removing any that are (still) // disabled. // This allows the MetaMod rules to include modules that are known // to be disabled, and it enables them automatically. $autoenable = $params->get( 'autoenable', 'all' ); $groups = implode(',', $user->getAuthorisedViewLevels()); $query = $db->getQuery(true); $query->select('m.id, m.title, m.module, m.position, m.content, m.showtitle, m.params, m.published, m.ordering' . ", m.id in ( $quoted_mod_identifiers ) as in_id" . ", m.position in ( $quoted_mod_identifiers ) as in_position" ); $query->from('#__modules AS m'); if ( !$changeObject && $autoenable == 'none') { $query->where('m.published = 1'); } $query->where('m.access IN ('.$groups.')'); $query->where( "( m.id in ( $quoted_mod_identifiers ) OR m.position in ( $quoted_mod_identifiers ) )" ); $query->order( "( field( " . "\n case when m.position in ( $quoted_mod_identifiers ) then m.position else m.id end," . "\n $quoted_mod_identifiers )), m.ordering" ); $db->setQuery($query); $modules = array(); if ( !( $modules = $db->loadObjectList() ) ) { JError::raiseWarning( 'SOME_ERROR_CODE', "Error loading Modules: " . $db->getErrorMsg()); return false; // FIXME - what to do here? Ignore? } // do some stuff that is found in libraries/joomla/application/module/helper.php $total = count( $modules ); for( $i = 0; $i < $total; $i++ ) { // autoenabling, according to our parameters if ( $autoenable == 'all' || ( $autoenable == 'id' && $modules[$i]->in_id == 1) || ( $autoenable == 'position' && $modules[$i]->in_position == 1 ) ) { $modules[$i]->published = 1; } // 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( $metamod_module->position ); } modMetaModHelper::applyParamChanges( $modules, $changeObject ); $document = &JFactory::getDocument(); $renderer = $document->loadRenderer( 'module' ); $style = trim( $params->get( 'force_style', trim( $params->get( 'style', 'table' ) ) ) ); $contents = ''; if ( !is_array( $attribs ) ) { $attribs = array(); } $attribs['style'] = $style; foreach ( $modules as $mod ) { if ( $mod->published ) { $contents .= $renderer->render($mod, $attribs); } } return $contents; } }
<?php /** * @version 3.0 * @copyright Copyright (C) 2007-2012 Stephen Brandon * @license GNU/GPL */ // no direct access defined('_JEXEC') or die('Restricted access'); // Include the helper functions only once require_once (dirname(__FILE__).DS.'helper.php'); // Note: if a MetaMod is included twice in the page, e.g. in a {loadposition right} as well // as in the normal position, it appears that the $attribs['name'] (which is the position) // is not set for *either* occurrence. list( $moduleIds, $changeCache ) = modMetaModHelper::moduleIdsAndChanges( $params, $module ); // $attribs is inherited from the calling code in Joomla. echo modMetaModHelper::displayModules( $moduleIds, $params, $module, isset($attribs) ? $attribs : null, $changeCache );
public static function displayModules(&$all_mod_array, &$params, $metamod_module, $attribs = array(), $changeObject = null) { if (is_array($all_mod_array) && count($all_mod_array)) { $app = JFactory::getApplication(); $db = JFactory::getDbo(); $user = JFactory::getUser(); $aid = $user->get('aid', 0); $quoted_mod_identifiers = modMetaModHelper::quotedEscapedListFromModuleArray($db, $all_mod_array); // If we are using the changecache system, then we // select all available modules EVEN IF THEY ARE DISABLED. Then we // trim the list again at the end, removing any that are (still) // disabled. // This allows the MetaMod rules to include modules that are known // to be disabled, and it enables them automatically. $autoenable = $params->get('autoenable', 'all'); $groups = implode(',', $user->getAuthorisedViewLevels()); $debug = $params->get('debug', 0); $query = $db->getQuery(true); $query->select('m.id, m.title, m.module, m.position, m.content, m.showtitle, m.params, m.published, m.ordering' . ", m.id in ( {$quoted_mod_identifiers} ) as in_id" . ", m.position in ( {$quoted_mod_identifiers} ) as in_position"); $query->from('#__modules AS m'); if (!$changeObject && $autoenable == 'none') { $query->where('m.published = 1'); } $query->where('m.access IN (' . $groups . ')'); $query->where("( m.id in ( {$quoted_mod_identifiers} ) OR m.position in ( {$quoted_mod_identifiers} ) )"); $query->order("( field( " . "\n case when m.position in ( {$quoted_mod_identifiers} ) then m.position else m.id end," . "\n {$quoted_mod_identifiers} )), m.ordering"); $db->setQuery($query); $modules = array(); if (version_compare(JVERSION, '3.0', '<')) { // J1.7, 2.5 if (!($modules = $db->loadObjectList())) { if ($debug) { JError::raiseWarning('SOME_ERROR_CODE', "Error loading Modules: " . $db->getErrorMsg()); } return false; // FIXME - what to do here? Ignore? } } else { // J3.0: try { $modules = $db->loadObjectList(); } catch (RuntimeException $e) { if ($debug) { JLog::add(JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $e->getMessage()), JLog::WARNING, 'jerror'); } return false; } } // do some stuff that is found in libraries/joomla/application/module/helper.php $total = count($modules); for ($i = 0; $i < $total; $i++) { // autoenabling, according to our parameters if ($autoenable == 'all' || $autoenable == 'id' && $modules[$i]->in_id == 1 || $autoenable == 'position' && $modules[$i]->in_position == 1) { $modules[$i]->published = 1; } // 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($metamod_module->position); } modMetaModHelper::applyParamChanges($modules, $changeObject); $document = JFactory::getDocument(); $renderer = $document->loadRenderer('module'); // Get the 3.0 style and trim it down // these only get used if/when the main "style" (advanced) parameter in J3.0 is set to Inherit. If it's // set to anything else, it overrides this one. if (version_compare(JVERSION, '3.0', '>=')) { // J3.0+ $style = trim($params->get('force_style', trim($params->get('style2', 'table')))); $template = $app->getTemplate(); $style = preg_replace('/^(system|' . $template . ')\\-/i', '', $style); } else { // J1.7-2.5; get the parameter named "style" $style = trim($params->get('force_style', trim($params->get('style', 'table')))); } $contents = ''; if (!is_array($attribs)) { $attribs = array(); } $attribs['style'] = $style; foreach ($modules as $mod) { if ($mod->published) { $contents .= $renderer->render($mod, $attribs); } } return $contents; } }