1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Document
5 *
6 * @copyright Copyright (C) 2005 - 2017 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 use Joomla\Registry\Registry;
13
14 /**
15 * JDocument Module renderer
16 *
17 * @since 3.5
18 */
19 class JDocumentRendererHtmlModule extends JDocumentRenderer
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 3.5
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
47 /**
48 * If module isn't found in the database but data has been pushed in the buffer
49 * we want to render it
50 */
51 $tmp = $module;
52 $module = new stdClass;
53 $module->params = null;
54 $module->module = $tmp;
55 $module->id = 0;
56 $module->user = 0;
57 }
58 }
59
60 // Set the module content
61 if (!is_null($content))
62 {
63 $module->content = $content;
64 }
65
66 // Get module parameters
67 $params = new Registry($module->params);
68
69 // Use parameters from template
70 if (isset($attribs['params']))
71 {
72 $template_params = new Registry(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8'));
73 $params->merge($template_params);
74 $module = clone $module;
75 $module->params = (string) $params;
76 }
77
78 // Default for compatibility purposes. Set cachemode parameter or use JModuleHelper::moduleCache from within the module instead
79 $cachemode = $params->get('cachemode', 'oldstatic');
80
81 if ($params->get('cache', 0) == 1 && JFactory::getConfig()->get('caching') >= 1 && $cachemode != 'id' && $cachemode != 'safeuri')
82 {
83 // Default to itemid creating method and workarounds on
84 $cacheparams = new stdClass;
85 $cacheparams->cachemode = $cachemode;
86 $cacheparams->class = 'JModuleHelper';
87 $cacheparams->method = 'renderModule';
88 $cacheparams->methodparams = array($module, $attribs);
89
90 return JModuleHelper::ModuleCache($module, $params, $cacheparams);
91 }
92
93 return JModuleHelper::renderModule($module, $attribs);
94 }
95 }
96