| [ Indice ] |
Riferimento incrociato di Joomla! 1.5.14 - VM 1.1.4Servizio fornito da VMItalia |
[Vedi sommario] [Stampa] [Vedi testo]
1 <?php 2 /** 3 * @version $Id: helper.php 10381 2008-06-01 03:35:53Z pasamio $ 4 * @package Joomla.Framework 5 * @subpackage Application 6 * @copyright Copyright (C) 2005 - 2008 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 /** 19 * Component helper class 20 * 21 * @static 22 * @package Joomla.Framework 23 * @subpackage Application 24 * @since 1.5 25 */ 26 class JComponentHelper 27 { 28 /** 29 * Get the component info 30 * 31 * @access public 32 * @param string $name The component name 33 * @param boolean $string If set and a component does not exist, the enabled attribue will be set to false 34 * @return object A JComponent object 35 */ 36 function &getComponent( $name, $strict = false ) 37 { 38 $result = null; 39 $components = JComponentHelper::_load(); 40 41 if (isset( $components[$name] )) 42 { 43 $result = &$components[$name]; 44 } 45 else 46 { 47 $result = new stdClass(); 48 $result->enabled = $strict ? false : true; 49 $result->params = null; 50 } 51 52 return $result; 53 } 54 55 /** 56 * Checks if the component is enabled 57 * 58 * @access public 59 * @param string $component The component name 60 * @param boolean $string If set and a component does not exist, false will be returned 61 * @return boolean 62 */ 63 function isEnabled( $component, $strict = false ) 64 { 65 global $mainframe; 66 67 $result = &JComponentHelper::getComponent( $component, $strict ); 68 return ($result->enabled | $mainframe->isAdmin()); 69 } 70 71 /** 72 * Gets the parameter object for the component 73 * 74 * @access public 75 * @param string $name The component name 76 * @return object A JParameter object 77 */ 78 function &getParams( $name ) 79 { 80 static $instances; 81 if (!isset( $instances[$name] )) 82 { 83 $component = &JComponentHelper::getComponent( $name ); 84 $instances[$name] = new JParameter($component->params); 85 } 86 return $instances[$name]; 87 } 88 89 function renderComponent($name = null, $params = array()) 90 { 91 global $mainframe, $option; 92 93 if(empty($name)) { 94 // Throw 404 if no component 95 JError::raiseError(404, JText::_("Component Not Found")); 96 return; 97 } 98 99 $scope = $mainframe->scope; //record the scope 100 $mainframe->scope = $name; //set scope to component name 101 102 // Build the component path 103 $name = preg_replace('/[^A-Z0-9_\.-]/i', '', $name); 104 $file = substr( $name, 4 ); 105 106 // Define component path 107 define( 'JPATH_COMPONENT', JPATH_BASE.DS.'components'.DS.$name); 108 define( 'JPATH_COMPONENT_SITE', JPATH_SITE.DS.'components'.DS.$name); 109 define( 'JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR.DS.'components'.DS.$name); 110 111 // get component path 112 if ( $mainframe->isAdmin() && file_exists(JPATH_COMPONENT.DS.'admin.'.$file.'.php') ) { 113 $path = JPATH_COMPONENT.DS.'admin.'.$file.'.php'; 114 } else { 115 $path = JPATH_COMPONENT.DS.$file.'.php'; 116 } 117 118 // If component disabled throw error 119 if (!JComponentHelper::isEnabled( $name ) || !file_exists($path)) { 120 JError::raiseError( 404, JText::_( 'Component Not Found' ) ); 121 } 122 123 // Handle legacy globals if enabled 124 if ($mainframe->getCfg('legacy')) 125 { 126 // Include legacy globals 127 global $my, $database, $id, $acl, $task; 128 129 // For backwards compatibility extract the config vars as globals 130 $registry =& JFactory::getConfig(); 131 foreach (get_object_vars($registry->toObject()) as $k => $v) 132 { 133 $varname = 'mosConfig_'.$k; 134 $$varname = $v; 135 } 136 $contentConfig = &JComponentHelper::getParams( 'com_content' ); 137 foreach (get_object_vars($contentConfig->toObject()) as $k => $v) 138 { 139 $varname = 'mosConfig_'.$k; 140 $$varname = $v; 141 } 142 $usersConfig = &JComponentHelper::getParams( 'com_users' ); 143 foreach (get_object_vars($usersConfig->toObject()) as $k => $v) 144 { 145 $varname = 'mosConfig_'.$k; 146 $$varname = $v; 147 } 148 149 } 150 151 $task = JRequest::getString( 'task' ); 152 153 // Load common language files 154 $lang =& JFactory::getLanguage(); 155 $lang->load($name); 156 157 // Handle template preview outlining 158 $contents = null; 159 160 // Execute the component 161 ob_start(); 162 require_once $path; 163 $contents = ob_get_contents(); 164 ob_end_clean(); 165 166 // Build the component toolbar 167 jimport( 'joomla.application.helper' ); 168 if (($path = JApplicationHelper::getPath( 'toolbar' )) && $mainframe->isAdmin()) { 169 170 // Get the task again, in case it has changed 171 $task = JRequest::getString( 'task' ); 172 173 // Make the toolbar 174 include_once( $path ); 175 } 176 177 $mainframe->scope = $scope; //revert the scope 178 179 return $contents; 180 } 181 182 /** 183 * Load components 184 * 185 * @access private 186 * @return array 187 */ 188 function _load() 189 { 190 static $components; 191 192 if (isset($components)) { 193 return $components; 194 } 195 196 $db = &JFactory::getDBO(); 197 198 $query = 'SELECT *' . 199 ' FROM #__components' . 200 ' WHERE parent = 0'; 201 $db->setQuery( $query ); 202 203 if (!($components = $db->loadObjectList( 'option' ))) { 204 JError::raiseWarning( 'SOME_ERROR_CODE', "Error loading Components: " . $db->getErrorMsg()); 205 return false; 206 } 207 208 return $components; 209 210 } 211 }
titolo
Descrizione
Corpo
titolo
Descrizione
Corpo
titolo
Descrizione
Corpo
titolo
Corpo
| Generato il: Mon Oct 19 20:29:27 2009 | Generato con PHPXref 0.7 |