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 | ); |
---|
29 | |
---|
30 | //keep |
---|
31 | var $bo; |
---|
32 | var $dispath; |
---|
33 | var $cwd; |
---|
34 | var $lesspath; |
---|
35 | var $dispsep; |
---|
36 | |
---|
37 | var $target; |
---|
38 | |
---|
39 | var $prefs;//array |
---|
40 | |
---|
41 | var $current_config; |
---|
42 | // this ones must be checked thorougly; |
---|
43 | var $fileman = Array(); |
---|
44 | //var $fileman; |
---|
45 | var $path; |
---|
46 | var $file; |
---|
47 | var $debug = false; |
---|
48 | var $now; |
---|
49 | |
---|
50 | function vfs_functions() |
---|
51 | { |
---|
52 | $this->now = date('Y-m-d'); |
---|
53 | |
---|
54 | $this->bo = CreateObject('filemanager.bofilemanager'); |
---|
55 | |
---|
56 | $c = CreateObject('phpgwapi.config','filemanager'); |
---|
57 | $c->read_repository(); |
---|
58 | $this->current_config = $c->config_data; |
---|
59 | |
---|
60 | |
---|
61 | // here local vars are created from the HTTP vars |
---|
62 | @reset($GLOBALS['HTTP_POST_VARS']); |
---|
63 | while(list($name,) = @each($GLOBALS['HTTP_POST_VARS'])) |
---|
64 | { |
---|
65 | $this->$name = $GLOBALS['HTTP_POST_VARS'][$name]; |
---|
66 | } |
---|
67 | |
---|
68 | @reset($GLOBALS['HTTP_GET_VARS']); |
---|
69 | while(list($name,) = @each($GLOBALS['HTTP_GET_VARS'])) |
---|
70 | { |
---|
71 | $$name = $GLOBALS['HTTP_GET_VARS'][$name]; |
---|
72 | $this->$name = $GLOBALS['HTTP_GET_VARS'][$name]; |
---|
73 | |
---|
74 | } |
---|
75 | |
---|
76 | $to_decode = array |
---|
77 | ( |
---|
78 | 'op' => array('op' => ''), |
---|
79 | 'path' => array('path' => ''), |
---|
80 | 'file' => array('file' => ''), |
---|
81 | 'sortby' => array('sortby' => ''), |
---|
82 | 'messages' => array('messages' => ''), |
---|
83 | 'comment' => array('comment' => ''), |
---|
84 | 'to' => array('to' => '') |
---|
85 | ); |
---|
86 | |
---|
87 | reset($to_decode); |
---|
88 | while(list($var, $conditions) = each($to_decode)) |
---|
89 | { |
---|
90 | while(list($condvar, $condvalue) = each($conditions)) |
---|
91 | { |
---|
92 | if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue)) |
---|
93 | { |
---|
94 | if(is_array($$var)) |
---|
95 | { |
---|
96 | $temp = array(); |
---|
97 | while(list($varkey, $varvalue) = each($$var)) |
---|
98 | { |
---|
99 | if(is_int($varkey)) |
---|
100 | { |
---|
101 | $temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue)))); |
---|
102 | } |
---|
103 | else |
---|
104 | { |
---|
105 | $temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue; |
---|
106 | } |
---|
107 | } |
---|
108 | $this->$var = $temp; |
---|
109 | } |
---|
110 | elseif(isset($$var)) |
---|
111 | { |
---|
112 | $this->$var = stripslashes(base64_decode(urldecode($$var))); |
---|
113 | } |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | // get appl. and user prefs |
---|
119 | $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']); |
---|
120 | $pref->read_repository(); |
---|
121 | $pref->save_repository(True); |
---|
122 | $pref_array = $pref->read_repository(); |
---|
123 | $this->prefs = $pref_array[$this->bo->appname]; |
---|
124 | |
---|
125 | //always show name |
---|
126 | |
---|
127 | $this->prefs[name] =1; |
---|
128 | |
---|
129 | } |
---|
130 | // String format is YYYY-MM-DD HH:MM |
---|
131 | function dateString2timeStamp($string){ |
---|
132 | return mktime($string[11].$string[12], |
---|
133 | $string[14].$string[15], |
---|
134 | $string[17].$string[18], |
---|
135 | $string[5].$string[6], |
---|
136 | $string[8].$string[9], |
---|
137 | $string[0].$string[1]. |
---|
138 | $string[2].$string[3]); |
---|
139 | } |
---|
140 | function verifyLock($file,$relative){ |
---|
141 | $ls_array = $this->bo->vfs->ls(array( |
---|
142 | 'string' => $file, |
---|
143 | 'relatives' => array($relative), |
---|
144 | 'checksubdirs' => False, |
---|
145 | 'nofiles' => True |
---|
146 | )); |
---|
147 | $timestamp = $this->dateString2timeStamp($ls_array[0]['modified']); |
---|
148 | if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']) // recently than last minute: someone is editing |
---|
149 | { |
---|
150 | $this->messages[]=lang('Error:').lang('This file is being edited right now by:').$GLOBALS['phpgw']->accounts->id2name($ls_array[0]['modifiedby_id']); |
---|
151 | return False; |
---|
152 | |
---|
153 | } |
---|
154 | else |
---|
155 | return True; |
---|
156 | } |
---|
157 | |
---|
158 | function setRestricted(){ |
---|
159 | $GLOBALS['phpgw_info']['flags'] = array |
---|
160 | ( |
---|
161 | 'currentapp' => 'filemanager', |
---|
162 | 'noheader' => True, |
---|
163 | 'nonavbar' => True, |
---|
164 | 'nofooter' => True, |
---|
165 | 'noappheader' => True, |
---|
166 | 'enable_browser_class' => True |
---|
167 | ); |
---|
168 | |
---|
169 | if ($this->file) |
---|
170 | { |
---|
171 | $filename=$this->path.'/'.$this->file; |
---|
172 | if(!$this->verifyLock($filename,RELATIVE_NONE)) |
---|
173 | { |
---|
174 | echo "False"; |
---|
175 | return False; |
---|
176 | } |
---|
177 | |
---|
178 | $ls_array = $this->bo->vfs->ls(array( |
---|
179 | 'string' => $filename, |
---|
180 | 'relatives' => array(RELATIVE_NONE), |
---|
181 | 'checksubdirs' => False, |
---|
182 | 'nofiles' => True |
---|
183 | )); |
---|
184 | if (intval($ls_array[0]['type']) == 0) |
---|
185 | $type = 1; |
---|
186 | else |
---|
187 | $type = 0; |
---|
188 | |
---|
189 | if($this->bo->vfs->set_attributes (array( |
---|
190 | 'string' => $filename, |
---|
191 | 'relatives' => RELATIVE_NONE, |
---|
192 | 'attributes' => array('type' => $type) |
---|
193 | )) |
---|
194 | ) |
---|
195 | { |
---|
196 | echo "True:".$this->file; |
---|
197 | } |
---|
198 | else |
---|
199 | { |
---|
200 | echo "False"; |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | } |
---|
205 | function touch(){ |
---|
206 | if($this->file) |
---|
207 | if ($this->bo->vfs->touch(array('string'=> $this->file,'relatives' => array(RELATIVE_ALL)))) |
---|
208 | { |
---|
209 | echo "True"; |
---|
210 | return True; |
---|
211 | } |
---|
212 | else |
---|
213 | return False; |
---|
214 | |
---|
215 | } |
---|
216 | function download() |
---|
217 | { |
---|
218 | if($this->file) |
---|
219 | { |
---|
220 | //$GLOBALS['phpgw']->browser->content_header($this->file); |
---|
221 | header ("Content-Type: application/octet-stream"); |
---|
222 | header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); |
---|
223 | header("Pragma: public"); |
---|
224 | header("Expires: 0"); |
---|
225 | header ("Content-Disposition: attachment; filename=\"". addslashes($this->file)."\""); |
---|
226 | echo $this->bo->vfs->read(array('string' => $this->file)); |
---|
227 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
228 | } |
---|
229 | } |
---|
230 | function delete(){ |
---|
231 | foreach($this->fileman as $filename) |
---|
232 | { |
---|
233 | if($this->verifyLock($filename,RELATIVE_ALL) && $this->bo->vfs->delete(array('string' => $filename))) |
---|
234 | { |
---|
235 | echo $filename.":"; |
---|
236 | } |
---|
237 | else |
---|
238 | { |
---|
239 | echo "False:".$filename; |
---|
240 | return False; |
---|
241 | } |
---|
242 | } |
---|
243 | } |
---|
244 | function editComment() |
---|
245 | { |
---|
246 | if($badchar = $this->bo->bad_chars($this->comment, False, True)) |
---|
247 | { |
---|
248 | echo "False:badchar:".$badchar; |
---|
249 | return False; |
---|
250 | } |
---|
251 | |
---|
252 | if ($this->bo->vfs->set_attributes(array( |
---|
253 | 'string' => $this->file, |
---|
254 | 'relatives' => array(RELATIVE_ALL), |
---|
255 | 'attributes' => array( |
---|
256 | 'comment' => stripslashes($this->comment) |
---|
257 | ) |
---|
258 | ))) |
---|
259 | { |
---|
260 | echo "True:".$this->file; |
---|
261 | return True; |
---|
262 | } |
---|
263 | } |
---|
264 | # Handle Renaming Files and Directories |
---|
265 | function rename() |
---|
266 | { |
---|
267 | if ($this->file) |
---|
268 | { |
---|
269 | if($badchar = $this->bo->bad_chars($this->to, True, True)) |
---|
270 | { |
---|
271 | echo "Error:badchar:".$badchar; |
---|
272 | return false; |
---|
273 | } |
---|
274 | if(ereg("/", $this->to) || ereg("\\\\", $this->to)) |
---|
275 | { |
---|
276 | echo "Error:slashes"; |
---|
277 | return false; |
---|
278 | } |
---|
279 | elseif(!$this->verifyLock($this->file,RELATIVE_CURRENT)) |
---|
280 | echo "Error:editing"; |
---|
281 | elseif ($this->bo->vfs->mv(array( |
---|
282 | 'from' => $this->path.'/'.$this->file, |
---|
283 | 'to' => $this->path.'/'.$this->to, |
---|
284 | 'relatives' => array(RELATIVE_NONE,RELATIVE_NONE) |
---|
285 | ))) |
---|
286 | { |
---|
287 | echo "True:".$this->file.":".$this->to; |
---|
288 | } |
---|
289 | else |
---|
290 | { |
---|
291 | echo "Error:".$this->file.":".$this->to; |
---|
292 | } |
---|
293 | } |
---|
294 | } |
---|
295 | |
---|
296 | } |
---|