| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: helper.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla.Framework 5 * @subpackage Application 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant 9 * to the GNU General Public License, and as distributed it includes or 10 * is derivative of works licensed under the GNU General Public License or 11 * other free or open source software licenses. 12 * See COPYRIGHT.php for copyright notices and details. 13 */ 14 15 // Check to ensure this file is within the rest of the framework 16 defined('JPATH_BASE') or die(); 17 18 // Import library dependencies 19 jimport('joomla.application.component.helper'); 20 21 /** 22 * Module helper class 23 * 24 * @static 25 * @package Joomla.Framework 26 * @subpackage Application 27 * @since 1.5 28 */ 29 class JModuleHelper 30 { 31 /** 32 * Get module by name (real, eg 'Breadcrumbs' or folder, eg 'mod_breadcrumbs') 33 * 34 * @access public 35 * @param string $name The name of the module 36 * @param string $title The title of the module, optional 37 * @return object The Module object 38 */ 39 function &getModule($name, $title = null ) 40 { 41 $result = null; 42 $modules =& JModuleHelper::_load(); 43 $total = count($modules); 44 for ($i = 0; $i < $total; $i++) 45 { 46 // Match the name of the module 47 if ($modules[$i]->name == $name) 48 { 49 // Match the title if we're looking for a specific instance of the module 50 if ( ! $title || $modules[$i]->title == $title ) 51 { 52 $result =& $modules[$i]; 53 break; // Found it 54 } 55 } 56 } 57 58 // if we didn't find it, and the name is mod_something, create a dummy object 59 if (is_null( $result ) && substr( $name, 0, 4 ) == 'mod_') 60 { 61 $result = new stdClass; 62 $result->id = 0; 63 $result->title = ''; 64 $result->module = $name; 65 $result->position = ''; 66 $result->content = ''; 67 $result->showtitle = 0; 68 $result->control = ''; 69 $result->params = ''; 70 $result->user = 0; 71 } 72 73 return $result; 74 } 75 76 /** 77 * Get modules by position 78 * 79 * @access public 80 * @param string $position The position of the module 81 * @return array An array of module objects 82 */ 83 function &getModules($position) 84 { 85 $position = strtolower( $position ); 86 $result = array(); 87 88 $modules =& JModuleHelper::_load(); 89 90 $total = count($modules); 91 for($i = 0; $i < $total; $i++) { 92 if($modules[$i]->position == $position) { 93 $result[] =& $modules[$i]; 94 } 95 } 96 if(count($result) == 0) { 97 if(JRequest::getBool('tp')) { 98 $result[0] = JModuleHelper::getModule( 'mod_'.$position ); 99 $result[0]->title = $position; 100 $result[0]->content = $position; 101 $result[0]->position = $position; 102 } 103 } 104 105 return $result; 106 } 107 108 /** 109 * Checks if a module is enabled 110 * 111 * @access public 112 * @param string $module The module name 113 * @return boolean 114 */ 115 function isEnabled( $module ) 116 { 117 $result = &JModuleHelper::getModule( $module); 118 return (!is_null($result)); 119 } 120 121 function renderModule($module, $attribs = array()) 122 { 123 static $chrome; 124 global $mainframe, $option; 125 126 $scope = $mainframe->scope; //record the scope 127 $mainframe->scope = $module->module; //set scope to component name 128 129 // Handle legacy globals if enabled 130 if ($mainframe->getCfg('legacy')) 131 { 132 // Include legacy globals 133 global $my, $database, $acl, $mosConfig_absolute_path; 134 135 // Get the task variable for local scope 136 $task = JRequest::getString('task'); 137 138 // For backwards compatibility extract the config vars as globals 139 $registry =& JFactory::getConfig(); 140 foreach (get_object_vars($registry->toObject()) as $k => $v) { 141 $name = 'mosConfig_'.$k; 142 $$name = $v; 143 } 144 $contentConfig = &JComponentHelper::getParams( 'com_content' ); 145 foreach (get_object_vars($contentConfig->toObject()) as $k => $v) 146 { 147 $name = 'mosConfig_'.$k; 148 $$name = $v; 149 } 150 $usersConfig = &JComponentHelper::getParams( 'com_users' ); 151 foreach (get_object_vars($usersConfig->toObject()) as $k => $v) 152 { 153 $name = 'mosConfig_'.$k; 154 $$name = $v; 155 } 156 } 157 158 // Get module parameters 159 $params = new JParameter( $module->params ); 160 161 // Get module path 162 $module->module = preg_replace('/[^A-Z0-9_\.-]/i', '', $module->module); 163 $path = JPATH_BASE.DS.'modules'.DS.$module->module.DS.$module->module.'.php'; 164 165 // Load the module 166 if (!$module->user && file_exists( $path ) && empty($module->content)) 167 { 168 $lang =& JFactory::getLanguage(); 169 $lang->load($module->module); 170 171 $content = ''; 172 ob_start(); 173 require $path; 174 $module->content = ob_get_contents().$content; 175 ob_end_clean(); 176 } 177 178 // Load the module chrome functions 179 if (!$chrome) { 180 $chrome = array(); 181 } 182 183 require_once (JPATH_BASE.DS.'templates'.DS.'system'.DS.'html'.DS.'modules.php'); 184 $chromePath = JPATH_BASE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'modules.php'; 185 if (!isset( $chrome[$chromePath])) 186 { 187 if (file_exists($chromePath)) { 188 require_once ($chromePath); 189 } 190 $chrome[$chromePath] = true; 191 } 192 193 //make sure a style is set 194 if(!isset($attribs['style'])) { 195 $attribs['style'] = 'none'; 196 } 197 198 //dynamically add outline style 199 if(JRequest::getBool('tp')) { 200 $attribs['style'] .= ' outline'; 201 } 202 203 foreach(explode(' ', $attribs['style']) as $style) 204 { 205 $chromeMethod = 'modChrome_'.$style; 206 207 // Apply chrome and render module 208 if (function_exists($chromeMethod)) 209 { 210 $module->style = $attribs['style']; 211 212 ob_start(); 213 $chromeMethod($module, $params, $attribs); 214 $module->content = ob_get_contents(); 215 ob_end_clean(); 216 } 217 } 218 219 $mainframe->scope = $scope; //revert the scope 220 221 return $module->content; 222 } 223 224 /** 225 * Get the path to a layout for a module 226 * 227 * @static 228 * @param string $module The name of the module 229 * @param string $layout The name of the module layout 230 * @return string The path to the module layout 231 * @since 1.5 232 */ 233 function getLayoutPath($module, $layout = 'default') 234 { 235 global $mainframe; 236 237 // Build the template and base path for the layout 238 $tPath = JPATH_BASE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.$module.DS.$layout.'.php'; 239 $bPath = JPATH_BASE.DS.'modules'.DS.$module.DS.'tmpl'.DS.$layout.'.php'; 240 241 // If the template has a layout override use it 242 if (file_exists($tPath)) { 243 return $tPath; 244 } else { 245 return $bPath; 246 } 247 } 248 249 /** 250 * Load published modules 251 * 252 * @access private 253 * @return array 254 */ 255 function &_load() 256 { 257 global $mainframe, $Itemid; 258 259 static $modules; 260 261 if (isset($modules)) { 262 return $modules; 263 } 264 265 $user =& JFactory::getUser(); 266 $db =& JFactory::getDBO(); 267 268 $aid = $user->get('aid', 0); 269 270 $modules = array(); 271 272 $wheremenu = isset( $Itemid ) ? ' AND ( mm.menuid = '. (int) $Itemid .' OR mm.menuid = 0 )' : ''; 273 274 $query = 'SELECT id, title, module, position, content, showtitle, control, params' 275 . ' FROM #__modules AS m' 276 . ' LEFT JOIN #__modules_menu AS mm ON mm.moduleid = m.id' 277 . ' WHERE m.published = 1' 278 . ' AND m.access <= '. (int)$aid 279 . ' AND m.client_id = '. (int)$mainframe->getClientId() 280 . $wheremenu 281 . ' ORDER BY position, ordering'; 282 283 $db->setQuery( $query ); 284 285 if (null === ($modules = $db->loadObjectList())) { 286 JError::raiseWarning( 'SOME_ERROR_CODE', JText::_( 'Error Loading Modules' ) . $db->getErrorMsg()); 287 return false; 288 } 289 290 $total = count($modules); 291 for($i = 0; $i < $total; $i++) 292 { 293 //determine if this is a custom module 294 $file = $modules[$i]->module; 295 $custom = substr( $file, 0, 4 ) == 'mod_' ? 0 : 1; 296 $modules[$i]->user = $custom; 297 // CHECK: custom module name is given by the title field, otherwise it's just 'om' ?? 298 $modules[$i]->name = $custom ? $modules[$i]->title : substr( $file, 4 ); 299 $modules[$i]->style = null; 300 $modules[$i]->position = strtolower($modules[$i]->position); 301 } 302 303 return $modules; 304 } 305 306 } 307
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |