API15

JModuleHelper/renderModule: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Render the module. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> ...
 
Doxiki (talk | contribs)
No edit summary
Line 1: Line 1:
===Description===
Render the module.


<span class="editsection" style="font-size:76%;">
<span class="editsection" style="font-size:76%;">
Line 9: Line 7:


===Syntax===
===Syntax===
<source lang="php">static renderModule($module, $attribs=array())</source>
<source lang="php">renderModule($module, $attribs=array())</source>


  {| class="wikitable"
  {| class="wikitable"
Line 19: Line 17:
| $module
| $module
|  
|  
A module object.
|   
|-
|-
| $attribs
| $attribs
| array()
| array()
An array of attributes for the module (probably from the XML).
|   
|}
|}
===Returns===
strign The HTML content of the module output.


===Defined in===
===Defined in===
Line 36: Line 31:
===Source Body===
===Source Body===
<source lang="php">
<source lang="php">
public static function renderModule($module, $attribs = array())
function renderModule($module, $attribs = array())
{
{
         static $chrome;
         static $chrome;
        global $mainframe, $option;


         $option = JRequest::getCmd('option');
         $scope = $mainframe->scope; //record the scope
         $app    = &JFactory::getApplication();
         $mainframe->scope = $module->module; //set scope to component name


         // Record the scope.
         // Handle legacy globals if enabled
         $scope  = $app->scope;
         if ($mainframe->getCfg('legacy'))
        {
                // Include legacy globals
                global $my, $database, $acl, $mosConfig_absolute_path;


        // Set scope to component name
                // Get the task variable for local scope
        $app->scope = $module->module;
                $task = JRequest::getString('task');
 
                // For backwards compatibility extract the config vars as globals
                $registry =& JFactory::getConfig();
                foreach (get_object_vars($registry->toObject()) as $k => $v) {
                        $name = 'mosConfig_'.$k;
                        $$name = $v;
                }
                $contentConfig = &JComponentHelper::getParams( 'com_content' );
                foreach (get_object_vars($contentConfig->toObject()) as $k => $v)
                {
                        $name = 'mosConfig_'.$k;
                        $$name = $v;
                }
                $usersConfig = &JComponentHelper::getParams( 'com_users' );
                foreach (get_object_vars($usersConfig->toObject()) as $k => $v)
                {
                        $name = 'mosConfig_'.$k;
                        $$name = $v;
                }
        }


         // Get module parameters
         // Get module parameters
         $params = new JParameter($module->params);
         $params = new JParameter( $module->params );


         // Get module path
         // Get module path
         $module->module = preg_replace('/[^A-Z0-9_\.-]/i', '', $module->module);
         $module->module = preg_replace('/[^A-Z0-9_\.-]/i', '', $module->module);
         $path = JPATH_BASE.'/modules/'.$module->module.'/'.$module->module.'.php';
         $path = JPATH_BASE.DS.'modules'.DS.$module->module.DS.$module->module.'.php';


         // Load the module
         // Load the module
         if (!$module->user && file_exists($path))
         if (!$module->user && file_exists( $path ) && empty($module->content))
         {
         {
                 $lang = &JFactory::getLanguage();
                 $lang =& JFactory::getLanguage();
                // 1.5 or Core
                 $lang->load($module->module);
                 $lang->load($module->module);
                // 1.6 3PD
                $lang->load($module->module, dirname($path));


                 $content = '';
                 $content = '';
Line 77: Line 93:
         }
         }


         require_once JPATH_BASE.'/templates/system/html/modules.php';
         require_once (JPATH_BASE.DS.'templates'.DS.'system'.DS.'html'.DS.'modules.php');
         $chromePath = JPATH_BASE.'/templates/'.$app->getTemplate().'/html/modules.php';
         $chromePath = JPATH_BASE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'modules.php';
         if (!isset($chrome[$chromePath]))
         if (!isset( $chrome[$chromePath]))
         {
         {
                 if (file_exists($chromePath)) {
                 if (file_exists($chromePath)) {
                         require_once $chromePath;
                         require_once ($chromePath);
                 }
                 }
                 $chrome[$chromePath] = true;
                 $chrome[$chromePath] = true;
Line 88: Line 104:


         //make sure a style is set
         //make sure a style is set
         if (!isset($attribs['style'])) {
         if(!isset($attribs['style'])) {
                 $attribs['style'] = 'none';
                 $attribs['style'] = 'none';
         }
         }


         //dynamically add outline style
         //dynamically add outline style
         if ($app->getCfg('debug_modules') && JRequest::getBool('tp')) {
         if(JRequest::getBool('tp')) {
                 $attribs['style'] .= ' outline';
                 $attribs['style'] .= ' outline';
         }
         }
Line 113: Line 129:
         }
         }


         $app->scope = $scope; //revert the scope
         $mainframe->scope = $scope; //revert the scope


         return $module->content;
         return $module->content;

Revision as of 22:09, 22 March 2010

[Edit Descripton]

Template:Description:JModuleHelper/renderModule

Syntax

renderModule($module, $attribs=array())
Parameter Name Default Value Description
$module
$attribs array()

Defined in

libraries/joomla/application/module/helper.php

Importing

jimport( 'joomla.application.module.helper' );

Source Body

function renderModule($module, $attribs = array())
{
        static $chrome;
        global $mainframe, $option;

        $scope = $mainframe->scope; //record the scope
        $mainframe->scope = $module->module;  //set scope to component name

        // Handle legacy globals if enabled
        if ($mainframe->getCfg('legacy'))
        {
                // Include legacy globals
                global $my, $database, $acl, $mosConfig_absolute_path;

                // Get the task variable for local scope
                $task = JRequest::getString('task');

                // For backwards compatibility extract the config vars as globals
                $registry =& JFactory::getConfig();
                foreach (get_object_vars($registry->toObject()) as $k => $v) {
                        $name = 'mosConfig_'.$k;
                        $$name = $v;
                }
                $contentConfig = &JComponentHelper::getParams( 'com_content' );
                foreach (get_object_vars($contentConfig->toObject()) as $k => $v)
                {
                        $name = 'mosConfig_'.$k;
                        $$name = $v;
                }
                $usersConfig = &JComponentHelper::getParams( 'com_users' );
                foreach (get_object_vars($usersConfig->toObject()) as $k => $v)
                {
                        $name = 'mosConfig_'.$k;
                        $$name = $v;
                }
        }

        // Get module parameters
        $params = new JParameter( $module->params );

        // Get module path
        $module->module = preg_replace('/[^A-Z0-9_\.-]/i', '', $module->module);
        $path = JPATH_BASE.DS.'modules'.DS.$module->module.DS.$module->module.'.php';

        // Load the module
        if (!$module->user && file_exists( $path ) && empty($module->content))
        {
                $lang =& JFactory::getLanguage();
                $lang->load($module->module);

                $content = '';
                ob_start();
                require $path;
                $module->content = ob_get_contents().$content;
                ob_end_clean();
        }

        // Load the module chrome functions
        if (!$chrome) {
                $chrome = array();
        }

        require_once (JPATH_BASE.DS.'templates'.DS.'system'.DS.'html'.DS.'modules.php');
        $chromePath = JPATH_BASE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'modules.php';
        if (!isset( $chrome[$chromePath]))
        {
                if (file_exists($chromePath)) {
                        require_once ($chromePath);
                }
                $chrome[$chromePath] = true;
        }

        //make sure a style is set
        if(!isset($attribs['style'])) {
                $attribs['style'] = 'none';
        }

        //dynamically add outline style
        if(JRequest::getBool('tp')) {
                $attribs['style'] .= ' outline';
        }

        foreach(explode(' ', $attribs['style']) as $style)
        {
                $chromeMethod = 'modChrome_'.$style;

                // Apply chrome and render module
                if (function_exists($chromeMethod))
                {
                        $module->style = $attribs['style'];

                        ob_start();
                        $chromeMethod($module, $params, $attribs);
                        $module->content = ob_get_contents();
                        ob_end_clean();
                }
        }

        $mainframe->scope = $scope; //revert the scope

        return $module->content;
}

[Edit See Also] Template:SeeAlso:JModuleHelper/renderModule

Examples

<CodeExamplesForm />