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

/src/site/components/com_base/templates/filters/module.php

https://github.com/bhar1red/anahita
PHP | 94 lines | 45 code | 10 blank | 39 comment | 4 complexity | bdf3f8c6f15accdd0df2ac3bf87e2aff MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * LICENSE: ##LICENSE##
  4. *
  5. * @category Anahita
  6. * @package Com_Base
  7. * @subpackage Template_Filter
  8. * @author Arash Sanieyan <ash@anahitapolis.com>
  9. * @author Rastin Mehr <rastin@anahitapolis.com>
  10. * @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc
  11. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html>
  12. * @version SVN: $Id: view.php 13650 2012-04-11 08:56:41Z asanieyan $
  13. * @link http://www.anahitapolis.com
  14. */
  15. /**
  16. * Module Filter
  17. *
  18. * @category Anahita
  19. * @package Com_Base
  20. * @subpackage Template_Filter
  21. * @author Arash Sanieyan <ash@anahitapolis.com>
  22. * @author Rastin Mehr <rastin@anahitapolis.com>
  23. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html>
  24. * @link http://www.anahitapolis.com
  25. */
  26. class ComBaseTemplateFilterModule extends KTemplateFilterAbstract implements KTemplateFilterWrite
  27. {
  28. /**
  29. * Initializes the options for the object
  30. *
  31. * Called from {@link __construct()} as a first step of object instantiation.
  32. *
  33. * @param object An optional KConfig object with configuration options
  34. * @return void
  35. */
  36. protected function _initialize(KConfig $config)
  37. {
  38. jimport('joomla.application.module.helper');
  39. $config->append(array(
  40. 'priority' => KCommand::PRIORITY_LOW,
  41. ));
  42. parent::_initialize($config);
  43. }
  44. /**
  45. * Find any <module></module> elements and inject them into the JDocument object
  46. *
  47. * @param string Block of text to parse
  48. *
  49. * @return void
  50. */
  51. public function write(&$text)
  52. {
  53. $matches = array();
  54. if ( KRequest::type() == 'AJAX' )
  55. return;
  56. if(preg_match_all('#<module([^>]*)>(.*)</module>#siU', $text, $matches))
  57. {
  58. $modules = array();
  59. foreach($matches[0] as $key => $match)
  60. {
  61. $text = str_replace($match, '', $text);
  62. $attributes = array(
  63. 'style' => 'component',
  64. 'params' => '',
  65. 'title' => '',
  66. 'class' => '',
  67. 'prepend' => true
  68. );
  69. $attributes = array_merge($attributes, $this->_parseAttributes($matches[1][$key]));
  70. if ( !empty($attributes['class']) ) {
  71. $attributes['params'] .= ' moduleclass_sfx= '.$attributes['class'];
  72. }
  73. JModuleHelper::addDynamicModule(array(
  74. 'content' => $matches[2][$key],
  75. 'position' => $attributes['position'],
  76. 'params' => $attributes['params'],
  77. 'title' => $attributes['title'],
  78. 'attribs' => $attributes
  79. ));
  80. }
  81. }
  82. return $this;
  83. }
  84. }