[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Document\Renderer\Html; 11 12 use Joomla\CMS\Document\DocumentRenderer; 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Helper\ModuleHelper; 15 use Joomla\Registry\Registry; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('JPATH_PLATFORM') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * HTML document renderer for a single module 23 * 24 * @since 3.5 25 */ 26 class ModuleRenderer extends DocumentRenderer 27 { 28 /** 29 * Renders a module script and returns the results as a string 30 * 31 * @param string $module The name of the module to render 32 * @param array $attribs Associative array of values 33 * @param string $content If present, module information from the buffer will be used 34 * 35 * @return string The output of the script 36 * 37 * @since 3.5 38 */ 39 public function render($module, $attribs = array(), $content = null) 40 { 41 if (!\is_object($module)) { 42 $title = $attribs['title'] ?? null; 43 44 $module = ModuleHelper::getModule($module, $title); 45 46 if (!\is_object($module)) { 47 if (\is_null($content)) { 48 return ''; 49 } 50 51 /** 52 * If module isn't found in the database but data has been pushed in the buffer 53 * we want to render it 54 */ 55 $tmp = $module; 56 $module = new \stdClass(); 57 $module->params = null; 58 $module->module = $tmp; 59 $module->id = 0; 60 $module->user = 0; 61 } 62 } 63 64 // Set the module content 65 if (!\is_null($content)) { 66 $module->content = $content; 67 } 68 69 // Get module parameters 70 $params = new Registry($module->params); 71 72 // Use parameters from template 73 if (isset($attribs['params'])) { 74 $template_params = new Registry(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8')); 75 $params->merge($template_params); 76 $module = clone $module; 77 $module->params = (string) $params; 78 } 79 80 // Set cachemode parameter or use JModuleHelper::moduleCache from within the module instead 81 $cachemode = $params->get('cachemode', 'static'); 82 83 if ($params->get('cache', 0) == 1 && Factory::getApplication()->get('caching') >= 1 && $cachemode !== 'id' && $cachemode !== 'safeuri') { 84 // Default to itemid creating method and workarounds on 85 $cacheparams = new \stdClass(); 86 $cacheparams->cachemode = $cachemode; 87 $cacheparams->class = ModuleHelper::class; 88 $cacheparams->method = 'renderModule'; 89 $cacheparams->methodparams = array($module, $attribs); 90 $cacheparams->cachesuffix = $attribs['contentOnly'] ?? false; 91 92 // It need to be done here because the cache controller does not keep reference to the module object 93 $module->content = ModuleHelper::moduleCache($module, $params, $cacheparams); 94 $module->contentRendered = true; 95 96 return $module->content; 97 } 98 99 return ModuleHelper::renderModule($module, $attribs); 100 } 101 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |