00001 <?php 00002 /* 00003 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 00004 * Copyright (C) 2002-2007 The Nucleus Group 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * (see nucleus/documentation/index.html#license for more info) 00011 */ 00020 define('ERROR',1); // only errors 00021 define('WARNING',2); // errors and warnings 00022 define('INFO',3); // info, errors and warnings 00023 define('DEBUG',4); // everything 00024 $CONF['LogLevel'] = INFO; 00025 00026 class ACTIONLOG { 00027 00031 function add($level, $message) { 00032 global $member, $CONF; 00033 00034 if ($CONF['LogLevel'] < $level) 00035 return; 00036 00037 if ($member && $member->isLoggedIn()) 00038 $message = "[" . $member->getDisplayName() . "] " . $message; 00039 00040 $message = addslashes($message); // add slashes 00041 $timestamp = date("Y-m-d H:i:s",time()); // format timestamp 00042 $query = "INSERT INTO " . sql_table('actionlog') . " (timestamp, message) VALUES ('$timestamp', '$message')"; 00043 00044 sql_query($query); 00045 00046 ACTIONLOG::trimLog(); 00047 } 00048 00052 function clear() { 00053 global $manager; 00054 00055 $query = 'DELETE FROM ' . sql_table('actionlog'); 00056 00057 $manager->notify('ActionLogCleared',array()); 00058 00059 return sql_query($query); 00060 } 00061 00065 function trimLog() { 00066 static $checked = 0; 00067 00068 // only check once per run 00069 if ($checked) return; 00070 00071 // trim 00072 $checked = 1; 00073 00074 $iTotal = quickQuery('SELECT COUNT(*) AS result FROM ' . sql_table('actionlog')); 00075 00076 // if size > 500, drop back to about 250 00077 $iMaxSize = 500; 00078 $iDropSize = 250; 00079 if ($iTotal > $iMaxSize) { 00080 $tsChop = quickQuery('SELECT timestamp as result FROM ' . sql_table('actionlog') . ' ORDER BY timestamp DESC LIMIT '.$iDropSize.',1'); 00081 sql_query('DELETE FROM ' . sql_table('actionlog') . ' WHERE timestamp < \'' . $tsChop . '\''); 00082 } 00083 00084 } 00085 00086 } 00087 00088 ?>