3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2011 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-2011 The Nucleus Group
18 * $NucleusJP: ACTIONLOG.php,v 1.7 2007/03/13 05:18:32 shizuki Exp $
20 define('ERROR',1); // only errors
21 define('WARNING',2); // errors and warnings
22 define('INFO',3); // info, errors and warnings
23 define('DEBUG',4); // everything
24 $CONF['LogLevel'] = INFO;
29 * (Static) Method to add a message to the action log
31 function add($level, $message) {
32 global $member, $CONF;
34 if ($CONF['LogLevel'] < $level)
37 if ($member && $member->isLoggedIn())
38 $message = "[" . $member->getDisplayName() . "] " . $message;
40 $message = sql_real_escape_string($message); // add slashes
41 $timestamp = date("Y-m-d H:i:s",time()); // format timestamp
42 $query = "INSERT INTO " . sql_table('actionlog') . " (timestamp, message) VALUES ('$timestamp', '$message')";
50 * (Static) Method to clear the whole action log
55 $query = 'DELETE FROM ' . sql_table('actionlog');
57 $manager->notify('ActionLogCleared',array());
59 return sql_query($query);
63 * (Static) Method to trim the action log (from over 500 back to 250 entries)
68 // only check once per run
74 $iTotal = quickQuery('SELECT COUNT(*) AS result FROM ' . sql_table('actionlog'));
76 // if size > 500, drop back to about 250
79 if ($iTotal > $iMaxSize) {
80 $tsChop = quickQuery('SELECT timestamp as result FROM ' . sql_table('actionlog') . ' ORDER BY timestamp DESC LIMIT '.$iDropSize.',1');
81 sql_query('DELETE FROM ' . sql_table('actionlog') . ' WHERE timestamp < \'' . $tsChop . '\'');