Support Joomla!

Packages

Package: Joomla-Framework

License

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

Documentation generated on Sat, 14 Nov 2009 11:14:32 +0000 by phpDocumentor 1.3.1