- md5
- 2a5ab5faec8b1064b3cd9c1361029b26
- sha1
- 9bec4bdfcb3f9abfbe5845845b5a1b1ff8985ba8
- sha256
- 3e25247078d7dc36889837f04caaa0e511eb56e3a21e12002d90e28cf95f8757
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
<?php
/**
* @version $Id: loadmodule.php 21097 2011-04-07 15:38:03Z dextercowley $
* @package Joomla.Plugin
* @subpackage Content.loadmodule
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// no direct access
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
class plgContentLoadmodule extends JPlugin
{
protected static $modules=array();
/**
* Plugin that loads module positions within content
*
* @param string The context of the content being passed to the plugin.
* @param object The article object. Note $article->text is also available
* @param object The article params
* @param int The 'page' number
*/
public function onContentPrepare($context, &$article, &$params, $page = 0)
{
// simple performance check to determine whether bot should process further
if (strpos($article->text, 'loadposition') === false) {
return true;
}
// expression to search for
$regex = '/{loadposition\s+(.*?)}/i';
$matches = array();
$style = $this->params->def('style', 'none');
// find all instances of plugin and put in $matches
preg_match_all($regex, $article->text, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
// $match[0] is full pattern match, $match[1] is the position
$output = $this->_load($match[1], $style);
// We should replace only first occurrence in order to allow positions with the same name to regenerate their content:
$article->text = preg_replace("|$match[0]|", $output, $article->text, 1);
}
}
protected function _load($position, $style = 'none')
{
if (!isset(self::$modules[$position])) {
self::$modules[$position] = '';
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$modules = JModuleHelper::getModules($position);
$params = array('style' => $style);
ob_start();
foreach ($modules as $module) {
echo $renderer->render($module, $params);
}
self::$modules[$position] = ob_get_clean();
}
return self::$modules[$position];
}
}
The same content is in 5 releases, Joomla 1.6.2 to 1.6.6. See them all, or every version of this file.