Blame Identity/Webenv/phpBB/3.0.4/includes/cache.php

ef5584
ef5584
/**
ef5584
*
ef5584
* @package acm
ef5584
* @version $Id: cache.php 8691 2008-07-28 13:26:20Z acydburn $
ef5584
* @copyright (c) 2005 phpBB Group
ef5584
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
ef5584
*
ef5584
*/
ef5584
ef5584
/**
ef5584
* @ignore
ef5584
*/
ef5584
if (!defined('IN_PHPBB'))
ef5584
{
ef5584
	exit;
ef5584
}
ef5584
ef5584
/**
ef5584
* Class for grabbing/handling cached entries, extends acm_file or acm_db depending on the setup
ef5584
* @package acm
ef5584
*/
ef5584
class cache extends acm
ef5584
{
ef5584
	/**
ef5584
	* Get config values
ef5584
	*/
ef5584
	function obtain_config()
ef5584
	{
ef5584
		global $db;
ef5584
ef5584
		if (($config = $this->get('config')) !== false)
ef5584
		{
ef5584
			$sql = 'SELECT config_name, config_value
ef5584
				FROM ' . CONFIG_TABLE . '
ef5584
				WHERE is_dynamic = 1';
ef5584
			$result = $db->sql_query($sql);
ef5584
ef5584
			while ($row = $db->sql_fetchrow($result))
ef5584
			{
ef5584
				$config[$row['config_name']] = $row['config_value'];
ef5584
			}
ef5584
			$db->sql_freeresult($result);
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			$config = $cached_config = array();
ef5584
ef5584
			$sql = 'SELECT config_name, config_value, is_dynamic
ef5584
				FROM ' . CONFIG_TABLE;
ef5584
			$result = $db->sql_query($sql);
ef5584
ef5584
			while ($row = $db->sql_fetchrow($result))
ef5584
			{
ef5584
				if (!$row['is_dynamic'])
ef5584
				{
ef5584
					$cached_config[$row['config_name']] = $row['config_value'];
ef5584
				}
ef5584
ef5584
				$config[$row['config_name']] = $row['config_value'];
ef5584
			}
ef5584
			$db->sql_freeresult($result);
ef5584
ef5584
			$this->put('config', $cached_config);
ef5584
		}
ef5584
ef5584
		return $config;
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Obtain list of naughty words and build preg style replacement arrays for use by the
ef5584
	* calling script
ef5584
	*/
ef5584
	function obtain_word_list()
ef5584
	{
ef5584
		global $db;
ef5584
ef5584
		if (($censors = $this->get('_word_censors')) === false)
ef5584
		{
ef5584
			$sql = 'SELECT word, replacement
ef5584
				FROM ' . WORDS_TABLE;
ef5584
			$result = $db->sql_query($sql);
ef5584
ef5584
			$censors = array();
ef5584
			while ($row = $db->sql_fetchrow($result))
ef5584
			{
ef5584
				$censors['match'][] = '#(?
ef5584
				$censors['replace'][] = $row['replacement'];
ef5584
			}
ef5584
			$db->sql_freeresult($result);
ef5584
ef5584
			$this->put('_word_censors', $censors);
ef5584
		}
ef5584
ef5584
		return $censors;
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Obtain currently listed icons
ef5584
	*/
ef5584
	function obtain_icons()
ef5584
	{
ef5584
		if (($icons = $this->get('_icons')) === false)
ef5584
		{
ef5584
			global $db;
ef5584
ef5584
			// Topic icons
ef5584
			$sql = 'SELECT *
ef5584
				FROM ' . ICONS_TABLE . '
ef5584
				ORDER BY icons_order';
ef5584
			$result = $db->sql_query($sql);
ef5584
ef5584
			$icons = array();
ef5584
			while ($row = $db->sql_fetchrow($result))
ef5584
			{
ef5584
				$icons[$row['icons_id']]['img'] = $row['icons_url'];
ef5584
				$icons[$row['icons_id']]['width'] = (int) $row['icons_width'];
ef5584
				$icons[$row['icons_id']]['height'] = (int) $row['icons_height'];
ef5584
				$icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting'];
ef5584
			}
ef5584
			$db->sql_freeresult($result);
ef5584
ef5584
			$this->put('_icons', $icons);
ef5584
		}
ef5584
ef5584
		return $icons;
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Obtain ranks
ef5584
	*/
ef5584
	function obtain_ranks()
ef5584
	{
ef5584
		if (($ranks = $this->get('_ranks')) === false)
ef5584
		{
ef5584
			global $db;
ef5584
ef5584
			$sql = 'SELECT *
ef5584
				FROM ' . RANKS_TABLE . '
ef5584
				ORDER BY rank_min DESC';
ef5584
			$result = $db->sql_query($sql);
ef5584
ef5584
			$ranks = array();
ef5584
			while ($row = $db->sql_fetchrow($result))
ef5584
			{
ef5584
				if ($row['rank_special'])
ef5584
				{
ef5584
					$ranks['special'][$row['rank_id']] = array(
ef5584
						'rank_title'	=>	$row['rank_title'],
ef5584
						'rank_image'	=>	$row['rank_image']
ef5584
					);
ef5584
				}
ef5584
				else
ef5584
				{
ef5584
					$ranks['normal'][] = array(
ef5584
						'rank_title'	=>	$row['rank_title'],
ef5584
						'rank_min'		=>	$row['rank_min'],
ef5584
						'rank_image'	=>	$row['rank_image']
ef5584
					);
ef5584
				}
ef5584
			}
ef5584
			$db->sql_freeresult($result);
ef5584
ef5584
			$this->put('_ranks', $ranks);
ef5584
		}
ef5584
ef5584
		return $ranks;
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Obtain allowed extensions
ef5584
	*
ef5584
	* @param mixed $forum_id If false then check for private messaging, if int then check for forum id. If true, then only return extension informations.
ef5584
	*
ef5584
	* @return array allowed extensions array.
ef5584
	*/
ef5584
	function obtain_attach_extensions($forum_id)
ef5584
	{
ef5584
		if (($extensions = $this->get('_extensions')) === false)
ef5584
		{
ef5584
			global $db;
ef5584
ef5584
			$extensions = array(
ef5584
				'_allowed_post'	=> array(),
ef5584
				'_allowed_pm'	=> array(),
ef5584
			);
ef5584
ef5584
			// The rule is to only allow those extensions defined. ;)
ef5584
			$sql = 'SELECT e.extension, g.*
ef5584
				FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
ef5584
				WHERE e.group_id = g.group_id
ef5584
					AND (g.allow_group = 1 OR g.allow_in_pm = 1)';
ef5584
			$result = $db->sql_query($sql);
ef5584
ef5584
			while ($row = $db->sql_fetchrow($result))
ef5584
			{
ef5584
				$extension = strtolower(trim($row['extension']));
ef5584
ef5584
				$extensions[$extension] = array(
ef5584
					'display_cat'	=> (int) $row['cat_id'],
ef5584
					'download_mode'	=> (int) $row['download_mode'],
ef5584
					'upload_icon'	=> trim($row['upload_icon']),
ef5584
					'max_filesize'	=> (int) $row['max_filesize'],
ef5584
					'allow_group'	=> $row['allow_group'],
ef5584
					'allow_in_pm'	=> $row['allow_in_pm'],
ef5584
				);
ef5584
ef5584
				$allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
ef5584
ef5584
				// Store allowed extensions forum wise
ef5584
				if ($row['allow_group'])
ef5584
				{
ef5584
					$extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums;
ef5584
				}
ef5584
ef5584
				if ($row['allow_in_pm'])
ef5584
				{
ef5584
					$extensions['_allowed_pm'][$extension] = 0;
ef5584
				}
ef5584
			}
ef5584
			$db->sql_freeresult($result);
ef5584
ef5584
			$this->put('_extensions', $extensions);
ef5584
		}
ef5584
ef5584
		// Forum post
ef5584
		if ($forum_id === false)
ef5584
		{
ef5584
			// We are checking for private messages, therefore we only need to get the pm extensions...
ef5584
			$return = array('_allowed_' => array());
ef5584
ef5584
			foreach ($extensions['_allowed_pm'] as $extension => $check)
ef5584
			{
ef5584
				$return['_allowed_'][$extension] = 0;
ef5584
				$return[$extension] = $extensions[$extension];
ef5584
			}
ef5584
ef5584
			$extensions = $return;
ef5584
		}
ef5584
		else if ($forum_id === true)
ef5584
		{
ef5584
			return $extensions;
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			$forum_id = (int) $forum_id;
ef5584
			$return = array('_allowed_' => array());
ef5584
ef5584
			foreach ($extensions['_allowed_post'] as $extension => $check)
ef5584
			{
ef5584
				// Check for allowed forums
ef5584
				if (is_array($check))
ef5584
				{
ef5584
					$allowed = (!in_array($forum_id, $check)) ? false : true;
ef5584
				}
ef5584
				else
ef5584
				{
ef5584
					$allowed = true;
ef5584
				}
ef5584
ef5584
				if ($allowed)
ef5584
				{
ef5584
					$return['_allowed_'][$extension] = 0;
ef5584
					$return[$extension] = $extensions[$extension];
ef5584
				}
ef5584
			}
ef5584
ef5584
			$extensions = $return;
ef5584
		}
ef5584
ef5584
		if (!isset($extensions['_allowed_']))
ef5584
		{
ef5584
			$extensions['_allowed_'] = array();
ef5584
		}
ef5584
ef5584
		return $extensions;
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Obtain active bots
ef5584
	*/
ef5584
	function obtain_bots()
ef5584
	{
ef5584
		if (($bots = $this->get('_bots')) === false)
ef5584
		{
ef5584
			global $db;
ef5584
ef5584
			switch ($db->sql_layer)
ef5584
			{
ef5584
				case 'mssql':
ef5584
				case 'mssql_odbc':
ef5584
					$sql = 'SELECT user_id, bot_agent, bot_ip
ef5584
						FROM ' . BOTS_TABLE . '
ef5584
						WHERE bot_active = 1
ef5584
					ORDER BY LEN(bot_agent) DESC';
ef5584
				break;
ef5584
ef5584
				case 'firebird':
ef5584
					$sql = 'SELECT user_id, bot_agent, bot_ip
ef5584
						FROM ' . BOTS_TABLE . '
ef5584
						WHERE bot_active = 1
ef5584
					ORDER BY CHAR_LENGTH(bot_agent) DESC';
ef5584
				break;
ef5584
ef5584
				// LENGTH supported by MySQL, IBM DB2 and Oracle for sure...
ef5584
				default:
ef5584
					$sql = 'SELECT user_id, bot_agent, bot_ip
ef5584
						FROM ' . BOTS_TABLE . '
ef5584
						WHERE bot_active = 1
ef5584
					ORDER BY LENGTH(bot_agent) DESC';
ef5584
				break;
ef5584
			}
ef5584
			$result = $db->sql_query($sql);
ef5584
ef5584
			$bots = array();
ef5584
			while ($row = $db->sql_fetchrow($result))
ef5584
			{
ef5584
				$bots[] = $row;
ef5584
			}
ef5584
			$db->sql_freeresult($result);
ef5584
ef5584
			$this->put('_bots', $bots);
ef5584
		}
ef5584
ef5584
		return $bots;
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Obtain cfg file data
ef5584
	*/
ef5584
	function obtain_cfg_items($theme)
ef5584
	{
ef5584
		global $config, $phpbb_root_path;
ef5584
ef5584
		$parsed_items = array(
ef5584
			'theme'		=> array(),
ef5584
			'template'	=> array(),
ef5584
			'imageset'	=> array()
ef5584
		);
ef5584
ef5584
		foreach ($parsed_items as $key => $parsed_array)
ef5584
		{
ef5584
			$parsed_array = $this->get('_cfg_' . $key . '_' . $theme[$key . '_path']);
ef5584
ef5584
			if ($parsed_array === false)
ef5584
			{
ef5584
				$parsed_array = array();
ef5584
			}
ef5584
ef5584
			$reparse = false;
ef5584
			$filename = $phpbb_root_path . 'styles/' . $theme[$key . '_path'] . '/' . $key . '/' . $key . '.cfg';
ef5584
ef5584
			if (!file_exists($filename))
ef5584
			{
ef5584
				continue;
ef5584
			}
ef5584
ef5584
			if (!isset($parsed_array['filetime']) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
ef5584
			{
ef5584
				$reparse = true;
ef5584
			}
ef5584
ef5584
			// Re-parse cfg file
ef5584
			if ($reparse)
ef5584
			{
ef5584
				$parsed_array = parse_cfg_file($filename);
ef5584
				$parsed_array['filetime'] = @filemtime($filename);
ef5584
ef5584
				$this->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array);
ef5584
			}
ef5584
			$parsed_items[$key] = $parsed_array;
ef5584
		}
ef5584
ef5584
		return $parsed_items;
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Obtain disallowed usernames
ef5584
	*/
ef5584
	function obtain_disallowed_usernames()
ef5584
	{
ef5584
		if (($usernames = $this->get('_disallowed_usernames')) === false)
ef5584
		{
ef5584
			global $db;
ef5584
ef5584
			$sql = 'SELECT disallow_username
ef5584
				FROM ' . DISALLOW_TABLE;
ef5584
			$result = $db->sql_query($sql);
ef5584
ef5584
			$usernames = array();
ef5584
			while ($row = $db->sql_fetchrow($result))
ef5584
			{
ef5584
				$usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#'));
ef5584
			}
ef5584
			$db->sql_freeresult($result);
ef5584
ef5584
			$this->put('_disallowed_usernames', $usernames);
ef5584
		}
ef5584
ef5584
		return $usernames;
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Obtain hooks...
ef5584
	*/
ef5584
	function obtain_hooks()
ef5584
	{
ef5584
		global $phpbb_root_path, $phpEx;
ef5584
ef5584
		if (($hook_files = $this->get('_hooks')) === false)
ef5584
		{
ef5584
			$hook_files = array();
ef5584
ef5584
			// Now search for hooks...
ef5584
			$dh = @opendir($phpbb_root_path . 'includes/hooks/');
ef5584
ef5584
			if ($dh)
ef5584
			{
ef5584
				while (($file = readdir($dh)) !== false)
ef5584
				{
ef5584
					if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($phpEx) + 1)) === '.' . $phpEx)
ef5584
					{
ef5584
						$hook_files[] = substr($file, 0, -(strlen($phpEx) + 1));
ef5584
					}
ef5584
				}
ef5584
				closedir($dh);
ef5584
			}
ef5584
ef5584
			$this->put('_hooks', $hook_files);
ef5584
		}
ef5584
ef5584
		return $hook_files;
ef5584
	}
ef5584
}
ef5584
ef5584
?>