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