[ Index ]

PHP Cross Reference of MyBB 1.8.39

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


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