Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
service.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\cache;
015
016 /**
017 * Class for grabbing/handling cached entries
018 */
019 class service
020 {
021 /**
022 * Cache driver.
023 *
024 * @var \phpbb\cache\driver\driver_interface
025 */
026 protected $driver;
027
028 /**
029 * The config.
030 *
031 * @var \phpbb\config\config
032 */
033 protected $config;
034
035 /**
036 * Database connection.
037 *
038 * @var \phpbb\db\driver\driver_interface
039 */
040 protected $db;
041
042 /**
043 * Root path.
044 *
045 * @var string
046 */
047 protected $phpbb_root_path;
048
049 /**
050 * PHP file extension.
051 *
052 * @var string
053 */
054 protected $php_ext;
055
056 /**
057 * Creates a cache service around a cache driver
058 *
059 * @param \phpbb\cache\driver\driver_interface $driver The cache driver
060 * @param \phpbb\config\config $config The config
061 * @param \phpbb\db\driver\driver_interface $db Database connection
062 * @param string $phpbb_root_path Root path
063 * @param string $php_ext PHP file extension
064 */
065 public function __construct(\phpbb\cache\driver\driver_interface $driver, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext)
066 {
067 $this->set_driver($driver);
068 $this->config = $config;
069 $this->db = $db;
070 $this->phpbb_root_path = $phpbb_root_path;
071 $this->php_ext = $php_ext;
072 }
073
074 /**
075 * Returns the cache driver used by this cache service.
076 *
077 * @return \phpbb\cache\driver\driver_interface The cache driver
078 */
079 public function get_driver()
080 {
081 return $this->driver;
082 }
083
084 /**
085 * Replaces the cache driver used by this cache service.
086 *
087 * @param \phpbb\cache\driver\driver_interface $driver The cache driver
088 */
089 public function set_driver(\phpbb\cache\driver\driver_interface $driver)
090 {
091 $this->driver = $driver;
092 }
093
094 public function __call($method, $arguments)
095 {
096 return call_user_func_array(array($this->driver, $method), $arguments);
097 }
098
099 /**
100 * Obtain list of naughty words and build preg style replacement arrays for use by the
101 * calling script
102 */
103 function obtain_word_list()
104 {
105 if (($censors = $this->driver->get('_word_censors')) === false)
106 {
107 $sql = 'SELECT word, replacement
108 FROM ' . WORDS_TABLE;
109 $result = $this->db->sql_query($sql);
110
111 $censors = array();
112 while ($row = $this->db->sql_fetchrow($result))
113 {
114 $censors['match'][] = get_censor_preg_expression($row['word']);
115 $censors['replace'][] = $row['replacement'];
116 }
117 $this->db->sql_freeresult($result);
118
119 $this->driver->put('_word_censors', $censors);
120 }
121
122 return $censors;
123 }
124
125 /**
126 * Obtain currently listed icons
127 */
128 function obtain_icons()
129 {
130 if (($icons = $this->driver->get('_icons')) === false)
131 {
132 // Topic icons
133 $sql = 'SELECT *
134 FROM ' . ICONS_TABLE . '
135 ORDER BY icons_order';
136 $result = $this->db->sql_query($sql);
137
138 $icons = array();
139 while ($row = $this->db->sql_fetchrow($result))
140 {
141 $icons[$row['icons_id']]['img'] = $row['icons_url'];
142 $icons[$row['icons_id']]['width'] = (int) $row['icons_width'];
143 $icons[$row['icons_id']]['height'] = (int) $row['icons_height'];
144 $icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting'];
145 }
146 $this->db->sql_freeresult($result);
147
148 $this->driver->put('_icons', $icons);
149 }
150
151 return $icons;
152 }
153
154 /**
155 * Obtain ranks
156 */
157 function obtain_ranks()
158 {
159 if (($ranks = $this->driver->get('_ranks')) === false)
160 {
161 $sql = 'SELECT *
162 FROM ' . RANKS_TABLE . '
163 ORDER BY rank_min DESC';
164 $result = $this->db->sql_query($sql);
165
166 $ranks = array();
167 while ($row = $this->db->sql_fetchrow($result))
168 {
169 if ($row['rank_special'])
170 {
171 unset($row['rank_min']);
172 $ranks['special'][$row['rank_id']] = $row;
173 }
174 else
175 {
176 $ranks['normal'][$row['rank_id']] = $row;
177 }
178 }
179 $this->db->sql_freeresult($result);
180
181 $this->driver->put('_ranks', $ranks);
182 }
183
184 return $ranks;
185 }
186
187 /**
188 * Obtain allowed extensions
189 *
190 * @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.
191 *
192 * @return array allowed extensions array.
193 */
194 function obtain_attach_extensions($forum_id)
195 {
196 if (($extensions = $this->driver->get('_extensions')) === false)
197 {
198 $extensions = array(
199 '_allowed_post' => array(),
200 '_allowed_pm' => array(),
201 );
202
203 // The rule is to only allow those extensions defined. ;)
204 $sql = 'SELECT e.extension, g.*
205 FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
206 WHERE e.group_id = g.group_id
207 AND (g.allow_group = 1 OR g.allow_in_pm = 1)';
208 $result = $this->db->sql_query($sql);
209
210 while ($row = $this->db->sql_fetchrow($result))
211 {
212 $extension = strtolower(trim($row['extension']));
213
214 $extensions[$extension] = array(
215 'display_cat' => (int) $row['cat_id'],
216 'download_mode' => (int) $row['download_mode'],
217 'upload_icon' => trim($row['upload_icon']),
218 'max_filesize' => (int) $row['max_filesize'],
219 'allow_group' => $row['allow_group'],
220 'allow_in_pm' => $row['allow_in_pm'],
221 'group_name' => $row['group_name'],
222 );
223
224 $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
225
226 // Store allowed extensions forum wise
227 if ($row['allow_group'])
228 {
229 $extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums;
230 }
231
232 if ($row['allow_in_pm'])
233 {
234 $extensions['_allowed_pm'][$extension] = 0;
235 }
236 }
237 $this->db->sql_freeresult($result);
238
239 $this->driver->put('_extensions', $extensions);
240 }
241
242 // Forum post
243 if ($forum_id === false)
244 {
245 // We are checking for private messages, therefore we only need to get the pm extensions...
246 $return = array('_allowed_' => array());
247
248 foreach ($extensions['_allowed_pm'] as $extension => $check)
249 {
250 $return['_allowed_'][$extension] = 0;
251 $return[$extension] = $extensions[$extension];
252 }
253
254 $extensions = $return;
255 }
256 else if ($forum_id === true)
257 {
258 return $extensions;
259 }
260 else
261 {
262 $forum_id = (int) $forum_id;
263 $return = array('_allowed_' => array());
264
265 foreach ($extensions['_allowed_post'] as $extension => $check)
266 {
267 // Check for allowed forums
268 if (is_array($check))
269 {
270 $allowed = (!in_array($forum_id, $check)) ? false : true;
271 }
272 else
273 {
274 $allowed = true;
275 }
276
277 if ($allowed)
278 {
279 $return['_allowed_'][$extension] = 0;
280 $return[$extension] = $extensions[$extension];
281 }
282 }
283
284 $extensions = $return;
285 }
286
287 if (!isset($extensions['_allowed_']))
288 {
289 $extensions['_allowed_'] = array();
290 }
291
292 return $extensions;
293 }
294
295 /**
296 * Obtain active bots
297 */
298 function obtain_bots()
299 {
300 if (($bots = $this->driver->get('_bots')) === false)
301 {
302 switch ($this->db->get_sql_layer())
303 {
304 case 'mssql':
305 case 'mssql_odbc':
306 case 'mssqlnative':
307 $sql = 'SELECT user_id, bot_agent, bot_ip
308 FROM ' . BOTS_TABLE . '
309 WHERE bot_active = 1
310 ORDER BY LEN(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 = $this->db->sql_query($sql);
322
323 $bots = array();
324 while ($row = $this->db->sql_fetchrow($result))
325 {
326 $bots[] = $row;
327 }
328 $this->db->sql_freeresult($result);
329
330 $this->driver->put('_bots', $bots);
331 }
332
333 return $bots;
334 }
335
336 /**
337 * Obtain cfg file data
338 */
339 function obtain_cfg_items($style)
340 {
341 $parsed_array = $this->driver->get('_cfg_' . $style['style_path']);
342
343 if ($parsed_array === false)
344 {
345 $parsed_array = array();
346 }
347
348 $filename = $this->phpbb_root_path . 'styles/' . $style['style_path'] . '/style.cfg';
349
350 if (!file_exists($filename))
351 {
352 return $parsed_array;
353 }
354
355 if (!isset($parsed_array['filetime']) || (($this->config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
356 {
357 // Re-parse cfg file
358 $parsed_array = parse_cfg_file($filename);
359 $parsed_array['filetime'] = @filemtime($filename);
360
361 $this->driver->put('_cfg_' . $style['style_path'], $parsed_array);
362 }
363
364 return $parsed_array;
365 }
366
367 /**
368 * Obtain disallowed usernames
369 */
370 function obtain_disallowed_usernames()
371 {
372 if (($usernames = $this->driver->get('_disallowed_usernames')) === false)
373 {
374 $sql = 'SELECT disallow_username
375 FROM ' . DISALLOW_TABLE;
376 $result = $this->db->sql_query($sql);
377
378 $usernames = array();
379 while ($row = $this->db->sql_fetchrow($result))
380 {
381 $usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#'));
382 }
383 $this->db->sql_freeresult($result);
384
385 $this->driver->put('_disallowed_usernames', $usernames);
386 }
387
388 return $usernames;
389 }
390 }
391