Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/application/component/helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3. @version        $Id: helper.php 6688 2007-02-21 08:36:39Z louis $
  4. @package        Joomla.Framework
  5. @subpackage    Application
  6. @copyright    Copyright (C) 2005 - 2007 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. /**
  16. * Component helper class
  17. *
  18. @static
  19. @author        Johan Janssens <[email protected]>
  20. @package        Joomla.Framework
  21. @subpackage    Application
  22. @since        1.5
  23. */
  24. {
  25.     /**
  26.      * Get the component info
  27.      *
  28.      * @access public
  29.      * @param string $name     The component name
  30.      * @return object JComponent object
  31.      */
  32.     function &getInfo$name )
  33.     {
  34.         static $instances;
  35.  
  36.         if (!isset$instances[$name))
  37.         {
  38.             $db &JFactory::getDBO();
  39.  
  40.             $query 'SELECT *' .
  41.                     ' FROM #__components' .
  42.                     ' WHERE parent = 0';
  43.             $db->setQuery$query );
  44.             $instances $db->loadObjectList'option' );
  45.         }
  46.  
  47.         if (isset$instances[$name))
  48.         {
  49.             $result &$instances[$name];
  50.         }
  51.         else
  52.         {
  53.             $result                new stdClass();
  54.             $result->enabled    true;
  55.             $result->params        null;
  56.         }
  57.  
  58.         return $result;
  59.     }
  60.  
  61.     /**
  62.      * Checks if the component is enabled
  63.      *
  64.      * @access public
  65.      * @param string $name The component name
  66.      * @return boolean 
  67.      */
  68.     function isEnabled$name )
  69.     {
  70.         global $mainframe;
  71.  
  72.         $component &JComponentHelper::getInfo$name );
  73.         return ($component->enabled $mainframe->isAdmin());
  74.     }
  75.  
  76.     /**
  77.      * Gets the parameter object for the component
  78.      *
  79.      * @access public
  80.      * @param string $name The component name
  81.      * @return object JParameter object
  82.      */
  83.     function &getParams$name )
  84.     {
  85.         static $instances;
  86.         if (!isset$instances[$name))
  87.         {
  88.             $component &JComponentHelper::getInfo$name );
  89.             $instances[$namenew JParameter($component->params);
  90.         }
  91.         return $instances[$name];
  92.     }
  93.  
  94.     function renderComponent($name null$params array())
  95.     {
  96.         global $mainframe$option;
  97.  
  98.         if(empty($name)) {
  99.             return;
  100.         }
  101.  
  102.         $task        JRequest::getVar'task' );
  103.  
  104.         // Build the component path
  105.         $file substr$name);
  106.  
  107.         // Define component path
  108.         define'JPATH_COMPONENT',                    JPATH_BASE.DS.'components'.DS.$name);
  109.         define'JPATH_COMPONENT_SITE',                JPATH_SITE.DS.'components'.DS.$name);
  110.         define'JPATH_COMPONENT_ADMINISTRATOR',    JPATH_ADMINISTRATOR.DS.'components'.DS.$name);
  111.  
  112.         // get component path
  113.         if $mainframe->isAdmin(&& file_exists(JPATH_COMPONENT.DS.'admin.'.$file.'.php') ) {
  114.             $path JPATH_COMPONENT.DS.'admin.'.$file.'.php';
  115.         else {
  116.             $path JPATH_COMPONENT.DS.$file.'.php';
  117.         }
  118.  
  119.         // If component disabled throw error
  120.         if (!JComponentHelper::isEnabled$name || !file_exists($path)) {
  121.             JError::raiseError404JText::_('Component Not Found') );
  122.         }
  123.  
  124.         // Handle legacy globals if enabled
  125.         if ($mainframe->getCfg('legacy'))
  126.         {
  127.             // Include legacy globals
  128.             global $my$database$id$acl$task;
  129.  
  130.             // For backwards compatibility extract the config vars as globals
  131.             $registry =JFactory::getConfig();
  132.             foreach (get_object_vars($registry->toObject()) as $k => $v)
  133.             {
  134.                 $varname 'mosConfig_'.$k;
  135.                 $$varname $v;
  136.             }
  137.             $contentConfig &JComponentHelper::getParams'com_content' );
  138.             foreach (get_object_vars($contentConfig->toObject()) as $k => $v)
  139.             {
  140.                 $varname 'mosConfig_'.$k;
  141.                 $$varname $v;
  142.             }
  143.             $usersConfig &JComponentHelper::getParams'com_users' );
  144.             foreach (get_object_vars($usersConfig->toObject()) as $k => $v)
  145.             {
  146.                 $varname 'mosConfig_'.$k;
  147.                 $$varname $v;
  148.             }
  149.         }
  150.  
  151.         // Load common language files
  152.         $lang =JFactory::getLanguage();
  153.         $lang->load($name);
  154.  
  155.         // Handle template preview outlining
  156.         $contents null;
  157.  
  158.         // Execute the component
  159.         ob_start();
  160.         require_once $path;
  161.         $contents ob_get_contents();
  162.         ob_end_clean();
  163.  
  164.         // Build the component toolbar
  165.         jimport'joomla.application.helper' );
  166.         if (($path JApplicationHelper::getPath'toolbar' )) && $mainframe->isAdmin()) {
  167.  
  168.             // Get the task again, in case it has changed
  169.             $task        JRequest::getVar'task' );
  170.  
  171.             // Make the toolbar
  172.             require_onceJPATH_ADMINISTRATOR .'/includes/menubar.html.php' );
  173.             include_once$path );
  174.         }
  175.  
  176.         return $contents;
  177.     }
  178. }
  179. ?>

Documentation generated on Mon, 05 Mar 2007 21:05:37 +0000 by phpDocumentor 1.3.1