3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2012 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-2012 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 $query = "INSERT INTO %s (timestamp, message) VALUES ('%s', %s)";
\r
52 $query = sprintf($query, sql_table('actionlog'), DB::formatDateTime(), DB::quoteValue($message));
\r
53 DB::execute($query);
\r
60 * (Static) Method to clear the whole action log
\r
65 $query = sprintf('DELETE FROM %s', sql_table('actionlog'));
\r
67 $manager->notify('ActionLogCleared',array());
\r
69 return DB::execute($query) !== FALSE;
\r
73 * (Static) Method to trim the action log (from over 500 back to 250 entries)
\r
75 function trimLog() {
\r
76 static $checked = 0;
\r
78 // only check once per run
\r
79 if ($checked) return;
\r
84 $query = sprintf('SELECT COUNT(*) AS result FROM %s', sql_table('actionlog'));
\r
85 $iTotal = DB::getValue($query);
\r
87 // if size > 500, drop back to about 250
\r
90 if ($iTotal > $iMaxSize) {
\r
91 $query = sprintf('SELECT timestamp as result FROM %s ORDER BY timestamp DESC LIMIT %d,1',
\r
92 sql_table('actionlog'), intval($iDropSize));
\r
93 $tsChop = DB::getValue($query);
\r
94 $query = sprintf("DELETE FROM %s WHERE timestamp < '%s'", sql_table('actionlog'), $tsChop);
\r
95 DB::execute($query);
\r