[geeklog-cvs] geeklog: recommended changes

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Tue Jan 26 15:53:53 EST 2010


changeset 7646:632cf4a1c40a
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/632cf4a1c40a
user: stan <yankees26an at gmail.com>
date: Thu Aug 13 17:24:26 2009 -0400
description:
recommended changes

diffstat:

 public_html/admin/sectest.php     |   2 -
 public_html/index.php             |   9 +++-
 system/classes/template.class.php |  15 +++----
 system/databases/mssql.class.php  |   4 +-
 system/databases/mysql.class.php  |   2 +-
 system/databases/pgsql.class.php  |  55 +++++++++++----------------
 system/lib-database.php           |  31 +++------------
 system/lib-plugins.php            |  29 +++++++++-----
 system/lib-sessions.php           |   2 +-
 system/lib-syndication.php        |   2 +-
 10 files changed, 64 insertions(+), 87 deletions(-)

diffs (truncated from 384 to 300 lines):

diff -r 4631b645ed06 -r 632cf4a1c40a public_html/admin/sectest.php
--- a/public_html/admin/sectest.php	Fri Aug 07 12:35:33 2009 -0400
+++ b/public_html/admin/sectest.php	Thu Aug 13 17:24:26 2009 -0400
@@ -369,12 +369,10 @@
     $display .= '<p class="warningsmall"><strong>'
              . $LANG_SECTEST['please_fix'] . '</strong></p>';
 
-    //DB_save($_TABLES['vars'], 'name,value', "'security_check','0'");
     DB_query("UPDATE {$_TABLES['vars']} SET name='security_check', value ='0'");
 } else {
     $display .= '<p>' . $LANG_SECTEST['please_note'] . '</p>';
 
-    //DB_save($_TABLES['vars'], 'name,value', "'security_check','1'");
     DB_query("UPDATE {$_TABLES['vars']} SET name='security_check', value ='1'");
 
 }
diff -r 4631b645ed06 -r 632cf4a1c40a public_html/index.php
--- a/public_html/index.php	Fri Aug 07 12:35:33 2009 -0400
+++ b/public_html/index.php	Thu Aug 13 17:24:26 2009 -0400
@@ -260,7 +260,12 @@
 $sql .= COM_getTopicSQL ('AND', 0, 's') . ' ';
 
 if ($newstories) {
-    $sql .= "AND (date >= (date_sub(NOW(), INTERVAL {$_CONF['newstoriesinterval']} SECOND))) ";
+    
+    $sql['mysql'] .= "AND (date >= (date_sub(NOW(), INTERVAL {$_CONF['newstoriesinterval']} SECOND))) ";
+    $sql['pgsql'] .= "AND (date >= (NOW(), INTERVAL '{$_CONF['newstoriesinterval']} SECOND')) ";
+    $sql['pgsql'] .= "AND (date >= (date_sub(NOW(), INTERVAL {$_CONF['newstoriesinterval']} SECOND))) ";
+
+
 }
 
 $offset = ($page - 1) * $limit;
