Blame Extras/phpBB/3.0.4/includes/cache.php

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