Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 7.68 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3.         /**
  4.          * Print a document error (startup) and halts script execution
  5.          *
  6.          * @param       string                  The message to show
  7.          * @return      void                    No value is returned
  8.          */
  9.         function doc_error($e)
  10.         {
  11.                 static $called;
  12.                 global $arictos, $configuration;
  13.                
  14.                 if(!is_null($called))
  15.                 {
  16.                         return;
  17.                 }
  18.                                
  19.                 $called                 = true;
  20.                 $buffer                 = ob_get_clean();
  21.                 $exception              = ($e instanceof Exception);
  22.                 $message                = ($exception ? $e->getMessage() : (string) $e);
  23.                 $errors                 = Arictos::globals('errors');
  24.                 $application    = ($configuration['application']['name'] ? $configuration['application']['name'] . ($configuration['application']['version'] ? ' ' . $configuration['application']['version'] : '') : false);
  25.                
  26.                 if($exception && $arictos->db && $e instanceof SQL_Exception)
  27.                 {
  28.                         $message = 'An error occured while querying the database';
  29.                        
  30.                         if(DEBUG)
  31.                         {
  32.                                 $message .= ':' . PHP_EOL .
  33.                                                         '<code>Error Code: ' . $e->getCode() . PHP_EOL .
  34.                                                         $e->getMessage() . '</code>' . PHP_EOL .  
  35.                                                         '<strong>Database driver:</strong> ' . constant(get_class($arictos->db) . '::DRIVER_NAME') . '';
  36.                         }
  37.                 }
  38.                 else if(empty($message))
  39.                 {
  40.                         $message = 'An unknown error occured!';
  41.                 }
  42.                 else if(function_exists('utf8_encode'))
  43.                 {
  44.                         $message = utf8_encode($message);
  45.                 }
  46.                
  47.                 header('HTTP/1.1 500 Internal Server Error');
  48.                 header('Content-Type: text/html');
  49.                
  50.                 echo(
  51.                         '<!DOCTYPE html> ' . PHP_EOL .
  52.                         '<html lang="es">' . PHP_EOL .
  53.                         '       <head>' . PHP_EOL .
  54.                         '               <title>A fatal error has occured.</title>' . PHP_EOL .
  55.                         '               <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . PHP_EOL .
  56.                         '               <style type="text/css">' . PHP_EOL .
  57.                         '                       html {' . PHP_EOL .
  58.                         '                               height: 100%;' . PHP_EOL .
  59.                         '                       }' . PHP_EOL .
  60.                         '                       body {' . PHP_EOL .
  61.                         '                               background: #cccccc;' . PHP_EOL .
  62.                         '                               margin: 0;' . PHP_EOL .
  63.                         '                               padding: 0;' . PHP_EOL .
  64.                         '                               height: 100%;' . PHP_EOL .
  65.                         '                               font: normal normal 13px/20px Lucida, \'Lucida Grande\', \'Trebuchet MS\', Tahoma, Verdana, sans-serif;' . PHP_EOL .
  66.                         '                               color: #333333;' . PHP_EOL .
  67.                         '                       }' . PHP_EOL .
  68.                         '                       h1 {' . PHP_EOL .
  69.                         '                               margin: 0;' . PHP_EOL .
  70.                         '                               padding: 20px 40px;' . PHP_EOL .
  71.                         '                               font-size: 20px;' . PHP_EOL .
  72.                         '                               font-weight: normal;' . PHP_EOL .
  73.                         '                               letter-spacing: -1px;' . PHP_EOL .
  74.                         '                               ' . PHP_EOL .
  75.                         '                               /* css 3 styles */' . PHP_EOL .
  76.                         '                               text-shadow: 0px 1px 0px #ffffff;' . PHP_EOL .
  77.                         '                       }' . PHP_EOL .
  78.                         '                       #wrapper {' . PHP_EOL .
  79.                         '                               background:-webkit-gradient(' . PHP_EOL .
  80.                         '                                       linear,' . PHP_EOL .
  81.                         '                                       left bottom,' . PHP_EOL .
  82.                         '                                       left top,' . PHP_EOL .
  83.                         '                                       color-stop(1, rgb(247,247,247)),' . PHP_EOL .
  84.                         '                                       color-stop(0, rgb(204,204,204))' . PHP_EOL .
  85.                         '                               );' . PHP_EOL .
  86.                         '                               background: -moz-linear-gradient(' . PHP_EOL .
  87.                         '                                       center bottom,' . PHP_EOL .
  88.                         '                                       rgb(204,204,204) 0%,' . PHP_EOL .
  89.                         '                                       rgb(247,247,247) 100%' . PHP_EOL .
  90.                         '                               );' . PHP_EOL .
  91.                         '                       }' . PHP_EOL .
  92.                         '                       .content {' . PHP_EOL .
  93.                         '                               background-color: #f4f4f4;' . PHP_EOL .
  94.                         '                               border: 1px solid #ffffff;' . PHP_EOL .
  95.                         '                               margin: 0 30px;' . PHP_EOL .
  96.                         '                               ' . PHP_EOL .
  97.                         '                               /* css 3 styles */' . PHP_EOL .
  98.                         '                               border-radius: 5px;' . PHP_EOL .
  99.                         '                       }' . PHP_EOL .
  100.                         '                       .content .block {' . PHP_EOL .
  101.                         '                               background-color: #ffffff;' . PHP_EOL .
  102.                         '                               border: 1px solid #dddddd;' . PHP_EOL .
  103.                         '                               border-top: 1px solid #cccccc;' . PHP_EOL .
  104.                         '                               border-bottom: 1px solid #eeeeee;' . PHP_EOL .
  105.                         '                               margin: 9px;' . PHP_EOL .
  106.                         '                               ' . PHP_EOL .
  107.                         '                               /* css 3 styles */' . PHP_EOL .
  108.                         '                               border-radius: 3px;' . PHP_EOL .
  109.                         '                       }' . PHP_EOL .
  110.                         '                       .content .block h2 {' . PHP_EOL .
  111.                         '                               background-color: #f4f4f4;' . PHP_EOL .
  112.                         '                               padding: 4px 8px 5px;' . PHP_EOL .
  113.                         '                       }' . PHP_EOL .
  114.                         '                       .content .block p {' . PHP_EOL .
  115.                         '                               margin: 0;' . PHP_EOL .
  116.                         '                               padding: 19px;' . PHP_EOL .
  117.                         '                       }' . PHP_EOL .
  118.                         '                       .content .block table {' . PHP_EOL .
  119.                         '                               margin: 0;' . PHP_EOL .
  120.                         '                               padding: 10px 10px 20px;' . PHP_EOL .
  121.                         '                       }' . PHP_EOL .
  122.                         '                       .content .block table thead tr td {' . PHP_EOL .
  123.                         '                               background-color: #f0f0f0;' . PHP_EOL .
  124.                         '                               border-top: 1px dashed #cccccc;' . PHP_EOL .
  125.                         '                               border-bottom: 1px dashed #cccccc;' . PHP_EOL .
  126.                         '                               margin: 0;' . PHP_EOL .
  127.                         '                               padding: 5px 7px;' . PHP_EOL .
  128.                         '                               font-weight: bold;' . PHP_EOL .
  129.                         '                       }' . PHP_EOL .
  130.                         '                       .content .block table tbody tr td {' . PHP_EOL .
  131.                         '                               margin: 0;' . PHP_EOL .
  132.                         '                               padding: 3px 7px;' . PHP_EOL .
  133.                         '                       }' . PHP_EOL .
  134.                         '                       .content .block table tbody tr:nth-child(odd) td {' . PHP_EOL .
  135.                         '                               padding: 14px 7px 5px;' . PHP_EOL .
  136.                         '                       }' . PHP_EOL .
  137.                         '                       .content .block table tbody tr:nth-child(even) td {' . PHP_EOL .
  138.                         '                               background-color: #f1f1f1;' . PHP_EOL .
  139.                         '                               border: 1px dashed #cccccc;' . PHP_EOL .
  140.                         '                       }' . PHP_EOL .
  141.                         '                       #footer {' . PHP_EOL .
  142.                         '                               margin: 6px 40px;' . PHP_EOL .
  143.                         '                               font-size: 11px;' . PHP_EOL .
  144.                         '                               color: #909090;' . PHP_EOL .
  145.                         '                       }' . PHP_EOL .
  146.                         '                       #footer p {' . PHP_EOL .
  147.                         '                               margin: 0;' . PHP_EOL .
  148.                         '                               padding: 0;' . PHP_EOL .
  149.                         '                       }' . PHP_EOL .
  150.                         '               </style>' . PHP_EOL .
  151.                         '       </head>' . PHP_EOL .
  152.                         '       <body>' . PHP_EOL .
  153.                         '               <div id="wrapper">' . PHP_EOL .
  154.                         '                       <h1>A fatal error has occured.</h1>' . PHP_EOL .
  155.                         '                       <div class="content">' . PHP_EOL .
  156.                         '                               <div class="block">' . PHP_EOL .
  157.                         '                                       <p>' . nl2br($message) . '</p>' . PHP_EOL .
  158.                         '                               </div>' . PHP_EOL .
  159.                         '                       </div>' . PHP_EOL
  160.                 );
  161.                
  162.                 if(DEBUG)
  163.                 {
  164.                         global $arictos;
  165.                        
  166.                         $bt = ($exception ? arictos_debug_backtrace($e) : arictos_debug_backtrace());
  167.                                                
  168.                         if(sizeof($bt))
  169.                         {
  170.                                 echo(
  171.                                         '                       <h1>Debug backtrace</h1>' . PHP_EOL .
  172.                                         '                       <div class="content">' . PHP_EOL .
  173.                                         '                               <div class="block">' . PHP_EOL .  
  174.                                         '                                       <table width="100%" cellspacing="0" cellpadding="0">' . PHP_EOL .
  175.                                         '                                               <thead>' . PHP_EOL .
  176.                                         '                                                       <tr>' . PHP_EOL .
  177.                                         '                                                               <td width="15px">&nbsp;</td>' . PHP_EOL .
  178.                                         '                                                               <td>Call</td>' . PHP_EOL .
  179.                                         '                                                               <td>File</td>' . PHP_EOL .
  180.                                         '                                                               <td>Line</td>' . PHP_EOL .
  181.                                         '                                                               <td>Notes</td>' . PHP_EOL .
  182.                                         '                                                       </tr>' . PHP_EOL .
  183.                                         '                                               </thead>' . PHP_EOL .
  184.                                         '                                               <tbody>' . PHP_EOL
  185.                                 );
  186.                                
  187.                                 foreach($bt as $n=> $trace)
  188.                                 {
  189.                                         echo(
  190.                                         '                                                       <tr>' . PHP_EOL .
  191.                                         '                                                               <td rowspan="2">' . ++$n . '</td>' . PHP_EOL .
  192.                                         '                                                               <td>' . $trace->call . '</td>' . PHP_EOL .
  193.                                         '                                                               <td>' . $trace->file . '</td>' . PHP_EOL .
  194.                                         '                                                               <td>' . $trace->line . '</td>' . PHP_EOL .
  195.                                         '                                                               <td>' . $trace->notes . '</td>' . PHP_EOL .
  196.                                         '                                                       </tr>' . PHP_EOL
  197.                                         );
  198.                                        
  199.                                         if(!empty($trace->callargs))
  200.                                         {
  201.                                                 echo(
  202.                                                         '                                                       <tr>' . PHP_EOL .
  203.                                                         '                                                               <td colspan="4">' . $trace->callargs . '</td>' . PHP_EOL .
  204.                                                         '                                                       </tr> ' . PHP_EOL
  205.                                                 );
  206.                                         }
  207.                                 }
  208.                                
  209.                                 echo(
  210.                                         '                                               </tbody>' . PHP_EOL .
  211.                                         '                                       </table>' . PHP_EOL .
  212.                                         '                               </div>' . PHP_EOL .
  213.                                         '                       </div>' . PHP_EOL
  214.                                 );
  215.                         }
  216.                 }
  217.                
  218.                 echo(
  219.                         '                       <div id="footer">' . PHP_EOL .
  220.                         '                               <p>Generated by ' . ($application ? $application . ' (' : '') . 'Arictos ' . Arictos::VERSION_STRING . ($application ? ')' : '') . ' on ' . TIMENOW_UTC . ' (UTC)</p>' . PHP_EOL .
  221.                         '                       </div>  ' . PHP_EOL .
  222.                         '               </div>' . PHP_EOL .
  223.                         '       </body>' . PHP_EOL .
  224.                         '</html>' . PHP_EOL
  225.                 );
  226.                
  227.                 exit;
  228.         }
  229.  
  230. ?>