PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/document/html/renderer/module.php

https://gitlab.com/vitaliylukin91/alex-lavka
PHP | 108 lines | 60 code | 13 blank | 35 comment | 12 complexity | b124e394d26c4807a1aaa7f180a86be0 MD5 | raw file
  1<?php
  2/**
  3 * @package     Joomla.Platform
  4 * @subpackage  Document
  5 *
  6 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
  7 * @license     GNU General Public License version 2 or later; see LICENSE
  8 */
  9
 10defined('JPATH_PLATFORM') or die;
 11
 12use Joomla\Registry\Registry;
 13
 14/**
 15 * JDocument Module renderer
 16 *
 17 * @since  11.1
 18 */
 19class JDocumentRendererModule 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   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 Registry;
 74		$params->loadString($module->params);
 75
 76		// Use parameters from template
 77		if (isset($attribs['params']))
 78		{
 79			$template_params = new Registry;
 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			// Default to itemid creating method and workarounds on
 93			$cacheparams = new stdClass;
 94			$cacheparams->cachemode = $cachemode;
 95			$cacheparams->class = 'JModuleHelper';
 96			$cacheparams->method = 'renderModule';
 97			$cacheparams->methodparams = array($module, $attribs);
 98
 99			$contents = JModuleHelper::ModuleCache($module, $params, $cacheparams);
100		}
101		else
102		{
103			$contents = JModuleHelper::renderModule($module, $attribs);
104		}
105
106		return $contents;
107	}
108}