[ Index ] |
PHP Cross Reference of phpBB 3.0 Beta 3 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * @package acm 5 * @version $Id: cache.php,v 1.5 2006/11/12 15:35:43 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 */ 13 if (!defined('IN_PHPBB')) 14 { 15 exit; 16 } 17 18 /** 19 * Class for grabbing/handling cached entries, extends acm_file or acm_db depending on the setup 20 * @package acm 21 */ 22 class cache extends acm 23 { 24 /** 25 * Get config values 26 */ 27 function obtain_config() 28 { 29 global $db; 30 31 if (($config = $this->get('config')) !== false) 32 { 33 $sql = 'SELECT config_name, config_value 34 FROM ' . CONFIG_TABLE . ' 35 WHERE is_dynamic = 1'; 36 $result = $db->sql_query($sql); 37 38 while ($row = $db->sql_fetchrow($result)) 39 { 40 $config[$row['config_name']] = $row['config_value']; 41 } 42 $db->sql_freeresult($result); 43 } 44 else 45 { 46 $config = $cached_config = array(); 47 48 $sql = 'SELECT config_name, config_value, is_dynamic 49 FROM ' . CONFIG_TABLE; 50 $result = $db->sql_query($sql); 51 52 while ($row = $db->sql_fetchrow($result)) 53 { 54 if (!$row['is_dynamic']) 55 { 56 $cached_config[$row['config_name']] = $row['config_value']; 57 } 58 59 $config[$row['config_name']] = $row['config_value']; 60 } 61 $db->sql_freeresult($result); 62 63 $this->put('config', $cached_config); 64 } 65 66 return $config; 67 } 68 69 /** 70 * Obtain list of naughty words and build preg style replacement arrays for use by the 71 * calling script 72 */ 73 function obtain_word_list() 74 { 75 global $config, $user, $db; 76 77 if (!$user->optionget('viewcensors') && $config['allow_nocensors']) 78 { 79 return array(); 80 } 81 82 if (($censors = $this->get('word_censors')) === false) 83 { 84 $sql = 'SELECT word, replacement 85 FROM ' . WORDS_TABLE; 86 $result = $db->sql_query($sql); 87 88 $censors = array(); 89 while ($row = $db->sql_fetchrow($result)) 90 { 91 $censors['match'][] = '#(?<!\w)(' . str_replace('\*', '\w*?', preg_quote($row['word'], '#')) . ')(?!\w)#i'; 92 $censors['replace'][] = $row['replacement']; 93 } 94 $db->sql_freeresult($result); 95 96 $this->put('word_censors', $censors); 97 } 98 99 return $censors; 100 } 101 102 /** 103 * Obtain currently listed icons 104 */ 105 function obtain_icons() 106 { 107 if (($icons = $this->get('icons')) === false) 108 { 109 global $db; 110 111 // Topic icons 112 $sql = 'SELECT * 113 FROM ' . ICONS_TABLE . ' 114 ORDER BY icons_order'; 115 $result = $db->sql_query($sql); 116 117 $icons = array(); 118 while ($row = $db->sql_fetchrow($result)) 119 { 120 $icons[$row['icons_id']]['img'] = $row['icons_url']; 121 $icons[$row['icons_id']]['width'] = (int) $row['icons_width']; 122 $icons[$row['icons_id']]['height'] = (int) $row['icons_height']; 123 $icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting']; 124 } 125 $db->sql_freeresult($result); 126 127 $this->put('icons', $icons); 128 } 129 130 return $icons; 131 } 132 133 /** 134 * Obtain ranks 135 */ 136 function obtain_ranks() 137 { 138 if (($ranks = $this->get('ranks')) === false) 139 { 140 global $db; 141 142 $sql = 'SELECT * 143 FROM ' . RANKS_TABLE . ' 144 ORDER BY rank_min DESC'; 145 $result = $db->sql_query($sql); 146 147 $ranks = array(); 148 while ($row = $db->sql_fetchrow($result)) 149 { 150 if ($row['rank_special']) 151 { 152 $ranks['special'][$row['rank_id']] = array( 153 'rank_title' => $row['rank_title'], 154 'rank_image' => $row['rank_image'] 155 ); 156 } 157 else 158 { 159 $ranks['normal'][] = array( 160 'rank_title' => $row['rank_title'], 161 'rank_min' => $row['rank_min'], 162 'rank_image' => $row['rank_image'] 163 ); 164 } 165 } 166 $db->sql_freeresult($result); 167 168 $this->put('ranks', $ranks); 169 } 170 171 return $ranks; 172 } 173 174 /** 175 * Obtain allowed extensions 176 */ 177 function obtain_attach_extensions($forum_id = false) 178 { 179 if (($extensions = $this->get('_extensions')) === false) 180 { 181 global $db; 182 183 // The rule is to only allow those extensions defined. ;) 184 $sql = 'SELECT e.extension, g.* 185 FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g 186 WHERE e.group_id = g.group_id 187 AND g.allow_group = 1'; 188 $result = $db->sql_query($sql); 189 190 $extensions = array('_allowed_' => array()); 191 while ($row = $db->sql_fetchrow($result)) 192 { 193 $extension = strtolower(trim($row['extension'])); 194 195 $extensions[$extension] = array( 196 'display_cat' => (int) $row['cat_id'], 197 'download_mode' => (int) $row['download_mode'], 198 'upload_icon' => trim($row['upload_icon']), 199 'max_filesize' => (int) $row['max_filesize'] 200 ); 201 202 $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array(); 203 204 if ($row['allow_in_pm']) 205 { 206 $allowed_forums = array_merge($allowed_forums, array(0)); 207 } 208 209 // Store allowed extensions forum wise 210 $extensions['_allowed_'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums; 211 } 212 $db->sql_freeresult($result); 213 214 $this->put('_extensions', $extensions); 215 } 216 217 if ($forum_id !== false) 218 { 219 $return = array(); 220 221 foreach ($extensions['_allowed_'] as $extension => $check) 222 { 223 $allowed = false; 224 225 if (is_array($check)) 226 { 227 // Check for private messaging AND all forums allowed 228 if (sizeof($check) == 1 && $check[0] == 0) 229 { 230 $allowed = true; 231 } 232 else 233 { 234 $allowed = (!in_array($forum_id, $check)) ? false : true; 235 } 236 } 237 else 238 { 239 $allowed = ($forum_id === 0) ? false : true; 240 } 241 242 if ($allowed) 243 { 244 $return['_allowed_'][$extension] = 0; 245 $return[$extension] = $extensions[$extension]; 246 } 247 } 248 249 $extensions = $return; 250 } 251 252 if (!isset($extensions['_allowed_'])) 253 { 254 $extensions['_allowed_'] = array(); 255 } 256 257 return $extensions; 258 } 259 260 /** 261 * Obtain active bots 262 */ 263 function obtain_bots() 264 { 265 if (($bots = $this->get('bots')) === false) 266 { 267 global $db; 268 269 switch ($db->sql_layer) 270 { 271 case 'mssql': 272 case 'mssql_odbc': 273 $sql = 'SELECT user_id, bot_agent, bot_ip 274 FROM ' . BOTS_TABLE . ' 275 WHERE bot_active = 1 276 ORDER BY LEN(bot_agent) DESC'; 277 break; 278 279 case 'firebird': 280 $sql = 'SELECT user_id, bot_agent, bot_ip 281 FROM ' . BOTS_TABLE . ' 282 WHERE bot_active = 1 283 ORDER BY CHAR_LENGTH(bot_agent) DESC'; 284 break; 285 286 // LENGTH supported by MySQL, IBM DB2 and Oracle for sure... 287 default: 288 $sql = 'SELECT user_id, bot_agent, bot_ip 289 FROM ' . BOTS_TABLE . ' 290 WHERE bot_active = 1 291 ORDER BY LENGTH(bot_agent) DESC'; 292 break; 293 } 294 $result = $db->sql_query($sql); 295 296 $bots = array(); 297 while ($row = $db->sql_fetchrow($result)) 298 { 299 $bots[] = $row; 300 } 301 $db->sql_freeresult($result); 302 303 $this->put('bots', $bots); 304 } 305 306 return $bots; 307 } 308 309 /** 310 * Obtain cfg file data 311 */ 312 function obtain_cfg_items($theme) 313 { 314 global $config, $phpbb_root_path; 315 316 $parsed_items = array( 317 'theme' => array(), 318 'template' => array(), 319 'imageset' => array() 320 ); 321 322 foreach ($parsed_items as $key => $parsed_array) 323 { 324 $parsed_array = $this->get('_cfg_' . $key . '_' . $theme[$key . '_path']); 325 326 if ($parsed_array === false) 327 { 328 $parsed_array = array(); 329 } 330 331 $reparse = false; 332 $filename = $phpbb_root_path . 'styles/' . $theme[$key . '_path'] . '/' . $key . '/' . $key . '.cfg'; 333 334 if (!file_exists($filename)) 335 { 336 continue; 337 } 338 339 if (!isset($parsed_array['filetime']) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']))) 340 { 341 $reparse = true; 342 } 343 344 // Re-parse cfg file 345 if ($reparse) 346 { 347 $parsed_array = parse_cfg_file($filename); 348 $parsed_array['filetime'] = @filemtime($filename); 349 350 $this->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array); 351 } 352 $parsed_items[$key] = $parsed_array; 353 } 354 355 return $parsed_items; 356 } 357 358 /** 359 * Obtain disallowed usernames 360 */ 361 function obtain_disallowed_usernames() 362 { 363 if (($usernames = $this->get('_disallowed_usernames')) === false) 364 { 365 global $db; 366 367 $sql = 'SELECT disallow_username 368 FROM ' . DISALLOW_TABLE; 369 $result = $db->sql_query($sql); 370 371 $usernames = array(); 372 while ($row = $db->sql_fetchrow($result)) 373 { 374 $usernames[] = utf8_clean_string(str_replace('%', '.*?', preg_quote($row['disallow_username'], '$#'))); 375 } 376 $db->sql_freeresult($result); 377 378 $this->put('_disallowed_usernames', $usernames); 379 } 380 381 return $usernames; 382 } 383 } 384 385 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 22 00:35:05 2006 | Cross-referenced by PHPXref 0.6 |