OSDN Git Service

b5bc6cac5c8c97f1faafbc7f1f6694b4b2ec17eb
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / ACTIONLOG.php
1 <?php\r
2 /*\r
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
4  * Copyright (C) 2002-2005 The Nucleus Group\r
5  *\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
11  */\r
12 /**\r
13  * Actionlog class for Nucleus\r
14  *\r
15  * @license http://nucleuscms.org/license.txt GNU General Public License\r
16  * @copyright Copyright (C) 2002-2005 The Nucleus Group\r
17  * @version $Id: ACTIONLOG.php,v 1.4 2005-08-13 07:31:04 kimitake Exp $\r
18  * $NucleusJP: ACTIONLOG.php,v 1.3 2005/03/12 06:19:04 kimitake Exp $\r
19  */\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
25 \r
26 class ACTIONLOG {\r
27 \r
28         /**\r
29           * (Static) Method to add message to log\r
30           */\r
31         function add($level, $message) {\r
32                 global $member, $CONF;\r
33                 \r
34                 if ($CONF['LogLevel'] < $level)\r
35                         return;\r
36                 \r
37                 if ($member && $member->isLoggedIn())\r
38                         $message = "[" . $member->getDisplayName() . "] " . $message;\r
39                 \r
40                 $message = addslashes($message);                // add slashes\r
41                 $timestamp = date("Y-m-d H:i:s",time());        // format timestamp\r
42                 $query = "INSERT INTO " . sql_table('actionlog') . " (timestamp, message) VALUES ('$timestamp', '$message')";\r
43                 \r
44                 sql_query($query);\r
45                 \r
46                 ACTIONLOG::trimLog();\r
47         }\r
48         \r
49         /**\r
50           * (Static) Method to clear log\r
51           */\r
52         function clear() {\r
53                 global $manager;\r
54                 \r
55                 $query = 'DELETE FROM ' . sql_table('actionlog');\r
56 \r
57                 $manager->notify('ActionLogCleared',array());\r
58                 \r
59                 return sql_query($query);\r
60         }\r
61         \r
62         function trimLog() {\r
63                 static $checked = 0;\r
64                 \r
65                 // only check once per run\r
66                 if ($checked) return;\r
67                 \r
68                 // trim\r
69                 $checked = 1;\r
70                 \r
71                 $iTotal = quickQuery('SELECT COUNT(*) AS result FROM ' . sql_table('actionlog'));\r
72                 \r
73                 // if size > 500, drop back to about 250\r
74                 $iMaxSize = 500;\r
75                 $iDropSize = 250;\r
76                 if ($iTotal > $iMaxSize) {\r
77                         $tsChop = quickQuery('SELECT timestamp as result FROM ' . sql_table('actionlog') . ' ORDER BY timestamp DESC LIMIT '.$iDropSize.',1');\r
78                         sql_query('DELETE FROM ' . sql_table('actionlog') . ' WHERE timestamp < \'' . $tsChop . '\'');\r
79                 }\r
80                 \r
81         }\r
82 \r
83 }\r
84 \r
85 ?>\r