[ Index ]

PHP Cross Reference of MyBB 1.8.37

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


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