Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
module.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Document
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * JDocument Module renderer
14  *
15  * @package Joomla.Platform
16  * @subpackage Document
17  * @since 11.1
18  */
20 {
21  /**
22  * Renders a module script and returns the results as a string
23  *
24  * @param string $module The name of the module to render
25  * @param array $attribs Associative array of values
26  * @param string $content If present, module information from the buffer will be used
27  *
28  * @return string The output of the script
29  *
30  * @since 11.1
31  */
32  public function render($module, $attribs = array(), $content = null)
33  {
34  if (!is_object($module))
35  {
36  $title = isset($attribs['title']) ? $attribs['title'] : null;
37 
38  $module = JModuleHelper::getModule($module, $title);
39 
40  if (!is_object($module))
41  {
42  if (is_null($content))
43  {
44  return '';
45  }
46  else
47  {
48  /**
49  * If module isn't found in the database but data has been pushed in the buffer
50  * we want to render it
51  */
52  $tmp = $module;
53  $module = new stdClass;
54  $module->params = null;
55  $module->module = $tmp;
56  $module->id = 0;
57  $module->user = 0;
58  }
59  }
60  }
61 
62  // Get the user and configuration object
63  // $user = JFactory::getUser();
64  $conf = JFactory::getConfig();
65 
66  // Set the module content
67  if (!is_null($content))
68  {
69  $module->content = $content;
70  }
71 
72  // Get module parameters
73  $params = new JRegistry;
74  $params->loadString($module->params);
75 
76  // Use parameters from template
77  if (isset($attribs['params']))
78  {
79  $template_params = new JRegistry;
80  $template_params->loadString(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8'));
81  $params->merge($template_params);
82  $module = clone $module;
83  $module->params = (string) $params;
84  }
85 
86  // Default for compatibility purposes. Set cachemode parameter or use JModuleHelper::moduleCache from within the
87  // module instead
88  $cachemode = $params->get('cachemode', 'oldstatic');
89 
90  if ($params->get('cache', 0) == 1 && $conf->get('caching') >= 1 && $cachemode != 'id' && $cachemode != 'safeuri')
91  {
92 
93  // Default to itemid creating method and workarounds on
94  $cacheparams = new stdClass;
95  $cacheparams->cachemode = $cachemode;
96  $cacheparams->class = 'JModuleHelper';
97  $cacheparams->method = 'renderModule';
98  $cacheparams->methodparams = array($module, $attribs);
99 
100  $contents = JModuleHelper::ModuleCache($module, $params, $cacheparams);
101 
102  }
103  else
104  {
105  $contents = JModuleHelper::renderModule($module, $attribs);
106  }
107 
108  return $contents;
109  }
110 }