/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. defined('JPATH_PLATFORM') or die;
  10. use Joomla\Registry\Registry;
  11. /**
  12. * JDocument Module renderer
  13. *
  14. * @since 11.1
  15. */
  16. class JDocumentRendererModule extends JDocumentRenderer
  17. {
  18. /**
  19. * Renders a module script and returns the results as a string
  20. *
  21. * @param string $module The name of the module to render
  22. * @param array $attribs Associative array of values
  23. * @param string $content If present, module information from the buffer will be used
  24. *
  25. * @return string The output of the script
  26. *
  27. * @since 11.1
  28. */
  29. public function render($module, $attribs = array(), $content = null)
  30. {
  31. if (!is_object($module))
  32. {
  33. $title = isset($attribs['title']) ? $attribs['title'] : null;
  34. $module = JModuleHelper::getModule($module, $title);
  35. if (!is_object($module))
  36. {
  37. if (is_null($content))
  38. {
  39. return '';
  40. }
  41. else
  42. {
  43. /**
  44. * If module isn't found in the database but data has been pushed in the buffer
  45. * we want to render it
  46. */
  47. $tmp = $module;
  48. $module = new stdClass;
  49. $module->params = null;
  50. $module->module = $tmp;
  51. $module->id = 0;
  52. $module->user = 0;
  53. }
  54. }
  55. }
  56. // Get the user and configuration object
  57. // $user = JFactory::getUser();
  58. $conf = JFactory::getConfig();
  59. // Set the module content
  60. if (!is_null($content))
  61. {
  62. $module->content = $content;
  63. }
  64. // Get module parameters
  65. $params = new Registry;
  66. $params->loadString($module->params);
  67. // Use parameters from template
  68. if (isset($attribs['params']))
  69. {
  70. $template_params = new Registry;
  71. $template_params->loadString(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8'));
  72. $params->merge($template_params);
  73. $module = clone $module;
  74. $module->params = (string) $params;
  75. }
  76. // Default for compatibility purposes. Set cachemode parameter or use JModuleHelper::moduleCache from within the
  77. // module instead
  78. $cachemode = $params->get('cachemode', 'oldstatic');
  79. if ($params->get('cache', 0) == 1 && $conf->get('caching') >= 1 && $cachemode != 'id' && $cachemode != 'safeuri')
  80. {
  81. // Default to itemid creating method and workarounds on
  82. $cacheparams = new stdClass;
  83. $cacheparams->cachemode = $cachemode;
  84. $cacheparams->class = 'JModuleHelper';
  85. $cacheparams->method = 'renderModule';
  86. $cacheparams->methodparams = array($module, $attribs);
  87. $contents = JModuleHelper::ModuleCache($module, $params, $cacheparams);
  88. }
  89. else
  90. {
  91. $contents = JModuleHelper::renderModule($module, $attribs);
  92. }
  93. return $contents;
  94. }
  95. }