3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2009 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
13 * Actionlog class for Nucleus
15 * @license http://nucleuscms.org/license.txt GNU General Public License
16 * @copyright Copyright (C) 2002-2009 The Nucleus Group
17 * @version $Id: ACTIONLOG.php 1822 2012-05-04 13:47:22Z sakamocchi $
19 define('ERROR',1); // only errors
20 define('WARNING',2); // errors and warnings
21 define('INFO',3); // info, errors and warnings
22 define('DEBUG',4); // everything
23 $CONF['LogLevel'] = INFO;
29 * Method to add a message to the action log
32 * @param Integer $level log level
33 * @param String $message log message
37 function add($level, $message)
39 global $member, $CONF;
41 if ( $CONF['LogLevel'] < $level )
46 if ( $member && $member->isLoggedIn() )
48 $message = "[" . $member->getDisplayName() . "] " . $message;
51 $query = "INSERT INTO %s (timestamp, message) VALUES (%s, %s)";
52 $query = sprintf($query, sql_table('actionlog'), DB::formatDateTime(), DB::quoteValue($message));
60 * (Static) Method to clear the whole action log
65 $query = sprintf('DELETE FROM %s', sql_table('actionlog'));
67 $manager->notify('ActionLogCleared',array());
69 return DB::execute($query) !== FALSE;
73 * (Static) Method to trim the action log (from over 500 back to 250 entries)
78 // only check once per run
84 $query = sprintf('SELECT COUNT(*) AS result FROM %s', sql_table('actionlog'));
85 $iTotal = DB::getValue($query);
87 // if size > 500, drop back to about 250
90 if ($iTotal > $iMaxSize) {
91 $query = sprintf('SELECT timestamp as result FROM %s ORDER BY timestamp DESC LIMIT %d,1',
92 sql_table('actionlog'), intval($iDropSize));
93 $tsChop = DB::getValue($query);
94 $query = sprintf("DELETE FROM %s WHERE timestamp < '%s'", sql_table('actionlog'), $tsChop);