1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * -------------------------------------------------------------------------* |
---|
4 | * This library is free software; you can redistribute it and/or modify it * |
---|
5 | * under the terms of the GNU Lesser General Public License as published by * |
---|
6 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
7 | * or any later version. * |
---|
8 | * This library is distributed in the hope that it will be useful, but * |
---|
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
11 | * See the GNU Lesser General Public License for more details. * |
---|
12 | * You should have received a copy of the GNU Lesser General Public License * |
---|
13 | * along with this library; if not, write to the Free Software Foundation, * |
---|
14 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
15 | \**************************************************************************/ |
---|
16 | |
---|
17 | /* $Id: class.vfs_functions.inc.php 2009-11-11 amuller $ */ |
---|
18 | |
---|
19 | class vfs_functions |
---|
20 | { |
---|
21 | var $public_functions = array( |
---|
22 | 'touch' => True, |
---|
23 | 'download'=>True, |
---|
24 | 'setRestricted'=>True, |
---|
25 | 'editComment'=> True, |
---|
26 | 'rename'=>True, |
---|
27 | 'delete'=>True, |
---|
28 | 'summary' => True |
---|
29 | ); |
---|
30 | |
---|
31 | //keep |
---|
32 | var $bo; |
---|
33 | var $dispath; |
---|
34 | var $cwd; |
---|
35 | var $lesspath; |
---|
36 | var $dispsep; |
---|
37 | |
---|
38 | var $target; |
---|
39 | |
---|
40 | var $prefs;//array |
---|
41 | |
---|
42 | var $current_config; |
---|
43 | // this ones must be checked thorougly; |
---|
44 | var $fileman = Array(); |
---|
45 | //var $fileman; |
---|
46 | var $path; |
---|
47 | var $file; |
---|
48 | var $debug = false; |
---|
49 | var $now; |
---|
50 | |
---|
51 | function vfs_functions() |
---|
52 | { |
---|
53 | $this->now = date('Y-m-d'); |
---|
54 | |
---|
55 | $this->bo = CreateObject('filemanager.bofilemanager'); |
---|
56 | |
---|
57 | $c = CreateObject('phpgwapi.config','filemanager'); |
---|
58 | $c->read_repository(); |
---|
59 | $this->current_config = $c->config_data; |
---|
60 | |
---|
61 | |
---|
62 | // here local vars are created from the HTTP vars |
---|
63 | @reset($GLOBALS['HTTP_POST_VARS']); |
---|
64 | while(list($name,) = @each($GLOBALS['HTTP_POST_VARS'])) |
---|
65 | { |
---|
66 | $this->$name = $GLOBALS['HTTP_POST_VARS'][$name]; |
---|
67 | } |
---|
68 | |
---|
69 | @reset($GLOBALS['HTTP_GET_VARS']); |
---|
70 | while(list($name,) = @each($GLOBALS['HTTP_GET_VARS'])) |
---|
71 | { |
---|
72 | $$name = $GLOBALS['HTTP_GET_VARS'][$name]; |
---|
73 | $this->$name = $GLOBALS['HTTP_GET_VARS'][$name]; |
---|
74 | |
---|
75 | } |
---|
76 | |
---|
77 | $to_decode = array |
---|
78 | ( |
---|
79 | 'op' => array('op' => ''), |
---|
80 | 'path' => array('path' => ''), |
---|
81 | 'file' => array('file' => ''), |
---|
82 | 'sortby' => array('sortby' => ''), |
---|
83 | 'messages' => array('messages' => ''), |
---|
84 | 'comment' => array('comment' => ''), |
---|
85 | 'to' => array('to' => '') |
---|
86 | ); |
---|
87 | |
---|
88 | reset($to_decode); |
---|
89 | while(list($var, $conditions) = each($to_decode)) |
---|
90 | { |
---|
91 | while(list($condvar, $condvalue) = each($conditions)) |
---|
92 | { |
---|
93 | if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue)) |
---|
94 | { |
---|
95 | if(is_array($$var)) |
---|
96 | { |
---|
97 | $temp = array(); |
---|
98 | while(list($varkey, $varvalue) = each($$var)) |
---|
99 | { |
---|
100 | if(is_int($varkey)) |
---|
101 | { |
---|
102 | $temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue)))); |
---|
103 | } |
---|
104 | else |
---|
105 | { |
---|
106 | $temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue; |
---|
107 | } |
---|
108 | } |
---|
109 | $this->$var = $temp; |
---|
110 | } |
---|
111 | elseif(isset($$var)) |
---|
112 | { |
---|
113 | $this->$var = stripslashes(base64_decode(urldecode($$var))); |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | // get appl. and user prefs |
---|
120 | $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']); |
---|
121 | $pref->read_repository(); |
---|
122 | $pref->save_repository(True); |
---|
123 | $pref_array = $pref->read_repository(); |
---|
124 | $this->prefs = $pref_array[$this->bo->appname]; |
---|
125 | |
---|
126 | //always show name |
---|
127 | |
---|
128 | $this->prefs[name] =1; |
---|
129 | |
---|
130 | } |
---|
131 | // String format is YYYY-MM-DD HH:MM |
---|
132 | function dateString2timeStamp($string){ |
---|
133 | return mktime($string[11].$string[12], |
---|
134 | $string[14].$string[15], |
---|
135 | $string[17].$string[18], |
---|
136 | $string[5].$string[6], |
---|
137 | $string[8].$string[9], |
---|
138 | $string[0].$string[1]. |
---|
139 | $string[2].$string[3]); |
---|
140 | } |
---|
141 | function verifyLock($file,$relative){ |
---|
142 | $ls_array = $this->bo->vfs->ls(array( |
---|
143 | 'string' => $file, |
---|
144 | 'relatives' => array($relative), |
---|
145 | 'checksubdirs' => False, |
---|
146 | 'nofiles' => True |
---|
147 | )); |
---|
148 | $timestamp = $this->dateString2timeStamp($ls_array[0]['modified']); |
---|
149 | if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']) // recently than last minute: someone is editing |
---|
150 | { |
---|
151 | $this->messages[]=lang('Error:').lang('This file is being edited right now by:').$GLOBALS['phpgw']->accounts->id2name($ls_array[0]['modifiedby_id']); |
---|
152 | return False; |
---|
153 | |
---|
154 | } |
---|
155 | else |
---|
156 | return True; |
---|
157 | } |
---|
158 | |
---|
159 | function setRestricted(){ |
---|
160 | $GLOBALS['phpgw_info']['flags'] = array |
---|
161 | ( |
---|
162 | 'currentapp' => 'filemanager', |
---|
163 | 'noheader' => True, |
---|
164 | 'nonavbar' => True, |
---|
165 | 'nofooter' => True, |
---|
166 | 'noappheader' => True, |
---|
167 | 'enable_browser_class' => True |
---|
168 | ); |
---|
169 | |
---|
170 | if ($this->file) |
---|
171 | { |
---|
172 | $filename=$this->path.'/'.$this->file; |
---|
173 | if(!$this->verifyLock($filename,RELATIVE_NONE)) |
---|
174 | { |
---|
175 | echo "False"; |
---|
176 | return False; |
---|
177 | } |
---|
178 | |
---|
179 | $ls_array = $this->bo->vfs->ls(array( |
---|
180 | 'string' => $filename, |
---|
181 | 'relatives' => array(RELATIVE_NONE), |
---|
182 | 'checksubdirs' => False, |
---|
183 | 'nofiles' => True |
---|
184 | )); |
---|
185 | if (intval($ls_array[0]['type']) == 0) |
---|
186 | $type = 1; |
---|
187 | else |
---|
188 | $type = 0; |
---|
189 | |
---|
190 | if($this->bo->vfs->set_attributes (array( |
---|
191 | 'string' => $filename, |
---|
192 | 'relatives' => RELATIVE_NONE, |
---|
193 | 'attributes' => array('type' => $type) |
---|
194 | )) |
---|
195 | ) |
---|
196 | { |
---|
197 | echo "True:".$this->file; |
---|
198 | } |
---|
199 | else |
---|
200 | { |
---|
201 | echo "False"; |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | } |
---|
206 | function touch(){ |
---|
207 | if($this->file) |
---|
208 | if ($this->bo->vfs->touch(array('string'=> $this->file,'relatives' => array(RELATIVE_ALL)))) |
---|
209 | { |
---|
210 | echo "True"; |
---|
211 | return True; |
---|
212 | } |
---|
213 | else |
---|
214 | return False; |
---|
215 | |
---|
216 | } |
---|
217 | function summary() |
---|
218 | { |
---|
219 | if($this->file) |
---|
220 | { |
---|
221 | header('Content-Type: image/gif'); |
---|
222 | $expires = 60*60*24*15; /* 15 days */ |
---|
223 | header("Cache-Control: maxage=".$expires); |
---|
224 | header("Pragma: public"); |
---|
225 | header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires)); |
---|
226 | $content = $this->bo->vfs->summary(array('path' => $this->path, |
---|
227 | 'string' => $this->file |
---|
228 | )); |
---|
229 | if (sizeof($content) > 0) |
---|
230 | echo $content; |
---|
231 | else |
---|
232 | { |
---|
233 | $filename = './filemanager/templates/default/images/error.gif'; |
---|
234 | $handle = fopen($filename,'rb'); |
---|
235 | echo fread($handle,filesize($filename)); |
---|
236 | fclose($handle); |
---|
237 | } |
---|
238 | |
---|
239 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | function delete(){ |
---|
244 | foreach($this->fileman as $filename) |
---|
245 | { |
---|
246 | if($this->verifyLock($filename,RELATIVE_ALL) && $this->bo->vfs->delete(array('string' => $filename))) |
---|
247 | { |
---|
248 | echo $filename.":"; |
---|
249 | } |
---|
250 | else |
---|
251 | { |
---|
252 | echo "False:".$filename; |
---|
253 | return False; |
---|
254 | } |
---|
255 | } |
---|
256 | } |
---|
257 | function editComment() |
---|
258 | { |
---|
259 | if($badchar = $this->bo->bad_chars($this->comment, False, True)) |
---|
260 | { |
---|
261 | echo "False:badchar:".$badchar; |
---|
262 | return False; |
---|
263 | } |
---|
264 | |
---|
265 | if ($this->bo->vfs->set_attributes(array( |
---|
266 | 'string' => $this->file, |
---|
267 | 'relatives' => array(RELATIVE_ALL), |
---|
268 | 'attributes' => array( |
---|
269 | 'comment' => stripslashes($this->comment) |
---|
270 | ) |
---|
271 | ))) |
---|
272 | { |
---|
273 | echo "True:".$this->file; |
---|
274 | return True; |
---|
275 | } |
---|
276 | } |
---|
277 | # Handle Renaming Files and Directories |
---|
278 | function rename() |
---|
279 | { |
---|
280 | if ($this->file) |
---|
281 | { |
---|
282 | if($badchar = $this->bo->bad_chars($this->to, True, True)) |
---|
283 | { |
---|
284 | echo "Error:badchar:".$badchar; |
---|
285 | return false; |
---|
286 | } |
---|
287 | if(ereg("/", $this->to) || ereg("\\\\", $this->to)) |
---|
288 | { |
---|
289 | echo "Error:slashes"; |
---|
290 | return false; |
---|
291 | } |
---|
292 | elseif(!$this->verifyLock($this->file,RELATIVE_CURRENT)) |
---|
293 | echo "Error:editing"; |
---|
294 | elseif ($this->bo->vfs->mv(array( |
---|
295 | 'from' => $this->path.'/'.$this->file, |
---|
296 | 'to' => $this->path.'/'.$this->to, |
---|
297 | 'relatives' => array(RELATIVE_NONE,RELATIVE_NONE) |
---|
298 | ))) |
---|
299 | { |
---|
300 | echo "True:".$this->file.":".$this->to; |
---|
301 | } |
---|
302 | else |
---|
303 | { |
---|
304 | echo "Error:".$this->file.":".$this->to; |
---|
305 | } |
---|
306 | } |
---|
307 | } |
---|
308 | |
---|
309 | } |
---|