Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

License

Content on this site is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Source code for file /joomla/application/component/helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3. @version        $Id: helper.php 9918 2008-01-10 01:41:37Z 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. @author        Johan Janssens <johan.janssens@joomla.org>
  23. @package        Joomla.Framework
  24. @subpackage    Application
  25. @since        1.5
  26. */
  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 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 JParameter object
  77.      */
  78.     function &getParams$name )
  79.     {
  80.         static $instances;
  81.         if (!isset$instances[$name))
  82.         {
  83.             $component &JComponentHelper::getComponent$name );
  84.             $instances[$namenew 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(404JText::_("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.         $task JRequest::getString'task' );
  103.  
  104.         // Build the component path
  105.         $name preg_replace('/[^A-Z0-9_\.-]/i'''$name);
  106.         $file substr$name);
  107.  
  108.         // Define component path
  109.         define'JPATH_COMPONENT',                    JPATH_BASE.DS.'components'.DS.$name);
  110.         define'JPATH_COMPONENT_SITE',                JPATH_SITE.DS.'components'.DS.$name);
  111.         define'JPATH_COMPONENT_ADMINISTRATOR',    JPATH_ADMINISTRATOR.DS.'components'.DS.$name);
  112.  
  113.         // get component path
  114.         if $mainframe->isAdmin(&& file_exists(JPATH_COMPONENT.DS.'admin.'.$file.'.php') ) {
  115.             $path JPATH_COMPONENT.DS.'admin.'.$file.'.php';
  116.         else {
  117.             $path JPATH_COMPONENT.DS.$file.'.php';
  118.         }
  119.  
  120.         // If component disabled throw error
  121.         if (!JComponentHelper::isEnabled$name || !file_exists($path)) {
  122.             JError::raiseError404JText::_'Component Not Found' ) );
  123.         }
  124.  
  125.         // Handle legacy globals if enabled
  126.         if ($mainframe->getCfg('legacy'))
  127.         {
  128.             // Include legacy globals
  129.             global $my$database$id$acl$task;
  130.  
  131.             // For backwards compatibility extract the config vars as globals
  132.             $registry =JFactory::getConfig();
  133.             foreach (get_object_vars($registry->toObject()) as $k => $v)
  134.             {
  135.                 $varname 'mosConfig_'.$k;
  136.                 $$varname $v;
  137.             }
  138.             $contentConfig &JComponentHelper::getParams'com_content' );
  139.             foreach (get_object_vars($contentConfig->toObject()) as $k => $v)
  140.             {
  141.                 $varname 'mosConfig_'.$k;
  142.                 $$varname $v;
  143.             }
  144.             $usersConfig &JComponentHelper::getParams'com_users' );
  145.             foreach (get_object_vars($usersConfig->toObject()) as $k => $v)
  146.             {
  147.                 $varname 'mosConfig_'.$k;
  148.                 $$varname $v;
  149.             }
  150.         }
  151.  
  152.         // Load common language files
  153.         $lang =JFactory::getLanguage();
  154.         $lang->load($name);
  155.  
  156.         // Handle template preview outlining
  157.         $contents null;
  158.  
  159.         // Execute the component
  160.         ob_start();
  161.         require_once $path;
  162.         $contents ob_get_contents();
  163.         ob_end_clean();
  164.  
  165.         // Build the component toolbar
  166.         jimport'joomla.application.helper' );
  167.         if (($path JApplicationHelper::getPath'toolbar' )) && $mainframe->isAdmin()) {
  168.  
  169.             // Get the task again, in case it has changed
  170.             $task JRequest::getString'task' );
  171.  
  172.             // Make the toolbar
  173.             include_once$path );
  174.         }
  175.         
  176.         $mainframe->scope $scope//revert the scope
  177.  
  178.         return $contents;
  179.     }
  180.  
  181.     /**
  182.      * Load components
  183.      *
  184.      * @access    private
  185.      * @return    array 
  186.      */
  187.     function _load()
  188.     {
  189.         static $components;
  190.  
  191.         if (isset($components)) {
  192.             return $components;
  193.         }
  194.  
  195.         $db &JFactory::getDBO();
  196.  
  197.         $query 'SELECT *' .
  198.                 ' FROM #__components' .
  199.                 ' WHERE parent = 0';
  200.         $db->setQuery$query );
  201.  
  202.         if (!($components $db->loadObjectList'option' ))) {
  203.             JError::raiseWarning'SOME_ERROR_CODE'"Error loading Components: " $db->getErrorMsg());
  204.             return false;
  205.         }
  206.  
  207.         return $components;
  208.  
  209.     }
  210. }

Documentation generated on Tue, 29 Jan 2008 18:47:30 +0000 by phpDocumentor 1.3.1