aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/classes
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/classes')
-rw-r--r--phpBB/includes/classes/cache.php373
1 files changed, 188 insertions, 185 deletions
diff --git a/phpBB/includes/classes/cache.php b/phpBB/includes/classes/cache.php
index f537b52b3f..eeeae58989 100644
--- a/phpBB/includes/classes/cache.php
+++ b/phpBB/includes/classes/cache.php
@@ -3,7 +3,7 @@
*
* @package acm
* @version $Id$
-* @copyright (c) 2005 phpBB Group
+* @copyright (c) 2005, 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
@@ -17,81 +17,95 @@ if (!defined('IN_PHPBB'))
}
/**
-* Class for grabbing/handling cached entries, extends acm_file or acm_db depending on the setup
+* Class for obtaining cached entries, for example censor word list, configuration...
* @package acm
*/
-class cache
+class phpbb_cache
{
/**
+ * We do not want this object instantiable
+ */
+ private function ___construct() { }
+
+ /**
+ * Required phpBB objects
+ */
+ public $phpbb_required = array('config', 'acm', 'db');
+
+ /**
+ * Optional phpBB objects
+ */
+ public $phpbb_optional = array();
+
+ /**
* Get config values
+ *
+ * @return array configuration
+ * @access public
*/
public static function obtain_config()
{
- global $db, $cache;
-
- if (($config = $cache->get('config')) !== false)
+ if ((phpbb::$config = phpbb::$acm->get('#config')) !== false)
{
$sql = 'SELECT config_name, config_value
FROM ' . CONFIG_TABLE . '
WHERE is_dynamic = 1';
- $result = $db->sql_query($sql);
+ $result = phpbb::$db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
+ while ($row = phpbb::$db->sql_fetchrow($result))
{
- $config[$row['config_name']] = $row['config_value'];
+ phpbb::$config[$row['config_name']] = $row['config_value'];
}
- $db->sql_freeresult($result);
+ phpbb::$db->sql_freeresult($result);
}
else
{
- $config = $cached_config = array();
+ phpbb::$config = $cached_config = array();
$sql = 'SELECT config_name, config_value, is_dynamic
FROM ' . CONFIG_TABLE;
- $result = $db->sql_query($sql);
+ $result = phpbb::$db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
+ while ($row = phpbb::$db->sql_fetchrow($result))
{
if (!$row['is_dynamic'])
{
$cached_config[$row['config_name']] = $row['config_value'];
}
- $config[$row['config_name']] = $row['config_value'];
+ phpbb::$config[$row['config_name']] = $row['config_value'];
}
- $db->sql_freeresult($result);
+ phpbb::$db->sql_freeresult($result);
- $cache->put('config', $cached_config);
+ phpbb::$acm->put('#config', $cached_config);
}
- return $config;
+ return phpbb::$config;
}
/**
- * Obtain list of naughty words and build preg style replacement arrays for use by the
- * calling script
+ * Obtain list of naughty words and build preg style replacement arrays for use by the calling script
+ *
+ * @return array Censored words
+ * @access public
*/
public static function obtain_word_list()
{
- global $cache;
-
- if (($censors = $cache->get('_word_censors')) === false)
+ if (($censors = phpbb::$acm->get('word_censors')) === false)
{
- global $db;
-
$sql = 'SELECT word, replacement
FROM ' . WORDS_TABLE;
- $result = $db->sql_query($sql);
+ $result = phpbb::$db->sql_query($sql);
$censors = array();
- while ($row = $db->sql_fetchrow($result))
+ while ($row = phpbb::$db->sql_fetchrow($result))
{
$censors['match'][] = '#(?<!\w)(' . str_replace('\*', '\w*?', preg_quote($row['word'], '#')) . ')(?!\w)#i';
$censors['replace'][] = $row['replacement'];
}
- $db->sql_freeresult($result);
+ phpbb::$db->sql_freeresult($result);
- $cache->put('_word_censors', $censors);
+ phpbb::$acm->put('word_censors', $censors);
}
return $censors;
@@ -99,32 +113,31 @@ class cache
/**
* Obtain currently listed icons
+ *
+ * @return array Icons
+ * @access public
*/
public static function obtain_icons()
{
- global $cache;
-
- if (($icons = $cache->get('_icons')) === false)
+ if (($icons = phpbb::$acm->get('icons')) === false)
{
- global $db;
-
// Topic icons
$sql = 'SELECT *
FROM ' . ICONS_TABLE . '
ORDER BY icons_order';
- $result = $db->sql_query($sql);
+ $result = phpbb::$db->sql_query($sql);
$icons = array();
- while ($row = $db->sql_fetchrow($result))
+ while ($row = phpbb::$db->sql_fetchrow($result))
{
$icons[$row['icons_id']]['img'] = $row['icons_url'];
$icons[$row['icons_id']]['width'] = (int) $row['icons_width'];
$icons[$row['icons_id']]['height'] = (int) $row['icons_height'];
$icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting'];
}
- $db->sql_freeresult($result);
+ phpbb::$db->sql_freeresult($result);
- $cache->put('_icons', $icons);
+ phpbb::$acm->put('icons', $icons);
}
return $icons;
@@ -132,22 +145,21 @@ class cache
/**
* Obtain ranks
+ *
+ * @return Ranks
+ * @access public
*/
public static function obtain_ranks()
{
- global $cache;
-
- if (($ranks = $cache->get('_ranks')) === false)
+ if (($ranks = phpbb::$acm->get('ranks')) === false)
{
- global $db;
-
$sql = 'SELECT *
FROM ' . RANKS_TABLE . '
ORDER BY rank_min DESC';
- $result = $db->sql_query($sql);
+ $result = phpbb::$db->sql_query($sql);
$ranks = array();
- while ($row = $db->sql_fetchrow($result))
+ while ($row = phpbb::$db->sql_fetchrow($result))
{
if ($row['rank_special'])
{
@@ -165,120 +177,146 @@ class cache
);
}
}
- $db->sql_freeresult($result);
+ phpbb::$db->sql_freeresult($result);
- $cache->put('_ranks', $ranks);
+ phpbb::$acm->put('ranks', $ranks);
}
return $ranks;
}
/**
- * Obtain allowed extensions
- *
- * @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.
+ * Put attachment extensions data into cache
*
- * @return array allowed extensions array.
+ * @return array Cached extensions
+ * @access private
*/
- public static function obtain_attach_extensions($forum_id)
+ private static function cache_extensions()
{
- global $cache;
-
- if (($extensions = $cache->get('_extensions')) === false)
+ $extensions = array(
+ '_allowed_post' => array(),
+ '_allowed_pm' => array(),
+ );
+
+ // The rule is to only allow those extensions defined. ;)
+ $sql = 'SELECT e.extension, g.*
+ FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
+ WHERE e.group_id = g.group_id
+ AND (g.allow_group = 1 OR g.allow_in_pm = 1)';
+ $result = phpbb::$db->sql_query($sql);
+
+ while ($row = phpbb::$db->sql_fetchrow($result))
{
- global $db;
-
- $extensions = array(
- '_allowed_post' => array(),
- '_allowed_pm' => array(),
+ $extension = strtolower(trim($row['extension']));
+
+ $extensions[$extension] = array(
+ 'display_cat' => (int) $row['cat_id'],
+ 'download_mode' => (int) $row['download_mode'],
+ 'upload_icon' => trim($row['upload_icon']),
+ 'max_filesize' => (int) $row['max_filesize'],
+ 'allow_group' => $row['allow_group'],
+ 'allow_in_pm' => $row['allow_in_pm'],
);
- // The rule is to only allow those extensions defined. ;)
- $sql = 'SELECT e.extension, g.*
- FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
- WHERE e.group_id = g.group_id
- AND (g.allow_group = 1 OR g.allow_in_pm = 1)';
- $result = $db->sql_query($sql);
+ $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
- while ($row = $db->sql_fetchrow($result))
+ // Store allowed extensions forum wise
+ if ($row['allow_group'])
{
- $extension = strtolower(trim($row['extension']));
-
- $extensions[$extension] = array(
- 'display_cat' => (int) $row['cat_id'],
- 'download_mode' => (int) $row['download_mode'],
- 'upload_icon' => trim($row['upload_icon']),
- 'max_filesize' => (int) $row['max_filesize'],
- 'allow_group' => $row['allow_group'],
- 'allow_in_pm' => $row['allow_in_pm'],
- );
-
- $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
-
- // Store allowed extensions forum wise
- if ($row['allow_group'])
- {
- $extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums;
- }
-
- if ($row['allow_in_pm'])
- {
- $extensions['_allowed_pm'][$extension] = 0;
- }
+ $extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums;
}
- $db->sql_freeresult($result);
- $cache->put('_extensions', $extensions);
+ if ($row['allow_in_pm'])
+ {
+ $extensions['_allowed_pm'][$extension] = 0;
+ }
}
+ phpbb::$db->sql_freeresult($result);
+
+ phpbb::$acm->put('extensions', $extensions);
+ return $extensions;
+ }
- // Forum post
- if ($forum_id === false)
+ /**
+ * Obtain allowed attachment extensions in private messages
+ *
+ * @return array Allowed extensions
+ * @access public
+ */
+ public static function obtain_extensions_pm()
+ {
+ if (($extensions = phpbb::$acm->get('extensions')) === false)
{
- // We are checking for private messages, therefore we only need to get the pm extensions...
- $return = array('_allowed_' => array());
+ $extensions = self::cache_extensions();
+ }
- foreach ($extensions['_allowed_pm'] as $extension => $check)
- {
- $return['_allowed_'][$extension] = 0;
- $return[$extension] = $extensions[$extension];
- }
+ // We are checking for private messages, therefore we only need to get the pm extensions...
+ $result = array('_allowed_' => array());
- $extensions = $return;
- }
- else if ($forum_id === true)
+ foreach ($extensions['_allowed_pm'] as $extension => $check)
{
- return $extensions;
+ $result['_allowed_'][$extension] = 0;
+ $result[$extension] = $extensions[$extension];
}
- else
+
+ return $result;
+ }
+
+ /**
+ * Obtain allowed attachment extensions in specific forum
+ *
+ * @param int $forum_id The forum id
+ * @return array Allowed extensions within the specified forum
+ * @access public
+ */
+ public static function obtain_extensions_forum($forum_id)
+ {
+ if (($extensions = phpbb::$acm->get('extensions')) === false)
{
- $forum_id = (int) $forum_id;
- $return = array('_allowed_' => array());
+ $extensions = self::cache_extensions();
+ }
+
+ $forum_id = (int) $forum_id;
+ $result = array('_allowed_' => array());
- foreach ($extensions['_allowed_post'] as $extension => $check)
+ foreach ($extensions['_allowed_post'] as $extension => $check)
+ {
+ // Check for allowed forums
+ if (is_array($check))
{
- // Check for allowed forums
- if (is_array($check))
- {
- $allowed = (!in_array($forum_id, $check)) ? false : true;
- }
- else
- {
- $allowed = true;
- }
+ $allowed = (!in_array($forum_id, $check)) ? false : true;
+ }
+ else
+ {
+ $allowed = true;
+ }
- if ($allowed)
- {
- $return['_allowed_'][$extension] = 0;
- $return[$extension] = $extensions[$extension];
- }
+ if ($allowed)
+ {
+ $result['_allowed_'][$extension] = 0;
+ $result[$extension] = $extensions[$extension];
}
+ }
- $extensions = $return;
+ if (!isset($result['_allowed_']))
+ {
+ $result['_allowed_'] = array();
}
- if (!isset($extensions['_allowed_']))
+ return $result;
+ }
+
+ /**
+ * Obtain general attachment extension information
+ *
+ * @return array Cached extension information
+ * @access public
+ */
+ public static function obtain_extensions()
+ {
+ if (($extensions = phpbb::$acm->get('extensions')) === false)
{
- $extensions['_allowed_'] = array();
+ $extensions = self::cache_extensions();
}
return $extensions;
@@ -286,47 +324,45 @@ class cache
/**
* Obtain active bots
+ *
+ * @return array Active bots
+ * @access public
*/
public static function obtain_bots()
{
- global $cache;
-
- if (($bots = $cache->get('_bots')) === false)
+ if (($bots = phpbb::$acm->get('bots')) === false)
{
- global $db;
-
+ // @todo We order by last visit date. This way we are able to safe some cycles by checking the most active ones first.
$sql = 'SELECT user_id, bot_agent, bot_ip
FROM ' . BOTS_TABLE . '
WHERE bot_active = 1
- ORDER BY ' . $db->sql_function('length_varchar', 'bot_agent') . 'DESC';
- $result = $db->sql_query($sql);
+ ORDER BY ' . phpbb::$db->sql_function('length_varchar', 'bot_agent') . 'DESC';
+ $result = phpbb::$db->sql_query($sql);
$bots = array();
- while ($row = $db->sql_fetchrow($result))
+ while ($row = phpbb::$db->sql_fetchrow($result))
{
$bots[] = $row;
}
- $db->sql_freeresult($result);
+ phpbb::$db->sql_freeresult($result);
- $cache->put('_bots', $bots);
+ phpbb::$acm->put('bots', $bots);
}
return $bots;
}
/**
- * Obtain cfg file data
- *
- * @param array $theme An array containing the path to the item
+ * Obtain Styles .cfg file data
*
+ * @param array $theme An array containing the path to the items
* @param string $item The specific item to get: 'theme', 'template', or 'imageset'
- *
+ * @return array The configuration
+ * @access public
*/
public static function obtain_cfg_item($theme, $item = 'theme')
{
- global $config, $cache;
-
- $parsed_array = $cache->get('_cfg_' . $item . '_' . $theme[$item . '_path']);
+ $parsed_array = phpbb::$acm->get('cfg_' . $item . '_' . $theme[$item . '_path']);
if ($parsed_array === false)
{
@@ -341,7 +377,7 @@ class cache
return $parsed_array;
}
- if (!isset($parsed_array['filetime']) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
+ if (!isset($parsed_array['filetime']) || ((phpbb::$config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
{
$reparse = true;
}
@@ -352,7 +388,7 @@ class cache
$parsed_array = parse_cfg_file($filename);
$parsed_array['filetime'] = @filemtime($filename);
- $cache->put('_cfg_' . $item . '_' . $theme[$item . '_path'], $parsed_array);
+ phpbb::$acm->put('cfg_' . $item . '_' . $theme[$item . '_path'], $parsed_array);
}
return $parsed_array;
@@ -360,63 +396,30 @@ class cache
/**
* Obtain disallowed usernames
+ *
+ * @return array Disallowed usernames
+ * @access public
*/
public static function obtain_disallowed_usernames()
{
- global $cache;
-
- if (($usernames = $cache->get('_disallowed_usernames')) === false)
+ if (($usernames = phpbb::$acm->get('disallowed_usernames')) === false)
{
- global $db;
-
$sql = 'SELECT disallow_username
FROM ' . DISALLOW_TABLE;
- $result = $db->sql_query($sql);
+ $result = phpbb::$db->sql_query($sql);
$usernames = array();
- while ($row = $db->sql_fetchrow($result))
+ while ($row = phpbb::$db->sql_fetchrow($result))
{
$usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#'));
}
- $db->sql_freeresult($result);
+ phpbb::$db->sql_freeresult($result);
- $cache->put('_disallowed_usernames', $usernames);
+ phpbb::$acm->put('disallowed_usernames', $usernames);
}
return $usernames;
}
-
- /**
- * Obtain hooks...
- */
- public static function obtain_hooks()
- {
- global $cache;
-
- if (($hook_files = $cache->get('_hooks')) === false)
- {
- $hook_files = array();
-
- // Now search for hooks...
- $dh = @opendir(PHPBB_ROOT_PATH . 'includes/hooks/');
-
- if ($dh)
- {
- while (($file = readdir($dh)) !== false)
- {
- if (strpos($file, 'hook_') === 0 && substr($file, -(strlen(PHP_EXT) + 1)) === '.' . PHP_EXT)
- {
- $hook_files[] = substr($file, 0, -(strlen(PHP_EXT) + 1));
- }
- }
- closedir($dh);
- }
-
- $cache->put('_hooks', $hook_files);
- }
-
- return $hook_files;
- }
}
?> \ No newline at end of file