Blame Identity/Models/Html/phpBB/3.0.4/includes/functions_module.php

d6e8d8
d6e8d8
/**
d6e8d8
*
d6e8d8
* @package phpBB3
d6e8d8
* @version $Id: functions_module.php 9095 2008-11-23 12:42:34Z acydburn $
d6e8d8
* @copyright (c) 2005 phpBB Group
d6e8d8
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
d6e8d8
*
d6e8d8
*/
d6e8d8
d6e8d8
/**
d6e8d8
* @ignore
d6e8d8
*/
d6e8d8
if (!defined('IN_PHPBB'))
d6e8d8
{
d6e8d8
	exit;
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
* Class handling all types of 'plugins' (a future term)
d6e8d8
* @package phpBB3
d6e8d8
*/
d6e8d8
class p_master
d6e8d8
{
d6e8d8
	var $p_id;
d6e8d8
	var $p_class;
d6e8d8
	var $p_name;
d6e8d8
	var $p_mode;
d6e8d8
	var $p_parent;
d6e8d8
d6e8d8
	var $include_path = false;
d6e8d8
	var $active_module = false;
d6e8d8
	var $active_module_row_id = false;
d6e8d8
	var $acl_forum_id = false;
d6e8d8
	var $module_ary = array();
d6e8d8
d6e8d8
	/**
d6e8d8
	* Constuctor
d6e8d8
	* Set module include path
d6e8d8
	*/
d6e8d8
	function p_master($include_path = false)
d6e8d8
	{
d6e8d8
		global $phpbb_root_path;
d6e8d8
d6e8d8
		$this->include_path = ($include_path !== false) ? $include_path : $phpbb_root_path . 'includes/';
d6e8d8
d6e8d8
		// Make sure the path ends with /
d6e8d8
		if (substr($this->include_path, -1) !== '/')
d6e8d8
		{
d6e8d8
			$this->include_path .= '/';
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Set custom include path for modules
d6e8d8
	* Schema for inclusion is include_path . modulebase
d6e8d8
	*
d6e8d8
	* @param string $include_path include path to be used.
d6e8d8
	* @access public
d6e8d8
	*/
d6e8d8
	function set_custom_include_path($include_path)
d6e8d8
	{
d6e8d8
		$this->include_path = $include_path;
d6e8d8
d6e8d8
		// Make sure the path ends with /
d6e8d8
		if (substr($this->include_path, -1) !== '/')
d6e8d8
		{
d6e8d8
			$this->include_path .= '/';
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* List modules
d6e8d8
	*
d6e8d8
	* This creates a list, stored in $this->module_ary of all available
d6e8d8
	* modules for the given class (ucp, mcp and acp). Additionally
d6e8d8
	* $this->module_y_ary is created with indentation information for
d6e8d8
	* displaying the module list appropriately. Only modules for which
d6e8d8
	* the user has access rights are included in these lists.
d6e8d8
	*/
d6e8d8
	function list_modules($p_class)
d6e8d8
	{
d6e8d8
		global $auth, $db, $user, $cache;
d6e8d8
		global $config, $phpbb_root_path, $phpEx;
d6e8d8
d6e8d8
		// Sanitise for future path use, it's escaped as appropriate for queries
d6e8d8
		$this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class));
d6e8d8
d6e8d8
		// Get cached modules
d6e8d8
		if (($this->module_cache = $cache->get('_modules_' . $this->p_class)) === false)
d6e8d8
		{
d6e8d8
			// Get modules
d6e8d8
			$sql = 'SELECT *
d6e8d8
				FROM ' . MODULES_TABLE . "
d6e8d8
				WHERE module_class = '" . $db->sql_escape($this->p_class) . "'
d6e8d8
				ORDER BY left_id ASC";
d6e8d8
			$result = $db->sql_query($sql);
d6e8d8
d6e8d8
			$rows = array();
d6e8d8
			while ($row = $db->sql_fetchrow($result))
d6e8d8
			{
d6e8d8
				$rows[$row['module_id']] = $row;
d6e8d8
			}
d6e8d8
			$db->sql_freeresult($result);
d6e8d8
d6e8d8
			$this->module_cache = array();
d6e8d8
			foreach ($rows as $module_id => $row)
d6e8d8
			{
d6e8d8
				$this->module_cache['modules'][] = $row;
d6e8d8
				$this->module_cache['parents'][$row['module_id']] = $this->get_parents($row['parent_id'], $row['left_id'], $row['right_id'], $rows);
d6e8d8
			}
d6e8d8
			unset($rows);
d6e8d8
d6e8d8
			$cache->put('_modules_' . $this->p_class, $this->module_cache);
d6e8d8
		}
d6e8d8
d6e8d8
		if (empty($this->module_cache))
d6e8d8
		{
d6e8d8
			$this->module_cache = array('modules' => array(), 'parents' => array());
d6e8d8
		}
d6e8d8
d6e8d8
		// We "could" build a true tree with this function - maybe mod authors want to use this...
d6e8d8
		// Functions for traversing and manipulating the tree are not available though
d6e8d8
		// We might re-structure the module system to use true trees in 3.2.x...
d6e8d8
		// $tree = $this->build_tree($this->module_cache['modules'], $this->module_cache['parents']);
d6e8d8
d6e8d8
		// Clean up module cache array to only let survive modules the user can access
d6e8d8
		$right_id = false;
d6e8d8
		foreach ($this->module_cache['modules'] as $key => $row)
d6e8d8
		{
d6e8d8
			// Not allowed to view module?
d6e8d8
			if (!$this->module_auth($row['module_auth']))
d6e8d8
			{
d6e8d8
				unset($this->module_cache['modules'][$key]);
d6e8d8
				continue;
d6e8d8
			}
d6e8d8
d6e8d8
			// Category with no members, ignore
d6e8d8
			if (!$row['module_basename'] && ($row['left_id'] + 1 == $row['right_id']))
d6e8d8
			{
d6e8d8
				unset($this->module_cache['modules'][$key]);
d6e8d8
				continue;
d6e8d8
			}
d6e8d8
d6e8d8
			// Skip branch
d6e8d8
			if ($right_id !== false)
d6e8d8
			{
d6e8d8
				if ($row['left_id'] < $right_id)
d6e8d8
				{
d6e8d8
					unset($this->module_cache['modules'][$key]);
d6e8d8
					continue;
d6e8d8
				}
d6e8d8
d6e8d8
				$right_id = false;
d6e8d8
			}
d6e8d8
d6e8d8
			// Not enabled?
d6e8d8
			if (!$row['module_enabled'])
d6e8d8
			{
d6e8d8
				// If category is disabled then disable every child too
d6e8d8
				unset($this->module_cache['modules'][$key]);
d6e8d8
				$right_id = $row['right_id'];
d6e8d8
				continue;
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		// Re-index (this is needed, else we are not able to array_slice later)
d6e8d8
		$this->module_cache['modules'] = array_merge($this->module_cache['modules']);
d6e8d8
d6e8d8
		// Include MOD _info files for populating language entries within the menus
d6e8d8
		$this->add_mod_info($this->p_class);
d6e8d8
d6e8d8
		// Now build the module array, but exclude completely empty categories...
d6e8d8
		$right_id = false;
d6e8d8
		$names = array();
d6e8d8
d6e8d8
		foreach ($this->module_cache['modules'] as $key => $row)
d6e8d8
		{
d6e8d8
			// Skip branch
d6e8d8
			if ($right_id !== false)
d6e8d8
			{
d6e8d8
				if ($row['left_id'] < $right_id)
d6e8d8
				{
d6e8d8
					continue;
d6e8d8
				}
d6e8d8
d6e8d8
				$right_id = false;
d6e8d8
			}
d6e8d8
d6e8d8
			// Category with no members on their way down (we have to check every level)
d6e8d8
			if (!$row['module_basename'])
d6e8d8
			{
d6e8d8
				$empty_category = true;
d6e8d8
d6e8d8
				// We go through the branch and look for an activated module
d6e8d8
				foreach (array_slice($this->module_cache['modules'], $key + 1) as $temp_row)
d6e8d8
				{
d6e8d8
					if ($temp_row['left_id'] > $row['left_id'] && $temp_row['left_id'] < $row['right_id'])
d6e8d8
					{
d6e8d8
						// Module there
d6e8d8
						if ($temp_row['module_basename'] && $temp_row['module_enabled'])
d6e8d8
						{
d6e8d8
							$empty_category = false;
d6e8d8
							break;
d6e8d8
						}
d6e8d8
						continue;
d6e8d8
					}
d6e8d8
					break;
d6e8d8
				}
d6e8d8
d6e8d8
				// Skip the branch
d6e8d8
				if ($empty_category)
d6e8d8
				{
d6e8d8
					$right_id = $row['right_id'];
d6e8d8
					continue;
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			$depth = sizeof($this->module_cache['parents'][$row['module_id']]);
d6e8d8
d6e8d8
			// We need to prefix the functions to not create a naming conflict
d6e8d8
d6e8d8
			// Function for building 'url_extra'
d6e8d8
			$url_func = '_module_' . $row['module_basename'] . '_url';
d6e8d8
d6e8d8
			// Function for building the language name
d6e8d8
			$lang_func = '_module_' . $row['module_basename'] . '_lang';
d6e8d8
d6e8d8
			// Custom function for calling parameters on module init (for example assigning template variables)
d6e8d8
			$custom_func = '_module_' . $row['module_basename'];
d6e8d8
d6e8d8
			$names[$row['module_basename'] . '_' . $row['module_mode']][] = true;
d6e8d8
d6e8d8
			$module_row = array(
d6e8d8
				'depth'		=> $depth,
d6e8d8
d6e8d8
				'id'		=> (int) $row['module_id'],
d6e8d8
				'parent'	=> (int) $row['parent_id'],
d6e8d8
				'cat'		=> ($row['right_id'] > $row['left_id'] + 1) ? true : false,
d6e8d8
d6e8d8
				'is_duplicate'	=> ($row['module_basename'] && sizeof($names[$row['module_basename'] . '_' . $row['module_mode']]) > 1) ? true : false,
d6e8d8
d6e8d8
				'name'		=> (string) $row['module_basename'],
d6e8d8
				'mode'		=> (string) $row['module_mode'],
d6e8d8
				'display'	=> (int) $row['module_display'],
d6e8d8
d6e8d8
				'url_extra'	=> (function_exists($url_func)) ? $url_func($row['module_mode'], $row) : '',
d6e8d8
d6e8d8
				'lang'		=> ($row['module_basename'] && function_exists($lang_func)) ? $lang_func($row['module_mode'], $row['module_langname']) : ((!empty($user->lang[$row['module_langname']])) ? $user->lang[$row['module_langname']] : $row['module_langname']),
d6e8d8
				'langname'	=> $row['module_langname'],
d6e8d8
d6e8d8
				'left'		=> $row['left_id'],
d6e8d8
				'right'		=> $row['right_id'],
d6e8d8
			);
d6e8d8
d6e8d8
			if (function_exists($custom_func))
d6e8d8
			{
d6e8d8
				$custom_func($row['module_mode'], $module_row);
d6e8d8
			}
d6e8d8
d6e8d8
			$this->module_ary[] = $module_row;
d6e8d8
		}
d6e8d8
d6e8d8
		unset($this->module_cache['modules'], $names);
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Check if a certain main module is accessible/loaded
d6e8d8
	* By giving the module mode you are able to additionally check for only one mode within the main module
d6e8d8
	*
d6e8d8
	* @param string $module_basename The module base name, for example logs, reports, main (for the mcp).
d6e8d8
	* @param mixed $module_mode The module mode to check. If provided the mode will be checked in addition for presence.
d6e8d8
	*
d6e8d8
	* @return bool Returns true if module is loaded and accessible, else returns false
d6e8d8
	*/
d6e8d8
	function loaded($module_basename, $module_mode = false)
d6e8d8
	{
d6e8d8
		if (empty($this->loaded_cache))
d6e8d8
		{
d6e8d8
			$this->loaded_cache = array();
d6e8d8
d6e8d8
			foreach ($this->module_ary as $row)
d6e8d8
			{
d6e8d8
				if (!$row['name'])
d6e8d8
				{
d6e8d8
					continue;
d6e8d8
				}
d6e8d8
d6e8d8
				if (!isset($this->loaded_cache[$row['name']]))
d6e8d8
				{
d6e8d8
					$this->loaded_cache[$row['name']] = array();
d6e8d8
				}
d6e8d8
d6e8d8
				if (!$row['mode'])
d6e8d8
				{
d6e8d8
					continue;
d6e8d8
				}
d6e8d8
d6e8d8
				$this->loaded_cache[$row['name']][$row['mode']] = true;
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		if ($module_mode === false)
d6e8d8
		{
d6e8d8
			return (isset($this->loaded_cache[$module_basename])) ? true : false;
d6e8d8
		}
d6e8d8
d6e8d8
		return (!empty($this->loaded_cache[$module_basename][$module_mode])) ? true : false;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Check module authorisation
d6e8d8
	*/
d6e8d8
	function module_auth($module_auth, $forum_id = false)
d6e8d8
	{
d6e8d8
		global $auth, $config;
d6e8d8
d6e8d8
		$module_auth = trim($module_auth);
d6e8d8
d6e8d8
		// Generally allowed to access module if module_auth is empty
d6e8d8
		if (!$module_auth)
d6e8d8
		{
d6e8d8
			return true;
d6e8d8
		}
d6e8d8
d6e8d8
		// With the code below we make sure only those elements get eval'd we really want to be checked
d6e8d8
		preg_match_all('/(?:
d6e8d8
			"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"         |
d6e8d8
			\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'     |
d6e8d8
			[(),]                                  |
d6e8d8
			[^\s(),]+)/x', $module_auth, $match);
d6e8d8
d6e8d8
		$tokens = $match[0];
d6e8d8
		for ($i = 0, $size = sizeof($tokens); $i < $size; $i++)
d6e8d8
		{
d6e8d8
			$token = &$tokens[$i];
d6e8d8
d6e8d8
			switch ($token)
d6e8d8
			{
d6e8d8
				case ')':
d6e8d8
				case '(':
d6e8d8
				case '&&':
d6e8d8
				case '||':
d6e8d8
				case ',':
d6e8d8
				break;
d6e8d8
d6e8d8
				default:
d6e8d8
					if (!preg_match('#(?:acl_([a-z0-9_]+)(,\$id)?)|(?:\$id)|(?:aclf_([a-z0-9_]+))|(?:cfg_([a-z0-9_]+))|(?:request_([a-zA-Z0-9_]+))#', $token))
d6e8d8
					{
d6e8d8
						$token = '';
d6e8d8
					}
d6e8d8
				break;
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		$module_auth = implode(' ', $tokens);
d6e8d8
d6e8d8
		// Make sure $id seperation is working fine
d6e8d8
		$module_auth = str_replace(' , ', ',', $module_auth);
d6e8d8
d6e8d8
		$forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id;
d6e8d8
d6e8d8
		$is_auth = false;
d6e8d8
		eval('$is_auth = (int) (' . preg_replace(array('#acl_([a-z0-9_]+)(,\$id)?#', '#\$id#', '#aclf_([a-z0-9_]+)#', '#cfg_([a-z0-9_]+)#', '#request_([a-zA-Z0-9_]+)#'), array('(int) $auth->acl_get(\'\\1\'\\2)', '(int) $forum_id', '(int) $auth->acl_getf_global(\'\\1\')', '(int) $config[\'\\1\']', '!empty($_REQUEST[\'\\1\'])'), $module_auth) . ');');
d6e8d8
d6e8d8
		return $is_auth;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Set active module
d6e8d8
	*/
d6e8d8
	function set_active($id = false, $mode = false)
d6e8d8
	{
d6e8d8
		$icat = false;
d6e8d8
		$this->active_module = false;
d6e8d8
d6e8d8
		if (request_var('icat', ''))
d6e8d8
		{
d6e8d8
			$icat = $id;
d6e8d8
			$id = request_var('icat', '');
d6e8d8
		}
d6e8d8
d6e8d8
		$category = false;
d6e8d8
		foreach ($this->module_ary as $row_id => $item_ary)
d6e8d8
		{
d6e8d8
			// If this is a module and it's selected, active
d6e8d8
			// If this is a category and the module is the first within it, active
d6e8d8
			// If this is a module and no mode selected, select first mode
d6e8d8
			// If no category or module selected, go active for first module in first category
d6e8d8
			if (
d6e8d8
				(($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (($item_ary['mode'] == $mode && !$item_ary['cat']) || ($icat && $item_ary['cat']))) ||
d6e8d8
				($item_ary['parent'] === $category && !$item_ary['cat'] && !$icat && $item_ary['display']) ||
d6e8d8
				(($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && !$mode && !$item_ary['cat']) ||
d6e8d8
				(!$id && !$mode && !$item_ary['cat'] && $item_ary['display'])
d6e8d8
				)
d6e8d8
			{
d6e8d8
				if ($item_ary['cat'])
d6e8d8
				{
d6e8d8
					$id = $icat;
d6e8d8
					$icat = false;
d6e8d8
d6e8d8
					continue;
d6e8d8
				}
d6e8d8
d6e8d8
				$this->p_id		= $item_ary['id'];
d6e8d8
				$this->p_parent	= $item_ary['parent'];
d6e8d8
				$this->p_name	= $item_ary['name'];
d6e8d8
				$this->p_mode 	= $item_ary['mode'];
d6e8d8
				$this->p_left	= $item_ary['left'];
d6e8d8
				$this->p_right	= $item_ary['right'];
d6e8d8
d6e8d8
				$this->module_cache['parents'] = $this->module_cache['parents'][$this->p_id];
d6e8d8
				$this->active_module = $item_ary['id'];
d6e8d8
				$this->active_module_row_id = $row_id;
d6e8d8
d6e8d8
				break;
d6e8d8
			}
d6e8d8
			else if (($item_ary['cat'] && $item_ary['id'] === (int) $id) || ($item_ary['parent'] === $category && $item_ary['cat']))
d6e8d8
			{
d6e8d8
				$category = $item_ary['id'];
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Loads currently active module
d6e8d8
	*
d6e8d8
	* This method loads a given module, passing it the relevant id and mode.
d6e8d8
	*/
d6e8d8
	function load_active($mode = false, $module_url = false, $execute_module = true)
d6e8d8
	{
d6e8d8
		global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user;
d6e8d8
d6e8d8
		$module_path = $this->include_path . $this->p_class;
d6e8d8
		$icat = request_var('icat', '');
d6e8d8
d6e8d8
		if ($this->active_module === false)
d6e8d8
		{
d6e8d8
			trigger_error('Module not accessible', E_USER_ERROR);
d6e8d8
		}
d6e8d8
d6e8d8
		if (!class_exists("{$this->p_class}_$this->p_name"))
d6e8d8
		{
d6e8d8
			if (!file_exists("$module_path/{$this->p_class}_$this->p_name.$phpEx"))
d6e8d8
			{
d6e8d8
				trigger_error("Cannot find module $module_path/{$this->p_class}_$this->p_name.$phpEx", E_USER_ERROR);
d6e8d8
			}
d6e8d8
d6e8d8
			include("$module_path/{$this->p_class}_$this->p_name.$phpEx");
d6e8d8
d6e8d8
			if (!class_exists("{$this->p_class}_$this->p_name"))
d6e8d8
			{
d6e8d8
				trigger_error("Module file $module_path/{$this->p_class}_$this->p_name.$phpEx does not contain correct class [{$this->p_class}_$this->p_name]", E_USER_ERROR);
d6e8d8
			}
d6e8d8
d6e8d8
			if (!empty($mode))
d6e8d8
			{
d6e8d8
				$this->p_mode = $mode;
d6e8d8
			}
d6e8d8
d6e8d8
			// Create a new instance of the desired module ... if it has a
d6e8d8
			// constructor it will of course be executed
d6e8d8
			$instance = "{$this->p_class}_$this->p_name";
d6e8d8
d6e8d8
			$this->module = new $instance($this);
d6e8d8
d6e8d8
			// We pre-define the action parameter we are using all over the place
d6e8d8
			if (defined('IN_ADMIN'))
d6e8d8
			{
d6e8d8
				// Is first module automatically enabled a duplicate and the category not passed yet?
d6e8d8
				if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate'])
d6e8d8
				{
d6e8d8
					$icat = $this->module_ary[$this->active_module_row_id]['parent'];
d6e8d8
				}
d6e8d8
d6e8d8
				// Not being able to overwrite ;)
d6e8d8
				$this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}";
d6e8d8
			}
d6e8d8
			else
d6e8d8
			{
d6e8d8
				// If user specified the module url we will use it...
d6e8d8
				if ($module_url !== false)
d6e8d8
				{
d6e8d8
					$this->module->u_action = $module_url;
d6e8d8
				}
d6e8d8
				else
d6e8d8
				{
d6e8d8
					$this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name'];
d6e8d8
				}
d6e8d8
d6e8d8
				$this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}";
d6e8d8
			}
d6e8d8
d6e8d8
			// Add url_extra parameter to u_action url
d6e8d8
			if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra'])
d6e8d8
			{
d6e8d8
				$this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra'];
d6e8d8
			}
d6e8d8
d6e8d8
			// Assign the module path for re-usage
d6e8d8
			$this->module->module_path = $module_path . '/';
d6e8d8
d6e8d8
			// Execute the main method for the new instance, we send the module id and mode as parameters
d6e8d8
			// Users are able to call the main method after this function to be able to assign additional parameters manually
d6e8d8
			if ($execute_module)
d6e8d8
			{
d6e8d8
				$this->module->main($this->p_name, $this->p_mode);
d6e8d8
			}
d6e8d8
d6e8d8
			return;
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Appending url parameter to the currently active module.
d6e8d8
	*
d6e8d8
	* This function is called for adding specific url parameters while executing the current module.
d6e8d8
	* It is doing the same as the _module_{name}_url() function, apart from being able to be called after
d6e8d8
	* having dynamically parsed specific parameters. This allows more freedom in choosing additional parameters.
d6e8d8
	* One example can be seen in /includes/mcp/mcp_notes.php - $this->p_master->adjust_url() call.
d6e8d8
	*
d6e8d8
	* @param string $url_extra Extra url parameters, e.g.: &u=$user_id
d6e8d8
	*
d6e8d8
	*/
d6e8d8
	function adjust_url($url_extra)
d6e8d8
	{
d6e8d8
		if (empty($this->module_ary[$this->active_module_row_id]))
d6e8d8
		{
d6e8d8
			return;
d6e8d8
		}
d6e8d8
d6e8d8
		$row = &$this->module_ary[$this->active_module_row_id];
d6e8d8
d6e8d8
		// We check for the same url_extra in $row['url_extra'] to overcome doubled additions...
d6e8d8
		if (strpos($row['url_extra'], $url_extra) === false)
d6e8d8
		{
d6e8d8
			$row['url_extra'] .= $url_extra;
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Check if a module is active
d6e8d8
	*/
d6e8d8
	function is_active($id, $mode = false)
d6e8d8
	{
d6e8d8
		// If we find a name by this id and being enabled we have our active one...
d6e8d8
		foreach ($this->module_ary as $row_id => $item_ary)
d6e8d8
		{
d6e8d8
			if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && $item_ary['display'])
d6e8d8
			{
d6e8d8
				if ($mode === false || $mode === $item_ary['mode'])
d6e8d8
				{
d6e8d8
					return true;
d6e8d8
				}
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		return false;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Get parents
d6e8d8
	*/
d6e8d8
	function get_parents($parent_id, $left_id, $right_id, &$all_parents)
d6e8d8
	{
d6e8d8
		global $db;
d6e8d8
d6e8d8
		$parents = array();
d6e8d8
d6e8d8
		if ($parent_id > 0)
d6e8d8
		{
d6e8d8
			foreach ($all_parents as $module_id => $row)
d6e8d8
			{
d6e8d8
				if ($row['left_id'] < $left_id && $row['right_id'] > $right_id)
d6e8d8
				{
d6e8d8
					$parents[$module_id] = $row['parent_id'];
d6e8d8
				}
d6e8d8
d6e8d8
				if ($row['left_id'] > $left_id)
d6e8d8
				{
d6e8d8
					break;
d6e8d8
				}
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		return $parents;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Get tree branch
d6e8d8
	*/
d6e8d8
	function get_branch($left_id, $right_id, $remaining)
d6e8d8
	{
d6e8d8
		$branch = array();
d6e8d8
d6e8d8
		foreach ($remaining as $key => $row)
d6e8d8
		{
d6e8d8
			if ($row['left_id'] > $left_id && $row['left_id'] < $right_id)
d6e8d8
			{
d6e8d8
				$branch[] = $row;
d6e8d8
				continue;
d6e8d8
			}
d6e8d8
			break;
d6e8d8
		}
d6e8d8
d6e8d8
		return $branch;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Build true binary tree from given array
d6e8d8
	* Not in use
d6e8d8
	*/
d6e8d8
	function build_tree(&$modules, &$parents)
d6e8d8
	{
d6e8d8
		$tree = array();
d6e8d8
d6e8d8
		foreach ($modules as $row)
d6e8d8
		{
d6e8d8
			$branch = &$tree;
d6e8d8
d6e8d8
			if ($row['parent_id'])
d6e8d8
			{
d6e8d8
				// Go through the tree to find our branch
d6e8d8
				$parent_tree = $parents[$row['module_id']];
d6e8d8
d6e8d8
				foreach ($parent_tree as $id => $value)
d6e8d8
				{
d6e8d8
					if (!isset($branch[$id]) && isset($branch['child']))
d6e8d8
					{
d6e8d8
						$branch = &$branch['child'];
d6e8d8
					}
d6e8d8
					$branch = &$branch[$id];
d6e8d8
				}
d6e8d8
				$branch = &$branch['child'];
d6e8d8
			}
d6e8d8
d6e8d8
			$branch[$row['module_id']] = $row;
d6e8d8
			if (!isset($branch[$row['module_id']]['child']))
d6e8d8
			{
d6e8d8
				$branch[$row['module_id']]['child'] = array();
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		return $tree;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Build navigation structure
d6e8d8
	*/
d6e8d8
	function assign_tpl_vars($module_url)
d6e8d8
	{
d6e8d8
		global $template;
d6e8d8
d6e8d8
		$current_id = $right_id = false;
d6e8d8
d6e8d8
		// Make sure the module_url has a question mark set, effectively determining the delimiter to use
d6e8d8
		$delim = (strpos($module_url, '?') === false) ? '?' : '&';
d6e8d8
d6e8d8
		$current_padding = $current_depth = 0;
d6e8d8
		$linear_offset 	= 'l_block1';
d6e8d8
		$tabular_offset = 't_block2';
d6e8d8
d6e8d8
		// Generate the list of modules, we'll do this in two ways ...
d6e8d8
		// 1) In a linear fashion
d6e8d8
		// 2) In a combined tabbed + linear fashion ... tabs for the categories
d6e8d8
		//    and a linear list for subcategories/items
d6e8d8
		foreach ($this->module_ary as $row_id => $item_ary)
d6e8d8
		{
d6e8d8
			// Skip hidden modules
d6e8d8
			if (!$item_ary['display'])
d6e8d8
			{
d6e8d8
				continue;
d6e8d8
			}
d6e8d8
d6e8d8
			// Skip branch
d6e8d8
			if ($right_id !== false)
d6e8d8
			{
d6e8d8
				if ($item_ary['left'] < $right_id)
d6e8d8
				{
d6e8d8
					continue;
d6e8d8
				}
d6e8d8
d6e8d8
				$right_id = false;
d6e8d8
			}
d6e8d8
d6e8d8
			// Category with no members on their way down (we have to check every level)
d6e8d8
			if (!$item_ary['name'])
d6e8d8
			{
d6e8d8
				$empty_category = true;
d6e8d8
d6e8d8
				// We go through the branch and look for an activated module
d6e8d8
				foreach (array_slice($this->module_ary, $row_id + 1) as $temp_row)
d6e8d8
				{
d6e8d8
					if ($temp_row['left'] > $item_ary['left'] && $temp_row['left'] < $item_ary['right'])
d6e8d8
					{
d6e8d8
						// Module there and displayed?
d6e8d8
						if ($temp_row['name'] && $temp_row['display'])
d6e8d8
						{
d6e8d8
							$empty_category = false;
d6e8d8
							break;
d6e8d8
						}
d6e8d8
						continue;
d6e8d8
					}
d6e8d8
					break;
d6e8d8
				}
d6e8d8
d6e8d8
				// Skip the branch
d6e8d8
				if ($empty_category)
d6e8d8
				{
d6e8d8
					$right_id = $item_ary['right'];
d6e8d8
					continue;
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			// Select first id we can get
d6e8d8
			if (!$current_id && (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id))
d6e8d8
			{
d6e8d8
				$current_id = $item_ary['id'];
d6e8d8
			}
d6e8d8
d6e8d8
			$depth = $item_ary['depth'];
d6e8d8
d6e8d8
			if ($depth > $current_depth)
d6e8d8
			{
d6e8d8
				$linear_offset = $linear_offset . '.l_block' . ($depth + 1);
d6e8d8
				$tabular_offset = ($depth + 1 > 2) ? $tabular_offset . '.t_block' . ($depth + 1) : $tabular_offset;
d6e8d8
			}
d6e8d8
			else if ($depth < $current_depth)
d6e8d8
			{
d6e8d8
				for ($i = $current_depth - $depth; $i > 0; $i--)
d6e8d8
				{
d6e8d8
					$linear_offset = substr($linear_offset, 0, strrpos($linear_offset, '.'));
d6e8d8
					$tabular_offset = ($i + $depth > 1) ? substr($tabular_offset, 0, strrpos($tabular_offset, '.')) : $tabular_offset;
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			$u_title = $module_url . $delim . 'i=' . (($item_ary['cat']) ? $item_ary['id'] : $item_ary['name'] . (($item_ary['is_duplicate']) ? '&icat=' . $current_id : '') . '&mode=' . $item_ary['mode']);
d6e8d8
d6e8d8
			// Was not allowed in categories before - /*!$item_ary['cat'] && */
d6e8d8
			$u_title .= (isset($item_ary['url_extra'])) ? $item_ary['url_extra'] : '';
d6e8d8
d6e8d8
			// Only output a categories items if it's currently selected
d6e8d8
			if (!$depth || ($depth && (in_array($item_ary['parent'], array_values($this->module_cache['parents'])) || $item_ary['parent'] == $this->p_parent)))
d6e8d8
			{
d6e8d8
				$use_tabular_offset = (!$depth) ? 't_block1' : $tabular_offset;
d6e8d8
d6e8d8
				$tpl_ary = array(
d6e8d8
					'L_TITLE'		=> $item_ary['lang'],
d6e8d8
					'S_SELECTED'	=> (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id) ? true : false,
d6e8d8
					'U_TITLE'		=> $u_title
d6e8d8
				);
d6e8d8
d6e8d8
				$template->assign_block_vars($use_tabular_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER)));
d6e8d8
			}
d6e8d8
d6e8d8
			$tpl_ary = array(
d6e8d8
				'L_TITLE'		=> $item_ary['lang'],
d6e8d8
				'S_SELECTED'	=> (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id) ? true : false,
d6e8d8
				'U_TITLE'		=> $u_title
d6e8d8
			);
d6e8d8
d6e8d8
			$template->assign_block_vars($linear_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER)));
d6e8d8
d6e8d8
			$current_depth = $depth;
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Returns desired template name
d6e8d8
	*/
d6e8d8
	function get_tpl_name()
d6e8d8
	{
d6e8d8
		return $this->module->tpl_name . '.html';
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Returns the desired page title
d6e8d8
	*/
d6e8d8
	function get_page_title()
d6e8d8
	{
d6e8d8
		global $user;
d6e8d8
d6e8d8
		if (!isset($this->module->page_title))
d6e8d8
		{
d6e8d8
			return '';
d6e8d8
		}
d6e8d8
d6e8d8
		return (isset($user->lang[$this->module->page_title])) ? $user->lang[$this->module->page_title] : $this->module->page_title;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Load module as the current active one without the need for registering it
d6e8d8
	*/
d6e8d8
	function load($class, $name, $mode = false)
d6e8d8
	{
d6e8d8
		$this->p_class = $class;
d6e8d8
		$this->p_name = $name;
d6e8d8
d6e8d8
		// Set active module to true instead of using the id
d6e8d8
		$this->active_module = true;
d6e8d8
d6e8d8
		$this->load_active($mode);
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Display module
d6e8d8
	*/
d6e8d8
	function display($page_title, $display_online_list = true)
d6e8d8
	{
d6e8d8
		global $template, $user;
d6e8d8
d6e8d8
		// Generate the page
d6e8d8
		if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
d6e8d8
		{
d6e8d8
			adm_page_header($page_title);
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			page_header($page_title, $display_online_list);
d6e8d8
		}
d6e8d8
d6e8d8
		$template->set_filenames(array(
d6e8d8
			'body' => $this->get_tpl_name())
d6e8d8
		);
d6e8d8
d6e8d8
		if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
d6e8d8
		{
d6e8d8
			adm_page_footer();
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			page_footer();
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Toggle whether this module will be displayed or not
d6e8d8
	*/
d6e8d8
	function set_display($id, $mode = false, $display = true)
d6e8d8
	{
d6e8d8
		foreach ($this->module_ary as $row_id => $item_ary)
d6e8d8
		{
d6e8d8
			if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (!$mode || $item_ary['mode'] === $mode))
d6e8d8
			{
d6e8d8
				$this->module_ary[$row_id]['display'] = (int) $display;
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Add custom MOD info language file
d6e8d8
	*/
d6e8d8
	function add_mod_info($module_class)
d6e8d8
	{
d6e8d8
		global $user, $phpEx;
d6e8d8
d6e8d8
		if (file_exists($user->lang_path . $user->lang_name . '/mods'))
d6e8d8
		{
d6e8d8
			$add_files = array();
d6e8d8
d6e8d8
			$dir = @opendir($user->lang_path . $user->lang_name . '/mods');
d6e8d8
d6e8d8
			if ($dir)
d6e8d8
			{
d6e8d8
				while (($entry = readdir($dir)) !== false)
d6e8d8
				{
d6e8d8
					if (strpos($entry, 'info_' . strtolower($module_class) . '_') === 0 && substr(strrchr($entry, '.'), 1) == $phpEx)
d6e8d8
					{
d6e8d8
						$add_files[] = 'mods/' . substr(basename($entry), 0, -(strlen($phpEx) + 1));
d6e8d8
					}
d6e8d8
				}
d6e8d8
				closedir($dir);
d6e8d8
			}
d6e8d8
d6e8d8
			if (sizeof($add_files))
d6e8d8
			{
d6e8d8
				$user->add_lang($add_files);
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
?>