source: trunk/forum/includes/cache.php

Last change on this file was 702, checked in by george, 15 years ago
  • Upraveno: Aktualizace fóra.
File size: 9.5 KB
Line 
1<?php
2/**
3*
4* @package acm
5* @version $Id$
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14if (!defined('IN_PHPBB'))
15{
16 exit;
17}
18
19/**
20* Class for grabbing/handling cached entries, extends acm_file or acm_db depending on the setup
21* @package acm
22*/
23class cache extends acm
24{
25 /**
26 * Get config values
27 */
28 function obtain_config()
29 {
30 global $db;
31
32 if (($config = $this->get('config')) !== false)
33 {
34 $sql = 'SELECT config_name, config_value
35 FROM ' . CONFIG_TABLE . '
36 WHERE is_dynamic = 1';
37 $result = $db->sql_query($sql);
38
39 while ($row = $db->sql_fetchrow($result))
40 {
41 $config[$row['config_name']] = $row['config_value'];
42 }
43 $db->sql_freeresult($result);
44 }
45 else
46 {
47 $config = $cached_config = array();
48
49 $sql = 'SELECT config_name, config_value, is_dynamic
50 FROM ' . CONFIG_TABLE;
51 $result = $db->sql_query($sql);
52
53 while ($row = $db->sql_fetchrow($result))
54 {
55 if (!$row['is_dynamic'])
56 {
57 $cached_config[$row['config_name']] = $row['config_value'];
58 }
59
60 $config[$row['config_name']] = $row['config_value'];
61 }
62 $db->sql_freeresult($result);
63
64 $this->put('config', $cached_config);
65 }
66
67 return $config;
68 }
69
70 /**
71 * Obtain list of naughty words and build preg style replacement arrays for use by the
72 * calling script
73 */
74 function obtain_word_list()
75 {
76 global $db;
77
78 if (($censors = $this->get('_word_censors')) === false)
79 {
80 $sql = 'SELECT word, replacement
81 FROM ' . WORDS_TABLE;
82 $result = $db->sql_query($sql);
83
84 $censors = array();
85 while ($row = $db->sql_fetchrow($result))
86 {
87 if ((version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) && @preg_match('/\p{L}/u', 'a') !== false)
88 {
89 $censors['match'][] = '#(?<![\p{Nd}\p{L}_])(' . str_replace('\*', '[\p{Nd}\p{L}_]*?', preg_quote($row['word'], '#')) . ')(?![\p{Nd}\p{L}_])#iu';
90 }
91 else
92 {
93 $censors['match'][] = '#(?<!\S)(' . str_replace('\*', '\S*?', preg_quote($row['word'], '#')) . ')(?!\S)#iu';
94 }
95
96 $censors['replace'][] = $row['replacement'];
97 }
98 $db->sql_freeresult($result);
99
100 $this->put('_word_censors', $censors);
101 }
102
103 return $censors;
104 }
105
106 /**
107 * Obtain currently listed icons
108 */
109 function obtain_icons()
110 {
111 if (($icons = $this->get('_icons')) === false)
112 {
113 global $db;
114
115 // Topic icons
116 $sql = 'SELECT *
117 FROM ' . ICONS_TABLE . '
118 ORDER BY icons_order';
119 $result = $db->sql_query($sql);
120
121 $icons = array();
122 while ($row = $db->sql_fetchrow($result))
123 {
124 $icons[$row['icons_id']]['img'] = $row['icons_url'];
125 $icons[$row['icons_id']]['width'] = (int) $row['icons_width'];
126 $icons[$row['icons_id']]['height'] = (int) $row['icons_height'];
127 $icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting'];
128 }
129 $db->sql_freeresult($result);
130
131 $this->put('_icons', $icons);
132 }
133
134 return $icons;
135 }
136
137 /**
138 * Obtain ranks
139 */
140 function obtain_ranks()
141 {
142 if (($ranks = $this->get('_ranks')) === false)
143 {
144 global $db;
145
146 $sql = 'SELECT *
147 FROM ' . RANKS_TABLE . '
148 ORDER BY rank_min DESC';
149 $result = $db->sql_query($sql);
150
151 $ranks = array();
152 while ($row = $db->sql_fetchrow($result))
153 {
154 if ($row['rank_special'])
155 {
156 $ranks['special'][$row['rank_id']] = array(
157 'rank_title' => $row['rank_title'],
158 'rank_image' => $row['rank_image']
159 );
160 }
161 else
162 {
163 $ranks['normal'][] = array(
164 'rank_title' => $row['rank_title'],
165 'rank_min' => $row['rank_min'],
166 'rank_image' => $row['rank_image']
167 );
168 }
169 }
170 $db->sql_freeresult($result);
171
172 $this->put('_ranks', $ranks);
173 }
174
175 return $ranks;
176 }
177
178 /**
179 * Obtain allowed extensions
180 *
181 * @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.
182 *
183 * @return array allowed extensions array.
184 */
185 function obtain_attach_extensions($forum_id)
186 {
187 if (($extensions = $this->get('_extensions')) === false)
188 {
189 global $db;
190
191 $extensions = array(
192 '_allowed_post' => array(),
193 '_allowed_pm' => array(),
194 );
195
196 // The rule is to only allow those extensions defined. ;)
197 $sql = 'SELECT e.extension, g.*
198 FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
199 WHERE e.group_id = g.group_id
200 AND (g.allow_group = 1 OR g.allow_in_pm = 1)';
201 $result = $db->sql_query($sql);
202
203 while ($row = $db->sql_fetchrow($result))
204 {
205 $extension = strtolower(trim($row['extension']));
206
207 $extensions[$extension] = array(
208 'display_cat' => (int) $row['cat_id'],
209 'download_mode' => (int) $row['download_mode'],
210 'upload_icon' => trim($row['upload_icon']),
211 'max_filesize' => (int) $row['max_filesize'],
212 'allow_group' => $row['allow_group'],
213 'allow_in_pm' => $row['allow_in_pm'],
214 );
215
216 $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
217
218 // Store allowed extensions forum wise
219 if ($row['allow_group'])
220 {
221 $extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums;
222 }
223
224 if ($row['allow_in_pm'])
225 {
226 $extensions['_allowed_pm'][$extension] = 0;
227 }
228 }
229 $db->sql_freeresult($result);
230
231 $this->put('_extensions', $extensions);
232 }
233
234 // Forum post
235 if ($forum_id === false)
236 {
237 // We are checking for private messages, therefore we only need to get the pm extensions...
238 $return = array('_allowed_' => array());
239
240 foreach ($extensions['_allowed_pm'] as $extension => $check)
241 {
242 $return['_allowed_'][$extension] = 0;
243 $return[$extension] = $extensions[$extension];
244 }
245
246 $extensions = $return;
247 }
248 else if ($forum_id === true)
249 {
250 return $extensions;
251 }
252 else
253 {
254 $forum_id = (int) $forum_id;
255 $return = array('_allowed_' => array());
256
257 foreach ($extensions['_allowed_post'] as $extension => $check)
258 {
259 // Check for allowed forums
260 if (is_array($check))
261 {
262 $allowed = (!in_array($forum_id, $check)) ? false : true;
263 }
264 else
265 {
266 $allowed = true;
267 }
268
269 if ($allowed)
270 {
271 $return['_allowed_'][$extension] = 0;
272 $return[$extension] = $extensions[$extension];
273 }
274 }
275
276 $extensions = $return;
277 }
278
279 if (!isset($extensions['_allowed_']))
280 {
281 $extensions['_allowed_'] = array();
282 }
283
284 return $extensions;
285 }
286
287 /**
288 * Obtain active bots
289 */
290 function obtain_bots()
291 {
292 if (($bots = $this->get('_bots')) === false)
293 {
294 global $db;
295
296 switch ($db->sql_layer)
297 {
298 case 'mssql':
299 case 'mssql_odbc':
300 $sql = 'SELECT user_id, bot_agent, bot_ip
301 FROM ' . BOTS_TABLE . '
302 WHERE bot_active = 1
303 ORDER BY LEN(bot_agent) DESC';
304 break;
305
306 case 'firebird':
307 $sql = 'SELECT user_id, bot_agent, bot_ip
308 FROM ' . BOTS_TABLE . '
309 WHERE bot_active = 1
310 ORDER BY CHAR_LENGTH(bot_agent) DESC';
311 break;
312
313 // LENGTH supported by MySQL, IBM DB2 and Oracle for sure...
314 default:
315 $sql = 'SELECT user_id, bot_agent, bot_ip
316 FROM ' . BOTS_TABLE . '
317 WHERE bot_active = 1
318 ORDER BY LENGTH(bot_agent) DESC';
319 break;
320 }
321 $result = $db->sql_query($sql);
322
323 $bots = array();
324 while ($row = $db->sql_fetchrow($result))
325 {
326 $bots[] = $row;
327 }
328 $db->sql_freeresult($result);
329
330 $this->put('_bots', $bots);
331 }
332
333 return $bots;
334 }
335
336 /**
337 * Obtain cfg file data
338 */
339 function obtain_cfg_items($theme)
340 {
341 global $config, $phpbb_root_path;
342
343 $parsed_items = array(
344 'theme' => array(),
345 'template' => array(),
346 'imageset' => array()
347 );
348
349 foreach ($parsed_items as $key => $parsed_array)
350 {
351 $parsed_array = $this->get('_cfg_' . $key . '_' . $theme[$key . '_path']);
352
353 if ($parsed_array === false)
354 {
355 $parsed_array = array();
356 }
357
358 $reparse = false;
359 $filename = $phpbb_root_path . 'styles/' . $theme[$key . '_path'] . '/' . $key . '/' . $key . '.cfg';
360
361 if (!file_exists($filename))
362 {
363 continue;
364 }
365
366 if (!isset($parsed_array['filetime']) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
367 {
368 $reparse = true;
369 }
370
371 // Re-parse cfg file
372 if ($reparse)
373 {
374 $parsed_array = parse_cfg_file($filename);
375 $parsed_array['filetime'] = @filemtime($filename);
376
377 $this->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array);
378 }
379 $parsed_items[$key] = $parsed_array;
380 }
381
382 return $parsed_items;
383 }
384
385 /**
386 * Obtain disallowed usernames
387 */
388 function obtain_disallowed_usernames()
389 {
390 if (($usernames = $this->get('_disallowed_usernames')) === false)
391 {
392 global $db;
393
394 $sql = 'SELECT disallow_username
395 FROM ' . DISALLOW_TABLE;
396 $result = $db->sql_query($sql);
397
398 $usernames = array();
399 while ($row = $db->sql_fetchrow($result))
400 {
401 $usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#'));
402 }
403 $db->sql_freeresult($result);
404
405 $this->put('_disallowed_usernames', $usernames);
406 }
407
408 return $usernames;
409 }
410
411 /**
412 * Obtain hooks...
413 */
414 function obtain_hooks()
415 {
416 global $phpbb_root_path, $phpEx;
417
418 if (($hook_files = $this->get('_hooks')) === false)
419 {
420 $hook_files = array();
421
422 // Now search for hooks...
423 $dh = @opendir($phpbb_root_path . 'includes/hooks/');
424
425 if ($dh)
426 {
427 while (($file = readdir($dh)) !== false)
428 {
429 if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($phpEx) + 1)) === '.' . $phpEx)
430 {
431 $hook_files[] = substr($file, 0, -(strlen($phpEx) + 1));
432 }
433 }
434 closedir($dh);
435 }
436
437 $this->put('_hooks', $hook_files);
438 }
439
440 return $hook_files;
441 }
442}
443
444?>
Note: See TracBrowser for help on using the repository browser.