3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2009 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-2009 The Nucleus Group
\r
17 * @version $Id: ACTIONLOG.php 1470 2010-11-29 22:10:16Z ftruscot $
\r
19 define('ERROR',1); // only errors
\r
20 define('WARNING',2); // errors and warnings
\r
21 define('INFO',3); // info, errors and warnings
\r
22 define('DEBUG',4); // everything
\r
23 $CONF['LogLevel'] = INFO;
\r
29 * Method to add a message to the action log
\r
32 * @param Integer $level log level
\r
33 * @param String $message log message
\r
37 function add($level, $message)
\r
39 global $member, $CONF;
\r
41 if ( $CONF['LogLevel'] < $level )
\r
46 if ( $member && $member->isLoggedIn() )
\r
48 $message = "[" . $member->getDisplayName() . "] " . $message;
\r
51 $message = sql_real_escape_string($message); // add slashes
\r
52 $timestamp = date("Y-m-d H:i:s",time()); // format timestamp
\r
53 $query = "INSERT INTO %s (timestamp, message) VALUES ('%s', '%s')";
\r
54 $query = sprintf($query, sql_table('actionlog'), $timestamp, $message);
\r
62 * (Static) Method to clear the whole action log
\r
67 $query = 'DELETE FROM ' . sql_table('actionlog');
\r
69 $manager->notify('ActionLogCleared',array());
\r
71 return sql_query($query);
\r
75 * (Static) Method to trim the action log (from over 500 back to 250 entries)
\r
77 function trimLog() {
\r
78 static $checked = 0;
\r
80 // only check once per run
\r
81 if ($checked) return;
\r
86 $iTotal = quickQuery('SELECT COUNT(*) AS result FROM ' . sql_table('actionlog'));
\r
88 // if size > 500, drop back to about 250
\r
91 if ($iTotal > $iMaxSize) {
\r
92 $tsChop = quickQuery('SELECT timestamp as result FROM ' . sql_table('actionlog') . ' ORDER BY timestamp DESC LIMIT '.$iDropSize.',1');
\r
93 sql_query('DELETE FROM ' . sql_table('actionlog') . ' WHERE timestamp < \'' . $tsChop . '\'');
\r