1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/cache.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,437 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package acm
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* Class for grabbing/handling cached entries, extends acm_file or acm_db depending on the setup
1.24 +* @package acm
1.25 +*/
1.26 +class cache extends acm
1.27 +{
1.28 + /**
1.29 + * Get config values
1.30 + */
1.31 + function obtain_config()
1.32 + {
1.33 + global $db;
1.34 +
1.35 + if (($config = $this->get('config')) !== false)
1.36 + {
1.37 + $sql = 'SELECT config_name, config_value
1.38 + FROM ' . CONFIG_TABLE . '
1.39 + WHERE is_dynamic = 1';
1.40 + $result = $db->sql_query($sql);
1.41 +
1.42 + while ($row = $db->sql_fetchrow($result))
1.43 + {
1.44 + $config[$row['config_name']] = $row['config_value'];
1.45 + }
1.46 + $db->sql_freeresult($result);
1.47 + }
1.48 + else
1.49 + {
1.50 + $config = $cached_config = array();
1.51 +
1.52 + $sql = 'SELECT config_name, config_value, is_dynamic
1.53 + FROM ' . CONFIG_TABLE;
1.54 + $result = $db->sql_query($sql);
1.55 +
1.56 + while ($row = $db->sql_fetchrow($result))
1.57 + {
1.58 + if (!$row['is_dynamic'])
1.59 + {
1.60 + $cached_config[$row['config_name']] = $row['config_value'];
1.61 + }
1.62 +
1.63 + $config[$row['config_name']] = $row['config_value'];
1.64 + }
1.65 + $db->sql_freeresult($result);
1.66 +
1.67 + $this->put('config', $cached_config);
1.68 + }
1.69 +
1.70 + return $config;
1.71 + }
1.72 +
1.73 + /**
1.74 + * Obtain list of naughty words and build preg style replacement arrays for use by the
1.75 + * calling script
1.76 + */
1.77 + function obtain_word_list()
1.78 + {
1.79 + global $db;
1.80 +
1.81 + if (($censors = $this->get('_word_censors')) === false)
1.82 + {
1.83 + $sql = 'SELECT word, replacement
1.84 + FROM ' . WORDS_TABLE;
1.85 + $result = $db->sql_query($sql);
1.86 +
1.87 + $censors = array();
1.88 + while ($row = $db->sql_fetchrow($result))
1.89 + {
1.90 + $censors['match'][] = get_censor_preg_expression($row['word']);
1.91 + $censors['replace'][] = $row['replacement'];
1.92 + }
1.93 + $db->sql_freeresult($result);
1.94 +
1.95 + $this->put('_word_censors', $censors);
1.96 + }
1.97 +
1.98 + return $censors;
1.99 + }
1.100 +
1.101 + /**
1.102 + * Obtain currently listed icons
1.103 + */
1.104 + function obtain_icons()
1.105 + {
1.106 + if (($icons = $this->get('_icons')) === false)
1.107 + {
1.108 + global $db;
1.109 +
1.110 + // Topic icons
1.111 + $sql = 'SELECT *
1.112 + FROM ' . ICONS_TABLE . '
1.113 + ORDER BY icons_order';
1.114 + $result = $db->sql_query($sql);
1.115 +
1.116 + $icons = array();
1.117 + while ($row = $db->sql_fetchrow($result))
1.118 + {
1.119 + $icons[$row['icons_id']]['img'] = $row['icons_url'];
1.120 + $icons[$row['icons_id']]['width'] = (int) $row['icons_width'];
1.121 + $icons[$row['icons_id']]['height'] = (int) $row['icons_height'];
1.122 + $icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting'];
1.123 + }
1.124 + $db->sql_freeresult($result);
1.125 +
1.126 + $this->put('_icons', $icons);
1.127 + }
1.128 +
1.129 + return $icons;
1.130 + }
1.131 +
1.132 + /**
1.133 + * Obtain ranks
1.134 + */
1.135 + function obtain_ranks()
1.136 + {
1.137 + if (($ranks = $this->get('_ranks')) === false)
1.138 + {
1.139 + global $db;
1.140 +
1.141 + $sql = 'SELECT *
1.142 + FROM ' . RANKS_TABLE . '
1.143 + ORDER BY rank_min DESC';
1.144 + $result = $db->sql_query($sql);
1.145 +
1.146 + $ranks = array();
1.147 + while ($row = $db->sql_fetchrow($result))
1.148 + {
1.149 + if ($row['rank_special'])
1.150 + {
1.151 + $ranks['special'][$row['rank_id']] = array(
1.152 + 'rank_title' => $row['rank_title'],
1.153 + 'rank_image' => $row['rank_image']
1.154 + );
1.155 + }
1.156 + else
1.157 + {
1.158 + $ranks['normal'][] = array(
1.159 + 'rank_title' => $row['rank_title'],
1.160 + 'rank_min' => $row['rank_min'],
1.161 + 'rank_image' => $row['rank_image']
1.162 + );
1.163 + }
1.164 + }
1.165 + $db->sql_freeresult($result);
1.166 +
1.167 + $this->put('_ranks', $ranks);
1.168 + }
1.169 +
1.170 + return $ranks;
1.171 + }
1.172 +
1.173 + /**
1.174 + * Obtain allowed extensions
1.175 + *
1.176 + * @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.
1.177 + *
1.178 + * @return array allowed extensions array.
1.179 + */
1.180 + function obtain_attach_extensions($forum_id)
1.181 + {
1.182 + if (($extensions = $this->get('_extensions')) === false)
1.183 + {
1.184 + global $db;
1.185 +
1.186 + $extensions = array(
1.187 + '_allowed_post' => array(),
1.188 + '_allowed_pm' => array(),
1.189 + );
1.190 +
1.191 + // The rule is to only allow those extensions defined. ;)
1.192 + $sql = 'SELECT e.extension, g.*
1.193 + FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
1.194 + WHERE e.group_id = g.group_id
1.195 + AND (g.allow_group = 1 OR g.allow_in_pm = 1)';
1.196 + $result = $db->sql_query($sql);
1.197 +
1.198 + while ($row = $db->sql_fetchrow($result))
1.199 + {
1.200 + $extension = strtolower(trim($row['extension']));
1.201 +
1.202 + $extensions[$extension] = array(
1.203 + 'display_cat' => (int) $row['cat_id'],
1.204 + 'download_mode' => (int) $row['download_mode'],
1.205 + 'upload_icon' => trim($row['upload_icon']),
1.206 + 'max_filesize' => (int) $row['max_filesize'],
1.207 + 'allow_group' => $row['allow_group'],
1.208 + 'allow_in_pm' => $row['allow_in_pm'],
1.209 + );
1.210 +
1.211 + $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
1.212 +
1.213 + // Store allowed extensions forum wise
1.214 + if ($row['allow_group'])
1.215 + {
1.216 + $extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums;
1.217 + }
1.218 +
1.219 + if ($row['allow_in_pm'])
1.220 + {
1.221 + $extensions['_allowed_pm'][$extension] = 0;
1.222 + }
1.223 + }
1.224 + $db->sql_freeresult($result);
1.225 +
1.226 + $this->put('_extensions', $extensions);
1.227 + }
1.228 +
1.229 + // Forum post
1.230 + if ($forum_id === false)
1.231 + {
1.232 + // We are checking for private messages, therefore we only need to get the pm extensions...
1.233 + $return = array('_allowed_' => array());
1.234 +
1.235 + foreach ($extensions['_allowed_pm'] as $extension => $check)
1.236 + {
1.237 + $return['_allowed_'][$extension] = 0;
1.238 + $return[$extension] = $extensions[$extension];
1.239 + }
1.240 +
1.241 + $extensions = $return;
1.242 + }
1.243 + else if ($forum_id === true)
1.244 + {
1.245 + return $extensions;
1.246 + }
1.247 + else
1.248 + {
1.249 + $forum_id = (int) $forum_id;
1.250 + $return = array('_allowed_' => array());
1.251 +
1.252 + foreach ($extensions['_allowed_post'] as $extension => $check)
1.253 + {
1.254 + // Check for allowed forums
1.255 + if (is_array($check))
1.256 + {
1.257 + $allowed = (!in_array($forum_id, $check)) ? false : true;
1.258 + }
1.259 + else
1.260 + {
1.261 + $allowed = true;
1.262 + }
1.263 +
1.264 + if ($allowed)
1.265 + {
1.266 + $return['_allowed_'][$extension] = 0;
1.267 + $return[$extension] = $extensions[$extension];
1.268 + }
1.269 + }
1.270 +
1.271 + $extensions = $return;
1.272 + }
1.273 +
1.274 + if (!isset($extensions['_allowed_']))
1.275 + {
1.276 + $extensions['_allowed_'] = array();
1.277 + }
1.278 +
1.279 + return $extensions;
1.280 + }
1.281 +
1.282 + /**
1.283 + * Obtain active bots
1.284 + */
1.285 + function obtain_bots()
1.286 + {
1.287 + if (($bots = $this->get('_bots')) === false)
1.288 + {
1.289 + global $db;
1.290 +
1.291 + switch ($db->sql_layer)
1.292 + {
1.293 + case 'mssql':
1.294 + case 'mssql_odbc':
1.295 + case 'mssqlnative':
1.296 + $sql = 'SELECT user_id, bot_agent, bot_ip
1.297 + FROM ' . BOTS_TABLE . '
1.298 + WHERE bot_active = 1
1.299 + ORDER BY LEN(bot_agent) DESC';
1.300 + break;
1.301 +
1.302 + case 'firebird':
1.303 + $sql = 'SELECT user_id, bot_agent, bot_ip
1.304 + FROM ' . BOTS_TABLE . '
1.305 + WHERE bot_active = 1
1.306 + ORDER BY CHAR_LENGTH(bot_agent) DESC';
1.307 + break;
1.308 +
1.309 + // LENGTH supported by MySQL, IBM DB2 and Oracle for sure...
1.310 + default:
1.311 + $sql = 'SELECT user_id, bot_agent, bot_ip
1.312 + FROM ' . BOTS_TABLE . '
1.313 + WHERE bot_active = 1
1.314 + ORDER BY LENGTH(bot_agent) DESC';
1.315 + break;
1.316 + }
1.317 + $result = $db->sql_query($sql);
1.318 +
1.319 + $bots = array();
1.320 + while ($row = $db->sql_fetchrow($result))
1.321 + {
1.322 + $bots[] = $row;
1.323 + }
1.324 + $db->sql_freeresult($result);
1.325 +
1.326 + $this->put('_bots', $bots);
1.327 + }
1.328 +
1.329 + return $bots;
1.330 + }
1.331 +
1.332 + /**
1.333 + * Obtain cfg file data
1.334 + */
1.335 + function obtain_cfg_items($theme)
1.336 + {
1.337 + global $config, $phpbb_root_path;
1.338 +
1.339 + $parsed_items = array(
1.340 + 'theme' => array(),
1.341 + 'template' => array(),
1.342 + 'imageset' => array()
1.343 + );
1.344 +
1.345 + foreach ($parsed_items as $key => $parsed_array)
1.346 + {
1.347 + $parsed_array = $this->get('_cfg_' . $key . '_' . $theme[$key . '_path']);
1.348 +
1.349 + if ($parsed_array === false)
1.350 + {
1.351 + $parsed_array = array();
1.352 + }
1.353 +
1.354 + $reparse = false;
1.355 + $filename = $phpbb_root_path . 'styles/' . $theme[$key . '_path'] . '/' . $key . '/' . $key . '.cfg';
1.356 +
1.357 + if (!file_exists($filename))
1.358 + {
1.359 + continue;
1.360 + }
1.361 +
1.362 + if (!isset($parsed_array['filetime']) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
1.363 + {
1.364 + $reparse = true;
1.365 + }
1.366 +
1.367 + // Re-parse cfg file
1.368 + if ($reparse)
1.369 + {
1.370 + $parsed_array = parse_cfg_file($filename);
1.371 + $parsed_array['filetime'] = @filemtime($filename);
1.372 +
1.373 + $this->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array);
1.374 + }
1.375 + $parsed_items[$key] = $parsed_array;
1.376 + }
1.377 +
1.378 + return $parsed_items;
1.379 + }
1.380 +
1.381 + /**
1.382 + * Obtain disallowed usernames
1.383 + */
1.384 + function obtain_disallowed_usernames()
1.385 + {
1.386 + if (($usernames = $this->get('_disallowed_usernames')) === false)
1.387 + {
1.388 + global $db;
1.389 +
1.390 + $sql = 'SELECT disallow_username
1.391 + FROM ' . DISALLOW_TABLE;
1.392 + $result = $db->sql_query($sql);
1.393 +
1.394 + $usernames = array();
1.395 + while ($row = $db->sql_fetchrow($result))
1.396 + {
1.397 + $usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#'));
1.398 + }
1.399 + $db->sql_freeresult($result);
1.400 +
1.401 + $this->put('_disallowed_usernames', $usernames);
1.402 + }
1.403 +
1.404 + return $usernames;
1.405 + }
1.406 +
1.407 + /**
1.408 + * Obtain hooks...
1.409 + */
1.410 + function obtain_hooks()
1.411 + {
1.412 + global $phpbb_root_path, $phpEx;
1.413 +
1.414 + if (($hook_files = $this->get('_hooks')) === false)
1.415 + {
1.416 + $hook_files = array();
1.417 +
1.418 + // Now search for hooks...
1.419 + $dh = @opendir($phpbb_root_path . 'includes/hooks/');
1.420 +
1.421 + if ($dh)
1.422 + {
1.423 + while (($file = readdir($dh)) !== false)
1.424 + {
1.425 + if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($phpEx) + 1)) === '.' . $phpEx)
1.426 + {
1.427 + $hook_files[] = substr($file, 0, -(strlen($phpEx) + 1));
1.428 + }
1.429 + }
1.430 + closedir($dh);
1.431 + }
1.432 +
1.433 + $this->put('_hooks', $hook_files);
1.434 + }
1.435 +
1.436 + return $hook_files;
1.437 + }
1.438 +}
1.439 +
1.440 +?>
1.441 \ No newline at end of file