@@ -303,7 +308,6 @@
 $num_pages = ceil ($D['count'] / $limit);
 
 if ( $A = DB_fetchArray( $result ) ) {
-    $varme= 'inside fetcha rray';
     $story = new Story();
     $story->loadFromArray($A);
     if ( $_CONF['showfirstasfeatured'] == 1 ) {
@@ -342,7 +346,6 @@
         $display .= COM_printPageNavigation ($base_url, $page, $num_pages);
     }
 } else { // no stories to display
-    $varme = 'not in fetch array!';
     if (!isset ($_CONF['hide_no_news_msg']) ||
             ($_CONF['hide_no_news_msg'] == 0)) {
         $display .= COM_startBlock ($LANG05[1], '',
diff -r 4631b645ed06 -r 632cf4a1c40a system/classes/template.class.php
--- a/system/classes/template.class.php	Fri Aug 07 12:35:33 2009 -0400
+++ b/system/classes/template.class.php	Thu Aug 13 17:24:26 2009 -0400
@@ -82,7 +82,7 @@
   * @var       int
   * @access    public
   */
-  var $debug    = 4;
+  var $debug    = false;
 
  /**
   * The base directory from which template files are loaded.
@@ -91,7 +91,7 @@
   * @access    private
   * @see       set_root
   */
-  var $root     = '';
+  var $root     = '.';
 
  /**
   * A hash of strings forming a translation table which translates variable names
@@ -159,8 +159,7 @@
   * @access    public
   * @return    void
   */
-  function Template($root='.', $unknowns = 'remove') {
- 
+  function Template($root = '.', $unknowns = 'remove') {
     if ($this->debug & 4) {
       echo "<p><b>Template:</b> root = $root, unknowns = $unknowns</p>\n";
     }
@@ -474,10 +473,10 @@
       return false;
     }
     
-    $varkeys = array_map(
-        create_function('$a', 'return "{" . $a . "}";'),
-        array_keys($this->varvals)
-    );
+	$varkeys = array_map(
+		create_function('$a', 'return "{" . $a . "}";'),
+		array_keys($this->varvals)
+	);
     $str = $this->get_var($varname);
     $str = str_replace($varkeys, array_values($this->varvals), $str);
     return $str;
diff -r 4631b645ed06 -r 632cf4a1c40a system/databases/mssql.class.php
--- a/system/databases/mssql.class.php	Fri Aug 07 12:35:33 2009 -0400
+++ b/system/databases/mssql.class.php	Thu Aug 13 17:24:26 2009 -0400
@@ -616,7 +616,7 @@
                 }
             } else {
                 // error, they both have to be arrays and of the
-                // same size
+                // same size 
                 return false;
             }
         } else {
@@ -964,7 +964,7 @@
     * your code should ALWAYS call this function with its resource identifier otherwise you'll just pull off the 
     * last insertted ID which MAY or MAY NOT be the one from YOUR specific insert.  You've been warned!
     */
-    function dbInsertId($link_identifier ='')
+    function dbInsertId($link_identifier ='',$sequence='')
     {
      
        if ($link_identifier ==''){  //wow is this dangerous...  
diff -r 4631b645ed06 -r 632cf4a1c40a system/databases/mysql.class.php
--- a/system/databases/mysql.class.php	Fri Aug 07 12:35:33 2009 -0400
+++ b/system/databases/mysql.class.php	Thu Aug 13 17:24:26 2009 -0400
@@ -668,7 +668,7 @@
     * @return   int                             Returns last auto-generated ID
     *
     */
-    function dbInsertId($link_identifier = '')
+    function dbInsertId($link_identifier = '',$sequence='')
     {
         if (empty($link_identifier)) {
             return @mysql_insert_id();
diff -r 4631b645ed06 -r 632cf4a1c40a system/databases/pgsql.class.php
--- a/system/databases/pgsql.class.php	Fri Aug 07 12:35:33 2009 -0400
+++ b/system/databases/pgsql.class.php	Thu Aug 13 17:24:26 2009 -0400
@@ -151,11 +151,9 @@
             }
         }
 
-        if ($this->_pgsql_version >= 7.4) {
-            if ($this->_charset == 'utf-8') {
-                pg_query($this->_db,"SET NAMES 'UTF8'"); //only pgsql > 7.4 supports utf8
-            }
-        }
+         if ($this->_pgsql_version >= 7.4 && $this->_charset == 'utf-8') {
+                    pg_query($this->_db,"SET NAMES 'UTF8'");
+                }
 
         if ($this->isVerbose()) {
             $this->_errorlog("\n***leaving database->_connect***");
@@ -338,20 +336,17 @@
     */
     function dbQuery($sql,$ignore_errors=0)
     {
-        if ($this->isVerbose()) {
+        //if ($this->isVerbose()) {
             $this->_errorlog("\n***inside database->dbQuery***");
             $this->_errorlog("\n*** sql to execute is $sql ***");
-        }
+        //}
         /* Replace some non ANSI keywords */
         if(preg_match('#LIMIT ([0-9]+),([\\s])?([0-9]+)#',$sql,$matches))
         {
             $sql = str_replace($matches[0],'LIMIT '.$matches[3].' OFFSET '.$matches[1],$sql); 
-            echo $sql;    
         }
         // Run query
         if ($ignore_errors == 1) {
-            echo $sql;
-                    print_r(debug_backtrace());
 
             $result = pg_query($this->_db,$sql);
         } else {
@@ -473,8 +468,8 @@
                     next($value);
                 }
             } else {
-                // error, they both have to be arrays and of the
-                // same size
+                // error, they both have to be arrays and of the same size
+                COM_errorLog("The columns ($id) do not match the value count ($value)"); 
                 return false;
             }
         } else {
@@ -665,11 +660,11 @@
     {
         if(!empty($sequence))
         {
-            $result = pg_query('SELECT NEXTVAL(\''.$sequence.'\'); ');    
+            $result = pg_query('SELECT CURRVAL(\''.$sequence.'\'); ');    
         }
         else
         {
-            $result = pg_query('SELECT lastval();');    
+            $result = pg_query('SELECT LASTVAL();');    
         }
         $row = pg_fetch_row($result);
         unset($result);
@@ -766,27 +761,21 @@
         $result = pg_get_result($this->_db);
         if($this->_pgsql_version>=7.4)
         {
-          if(pg_result_error_field($result,PGSQL_DIAG_SOURCE_LINE))
-          {
+            if(pg_result_error_field($result,PGSQL_DIAG_SOURCE_LINE)) //this provides a much more detailed error report
+            {
               $this->_errorlog('You have an error in your SQL query on line'.pg_result_error_field($result,PGSQL_DIAG_SOURCE_LINE)."<br/> SQL in question: $sql");
-             return('Error:'.pg_result_error_field($result,PGSQL_DIAG_SQLSTATE).'<br/>Description:'.pg_result_error_field($result,PGSQL_DIAG_MESSAGE_DETAIL));
-          }
-          return;  
+             $error = 'Error:'.pg_result_error_field($result,PGSQL_DIAG_SQLSTATE).'<br/>Description:'.pg_result_error_field($result,PGSQL_DIAG_MESSAGE_DETAIL);
+            }
+            else {$error = "An SQL error has occurred in the following SQL : $sql.";}
         }
-        else
-        {
-        if (pg_result_error($result)) {
-            $this->_errorlog(pg_result_error($result) . ". SQL in question: $sql");        
-            if ($this->_display_error) 
-            {
-                return  'Error'.pg_result_error($result);
-            } else
-             {
-                return 'An SQL error has occurred. Please see error.log for details.';
-             }
-        }
-  
-        return;
+         else
+         {
+            if (pg_result_error($result)) {
+                $this->_errorlog(pg_result_error($result) . ". SQL in question: $sql");        
+                if ($this->_display_error) {$error = 'Error'.pg_result_error($result);} 
+                else{$error = "An SQL error has occurred in the following SQL : $sql.";}
+            }
+        return $error;
         }
     }
     
diff -r 4631b645ed06 -r 632cf4a1c40a system/lib-database.php
--- a/system/lib-database.php	Fri Aug 07 12:35:33 2009 -0400
+++ b/system/lib-database.php	Thu Aug 13 17:24:26 2009 -0400
@@ -265,32 +265,13 @@
 */
 function DB_getItem($table,$what,$selection='')
 {
-    global $_DB_dbms;
-    if($_DB_dbms=='mysql')
-    {
-        if (!empty($selection)) {
-            $result = DB_query("SELECT $what FROM $table WHERE $selection");
-        } else {
-            $result = DB_query("SELECT $what FROM $table");
-        }
-        $ITEM = DB_fetchArray($result, true);
-        return $ITEM[0];
+    if (!empty($selection)) {
+        $result = DB_query("SELECT $what FROM $table WHERE $selection");
+    } else {
+        $result = DB_query("SELECT $what FROM $table");
     }
-    elseif($_DB_dbms=='pgsql')
-    {
-        $result = DB_query("SELECT check_table('$table', 'public');");
-        $row=DB_fetchArray($result);
-        if(!empty($row[0]))
-        {     //table exists
-             if(!empty($selection)) {$result = DB_query("SELECT $what FROM $table WHERE $selection");}
-             else {$result = DB_query("SELECT $what FROM $table");}
-             
-             $ITEM = DB_fetchArray($result, true);
-             return $ITEM[0];   
-        }
-    }
-    else{ COM_errorLog ('Unknown DB selected', 3);}
-    
+    $ITEM = DB_fetchArray($result, true);
+    return $ITEM[0];
 }
 
 /**
diff -r 4631b645ed06 -r 632cf4a1c40a system/lib-plugins.php
--- a/system/lib-plugins.php	Fri Aug 07 12:35:33 2009 -0400
+++ b/system/lib-plugins.php	Thu Aug 13 17:24:26 2009 -0400
@@ -242,21 +242,26 @@
         }
 
         // removing tables
-        for ($i=0; $i < count($remvars['tables']); $i++) {
-            COM_errorLog ("Dropping table {$_TABLES[$remvars['tables'][$i]]}", 1);
-            DB_query ("DROP TABLE {$_TABLES[$remvars['tables'][$i]]}", 1    );
-            COM_errorLog ('...success', 1);
+        $num_tables = count($remvars['tables']);
+        for ($i = 0; $i < $num_tables; $i++) {
+            if (isset($_TABLES[$remvars['tables'][$i]])) {
+                COM_errorLog("Dropping table {$_TABLES[$remvars['tables'][$i]]}", 1);
+                DB_query("DROP TABLE {$_TABLES[$remvars['tables'][$i]]}", 1);
+                COM_errorLog('...success', 1);
+            }
         }
 
         // removing variables
-        for ($i = 0; $i < count($remvars['vars']); $i++) {
+        $num_vars = count($remvars['vars']);



More information about the geeklog-cvs mailing list