[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\cache; 15 16 /** 17 * Class for grabbing/handling cached entries 18 */ 19 class service 20 { 21 /** @var string Name of event used for cache purging */ 22 private const PURGE_DEFERRED_ON_EVENT = 'core.garbage_collection'; 23 24 /** @var bool Flag whether cache purge has been deferred */ 25 private $cache_purge_deferred = false; 26 27 /** 28 * Cache driver. 29 * 30 * @var \phpbb\cache\driver\driver_interface 31 */ 32 protected $driver; 33 34 /** 35 * The config. 36 * 37 * @var \phpbb\config\config 38 */ 39 protected $config; 40 41 /** 42 * Database connection. 43 * 44 * @var \phpbb\db\driver\driver_interface 45 */ 46 protected $db; 47 48 /** @var \phpbb\event\dispatcher phpBB Event dispatcher */ 49 protected $dispatcher; 50 51 /** 52 * Root path. 53 * 54 * @var string 55 */ 56 protected $phpbb_root_path; 57 58 /** 59 * PHP file extension. 60 * 61 * @var string 62 */ 63 protected $php_ext; 64 65 /** 66 * Creates a cache service around a cache driver 67 * 68 * @param \phpbb\cache\driver\driver_interface $driver The cache driver 69 * @param \phpbb\config\config $config The config 70 * @param \phpbb\db\driver\driver_interface $db Database connection 71 * @param \phpbb\event\dispatcher $dispatcher Event dispatcher 72 * @param string $phpbb_root_path Root path 73 * @param string $php_ext PHP file extension 74 */ 75 public function __construct(\phpbb\cache\driver\driver_interface $driver, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, $phpbb_root_path, $php_ext) 76 { 77 $this->set_driver($driver); 78 $this->config = $config; 79 $this->db = $db; 80 $this->dispatcher = $dispatcher; 81 $this->phpbb_root_path = $phpbb_root_path; 82 $this->php_ext = $php_ext; 83 } 84 85 /** 86 * Returns the cache driver used by this cache service. 87 * 88 * @return \phpbb\cache\driver\driver_interface The cache driver 89 */ 90 public function get_driver() 91 { 92 return $this->driver; 93 } 94 95 /** 96 * Deferred purge of the cache. 97 * 98 * A deferred purge will be executed after rendering a page. 99 * It is recommended to be used in cases where an instant purge of the cache 100 * is not required, i.e. when the goal of a cache purge is to start from a 101 * clear cache at the next page load. 102 * 103 * @return void 104 */ 105 public function deferred_purge(): void 106 { 107 if (!$this->cache_purge_deferred) 108 { 109 $this->dispatcher->addListener(self::PURGE_DEFERRED_ON_EVENT, [$this, 'purge']); 110 $this->cache_purge_deferred = true; 111 } 112 } 113 114 /** 115 * Replaces the cache driver used by this cache service. 116 * 117 * @param \phpbb\cache\driver\driver_interface $driver The cache driver 118 */ 119 public function set_driver(\phpbb\cache\driver\driver_interface $driver) 120 { 121 $this->driver = $driver; 122 } 123 124 public function __call($method, $arguments) 125 { 126 return call_user_func_array(array($this->driver, $method), $arguments); 127 } 128 129 /** 130 * Obtain list of naughty words and build preg style replacement arrays for use by the 131 * calling script 132 */ 133 function obtain_word_list() 134 { 135 if (($censors = $this->driver->get('_word_censors')) === false) 136 { 137 $sql = 'SELECT word, replacement 138 FROM ' . WORDS_TABLE; 139 $result = $this->db->sql_query($sql); 140 141 $censors = array(); 142 while ($row = $this->db->sql_fetchrow($result)) 143 { 144 $censors['match'][] = get_censor_preg_expression($row['word']); 145 $censors['replace'][] = $row['replacement']; 146 } 147 $this->db->sql_freeresult($result); 148 149 $this->driver->put('_word_censors', $censors); 150 } 151 152 return $censors; 153 } 154 155 /** 156 * Obtain currently listed icons 157 */ 158 function obtain_icons() 159 { 160 if (($icons = $this->driver->get('_icons')) === false) 161 { 162 // Topic icons 163 $sql = 'SELECT * 164 FROM ' . ICONS_TABLE . ' 165 ORDER BY icons_order'; 166 $result = $this->db->sql_query($sql); 167 168 $icons = array(); 169 while ($row = $this->db->sql_fetchrow($result)) 170 { 171 $icons[$row['icons_id']]['img'] = $row['icons_url']; 172 $icons[$row['icons_id']]['width'] = (int) $row['icons_width']; 173 $icons[$row['icons_id']]['height'] = (int) $row['icons_height']; 174 $icons[$row['icons_id']]['alt'] = ($row['icons_alt']) ? $row['icons_alt'] : ''; 175 $icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting']; 176 } 177 $this->db->sql_freeresult($result); 178 179 $this->driver->put('_icons', $icons); 180 } 181 182 return $icons; 183 } 184 185 /** 186 * Obtain ranks 187 */ 188 function obtain_ranks() 189 { 190 if (($ranks = $this->driver->get('_ranks')) === false) 191 { 192 $sql = 'SELECT * 193 FROM ' . RANKS_TABLE . ' 194 ORDER BY rank_min DESC'; 195 $result = $this->db->sql_query($sql); 196 197 $ranks = array(); 198 while ($row = $this->db->sql_fetchrow($result)) 199 { 200 if ($row['rank_special']) 201 { 202 unset($row['rank_min']); 203 $ranks['special'][$row['rank_id']] = $row; 204 } 205 else 206 { 207 $ranks['normal'][$row['rank_id']] = $row; 208 } 209 } 210 $this->db->sql_freeresult($result); 211 212 $this->driver->put('_ranks', $ranks); 213 } 214 215 return $ranks; 216 } 217 218 /** 219 * Obtain allowed extensions 220 * 221 * @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. 222 * 223 * @return array allowed extensions array. 224 */ 225 function obtain_attach_extensions($forum_id) 226 { 227 if (($extensions = $this->driver->get('_extensions')) === false) 228 { 229 $extensions = array( 230 '_allowed_post' => array(), 231 '_allowed_pm' => array(), 232 ); 233 234 // The rule is to only allow those extensions defined. ;) 235 $sql = 'SELECT e.extension, g.* 236 FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g 237 WHERE e.group_id = g.group_id 238 AND (g.allow_group = 1 OR g.allow_in_pm = 1)'; 239 $result = $this->db->sql_query($sql); 240 241 while ($row = $this->db->sql_fetchrow($result)) 242 { 243 $extension = strtolower(trim($row['extension'])); 244 245 $extensions[$extension] = array( 246 'display_cat' => (int) $row['cat_id'], 247 'download_mode' => (int) $row['download_mode'], 248 'upload_icon' => trim($row['upload_icon']), 249 'max_filesize' => (int) $row['max_filesize'], 250 'allow_group' => $row['allow_group'], 251 'allow_in_pm' => $row['allow_in_pm'], 252 'group_name' => $row['group_name'], 253 ); 254 255 $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array(); 256 257 // Store allowed extensions forum wise 258 if ($row['allow_group']) 259 { 260 $extensions['_allowed_post'][$extension] = (!count($allowed_forums)) ? 0 : $allowed_forums; 261 } 262 263 if ($row['allow_in_pm']) 264 { 265 $extensions['_allowed_pm'][$extension] = 0; 266 } 267 } 268 $this->db->sql_freeresult($result); 269 270 $this->driver->put('_extensions', $extensions); 271 } 272 273 // Forum post 274 if ($forum_id === false) 275 { 276 // We are checking for private messages, therefore we only need to get the pm extensions... 277 $return = array('_allowed_' => array()); 278 279 foreach ($extensions['_allowed_pm'] as $extension => $check) 280 { 281 $return['_allowed_'][$extension] = 0; 282 $return[$extension] = $extensions[$extension]; 283 } 284 285 $extensions = $return; 286 } 287 else if ($forum_id === true) 288 { 289 return $extensions; 290 } 291 else 292 { 293 $forum_id = (int) $forum_id; 294 $return = array('_allowed_' => array()); 295 296 foreach ($extensions['_allowed_post'] as $extension => $check) 297 { 298 // Check for allowed forums 299 if (is_array($check)) 300 { 301 $allowed = (!in_array($forum_id, $check)) ? false : true; 302 } 303 else 304 { 305 $allowed = true; 306 } 307 308 if ($allowed) 309 { 310 $return['_allowed_'][$extension] = 0; 311 $return[$extension] = $extensions[$extension]; 312 } 313 } 314 315 $extensions = $return; 316 } 317 318 if (!isset($extensions['_allowed_'])) 319 { 320 $extensions['_allowed_'] = array(); 321 } 322 323 return $extensions; 324 } 325 326 /** 327 * Obtain active bots 328 */ 329 function obtain_bots() 330 { 331 if (($bots = $this->driver->get('_bots')) === false) 332 { 333 switch ($this->db->get_sql_layer()) 334 { 335 case 'mssql_odbc': 336 case 'mssqlnative': 337 $sql = 'SELECT user_id, bot_agent, bot_ip 338 FROM ' . BOTS_TABLE . ' 339 WHERE bot_active = 1 340 ORDER BY LEN(bot_agent) DESC'; 341 break; 342 343 // LENGTH supported by MySQL, IBM DB2 and Oracle for sure... 344 default: 345 $sql = 'SELECT user_id, bot_agent, bot_ip 346 FROM ' . BOTS_TABLE . ' 347 WHERE bot_active = 1 348 ORDER BY LENGTH(bot_agent) DESC'; 349 break; 350 } 351 $result = $this->db->sql_query($sql); 352 353 $bots = array(); 354 while ($row = $this->db->sql_fetchrow($result)) 355 { 356 $bots[] = $row; 357 } 358 $this->db->sql_freeresult($result); 359 360 $this->driver->put('_bots', $bots); 361 } 362 363 return $bots; 364 } 365 366 /** 367 * Obtain cfg file data 368 */ 369 function obtain_cfg_items($style) 370 { 371 $parsed_array = $this->driver->get('_cfg_' . $style['style_path']); 372 373 if ($parsed_array === false) 374 { 375 $parsed_array = array(); 376 } 377 378 $filename = $this->phpbb_root_path . 'styles/' . $style['style_path'] . '/style.cfg'; 379 380 if (!file_exists($filename)) 381 { 382 return $parsed_array; 383 } 384 385 if (!isset($parsed_array['filetime']) || (($this->config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']))) 386 { 387 // Re-parse cfg file 388 $parsed_array = parse_cfg_file($filename); 389 $parsed_array['filetime'] = @filemtime($filename); 390 391 $this->driver->put('_cfg_' . $style['style_path'], $parsed_array); 392 } 393 394 return $parsed_array; 395 } 396 397 /** 398 * Obtain disallowed usernames 399 */ 400 function obtain_disallowed_usernames() 401 { 402 if (($usernames = $this->driver->get('_disallowed_usernames')) === false) 403 { 404 $sql = 'SELECT disallow_username 405 FROM ' . DISALLOW_TABLE; 406 $result = $this->db->sql_query($sql); 407 408 $usernames = array(); 409 while ($row = $this->db->sql_fetchrow($result)) 410 { 411 $usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#')); 412 } 413 $this->db->sql_freeresult($result); 414 415 $this->driver->put('_disallowed_usernames', $usernames); 416 } 417 418 return $usernames; 419 } 420 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |