PageRenderTime 39ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/nooku/site/components/com_default/templates/filters/module.php

https://github.com/bhar1red/anahita
PHP | 130 lines | 66 code | 14 blank | 50 comment | 4 complexity | 8a1407c90d8ca2cc5ad2eda6e667cbe3 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: module.php 4628 2012-05-06 19:56:43Z johanjanssens $
  4. * @package Nooku_Components
  5. * @subpackage Default
  6. * @copyright Copyright (C) 2007 - 2012 Johan Janssens. All rights reserved.
  7. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
  8. * @link http://www.nooku.org
  9. */
  10. /**
  11. * Module Template Filter
  12. *
  13. * This filter allow to dynamically inject data into module position.
  14. *
  15. * Filter will parse elements of the form <modules position="[position]">[content]</modules>
  16. * and prepend or append the content to the module position.
  17. *
  18. * @author Johan Janssens <johan@nooku.org>
  19. * @package Nooku_Components
  20. * @subpackage Default
  21. */
  22. class ComDefaultTemplateFilterModule extends KTemplateFilterAbstract implements KTemplateFilterWrite
  23. {
  24. /**
  25. * Initializes the options for the object
  26. *
  27. * Called from {@link __construct()} as a first step of object instantiation.
  28. *
  29. * @param object An optional KConfig object with configuration options
  30. * @return void
  31. */
  32. protected function _initialize(KConfig $config)
  33. {
  34. $config->append(array(
  35. 'priority' => KCommand::PRIORITY_LOW,
  36. ));
  37. parent::_initialize($config);
  38. }
  39. /**
  40. * Find any <module></module> elements and inject them into the JDocument object
  41. *
  42. * @param string Block of text to parse
  43. * @return ComDefaultTemplateFilterModule
  44. */
  45. public function write(&$text)
  46. {
  47. $matches = array();
  48. if(preg_match_all('#<module([^>]*)>(.*)</module>#siU', $text, $matches))
  49. {
  50. foreach($matches[0] as $key => $match)
  51. {
  52. //Remove placeholder
  53. $text = str_replace($match, '', $text);
  54. //Create attributes array
  55. $attributes = array(
  56. 'style' => 'component',
  57. 'params' => '',
  58. 'title' => '',
  59. 'class' => '',
  60. 'prepend' => true
  61. );
  62. $attributes = array_merge($attributes, $this->_parseAttributes($matches[1][$key]));
  63. //Create module object
  64. $module = new KObject();
  65. $module->id = uniqid();
  66. $module->content = $matches[2][$key];
  67. $module->position = $attributes['position'];
  68. $module->params = $attributes['params'];
  69. $module->showtitle = !empty($attributes['title']);
  70. $module->title = $attributes['title'];
  71. $module->attribs = $attributes;
  72. $module->user = 0;
  73. $module->module = 'mod_dynamic';
  74. JFactory::getDocument()->modules[$attributes['position']][] = $module;
  75. }
  76. }
  77. return $this;
  78. }
  79. }
  80. /**
  81. * Modules Renderer
  82. *
  83. * This is a specialised modules renderer which prepends or appends the dynamically created modules
  84. * to the list of modules before rendering them.
  85. .*
  86. * @author Johan Janssens <johan@nooku.org>
  87. * @package Nooku_Components
  88. * @subpackage Default
  89. */
  90. class JDocumentRendererModules extends JDocumentRenderer
  91. {
  92. public function render( $position, $params = array(), $content = null )
  93. {
  94. //Get the modules
  95. $modules = JModuleHelper::getModules($position);
  96. if(isset($this->_doc->modules[$position]))
  97. {
  98. foreach($this->_doc->modules[$position] as $module)
  99. {
  100. if($module->attribs['prepend']) {
  101. array_push($modules, $module);
  102. } else {
  103. array_unshift($modules, $module);
  104. }
  105. }
  106. }
  107. //Render the modules
  108. $renderer = $this->_doc->loadRenderer('module');
  109. $contents = '';
  110. foreach ($modules as $module) {
  111. $contents .= $renderer->render($module, $params, $content);
  112. }
  113. return $contents;
  114. }
  115. }