4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2002-2012 The Nucleus Group
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 2
\r
10 * of the License, or (at your option) any later version.
\r
11 * (see nucleus/documentation/index.html#license for more info)
\r
14 * Actionlog class for Nucleus
\r
16 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
17 * @copyright Copyright (C) 2002-2012 The Nucleus Group
\r
18 * @version $Id: ACTIONLOG.php 1470 2010-11-29 22:10:16Z ftruscot $
\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
30 * Method to add a message to the action log
\r
33 * @param Integer $level log level
\r
34 * @param String $message log message
\r
38 function add($level, $message)
\r
40 global $member, $CONF;
\r
42 if ( $CONF['LogLevel'] < $level )
\r
47 if ( $member && $member->isLoggedIn() )
\r
49 $message = "[" . $member->getDisplayName() . "] " . $message;
\r
52 $query = "INSERT INTO %s (timestamp, message) VALUES (%s, %s)";
\r
53 $query = sprintf($query, sql_table('actionlog'), DB::formatDateTime(), DB::quoteValue($message));
\r
54 DB::execute($query);
\r
61 * (Static) Method to clear the whole action log
\r
66 $query = sprintf('DELETE FROM %s', sql_table('actionlog'));
\r
68 $manager->notify('ActionLogCleared',array());
\r
70 return DB::execute($query) !== FALSE;
\r
74 * (Static) Method to trim the action log (from over 500 back to 250 entries)
\r
76 function trimLog() {
\r
77 static $checked = 0;
\r
79 // only check once per run
\r
80 if ($checked) return;
\r
85 $query = sprintf('SELECT COUNT(*) AS result FROM %s', sql_table('actionlog'));
\r
86 $iTotal = DB::getValue($query);
\r
88 // if size > 500, drop back to about 250
\r
91 if ($iTotal > $iMaxSize) {
\r
92 $query = sprintf('SELECT timestamp as result FROM %s ORDER BY timestamp DESC LIMIT %d,1',
\r
93 sql_table('actionlog'), intval($iDropSize));
\r
94 $tsChop = DB::getValue($query);
\r
95 $query = sprintf("DELETE FROM %s WHERE timestamp < '%s'", sql_table('actionlog'), $tsChop);
\r
96 DB::execute($query);
\r
107 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
108 * Copyright (C) 2002-2009 The Nucleus Group
110 * This program is free software; you can redistribute it and/or
111 * modify it under the terms of the GNU General Public License
112 * as published by the Free Software Foundation; either version 2
113 * of the License, or (at your option) any later version.
114 * (see nucleus/documentation/index.html#license for more info)
117 * Actionlog class for Nucleus
119 * @license http://nucleuscms.org/license.txt GNU General Public License
120 * @copyright Copyright (C) 2002-2009 The Nucleus Group
121 * @version $Id: ACTIONLOG.php 1822 2012-05-04 13:47:22Z sakamocchi $
123 define('ERROR',1); // only errors
124 define('WARNING',2); // errors and warnings
125 define('INFO',3); // info, errors and warnings
126 define('DEBUG',4); // everything
127 $CONF['LogLevel'] = INFO;
133 * Method to add a message to the action log
136 * @param Integer $level log level
137 * @param String $message log message
141 function add($level, $message)
143 global $member, $CONF;
145 if ( $CONF['LogLevel'] < $level )
150 if ( $member && $member->isLoggedIn() )
152 $message = "[" . $member->getDisplayName() . "] " . $message;
155 $query = "INSERT INTO %s (timestamp, message) VALUES (%s, %s)";
156 $query = sprintf($query, sql_table('actionlog'), DB::formatDateTime(), DB::quoteValue($message));
164 * (Static) Method to clear the whole action log
169 $query = sprintf('DELETE FROM %s', sql_table('actionlog'));
172 $manager->notify('ActionLogCleared', $data);
174 return DB::execute($query) !== FALSE;
178 * (Static) Method to trim the action log (from over 500 back to 250 entries)
183 // only check once per run
184 if ($checked) return;
189 $query = sprintf('SELECT COUNT(*) AS result FROM %s', sql_table('actionlog'));
190 $iTotal = DB::getValue($query);
192 // if size > 500, drop back to about 250
195 if ($iTotal > $iMaxSize) {
196 $query = sprintf('SELECT timestamp as result FROM %s ORDER BY timestamp DESC LIMIT %d,1',
197 sql_table('actionlog'), intval($iDropSize));
198 $tsChop = DB::getValue($query);
199 $query = sprintf("DELETE FROM %s WHERE timestamp < '%s'", sql_table('actionlog'), $tsChop);
208 >>>>>>> skinnable-master