[ Index ] |
PHP Cross Reference of phpBB-3.2.11-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 /** 22 * Cache driver. 23 * 24 * @var \phpbb\cache\driver\driver_interface 25 */ 26 protected $driver; 27 28 /** 29 * The config. 30 * 31 * @var \phpbb\config\config 32 */ 33 protected $config; 34 35 /** 36 * Database connection. 37 * 38 * @var \phpbb\db\driver\driver_interface 39 */ 40 protected $db; 41 42 /** 43 * Root path. 44 * 45 * @var string 46 */ 47 protected $phpbb_root_path; 48 49 /** 50 * PHP file extension. 51 * 52 * @var string 53 */ 54 protected $php_ext; 55 56 /** 57 * Creates a cache service around a cache driver 58 * 59 * @param \phpbb\cache\driver\driver_interface $driver The cache driver 60 * @param \phpbb\config\config $config The config 61 * @param \phpbb\db\driver\driver_interface $db Database connection 62 * @param string $phpbb_root_path Root path 63 * @param string $php_ext PHP file extension 64 */ 65 public function __construct(\phpbb\cache\driver\driver_interface $driver, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext) 66 { 67 $this->set_driver($driver); 68 $this->config = $config; 69 $this->db = $db; 70 $this->phpbb_root_path = $phpbb_root_path; 71 $this->php_ext = $php_ext; 72 } 73 74 /** 75 * Returns the cache driver used by this cache service. 76 * 77 * @return \phpbb\cache\driver\driver_interface The cache driver 78 */ 79 public function get_driver() 80 { 81 return $this->driver; 82 } 83 84 /** 85 * Replaces the cache driver used by this cache service. 86 * 87 * @param \phpbb\cache\driver\driver_interface $driver The cache driver 88 */ 89 public function set_driver(\phpbb\cache\driver\driver_interface $driver) 90 { 91 $this->driver = $driver; 92 } 93 94 public function __call($method, $arguments) 95 { 96 return call_user_func_array(array($this->driver, $method), $arguments); 97 } 98 99 /** 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']]['alt'] = ($row['icons_alt']) ? $row['icons_alt'] : ''; 145 $icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting']; 146 } 147 $this->db->sql_freeresult($result); 148 149 $this->driver->put('_icons', $icons); 150 } 151 152 return $icons; 153 } 154 155 /** 156 * Obtain ranks 157 */ 158 function obtain_ranks() 159 { 160 if (($ranks = $this->driver->get('_ranks')) === false) 161 { 162 $sql = 'SELECT * 163 FROM ' . RANKS_TABLE . ' 164 ORDER BY rank_min DESC'; 165 $result = $this->db->sql_query($sql); 166 167 $ranks = array(); 168 while ($row = $this->db->sql_fetchrow($result)) 169 { 170 if ($row['rank_special']) 171 { 172 unset($row['rank_min']); 173 $ranks['special'][$row['rank_id']] = $row; 174 } 175 else 176 { 177 $ranks['normal'][$row['rank_id']] = $row; 178 } 179 } 180 $this->db->sql_freeresult($result); 181 182 $this->driver->put('_ranks', $ranks); 183 } 184 185 return $ranks; 186 } 187 188 /** 189 * Obtain allowed extensions 190 * 191 * @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. 192 * 193 * @return array allowed extensions array. 194 */ 195 function obtain_attach_extensions($forum_id) 196 { 197 if (($extensions = $this->driver->get('_extensions')) === false) 198 { 199 $extensions = array( 200 '_allowed_post' => array(), 201 '_allowed_pm' => array(), 202 ); 203 204 // The rule is to only allow those extensions defined. ;) 205 $sql = 'SELECT e.extension, g.* 206 FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g 207 WHERE e.group_id = g.group_id 208 AND (g.allow_group = 1 OR g.allow_in_pm = 1)'; 209 $result = $this->db->sql_query($sql); 210 211 while ($row = $this->db->sql_fetchrow($result)) 212 { 213 $extension = strtolower(trim($row['extension'])); 214 215 $extensions[$extension] = array( 216 'display_cat' => (int) $row['cat_id'], 217 'download_mode' => (int) $row['download_mode'], 218 'upload_icon' => trim($row['upload_icon']), 219 'max_filesize' => (int) $row['max_filesize'], 220 'allow_group' => $row['allow_group'], 221 'allow_in_pm' => $row['allow_in_pm'], 222 'group_name' => $row['group_name'], 223 ); 224 225 $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array(); 226 227 // Store allowed extensions forum wise 228 if ($row['allow_group']) 229 { 230 $extensions['_allowed_post'][$extension] = (!count($allowed_forums)) ? 0 : $allowed_forums; 231 } 232 233 if ($row['allow_in_pm']) 234 { 235 $extensions['_allowed_pm'][$extension] = 0; 236 } 237 } 238 $this->db->sql_freeresult($result); 239 240 $this->driver->put('_extensions', $extensions); 241 } 242 243 // Forum post 244 if ($forum_id === false) 245 { 246 // We are checking for private messages, therefore we only need to get the pm extensions... 247 $return = array('_allowed_' => array()); 248 249 foreach ($extensions['_allowed_pm'] as $extension => $check) 250 { 251 $return['_allowed_'][$extension] = 0; 252 $return[$extension] = $extensions[$extension]; 253 } 254 255 $extensions = $return; 256 } 257 else if ($forum_id === true) 258 { 259 return $extensions; 260 } 261 else 262 { 263 $forum_id = (int) $forum_id; 264 $return = array('_allowed_' => array()); 265 266 foreach ($extensions['_allowed_post'] as $extension => $check) 267 { 268 // Check for allowed forums 269 if (is_array($check)) 270 { 271 $allowed = (!in_array($forum_id, $check)) ? false : true; 272 } 273 else 274 { 275 $allowed = true; 276 } 277 278 if ($allowed) 279 { 280 $return['_allowed_'][$extension] = 0; 281 $return[$extension] = $extensions[$extension]; 282 } 283 } 284 285 $extensions = $return; 286 } 287 288 if (!isset($extensions['_allowed_'])) 289 { 290 $extensions['_allowed_'] = array(); 291 } 292 293 return $extensions; 294 } 295 296 /** 297 * Obtain active bots 298 */ 299 function obtain_bots() 300 { 301 if (($bots = $this->driver->get('_bots')) === false) 302 { 303 switch ($this->db->get_sql_layer()) 304 { 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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |