5
* @version $Id: cache.php,v 1.14 2007/12/05 16:34:38 acydburn Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
14
if (!defined('IN_PHPBB'))
20
* Class for grabbing/handling cached entries, extends acm_file or acm_db depending on the setup
23
class cache extends acm
28
function obtain_config()
32
if (($config = $this->get('config')) !== false)
34
$sql = 'SELECT config_name, config_value
35
FROM ' . CONFIG_TABLE . '
36
WHERE is_dynamic = 1';
37
$result = $db->sql_query($sql);
39
while ($row = $db->sql_fetchrow($result))
41
$config[$row['config_name']] = $row['config_value'];
43
$db->sql_freeresult($result);
47
$config = $cached_config = array();
49
$sql = 'SELECT config_name, config_value, is_dynamic
50
FROM ' . CONFIG_TABLE;
51
$result = $db->sql_query($sql);
53
while ($row = $db->sql_fetchrow($result))
55
if (!$row['is_dynamic'])
57
$cached_config[$row['config_name']] = $row['config_value'];
60
$config[$row['config_name']] = $row['config_value'];
62
$db->sql_freeresult($result);
64
$this->put('config', $cached_config);
71
* Obtain list of naughty words and build preg style replacement arrays for use by the
74
function obtain_word_list()
78
if (($censors = $this->get('_word_censors')) === false)
80
$sql = 'SELECT word, replacement
82
$result = $db->sql_query($sql);
85
while ($row = $db->sql_fetchrow($result))
87
$censors['match'][] = '#(?<!\w)(' . str_replace('\*', '\w*?', preg_quote($row['word'], '#')) . ')(?!\w)#i';
88
$censors['replace'][] = $row['replacement'];
90
$db->sql_freeresult($result);
92
$this->put('_word_censors', $censors);
99
* Obtain currently listed icons
101
function obtain_icons()
103
if (($icons = $this->get('_icons')) === false)
109
FROM ' . ICONS_TABLE . '
110
ORDER BY icons_order';
111
$result = $db->sql_query($sql);
114
while ($row = $db->sql_fetchrow($result))
116
$icons[$row['icons_id']]['img'] = $row['icons_url'];
117
$icons[$row['icons_id']]['width'] = (int) $row['icons_width'];
118
$icons[$row['icons_id']]['height'] = (int) $row['icons_height'];
119
$icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting'];
121
$db->sql_freeresult($result);
123
$this->put('_icons', $icons);
132
function obtain_ranks()
134
if (($ranks = $this->get('_ranks')) === false)
139
FROM ' . RANKS_TABLE . '
140
ORDER BY rank_min DESC';
141
$result = $db->sql_query($sql);
144
while ($row = $db->sql_fetchrow($result))
146
if ($row['rank_special'])
148
$ranks['special'][$row['rank_id']] = array(
149
'rank_title' => $row['rank_title'],
150
'rank_image' => $row['rank_image']
155
$ranks['normal'][] = array(
156
'rank_title' => $row['rank_title'],
157
'rank_min' => $row['rank_min'],
158
'rank_image' => $row['rank_image']
162
$db->sql_freeresult($result);
164
$this->put('_ranks', $ranks);
171
* Obtain allowed extensions
173
* @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.
175
* @return array allowed extensions array.
177
function obtain_attach_extensions($forum_id)
179
if (($extensions = $this->get('_extensions')) === false)
184
'_allowed_post' => array(),
185
'_allowed_pm' => array(),
188
// The rule is to only allow those extensions defined. ;)
189
$sql = 'SELECT e.extension, g.*
190
FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
191
WHERE e.group_id = g.group_id
192
AND (g.allow_group = 1 OR g.allow_in_pm = 1)';
193
$result = $db->sql_query($sql);
195
while ($row = $db->sql_fetchrow($result))
197
$extension = strtolower(trim($row['extension']));
199
$extensions[$extension] = array(
200
'display_cat' => (int) $row['cat_id'],
201
'download_mode' => (int) $row['download_mode'],
202
'upload_icon' => trim($row['upload_icon']),
203
'max_filesize' => (int) $row['max_filesize'],
204
'allow_group' => $row['allow_group'],
205
'allow_in_pm' => $row['allow_in_pm'],
208
$allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
210
// Store allowed extensions forum wise
211
if ($row['allow_group'])
213
$extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums;
216
if ($row['allow_in_pm'])
218
$extensions['_allowed_pm'][$extension] = 0;
221
$db->sql_freeresult($result);
223
$this->put('_extensions', $extensions);
227
if ($forum_id === false)
229
// We are checking for private messages, therefore we only need to get the pm extensions...
230
$return = array('_allowed_' => array());
232
foreach ($extensions['_allowed_pm'] as $extension => $check)
234
$return['_allowed_'][$extension] = 0;
235
$return[$extension] = $extensions[$extension];
238
$extensions = $return;
240
else if ($forum_id === true)
246
$forum_id = (int) $forum_id;
247
$return = array('_allowed_' => array());
249
foreach ($extensions['_allowed_post'] as $extension => $check)
251
// Check for allowed forums
252
if (is_array($check))
254
$allowed = (!in_array($forum_id, $check)) ? false : true;
263
$return['_allowed_'][$extension] = 0;
264
$return[$extension] = $extensions[$extension];
268
$extensions = $return;
271
if (!isset($extensions['_allowed_']))
273
$extensions['_allowed_'] = array();
282
function obtain_bots()
284
if (($bots = $this->get('_bots')) === false)
288
switch ($db->sql_layer)
292
$sql = 'SELECT user_id, bot_agent, bot_ip
293
FROM ' . BOTS_TABLE . '
295
ORDER BY LEN(bot_agent) DESC';
299
$sql = 'SELECT user_id, bot_agent, bot_ip
300
FROM ' . BOTS_TABLE . '
302
ORDER BY CHAR_LENGTH(bot_agent) DESC';
305
// LENGTH supported by MySQL, IBM DB2 and Oracle for sure...
307
$sql = 'SELECT user_id, bot_agent, bot_ip
308
FROM ' . BOTS_TABLE . '
310
ORDER BY LENGTH(bot_agent) DESC';
313
$result = $db->sql_query($sql);
316
while ($row = $db->sql_fetchrow($result))
320
$db->sql_freeresult($result);
322
$this->put('_bots', $bots);
329
* Obtain cfg file data
331
function obtain_cfg_items($theme)
333
global $config, $phpbb_root_path;
335
$parsed_items = array(
337
'template' => array(),
338
'imageset' => array()
341
foreach ($parsed_items as $key => $parsed_array)
343
$parsed_array = $this->get('_cfg_' . $key . '_' . $theme[$key . '_path']);
345
if ($parsed_array === false)
347
$parsed_array = array();
351
$filename = $phpbb_root_path . 'styles/' . $theme[$key . '_path'] . '/' . $key . '/' . $key . '.cfg';
353
if (!file_exists($filename))
358
if (!isset($parsed_array['filetime']) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
366
$parsed_array = parse_cfg_file($filename);
367
$parsed_array['filetime'] = @filemtime($filename);
369
$this->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array);
371
$parsed_items[$key] = $parsed_array;
374
return $parsed_items;
378
* Obtain disallowed usernames
380
function obtain_disallowed_usernames()
382
if (($usernames = $this->get('_disallowed_usernames')) === false)
386
$sql = 'SELECT disallow_username
387
FROM ' . DISALLOW_TABLE;
388
$result = $db->sql_query($sql);
390
$usernames = array();
391
while ($row = $db->sql_fetchrow($result))
393
$usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#'));
395
$db->sql_freeresult($result);
397
$this->put('_disallowed_usernames', $usernames);
406
function obtain_hooks()
408
global $phpbb_root_path, $phpEx;
410
if (($hook_files = $this->get('_hooks')) === false)
412
$hook_files = array();
414
// Now search for hooks...
415
$dh = @opendir($phpbb_root_path . 'includes/hooks/');
419
while (($file = readdir($dh)) !== false)
421
if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($phpEx) + 1)) === '.' . $phpEx)
423
$hook_files[] = substr($file, 0, -(strlen($phpEx) + 1));
429
$this->put('_hooks', $hook_files);
b'\\ No newline at end of file'