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

/plugins/content/loadmodule/loadmodule.php

https://github.com/joebushi/joomla
PHP | 55 lines | 33 code | 8 blank | 14 comment | 1 complexity | 9b898453a28361bf1b1548f73d732c23 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla
  5. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE.txt
  7. */
  8. // no direct access
  9. defined('_JEXEC') or die;
  10. jimport('joomla.plugin.plugin');
  11. class plgContentLoadmodule extends JPlugin
  12. {
  13. /**
  14. * Plugin that loads module positions within content
  15. */
  16. public function onPrepareContent(&$article, &$params, $page = 0)
  17. {
  18. // simple performance check to determine whether bot should process further
  19. if (strpos($article->text, 'loadposition') === false) {
  20. return true;
  21. }
  22. // expression to search for
  23. $regex = '/{loadposition\s+(.*?)}/i';
  24. $matches = array();
  25. $style = $this->params->def('style', 'none');
  26. // find all instances of plugin and put in $matches
  27. preg_match_all($regex, $article->text, $matches, PREG_SET_ORDER);
  28. foreach ($matches as $match) {
  29. // $match[0] is full pattern match, $match[1] is the position
  30. $output = $this->_load($match[1], $style);
  31. $article->text = str_replace($match[0], $output, $article->text);
  32. }
  33. }
  34. protected function _load($position, $style = 'none')
  35. {
  36. $document = &JFactory::getDocument();
  37. $renderer = $document->loadRenderer('module');
  38. $modules = JModuleHelper::getModules($position);
  39. $params = array('style' => $style);
  40. ob_start();
  41. foreach ($modules as $module) {
  42. echo $renderer->render($module, $params);
  43. }
  44. $output = ob_get_clean();
  45. return $output;
  46. }
  47. }