[ Index ]

PHP Cross Reference of MyBB 1.8.32

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_callback"), $error_types);
 141      }
 142  
 143      /**
 144       * Passes relevant arguments for error 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       */
 151  	function error_callback($type, $message, $file=null, $line=0)
 152      {
 153          return $this->error($type, $message, $file, $line);
 154      }
 155  
 156      /**
 157       * Processes an error.
 158       *
 159       * @param string $type The error type (i.e. E_ERROR, E_FATAL)
 160       * @param string $message The error message
 161       * @param string $file The error file
 162       * @param integer $line The error line
 163       * @param boolean $allow_output Whether or not output is permitted
 164       * @return boolean True if parsing was a success, otherwise assume a error
 165       */
 166  	function error($type, $message, $file=null, $line=0, $allow_output=true)
 167      {
 168          global $mybb;
 169  
 170          // Error reporting turned off for this type
 171          if((error_reporting() & $type) == 0)
 172          {
 173              return true;
 174          }
 175  
 176          if(in_array($type, $this->ignore_types))
 177          {
 178              return true;
 179          }
 180  
 181          $file = str_replace(MYBB_ROOT, "", $file);
 182  
 183          $this->has_errors = true;
 184  
 185          // For some reason in the installer this setting is set to "<"
 186          $accepted_error_types = array('both', 'error', 'warning', 'none');
 187          if(isset($mybb->settings['errortypemedium']) && in_array($mybb->settings['errortypemedium'], $accepted_error_types))
 188          {
 189              $errortypemedium = $mybb->settings['errortypemedium'];
 190          }
 191          else
 192          {
 193              $errortypemedium = "none";
 194          }
 195  
 196          if(isset($mybb->settings['errorlogmedium']))
 197          {
 198              $errorlogmedium = $mybb->settings['errorlogmedium'];
 199          }
 200          else
 201          {
 202              $errorlogmedium = 'none';
 203          }
 204  
 205          if(defined("IN_TASK"))
 206          {
 207              global $task;
 208  
 209              require_once  MYBB_ROOT."inc/functions_task.php";
 210  
 211              $filestr = '';
 212              if($file)
 213              {
 214                  $filestr = " - Line: $line - File: $file";
 215              }
 216  
 217              add_task_log($task, "{$this->error_types[$type]} - [$type] ".var_export($message, true)."{$filestr}");
 218          }
 219  
 220          // Saving error to log file.
 221          if($errorlogmedium == "log" || $errorlogmedium == "both")
 222          {
 223              $this->log_error($type, $message, $file, $line);
 224          }
 225  
 226          // Are we emailing the Admin a copy?
 227          if($errorlogmedium == "mail" || $errorlogmedium == "both")
 228          {
 229              $this->email_error($type, $message, $file, $line);
 230          }
 231  
 232          if($allow_output === true)
 233          {
 234              // SQL Error
 235              if($type == MYBB_SQL)
 236              {
 237                  $this->output_error($type, $message, $file, $line);
 238              }
 239              // PHP Error
 240              elseif(strpos(strtolower($this->error_types[$type]), 'warning') === false)
 241              {
 242                  $this->output_error($type, $message, $file, $line);
 243              }
 244              // PHP Warning
 245              elseif(in_array($errortypemedium, array('warning', 'both')))
 246              {
 247                  global $templates;
 248  
 249                  $warning = "<strong>{$this->error_types[$type]}</strong> [$type] $message - Line: $line - File: $file PHP ".PHP_VERSION." (".PHP_OS.")<br />\n";
 250                  if(is_object($templates) && method_exists($templates, "get") && !defined("IN_ADMINCP"))
 251                  {
 252                      $this->warnings .= $warning;
 253                      $this->warnings .= $this->generate_backtrace();
 254                  }
 255                  else
 256                  {
 257                      echo "<div class=\"php_warning\">{$warning}".$this->generate_backtrace()."</div>";
 258                  }
 259              }
 260          }
 261  
 262          return true;
 263      }
 264  
 265      /**
 266       * Returns all the warnings
 267       *
 268       * @return string|bool The warnings or false if no warnings exist
 269       */
 270  	function show_warnings()
 271      {
 272          global $lang, $templates;
 273  
 274          if(empty($this->warnings))
 275          {
 276              return false;
 277          }
 278  
 279          // Incase a template fails and we're receiving a blank page.
 280          if(MANUAL_WARNINGS)
 281          {
 282              echo $this->warnings."<br />";
 283          }
 284  
 285          if(!$lang->warnings)
 286          {
 287              $lang->warnings = "The following warnings occurred:";
 288          }
 289  
 290          $template_exists = false;
 291  
 292          if(!is_object($templates) || !method_exists($templates, 'get'))
 293          {
 294              if(@file_exists(MYBB_ROOT."inc/class_templates.php"))
 295              {
 296                  @require_once  MYBB_ROOT."inc/class_templates.php";
 297                  $templates = new templates;
 298                  $template_exists = true;
 299              }
 300          }
 301          else
 302          {
 303              $template_exists = true;
 304          }
 305  
 306          $warning = '';
 307          if($template_exists == true)
 308          {
 309              eval("\$warning = \"".$templates->get("php_warnings")."\";");
 310          }
 311  
 312          return $warning;
 313      }
 314  
 315      /**
 316       * Triggers a user created error
 317       * Example: $error_handler->trigger("Some Warning", E_USER_ERROR);
 318       *
 319       * @param string $message Message
 320       * @param string|int $type Type
 321       */
 322  	function trigger($message="", $type=E_USER_ERROR)
 323      {
 324          global $lang;
 325  
 326          if(!$message)
 327          {
 328              if(isset($lang->unknown_user_trigger))
 329              {
 330                  $message = $lang->unknown_user_trigger;
 331              }
 332              else
 333              {
 334                  $message .= 'An unknown error has been triggered.';
 335              }
 336          }
 337  
 338          if(in_array($type, $this->mybb_error_types))
 339          {
 340              $this->error($type, $message);
 341          }
 342          else
 343          {
 344              trigger_error($message, $type);
 345          }
 346      }
 347  
 348      /**
 349       * Logs the error in the specified error log file.
 350       *
 351       * @param string $type Warning type
 352       * @param string $message Warning message
 353       * @param string $file Warning file
 354       * @param integer $line Warning line
 355       */
 356  	function log_error($type, $message, $file, $line)
 357      {
 358          global $mybb;
 359  
 360          if($type == MYBB_SQL)
 361          {
 362              $message = "SQL Error: {$message['error_no']} - {$message['error']}\nQuery: {$message['query']}";
 363          }
 364  
 365          // Do not log something that might be executable
 366          $message = str_replace('<?', '< ?', $message);
 367  
 368          $back_trace = $this->generate_backtrace(false, 2);
 369  
 370          if($back_trace)
 371          {
 372              $back_trace = "\t<back_trace>{$back_trace}</back_trace>\n";
 373          }
 374  
 375          $error_data = "<error>\n";
 376          $error_data .= "\t<dateline>".TIME_NOW."</dateline>\n";
 377          $error_data .= "\t<script>".$file."</script>\n";
 378          $error_data .= "\t<line>".$line."</line>\n";
 379          $error_data .= "\t<type>".$type."</type>\n";
 380          $error_data .= "\t<friendly_type>".$this->error_types[$type]."</friendly_type>\n";
 381          $error_data .= "\t<message>".$message."</message>\n";
 382          $error_data .= $back_trace;
 383          $error_data .= "</error>\n\n";
 384  
 385          if(isset($mybb->settings['errorloglocation']) && trim($mybb->settings['errorloglocation']) != "")
 386          {
 387              @error_log($error_data, 3, $mybb->settings['errorloglocation']);
 388          }
 389          else
 390          {
 391              @error_log($error_data, 0);
 392          }
 393      }
 394  
 395      /**
 396       * Emails the error in the specified error log file.
 397       *
 398       * @param string $type Warning type
 399       * @param string $message Warning message
 400       * @param string $file Warning file
 401       * @param integer $line Warning line
 402       * @return bool returns false if no admin email is set
 403       */
 404  	function email_error($type, $message, $file, $line)
 405      {
 406          global $mybb;
 407  
 408          if(empty($mybb->settings['adminemail']))
 409          {
 410              return false;
 411          }
 412  
 413          if($type == MYBB_SQL)
 414          {
 415              $message = "SQL Error: {$message['error_no']} - {$message['error']}\nQuery: {$message['query']}";
 416          }
 417  
 418          if(function_exists('debug_backtrace'))
 419          {
 420              ob_start();
 421              debug_print_backtrace();
 422              $trace = ob_get_contents();
 423              ob_end_clean();
 424  
 425              $back_trace = "\nBack Trace: {$trace}";
 426          }
 427          else
 428          {
 429              $back_trace = '';
 430          }
 431  
 432          $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}";
 433  
 434          @my_mail($mybb->settings['adminemail'], "MyBB error on {$mybb->settings['bbname']}", $message, $mybb->settings['adminemail']);
 435  
 436          return true;
 437      }
 438  
 439      /**
 440       * @param string $type
 441       * @param string $message
 442       * @param string $file
 443       * @param int $line
 444       */
 445  	function output_error($type, $message, $file, $line)
 446      {
 447          global $mybb, $parser, $lang;
 448  
 449          if(isset($mybb->settings['bbname']))
 450          {
 451              $bbname = $mybb->settings['bbname'];
 452          }
 453          else
 454          {
 455              $bbname = "MyBB";
 456          }
 457  
 458          // For some reason in the installer this setting is set to "<"
 459          $accepted_error_types = array('both', 'error', 'warning', 'none');
 460          if(isset($mybb->settings['errortypemedium']) && in_array($mybb->settings['errortypemedium'], $accepted_error_types))
 461          {
 462              $errortypemedium = $mybb->settings['errortypemedium'];
 463          }
 464          else
 465          {
 466              $errortypemedium = "none";
 467          }
 468  
 469          $show_details = (
 470              $this->force_display_errors ||
 471              in_array($errortypemedium, array('both', 'error')) ||
 472              defined("IN_INSTALL") ||
 473              defined("IN_UPGRADE")
 474          );
 475  
 476          if($type == MYBB_SQL)
 477          {
 478              $title = "MyBB SQL Error";
 479              $error_message = "<p>MyBB has experienced an internal SQL error and cannot continue.</p>";
 480              if($show_details)
 481              {
 482                  $message['query'] = htmlspecialchars_uni($message['query']);
 483                  $message['error'] = htmlspecialchars_uni($message['error']);
 484                  $error_message .= "<dl>\n";
 485                  $error_message .= "<dt>SQL Error:</dt>\n<dd>{$message['error_no']} - {$message['error']}</dd>\n";
 486                  if($message['query'] != "")
 487                  {
 488                      $error_message .= "<dt>Query:</dt>\n<dd>{$message['query']}</dd>\n";
 489                  }
 490                  $error_message .= "</dl>\n";
 491              }
 492          }
 493          else
 494          {
 495              $title = "MyBB Internal Error";
 496              $error_message = "<p>MyBB has experienced an internal error and cannot continue.</p>";
 497              if($show_details)
 498              {
 499                  $error_message .= "<dl>\n";
 500                  $error_message .= "<dt>Error Type:</dt>\n<dd>{$this->error_types[$type]} ($type)</dd>\n";
 501                  $error_message .= "<dt>Error Message:</dt>\n<dd>{$message}</dd>\n";
 502                  if(!empty($file))
 503                  {
 504                      $error_message .= "<dt>Location:</dt><dd>File: {$file}<br />Line: {$line}</dd>\n";
 505                      if(!@preg_match('#config\.php|settings\.php#', $file) && @file_exists($file))
 506                      {
 507                          $code_pre = @file($file);
 508  
 509                          $code = "";
 510  
 511                          if(isset($code_pre[$line-4]))
 512                          {
 513                              $code .= $line-3 . ". ".$code_pre[$line-4];
 514                          }
 515  
 516                          if(isset($code_pre[$line-3]))
 517                          {
 518                              $code .= $line-2 . ". ".$code_pre[$line-3];
 519                          }
 520  
 521                          if(isset($code_pre[$line-2]))
 522                          {
 523                              $code .= $line-1 . ". ".$code_pre[$line-2];
 524                          }
 525  
 526                          $code .= $line . ". ".$code_pre[$line-1]; // The actual line.
 527  
 528                          if(isset($code_pre[$line]))
 529                          {
 530                              $code .= $line+1 . ". ".$code_pre[$line];
 531                          }
 532  
 533                          if(isset($code_pre[$line+1]))
 534                          {
 535                              $code .= $line+2 . ". ".$code_pre[$line+1];
 536                          }
 537  
 538                          if(isset($code_pre[$line+2]))
 539                          {
 540                              $code .= $line+3 . ". ".$code_pre[$line+2];
 541                          }
 542  
 543                          unset($code_pre);
 544  
 545                          $parser_exists = false;
 546  
 547                          if(!is_object($parser) || !method_exists($parser, 'mycode_parse_php'))
 548                          {
 549                              if(@file_exists(MYBB_ROOT."inc/class_parser.php"))
 550                              {
 551                                  @require_once  MYBB_ROOT."inc/class_parser.php";
 552                                  $parser = new postParser;
 553                                  $parser_exists = true;
 554                              }
 555                          }
 556                          else
 557                          {
 558                              $parser_exists = true;
 559                          }
 560  
 561                          if($parser_exists)
 562                          {
 563                              $code = $parser->mycode_parse_php($code, true);
 564                          }
 565                          else
 566                          {
 567                              $code = @nl2br($code);
 568                          }
 569  
 570                          $error_message .= "<dt>Code:</dt><dd>{$code}</dd>\n";
 571                      }
 572                  }
 573                  $backtrace = $this->generate_backtrace();
 574                  if($backtrace && !in_array($type, $this->mybb_error_types))
 575                  {
 576                      $error_message .= "<dt>Backtrace:</dt><dd>{$backtrace}</dd>\n";
 577                  }
 578                  $error_message .= "</dl>\n";
 579              }
 580          }
 581  
 582          if(isset($lang->settings['charset']))
 583          {
 584              $charset = $lang->settings['charset'];
 585          }
 586          else
 587          {
 588              $charset = 'UTF-8';
 589          }
 590  
 591          $contact_site_owner = '';
 592          $is_in_contact = defined('THIS_SCRIPT') && THIS_SCRIPT === 'contact.php';
 593          if(
 594              !empty($mybb->settings['contactlink']) &&
 595              (
 596                  !empty($mybb->settings['contact']) &&
 597                  !$is_in_contact &&
 598                  (
 599                      $mybb->settings['contactlink'] == "contact.php" &&
 600                      (
 601                          !isset($mybb->user['uid']) ||
 602                          ($mybb->settings['contact_guests'] != 1 && $mybb->user['uid'] == 0) ||
 603                          $mybb->user['uid'] > 0
 604                      )
 605                  ) ||
 606                  $mybb->settings['contactlink'] != "contact.php"
 607              )
 608          )
 609          {
 610              if(
 611                  !my_validate_url($mybb->settings['contactlink'], true, true) &&
 612                  my_substr($mybb->settings['contactlink'], 0, 7) != 'mailto:'
 613              )
 614              {
 615                  $mybb->settings['contactlink'] = $mybb->settings['bburl'].'/'.$mybb->settings['contactlink'];
 616              }
 617  
 618              $contact_site_owner = <<<HTML
 619   If this problem persists, please <a href="{$mybb->settings['contactlink']}">contact the site owner</a>.
 620  HTML;
 621          }
 622  
 623          $additional_name = '';
 624          $docs_link = 'https://docs.mybb.com';
 625          $common_issues_link = 'https://docs.mybb.com/1.8/faq/';
 626          $support_link = 'https://community.mybb.com/';
 627  
 628          if(isset($lang->settings['docs_link']))
 629          {
 630              $docs_link = $lang->settings['docs_link'];
 631          }
 632  
 633          if(isset($lang->settings['common_issues_link']))
 634          {
 635              $common_issues_link = $lang->settings['common_issues_link'];
 636          }
 637  
 638          if(isset($lang->settings['support_link']))
 639          {
 640              $support_link = $lang->settings['support_link'];
 641          }
 642  
 643  
 644          if(isset($lang->settings['additional_name']))
 645          {
 646              $additional_name = $lang->settings['additional_name'];
 647          }
 648  
 649          $contact = <<<HTML
 650  <p>
 651      <strong>If you're a visitor of this website</strong>, please wait a few minutes and try again.{$contact_site_owner}
 652  </p>
 653  
 654  <p>
 655      <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>.
 656  </p>
 657  HTML;
 658  
 659          if(!headers_sent() && !defined("IN_INSTALL") && !defined("IN_UPGRADE"))
 660          {
 661              @header('HTTP/1.1 503 Service Temporarily Unavailable');
 662              @header('Status: 503 Service Temporarily Unavailable');
 663              @header('Retry-After: 1800');
 664              @header("Content-type: text/html; charset={$charset}");
 665  
 666              $file_name = basename($_SERVER['SCRIPT_FILENAME']);
 667              if(function_exists('htmlspecialchars_uni'))
 668              {
 669                  $file_name = htmlspecialchars_uni($file_name);
 670              }
 671              else
 672              {
 673                  $file_name = htmlspecialchars($file_name);
 674              }
 675  
 676              echo <<<EOF
 677  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 678  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 679  <head profile="http://gmpg.org/xfn/11">
 680      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 681      <title>{$bbname} - Internal Error</title>
 682      <style type="text/css">
 683          body { background: #efefef; color: #000; font-family: Tahoma,Verdana,Arial,Sans-Serif; font-size: 12px; text-align: center; line-height: 1.4; }
 684          a:link { color: #026CB1; text-decoration: none;    }
 685          a:visited {    color: #026CB1;    text-decoration: none; }
 686          a:hover, a:active {    color: #000; text-decoration: underline; }
 687          #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; }
 688          h1 { margin: 0; background: url({$file_name}?action=mybb_logo) no-repeat;    height: 82px; width: 248px; }
 689          #content { border: 1px solid #026CB1; background: #fff; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; }
 690          h2 { font-size: 12px; padding: 4px; background: #026CB1; color: #fff; margin: 0; }
 691          .invisible { display: none; }
 692          #error { padding: 6px; }
 693          #footer { font-size: 12px; border-top: 1px dotted #DDDDDD; padding-top: 10px; }
 694          dt { font-weight: bold; }
 695      </style>
 696  </head>
 697  <body>
 698      <div id="container">
 699          <div id="logo">
 700              <h1><a href="https://mybb.com/" title="MyBB"><span class="invisible">MyBB</span></a></h1>
 701          </div>
 702  
 703          <div id="content">
 704              <h2>{$title}</h2>
 705  
 706              <div id="error">
 707                  {$error_message}
 708                  <p id="footer">{$contact}</p>
 709              </div>
 710          </div>
 711      </div>
 712  </body>
 713  </html>
 714  EOF;
 715          }
 716          else
 717          {
 718              echo <<<EOF
 719      <style type="text/css">
 720          #mybb_error_content { border: 1px solid #026CB1; background: #fff; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; }
 721          #mybb_error_content a:link { color: #026CB1; text-decoration: none;    }
 722          #mybb_error_content a:visited {    color: #026CB1;    text-decoration: none; }
 723          #mybb_error_content a:hover, a:active {    color: #000; text-decoration: underline; }
 724          #mybb_error_content h2 { font-size: 12px; padding: 4px; background: #026CB1; color: #fff; margin: 0; border-bottom: none; }
 725          #mybb_error_error { padding: 6px; }
 726          #mybb_error_footer { font-size: 12px; border-top: 1px dotted #DDDDDD; padding-top: 10px; }
 727          #mybb_error_content dt { font-weight: bold; }
 728      </style>
 729      <div id="mybb_error_content">
 730          <h2>{$title}</h2>
 731          <div id="mybb_error_error">
 732          {$error_message}
 733              <p id="mybb_error_footer">{$contact}</p>
 734          </div>
 735      </div>
 736  EOF;
 737          }
 738  
 739          exit(1);
 740      }
 741  
 742      /**
 743       * Generates a backtrace if the server supports it.
 744       *
 745       * @return string The generated backtrace
 746       */
 747  	function generate_backtrace($html=true, $strip=1)
 748      {
 749          $backtrace = '';
 750          if(function_exists("debug_backtrace"))
 751          {
 752              $trace = debug_backtrace(1<<1 /* DEBUG_BACKTRACE_IGNORE_ARGS */);
 753  
 754              if($html)
 755              {
 756                  $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";
 757                  $backtrace .= "<thead><tr>\n";
 758                  $backtrace .= "<th style=\"border-bottom: 1px solid #aaa; background: #ccc; padding: 4px; text-align: left; font-size: 11px;\">File</th>\n";
 759                  $backtrace .= "<th style=\"border-bottom: 1px solid #aaa; background: #ccc; padding: 4px; text-align: left; font-size: 11px;\">Line</th>\n";
 760                  $backtrace .= "<th style=\"border-bottom: 1px solid #aaa; background: #ccc; padding: 4px; text-align: left; font-size: 11px;\">Function</th>\n";
 761                  $backtrace .= "</tr></thead>\n<tbody>\n";
 762              }
 763  
 764              // Strip off calls from trace
 765              $trace = array_slice($trace, $strip);
 766  
 767              $i = 0;
 768  
 769              foreach($trace as $call)
 770              {
 771                  if(empty($call['file'])) $call['file'] = "[PHP]";
 772                  if(empty($call['line'])) $call['line'] = " ";
 773                  if(!empty($call['class'])) $call['function'] = $call['class'].$call['type'].$call['function'];
 774                  $call['file'] = str_replace(MYBB_ROOT, "/", $call['file']);
 775  
 776                  if($html)
 777                  {
 778                      $backtrace .= "<tr>\n";
 779                      $backtrace .= "<td style=\"font-size: 11px; padding: 4px; border-bottom: 1px solid #ccc;\">{$call['file']}</td>\n";
 780                      $backtrace .= "<td style=\"font-size: 11px; padding: 4px; border-bottom: 1px solid #ccc;\">{$call['line']}</td>\n";
 781                      $backtrace .= "<td style=\"font-size: 11px; padding: 4px; border-bottom: 1px solid #ccc;\">{$call['function']}</td>\n";
 782                      $backtrace .= "</tr>\n";
 783                  }
 784                  else
 785                  {
 786                      $backtrace .= "#{$i}  {$call['function']}() called at [{$call['file']}:{$call['line']}]\n";
 787                  }
 788  
 789                  $i++;
 790              }
 791  
 792              if($html)
 793              {
 794                  $backtrace .= "</tbody></table>\n";
 795              }
 796          }
 797          return $backtrace;
 798      }
 799  }


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