~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/php/phpBB3/includes/cache.php

ivle.config.Config: Added set_by_path method (based on code from
    setup.configure).
setup.configure: Use ivle.config.Config.set_by_path rather than doing it
    manually.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
*
 
4
* @package acm
 
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
 
8
*
 
9
*/
 
10
 
 
11
/**
 
12
* @ignore
 
13
*/
 
14
if (!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
*/
 
23
class 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
                                $censors['match'][] = '#(?<!\w)(' . str_replace('\*', '\w*?', preg_quote($row['word'], '#')) . ')(?!\w)#i';
 
88
                                $censors['replace'][] = $row['replacement'];
 
89
                        }
 
90
                        $db->sql_freeresult($result);
 
91
 
 
92
                        $this->put('_word_censors', $censors);
 
93
                }
 
94
 
 
95
                return $censors;
 
96
        }
 
97
 
 
98
        /**
 
99
        * Obtain currently listed icons
 
100
        */
 
101
        function obtain_icons()
 
102
        {
 
103
                if (($icons = $this->get('_icons')) === false)
 
104
                {
 
105
                        global $db;
 
106
        
 
107
                        // Topic icons
 
108
                        $sql = 'SELECT *
 
109
                                FROM ' . ICONS_TABLE . '
 
110
                                ORDER BY icons_order';
 
111
                        $result = $db->sql_query($sql);
 
112
 
 
113
                        $icons = array();
 
114
                        while ($row = $db->sql_fetchrow($result))
 
115
                        {
 
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'];
 
120
                        }
 
121
                        $db->sql_freeresult($result);
 
122
 
 
123
                        $this->put('_icons', $icons);
 
124
                }
 
125
 
 
126
                return $icons;
 
127
        }
 
128
 
 
129
        /**
 
130
        * Obtain ranks
 
131
        */
 
132
        function obtain_ranks()
 
133
        {
 
134
                if (($ranks = $this->get('_ranks')) === false)
 
135
                {
 
136
                        global $db;
 
137
        
 
138
                        $sql = 'SELECT *
 
139
                                FROM ' . RANKS_TABLE . '
 
140
                                ORDER BY rank_min DESC';
 
141
                        $result = $db->sql_query($sql);
 
142
 
 
143
                        $ranks = array();
 
144
                        while ($row = $db->sql_fetchrow($result))
 
145
                        {
 
146
                                if ($row['rank_special'])
 
147
                                {
 
148
                                        $ranks['special'][$row['rank_id']] = array(
 
149
                                                'rank_title'    =>      $row['rank_title'],
 
150
                                                'rank_image'    =>      $row['rank_image']
 
151
                                        );
 
152
                                }
 
153
                                else
 
154
                                {
 
155
                                        $ranks['normal'][] = array(
 
156
                                                'rank_title'    =>      $row['rank_title'],
 
157
                                                'rank_min'              =>      $row['rank_min'],
 
158
                                                'rank_image'    =>      $row['rank_image']
 
159
                                        );
 
160
                                }
 
161
                        }
 
162
                        $db->sql_freeresult($result);
 
163
 
 
164
                        $this->put('_ranks', $ranks);
 
165
                }
 
166
 
 
167
                return $ranks;
 
168
        }
 
169
 
 
170
        /**
 
171
        * Obtain allowed extensions
 
172
        *
 
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.
 
174
        *
 
175
        * @return array allowed extensions array.
 
176
        */
 
177
        function obtain_attach_extensions($forum_id)
 
178
        {
 
179
                if (($extensions = $this->get('_extensions')) === false)
 
180
                {
 
181
                        global $db;
 
182
 
 
183
                        $extensions = array(
 
184
                                '_allowed_post' => array(),
 
185
                                '_allowed_pm'   => array(),
 
186
                        );
 
187
 
 
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);
 
194
 
 
195
                        while ($row = $db->sql_fetchrow($result))
 
196
                        {
 
197
                                $extension = strtolower(trim($row['extension']));
 
198
 
 
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'],
 
206
                                );
 
207
 
 
208
                                $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
 
209
 
 
210
                                // Store allowed extensions forum wise
 
211
                                if ($row['allow_group'])
 
212
                                {
 
213
                                        $extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums;
 
214
                                }
 
215
 
 
216
                                if ($row['allow_in_pm'])
 
217
                                {
 
218
                                        $extensions['_allowed_pm'][$extension] = 0;
 
219
                                }
 
220
                        }
 
221
                        $db->sql_freeresult($result);
 
222
 
 
223
                        $this->put('_extensions', $extensions);
 
224
                }
 
225
 
 
226
                // Forum post
 
227
                if ($forum_id === false)
 
228
                {
 
229
                        // We are checking for private messages, therefore we only need to get the pm extensions...
 
230
                        $return = array('_allowed_' => array());
 
231
 
 
232
                        foreach ($extensions['_allowed_pm'] as $extension => $check)
 
233
                        {
 
234
                                $return['_allowed_'][$extension] = 0;
 
235
                                $return[$extension] = $extensions[$extension];
 
236
                        }
 
237
 
 
238
                        $extensions = $return;
 
239
                }
 
240
                else if ($forum_id === true)
 
241
                {
 
242
                        return $extensions;
 
243
                }
 
244
                else
 
245
                {
 
246
                        $forum_id = (int) $forum_id;
 
247
                        $return = array('_allowed_' => array());
 
248
 
 
249
                        foreach ($extensions['_allowed_post'] as $extension => $check)
 
250
                        {
 
251
                                // Check for allowed forums
 
252
                                if (is_array($check))
 
253
                                {
 
254
                                        $allowed = (!in_array($forum_id, $check)) ? false : true;
 
255
                                }
 
256
                                else
 
257
                                {
 
258
                                        $allowed = true;
 
259
                                }
 
260
 
 
261
                                if ($allowed)
 
262
                                {
 
263
                                        $return['_allowed_'][$extension] = 0;
 
264
                                        $return[$extension] = $extensions[$extension];
 
265
                                }
 
266
                        }
 
267
 
 
268
                        $extensions = $return;
 
269
                }
 
270
 
 
271
                if (!isset($extensions['_allowed_']))
 
272
                {
 
273
                        $extensions['_allowed_'] = array();
 
274
                }
 
275
 
 
276
                return $extensions;
 
277
        }
 
278
 
 
279
        /**
 
280
        * Obtain active bots
 
281
        */
 
282
        function obtain_bots()
 
283
        {
 
284
                if (($bots = $this->get('_bots')) === false)
 
285
                {
 
286
                        global $db;
 
287
        
 
288
                        switch ($db->sql_layer)
 
289
                        {
 
290
                                case 'mssql':
 
291
                                case 'mssql_odbc':
 
292
                                        $sql = 'SELECT user_id, bot_agent, bot_ip
 
293
                                                FROM ' . BOTS_TABLE . '
 
294
                                                WHERE bot_active = 1
 
295
                                        ORDER BY LEN(bot_agent) DESC';
 
296
                                break;
 
297
 
 
298
                                case 'firebird':
 
299
                                        $sql = 'SELECT user_id, bot_agent, bot_ip
 
300
                                                FROM ' . BOTS_TABLE . '
 
301
                                                WHERE bot_active = 1
 
302
                                        ORDER BY CHAR_LENGTH(bot_agent) DESC';
 
303
                                break;
 
304
 
 
305
                                // LENGTH supported by MySQL, IBM DB2 and Oracle for sure...
 
306
                                default:
 
307
                                        $sql = 'SELECT user_id, bot_agent, bot_ip
 
308
                                                FROM ' . BOTS_TABLE . '
 
309
                                                WHERE bot_active = 1
 
310
                                        ORDER BY LENGTH(bot_agent) DESC';
 
311
                                break;
 
312
                        }
 
313
                        $result = $db->sql_query($sql);
 
314
 
 
315
                        $bots = array();
 
316
                        while ($row = $db->sql_fetchrow($result))
 
317
                        {
 
318
                                $bots[] = $row;
 
319
                        }
 
320
                        $db->sql_freeresult($result);
 
321
 
 
322
                        $this->put('_bots', $bots);
 
323
                }
 
324
        
 
325
                return $bots;
 
326
        }
 
