[ Index ] |
PHP Cross Reference of phpBB 2.0.21 |
[Summary view] [Print] [Text view]
1 <?php 2 /*************************************************************************** 3 * functions.php 4 * ------------------- 5 * begin : Saturday, Feb 13, 2001 6 * copyright : (C) 2001 The phpBB Group 7 * email : support@phpbb.com 8 * 9 * $Id: functions.php,v 1.133.2.46 2006/05/16 19:14:35 grahamje Exp $ 10 * 11 * 12 ***************************************************************************/ 13 14 /*************************************************************************** 15 * 16 * This program is free software; you can redistribute it and/or modify 17 * it under the terms of the GNU General Public License as published by 18 * the Free Software Foundation; either version 2 of the License, or 19 * (at your option) any later version. 20 * 21 * 22 ***************************************************************************/ 23 24 /*************************************************************************** 25 * 26 * Deutsche Version (c) 2006 phpBB.de 27 * 28 * Aenderungen an create_date() und message_die() 29 * 30 * create_date: Sommerzeitfix (DST fix) 31 * message_die: Deutsch als Standardsprache (Messages in German) 32 * 33 ***************************************************************************/ 34 35 function get_db_stat($mode) 36 { 37 global $db; 38 39 switch( $mode ) 40 { 41 case 'usercount': 42 $sql = "SELECT COUNT(user_id) AS total 43 FROM " . USERS_TABLE . " 44 WHERE user_id <> " . ANONYMOUS; 45 break; 46 47 case 'newestuser': 48 $sql = "SELECT user_id, username 49 FROM " . USERS_TABLE . " 50 WHERE user_id <> " . ANONYMOUS . " 51 ORDER BY user_id DESC 52 LIMIT 1"; 53 break; 54 55 case 'postcount': 56 case 'topiccount': 57 $sql = "SELECT SUM(forum_topics) AS topic_total, SUM(forum_posts) AS post_total 58 FROM " . FORUMS_TABLE; 59 break; 60 } 61 62 if ( !($result = $db->sql_query($sql)) ) 63 { 64 return false; 65 } 66 67 $row = $db->sql_fetchrow($result); 68 69 switch ( $mode ) 70 { 71 case 'usercount': 72 return $row['total']; 73 break; 74 case 'newestuser': 75 return $row; 76 break; 77 case 'postcount': 78 return $row['post_total']; 79 break; 80 case 'topiccount': 81 return $row['topic_total']; 82 break; 83 } 84 85 return false; 86 } 87 88 // added at phpBB 2.0.11 to properly format the username 89 function phpbb_clean_username($username) 90 { 91 $username = substr(htmlspecialchars(str_replace("\'", "'", trim($username))), 0, 25); 92 $username = phpbb_rtrim($username, "\\"); 93 $username = str_replace("'", "\'", $username); 94 95 return $username; 96 } 97 98 /** 99 * This function is a wrapper for ltrim, as charlist is only supported in php >= 4.1.0 100 * Added in phpBB 2.0.18 101 */ 102 function phpbb_ltrim($str, $charlist = false) 103 { 104 if ($charlist === false) 105 { 106 return ltrim($str); 107 } 108 109 $php_version = explode('.', PHP_VERSION); 110 111 // php version < 4.1.0 112 if ((int) $php_version[0] < 4 || ((int) $php_version[0] == 4 && (int) $php_version[1] < 1)) 113 { 114 while ($str{0} == $charlist) 115 { 116 $str = substr($str, 1); 117 } 118 } 119 else 120 { 121 $str = ltrim($str, $charlist); 122 } 123 124 return $str; 125 } 126 127 // added at phpBB 2.0.12 to fix a bug in PHP 4.3.10 (only supporting charlist in php >= 4.1.0) 128 function phpbb_rtrim($str, $charlist = false) 129 { 130 if ($charlist === false) 131 { 132 return rtrim($str); 133 } 134 135 $php_version = explode('.', PHP_VERSION); 136 137 // php version < 4.1.0 138 if ((int) $php_version[0] < 4 || ((int) $php_version[0] == 4 && (int) $php_version[1] < 1)) 139 { 140 while ($str{strlen($str)-1} == $charlist) 141 { 142 $str = substr($str, 0, strlen($str)-1); 143 } 144 } 145 else 146 { 147 $str = rtrim($str, $charlist); 148 } 149 150 return $str; 151 } 152 153 /** 154 * Our own generator of random values 155 * This uses a constantly changing value as the base for generating the values 156 * The board wide setting is updated once per page if this code is called 157 * With thanks to Anthrax101 for the inspiration on this one 158 * Added in phpBB 2.0.20 159 */ 160 function dss_rand() 161 { 162 global $db, $board_config, $dss_seeded; 163 164 $val = $board_config['rand_seed'] . microtime(); 165 $val = md5($val); 166 $board_config['rand_seed'] = md5($board_config['rand_seed'] . $val . 'a'); 167 168 if($dss_seeded !== true) 169 { 170 $sql = "UPDATE " . CONFIG_TABLE . " SET 171 config_value = '" . $board_config['rand_seed'] . "' 172 WHERE config_name = 'rand_seed'"; 173 174 if( !$db->sql_query($sql) ) 175 { 176 message_die(GENERAL_ERROR, "Unable to reseed PRNG", "", __LINE__, __FILE__, $sql); 177 } 178 179 $dss_seeded = true; 180 } 181 182 return substr($val, 4, 16); 183 } 184 // 185 // Get Userdata, $user can be username or user_id. If force_str is true, the username will be forced. 186 // 187 function get_userdata($user, $force_str = false) 188 { 189 global $db; 190 191 if (!is_numeric($user) || $force_str) 192 { 193 $user = phpbb_clean_username($user); 194 } 195 else 196 { 197 $user = intval($user); 198 } 199 200 $sql = "SELECT * 201 FROM " . USERS_TABLE . " 202 WHERE "; 203 $sql .= ( ( is_integer($user) ) ? "user_id = $user" : "username = '" . str_replace("\'", "''", $user) . "'" ) . " AND user_id <> " . ANONYMOUS; 204 if ( !($result = $db->sql_query($sql)) ) 205 { 206 message_die(GENERAL_ERROR, 'Tried obtaining data for a non-existent user', '', __LINE__, __FILE__, $sql); 207 } 208 209 return ( $row = $db->sql_fetchrow($result) ) ? $row : false; 210 } 211 212 function make_jumpbox($action, $match_forum_id = 0) 213 { 214 global $template, $userdata, $lang, $db, $nav_links, $phpEx, $SID; 215 216 // $is_auth = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata); 217 218 $sql = "SELECT c.cat_id, c.cat_title, c.cat_order 219 FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f 220 WHERE f.cat_id = c.cat_id 221 GROUP BY c.cat_id, c.cat_title, c.cat_order 222 ORDER BY c.cat_order"; 223 if ( !($result = $db->sql_query($sql)) ) 224 { 225 message_die(GENERAL_ERROR, "Couldn't obtain category list.", "", __LINE__, __FILE__, $sql); 226 } 227 228 $category_rows = array(); 229 while ( $row = $db->sql_fetchrow($result) ) 230 { 231 $category_rows[] = $row; 232 } 233 234 if ( $total_categories = count($category_rows) ) 235 { 236 $sql = "SELECT * 237 FROM " . FORUMS_TABLE . " 238 ORDER BY cat_id, forum_order"; 239 if ( !($result = $db->sql_query($sql)) ) 240 { 241 message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql); 242 } 243 244 $boxstring = '<select name="' . POST_FORUM_URL . '" onchange="if(this.options[this.selectedIndex].value != -1){ forms[\'jumpbox\'].submit() }"><option value="-1">' . $lang['Select_forum'] . '</option>'; 245 246 $forum_rows = array(); 247 while ( $row = $db->sql_fetchrow($result) ) 248 { 249 $forum_rows[] = $row; 250 } 251 252 if ( $total_forums = count($forum_rows) ) 253 { 254 for($i = 0; $i < $total_categories; $i++) 255 { 256 $boxstring_forums = ''; 257 for($j = 0; $j < $total_forums; $j++) 258 { 259 if ( $forum_rows[$j]['cat_id'] == $category_rows[$i]['cat_id'] && $forum_rows[$j]['auth_view'] <= AUTH_REG ) 260 { 261 262 // if ( $forum_rows[$j]['cat_id'] == $category_rows[$i]['cat_id'] && $is_auth[$forum_rows[$j]['forum_id']]['auth_view'] ) 263 // { 264 $selected = ( $forum_rows[$j]['forum_id'] == $match_forum_id ) ? 'selected="selected"' : ''; 265 $boxstring_forums .= '<option value="' . $forum_rows[$j]['forum_id'] . '"' . $selected . '>' . $forum_rows[$j]['forum_name'] . '</option>'; 266 267 // 268 // Add an array to $nav_links for the Mozilla navigation bar. 269 // 'chapter' and 'forum' can create multiple items, therefore we are using a nested array. 270 // 271 $nav_links['chapter forum'][$forum_rows[$j]['forum_id']] = array ( 272 'url' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=" . $forum_rows[$j]['forum_id']), 273 'title' => $forum_rows[$j]['forum_name'] 274 ); 275 276 } 277 } 278 279 if ( $boxstring_forums != '' ) 280 { 281 $boxstring .= '<option value="-1"> </option>'; 282 $boxstring .= '<option value="-1">' . $category_rows[$i]['cat_title'] . '</option>'; 283 $boxstring .= '<option value="-1">----------------</option>'; 284 $boxstring .= $boxstring_forums; 285 } 286 } 287 } 288 289 $boxstring .= '</select>'; 290 } 291 else 292 { 293 $boxstring .= '<select name="' . POST_FORUM_URL . '" onchange="if(this.options[this.selectedIndex].value != -1){ forms[\'jumpbox\'].submit() }"></select>'; 294 } 295 296 // Let the jumpbox work again in sites having additional session id checks. 297 // if ( !empty($SID) ) 298 // { 299 $boxstring .= '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />'; 300 // } 301 302 $template->set_filenames(array( 303 'jumpbox' => 'jumpbox.tpl') 304 ); 305 $template->assign_vars(array( 306 'L_GO' => $lang['Go'], 307 'L_JUMP_TO' => $lang['Jump_to'], 308 'L_SELECT_FORUM' => $lang['Select_forum'], 309 310 'S_JUMPBOX_SELECT' => $boxstring, 311 'S_JUMPBOX_ACTION' => append_sid($action)) 312 ); 313 $template->assign_var_from_handle('JUMPBOX', 'jumpbox'); 314 315 return; 316 } 317 318 // 319 // Initialise user settings on page load 320 function init_userprefs($userdata) 321 { 322 global $board_config, $theme, $images; 323 global $template, $lang, $phpEx, $phpbb_root_path, $db; 324 global $nav_links; 325 326 if ( $userdata['user_id'] != ANONYMOUS ) 327 { 328 if ( !empty($userdata['user_lang'])) 329 { 330 $default_lang = phpbb_ltrim(basename(phpbb_rtrim($userdata['user_lang'])), "'"); 331 } 332 333 if ( !empty($userdata['user_dateformat']) ) 334 { 335 $board_config['default_dateformat'] = $userdata['user_dateformat']; 336 } 337 338 if ( isset($userdata['user_timezone']) ) 339 { 340 $board_config['board_timezone'] = $userdata['user_timezone']; 341 } 342 } 343 else 344 { 345 $default_lang = phpbb_ltrim(basename(phpbb_rtrim($board_config['default_lang'])), "'"); 346 } 347 348 if ( !file_exists(@phpbb_realpath($phpbb_root_path . 'language/lang_' . $default_lang . '/lang_main.'.$phpEx)) ) 349 { 350 if ( $userdata['user_id'] != ANONYMOUS ) 351 { 352 // For logged in users, try the board default language next 353 $default_lang = phpbb_ltrim(basename(phpbb_rtrim($board_config['default_lang'])), "'"); 354 } 355 else 356 { 357 // For guests it means the default language is not present, try english 358 // This is a long shot since it means serious errors in the setup to reach here, 359 // but english is part of a new install so it's worth us trying 360 $default_lang = 'english'; 361 } 362 363 if ( !file_exists(@phpbb_realpath($phpbb_root_path . 'language/lang_' . $default_lang . '/lang_main.'.$phpEx)) ) 364 { 365 message_die(CRITICAL_ERROR, 'Could not locate valid language pack'); 366 } 367 } 368 369 // If we've had to change the value in any way then let's write it back to the database 370 // before we go any further since it means there is something wrong with it 371 if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_lang'] !== $default_lang ) 372 { 373 $sql = 'UPDATE ' . USERS_TABLE . " 374 SET user_lang = '" . $default_lang . "' 375 WHERE user_lang = '" . $userdata['user_lang'] . "'"; 376 377 if ( !($result = $db->sql_query($sql)) ) 378 { 379 message_die(CRITICAL_ERROR, 'Could not update user language info'); 380 } 381 382 $userdata['user_lang'] = $default_lang; 383 } 384 elseif ( $userdata['user_id'] === ANONYMOUS && $board_config['default_lang'] !== $default_lang ) 385 { 386 $sql = 'UPDATE ' . CONFIG_TABLE . " 387 SET config_value = '" . $default_lang . "' 388 WHERE config_name = 'default_lang'"; 389 390 if ( !($result = $db->sql_query($sql)) ) 391 { 392 message_die(CRITICAL_ERROR, 'Could not update user language info'); 393 } 394 } 395 396 $board_config['default_lang'] = $default_lang; 397 398 include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx); 399 400 if ( defined('IN_ADMIN') ) 401 { 402 if( !file_exists(@phpbb_realpath($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.'.$phpEx)) ) 403 { 404 $board_config['default_lang'] = 'english'; 405 } 406 407 include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx); 408 } 409 410 // 411 // Set up style 412 // 413 if ( !$board_config['override_user_style'] ) 414 { 415 if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 ) 416 { 417 if ( $theme = setup_style($userdata['user_style']) ) 418 { 419 return; 420 } 421 } 422 } 423 424 $theme = setup_style($board_config['default_style']); 425 426 // 427 // Mozilla navigation bar 428 // Default items that should be valid on all pages. 429 // Defined here to correctly assign the Language Variables 430 // and be able to change the variables within code. 431 // 432 $nav_links['top'] = array ( 433 'url' => append_sid($phpbb_root_path . 'index.' . $phpEx), 434 'title' => sprintf($lang['Forum_Index'], $board_config['sitename']) 435 ); 436 $nav_links['search'] = array ( 437 'url' => append_sid($phpbb_root_path . 'search.' . $phpEx), 438 'title' => $lang['Search'] 439 ); 440 $nav_links['help'] = array ( 441 'url' => append_sid($phpbb_root_path . 'faq.' . $phpEx), 442 'title' => $lang['FAQ'] 443 ); 444 $nav_links['author'] = array ( 445 'url' => append_sid($phpbb_root_path . 'memberlist.' . $phpEx), 446 'title' => $lang['Memberlist'] 447 ); 448 449 return; 450 } 451 452 function setup_style($style) 453 { 454 global $db, $board_config, $template, $images, $phpbb_root_path; 455 456 $sql = 'SELECT * 457 FROM ' . THEMES_TABLE . ' 458 WHERE themes_id = ' . (int) $style; 459 if ( !($result = $db->sql_query($sql)) ) 460 { 461 message_die(CRITICAL_ERROR, 'Could not query database for theme info'); 462 } 463 464 if ( !($row = $db->sql_fetchrow($result)) ) 465 { 466 // We are trying to setup a style which does not exist in the database 467 // Try to fallback to the board default (if the user had a custom style) 468 // and then any users using this style to the default if it succeeds 469 if ( $style != $board_config['default_style']) 470 { 471 $sql = 'SELECT * 472 FROM ' . THEMES_TABLE . ' 473 WHERE themes_id = ' . (int) $board_config['default_style']; 474 if ( !($result = $db->sql_query($sql)) ) 475 { 476 message_die(CRITICAL_ERROR, 'Could not query database for theme info'); 477 } 478 479 if ( $row = $db->sql_fetchrow($result) ) 480 { 481 $db->sql_freeresult($result); 482 483 $sql = 'UPDATE ' . USERS_TABLE . ' 484 SET user_style = ' . (int) $board_config['default_style'] . " 485 WHERE user_style = $style"; 486 if ( !($result = $db->sql_query($sql)) ) 487 { 488 message_die(CRITICAL_ERROR, 'Could not update user theme info'); 489 } 490 } 491 else 492 { 493 message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]"); 494 } 495 } 496 else 497 { 498 message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]"); 499 } 500 } 501 502 $template_path = 'templates/' ; 503 $template_name = $row['template_name'] ; 504 505 $template = new Template($phpbb_root_path . $template_path . $template_name); 506 507 if ( $template ) 508 { 509 $current_template_path = $template_path . $template_name; 510 @include($phpbb_root_path . $template_path . $template_name . '/' . $template_name . '.cfg'); 511 512 if ( !defined('TEMPLATE_CONFIG') ) 513 { 514 message_die(CRITICAL_ERROR, "Could not open $template_name template config file", '', __LINE__, __FILE__); 515 } 516 517 $img_lang = ( file_exists(@phpbb_realpath($phpbb_root_path . $current_template_path . '/images/lang_' . $board_config['default_lang'])) ) ? $board_config['default_lang'] : 'english'; 518 519 while( list($key, $value) = @each($images) ) 520 { 521 if ( !is_array($value) ) 522 { 523 $images[$key] = str_replace('{LANG}', 'lang_' . $img_lang, $value); 524 } 525 } 526 } 527 528 return $row; 529 } 530 531 function encode_ip($dotquad_ip) 532 { 533 $ip_sep = explode('.', $dotquad_ip); 534 return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]); 535 } 536 537 function decode_ip($int_ip) 538 { 539 $hexipbang = explode('.', chunk_split($int_ip, 2, '.')); 540 return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]); 541 } 542 543 // 544 // Create date/time from format and timezone 545 // 546 function create_date($format, $gmepoch, $tz) 547 { 548 global $board_config, $lang; 549 static $translate; 550 551 if ( empty($translate) && $board_config['default_lang'] != 'english' ) 552 { 553 @reset($lang['datetime']); 554 while ( list($match, $replace) = @each($lang['datetime']) ) 555 { 556 $translate[$match] = $replace; 557 } 558 } 559 560 return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * ($tz+date("I")))), $translate) : @gmdate($format, $gmepoch + (3600 * ($tz+date("I")))); 561 } 562 563 // 564 // Pagination routine, generates 565 // page number sequence 566 // 567 function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE) 568 { 569 global $lang; 570 571 $total_pages = ceil($num_items/$per_page); 572 573 if ( $total_pages == 1 ) 574 { 575 return ''; 576 } 577 578 $on_page = floor($start_item / $per_page) + 1; 579 580 $page_string = ''; 581 if ( $total_pages > 10 ) 582 { 583 $init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages; 584 585 for($i = 1; $i < $init_page_max + 1; $i++) 586 { 587 $page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>'; 588 if ( $i < $init_page_max ) 589 { 590 $page_string .= ", "; 591 } 592 } 593 594 if ( $total_pages > 3 ) 595 { 596 if ( $on_page > 1 && $on_page < $total_pages ) 597 { 598 $page_string .= ( $on_page > 5 ) ? ' ... ' : ', '; 599 600 $init_page_min = ( $on_page > 4 ) ? $on_page : 5; 601 $init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4; 602 603 for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++) 604 { 605 $page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>'; 606 if ( $i < $init_page_max + 1 ) 607 { 608 $page_string .= ', '; 609 } 610 } 611 612 $page_string .= ( $on_page < $total_pages - 4 ) ? ' ... ' : ', '; 613 } 614 else 615 { 616 $page_string .= ' ... '; 617 } 618 619 for($i = $total_pages - 2; $i < $total_pages + 1; $i++) 620 { 621 $page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>'; 622 if( $i < $total_pages ) 623 { 624 $page_string .= ", "; 625 } 626 } 627 } 628 } 629 else 630 { 631 for($i = 1; $i < $total_pages + 1; $i++) 632 { 633 $page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . append_sid($base_url . "&start=" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>'; 634 if ( $i < $total_pages ) 635 { 636 $page_string .= ', '; 637 } 638 } 639 } 640 641 if ( $add_prevnext_text ) 642 { 643 if ( $on_page > 1 ) 644 { 645 $page_string = ' <a href="' . append_sid($base_url . "&start=" . ( ( $on_page - 2 ) * $per_page ) ) . '">' . $lang['Previous'] . '</a> ' . $page_string; 646 } 647 648 if ( $on_page < $total_pages ) 649 { 650 $page_string .= ' <a href="' . append_sid($base_url . "&start=" . ( $on_page * $per_page ) ) . '">' . $lang['Next'] . '</a>'; 651 } 652 653 } 654 655 $page_string = $lang['Goto_page'] . ' ' . $page_string; 656 657 return $page_string; 658 } 659 660 // 661 // This does exactly what preg_quote() does in PHP 4-ish 662 // If you just need the 1-parameter preg_quote call, then don't bother using this. 663 // 664 function phpbb_preg_quote($str, $delimiter) 665 { 666 $text = preg_quote($str); 667 $text = str_replace($delimiter, '\\' . $delimiter, $text); 668 669 return $text; 670 } 671 672 // 673 // Obtain list of naughty words and build preg style replacement arrays for use by the 674 // calling script, note that the vars are passed as references this just makes it easier 675 // to return both sets of arrays 676 // 677 function obtain_word_list(&$orig_word, &$replacement_word) 678 { 679 global $db; 680 681 // 682 // Define censored word matches 683 // 684 $sql = "SELECT word, replacement 685 FROM " . WORDS_TABLE; 686 if( !($result = $db->sql_query($sql)) ) 687 { 688 message_die(GENERAL_ERROR, 'Could not get censored words from database', '', __LINE__, __FILE__, $sql); 689 } 690 691 if ( $row = $db->sql_fetchrow($result) ) 692 { 693 do 694 { 695 $orig_word[] = '#\b(' . str_replace('\*', '\w*?', preg_quote($row['word'], '#')) . ')\b#i'; 696 $replacement_word[] = $row['replacement']; 697 } 698 while ( $row = $db->sql_fetchrow($result) ); 699 } 700 701 return true; 702 } 703 704 // 705 // This is general replacement for die(), allows templated 706 // output in users (or default) language, etc. 707 // 708 // $msg_code can be one of these constants: 709 // 710 // GENERAL_MESSAGE : Use for any simple text message, eg. results 711 // of an operation, authorisation failures, etc. 712 // 713 // GENERAL ERROR : Use for any error which occurs _AFTER_ the 714 // common.php include and session code, ie. most errors in 715 // pages/functions 716 // 717 // CRITICAL_MESSAGE : Used when basic config data is available but 718 // a session may not exist, eg. banned users 719 // 720 // CRITICAL_ERROR : Used when config data cannot be obtained, eg 721 // no database connection. Should _not_ be used in 99.5% of cases 722 // 723 function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '') 724 { 725 global $db, $template, $board_config, $theme, $lang, $phpEx, $phpbb_root_path, $nav_links, $gen_simple_header, $images; 726 global $userdata, $user_ip, $session_length; 727 global $starttime; 728 729 if(defined('HAS_DIED')) 730 { 731 die("message_die() was called multiple times. This isn't supposed to happen. Was message_die() used in page_tail.php?"); 732 } 733 734 define('HAS_DIED', 1); 735 736 737 $sql_store = $sql; 738 739 // 740 // Get SQL error if we are debugging. Do this as soon as possible to prevent 741 // subsequent queries from overwriting the status of sql_error() 742 // 743 if ( DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) ) 744 { 745 $sql_error = $db->sql_error(); 746 747 $debug_text = ''; 748 749 if ( $sql_error['message'] != '' ) 750 { 751 $debug_text .= '<br /><br />SQL Error : ' . $sql_error['code'] . ' ' . $sql_error['message']; 752 } 753 754 if ( $sql_store != '' ) 755 { 756 $debug_text .= "<br /><br />$sql_store"; 757 } 758 759 if ( $err_line != '' && $err_file != '' ) 760 { 761 $debug_text .= '<br /><br />Line : ' . $err_line . '<br />File : ' . basename($err_file); 762 } 763 } 764 765 if( empty($userdata) && ( $msg_code == GENERAL_MESSAGE || $msg_code == GENERAL_ERROR ) ) 766 { 767 $userdata = session_pagestart($user_ip, PAGE_INDEX); 768 init_userprefs($userdata); 769 } 770 771 // 772 // If the header hasn't been output then do it 773 // 774 if ( !defined('HEADER_INC') && $msg_code != CRITICAL_ERROR ) 775 { 776 if ( empty($lang) ) 777 { 778 if ( !empty($board_config['default_lang']) ) 779 { 780 include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.'.$phpEx); 781 } 782 else 783 { 784 include($phpbb_root_path . 'language/lang_german/lang_main.'.$phpEx); 785 } 786 } 787 788 if ( empty($template) || empty($theme) ) 789 { 790 $theme = setup_style($board_config['default_style']); 791 } 792 793 // 794 // Load the Page Header 795 // 796 if ( !defined('IN_ADMIN') ) 797 { 798 include($phpbb_root_path . 'includes/page_header.'.$phpEx); 799 } 800 else 801 { 802 include($phpbb_root_path . 'admin/page_header_admin.'.$phpEx); 803 } 804 } 805 806 switch($msg_code) 807 { 808 case GENERAL_MESSAGE: 809 if ( $msg_title == '' ) 810 { 811 $msg_title = $lang['Information']; 812 } 813 break; 814 815 case CRITICAL_MESSAGE: 816 if ( $msg_title == '' ) 817 { 818 $msg_title = $lang['Critical_Information']; 819 } 820 break; 821 822 case GENERAL_ERROR: 823 if ( $msg_text == '' ) 824 { 825 $msg_text = $lang['An_error_occured']; 826 } 827 828 if ( $msg_title == '' ) 829 { 830 $msg_title = $lang['General_Error']; 831 } 832 break; 833 834 case CRITICAL_ERROR: 835 // 836 // Critical errors mean we cannot rely on _ANY_ DB information being 837 // available so we're going to dump out a simple echo'd statement 838 // 839 include($phpbb_root_path . 'language/lang_german/lang_main.'.$phpEx); 840 841 if ( $msg_text == '' ) 842 { 843 $msg_text = $lang['A_critical_error']; 844 } 845 846 if ( $msg_title == '' ) 847 { 848 $msg_title = 'phpBB : <b>' . $lang['Critical_Error'] . '</b>'; 849 } 850 break; 851 } 852 853 // 854 // Add on DEBUG info if we've enabled debug mode and this is an error. This 855 // prevents debug info being output for general messages should DEBUG be 856 // set TRUE by accident (preventing confusion for the end user!) 857 // 858 if ( DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) ) 859 { 860 if ( $debug_text != '' ) 861 { 862 $msg_text = $msg_text . '<br /><br /><b><u>DEBUG MODE</u></b>' . $debug_text; 863 } 864 } 865 866 if ( $msg_code != CRITICAL_ERROR ) 867 { 868 if ( !empty($lang[$msg_text]) ) 869 { 870 $msg_text = $lang[$msg_text]; 871 } 872 873 if ( !defined('IN_ADMIN') ) 874 { 875 $template->set_filenames(array( 876 'message_body' => 'message_body.tpl') 877 ); 878 } 879 else 880 { 881 $template->set_filenames(array( 882 'message_body' => 'admin/admin_message_body.tpl') 883 ); 884 } 885 886 $template->assign_vars(array( 887 'MESSAGE_TITLE' => $msg_title, 888 'MESSAGE_TEXT' => $msg_text) 889 ); 890 $template->pparse('message_body'); 891 892 if ( !defined('IN_ADMIN') ) 893 { 894 include($phpbb_root_path . 'includes/page_tail.'.$phpEx); 895 } 896 else 897 { 898 include($phpbb_root_path . 'admin/page_footer_admin.'.$phpEx); 899 } 900 } 901 else 902 { 903 echo "<html>\n<body>\n" . $msg_title . "\n<br /><br />\n" . $msg_text . "</body>\n</html>"; 904 } 905 906 exit; 907 } 908 909 // 910 // This function is for compatibility with PHP 4.x's realpath() 911 // function. In later versions of PHP, it needs to be called 912 // to do checks with some functions. Older versions of PHP don't 913 // seem to need this, so we'll just return the original value. 914 // dougk_ff7 <October 5, 2002> 915 function phpbb_realpath($path) 916 { 917 global $phpbb_root_path, $phpEx; 918 919 return (!@function_exists('realpath') || !@realpath($phpbb_root_path . 'includes/functions.'.$phpEx)) ? $path : @realpath($path); 920 } 921 922 function redirect($url) 923 { 924 global $db, $board_config; 925 926 if (!empty($db)) 927 { 928 $db->sql_close(); 929 } 930 931 if (strstr(urldecode($url), "\n") || strstr(urldecode($url), "\r")) 932 { 933 message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.'); 934 } 935 936 $server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://'; 937 $server_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['server_name'])); 938 $server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) : ''; 939 $script_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['script_path'])); 940 $script_name = ($script_name == '') ? $script_name : '/' . $script_name; 941 $url = preg_replace('#^\/?(.*?)\/?$#', '/\1', trim($url)); 942 943 // Redirect via an HTML form for PITA webservers 944 if (@preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE'))) 945 { 946 header('Refresh: 0; URL=' . $server_protocol . $server_name . $server_port . $script_name . $url); 947 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta http-equiv="refresh" content="0; url=' . $server_protocol . $server_name . $server_port . $script_name . $url . '"><title>Redirect</title></head><body><div align="center">If your browser does not support meta redirection please click <a href="' . $server_protocol . $server_name . $server_port . $script_name . $url . '">HERE</a> to be redirected</div></body></html>'; 948 exit; 949 } 950 951 // Behave as per HTTP/1.1 spec for others 952 header('Location: ' . $server_protocol . $server_name . $server_port . $script_name . $url); 953 exit; 954 } 955 956 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jun 15 00:04:58 2006 | Cross-referenced by PHPXref 0.6 |