includes/functions.php
changeset 798 ddfc1b554a08
parent 770 62fed244fa1c
child 800 9cdfe82c56cd
equal deleted inserted replaced
797:8d2a40574bbc 798:ddfc1b554a08
  3252           (empty($comment) ? "" : $comment . "\0") .
  3252           (empty($comment) ? "" : $comment . "\0") .
  3253           gzdeflate($data, $level) .
  3253           gzdeflate($data, $level) .
  3254           pack("VV", crc32($data), strlen($data)));
  3254           pack("VV", crc32($data), strlen($data)));
  3255 }
  3255 }
  3256 
  3256 
       
  3257 $php_errors = array();
       
  3258 
       
  3259 /**
       
  3260  * Enano's PHP error handler.
       
  3261  * handler  ( int $errno  , string $errstr  [, string $errfile  [, int $errline  [, array $errcontext  ]]] )
       
  3262  * @access private
       
  3263  */
       
  3264 
       
  3265 function enano_handle_error($errno, $errstr, $errfile, $errline)
       
  3266 {
       
  3267   global $db, $session, $paths, $template, $plugins; // Common objects
       
  3268   
       
  3269   $er = error_reporting();
       
  3270   if ( ! $er & $errno || $er == 0 )
       
  3271   {
       
  3272     return true;
       
  3273   }
       
  3274   global $do_gzip, $php_errors;
       
  3275   
       
  3276   if ( defined('ENANO_DEBUG') )
       
  3277   {
       
  3278     // turn off gzip and echo out error immediately for debug installs
       
  3279     $do_gzip = false;
       
  3280   }
       
  3281   
       
  3282   $error_type = 'error';
       
  3283   if ( in_array($errno, array(E_WARNING, E_USER_WARNING)) )
       
  3284     $error_type = 'warning';
       
  3285   else if ( in_array($errno, array(E_NOTICE, E_USER_NOTICE)) )
       
  3286     $error_type = 'notice';
       
  3287   
       
  3288   if ( @is_object(@$plugins) )
       
  3289   {
       
  3290     $code = $plugins->setHook('php_error');
       
  3291     foreach ( $code as $cmd )
       
  3292     {
       
  3293       eval($cmd);
       
  3294     }
       
  3295   }
       
  3296   
       
  3297   // bypass errors in date() and mktime() (Enano has its own code for this anyway)
       
  3298   if ( strstr($errstr, "It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.") )
       
  3299   {
       
  3300     return true;
       
  3301   }
       
  3302   
       
  3303   if ( $do_gzip )
       
  3304   {
       
  3305     $php_errors[] = array(
       
  3306         'num' => $errno,
       
  3307         'type' => $error_type,
       
  3308         'error' => $errstr,
       
  3309         'file' => $errfile,
       
  3310         'line' => $errline
       
  3311       );
       
  3312   }
       
  3313   else
       
  3314   {
       
  3315     echo "[ <b>PHP $error_type:</b> $errstr in <b>$errfile</b>:<b>$errline</b> ]<br />";
       
  3316   }
       
  3317 }
       
  3318 
       
  3319 set_error_handler('enano_handle_error');
       
  3320 
  3257 /**
  3321 /**
  3258  * Gzips the output buffer.
  3322  * Gzips the output buffer.
  3259  */
  3323  */
  3260 
  3324 
  3261 function gzip_output()
  3325 function gzip_output()
  3268   //
  3332   //
  3269   if ( $do_gzip && function_exists('gzdeflate') && !strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && !headers_sent() )
  3333   if ( $do_gzip && function_exists('gzdeflate') && !strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && !headers_sent() )
  3270   {
  3334   {
  3271     $gzip_contents = ob_get_contents();
  3335     $gzip_contents = ob_get_contents();
  3272     ob_end_clean();
  3336     ob_end_clean();
       
  3337     
       
  3338     global $php_errors;
       
  3339     if ( !empty($php_errors) )
       
  3340     {
       
  3341       $errors = '';
       
  3342       foreach ( $php_errors as $error )
       
  3343       {
       
  3344         $errors .= "[ <b>PHP {$error['type']}:</b> {$error['error']} in <b>{$error['file']}</b>:<b>{$error['line']}</b> ]<br />";
       
  3345       }
       
  3346       $gzip_contents = str_replace("</body>", "$errors</body>", $gzip_contents);
       
  3347     }
  3273     
  3348     
  3274     $return = @enano_gzencode($gzip_contents);
  3349     $return = @enano_gzencode($gzip_contents);
  3275     if ( $return )
  3350     if ( $return )
  3276     {
  3351     {
  3277       header('Content-encoding: gzip');
  3352       header('Content-encoding: gzip');