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/module/helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3. @version        $Id: helper.php 9779 2007-12-31 01:44:42Z jinx $
  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. // Import library dependencies
  19. jimport('joomla.application.component.helper');
  20.  
  21. /**
  22.  * Module helper class
  23.  *
  24.  * @static
  25.  * @author        Johan Janssens <johan.janssens@joomla.org>
  26.  * @package        Joomla.Framework
  27.  * @subpackage    Application
  28.  * @since        1.5
  29.  */
  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.      * @return    object    The Module object
  37.      */
  38.     function &getModule($name)
  39.     {
  40.         $result        null;
  41.         $modules    =JModuleHelper::_load();
  42.         $total        count($modules);
  43.         for ($i 0$i $total$i++)
  44.         {
  45.             if ($modules[$i]->name == $name)
  46.             {
  47.                 $result =$modules[$i];
  48.                 break;
  49.             }
  50.         }
  51.         // if we didn't find it, and the name is mod_something, create a dummy object
  52.         if (is_null$result && substr$name0== 'mod_')
  53.         {
  54.             $result                new stdClass;
  55.             $result->id            0;
  56.             $result->title        '';
  57.             $result->module        $name;
  58.             $result->position    '';
  59.             $result->content    '';
  60.             $result->showtitle    0;
  61.             $result->control    '';
  62.             $result->params        '';
  63.             $result->user        0;
  64.         }
  65.  
  66.         return $result;
  67.     }
  68.  
  69.     /**
  70.      * Get modules by position
  71.      *
  72.      * @access public
  73.      * @param string     $position    The position of the module
  74.      * @return array    An array of module objects
  75.      */
  76.     function &getModules($position)
  77.     {
  78.         $position    strtolower$position );
  79.         $result        array();
  80.  
  81.         $modules =JModuleHelper::_load();
  82.  
  83.         $total count($modules);
  84.         for($i 0$i $total$i++{
  85.             if($modules[$i]->position == $position{
  86.                 $result[=$modules[$i];
  87.             }
  88.         }
  89.  
  90.         return $result;
  91.     }
  92.  
  93.     /**
  94.      * Checks if a module is enabled
  95.      *
  96.      * @access    public
  97.      * @param   string     $module    The module name
  98.      * @return    boolean 
  99.      */
  100.     function isEnabled$module )
  101.     {
  102.         $result &JModuleHelper::getModule$module);
  103.         return (!is_null($result));
  104.     }
  105.  
  106.     function renderModule($module$attribs array())
  107.     {
  108.         static $chrome;
  109.         global $mainframe$option;
  110.         
  111.         $scope $mainframe->scope//record the scope
  112.         $mainframe->scope $module->module;  //set scope to component name
  113.         
  114.         // Handle legacy globals if enabled
  115.         if ($mainframe->getCfg('legacy'))
  116.         {
  117.             // Include legacy globals
  118.             global $my$database$acl$mosConfig_absolute_path;
  119.  
  120.             // Get the task variable for local scope
  121.             $task JRequest::getString('task');
  122.  
  123.             // For backwards compatibility extract the config vars as globals
  124.             $registry =JFactory::getConfig();
  125.             foreach (get_object_vars($registry->toObject()) as $k => $v{
  126.                 $name 'mosConfig_'.$k;
  127.                 $$name $v;
  128.             }
  129.             $contentConfig &JComponentHelper::getParams'com_content' );
  130.             foreach (get_object_vars($contentConfig->toObject()) as $k => $v)
  131.             {
  132.                 $name 'mosConfig_'.$k;
  133.                 $$name $v;
  134.             }
  135.             $usersConfig &JComponentHelper::getParams'com_users' );
  136.             foreach (get_object_vars($usersConfig->toObject()) as $k => $v)
  137.             {
  138.                 $name 'mosConfig_'.$k;
  139.                 $$name $v;
  140.             }
  141.         }
  142.  
  143.         // Get module parameters
  144.         $params new JParameter$module->params );
  145.  
  146.         // Get module path
  147.         $module->module preg_replace('/[^A-Z0-9_\.-]/i'''$module->module);
  148.         $path JPATH_BASE.DS.'modules'.DS.$module->module.DS.$module->module.'.php';
  149.  
  150.         // Load the module
  151.         if (!$module->user && file_exists$path && empty($module->content))
  152.         {
  153.             $lang =JFactory::getLanguage();
  154.             $lang->load($module->module);
  155.  
  156.             $content '';
  157.             ob_start();
  158.             require $path;
  159.             $module->content ob_get_contents().$content;
  160.             ob_end_clean();
  161.         }
  162.  
  163.         // Load the module chrome functions
  164.         if (!$chrome{
  165.             $chrome array();
  166.         }
  167.  
  168.         require_once (JPATH_BASE.DS.'templates'.DS.'system'.DS.'html'.DS.'modules.php');
  169.         $chromePath JPATH_BASE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'modules.php';
  170.         if (!isset$chrome[$chromePath]))
  171.         {
  172.             if (file_exists($chromePath)) {
  173.                 require_once ($chromePath);
  174.             }
  175.             $chrome[$chromePathtrue;
  176.         }
  177.  
  178.         //make sure a style is set
  179.         if(!isset($attribs['style'])) {
  180.             $attribs['style''none';
  181.         }
  182.  
  183.         //dynamically add outline style
  184.         if(JRequest::getBool('tp')) {
  185.             $attribs['style'.= ' outline';
  186.         }
  187.  
  188.         foreach(explode(' '$attribs['style']as $style)
  189.         {
  190.             $chromeMethod 'modChrome_'.$style;
  191.  
  192.             // Apply chrome and render module
  193.             if (function_exists($chromeMethod))
  194.             {
  195.                 $module->style $attribs['style'];
  196.  
  197.                 ob_start();
  198.                 $chromeMethod($module$params$attribs);
  199.                 $module->content ob_get_contents();
  200.                 ob_end_clean();
  201.             }
  202.         }
  203.         
  204.         $mainframe->scope $scope//revert the scope
  205.         
  206.         return $module->content;
  207.     }
  208.  
  209.     /**
  210.      * Get the path to a layout for a module
  211.      *
  212.      * @static
  213.      * @param    string    $module    The name of the module
  214.      * @param    string    $layout    The name of the module layout
  215.      * @return    string    The path to the module layout
  216.      * @since    1.5
  217.      */
  218.     function getLayoutPath($module$layout 'default')
  219.     {
  220.         global $mainframe;
  221.  
  222.         // Build the template and base path for the layout
  223.         $tPath JPATH_BASE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.$module.DS.$layout.'.php';
  224.         $bPath JPATH_BASE.DS.'modules'.DS.$module.DS.'tmpl'.DS.$layout.'.php';
  225.  
  226.         // If the template has a layout override use it
  227.         if (file_exists($tPath)) {
  228.             return $tPath;
  229.         else {
  230.             return $bPath;
  231.         }
  232.     }
  233.  
  234.     /**
  235.      * Load published modules
  236.      *
  237.      * @access    private
  238.      * @return    array 
  239.      */
  240.     function &_load()
  241.     {
  242.         global $mainframe$Itemid;
  243.  
  244.         static $modules;
  245.  
  246.         if (isset($modules)) {
  247.             return $modules;
  248.         }
  249.  
  250.         $user    =JFactory::getUser();
  251.         $db        =JFactory::getDBO();
  252.  
  253.         $aid    $user->get('aid'0);
  254.  
  255.         $modules    array();
  256.  
  257.         $wheremenu = isset$Itemid ' AND ( mm.menuid = '. (int) $Itemid .' OR mm.menuid = 0 )' '';
  258.  
  259.         $query 'SELECT id, title, module, position, content, showtitle, control, params'
  260.             . ' FROM #__modules AS m'
  261.             . ' LEFT JOIN #__modules_menu AS mm ON mm.moduleid = m.id'
  262.             . ' WHERE m.published = 1'
  263.             . ' AND m.access <= '. (int)$aid
  264.             . ' AND m.client_id = '. (int)$mainframe->getClientId()
  265.             . $wheremenu
  266.             . ' ORDER BY position, ordering';
  267.  
  268.         $db->setQuery$query );
  269.  
  270.         if (!($modules $db->loadObjectList())) {
  271.             JError::raiseWarning'SOME_ERROR_CODE'"Error loading Modules: " $db->getErrorMsg());
  272.             return false;
  273.         }
  274.  
  275.         $total count($modules);
  276.         for($i 0$i $total$i++)
  277.         {
  278.             //determine if this is a custom module
  279.             $file                    $modules[$i]->module;
  280.             $custom                 substr$file0== 'mod_' ?  1;
  281.             $modules[$i]->user      $custom;
  282.             // CHECK: custom module name is given by the title field, otherwise it's just 'om' ??
  283.             $modules[$i]->name        $custom $modules[$i]->title substr$file);
  284.             $modules[$i]->style        null;
  285.             $modules[$i]->position    strtolower($modules[$i]->position);
  286.         }
  287.  
  288.         return $modules;
  289.     }
  290.  
  291. }

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