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
12 * Actionlog class for Nucleus
\r
14 * $Id: ACTIONLOG.php,v 1.3 2005-03-12 06:19:04 kimitake Exp $
\r
17 define('ERROR',1); // only errors
\r
18 define('WARNING',2); // errors and warnings
\r
19 define('INFO',3); // info, errors and warnings
\r
20 define('DEBUG',4); // everything
\r
21 $CONF['LogLevel'] = INFO;
\r
26 * (Static) Method to add message to log
\r
28 function add($level, $message) {
\r
29 global $member, $CONF;
\r
31 if ($CONF['LogLevel'] < $level)
\r
34 if ($member && $member->isLoggedIn())
\r
35 $message = "[" . $member->getDisplayName() . "] " . $message;
\r
37 $message = addslashes($message); // add slashes
\r
38 $timestamp = date("Y-m-d H:i:s",time()); // format timestamp
\r
39 $query = "INSERT INTO " . sql_table('actionlog') . " (timestamp, message) VALUES ('$timestamp', '$message')";
\r
43 ACTIONLOG::trimLog();
\r
47 * (Static) Method to clear log
\r
52 $query = 'DELETE FROM ' . sql_table('actionlog');
\r
54 $manager->notify('ActionLogCleared',array());
\r
56 return sql_query($query);
\r
59 function trimLog() {
\r
60 static $checked = 0;
\r
62 // only check once per run
\r
63 if ($checked) return;
\r
68 $iTotal = quickQuery('SELECT COUNT(*) AS result FROM ' . sql_table('actionlog'));
\r
70 // if size > 500, drop back to about 250
\r
73 if ($iTotal > $iMaxSize) {
\r
74 $tsChop = quickQuery('SELECT timestamp as result FROM ' . sql_table('actionlog') . ' ORDER BY timestamp DESC LIMIT '.$iDropSize.',1');
\r
75 sql_query('DELETE FROM ' . sql_table('actionlog') . ' WHERE timestamp < \'' . $tsChop . '\'');
\r