1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Files statistics - a PWG Plugin | |
---|
4 | // | Copyright (C) 2007 Ruben ARNAUD - rub@phpwebgallery.net | |
---|
5 | // +-----------------------------------------------------------------------+ |
---|
6 | // | This program is free software; you can redistribute it and/or modify | |
---|
7 | // | it under the terms of the GNU General Public License as published by | |
---|
8 | // | the Free Software Foundation | |
---|
9 | // | | |
---|
10 | // | This program is distributed in the hope that it will be useful, but | |
---|
11 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
12 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
13 | // | General Public License for more details. | |
---|
14 | // | | |
---|
15 | // | You should have received a copy of the GNU General Public License | |
---|
16 | // | along with this program; if not, write to the Free Software | |
---|
17 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
18 | // | USA. | |
---|
19 | // +-----------------------------------------------------------------------+ |
---|
20 | |
---|
21 | if (!defined('PHPWG_ROOT_PATH')) |
---|
22 | { |
---|
23 | die('Hacking attempt!'); |
---|
24 | } |
---|
25 | |
---|
26 | add_event_handler('pwg_log_allowed', 'fstats_pwg_log_allowed', 9999999 /* EVENT_HANDLER_PRIORITY_LAST */, 3); |
---|
27 | |
---|
28 | function fstats_pwg_log_allowed($do_log, $image_id, $image_type) |
---|
29 | { |
---|
30 | if ($do_log) |
---|
31 | { |
---|
32 | global $page, $user; |
---|
33 | |
---|
34 | $tags_string = null; |
---|
35 | if (isset($page['section']) and $page['section'] == 'tags') |
---|
36 | { |
---|
37 | $tag_ids = array(); |
---|
38 | foreach ($page['tags'] as $tag) |
---|
39 | { |
---|
40 | array_push($tag_ids, $tag['id']); |
---|
41 | } |
---|
42 | |
---|
43 | $tags_string = implode(',', $tag_ids); |
---|
44 | } |
---|
45 | |
---|
46 | // here we ask the database the current date and time, and we extract |
---|
47 | // {year, month, day} from the current date. We could do this during the |
---|
48 | // insert query with a CURDATE(), CURTIME(), DATE_FORMAT(CURDATE(), '%Y') |
---|
49 | // ... but I (plg) think it would cost more than a double query and a PHP |
---|
50 | // extraction. |
---|
51 | $query = ' |
---|
52 | SELECT CURDATE(), CURTIME() |
---|
53 | ;'; |
---|
54 | list($curdate, $curtime) = mysql_fetch_row(pwg_query($query)); |
---|
55 | |
---|
56 | list($curyear, $curmonth, $curday) = explode('-', $curdate); |
---|
57 | list($curhour) = explode(':', $curtime); |
---|
58 | |
---|
59 | $dirname =sprintf(FSTATS_FMT_RAW_DIR_H, $curyear, $curmonth, $curday, $curhour); |
---|
60 | fstats_Rmkdir($dirname); |
---|
61 | |
---|
62 | $filename = $dirname.'/'.sprintf(FSTATS_FMT_RAW_FILE, $curyear, $curmonth, $curday, $curhour, $user['id']); |
---|
63 | |
---|
64 | $contents = array(); |
---|
65 | $contents['version'] = '1'; |
---|
66 | |
---|
67 | $contents['date'] = $curdate; |
---|
68 | $contents['time'] = $curtime; |
---|
69 | $contents['year'] = $curyear; |
---|
70 | $contents['month'] = $curmonth; |
---|
71 | $contents['day'] = $curday; |
---|
72 | $contents['hour'] = $curhour; |
---|
73 | $contents['user_id'] = $user['id']; |
---|
74 | $contents['IP'] = $_SERVER['REMOTE_ADDR']; |
---|
75 | $contents['section'] = (isset($page['section']) ? "'".$page['section']."'" : 'NULL'); |
---|
76 | $contents['category_id'] = (isset($page['category']) ? $page['category']['id'] : 'NULL'); |
---|
77 | $contents['image_id'] = (isset($image_id) ? $image_id : 'NULL'); |
---|
78 | $contents['image_type'] = (isset($image_type) ? "'".$image_type."'" : 'NULL'); |
---|
79 | $contents['tag_ids'] = (isset($tags_string) ? "'".$tags_string."'" : 'NULL'); |
---|
80 | |
---|
81 | $hfile = fopen($filename, 'a+'); |
---|
82 | if ($hfile !== FALSE) |
---|
83 | { |
---|
84 | fwrite($hfile, serialize ($contents)."\n"); |
---|
85 | fclose($hfile); |
---|
86 | } |
---|
87 | |
---|
88 | } |
---|
89 | |
---|
90 | // Stop Database statitics |
---|
91 | $do_log = false; |
---|
92 | |
---|
93 | return $do_log; |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | ?> |
---|