327
 
 
328
        /**
 
329
        * Obtain cfg file data
 
330
        */
 
331
        function obtain_cfg_items($theme)
 
332
        {
 
333
                global $config, $phpbb_root_path;
 
334
 
 
335
                $parsed_items = array(
 
336
                        'theme'         => array(),
 
337
                        'template'      => array(),
 
338
                        'imageset'      => array()
 
339
                );
 
340
 
 
341
                foreach ($parsed_items as $key => $parsed_array)
 
342
                {
 
343
                        $parsed_array = $this->get('_cfg_' . $key . '_' . $theme[$key . '_path']);
 
344
 
 
345
                        if ($parsed_array === false)
 
346
                        {
 
347
                                $parsed_array = array();
 
348
                        }
 
349
 
 
350
                        $reparse = false;
 
351
                        $filename = $phpbb_root_path . 'styles/' . $theme[$key . '_path'] . '/' . $key . '/' . $key . '.cfg';
 
352
 
 
353
                        if (!file_exists($filename))
 
354
                        {
 
355
                                continue;
 
356
                        }
 
357
 
 
358
                        if (!isset($parsed_array['filetime']) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
 
359
                        {
 
360
                                $reparse = true;
 
361
                        }
 
362
 
 
363
                        // Re-parse cfg file
 
364
                        if ($reparse)
 
365
                        {
 
366
                                $parsed_array = parse_cfg_file($filename);
 
367
                                $parsed_array['filetime'] = @filemtime($filename);
 
368
 
 
369
                                $this->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array);
 
370
                        }
 
371
                        $parsed_items[$key] = $parsed_array;
 
372
                }
 
373
 
 
374
                return $parsed_items;
 
375
        }
 
376
 
 
377
        /**
 
378
        * Obtain disallowed usernames
 
379
        */
 
380
        function obtain_disallowed_usernames()
 
381
        {
 
382
                if (($usernames = $this->get('_disallowed_usernames')) === false)
 
383
                {
 
384
                        global $db;
 
385
 
 
386
                        $sql = 'SELECT disallow_username
 
387
                                FROM ' . DISALLOW_TABLE;
 
388
                        $result = $db->sql_query($sql);
 
389
 
 
390
                        $usernames = array();
 
391
                        while ($row = $db->sql_fetchrow($result))
 
392
                        {
 
393
                                $usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#'));
 
394
                        }
 
395
                        $db->sql_freeresult($result);
 
396
 
 
397
                        $this->put('_disallowed_usernames', $usernames);
 
398
                }
 
399
 
 
400
                return $usernames;
 
401
        }
 
402
 
 
403
        /**
 
404
        * Obtain hooks...
 
405
        */
 
406
        function obtain_hooks()
 
407
        {
 
408
                global $phpbb_root_path, $phpEx;
 
409
 
 
410
                if (($hook_files = $this->get('_hooks')) === false)
 
411
                {
 
412
                        $hook_files = array();
 
413
 
 
414
                        // Now search for hooks...
 
415
                        $dh = @opendir($phpbb_root_path . 'includes/hooks/');
 
416
 
 
417
                        if ($dh)
 
418
                        {
 
419
                                while (($file = readdir($dh)) !== false)
 
420
                                {
 
421
                                        if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($phpEx) + 1)) === '.' . $phpEx)
 
422
                                        {
 
423
                                                $hook_files[] = substr($file, 0, -(strlen($phpEx) + 1));
 
424
                                        }
 
425
                                }
 
426
                                closedir($dh);
 
427
                        }
 
428
 
 
429
                        $this->put('_hooks', $hook_files);
 
430
                }
 
431
 
 
432
                return $hook_files;
 
433
        }
 
434
}
 
435
 
 
436
?>
 
 
b'\\ No newline at end of file'