PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/bhar1red/anahita
PHP | 141 lines | 74 code | 16 blank | 51 comment | 2 complexity | d034099a882f49ae0da79baf648a7d0b 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. 'content' => 'prepend'
  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. //Store the module for rendering
  75. JFactory::getDocument()->modules[$attributes['position']][] = $module;
  76. }
  77. }
  78. return $this;
  79. }
  80. }
  81. /**
  82. * Modules Renderer
  83. *
  84. * This is a specialised modules renderer which prepends or appends the dynamically created modules
  85. * to the list of modules before rendering them.
  86. .*
  87. * @author Johan Janssens <johan@nooku.org>
  88. * @category Nooku
  89. * @package Nooku_Components
  90. * @subpackage Default
  91. */
  92. class JDocumentRendererModules extends JDocumentRenderer
  93. {
  94. public function render( $position, $params = array(), $content = null )
  95. {
  96. //Get the modules
  97. $modules = JModuleHelper::getModules($position);
  98. if(isset($this->_doc->modules[$position]))
  99. {
  100. foreach($this->_doc->modules[$position] as $module)
  101. {
  102. switch($module->attribs['content'])
  103. {
  104. case 'append' :
  105. array_unshift($modules, $module);
  106. break;
  107. case 'replace' :
  108. unset($modules);
  109. $modules[] = $module;
  110. break;
  111. case 'prepend' :
  112. default :
  113. array_push($modules, $module);
  114. }
  115. }
  116. }
  117. //Render the modules
  118. $renderer = $this->_doc->loadRenderer('module');
  119. $contents = $content;
  120. foreach ($modules as $module) {
  121. $contents .= $renderer->render($module, $params, $content);
  122. }
  123. return $contents;
  124. }
  125. }