[ Index ]

PHP Cross Reference of MyBB 1.8.27

title

Body

[close]

/inc/ -> class_error.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  // Set to 1 if receiving a blank page (template failure).
  12  define("MANUAL_WARNINGS", 0);
  13  
  14  // Define Custom MyBB error handler constants with a value not used by php's error handler.
  15  define("MYBB_SQL", 20);
  16  define("MYBB_TEMPLATE", 30);
  17  define("MYBB_GENERAL", 40);
  18  define("MYBB_NOT_INSTALLED", 41);
  19  define("MYBB_NOT_UPGRADED", 42);
  20  define("MYBB_INSTALL_DIR_EXISTS", 43);
  21  define("MYBB_SQL_LOAD_ERROR", 44);
  22  define("MYBB_CACHE_NO_WRITE", 45);
  23  define("MYBB_CACHEHANDLER_LOAD_ERROR", 46);
  24  
  25  if(!defined("E_RECOVERABLE_ERROR"))
  26  {
  27      // This constant has been defined since PHP 5.2.
  28      define("E_RECOVERABLE_ERROR", 4096);
  29  }
  30  
  31  if(!defined("E_DEPRECATED"))
  32  {
  33      // This constant has been defined since PHP 5.3.
  34      define("E_DEPRECATED", 8192);
  35  }
  36  
  37  if(!defined("E_USER_DEPRECATED"))
  38  {
  39      // This constant has been defined since PHP 5.3.
  40      define("E_USER_DEPRECATED", 16384);
  41  }
  42  
  43  class errorHandler {
  44  
  45      /**
  46       * Array of all of the error types
  47       *
  48       * @var array
  49       */
  50      public $error_types = array(
  51          E_ERROR                            => 'Error',
  52          E_WARNING                        => 'Warning',
  53          E_PARSE                            => 'Parsing Error',
  54          E_NOTICE                        => 'Notice',
  55          E_CORE_ERROR                    => 'Core Error',
  56          E_CORE_WARNING                    => 'Core Warning',
  57          E_COMPILE_ERROR                    => 'Compile Error',
  58          E_COMPILE_WARNING                => 'Compile Warning',
  59          E_DEPRECATED                    => 'Deprecated Warning',
  60          E_USER_ERROR                    => 'User Error',
  61          E_USER_WARNING                    => 'User Warning',
  62          E_USER_NOTICE                    => 'User Notice',
  63          E_USER_DEPRECATED                 => 'User Deprecated Warning',
  64          E_STRICT                        => 'Runtime Notice',
  65          E_RECOVERABLE_ERROR                => 'Catchable Fatal Error',
  66          MYBB_SQL                         => 'MyBB SQL Error',
  67          MYBB_TEMPLATE                    => 'MyBB Template Error',
  68          MYBB_GENERAL                    => 'MyBB Error',
  69          MYBB_NOT_INSTALLED                => 'MyBB Error',
  70          MYBB_NOT_UPGRADED                => 'MyBB Error',
  71          MYBB_INSTALL_DIR_EXISTS            => 'MyBB Error',
  72          MYBB_SQL_LOAD_ERROR                => 'MyBB Error',
  73          MYBB_CACHE_NO_WRITE                => 'MyBB Error',
  74          MYBB_CACHEHANDLER_LOAD_ERROR    => 'MyBB Error',
  75      );
  76  
  77      /**
  78       * Array of MyBB error types
  79       *
  80       * @var array
  81       */
  82      public $mybb_error_types = array(
  83          MYBB_SQL,
  84          MYBB_TEMPLATE,
  85          MYBB_GENERAL,
  86          MYBB_NOT_INSTALLED,
  87          MYBB_NOT_UPGRADED,
  88          MYBB_INSTALL_DIR_EXISTS,
  89          MYBB_SQL_LOAD_ERROR,
  90          MYBB_CACHE_NO_WRITE,
  91          MYBB_CACHEHANDLER_LOAD_ERROR,
  92      );
  93  
  94      /**
  95       * Array of all of the error types to ignore
  96       *
  97       * @var array
  98       */
  99      public $ignore_types = array(
 100          E_DEPRECATED,
 101          E_NOTICE,
 102          E_USER_NOTICE,
 103          E_STRICT
 104      );
 105  
 106      /**
 107       * String of all the warnings collected
 108       *
 109       * @var string
 110       */
 111      public $warnings = "";
 112  
 113      /**
 114       * Is MyBB in an errornous state? (Have we received an error?)
 115       *
 116       * @var boolean
 117       */
 118      public $has_errors = false;
 119  
 120      /**
 121       * Display errors regardless of related settings (useful during initialization stage)
 122       *
 123       * @var boolean
 124       */
 125      public $force_display_errors = false;
 126  
 127      /**
 128       * Initializes the error handler
 129       *
 130       */
 131  	function __construct()
 132      {
 133          // Lets set the error handler in here so we can just do $handler = new errorHandler() and be all set up.
 134          $error_types = E_ALL;
 135          foreach($this->ignore_types as $bit)
 136          {
 137              $error_types = $error_types & ~$bit;
 138          }
 139          error_reporting($error_types);
 140          set_error_handler(array(&$this, "error"), $error_types);
 141      }
 142  
 143      /**
 144       * Parses a error for processing.
 145       *
 146       * @param string $type The error type (i.e. E_ERROR, E_FATAL)
 147       * @param string $message The error message
 148       * @param string $file The error file
 149       * @param integer $line The error line
 150       * @param boolean $allow_output Whether or not output is permitted
 151       * @return boolean True if parsing was a success, otherwise assume a error
 152       */
 153  	function error($type, $message, $file=null, $line=0, $allow_output=true)
 154      {
 155          global $mybb;
 156  
 157          // Error reporting turned off (either globally or by @ before erroring statement)
 158          if(error_reporting() == 0)
 159          {
 160              return true;
 161          }
 162  
 163          if(in_array($type, $this->ignore_types))
 164          {
 165              return true;
 166          }
 167  
 168          $file = str_replace(MYBB_ROOT, "", $file);
 169  
 170          $this->has_errors = true;
 171  
 172          // For some reason in the installer this setting is set to "<"
 173          $accepted_error_types = array('both', 'error', 'warning', 'none');
 174          if(!in_array($mybb->settings['errortypemedium'], $accepted_error_types))
 175          {
 176              $mybb->settings['errortypemedium'] = "none";
 177          }
 178  
 179          if(defined("IN_TASK"))
 180          {
 181              global $task;
 182  
 183              require_once  MYBB_ROOT."inc/functions_task.php";
 184  
 185              $filestr = '';
 186              if($file)
 187              {
 188                  $filestr = " - Line: $line - File: $file";
 189              }
 190  
 191              add_task_log($task, "{$this->error_types[$type]} - [$type] ".var_export($message, true)."{$filestr}");
 192          }
 193  
 194          // Saving error to log file.
 195          if($mybb->settings['errorlogmedium'] == "log" || $mybb->settings['errorlogmedium'] == "both")
 196          {
 197              $this->log_error($type, $message, $file, $line);
 198          }
 199  
 200          // Are we emailing the Admin a copy?
 201          if($mybb->settings['errorlogmedium'] == "mail" || $mybb->settings['errorlogmedium'] == "both")
 202          {
 203              $this->email_error($type, $message, $file, $line);
 204          }
 205  
 206          if($allow_output === true)
 207          {
 208              // SQL Error
 209              if($type == MYBB_SQL)
 210              {
 211                  $this->output_error($type, $message, $file, $line);
 212              }
 213              else
 214              {
 215                  // Do we have a PHP error?
 216                  if(my_strpos(my_strtolower($this->error_types[$type]), 'warning') === false)
 217                  {
 218                      $this->output_error($type, $message, $file, $line);
 219                  }
 220                  // PHP Error
 221                  else
 222                  {
 223                      if($mybb->settings['errortypemedium'] == "none" || $mybb->settings['errortypemedium'] == "error")
 224                      {
 225                          echo "<div class=\"php_warning\">MyBB Internal: One or more warnings occurred. Please contact your administrator for assistance.</div>";
 226                      }
 227                      else
 228                      {
 229                          global $templates;
 230  
 231                          $warning = "<strong>{$this->error_types[$type]}</strong> [$type] $message - Line: $line - File: $file PHP ".PHP_VERSION." (".PHP_OS.")<br />\n";
 232                          if(is_object($templates) && method_exists($templates, "get") && !defined("IN_ADMINCP"))
 233                          {
 234                              $this->warnings .= $warning;
 235                              $this->warnings .= $this->generate_backtrace();
 236                          }
 237                          else
 238                          {
 239                              echo "<div class=\"php_warning\">{$warning}".$this->generate_backtrace()."</div>";
 240                          }
 241                      }
 242                  }
 243              }
 244          }
 245  
 246          return true;
 247      }
 248  
 249      /**
 250       * Returns all the warnings
 251       *
 252       * @return string|bool The warnings or false if no warnings exist
 253       */
 254  	function show_warnings()
 255      {
 256          global $lang, $templates;
 257  
 258          if(empty($this->warnings))
 259          {
 260              return false;
 261          }
 262  
 263          // Incase a template fails and we're receiving a blank page.
 264          if(MANUAL_WARNINGS)
 265          {
 266              echo $this->warnings."<br />";
 267          }
 268  
 269          if(!$lang->warnings)
 270          {
 271              $lang->warnings = "The following warnings occurred:";
 272          }
 273  
 274          $template_exists = false;
 275  
 276          if(!is_object($templates) || !method_exists($templates, 'get'))
 277          {
 278              if(@file_exists(MYBB_ROOT."inc/class_templates.php"))
 279              {
 280                  @require_once  MYBB_ROOT."inc/class_templates.php";
 281                  $templates = new templates;
 282                  $template_exists = true;
 283              }
 284          }
 285          else
 286          {
 287              $template_exists = true;
 288          }
 289  
 290          $warning = '';
 291          if($template_exists == true)
 292          {
 293              eval("\$warning = \"".$templates->get("php_warnings")."\";");
 294          }
 295  
 296          return $warning;
 297      }
 298  
 299      /**
 300       * Triggers a user created error
 301       * Example: $error_handler->trigger("Some Warning", E_USER_ERROR);
 302       *
 303       * @param string $message Message
 304       * @param string|int $type Type
 305       */
 306  	function trigger($message="", $type=E_USER_ERROR)
 307      {
 308          global $lang;
 309  
 310          if(!$message)
 311          {
 312              $message = $lang->unknown_user_trigger;
 313          }
 314  
 315          if(in_array($type, $this->mybb_error_types))
 316          {
 317              $this->error($type, $message);
 318          }
 319          else
 320          {
 321              trigger_error($message, $type);
 322          }
 323      }
 324  
 325      /**
 326       * Logs the error in the specified error log file.
 327       *
 328       * @param string $type Warning type
 329       * @param string $message Warning message
 330       * @param string $file Warning file
 331       * @param integer $line Warning line
 332       */
 333  	function log_error($type, $message, $file, $line)
 334      {
 335          global $mybb;
 336  
 337          if($type == MYBB_SQL)
 338          {
 339              $message = "SQL Error: {$message['error_no']} - {$message['error']}\nQuery: {$message['query']}";
 340          }
 341  
 342          // Do not log something that might be executable
 343          $message = str_replace('<?', '< ?', $message);
 344  
 345          $back_trace = $this->generate_backtrace(false, 2);
 346  
 347          if($back_trace)
 348          {
 349              $back_trace = "\t<back_trace>{$back_trace}</back_trace>\n";
 350          }
 351  
 352          $error_data = "<error>\n";
 353          $error_data .= "\t<dateline>".TIME_NOW."</dateline>\n";
 354          $error_data .= "\t<script>".$file."</script>\n";
 355          $error_data .= "\t<line>".$line."</line>\n";
 356          $error_data .= "\t<type>".$type."</type>\n";
 357          $error_data .= "\t<friendly_type>".$this->error_types[$type]."</friendly_type>\n";
 358          $error_data .= "\t<message>".$message."</message>\n";
 359          $error_data .= $back_trace;
 360          $error_data .= "</error>\n\n";
 361  
 362          if(trim($mybb->settings['errorloglocation']) != "")
 363          {
 364              @error_log($error_data, 3, $mybb->settings['errorloglocation']);
 365          }
 366          else
 367          {
 368              @error_log($error_data, 0);
 369          }
 370      }
 371  
 372      /**
 373       * Emails the error in the specified error log file.
 374       *
 375       * @param string $type Warning type
 376       * @param string $message Warning message
 377       * @param string $file Warning file
 378       * @param integer $line Warning line
 379       * @return bool returns false if no admin email is set
 380       */
 381  	function email_error($type, $message, $file, $line)
 382      {
 383          global $mybb;
 384  
 385          if(!$mybb->settings['adminemail'])
 386          {
 387              return false;
 388          }
 389  
 390          if($type == MYBB_SQL)
 391          {
 392              $message = "SQL Error: {$message['error_no']} - {$message['error']}\nQuery: {$message['query']}";
 393          }
 394  
 395          if(function_exists('debug_backtrace'))
 396          {
 397              ob_start();
 398              debug_print_backtrace();
 399              $trace = ob_get_contents();
 400              ob_end_clean();
 401  
 402              $back_trace = "\nBack Trace: {$trace}";
 403          }
 404          else
 405          {
 406              $back_trace = '';
 407          }
 408  
 409          $message = "Your copy of MyBB running on {$mybb->settings['bbname']} ({$mybb->settings['bburl']}) has experienced an error. Details of the error include:\n---\nType: $type\nFile: $file (Line no. $line)\nMessage\n$message{$back_trace}";
 410  
 411          @my_mail($mybb->settings['adminemail'], "MyBB error on {$mybb->settings['bbname']}", $message, $mybb->settings['adminemail']);
 412  
 413          return true;
 414      }
 415  
 416      /**
 417       * @param string $type
 418       * @param string $message
 419       * @param string $file
 420       * @param int $line
 421       */
 422  	function output_error($type, $message, $file, $line)
 423      {
 424          global $mybb, $parser, $lang;
 425  
 426          if(!$mybb->settings['bbname'])
 427          {
 428              $mybb->settings['bbname'] = "MyBB";
 429          }
 430          
 431          if($type == MYBB_SQL)
 432          {
 433              $title = "MyBB SQL Error";
 434              $error_message = "<p>MyBB has experienced an internal SQL error and cannot continue.</p>";
 435              if($this->force_display_errors || $mybb->settings['errortypemedium'] == "both" || $mybb->settings['errortypemedium'] == "error" || defined("IN_INSTALL") || defined("IN_UPGRADE"))
 436              {
 437                  $message['query'] = htmlspecialchars_uni($message['query']);
 438                  $message['error'] = htmlspecialchars_uni($message['error']);
 439                  $error_message .= "<dl>\n";
 440                  $error_message .= "<dt>SQL Error:</dt>\n<dd>{$message['error_no']} - {$message['error']}</dd>\n";
 441                  if($message['query'] != "")
 442                  {
 443                      $error_message .= "<dt>Query:</dt>\n<dd>{$message['query']}</dd>\n";
 444                  }
 445                  $error_message .= "</dl>\n";
 446              }
 447          }
 448          else
 449          {
 450              $title = "MyBB Internal Error";
 451              $error_message = "<p>MyBB has experienced an internal error and cannot continue.</p>";
 452              if($this->force_display_errors || $mybb->settings['errortypemedium'] == "both" || $mybb->settings['errortypemedium'] == "error" || defined("IN_INSTALL") || defined("IN_UPGRADE"))
 453              {
 454                  $error_message .= "<dl>\n";
 455                  $error_message .= "<dt>Error Type:</dt>\n<dd>{$this->error_types[$type]} ($type)</dd>\n";
 456                  $error_message .= "<dt>Error Message:</dt>\n<dd>{$message}</dd>\n";
 457                  if(!empty($file))
 458                  {
 459                      $error_message .= "<dt>Location:</dt><dd>File: {$file}<br />Line: {$line}</dd>\n";
 460                      if(!@preg_match('#config\.php|settings\.php#', $file) && @file_exists($file))
 461                      {
 462                          $code_pre = @file($file);
 463  
 464                          $code = "";
 465  
 466                          if(isset($code_pre[$line-4]))
 467                          {
 468                              $code .= $line-3 . ". ".$code_pre[$line-4];
 469                          }
 470  
 471                          if(isset($code_pre[$line-3]))
 472                          {
 473                              $code .= $line-2 . ". ".$code_pre[$line-3];
 474                          }
 475  
 476                          if(isset($code_pre[$line-2]))
 477                          {
 478                              $code .= $line-1 . ". ".$code_pre[$line-2];
 479                          }
 480  
 481                          $code .= $line . ". ".$code_pre[$line-1]; // The actual line.
 482  
 483                          if(isset($code_pre[$line]))
 484                          {
 485                              $code .= $line+1 . ". ".$code_pre[$line];
 486                          }
 487  
 488                          if(isset($code_pre[$line+1]))
 489                          {
 490                              $code .= $line+2 . ". ".$code_pre[$line+1];
 491                          }
 492  
 493                          if(isset($code_pre[$line+2]))
 494                          {
 495                              $code .= $line+3 . ". ".$code_pre[$line+2];
 496                          }
 497  
 498                          unset($code_pre);
 499  
 500                          $parser_exists = false;
 501  
 502                          if(!is_object($parser) || !method_exists($parser, 'mycode_parse_php'))
 503                          {
 504                              if(@file_exists(MYBB_ROOT."inc/class_parser.php"))
 505                              {
 506                                  @require_once  MYBB_ROOT."inc/class_parser.php";
 507                                  $parser = new postParser;
 508                                  $parser_exists = true;
 509                              }
 510                          }
 511                          else
 512                          {
 513                              $parser_exists = true;
 514                          }
 515  
 516                          if($parser_exists)
 517                          {
 518                              $code = $parser->mycode_parse_php($code, true);
 519                          }
 520                          else
 521                          {
 522                              $code = @nl2br($code);
 523                          }
 524  
 525                          $error_message .= "<dt>Code:</dt><dd>{$code}</dd>\n";
 526                      }
 527                  }
 528                  $backtrace = $this->generate_backtrace();
 529                  if($backtrace && !in_array($type, $this->mybb_error_types))
 530                  {
 531                      $error_message .= "<dt>Backtrace:</dt><dd>{$backtrace}</dd>\n";
 532                  }
 533                  $error_message .= "</dl>\n";
 534              }
 535          }
 536  
 537          if(isset($lang->settings['charset']))
 538          {
 539              $charset = $lang->settings['charset'];
 540          }
 541          else
 542          {
 543              $charset = 'UTF-8';
 544          }
 545  
 546          $contact_site_owner = '';
 547          $is_in_contact = defined('THIS_SCRIPT') && THIS_SCRIPT === 'contact.php';
 548          if(!$is_in_contact && ($mybb->settings['contactlink'] == "contact.php" && $mybb->settings['contact'] == 1 && ($mybb->settings['contact_guests'] != 1 && $mybb->user['uid'] == 0 || $mybb->user['uid'] > 0)) || $mybb->settings['contactlink'] != "contact.php")
 549          {
 550              if(!my_validate_url($mybb->settings['contactlink'], true, true) && my_substr($mybb->settings['contactlink'], 0, 7) != 'mailto:')
 551              {
 552                  $mybb->settings['contactlink'] = $mybb->settings['bburl'].'/'.$mybb->settings['contactlink'];
 553              }
 554  
 555              $contact_site_owner = <<<HTML
 556   If this problem persists, please <a href="{$mybb->settings['contactlink']}">contact the site owner</a>.
 557  HTML;
 558          }
 559  
 560          $additional_name = '';
 561          $docs_link = 'https://docs.mybb.com';
 562          $common_issues_link = 'https://docs.mybb.com/1.8/faq/';
 563          $support_link = 'https://community.mybb.com/';
 564  
 565          if(isset($lang->settings['docs_link']))
 566          {
 567              $docs_link = $lang->settings['docs_link'];
 568          }
 569  
 570          if(isset($lang->settings['common_issues_link']))
 571          {
 572              $common_issues_link = $lang->settings['common_issues_link'];
 573          }
 574  
 575          if(isset($lang->settings['support_link']))
 576          {
 577              $support_link = $lang->settings['support_link'];
 578          }
 579  
 580  
 581          if(isset($lang->settings['additional_name']))
 582          {
 583              $additional_name = $lang->settings['additional_name'];
 584          }
 585  
 586          $contact = <<<HTML
 587  <p>
 588      <strong>If you're a visitor of this website</strong>, please wait a few minutes and try again.{$contact_site_owner}
 589  </p>
 590  
 591  <p>
 592      <strong>If you are the site owner</strong>, please check the <a href="{$docs_link}">MyBB{$additional_name} Documentation</a> for help resolving <a href="{$common_issues_link}">common issues</a>, or get technical help on the <a href="{$support_link}">MyBB{$additional_name} Community Forums</a>.
 593  </p>
 594  HTML;
 595  
 596          if(!headers_sent() && !defined("IN_INSTALL") && !defined("IN_UPGRADE"))
 597          {
 598              @header('HTTP/1.1 503 Service Temporarily Unavailable');
 599              @header('Status: 503 Service Temporarily Unavailable');
 600              @header('Retry-After: 1800');
 601              @header("Content-type: text/html; charset={$charset}");
 602              $file_name = htmlspecialchars_uni(basename($_SERVER['SCRIPT_FILENAME']));
 603  
 604              echo <<<EOF
 605  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 606  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 607  <head profile="http://gmpg.org/xfn/11">
 608      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 609      <title>{$mybb->settings['bbname']} - Internal Error</title>
 610      <style type="text/css">
 611          body { background: #efefef; color: #000; font-family: Tahoma,Verdana,Arial,Sans-Serif; font-size: 12px; text-align: center; line-height: 1.4; }
 612          a:link { color: #026CB1; text-decoration: none;    }
 613          a:visited {    color: #026CB1;    text-decoration: none; }
 614          a:hover, a:active {    color: #000; text-decoration: underline; }
 615          #container { width: 600px; padding: 20px; background: #fff;    border: 1px solid #e4e4e4; margin: 100px auto; text-align: left; -moz-border-radius: 6px; -webkit-border-radius: 6px; border-radius: 6px; }
 616          h1 { margin: 0; background: url({$file_name}?action=mybb_logo) no-repeat;    height: 82px; width: 248px; }
 617          #content { border: 1px solid #026CB1; background: #fff; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; }
 618          h2 { font-size: 12px; padding: 4px; background: #026CB1; color: #fff; margin: 0; }
 619          .invisible { display: none; }
 620          #error { padding: 6px; }
 621          #footer { font-size: 12px; border-top: 1px dotted #DDDDDD; padding-top: 10px; }
 622          dt { font-weight: bold; }
 623      </style>
 624  </head>
 625  <body>
 626      <div id="container">
 627          <div id="logo">
 628              <h1><a href="https://mybb.com/" title="MyBB"><span class="invisible">MyBB</span></a></h1>
 629          </div>
 630  
 631          <div id="content">
 632              <h2>{$title}</h2>
 633  
 634              <div id="error">
 635                  {$error_message}
 636                  <p id="footer">{$contact}</p>
 637              </div>
 638          </div>
 639      </div>
 640  </body>
 641  </html>
 642  EOF;
 643          }
 644          else
 645          {
 646              echo <<<EOF
 647      <style type="text/css">
 648          #mybb_error_content { border: 1px solid #026CB1; background: #fff; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; }
 649          #mybb_error_content a:link { color: #026CB1; text-decoration: none;    }
 650          #mybb_error_content a:visited {    color: #026CB1;    text-decoration: none; }
 651          #mybb_error_content a:hover, a:active {    color: #000; text-decoration: underline; }
 652          #mybb_error_content h2 { font-size: 12px; padding: 4px; background: #026CB1; color: #fff; margin: 0; border-bottom: none; }
 653          #mybb_error_error { padding: 6px; }
 654          #mybb_error_footer { font-size: 12px; border-top: 1px dotted #DDDDDD; padding-top: 10px; }
 655          #mybb_error_content dt { font-weight: bold; }
 656      </style>
 657      <div id="mybb_error_content">
 658          <h2>{$title}</h2>
 659          <div id="mybb_error_error">
 660          {$error_message}
 661              <p id="mybb_error_footer">{$contact}</p>
 662          </div>
 663      </div>
 664  EOF;
 665          }
 666  
 667          exit(1);
 668      }
 669  
 670      /**
 671       * Generates a backtrace if the server supports it.
 672       *
 673       * @return string The generated backtrace
 674       */
 675  	function generate_backtrace($html=true, $strip=1)
 676      {
 677          $backtrace = '';
 678          if(function_exists("debug_backtrace"))
 679          {
 680              $trace = debug_backtrace(1<<1 /* DEBUG_BACKTRACE_IGNORE_ARGS */);
 681  
 682              if($html)
 683              {
 684                  $backtrace = "<table style=\"width: 100%; margin: 10px 0; border: 1px solid #aaa; border-collapse: collapse; border-bottom: 0;\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n";
 685                  $backtrace .= "<thead><tr>\n";
 686                  $backtrace .= "<th style=\"border-bottom: 1px solid #aaa; background: #ccc; padding: 4px; text-align: left; font-size: 11px;\">File</th>\n";
 687                  $backtrace .= "<th style=\"border-bottom: 1px solid #aaa; background: #ccc; padding: 4px; text-align: left; font-size: 11px;\">Line</th>\n";
 688                  $backtrace .= "<th style=\"border-bottom: 1px solid #aaa; background: #ccc; padding: 4px; text-align: left; font-size: 11px;\">Function</th>\n";
 689                  $backtrace .= "</tr></thead>\n<tbody>\n";
 690              }
 691  
 692              // Strip off calls from trace
 693              $trace = array_slice($trace, $strip);
 694  
 695              $i = 0;
 696  
 697              foreach($trace as $call)
 698              {
 699                  if(empty($call['file'])) $call['file'] = "[PHP]";
 700                  if(empty($call['line'])) $call['line'] = " ";
 701                  if(!empty($call['class'])) $call['function'] = $call['class'].$call['type'].$call['function'];
 702                  $call['file'] = str_replace(MYBB_ROOT, "/", $call['file']);
 703  
 704                  if($html)
 705                  {
 706                      $backtrace .= "<tr>\n";
 707                      $backtrace .= "<td style=\"font-size: 11px; padding: 4px; border-bottom: 1px solid #ccc;\">{$call['file']}</td>\n";
 708                      $backtrace .= "<td style=\"font-size: 11px; padding: 4px; border-bottom: 1px solid #ccc;\">{$call['line']}</td>\n";
 709                      $backtrace .= "<td style=\"font-size: 11px; padding: 4px; border-bottom: 1px solid #ccc;\">{$call['function']}</td>\n";
 710                      $backtrace .= "</tr>\n";
 711                  }
 712                  else
 713                  {
 714                      $backtrace .= "#{$i}  {$call['function']}() called at [{$call['file']}:{$call['line']}]\n";
 715                  }
 716  
 717                  $i++;
 718              }
 719  
 720              if($html)
 721              {
 722                  $backtrace .= "</tbody></table>\n";
 723              }
 724          }
 725          return $backtrace;
 726      }
 727  }


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref