3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2005 The Nucleus Group
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
10 * (see nucleus/documentation/index.html#license for more info)
\r
13 * Actionlog class for Nucleus
\r
15 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
16 * @copyright Copyright (C) 2002-2005 The Nucleus Group
\r
17 * @version $Id: ACTIONLOG.php,v 1.4 2005-08-13 07:31:04 kimitake Exp $
\r
18 * $NucleusJP: ACTIONLOG.php,v 1.3 2005/03/12 06:19:04 kimitake Exp $
\r
20 define('ERROR',1); // only errors
\r
21 define('WARNING',2); // errors and warnings
\r
22 define('INFO',3); // info, errors and warnings
\r
23 define('DEBUG',4); // everything
\r
24 $CONF['LogLevel'] = INFO;
\r
29 * (Static) Method to add message to log
\r
31 function add($level, $message) {
\r
32 global $member, $CONF;
\r
34 if ($CONF['LogLevel'] < $level)
\r
37 if ($member && $member->isLoggedIn())
\r
38 $message = "[" . $member->getDisplayName() . "] " . $message;
\r
40 $message = addslashes($message); // add slashes
\r
41 $timestamp = date("Y-m-d H:i:s",time()); // format timestamp
\r
42 $query = "INSERT INTO " . sql_table('actionlog') . " (timestamp, message) VALUES ('$timestamp', '$message')";
\r
46 ACTIONLOG::trimLog();
\r
50 * (Static) Method to clear log
\r
55 $query = 'DELETE FROM ' . sql_table('actionlog');
\r
57 $manager->notify('ActionLogCleared',array());
\r
59 return sql_query($query);
\r
62 function trimLog() {
\r
63 static $checked = 0;
\r
65 // only check once per run
\r
66 if ($checked) return;
\r
71 $iTotal = quickQuery('SELECT COUNT(*) AS result FROM ' . sql_table('actionlog'));
\r
73 // if size > 500, drop back to about 250
\r
76 if ($iTotal > $iMaxSize) {
\r
77 $tsChop = quickQuery('SELECT timestamp as result FROM ' . sql_table('actionlog') . ' ORDER BY timestamp DESC LIMIT '.$iDropSize.',1');
\r
78 sql_query('DELETE FROM ' . sql_table('actionlog') . ' WHERE timestamp < \'' . $tsChop . '\'');
\r