[ Index ] |
PHP Cross Reference of phpBB-3.1.12-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']]['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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |