# HG changeset patch
# User Dan
# Date 1230730838 18000
# Node ID ddfc1b554a08d5ba9764ec1b506d9e0eeb48df59
# Parent 8d2a40574bbcbd8e3f6202355cd5571b4479e22b
Redid error handler (it was causing some problems with gzip enabled)
diff -r 8d2a40574bbc -r ddfc1b554a08 includes/clientside/jsres.php
--- a/includes/clientside/jsres.php Wed Dec 24 10:04:48 2008 -0500
+++ b/includes/clientside/jsres.php Wed Dec 31 08:40:38 2008 -0500
@@ -255,7 +255,7 @@
}
// generate expires header
-$expires = date('r', mktime(-1, -1, -1, -1, -1, intval(date('y'))+1));
+$expires = date('r', mktime(0, 0, 0, intval(date('m')), intval(date('d')), intval(date('y'))+1));
$everything = str_replace('/* JavaScriptCompressor 0.8 [www.devpro.it], thanks to Dean Edwards for idea [dean.edwards.name] */' . "\r\n", '', $everything);
@@ -270,6 +270,7 @@
header("Last-Modified: $date");
header("ETag: \"$etag\"");
header("Expires: $expires");
+header("Content-Length: " . strlen($everything));
$local_end = microtime_float();
$local_gentime = $local_end - $local_start;
diff -r 8d2a40574bbc -r ddfc1b554a08 includes/dbal.php
--- a/includes/dbal.php Wed Dec 24 10:04:48 2008 -0500
+++ b/includes/dbal.php Wed Dec 31 08:40:38 2008 -0500
@@ -132,8 +132,6 @@
function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false)
{
- $this->enable_errorhandler();
-
if ( !defined('ENANO_SQL_CONSTANTS') )
{
define('ENANO_SQL_CONSTANTS', '');
@@ -220,15 +218,11 @@
}
// We're in!
- $this->disable_errorhandler();
return true;
}
function sql_query($q, $log_query = true)
{
- if ( $log_query || defined('ENANO_DEBUG') )
- $this->enable_errorhandler();
-
if ( $this->debug && function_exists('debug_backtrace') )
{
$backtrace = @debug_backtrace();
@@ -279,15 +273,11 @@
$this->latest_result = $r;
- if ( $log_query )
- $this->disable_errorhandler();
return $r;
}
function sql_unbuffered_query($q, $log_query = true)
{
- $this->enable_errorhandler();
-
$this->num_queries++;
if ( $log_query || defined('ENANO_DEBUG') )
$this->query_backtrace[] = '(UNBUFFERED) ' . $q;
@@ -309,7 +299,6 @@
$r = @mysql_unbuffered_query($q, $this->_conn);
$this->query_times[$q] = microtime_float() - $time_start;
$this->latest_result = $r;
- $this->disable_errorhandler();
return $r;
}
@@ -366,22 +355,18 @@
function sql_data_seek($pos, $result = false)
{
- $this->enable_errorhandler();
if(!$result)
$result = $this->latest_result;
if(!$result)
{
- $this->disable_errorhandler();
return false;
}
if(mysql_data_seek($result, $pos))
{
- $this->disable_errorhandler();
return true;
}
else
{
- $this->disable_errorhandler();
return false;
}
}
@@ -415,53 +400,42 @@
}
function fetchrow($r = false) {
- $this->enable_errorhandler();
if(!$this->_conn) return false;
if(!$r) $r = $this->latest_result;
if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
$row = mysql_fetch_assoc($r);
- $this->disable_errorhandler();
return integerize_array($row);
}
function fetchrow_num($r = false) {
- $this->enable_errorhandler();
if(!$r) $r = $this->latest_result;
if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
$row = mysql_fetch_row($r);
- $this->disable_errorhandler();
return integerize_array($row);
}
function numrows($r = false) {
- $this->enable_errorhandler();
if(!$r) $r = $this->latest_result;
if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
$n = mysql_num_rows($r);
- $this->disable_errorhandler();
return $n;
}
function escape($str)
{
- $this->enable_errorhandler();
$str = mysql_real_escape_string($str);
- $this->disable_errorhandler();
return $str;
}
function free_result($result = false)
{
- $this->enable_errorhandler();
if(!$result)
$result = $this->latest_result;
if(!$result)
{
- $this->disable_errorhandler();
return null;
}
@mysql_free_result($result);
- $this->disable_errorhandler();
return null;
}
@@ -798,28 +772,6 @@
var $rowset = array();
var $errhandler;
- function enable_errorhandler()
- {
- // echo "DBAL: enabling error handler
";
- if ( function_exists('debug_backtrace') )
- {
- $this->errhandler = set_error_handler('db_error_handler');
- }
- }
-
- function disable_errorhandler()
- {
- // echo "DBAL: disabling error handler
";
- if ( $this->errhandler )
- {
- set_error_handler($this->errhandler);
- }
- else
- {
- restore_error_handler();
- }
- }
-
function sql_backtrace()
{
return implode("\n-------------------------------------------------------------------\n", $this->query_backtrace);
@@ -881,8 +833,6 @@
function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false)
{
- $this->enable_errorhandler();
-
if ( !defined('ENANO_SQL_CONSTANTS') )
{
define('ENANO_SQL_CONSTANTS', '');
@@ -954,14 +904,11 @@
$this->debug = ( defined('ENANO_DEBUG') );
// We're in!
- $this->disable_errorhandler();
return true;
}
function sql_query($q)
{
- $this->enable_errorhandler();
-
if ( $this->debug && function_exists('debug_backtrace') )
{
$backtrace = @debug_backtrace();
@@ -999,7 +946,6 @@
$r = pg_query($q);
$this->query_times[$q] = microtime_float() - $time_start;
$this->latest_result = $r;
- $this->disable_errorhandler();
return $r;
}
@@ -1061,22 +1007,18 @@
function sql_data_seek($pos, $result = false)
{
- $this->enable_errorhandler();
if(!$result)
$result = $this->latest_result;
if(!$result)
{
- $this->disable_errorhandler();
return false;
}
if(pg_result_seek($result, $pos))
{
- $this->disable_errorhandler();
return true;
}
else
{
- $this->disable_errorhandler();
return false;
}
}
@@ -1159,53 +1101,42 @@
}
function fetchrow($r = false) {
- $this->enable_errorhandler();
if(!$this->_conn) return false;
if(!$r) $r = $this->latest_result;
if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
$row = pg_fetch_assoc($r);
- $this->disable_errorhandler();
return integerize_array($row);
}
function fetchrow_num($r = false) {
- $this->enable_errorhandler();
if(!$r) $r = $this->latest_result;
if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
$row = pg_fetch_row($r);
- $this->disable_errorhandler();
return integerize_array($row);
}
function numrows($r = false) {
- $this->enable_errorhandler();
if(!$r) $r = $this->latest_result;
if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
$n = pg_num_rows($r);
- $this->disable_errorhandler();
return $n;
}
function escape($str)
{
- $this->enable_errorhandler();
$str = pg_escape_string($str);
- $this->disable_errorhandler();
return $str;
}
function free_result($result = false)
{
- $this->enable_errorhandler();
if(!$result)
$result = $this->latest_result;
if(!$result)
{
- $this->disable_errorhandler();
return null;
}
@pg_free_result($result);
- $this->disable_errorhandler();
return null;
}
diff -r 8d2a40574bbc -r ddfc1b554a08 includes/functions.php
--- a/includes/functions.php Wed Dec 24 10:04:48 2008 -0500
+++ b/includes/functions.php Wed Dec 31 08:40:38 2008 -0500
@@ -3254,6 +3254,70 @@
pack("VV", crc32($data), strlen($data)));
}
+$php_errors = array();
+
+/**
+ * Enano's PHP error handler.
+ * handler ( int $errno , string $errstr [, string $errfile [, int $errline [, array $errcontext ]]] )
+ * @access private
+ */
+
+function enano_handle_error($errno, $errstr, $errfile, $errline)
+{
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ $er = error_reporting();
+ if ( ! $er & $errno || $er == 0 )
+ {
+ return true;
+ }
+ global $do_gzip, $php_errors;
+
+ if ( defined('ENANO_DEBUG') )
+ {
+ // turn off gzip and echo out error immediately for debug installs
+ $do_gzip = false;
+ }
+
+ $error_type = 'error';
+ if ( in_array($errno, array(E_WARNING, E_USER_WARNING)) )
+ $error_type = 'warning';
+ else if ( in_array($errno, array(E_NOTICE, E_USER_NOTICE)) )
+ $error_type = 'notice';
+
+ if ( @is_object(@$plugins) )
+ {
+ $code = $plugins->setHook('php_error');
+ foreach ( $code as $cmd )
+ {
+ eval($cmd);
+ }
+ }
+
+ // bypass errors in date() and mktime() (Enano has its own code for this anyway)
+ 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.") )
+ {
+ return true;
+ }
+
+ if ( $do_gzip )
+ {
+ $php_errors[] = array(
+ 'num' => $errno,
+ 'type' => $error_type,
+ 'error' => $errstr,
+ 'file' => $errfile,
+ 'line' => $errline
+ );
+ }
+ else
+ {
+ echo "[ PHP $error_type: $errstr in $errfile:$errline ]
";
+ }
+}
+
+set_error_handler('enano_handle_error');
+
/**
* Gzips the output buffer.
*/
@@ -3271,6 +3335,17 @@
$gzip_contents = ob_get_contents();
ob_end_clean();
+ global $php_errors;
+ if ( !empty($php_errors) )
+ {
+ $errors = '';
+ foreach ( $php_errors as $error )
+ {
+ $errors .= "[ PHP {$error['type']}: {$error['error']} in {$error['file']}:{$error['line']} ]
";
+ }
+ $gzip_contents = str_replace("