source: extensions/fstats/initialize.admin.php @ 3956

Last change on this file since 3956 was 3324, checked in by rub, 15 years ago

extension added: fstats

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
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
21if (!defined('PHPWG_ROOT_PATH'))
22{
23  die('Hacking attempt!');
24}
25
26function fstats_remove_history_controls()
27{
28  global $page, $template;
29
30  if (isset($page['page']) and ($page['page'] == 'history'))
31  {
32    $js = '
33<script type="text/javascript">
34var FindNode = document.getElementsByName("types[]")[0].parentNode;
35FindNode.parentNode.removeChild(FindNode);
36var FindNode = document.getElementsByName("image_id")[0].parentNode;
37FindNode.parentNode.removeChild(FindNode);
38var FindNode = document.getElementsByName("filename")[0].parentNode;
39FindNode.parentNode.removeChild(FindNode);
40</script>
41';
42    $template->assign_block_vars('footer_element', array('CONTENT' => $js));
43  }
44}
45
46function fstats_change_array_value_null($v)
47{
48  return ($v === 'NULL' ? null : $v);
49}
50
51function fstats_get_history($data, $search, $types)
52{
53  $criteria = array();
54
55  if (isset($search['fields']['date-after']))
56  {
57    $tokens = explode('-', $search['fields']['date-after']);
58   
59    $criteria['start_year']  = (int)$tokens[0];
60    $criteria['start_month'] = (int)$tokens[1];
61    $criteria['start_day']   = (int)$tokens[2];
62  }
63  else
64  {
65    $criteria['start_year']  = (int)date('Y');
66    $criteria['start_month'] = (int)date('n');
67    $criteria['start_day']   = (int)date('j');
68  }
69
70  if (isset($search['fields']['date-before']))
71  {
72    $tokens = explode('-', $search['fields']['date-before']);
73
74    $criteria['end_year']  = (int)$tokens[0];
75    $criteria['end_month'] = (int)$tokens[1];
76    $criteria['end_day']   = (int)$tokens[2];
77  }
78  else
79  {
80    $criteria['end_year']  = $criteria['start_year'];
81    $criteria['end_month'] = $criteria['start_month'];
82    $criteria['end_day']   = $criteria['start_day'];
83  }
84
85  if (isset($search['fields']['user'])
86      and $search['fields']['user'] != -1)
87  {
88    $criteria['user_id'] = $search['fields']['user'];
89  }
90
91  $y = $criteria['start_year'];
92  $m = 0;
93  $d = 0;
94  $h = 0;
95
96  //echo "<PRE> \n";
97  while ($y <= $criteria['end_year'])
98  {
99    if (is_dir(sprintf(FSTATS_FMT_RAW_DIR_Y, $y)))
100    {
101      $m = (($y == $criteria['start_year']) ? $criteria['start_month'] : 1);
102      $m_end = (($y == $criteria['end_year']) ? $criteria['end_month'] : 12);
103      while ($m <= $m_end)
104      {
105        if (is_dir(sprintf(FSTATS_FMT_RAW_DIR_M, $y, $m)))
106        {
107          $d = ((($y == $criteria['start_year']) and ($m == $criteria['start_month'])) ? $criteria['start_day'] : 1);
108          $d_end = ((($y == $criteria['end_year']) and ($m == $criteria['end_month'])) ? $criteria['end_day'] : 31);
109          while ($d <= $d_end)
110          {
111            if (is_dir(sprintf(FSTATS_FMT_RAW_DIR_D, $y, $m, $d)))
112            {
113              $h = 0;
114              while ($h <= 23)
115              {
116                $dirname = sprintf(FSTATS_FMT_RAW_DIR_H, $y, $m, $d, $h);
117                if (isset($criteria['user_id']))
118                {
119                  $fileuser = sprintf(FSTATS_FMT_RAW_FILE, $y, $m, $d, $h, $criteria['user_id']);
120                }
121                if (is_dir($dirname))
122                {
123                  //echo $dirname." \n";
124                  if ($hdir = opendir($dirname))
125                  {
126                    while (($file = readdir($hdir)) !== false)
127                    {
128                      if (
129                          !is_dir($dirname.'/'.$file)
130                          and $file != '.'
131                          and $file != '..'
132                          and $file != '.svn'
133                          and (!isset($criteria['user_id']) or ($file == $fileuser))
134                         )
135                      {
136                        $filename = $dirname.'/'.$file;
137                        //echo $filename." \n";
138                        $file_contents = @file_get_contents($filename);
139                        if ($file_contents === false)
140                        {
141                          die('CANNOT LOAD '.$filename);
142                        }
143                        foreach (explode("\n", $file_contents) as $row)
144                        {
145                          if (!empty($row))
146                          {
147                            //echo 'r '.$row." \n";
148                            //$row = array_map('fstats_change_array_value_null', unserialize($row));
149                            //array_push($data, $row);
150                            array_push($data, array_map('fstats_change_array_value_null', unserialize($row)));
151                          }
152                        }
153                      }
154                    }
155                    closedir($hdir);
156                  }
157                }
158                $h++;
159              }
160            }
161            $d++;
162          }
163        }
164        $m++;
165      }
166    }
167    $y++;
168  }
169  //echo "</PRE> \n";
170
171  return $data;
172}
173
174add_event_handler('loc_begin_page_tail', 'fstats_remove_history_controls');
175add_event_handler('get_history', 'fstats_get_history', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
176
177?>
Note: See TracBrowser for help on using the repository browser.