3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2012 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)
12 * Actionlog class for Nucleus
15 define('ERROR',1); // only errors
16 define('WARNING',2); // errors and warnings
17 define('INFO',3); // info, errors and warnings
18 define('DEBUG',4); // everything
19 $CONF['LogLevel'] = INFO;
24 * (Static) Method to add a message to the action log
26 function add($level, $message) {
27 global $member, $CONF;
29 if ($CONF['LogLevel'] < $level)
32 if ($member && $member->isLoggedIn())
33 $message = "[" . $member->getDisplayName() . "] " . $message;
35 $message = sql_real_escape_string($message); // add slashes
36 $timestamp = date("Y-m-d H:i:s",time()); // format timestamp
37 $query = "INSERT INTO " . sql_table('actionlog') . " (timestamp, message) VALUES ('$timestamp', '$message')";
45 * (Static) Method to clear the whole action log
50 $query = 'DELETE FROM ' . sql_table('actionlog');
53 $manager->notify('ActionLogCleared', $param);
55 return sql_query($query);
59 * (Static) Method to trim the action log (from over 500 back to 250 entries)
64 // only check once per run
70 $iTotal = quickQuery('SELECT COUNT(*) AS result FROM ' . sql_table('actionlog'));
72 // if size > 500, drop back to about 250
75 if ($iTotal > $iMaxSize) {
76 $tsChop = quickQuery('SELECT timestamp as result FROM ' . sql_table('actionlog') . ' ORDER BY timestamp DESC LIMIT '.$iDropSize.',1');
77 sql_query('DELETE FROM ' . sql_table('actionlog') . ' WHERE timestamp < \'' . $tsChop . '\'');