Merging Nighthawk and Scribus branches
authorDan
Mon, 18 Feb 2008 16:14:22 -0500
changeset 427 e7ad98914d06
parent 425 fa51b1b5eae6 (diff)
parent 426 f5718d7c2a6a (current diff)
child 428 921bae9104b0
Merging Nighthawk and Scribus branches
--- a/includes/dbal.php	Sun Feb 17 20:19:17 2008 -0500
+++ b/includes/dbal.php	Mon Feb 18 16:14:22 2008 -0500
@@ -41,6 +41,8 @@
   
   function enable_errorhandler()
   {
+    if ( !defined('ENANO_DEBUG') )
+      return true;
     // echo "DBAL: enabling error handler<br />";
     if ( function_exists('debug_backtrace') )
     {
@@ -50,6 +52,8 @@
   
   function disable_errorhandler()
   {
+    if ( !defined('ENANO_DEBUG') )
+      return true;
     // echo "DBAL: disabling error handler<br />";
     if ( $this->errhandler )
     {
@@ -210,9 +214,10 @@
     return true;
   }
   
-  function sql_query($q)
+  function sql_query($q, $log_query = true)
   {
-    $this->enable_errorhandler();
+    if ( $log_query || defined('ENANO_DEBUG') )
+      $this->enable_errorhandler();
     
     if ( $this->debug && function_exists('debug_backtrace') )
     {
@@ -233,34 +238,48 @@
     }
     
     $this->num_queries++;
-    $this->query_backtrace[] = $q;
-    $this->latest_query = $q;
+    if ( $log_query || defined('ENANO_DEBUG') )
+    {
+      $this->query_backtrace[] = $q;
+      $this->latest_query = $q;
+    }
     // First make sure we have a connection
     if ( !$this->_conn )
     {
       $this->_die('A database connection has not yet been established.');
     }
+    // Start the timer
+    if ( $log_query || defined('ENANO_DEBUG') )
+      $time_start = microtime_float();
     // Does this query look malicious?
-    if ( !$this->check_query($q) )
+    if ( $log_query || defined('ENANO_DEBUG') )
     {
-      $this->report_query($q);
-      grinding_halt('SQL Injection attempt', '<p>Enano has caught and prevented an SQL injection attempt. Your IP address has been recorded and the administrator has been notified.</p><p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>');
+      if ( !$this->check_query($q) )
+      {
+        $this->report_query($q);
+        grinding_halt('SQL Injection attempt', '<p>Enano has caught and prevented an SQL injection attempt. Your IP address has been recorded and the administrator has been notified.</p><p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>');
+      }
     }
     
-    $time_start = microtime_float();
     $r = mysql_query($q, $this->_conn);
-    $this->query_times[$q] = microtime_float() - $time_start;
+    
+    if ( $log_query )
+      $this->query_times[$q] = microtime_float() - $time_start;
+    
     $this->latest_result = $r;
-    $this->disable_errorhandler();
+    
+    if ( $log_query )
+      $this->disable_errorhandler();
     return $r;
   }
   
-  function sql_unbuffered_query($q)
+  function sql_unbuffered_query($q, $log_query = true)
   {
     $this->enable_errorhandler();
     
     $this->num_queries++;
-    $this->query_backtrace[] = '(UNBUFFERED) ' . $q;
+    if ( $log_query || defined('ENANO_DEBUG') )
+      $this->query_backtrace[] = '(UNBUFFERED) ' . $q;
     $this->latest_query = $q;
     // First make sure we have a connection
     if ( !$this->_conn )
--- a/includes/functions.php	Sun Feb 17 20:19:17 2008 -0500
+++ b/includes/functions.php	Mon Feb 18 16:14:22 2008 -0500
@@ -4024,8 +4024,13 @@
   $_profiler[] = array(
       'point' => 'Profiling started',
       'time' => microtime_float(),
-      'backtrace' => false
+      'backtrace' => false,
+      'mem' => false
     );
+  if ( function_exists('memory_get_usage') )
+  {
+    $_profiler[ count($_profiler) - 1 ]['mem'] = memory_get_usage();
+  }
 }
 
 /**
@@ -4048,8 +4053,13 @@
   $_profiler[] = array(
       'point' => $point,
       'time' => microtime_float(),
-      'backtrace' => $backtrace
+      'backtrace' => $backtrace,
+      'mem' => false
     );
+  if ( function_exists('memory_get_usage') )
+  {
+    $_profiler[ count($_profiler) - 1 ]['mem'] = memory_get_usage();
+  }
 }
 
 /**
@@ -4114,6 +4124,14 @@
       $html .= '</tr>' . "\n";
     }
     
+    if ( $entry['mem'] )
+    {
+      $html .= '<tr>' . "\n";
+      $html .= '  <td class="row2">Total mem usage:</td>' . "\n";
+      $html .= '  <td class="row1">' . htmlspecialchars($entry['mem']) . ' (bytes)</td>' . "\n";
+      $html .= '</tr>' . "\n";
+    }
+    
     $html .= "\n";
     
     $time_last = $entry['time'];
--- a/includes/sessions.php	Sun Feb 17 20:19:17 2008 -0500
+++ b/includes/sessions.php	Mon Feb 18 16:14:22 2008 -0500
@@ -1624,7 +1624,7 @@
       {
         while ( list($reason_temp, $ban_value, $ban_type, $is_regex) = $db->fetchrow_num() )
         {
-          if ( $ban_type == BAN_IP && $row['is_regex'] != 1 )
+          if ( $ban_type == BAN_IP && $is_regex != 1 )
           {
             // check range
             $regexp = parse_ip_range_regex($ban_value);