OSDN Git Service

FIX:MANAGER::instance()をstaticに
[nucleus-jp/nucleus-next.git] / nucleus / libs / ACTIONLOG.php
index cac2c53..02544ce 100644 (file)
@@ -14,7 +14,7 @@
  *
  * @license http://nucleuscms.org/license.txt GNU General Public License
  * @copyright Copyright (C) 2002-2009 The Nucleus Group
- * @version $Id: ACTIONLOG.php 1470 2010-11-29 22:10:16Z ftruscot $
+ * @version $Id: ACTIONLOG.php 1822 2012-05-04 13:47:22Z sakamocchi $
  */
 define('ERROR',1);             // only errors
 define('WARNING',2);   // errors and warnings
@@ -22,10 +22,10 @@ define('INFO',3);           // info, errors and warnings
 define('DEBUG',4);             // everything
 $CONF['LogLevel'] = INFO;
 
-class ACTIONLOG
+class ActionLog
 {
        /**
-        * ACTIONLOG::add()
+        * ActionLog::add()
         * Method to add a message to the action log
         * 
         * @static
@@ -48,11 +48,9 @@ class ACTIONLOG
                        $message = "[" . $member->getDisplayName() . "] " . $message;
                }
                
-               $message = sql_real_escape_string($message);            // add slashes
-               $timestamp = date("Y-m-d H:i:s",time());        // format timestamp
-               $query = "INSERT INTO %s (timestamp, message) VALUES ('%s', '%s')";
-               $query = sprintf($query, sql_table('actionlog'), $timestamp, $message);
-               sql_query($query);
+               $query = "INSERT INTO %s (timestamp, message) VALUES (%s, %s)";
+               $query = sprintf($query, sql_table('actionlog'), DB::formatDateTime(), DB::quoteValue($message));
+               DB::execute($query);
                
                self::trimLog();
                return;
@@ -64,11 +62,11 @@ class ACTIONLOG
        function clear() {
                global $manager;
 
-               $query = 'DELETE FROM ' . sql_table('actionlog');
+               $query = sprintf('DELETE FROM %s', sql_table('actionlog'));
 
                $manager->notify('ActionLogCleared',array());
 
-               return sql_query($query);
+               return DB::execute($query) !== FALSE;
        }
 
        /**
@@ -83,14 +81,18 @@ class ACTIONLOG
                // trim
                $checked = 1;
 
-               $iTotal = quickQuery('SELECT COUNT(*) AS result FROM ' . sql_table('actionlog'));
+               $query = sprintf('SELECT COUNT(*) AS result FROM %s', sql_table('actionlog'));
+               $iTotal = DB::getValue($query);
 
                // if size > 500, drop back to about 250
                $iMaxSize = 500;
                $iDropSize = 250;
                if ($iTotal > $iMaxSize) {
-                       $tsChop = quickQuery('SELECT timestamp as result FROM ' . sql_table('actionlog') . ' ORDER BY timestamp DESC LIMIT '.$iDropSize.',1');
-                       sql_query('DELETE FROM ' . sql_table('actionlog') . ' WHERE timestamp < \'' . $tsChop . '\'');
+                       $query = sprintf('SELECT timestamp as result FROM %s ORDER BY timestamp DESC LIMIT %d,1',
+                               sql_table('actionlog'), intval($iDropSize));
+                       $tsChop = DB::getValue($query);
+                       $query = sprintf("DELETE FROM %s WHERE timestamp < '%s'", sql_table('actionlog'), $tsChop);
+                       DB::execute($query);
                }
 
        }