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

Documentation is available at helper.php

  1. <?php
  2. /**
  3. @version        $Id: helper.php 6674 2007-02-19 05:52:03Z Jinx $
  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. // 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 <[email protected]>
  26. @package        Joomla.Framework
  27. @subpackage    Application
  28. @since        1.5
  29. */
  30. {
  31.     /**
  32.      * Get module by name
  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.  
  42.         $modules =JModuleHelper::_load();
  43.  
  44.         $total count($modules);
  45.         for ($i 0$i $total$i++{
  46.             if ($modules[$i]->name == $name)
  47.             {
  48.                 $result =$modules[$i];
  49.                 break;
  50.             }
  51.         }
  52.  
  53.         return $result;
  54.     }
  55.  
  56.     /**
  57.      * Get modules by position
  58.      *
  59.      * @access public
  60.      * @param string     $position    The position of the module
  61.      * @return array    An array of module objects
  62.      */
  63.     function &getModules($position)
  64.     {
  65.         $position    strtolower$position );
  66.         $result        array();
  67.  
  68.         $modules =JModuleHelper::_load();
  69.  
  70.         $total count($modules);
  71.         for($i 0$i $total$i++{
  72.             if($modules[$i]->position == $position{
  73.                 $result[=$modules[$i];
  74.             }
  75.         }
  76.  
  77.         return $result;
  78.     }
  79.  
  80.     function renderModule($module$attribs array())
  81.     {
  82.         static $chrome;
  83.         global $mainframe$option;
  84.  
  85.         // Handle legacy globals if enabled
  86.         if ($mainframe->getCfg('legacy'))
  87.         {
  88.             // Include legacy globals
  89.             global $my$database$acl;
  90.  
  91.             // Get the task variable for local scope
  92.             $task JRequest::getVar'task' );
  93.  
  94.             // For backwards compatibility extract the config vars as globals
  95.             $registry =JFactory::getConfig();
  96.             foreach (get_object_vars($registry->toObject()) as $k => $v{
  97.                 $name 'mosConfig_'.$k;
  98.                 $$name $v;
  99.             }
  100.             $contentConfig &JComponentHelper::getParams'com_content' );
  101.             foreach (get_object_vars($contentConfig->toObject()) as $k => $v)
  102.             {
  103.                 $name 'mosConfig_'.$k;
  104.                 $$name $v;
  105.             }
  106.             $usersConfig &JComponentHelper::getParams'com_users' );
  107.             foreach (get_object_vars($usersConfig->toObject()) as $k => $v)
  108.             {
  109.                 $name 'mosConfig_'.$k;
  110.                 $$name $v;
  111.             }
  112.         }
  113.  
  114.         // Get module parameters
  115.         $params new JParameter$module->params );
  116.  
  117.         // Get module path
  118.         $path JPATH_BASE.'/modules/'.$module->module.'/'.$module->module.'.php';
  119.  
  120.         // Load the module
  121.         if (!$module->user && file_exists$path && empty($module->content))
  122.         {
  123.             $lang =JFactory::getLanguage();
  124.             $lang->load($module->module);
  125.  
  126.             ob_start();
  127.             require $path;
  128.             $module->content ob_get_contents();
  129.             ob_end_clean();
  130.         }
  131.  
  132.         // Load the module chrome functions
  133.         if (!$chrome{
  134.             $chrome array();
  135.         }
  136.  
  137.         require_once (JPATH_BASE.'/modules/templates/modules.php');
  138.         $chromePath JPATH_BASE.'/templates/'.$mainframe->getTemplate().'/html/modules.php';
  139.         if (!isset$chrome[$chromePath]))
  140.         {
  141.             if (file_exists($chromePath)) {
  142.                 require_once ($chromePath);
  143.             }
  144.             $chrome[$chromePathtrue;
  145.         }
  146.  
  147.         //make sure a style is set
  148.         if(!isset($attribs['style'])) {
  149.             $attribs['style''none';
  150.         }
  151.  
  152.         //dynamically add outline style
  153.         if(JRequest::getVar('tp')) {
  154.             $attribs['style'.= ' outline';
  155.         }
  156.  
  157.         foreach(explode(' '$attribs['style']as $style)
  158.         {
  159.             $chromeMethod 'modChrome_'.$style;
  160.  
  161.             // Apply chrome and render module
  162.             if (function_exists($chromeMethod))
  163.             {
  164.                 $module->style $attribs['style'];
  165.  
  166.                 ob_start();
  167.                 $chromeMethod($module$params$attribs);
  168.                 $module->content ob_get_contents();
  169.                 ob_end_clean();
  170.             }
  171.         }
  172.  
  173.         return $module->content;
  174.     }
  175.  
  176.     /**
  177.      * Get the path to a layout for a module
  178.      *
  179.      * @static
  180.      * @param    string    $module    The name of the module
  181.      * @param    string    $layout    The name of the module layout
  182.      * @return    string    The path to the module layout
  183.      * @since    1.5
  184.      */
  185.     function getLayoutPath($module$layout 'default')
  186.     {
  187.         global $mainframe;
  188.  
  189.         // Build the template and base path for the layout
  190.         $tPath JPATH_BASE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.$module.DS.$layout.'.php';
  191.         $bPath JPATH_BASE.DS.'modules'.DS.$module.DS.'tmpl'.DS.$layout.'.php';
  192.  
  193.         // If the template has a layout override use it
  194.         if (file_exists($tPath)) {
  195.             return $tPath;
  196.         else {
  197.             return $bPath;
  198.         }
  199.     }
  200.  
  201.     /**
  202.      * Load published modules
  203.      *
  204.      * @access    private
  205.      * @return    array 
  206.      */
  207.     function &_load()
  208.     {
  209.         global $mainframe$Itemid;
  210.  
  211.         static $modules;
  212.  
  213.         if (isset($modules)) {
  214.             return $modules;
  215.         }
  216.  
  217.         $user    =JFactory::getUser();
  218.         $db        =JFactory::getDBO();
  219.  
  220.         $aid    $user->get('aid'0);
  221.  
  222.         $modules    array();
  223.  
  224.         $wheremenu = isset$Itemid ' AND ( mm.menuid = '$Itemid .' OR mm.menuid = 0 )' '';
  225.  
  226.         $query 'SELECT id, title, module, position, content, showtitle, control, params'
  227.             . ' FROM #__modules AS m'
  228.             . ' LEFT JOIN #__modules_menu AS mm ON mm.moduleid = m.id'
  229.             . ' WHERE m.published = 1'
  230.             . ' AND m.access <= '. (int)$aid
  231.             . ' AND m.client_id = '. (int)$mainframe->getClientId()
  232.             . $wheremenu
  233.             . ' ORDER BY position, ordering';
  234.  
  235.         $db->setQuery$query );
  236.         $modules $db->loadObjectList();
  237.  
  238.         $total count($modules);
  239.         for($i 0$i $total$i++)
  240.         {
  241.             //determine if this is a custom module
  242.             $file                    $modules[$i]->module;
  243.             $custom                 substr$file0== 'mod_' ?  1;
  244.             $modules[$i]->user      $custom;
  245.             // CHECK: custom module name is given by the title field, otherwise it's just 'om' ??
  246.             $modules[$i]->name        $custom $modules[$i]->title substr$file);
  247.             $modules[$i]->style        null;
  248.             $modules[$i]->position    strtolower($modules[$i]->position);
  249.         }
  250.  
  251.         return $modules;
  252.     }
  253. }
  254. ?>

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