CoreFiles by mySites.guru
loadmodule.php66 lines, 2,084 bytes, from Joomla_1.6.1-Stable-Full_Package.zip
Raw History Compare with 1.6.0
md5
8e97ca307e42e555183acc6883d45a17
sha1
a4036c07d28393911e99e59dead92f559d5e2896
sha256
a46fea3b551bbb2b799abe35070d15b1ce4f3e0c54451dbbe0da8696c50790dc
<?php
/**
 * @version		$Id: loadmodule.php 20196 2011-01-09 02:40:25Z ian $
 * @package		Joomla
 * @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 2 releases, Joomla 1.6.0 to 1.6.1. See them all, or every version of this file.