OSDN Git Service

applied 3.2 modification
[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   * Actionlog class for Nucleus\r
13   *\r
14   * $Id: ACTIONLOG.php,v 1.3 2005-03-12 06:19:04 kimitake Exp $\r
15   * $NucleusJP$\r
16   */\r
17 define('ERROR',1);              // only errors\r
18 define('WARNING',2);    // errors and warnings\r
19 define('INFO',3);               // info, errors and warnings\r
20 define('DEBUG',4);              // everything \r
21 $CONF['LogLevel'] = INFO;\r
22 \r
23 class ACTIONLOG {\r
24 \r
25         /**\r
26           * (Static) Method to add message to log\r
27           */\r
28         function add($level, $message) {\r
29                 global $member, $CONF;\r
30                 \r
31                 if ($CONF['LogLevel'] < $level)\r
32                         return;\r
33                 \r
34                 if ($member && $member->isLoggedIn())\r
35                         $message = "[" . $member->getDisplayName() . "] " . $message;\r
36                 \r
37                 $message = addslashes($message);                // add slashes\r
38                 $timestamp = date("Y-m-d H:i:s",time());        // format timestamp\r
39                 $query = "INSERT INTO " . sql_table('actionlog') . " (timestamp, message) VALUES ('$timestamp', '$message')";\r
40                 \r
41                 sql_query($query);\r
42                 \r
43                 ACTIONLOG::trimLog();\r
44         }\r
45         \r
46         /**\r
47           * (Static) Method to clear log\r
48           */\r
49         function clear() {\r
50                 global $manager;\r
51                 \r
52                 $query = 'DELETE FROM ' . sql_table('actionlog');\r
53 \r
54                 $manager->notify('ActionLogCleared',array());\r
55                 \r
56                 return sql_query($query);\r
57         }\r
58         \r
59         function trimLog() {\r
60                 static $checked = 0;\r
61                 \r
62                 // only check once per run\r
63                 if ($checked) return;\r
64                 \r
65                 // trim\r
66                 $checked = 1;\r
67                 \r
68                 $iTotal = quickQuery('SELECT COUNT(*) AS result FROM ' . sql_table('actionlog'));\r
69                 \r
70                 // if size > 500, drop back to about 250\r
71                 $iMaxSize = 500;\r
72                 $iDropSize = 250;\r
73                 if ($iTotal > $iMaxSize) {\r
74                         $tsChop = quickQuery('SELECT timestamp as result FROM ' . sql_table('actionlog') . ' ORDER BY timestamp DESC LIMIT '.$iDropSize.',1');\r
75                         sql_query('DELETE FROM ' . sql_table('actionlog') . ' WHERE timestamp < \'' . $tsChop . '\'');\r
76                 }\r
77                 \r
78         }\r
79 \r
80 }\r
81 \r
82 ?>\r