@@ -12,23 +12,29 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class browser extends uploader { |
|
15 | +class browser extends uploader |
|
16 | +{ |
|
16 | 17 | protected $action; |
17 | 18 | protected $thumbsDir; |
18 | 19 | protected $thumbsTypeDir; |
19 | 20 | |
20 | - public function __construct($modx) { |
|
21 | + public function __construct($modx) |
|
22 | + { |
|
21 | 23 | parent::__construct($modx); |
22 | 24 | |
23 | 25 | if (isset($this->post['dir'])) { |
24 | 26 | $dir = $this->checkInputDir($this->post['dir'], true, false); |
25 | - if ($dir === false) unset($this->post['dir']); |
|
27 | + if ($dir === false) { |
|
28 | + unset($this->post['dir']); |
|
29 | + } |
|
26 | 30 | $this->post['dir'] = $dir; |
27 | 31 | } |
28 | 32 | |
29 | 33 | if (isset($this->get['dir'])) { |
30 | 34 | $dir = $this->checkInputDir($this->get['dir'], true, false); |
31 | - if ($dir === false) unset($this->get['dir']); |
|
35 | + if ($dir === false) { |
|
36 | + unset($this->get['dir']); |
|
37 | + } |
|
32 | 38 | $this->get['dir'] = $dir; |
33 | 39 | } |
34 | 40 | |
@@ -44,8 +50,9 @@ discard block |
||
44 | 50 | !is_dir("$thumbsDir/{$this->type}") && |
45 | 51 | !@mkdir("$thumbsDir/{$this->type}", $this->config['dirPerms']) |
46 | 52 | ) |
47 | - ) |
|
48 | - $this->errorMsg("Cannot access or create thumbnails folder."); |
|
53 | + ) { |
|
54 | + $this->errorMsg("Cannot access or create thumbnails folder."); |
|
55 | + } |
|
49 | 56 | |
50 | 57 | $this->thumbsDir = $thumbsDir; |
51 | 58 | $this->thumbsTypeDir = "$thumbsDir/{$this->type}"; |
@@ -58,23 +65,29 @@ discard block |
||
58 | 65 | |
59 | 66 | if (is_array($files) && count($files)) { |
60 | 67 | $time = time(); |
61 | - foreach ($files as $file) |
|
62 | - if (is_file($file) && ($time - filemtime($file) > 3600)) |
|
68 | + foreach ($files as $file) { |
|
69 | + if (is_file($file) && ($time - filemtime($file) > 3600)) |
|
63 | 70 | unlink($file); |
71 | + } |
|
64 | 72 | } |
65 | 73 | |
66 | 74 | if (isset($this->get['theme']) && |
67 | 75 | ($this->get['theme'] == basename($this->get['theme'])) && |
68 | 76 | is_dir("themes/{$this->get['theme']}") |
69 | - ) |
|
70 | - $this->config['theme'] = $this->get['theme']; |
|
77 | + ) { |
|
78 | + $this->config['theme'] = $this->get['theme']; |
|
79 | + } |
|
71 | 80 | } |
72 | 81 | |
73 | - public function action() { |
|
82 | + public function action() |
|
83 | + { |
|
74 | 84 | $act = isset($this->get['act']) ? $this->get['act'] : "browser"; |
75 | - if(!preg_match('@^[0-9a-zA-Z_]+$@', $act)) $this->errorMsg("Unknown error."); |
|
76 | - if (!method_exists($this, "act_$act")) |
|
77 | - $act = "browser"; |
|
85 | + if(!preg_match('@^[0-9a-zA-Z_]+$@', $act)) { |
|
86 | + $this->errorMsg("Unknown error."); |
|
87 | + } |
|
88 | + if (!method_exists($this, "act_$act")) { |
|
89 | + $act = "browser"; |
|
90 | + } |
|
78 | 91 | $this->action = $act; |
79 | 92 | $method = "act_$act"; |
80 | 93 | |
@@ -82,21 +95,22 @@ discard block |
||
82 | 95 | $message = $this->label("You don't have permissions to browse server."); |
83 | 96 | if (in_array($act, array("browser", "upload")) || |
84 | 97 | (substr($act, 0, 8) == "download") |
85 | - ) |
|
86 | - $this->backMsg($message); |
|
87 | - else { |
|
98 | + ) { |
|
99 | + $this->backMsg($message); |
|
100 | + } else { |
|
88 | 101 | header("Content-Type: text/plain; charset={$this->charset}"); |
89 | 102 | die(json_encode(array('error' => $message))); |
90 | 103 | } |
91 | 104 | } |
92 | 105 | |
93 | - if (!isset($this->session['dir'])) |
|
94 | - $this->session['dir'] = $this->type; |
|
95 | - else { |
|
106 | + if (!isset($this->session['dir'])) { |
|
107 | + $this->session['dir'] = $this->type; |
|
108 | + } else { |
|
96 | 109 | $type = $this->getTypeFromPath($this->session['dir']); |
97 | 110 | $dir = $this->config['uploadDir'] . "/" . $this->session['dir']; |
98 | - if (($type != $this->type) || !is_dir($dir) || !is_readable($dir)) |
|
99 | - $this->session['dir'] = $this->type; |
|
111 | + if (($type != $this->type) || !is_dir($dir) || !is_readable($dir)) { |
|
112 | + $this->session['dir'] = $this->type; |
|
113 | + } |
|
100 | 114 | } |
101 | 115 | $this->session['dir'] = path::normalize($this->session['dir']); |
102 | 116 | |
@@ -106,8 +120,9 @@ discard block |
||
106 | 120 | } elseif ( |
107 | 121 | (substr($act, 0, 8) != "download") && |
108 | 122 | !in_array($act, array("thumb", "upload")) |
109 | - ) |
|
110 | - header("Content-Type: text/plain; charset={$this->charset}"); |
|
123 | + ) { |
|
124 | + header("Content-Type: text/plain; charset={$this->charset}"); |
|
125 | + } |
|
111 | 126 | |
112 | 127 | $return = $this->$method(); |
113 | 128 | echo ($return === true) |
@@ -115,21 +130,25 @@ discard block |
||
115 | 130 | : $return; |
116 | 131 | } |
117 | 132 | |
118 | - protected function act_browser() { |
|
133 | + protected function act_browser() |
|
134 | + { |
|
119 | 135 | if (isset($this->get['dir']) && |
120 | 136 | is_dir("{$this->typeDir}/{$this->get['dir']}") && |
121 | 137 | is_readable("{$this->typeDir}/{$this->get['dir']}") |
122 | - ) |
|
123 | - $this->session['dir'] = path::normalize("{$this->type}/{$this->get['dir']}"); |
|
138 | + ) { |
|
139 | + $this->session['dir'] = path::normalize("{$this->type}/{$this->get['dir']}"); |
|
140 | + } |
|
124 | 141 | |
125 | 142 | return $this->output(); |
126 | 143 | } |
127 | 144 | |
128 | - protected function act_init() { |
|
145 | + protected function act_init() |
|
146 | + { |
|
129 | 147 | $tree = $this->getDirInfo($this->typeDir); |
130 | 148 | $tree['dirs'] = $this->getTree($this->session['dir']); |
131 | - if (!is_array($tree['dirs']) || !count($tree['dirs'])) |
|
132 | - unset($tree['dirs']); |
|
149 | + if (!is_array($tree['dirs']) || !count($tree['dirs'])) { |
|
150 | + unset($tree['dirs']); |
|
151 | + } |
|
133 | 152 | $files = $this->getFiles($this->session['dir']); |
134 | 153 | $dirWritable = dir::isWritable("{$this->config['uploadDir']}/{$this->session['dir']}"); |
135 | 154 | $data = array( |
@@ -140,21 +159,26 @@ discard block |
||
140 | 159 | return json_encode($data); |
141 | 160 | } |
142 | 161 | |
143 | - protected function act_thumb() { |
|
162 | + protected function act_thumb() |
|
163 | + { |
|
144 | 164 | $this->getDir($this->get['dir'], true); |
145 | - if (!isset($this->get['file']) || !isset($this->get['dir'])) |
|
146 | - $this->sendDefaultThumb(); |
|
165 | + if (!isset($this->get['file']) || !isset($this->get['dir'])) { |
|
166 | + $this->sendDefaultThumb(); |
|
167 | + } |
|
147 | 168 | $file = $this->get['file']; |
148 | - if (basename($file) != $file) |
|
149 | - $this->sendDefaultThumb(); |
|
169 | + if (basename($file) != $file) { |
|
170 | + $this->sendDefaultThumb(); |
|
171 | + } |
|
150 | 172 | $file = "{$this->thumbsDir}/{$this->type}/{$this->get['dir']}/$file"; |
151 | 173 | if (!is_file($file) || !is_readable($file)) { |
152 | 174 | $file = "{$this->config['uploadDir']}/{$this->type}/{$this->get['dir']}/" . basename($file); |
153 | - if (!is_file($file) || !is_readable($file)) |
|
154 | - $this->sendDefaultThumb($file); |
|
175 | + if (!is_file($file) || !is_readable($file)) { |
|
176 | + $this->sendDefaultThumb($file); |
|
177 | + } |
|
155 | 178 | $image = image::factory($this->imageDriver, $file); |
156 | - if ($image->initError) |
|
157 | - $this->sendDefaultThumb($file); |
|
179 | + if ($image->initError) { |
|
180 | + $this->sendDefaultThumb($file); |
|
181 | + } |
|
158 | 182 | list($tmp, $tmp, $type) = getimagesize($file); |
159 | 183 | if (in_array($type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)) && |
160 | 184 | ($image->width <= $this->config['thumbWidth']) && |
@@ -165,17 +189,20 @@ discard block |
||
165 | 189 | ($type == IMAGETYPE_PNG) ? "png" : "jpeg"); |
166 | 190 | $mime = "image/$mime"; |
167 | 191 | httpCache::file($file, $mime); |
168 | - } else |
|
169 | - $this->sendDefaultThumb($file); |
|
192 | + } else { |
|
193 | + $this->sendDefaultThumb($file); |
|
194 | + } |
|
170 | 195 | } |
171 | 196 | httpCache::file($file, "image/jpeg"); |
172 | 197 | } |
173 | 198 | |
174 | - protected function act_expand() { |
|
199 | + protected function act_expand() |
|
200 | + { |
|
175 | 201 | return json_encode(array('dirs' => $this->getDirs($this->postDir()))); |
176 | 202 | } |
177 | 203 | |
178 | - protected function act_chDir() { |
|
204 | + protected function act_chDir() |
|
205 | + { |
|
179 | 206 | $this->postDir(); // Just for existing check |
180 | 207 | $this->session['dir'] = $this->type . "/" . $this->post['dir']; |
181 | 208 | $dirWritable = dir::isWritable("{$this->config['uploadDir']}/{$this->session['dir']}"); |
@@ -185,81 +212,104 @@ discard block |
||
185 | 212 | )); |
186 | 213 | } |
187 | 214 | |
188 | - protected function act_newDir() { |
|
215 | + protected function act_newDir() |
|
216 | + { |
|
189 | 217 | if (!$this->config['access']['dirs']['create'] || |
190 | 218 | !isset($this->post['dir']) || |
191 | 219 | !isset($this->post['newDir']) |
192 | - ) |
|
193 | - $this->errorMsg("Unknown error."); |
|
220 | + ) { |
|
221 | + $this->errorMsg("Unknown error."); |
|
222 | + } |
|
194 | 223 | |
195 | 224 | $dir = $this->postDir(); |
196 | 225 | $newDir = $this->normalizeDirname(trim($this->post['newDir'])); |
197 | - if (!strlen($newDir)) |
|
198 | - $this->errorMsg("Please enter new folder name."); |
|
199 | - if (preg_match('/[\/\\\\]/s', $newDir)) |
|
200 | - $this->errorMsg("Unallowable characters in folder name."); |
|
201 | - if (substr($newDir, 0, 1) == ".") |
|
202 | - $this->errorMsg("Folder name shouldn't begins with '.'"); |
|
203 | - if (file_exists("$dir/$newDir")) |
|
204 | - $this->errorMsg("A file or folder with that name already exists."); |
|
205 | - if (!@mkdir("$dir/$newDir", $this->config['dirPerms'])) |
|
206 | - $this->errorMsg("Cannot create {dir} folder.", array('dir' => $newDir)); |
|
226 | + if (!strlen($newDir)) { |
|
227 | + $this->errorMsg("Please enter new folder name."); |
|
228 | + } |
|
229 | + if (preg_match('/[\/\\\\]/s', $newDir)) { |
|
230 | + $this->errorMsg("Unallowable characters in folder name."); |
|
231 | + } |
|
232 | + if (substr($newDir, 0, 1) == ".") { |
|
233 | + $this->errorMsg("Folder name shouldn't begins with '.'"); |
|
234 | + } |
|
235 | + if (file_exists("$dir/$newDir")) { |
|
236 | + $this->errorMsg("A file or folder with that name already exists."); |
|
237 | + } |
|
238 | + if (!@mkdir("$dir/$newDir", $this->config['dirPerms'])) { |
|
239 | + $this->errorMsg("Cannot create {dir} folder.", array('dir' => $newDir)); |
|
240 | + } |
|
207 | 241 | return true; |
208 | 242 | } |
209 | 243 | |
210 | - protected function act_renameDir() { |
|
244 | + protected function act_renameDir() |
|
245 | + { |
|
211 | 246 | if (!$this->config['access']['dirs']['rename'] || |
212 | 247 | !isset($this->post['dir']) || |
213 | 248 | !isset($this->post['newName']) |
214 | - ) |
|
215 | - $this->errorMsg("Unknown error."); |
|
249 | + ) { |
|
250 | + $this->errorMsg("Unknown error."); |
|
251 | + } |
|
216 | 252 | |
217 | 253 | $dir = $this->postDir(); |
218 | 254 | $newName = $this->normalizeDirname(trim($this->post['newName'])); |
219 | - if (!strlen($newName)) |
|
220 | - $this->errorMsg("Please enter new folder name."); |
|
221 | - if (preg_match('/[\/\\\\]/s', $newName)) |
|
222 | - $this->errorMsg("Unallowable characters in folder name."); |
|
223 | - if (substr($newName, 0, 1) == ".") |
|
224 | - $this->errorMsg("Folder name shouldn't begins with '.'"); |
|
225 | - if (!@rename($dir, dirname($dir) . "/$newName")) |
|
226 | - $this->errorMsg("Cannot rename the folder."); |
|
255 | + if (!strlen($newName)) { |
|
256 | + $this->errorMsg("Please enter new folder name."); |
|
257 | + } |
|
258 | + if (preg_match('/[\/\\\\]/s', $newName)) { |
|
259 | + $this->errorMsg("Unallowable characters in folder name."); |
|
260 | + } |
|
261 | + if (substr($newName, 0, 1) == ".") { |
|
262 | + $this->errorMsg("Folder name shouldn't begins with '.'"); |
|
263 | + } |
|
264 | + if (!@rename($dir, dirname($dir) . "/$newName")) { |
|
265 | + $this->errorMsg("Cannot rename the folder."); |
|
266 | + } |
|
227 | 267 | $thumbDir = "$this->thumbsTypeDir/{$this->post['dir']}"; |
228 | - if (is_dir($thumbDir)) |
|
229 | - @rename($thumbDir, dirname($thumbDir) . "/$newName"); |
|
268 | + if (is_dir($thumbDir)) { |
|
269 | + @rename($thumbDir, dirname($thumbDir) . "/$newName"); |
|
270 | + } |
|
230 | 271 | return json_encode(array('name' => $newName)); |
231 | 272 | } |
232 | 273 | |
233 | - protected function act_deleteDir() { |
|
274 | + protected function act_deleteDir() |
|
275 | + { |
|
234 | 276 | if (!$this->config['access']['dirs']['delete'] || |
235 | 277 | !isset($this->post['dir']) || |
236 | 278 | !strlen(trim($this->post['dir'])) |
237 | - ) |
|
238 | - $this->errorMsg("Unknown error."); |
|
279 | + ) { |
|
280 | + $this->errorMsg("Unknown error."); |
|
281 | + } |
|
239 | 282 | |
240 | 283 | $dir = $this->postDir(); |
241 | 284 | |
242 | - if (!dir::isWritable($dir)) |
|
243 | - $this->errorMsg("Cannot delete the folder."); |
|
285 | + if (!dir::isWritable($dir)) { |
|
286 | + $this->errorMsg("Cannot delete the folder."); |
|
287 | + } |
|
244 | 288 | $result = !dir::prune($dir, false); |
245 | - if (is_array($result) && count($result)) |
|
246 | - $this->errorMsg("Failed to delete {count} files/folders.", |
|
289 | + if (is_array($result) && count($result)) { |
|
290 | + $this->errorMsg("Failed to delete {count} files/folders.", |
|
247 | 291 | array('count' => count($result))); |
292 | + } |
|
248 | 293 | $thumbDir = "$this->thumbsTypeDir/{$this->post['dir']}"; |
249 | - if (is_dir($thumbDir)) dir::prune($thumbDir); |
|
294 | + if (is_dir($thumbDir)) { |
|
295 | + dir::prune($thumbDir); |
|
296 | + } |
|
250 | 297 | return true; |
251 | 298 | } |
252 | 299 | |
253 | - protected function act_upload() { |
|
300 | + protected function act_upload() |
|
301 | + { |
|
254 | 302 | if (!$this->config['access']['files']['upload'] || |
255 | 303 | !isset($this->post['dir']) |
256 | - ) |
|
257 | - $this->errorMsg("Unknown error."); |
|
304 | + ) { |
|
305 | + $this->errorMsg("Unknown error."); |
|
306 | + } |
|
258 | 307 | |
259 | 308 | $dir = $this->postDir(); |
260 | 309 | |
261 | - if (!dir::isWritable($dir)) |
|
262 | - $this->errorMsg("Cannot access or write to upload folder."); |
|
310 | + if (!dir::isWritable($dir)) { |
|
311 | + $this->errorMsg("Cannot access or write to upload folder."); |
|
312 | + } |
|
263 | 313 | |
264 | 314 | if (is_array($this->file['name'])) { |
265 | 315 | $return = array(); |
@@ -271,19 +321,22 @@ discard block |
||
271 | 321 | ), $dir); |
272 | 322 | } |
273 | 323 | return implode("\n", $return); |
274 | - } else |
|
275 | - return $this->moveUploadFile($this->file, $dir); |
|
324 | + } else { |
|
325 | + return $this->moveUploadFile($this->file, $dir); |
|
326 | + } |
|
276 | 327 | } |
277 | 328 | |
278 | - protected function act_download() { |
|
329 | + protected function act_download() |
|
330 | + { |
|
279 | 331 | $dir = $this->postDir(); |
280 | 332 | if (!isset($this->post['dir']) || |
281 | 333 | !isset($this->post['file']) || |
282 | 334 | strpos($this->post['file'],'../')!==false || |
283 | 335 | (false === ($file = "$dir/{$this->post['file']}")) || |
284 | 336 | !file_exists($file) || !is_readable($file) |
285 | - ) |
|
286 | - $this->errorMsg("Unknown error."); |
|
337 | + ) { |
|
338 | + $this->errorMsg("Unknown error."); |
|
339 | + } |
|
287 | 340 | |
288 | 341 | header("Pragma: public"); |
289 | 342 | header("Expires: 0"); |
@@ -297,7 +350,8 @@ discard block |
||
297 | 350 | die; |
298 | 351 | } |
299 | 352 | |
300 | - protected function act_rename() { |
|
353 | + protected function act_rename() |
|
354 | + { |
|
301 | 355 | $dir = $this->postDir(); |
302 | 356 | if (!$this->config['access']['files']['rename'] || |
303 | 357 | !isset($this->post['dir']) || |
@@ -306,42 +360,52 @@ discard block |
||
306 | 360 | !isset($this->post['newName']) || |
307 | 361 | (false === ($file = "$dir/{$this->post['file']}")) || |
308 | 362 | !file_exists($file) || !is_readable($file) || !file::isWritable($file) |
309 | - ) |
|
310 | - $this->errorMsg("Unknown error."); |
|
363 | + ) { |
|
364 | + $this->errorMsg("Unknown error."); |
|
365 | + } |
|
311 | 366 | |
312 | 367 | if (isset($this->config['denyExtensionRename']) && |
313 | 368 | $this->config['denyExtensionRename'] && |
314 | 369 | (file::getExtension($this->post['file'], true) !== |
315 | 370 | file::getExtension($this->post['newName'], true) |
316 | 371 | ) |
317 | - ) |
|
318 | - $this->errorMsg("You cannot rename the extension of files!"); |
|
372 | + ) { |
|
373 | + $this->errorMsg("You cannot rename the extension of files!"); |
|
374 | + } |
|
319 | 375 | |
320 | 376 | $newName = $this->normalizeFilename(trim($this->post['newName'])); |
321 | - if (!strlen($newName)) |
|
322 | - $this->errorMsg("Please enter new file name."); |
|
323 | - if (preg_match('/[\/\\\\]/s', $newName)) |
|
324 | - $this->errorMsg("Unallowable characters in file name."); |
|
325 | - if (substr($newName, 0, 1) == ".") |
|
326 | - $this->errorMsg("File name shouldn't begins with '.'"); |
|
377 | + if (!strlen($newName)) { |
|
378 | + $this->errorMsg("Please enter new file name."); |
|
379 | + } |
|
380 | + if (preg_match('/[\/\\\\]/s', $newName)) { |
|
381 | + $this->errorMsg("Unallowable characters in file name."); |
|
382 | + } |
|
383 | + if (substr($newName, 0, 1) == ".") { |
|
384 | + $this->errorMsg("File name shouldn't begins with '.'"); |
|
385 | + } |
|
327 | 386 | $newName = "$dir/$newName"; |
328 | - if (file_exists($newName)) |
|
329 | - $this->errorMsg("A file or folder with that name already exists."); |
|
387 | + if (file_exists($newName)) { |
|
388 | + $this->errorMsg("A file or folder with that name already exists."); |
|
389 | + } |
|
330 | 390 | $ext = file::getExtension($newName); |
331 | - if (!$this->validateExtension($ext, $this->type)) |
|
332 | - $this->errorMsg("Denied file extension."); |
|
333 | - if (!@rename($file, $newName)) |
|
334 | - $this->errorMsg("Unknown error."); |
|
391 | + if (!$this->validateExtension($ext, $this->type)) { |
|
392 | + $this->errorMsg("Denied file extension."); |
|
393 | + } |
|
394 | + if (!@rename($file, $newName)) { |
|
395 | + $this->errorMsg("Unknown error."); |
|
396 | + } |
|
335 | 397 | |
336 | 398 | $thumbDir = "{$this->thumbsTypeDir}/{$this->post['dir']}"; |
337 | 399 | $thumbFile = "$thumbDir/{$this->post['file']}"; |
338 | 400 | |
339 | - if (file_exists($thumbFile)) |
|
340 | - @rename($thumbFile, "$thumbDir/" . basename($newName)); |
|
401 | + if (file_exists($thumbFile)) { |
|
402 | + @rename($thumbFile, "$thumbDir/" . basename($newName)); |
|
403 | + } |
|
341 | 404 | return true; |
342 | 405 | } |
343 | 406 | |
344 | - protected function act_delete() { |
|
407 | + protected function act_delete() |
|
408 | + { |
|
345 | 409 | $dir = $this->postDir(); |
346 | 410 | if (!$this->config['access']['files']['delete'] || |
347 | 411 | !isset($this->post['dir']) || |
@@ -350,152 +414,184 @@ discard block |
||
350 | 414 | (false === ($file = "$dir/{$this->post['file']}")) || |
351 | 415 | !file_exists($file) || !is_readable($file) || !file::isWritable($file) || |
352 | 416 | !@unlink($file) |
353 | - ) |
|
354 | - $this->errorMsg("Unknown error."); |
|
417 | + ) { |
|
418 | + $this->errorMsg("Unknown error."); |
|
419 | + } |
|
355 | 420 | |
356 | 421 | $thumb = "{$this->thumbsTypeDir}/{$this->post['dir']}/{$this->post['file']}"; |
357 | - if (file_exists($thumb)) @unlink($thumb); |
|
422 | + if (file_exists($thumb)) { |
|
423 | + @unlink($thumb); |
|
424 | + } |
|
358 | 425 | return true; |
359 | 426 | } |
360 | 427 | |
361 | - protected function act_cp_cbd() { |
|
428 | + protected function act_cp_cbd() |
|
429 | + { |
|
362 | 430 | $dir = $this->postDir(); |
363 | 431 | if (!$this->config['access']['files']['copy'] || |
364 | 432 | !isset($this->post['dir']) || |
365 | 433 | !is_dir($dir) || !is_readable($dir) || !dir::isWritable($dir) || |
366 | 434 | !isset($this->post['files']) || !is_array($this->post['files']) || |
367 | 435 | !count($this->post['files']) |
368 | - ) |
|
369 | - $this->errorMsg("Unknown error."); |
|
436 | + ) { |
|
437 | + $this->errorMsg("Unknown error."); |
|
438 | + } |
|
370 | 439 | |
371 | 440 | $error = array(); |
372 | 441 | foreach($this->post['files'] as $file) { |
373 | 442 | $file = path::normalize($file); |
374 | - if (substr($file, 0, 1) == ".") continue; |
|
443 | + if (substr($file, 0, 1) == ".") { |
|
444 | + continue; |
|
445 | + } |
|
375 | 446 | $type = explode("/", $file); |
376 | 447 | $type = $type[0]; |
377 | - if ($type != $this->type) continue; |
|
448 | + if ($type != $this->type) { |
|
449 | + continue; |
|
450 | + } |
|
378 | 451 | $path = "{$this->config['uploadDir']}/$file"; |
379 | 452 | $base = basename($file); |
380 | 453 | $replace = array('file' => $base); |
381 | 454 | $ext = file::getExtension($base); |
382 | - if (!file_exists($path)) |
|
383 | - $error[] = $this->label("The file '{file}' does not exist.", $replace); |
|
384 | - elseif (substr($base, 0, 1) == ".") |
|
385 | - $error[] = "$base: " . $this->label("File name shouldn't begins with '.'"); |
|
386 | - elseif (!$this->validateExtension($ext, $type)) |
|
387 | - $error[] = "$base: " . $this->label("Denied file extension."); |
|
388 | - elseif (file_exists("$dir/$base")) |
|
389 | - $error[] = "$base: " . $this->label("A file or folder with that name already exists."); |
|
390 | - elseif (!is_readable($path) || !is_file($path)) |
|
391 | - $error[] = $this->label("Cannot read '{file}'.", $replace); |
|
392 | - elseif (!@copy($path, "$dir/$base")) |
|
393 | - $error[] = $this->label("Cannot copy '{file}'.", $replace); |
|
394 | - else { |
|
395 | - if (function_exists("chmod")) |
|
396 | - @chmod("$dir/$base", $this->config['filePerms']); |
|
455 | + if (!file_exists($path)) { |
|
456 | + $error[] = $this->label("The file '{file}' does not exist.", $replace); |
|
457 | + } elseif (substr($base, 0, 1) == ".") { |
|
458 | + $error[] = "$base: " . $this->label("File name shouldn't begins with '.'"); |
|
459 | + } elseif (!$this->validateExtension($ext, $type)) { |
|
460 | + $error[] = "$base: " . $this->label("Denied file extension."); |
|
461 | + } elseif (file_exists("$dir/$base")) { |
|
462 | + $error[] = "$base: " . $this->label("A file or folder with that name already exists."); |
|
463 | + } elseif (!is_readable($path) || !is_file($path)) { |
|
464 | + $error[] = $this->label("Cannot read '{file}'.", $replace); |
|
465 | + } elseif (!@copy($path, "$dir/$base")) { |
|
466 | + $error[] = $this->label("Cannot copy '{file}'.", $replace); |
|
467 | + } else { |
|
468 | + if (function_exists("chmod")) { |
|
469 | + @chmod("$dir/$base", $this->config['filePerms']); |
|
470 | + } |
|
397 | 471 | $fromThumb = "{$this->thumbsDir}/$file"; |
398 | 472 | if (is_file($fromThumb) && is_readable($fromThumb)) { |
399 | 473 | $toThumb = "{$this->thumbsTypeDir}/{$this->post['dir']}"; |
400 | - if (!is_dir($toThumb)) |
|
401 | - @mkdir($toThumb, $this->config['dirPerms'], true); |
|
474 | + if (!is_dir($toThumb)) { |
|
475 | + @mkdir($toThumb, $this->config['dirPerms'], true); |
|
476 | + } |
|
402 | 477 | $toThumb .= "/$base"; |
403 | 478 | @copy($fromThumb, $toThumb); |
404 | 479 | } |
405 | 480 | } |
406 | 481 | } |
407 | - if (count($error)) |
|
408 | - return json_encode(array('error' => $error)); |
|
482 | + if (count($error)) { |
|
483 | + return json_encode(array('error' => $error)); |
|
484 | + } |
|
409 | 485 | return true; |
410 | 486 | } |
411 | 487 | |
412 | - protected function act_mv_cbd() { |
|
488 | + protected function act_mv_cbd() |
|
489 | + { |
|
413 | 490 | $dir = $this->postDir(); |
414 | 491 | if (!$this->config['access']['files']['move'] || |
415 | 492 | !isset($this->post['dir']) || |
416 | 493 | !is_dir($dir) || !is_readable($dir) || !dir::isWritable($dir) || |
417 | 494 | !isset($this->post['files']) || !is_array($this->post['files']) || |
418 | 495 | !count($this->post['files']) |
419 | - ) |
|
420 | - $this->errorMsg("Unknown error."); |
|
496 | + ) { |
|
497 | + $this->errorMsg("Unknown error."); |
|
498 | + } |
|
421 | 499 | |
422 | 500 | $error = array(); |
423 | 501 | foreach($this->post['files'] as $file) { |
424 | 502 | $file = path::normalize($file); |
425 | - if (substr($file, 0, 1) == ".") continue; |
|
503 | + if (substr($file, 0, 1) == ".") { |
|
504 | + continue; |
|
505 | + } |
|
426 | 506 | $type = explode("/", $file); |
427 | 507 | $type = $type[0]; |
428 | - if ($type != $this->type) continue; |
|
508 | + if ($type != $this->type) { |
|
509 | + continue; |
|
510 | + } |
|
429 | 511 | $path = "{$this->config['uploadDir']}/$file"; |
430 | 512 | $base = basename($file); |
431 | 513 | $replace = array('file' => $base); |
432 | 514 | $ext = file::getExtension($base); |
433 | - if (!file_exists($path)) |
|
434 | - $error[] = $this->label("The file '{file}' does not exist.", $replace); |
|
435 | - elseif (substr($base, 0, 1) == ".") |
|
436 | - $error[] = "$base: " . $this->label("File name shouldn't begins with '.'"); |
|
437 | - elseif (!$this->validateExtension($ext, $type)) |
|
438 | - $error[] = "$base: " . $this->label("Denied file extension."); |
|
439 | - elseif (file_exists("$dir/$base")) |
|
440 | - $error[] = "$base: " . $this->label("A file or folder with that name already exists."); |
|
441 | - elseif (!is_readable($path) || !is_file($path)) |
|
442 | - $error[] = $this->label("Cannot read '{file}'.", $replace); |
|
443 | - elseif (!file::isWritable($path) || !@rename($path, "$dir/$base")) |
|
444 | - $error[] = $this->label("Cannot move '{file}'.", $replace); |
|
445 | - else { |
|
446 | - if (function_exists("chmod")) |
|
447 | - @chmod("$dir/$base", $this->config['filePerms']); |
|
515 | + if (!file_exists($path)) { |
|
516 | + $error[] = $this->label("The file '{file}' does not exist.", $replace); |
|
517 | + } elseif (substr($base, 0, 1) == ".") { |
|
518 | + $error[] = "$base: " . $this->label("File name shouldn't begins with '.'"); |
|
519 | + } elseif (!$this->validateExtension($ext, $type)) { |
|
520 | + $error[] = "$base: " . $this->label("Denied file extension."); |
|
521 | + } elseif (file_exists("$dir/$base")) { |
|
522 | + $error[] = "$base: " . $this->label("A file or folder with that name already exists."); |
|
523 | + } elseif (!is_readable($path) || !is_file($path)) { |
|
524 | + $error[] = $this->label("Cannot read '{file}'.", $replace); |
|
525 | + } elseif (!file::isWritable($path) || !@rename($path, "$dir/$base")) { |
|
526 | + $error[] = $this->label("Cannot move '{file}'.", $replace); |
|
527 | + } else { |
|
528 | + if (function_exists("chmod")) { |
|
529 | + @chmod("$dir/$base", $this->config['filePerms']); |
|
530 | + } |
|
448 | 531 | $fromThumb = "{$this->thumbsDir}/$file"; |
449 | 532 | if (is_file($fromThumb) && is_readable($fromThumb)) { |
450 | 533 | $toThumb = "{$this->thumbsTypeDir}/{$this->post['dir']}"; |
451 | - if (!is_dir($toThumb)) |
|
452 | - @mkdir($toThumb, $this->config['dirPerms'], true); |
|
534 | + if (!is_dir($toThumb)) { |
|
535 | + @mkdir($toThumb, $this->config['dirPerms'], true); |
|
536 | + } |
|
453 | 537 | $toThumb .= "/$base"; |
454 | 538 | @rename($fromThumb, $toThumb); |
455 | 539 | } |
456 | 540 | } |
457 | 541 | } |
458 | - if (count($error)) |
|
459 | - return json_encode(array('error' => $error)); |
|
542 | + if (count($error)) { |
|
543 | + return json_encode(array('error' => $error)); |
|
544 | + } |
|
460 | 545 | return true; |
461 | 546 | } |
462 | 547 | |
463 | - protected function act_rm_cbd() { |
|
548 | + protected function act_rm_cbd() |
|
549 | + { |
|
464 | 550 | if (!$this->config['access']['files']['delete'] || |
465 | 551 | !isset($this->post['files']) || |
466 | 552 | !is_array($this->post['files']) || |
467 | 553 | !count($this->post['files']) |
468 | - ) |
|
469 | - $this->errorMsg("Unknown error."); |
|
554 | + ) { |
|
555 | + $this->errorMsg("Unknown error."); |
|
556 | + } |
|
470 | 557 | |
471 | 558 | $error = array(); |
472 | 559 | foreach($this->post['files'] as $file) { |
473 | 560 | $file = path::normalize($file); |
474 | - if (substr($file, 0, 1) == ".") continue; |
|
561 | + if (substr($file, 0, 1) == ".") { |
|
562 | + continue; |
|
563 | + } |
|
475 | 564 | $type = explode("/", $file); |
476 | 565 | $type = $type[0]; |
477 | - if ($type != $this->type) continue; |
|
566 | + if ($type != $this->type) { |
|
567 | + continue; |
|
568 | + } |
|
478 | 569 | $path = "{$this->config['uploadDir']}/$file"; |
479 | 570 | $base = basename($file); |
480 | 571 | $replace = array('file' => $base); |
481 | - if (!is_file($path)) |
|
482 | - $error[] = $this->label("The file '{file}' does not exist.", $replace); |
|
483 | - elseif (!@unlink($path)) |
|
484 | - $error[] = $this->label("Cannot delete '{file}'.", $replace); |
|
485 | - else { |
|
572 | + if (!is_file($path)) { |
|
573 | + $error[] = $this->label("The file '{file}' does not exist.", $replace); |
|
574 | + } elseif (!@unlink($path)) { |
|
575 | + $error[] = $this->label("Cannot delete '{file}'.", $replace); |
|
576 | + } else { |
|
486 | 577 | $thumb = "{$this->thumbsDir}/$file"; |
487 | - if (is_file($thumb)) @unlink($thumb); |
|
578 | + if (is_file($thumb)) { |
|
579 | + @unlink($thumb); |
|
580 | + } |
|
488 | 581 | } |
489 | 582 | } |
490 | - if (count($error)) |
|
491 | - return json_encode(array('error' => $error)); |
|
583 | + if (count($error)) { |
|
584 | + return json_encode(array('error' => $error)); |
|
585 | + } |
|
492 | 586 | return true; |
493 | 587 | } |
494 | 588 | |
495 | - protected function act_downloadDir() { |
|
589 | + protected function act_downloadDir() |
|
590 | + { |
|
496 | 591 | $dir = $this->postDir(); |
497 | - if (!isset($this->post['dir']) || $this->config['denyZipDownload']) |
|
498 | - $this->errorMsg("Unknown error."); |
|
592 | + if (!isset($this->post['dir']) || $this->config['denyZipDownload']) { |
|
593 | + $this->errorMsg("Unknown error."); |
|
594 | + } |
|
499 | 595 | $filename = basename($dir) . ".zip"; |
500 | 596 | do { |
501 | 597 | $file = md5(time() . session_id()); |
@@ -510,23 +606,27 @@ discard block |
||
510 | 606 | die; |
511 | 607 | } |
512 | 608 | |
513 | - protected function act_downloadSelected() { |
|
609 | + protected function act_downloadSelected() |
|
610 | + { |
|
514 | 611 | $dir = $this->postDir(); |
515 | 612 | if (!isset($this->post['dir']) || |
516 | 613 | !isset($this->post['files']) || |
517 | 614 | !is_array($this->post['files']) || |
518 | 615 | $this->config['denyZipDownload'] |
519 | - ) |
|
520 | - $this->errorMsg("Unknown error."); |
|
616 | + ) { |
|
617 | + $this->errorMsg("Unknown error."); |
|
618 | + } |
|
521 | 619 | |
522 | 620 | $zipFiles = array(); |
523 | 621 | foreach ($this->post['files'] as $file) { |
524 | 622 | $file = path::normalize($file); |
525 | - if ((substr($file, 0, 1) == ".") || (strpos($file, '/') !== false)) |
|
526 | - continue; |
|
623 | + if ((substr($file, 0, 1) == ".") || (strpos($file, '/') !== false)) { |
|
624 | + continue; |
|
625 | + } |
|
527 | 626 | $file = "$dir/$file"; |
528 | - if (!is_file($file) || !is_readable($file)) |
|
529 | - continue; |
|
627 | + if (!is_file($file) || !is_readable($file)) { |
|
628 | + continue; |
|
629 | + } |
|
530 | 630 | $zipFiles[] = $file; |
531 | 631 | } |
532 | 632 | |
@@ -538,8 +638,9 @@ discard block |
||
538 | 638 | $zip = new ZipArchive(); |
539 | 639 | $res = $zip->open($file, ZipArchive::CREATE); |
540 | 640 | if ($res === TRUE) { |
541 | - foreach ($zipFiles as $cfile) |
|
542 | - $zip->addFile($cfile, basename($cfile)); |
|
641 | + foreach ($zipFiles as $cfile) { |
|
642 | + $zip->addFile($cfile, basename($cfile)); |
|
643 | + } |
|
543 | 644 | $zip->close(); |
544 | 645 | } |
545 | 646 | header("Content-Type: application/x-zip"); |
@@ -550,25 +651,30 @@ discard block |
||
550 | 651 | die; |
551 | 652 | } |
552 | 653 | |
553 | - protected function act_downloadClipboard() { |
|
654 | + protected function act_downloadClipboard() |
|
655 | + { |
|
554 | 656 | if (!isset($this->post['files']) || |
555 | 657 | !is_array($this->post['files']) || |
556 | 658 | $this->config['denyZipDownload'] |
557 | - ) |
|
558 | - $this->errorMsg("Unknown error."); |
|
659 | + ) { |
|
660 | + $this->errorMsg("Unknown error."); |
|
661 | + } |
|
559 | 662 | |
560 | 663 | $zipFiles = array(); |
561 | 664 | foreach ($this->post['files'] as $file) { |
562 | 665 | $file = path::normalize($file); |
563 | - if ((substr($file, 0, 1) == ".")) |
|
564 | - continue; |
|
666 | + if ((substr($file, 0, 1) == ".")) { |
|
667 | + continue; |
|
668 | + } |
|
565 | 669 | $type = explode("/", $file); |
566 | 670 | $type = $type[0]; |
567 | - if ($type != $this->type) |
|
568 | - continue; |
|
671 | + if ($type != $this->type) { |
|
672 | + continue; |
|
673 | + } |
|
569 | 674 | $file = $this->config['uploadDir'] . "/$file"; |
570 | - if (!is_file($file) || !is_readable($file)) |
|
571 | - continue; |
|
675 | + if (!is_file($file) || !is_readable($file)) { |
|
676 | + continue; |
|
677 | + } |
|
572 | 678 | $zipFiles[] = $file; |
573 | 679 | } |
574 | 680 | |
@@ -580,8 +686,9 @@ discard block |
||
580 | 686 | $zip = new ZipArchive(); |
581 | 687 | $res = $zip->open($file, ZipArchive::CREATE); |
582 | 688 | if ($res === TRUE) { |
583 | - foreach ($zipFiles as $cfile) |
|
584 | - $zip->addFile($cfile, basename($cfile)); |
|
689 | + foreach ($zipFiles as $cfile) { |
|
690 | + $zip->addFile($cfile, basename($cfile)); |
|
691 | + } |
|
585 | 692 | $zip->close(); |
586 | 693 | } |
587 | 694 | header("Content-Type: application/x-zip"); |
@@ -592,16 +699,19 @@ discard block |
||
592 | 699 | die; |
593 | 700 | } |
594 | 701 | |
595 | - protected function act_check4Update() { |
|
596 | - if ($this->config['denyUpdateCheck']) |
|
597 | - return json_encode(array('version' => false)); |
|
702 | + protected function act_check4Update() |
|
703 | + { |
|
704 | + if ($this->config['denyUpdateCheck']) { |
|
705 | + return json_encode(array('version' => false)); |
|
706 | + } |
|
598 | 707 | |
599 | 708 | // Caching HTTP request for 6 hours |
600 | 709 | if (isset($this->session['checkVersion']) && |
601 | 710 | isset($this->session['checkVersionTime']) && |
602 | 711 | ((time() - $this->session['checkVersionTime']) < 21600) |
603 | - ) |
|
604 | - return json_encode(array('version' => $this->session['checkVersion'])); |
|
712 | + ) { |
|
713 | + return json_encode(array('version' => $this->session['checkVersion'])); |
|
714 | + } |
|
605 | 715 | |
606 | 716 | $protocol = "http"; |
607 | 717 | $host = "kcfinder.sunhater.com"; |
@@ -651,27 +761,32 @@ discard block |
||
651 | 761 | (false !== @socket_write($socket, $cmd, strlen($cmd)) ) && |
652 | 762 | (false !== ( $ver = @socket_read($socket, 2048) )) && |
653 | 763 | preg_match($responsePattern, $ver, $match) |
654 | - ) |
|
655 | - $ver = $match[2]; |
|
764 | + ) { |
|
765 | + $ver = $match[2]; |
|
766 | + } |
|
656 | 767 | |
657 | - if (isset($socket) && is_resource($socket)) |
|
658 | - @socket_close($socket); |
|
768 | + if (isset($socket) && is_resource($socket)) { |
|
769 | + @socket_close($socket); |
|
770 | + } |
|
659 | 771 | } |
660 | 772 | |
661 | 773 | if (isset($ver) && preg_match($pattern, $ver)) { |
662 | 774 | $this->session['checkVersion'] = $ver; |
663 | 775 | $this->session['checkVersionTime'] = time(); |
664 | 776 | return json_encode(array('version' => $ver)); |
665 | - } else |
|
666 | - return json_encode(array('version' => false)); |
|
777 | + } else { |
|
778 | + return json_encode(array('version' => false)); |
|
779 | + } |
|
667 | 780 | } |
668 | 781 | |
669 | - protected function moveUploadFile($file, $dir) { |
|
782 | + protected function moveUploadFile($file, $dir) |
|
783 | + { |
|
670 | 784 | $message = $this->checkUploadedFile($file); |
671 | 785 | |
672 | 786 | if ($message !== true) { |
673 | - if (isset($file['tmp_name'])) |
|
674 | - @unlink($file['tmp_name']); |
|
787 | + if (isset($file['tmp_name'])) { |
|
788 | + @unlink($file['tmp_name']); |
|
789 | + } |
|
675 | 790 | return "{$file['name']}: $message"; |
676 | 791 | } |
677 | 792 | |
@@ -684,8 +799,9 @@ discard block |
||
684 | 799 | ) { |
685 | 800 | @unlink($file['tmp_name']); |
686 | 801 | return "{$file['name']}: " . $this->label("Cannot move uploaded file to target folder."); |
687 | - } elseif (function_exists('chmod')) |
|
688 | - chmod($target, $this->config['filePerms']); |
|
802 | + } elseif (function_exists('chmod')) { |
|
803 | + chmod($target, $this->config['filePerms']); |
|
804 | + } |
|
689 | 805 | |
690 | 806 | $this->modx->invokeEvent('OnFileBrowserUpload',array( |
691 | 807 | 'filepath'=>realpath($dir), |
@@ -697,25 +813,29 @@ discard block |
||
697 | 813 | return "/" . basename($target); |
698 | 814 | } |
699 | 815 | |
700 | - protected function sendDefaultThumb($file=null) { |
|
816 | + protected function sendDefaultThumb($file=null) |
|
817 | + { |
|
701 | 818 | if ($file !== null) { |
702 | 819 | $ext = file::getExtension($file); |
703 | 820 | $thumb = "themes/{$this->config['theme']}/img/files/big/$ext.png"; |
704 | 821 | } |
705 | - if (!isset($thumb) || !file_exists($thumb)) |
|
706 | - $thumb = "themes/{$this->config['theme']}/img/files/big/..png"; |
|
822 | + if (!isset($thumb) || !file_exists($thumb)) { |
|
823 | + $thumb = "themes/{$this->config['theme']}/img/files/big/..png"; |
|
824 | + } |
|
707 | 825 | header("Content-Type: image/png"); |
708 | 826 | readfile($thumb); |
709 | 827 | die; |
710 | 828 | } |
711 | 829 | |
712 | - protected function getFiles($dir) { |
|
830 | + protected function getFiles($dir) |
|
831 | + { |
|
713 | 832 | $thumbDir = "{$this->config['uploadDir']}/{$this->config['thumbsDir']}/$dir"; |
714 | 833 | $dir = "{$this->config['uploadDir']}/$dir"; |
715 | 834 | $return = array(); |
716 | 835 | $files = dir::content($dir, array('types' => "file")); |
717 | - if ($files === false) |
|
718 | - return $return; |
|
836 | + if ($files === false) { |
|
837 | + return $return; |
|
838 | + } |
|
719 | 839 | |
720 | 840 | foreach ($files as $file) { |
721 | 841 | $ext = file::getExtension($file); |
@@ -724,8 +844,9 @@ discard block |
||
724 | 844 | $size = @getimagesize($file); |
725 | 845 | if (is_array($size) && count($size)) { |
726 | 846 | $thumb_file = "$thumbDir/" . basename($file); |
727 | - if (!is_file($thumb_file) || filemtime($file) > filemtime($thumb_file)) |
|
728 | - $this->makeThumb($file); |
|
847 | + if (!is_file($thumb_file) || filemtime($file) > filemtime($thumb_file)) { |
|
848 | + $this->makeThumb($file); |
|
849 | + } |
|
729 | 850 | $smallThumb = |
730 | 851 | ($size[0] <= $this->config['thumbWidth']) && |
731 | 852 | ($size[1] <= $this->config['thumbHeight']) && |
@@ -733,12 +854,18 @@ discard block |
||
733 | 854 | } |
734 | 855 | } |
735 | 856 | $stat = stat($file); |
736 | - if ($stat === false) continue; |
|
857 | + if ($stat === false) { |
|
858 | + continue; |
|
859 | + } |
|
737 | 860 | $name = basename($file); |
738 | 861 | $types = $this->config['types']; |
739 | 862 | $types = explode(' ',$types['images'].' '.$types['image']); |
740 | - if (substr($name,0,1) == '.' && !$this->config['showHiddenFiles']) continue; |
|
741 | - if ($this->type == 'images' && !in_array(strtolower($ext),$types)) continue; |
|
863 | + if (substr($name,0,1) == '.' && !$this->config['showHiddenFiles']) { |
|
864 | + continue; |
|
865 | + } |
|
866 | + if ($this->type == 'images' && !in_array(strtolower($ext),$types)) { |
|
867 | + continue; |
|
868 | + } |
|
742 | 869 | $bigIcon = file_exists("themes/{$this->config['theme']}/img/files/big/$ext.png"); |
743 | 870 | $smallIcon = file_exists("themes/{$this->config['theme']}/img/files/small/$ext.png"); |
744 | 871 | $thumb = file_exists("$thumbDir/$name"); |
@@ -758,14 +885,17 @@ discard block |
||
758 | 885 | return $return; |
759 | 886 | } |
760 | 887 | |
761 | - protected function getTree($dir, $index=0) { |
|
888 | + protected function getTree($dir, $index=0) |
|
889 | + { |
|
762 | 890 | $path = explode("/", $dir); |
763 | 891 | |
764 | 892 | $pdir = ""; |
765 | - for ($i = 0; ($i <= $index && $i < count($path)); $i++) |
|
766 | - $pdir .= "/{$path[$i]}"; |
|
767 | - if (strlen($pdir)) |
|
768 | - $pdir = substr($pdir, 1); |
|
893 | + for ($i = 0; ($i <= $index && $i < count($path)); $i++) { |
|
894 | + $pdir .= "/{$path[$i]}"; |
|
895 | + } |
|
896 | + if (strlen($pdir)) { |
|
897 | + $pdir = substr($pdir, 1); |
|
898 | + } |
|
769 | 899 | |
770 | 900 | $fdir = "{$this->config['uploadDir']}/$pdir"; |
771 | 901 | |
@@ -787,38 +917,48 @@ discard block |
||
787 | 917 | } |
788 | 918 | } |
789 | 919 | } |
790 | - } else |
|
791 | - return false; |
|
920 | + } else { |
|
921 | + return false; |
|
922 | + } |
|
792 | 923 | |
793 | 924 | return $dirs; |
794 | 925 | } |
795 | 926 | |
796 | - protected function postDir($existent=true) { |
|
927 | + protected function postDir($existent=true) |
|
928 | + { |
|
797 | 929 | $dir = $this->typeDir; |
798 | - if (isset($this->post['dir'])) |
|
799 | - $dir .= "/" . $this->post['dir']; |
|
800 | - if ($existent && (!is_dir($dir) || !is_readable($dir))) |
|
801 | - $this->errorMsg("Inexistant or inaccessible folder."); |
|
930 | + if (isset($this->post['dir'])) { |
|
931 | + $dir .= "/" . $this->post['dir']; |
|
932 | + } |
|
933 | + if ($existent && (!is_dir($dir) || !is_readable($dir))) { |
|
934 | + $this->errorMsg("Inexistant or inaccessible folder."); |
|
935 | + } |
|
802 | 936 | return $dir; |
803 | 937 | } |
804 | 938 | |
805 | - protected function getDir($existent=true) { |
|
939 | + protected function getDir($existent=true) |
|
940 | + { |
|
806 | 941 | $dir = $this->typeDir; |
807 | - if (isset($this->get['dir'])) |
|
808 | - $dir .= "/" . $this->get['dir']; |
|
809 | - if ($existent && (!is_dir($dir) || !is_readable($dir))) |
|
810 | - $this->errorMsg("Inexistant or inaccessible folder."); |
|
942 | + if (isset($this->get['dir'])) { |
|
943 | + $dir .= "/" . $this->get['dir']; |
|
944 | + } |
|
945 | + if ($existent && (!is_dir($dir) || !is_readable($dir))) { |
|
946 | + $this->errorMsg("Inexistant or inaccessible folder."); |
|
947 | + } |
|
811 | 948 | return $dir; |
812 | 949 | } |
813 | 950 | |
814 | - protected function getDirs($dir) { |
|
951 | + protected function getDirs($dir) |
|
952 | + { |
|
815 | 953 | $dirs = dir::content($dir, array('types' => "dir")); |
816 | 954 | $return = array(); |
817 | 955 | if (is_array($dirs)) { |
818 | 956 | $writable = dir::isWritable($dir); |
819 | 957 | foreach ($dirs as $cdir) { |
820 | 958 | $info = $this->getDirInfo($cdir); |
821 | - if ($info === false) continue; |
|
959 | + if ($info === false) { |
|
960 | + continue; |
|
961 | + } |
|
822 | 962 | $info['removable'] = $writable && $info['writable']; |
823 | 963 | $return[] = $info; |
824 | 964 | } |
@@ -826,17 +966,21 @@ discard block |
||
826 | 966 | return $return; |
827 | 967 | } |
828 | 968 | |
829 | - protected function getDirInfo($dir, $removable=false) { |
|
830 | - if ((substr(basename($dir), 0, 1) == ".") || !is_dir($dir) || !is_readable($dir)) |
|
831 | - return false; |
|
969 | + protected function getDirInfo($dir, $removable=false) |
|
970 | + { |
|
971 | + if ((substr(basename($dir), 0, 1) == ".") || !is_dir($dir) || !is_readable($dir)) { |
|
972 | + return false; |
|
973 | + } |
|
832 | 974 | $dirs = dir::content($dir, array('types' => "dir")); |
833 | 975 | if (is_array($dirs)) { |
834 | - foreach ($dirs as $key => $cdir) |
|
835 | - if (substr(basename($cdir), 0, 1) == ".") |
|
976 | + foreach ($dirs as $key => $cdir) { |
|
977 | + if (substr(basename($cdir), 0, 1) == ".") |
|
836 | 978 | unset($dirs[$key]); |
979 | + } |
|
837 | 980 | $hasDirs = count($dirs) ? true : false; |
838 | - } else |
|
839 | - $hasDirs = false; |
|
981 | + } else { |
|
982 | + $hasDirs = false; |
|
983 | + } |
|
840 | 984 | |
841 | 985 | $writable = dir::isWritable($dir); |
842 | 986 | $info = array( |
@@ -847,24 +991,30 @@ discard block |
||
847 | 991 | 'hasDirs' => $hasDirs |
848 | 992 | ); |
849 | 993 | |
850 | - if ($dir == "{$this->config['uploadDir']}/{$this->session['dir']}") |
|
851 | - $info['current'] = true; |
|
994 | + if ($dir == "{$this->config['uploadDir']}/{$this->session['dir']}") { |
|
995 | + $info['current'] = true; |
|
996 | + } |
|
852 | 997 | |
853 | 998 | return $info; |
854 | 999 | } |
855 | 1000 | |
856 | - protected function output($data=null, $template=null) { |
|
857 | - if (!is_array($data)) $data = array(); |
|
858 | - if ($template === null) |
|
859 | - $template = $this->action; |
|
1001 | + protected function output($data=null, $template=null) |
|
1002 | + { |
|
1003 | + if (!is_array($data)) { |
|
1004 | + $data = array(); |
|
1005 | + } |
|
1006 | + if ($template === null) { |
|
1007 | + $template = $this->action; |
|
1008 | + } |
|
860 | 1009 | |
861 | 1010 | if (file_exists("tpl/tpl_$template.php")) { |
862 | 1011 | ob_start(); |
863 | 1012 | $eval = "unset(\$data);unset(\$template);unset(\$eval);"; |
864 | 1013 | $_ = $data; |
865 | - foreach (array_keys($data) as $key) |
|
866 | - if (preg_match('/^[a-z\d_]+$/i', $key)) |
|
1014 | + foreach (array_keys($data) as $key) { |
|
1015 | + if (preg_match('/^[a-z\d_]+$/i', $key)) |
|
867 | 1016 | $eval .= "\$$key=\$_['$key'];"; |
1017 | + } |
|
868 | 1018 | $eval .= "unset(\$_);require \"tpl/tpl_$template.php\";"; |
869 | 1019 | eval($eval); |
870 | 1020 | return ob_get_clean(); |
@@ -873,12 +1023,14 @@ discard block |
||
873 | 1023 | return ""; |
874 | 1024 | } |
875 | 1025 | |
876 | - protected function errorMsg($message, array $data=null) { |
|
877 | - if (in_array($this->action, array("thumb", "upload", "download", "downloadDir"))) |
|
878 | - die($this->label($message, $data)); |
|
879 | - if (($this->action === null) || ($this->action == "browser")) |
|
880 | - $this->backMsg($message, $data); |
|
881 | - else { |
|
1026 | + protected function errorMsg($message, array $data=null) |
|
1027 | + { |
|
1028 | + if (in_array($this->action, array("thumb", "upload", "download", "downloadDir"))) { |
|
1029 | + die($this->label($message, $data)); |
|
1030 | + } |
|
1031 | + if (($this->action === null) || ($this->action == "browser")) { |
|
1032 | + $this->backMsg($message, $data); |
|
1033 | + } else { |
|
882 | 1034 | $message = $this->label($message, $data); |
883 | 1035 | die(json_encode(array('error' => $message))); |
884 | 1036 | } |
@@ -14,7 +14,9 @@ |
||
14 | 14 | |
15 | 15 | require "core/autoload.php"; |
16 | 16 | $mtime = @filemtime(__FILE__); |
17 | -if ($mtime) httpCache::checkMTime($mtime); |
|
17 | +if ($mtime) { |
|
18 | + httpCache::checkMTime($mtime); |
|
19 | +} |
|
18 | 20 | $browser = new browser($modx); |
19 | 21 | $config = $browser->config; |
20 | 22 | ob_start(); |
@@ -10,11 +10,17 @@ |
||
10 | 10 | } |
11 | 11 | }; |
12 | 12 | <?php |
13 | - if(isset($_GET['type'])) $type = htmlspecialchars(trim($_GET['type']), ENT_QUOTES); |
|
14 | - elseif(isset($_GET['Type'])) $type = htmlspecialchars(trim($_GET['Type']), ENT_QUOTES); |
|
15 | - else $type = 'images'; |
|
13 | + if(isset($_GET['type'])) { |
|
14 | + $type = htmlspecialchars(trim($_GET['type']), ENT_QUOTES); |
|
15 | + } elseif(isset($_GET['Type'])) { |
|
16 | + $type = htmlspecialchars(trim($_GET['Type']), ENT_QUOTES); |
|
17 | + } else { |
|
18 | + $type = 'images'; |
|
19 | + } |
|
16 | 20 | |
17 | - if($type==='image') $type = 'images'; |
|
21 | + if($type==='image') { |
|
22 | + $type = 'images'; |
|
23 | + } |
|
18 | 24 | |
19 | 25 | $opener = (isset($_GET['editor'])) ? 'opener=' . htmlspecialchars(trim($_GET['editor']), ENT_QUOTES) : ''; |
20 | 26 | $request_uri = "{$opener}&type={$type}"; |
@@ -12,23 +12,27 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class dir { |
|
15 | +class dir |
|
16 | +{ |
|
16 | 17 | |
17 | 18 | /** Checks if the given directory is really writable. The standard PHP |
18 | 19 | * function is_writable() does not work properly on Windows servers |
19 | 20 | * @param string $dir |
20 | 21 | * @return bool */ |
21 | 22 | |
22 | - static function isWritable($dir) { |
|
23 | + static function isWritable($dir) |
|
24 | + { |
|
23 | 25 | $dir = path::normalize($dir); |
24 | - if (!is_dir($dir)) |
|
25 | - return false; |
|
26 | + if (!is_dir($dir)) { |
|
27 | + return false; |
|
28 | + } |
|
26 | 29 | $i = 0; |
27 | 30 | do { |
28 | 31 | $file = "$dir/is_writable_" . md5($i++); |
29 | 32 | } while (file_exists($file)); |
30 | - if (!@touch($file)) |
|
31 | - return false; |
|
33 | + if (!@touch($file)) { |
|
34 | + return false; |
|
35 | + } |
|
32 | 36 | unlink($file); |
33 | 37 | return true; |
34 | 38 | } |
@@ -44,12 +48,16 @@ discard block |
||
44 | 48 | * @param array $failed |
45 | 49 | * @return mixed */ |
46 | 50 | |
47 | - static function prune($dir, $firstFailExit=true, array $failed=null) { |
|
48 | - if ($failed === null) $failed = array(); |
|
51 | + static function prune($dir, $firstFailExit=true, array $failed=null) |
|
52 | + { |
|
53 | + if ($failed === null) { |
|
54 | + $failed = array(); |
|
55 | + } |
|
49 | 56 | $files = self::content($dir); |
50 | 57 | if ($files === false) { |
51 | - if ($firstFailExit) |
|
52 | - return $dir; |
|
58 | + if ($firstFailExit) { |
|
59 | + return $dir; |
|
60 | + } |
|
53 | 61 | $failed[] = $dir; |
54 | 62 | return $failed; |
55 | 63 | } |
@@ -58,23 +66,27 @@ discard block |
||
58 | 66 | if (is_dir($file)) { |
59 | 67 | $failed_in = self::prune($file, $firstFailExit, $failed); |
60 | 68 | if ($failed_in !== true) { |
61 | - if ($firstFailExit) |
|
62 | - return $failed_in; |
|
63 | - if (is_array($failed_in)) |
|
64 | - $failed = array_merge($failed, $failed_in); |
|
65 | - else |
|
66 | - $failed[] = $failed_in; |
|
69 | + if ($firstFailExit) { |
|
70 | + return $failed_in; |
|
71 | + } |
|
72 | + if (is_array($failed_in)) { |
|
73 | + $failed = array_merge($failed, $failed_in); |
|
74 | + } else { |
|
75 | + $failed[] = $failed_in; |
|
76 | + } |
|
67 | 77 | } |
68 | 78 | } elseif (!@unlink($file)) { |
69 | - if ($firstFailExit) |
|
70 | - return $file; |
|
79 | + if ($firstFailExit) { |
|
80 | + return $file; |
|
81 | + } |
|
71 | 82 | $failed[] = $file; |
72 | 83 | } |
73 | 84 | } |
74 | 85 | |
75 | 86 | if (!@rmdir($dir)) { |
76 | - if ($firstFailExit) |
|
77 | - return $dir; |
|
87 | + if ($firstFailExit) { |
|
88 | + return $dir; |
|
89 | + } |
|
78 | 90 | $failed[] = $dir; |
79 | 91 | } |
80 | 92 | |
@@ -87,7 +99,8 @@ discard block |
||
87 | 99 | * @param array $options |
88 | 100 | * @return mixed */ |
89 | 101 | |
90 | - static function content($dir, array $options=null) { |
|
102 | + static function content($dir, array $options=null) |
|
103 | + { |
|
91 | 104 | |
92 | 105 | $defaultOptions = array( |
93 | 106 | 'types' => "all", // Allowed: "all" or possible return values |
@@ -97,23 +110,28 @@ discard block |
||
97 | 110 | 'followLinks' => true |
98 | 111 | ); |
99 | 112 | |
100 | - if (!is_dir($dir) || !is_readable($dir)) |
|
101 | - return false; |
|
113 | + if (!is_dir($dir) || !is_readable($dir)) { |
|
114 | + return false; |
|
115 | + } |
|
102 | 116 | |
103 | - if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") |
|
104 | - $dir = str_replace("\\", "/", $dir); |
|
117 | + if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") { |
|
118 | + $dir = str_replace("\\", "/", $dir); |
|
119 | + } |
|
105 | 120 | $dir = rtrim($dir, "/"); |
106 | 121 | |
107 | 122 | $dh = @opendir($dir); |
108 | - if ($dh === false) |
|
109 | - return false; |
|
123 | + if ($dh === false) { |
|
124 | + return false; |
|
125 | + } |
|
110 | 126 | |
111 | - if ($options === null) |
|
112 | - $options = $defaultOptions; |
|
127 | + if ($options === null) { |
|
128 | + $options = $defaultOptions; |
|
129 | + } |
|
113 | 130 | |
114 | - foreach ($defaultOptions as $key => $val) |
|
115 | - if (!isset($options[$key])) |
|
131 | + foreach ($defaultOptions as $key => $val) { |
|
132 | + if (!isset($options[$key])) |
|
116 | 133 | $options[$key] = $val; |
134 | + } |
|
117 | 135 | |
118 | 136 | $files = array(); |
119 | 137 | while (($file = @readdir($dh)) !== false) { |
@@ -124,28 +142,32 @@ discard block |
||
124 | 142 | do { |
125 | 143 | $ldir = dirname($lfile); |
126 | 144 | $lfile = @readlink($lfile); |
127 | - if (substr($lfile, 0, 1) != "/") |
|
128 | - $lfile = "$ldir/$lfile"; |
|
145 | + if (substr($lfile, 0, 1) != "/") { |
|
146 | + $lfile = "$ldir/$lfile"; |
|
147 | + } |
|
129 | 148 | $type = filetype($lfile); |
130 | 149 | } while ($type == "link"); |
131 | 150 | } |
132 | 151 | |
133 | 152 | if ((($type === "dir") && (($file == ".") || ($file == ".."))) || |
134 | 153 | !preg_match($options['pattern'], $file) |
135 | - ) |
|
136 | - continue; |
|
154 | + ) { |
|
155 | + continue; |
|
156 | + } |
|
137 | 157 | |
138 | 158 | if (($options['types'] === "all") || ($type === $options['types']) || |
139 | 159 | ((is_array($options['types'])) && in_array($type, $options['types'])) |
140 | - ) |
|
141 | - $files[] = $options['addPath'] ? "$dir/$file" : $file; |
|
160 | + ) { |
|
161 | + $files[] = $options['addPath'] ? "$dir/$file" : $file; |
|
162 | + } |
|
142 | 163 | } |
143 | 164 | closedir($dh); |
144 | 165 | usort($files, array("dir", "fileSort")); |
145 | 166 | return $files; |
146 | 167 | } |
147 | 168 | |
148 | - static function fileSort($a, $b) { |
|
169 | + static function fileSort($a, $b) |
|
170 | + { |
|
149 | 171 | if (function_exists("mb_strtolower")) { |
150 | 172 | $a = mb_strtolower($a); |
151 | 173 | $b = mb_strtolower($b); |
@@ -153,7 +175,9 @@ discard block |
||
153 | 175 | $a = strtolower($a); |
154 | 176 | $b = strtolower($b); |
155 | 177 | } |
156 | - if ($a == $b) return 0; |
|
178 | + if ($a == $b) { |
|
179 | + return 0; |
|
180 | + } |
|
157 | 181 | return ($a < $b) ? -1 : 1; |
158 | 182 | } |
159 | 183 | } |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class input { |
|
15 | +class input |
|
16 | +{ |
|
16 | 17 | |
17 | 18 | /** Filtered $_GET array |
18 | 19 | * @var array */ |
@@ -26,7 +27,8 @@ discard block |
||
26 | 27 | * @var array */ |
27 | 28 | public $cookie; |
28 | 29 | |
29 | - public function __construct() { |
|
30 | + public function __construct() |
|
31 | + { |
|
30 | 32 | $this->get = &$_GET; |
31 | 33 | $this->post = &$_POST; |
32 | 34 | $this->cookie = &$_COOKIE; |
@@ -36,7 +38,8 @@ discard block |
||
36 | 38 | * @param string $property |
37 | 39 | * @return mixed */ |
38 | 40 | |
39 | - public function __get($property) { |
|
41 | + public function __get($property) |
|
42 | + { |
|
40 | 43 | return property_exists($this, $property) ? $this->$property : null; |
41 | 44 | } |
42 | 45 | } |
@@ -12,29 +12,36 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class path { |
|
15 | +class path |
|
16 | +{ |
|
16 | 17 | |
17 | 18 | /** Get the absolute URL path of the given one. Returns FALSE if the URL |
18 | 19 | * is not valid or the current directory cannot be resolved (getcwd()) |
19 | 20 | * @param string $path |
20 | 21 | * @return string */ |
21 | 22 | |
22 | - static function rel2abs_url($path) { |
|
23 | - if (substr($path, 0, 1) == "/") return $path; |
|
23 | + static function rel2abs_url($path) |
|
24 | + { |
|
25 | + if (substr($path, 0, 1) == "/") { |
|
26 | + return $path; |
|
27 | + } |
|
24 | 28 | $dir = @getcwd(); |
25 | 29 | |
26 | - if (!isset($_SERVER['DOCUMENT_ROOT']) || ($dir === false)) |
|
27 | - return false; |
|
30 | + if (!isset($_SERVER['DOCUMENT_ROOT']) || ($dir === false)) { |
|
31 | + return false; |
|
32 | + } |
|
28 | 33 | |
29 | 34 | $dir = self::normalize($dir); |
30 | 35 | $doc_root = self::normalize($_SERVER['DOCUMENT_ROOT']); |
31 | 36 | |
32 | - if (substr($dir, 0, strlen($doc_root)) != $doc_root) |
|
33 | - return false; |
|
37 | + if (substr($dir, 0, strlen($doc_root)) != $doc_root) { |
|
38 | + return false; |
|
39 | + } |
|
34 | 40 | |
35 | 41 | $return = self::normalize(substr($dir, strlen($doc_root)) . "/$path"); |
36 | - if (substr($return, 0, 1) !== "/") |
|
37 | - $return = "/$return"; |
|
42 | + if (substr($return, 0, 1) !== "/") { |
|
43 | + $return = "/$return"; |
|
44 | + } |
|
38 | 45 | |
39 | 46 | return $return; |
40 | 47 | } |
@@ -44,7 +51,8 @@ discard block |
||
44 | 51 | * @param string $url |
45 | 52 | * @return string */ |
46 | 53 | |
47 | - static function url2fullPath($url) { |
|
54 | + static function url2fullPath($url) |
|
55 | + { |
|
48 | 56 | $url = self::normalize($url); |
49 | 57 | |
50 | 58 | $uri = isset($_SERVER['SCRIPT_NAME']) |
@@ -55,7 +63,9 @@ discard block |
||
55 | 63 | $uri = self::normalize($uri); |
56 | 64 | |
57 | 65 | if (substr($url, 0, 1) !== "/") { |
58 | - if ($uri === false) return false; |
|
66 | + if ($uri === false) { |
|
67 | + return false; |
|
68 | + } |
|
59 | 69 | $url = dirname($uri) . "/$url"; |
60 | 70 | } |
61 | 71 | |
@@ -63,7 +73,9 @@ discard block |
||
63 | 73 | return self::normalize($_SERVER['DOCUMENT_ROOT'] . "/$url"); |
64 | 74 | |
65 | 75 | } else { |
66 | - if ($uri === false) return false; |
|
76 | + if ($uri === false) { |
|
77 | + return false; |
|
78 | + } |
|
67 | 79 | |
68 | 80 | if (isset($_SERVER['SCRIPT_FILENAME'])) { |
69 | 81 | $scr_filename = self::normalize($_SERVER['SCRIPT_FILENAME']); |
@@ -71,13 +83,15 @@ discard block |
||
71 | 83 | } |
72 | 84 | |
73 | 85 | $count = count(explode('/', $uri)) - 1; |
74 | - for ($i = 0, $chdir = ""; $i < $count; $i++) |
|
75 | - $chdir .= "../"; |
|
86 | + for ($i = 0, $chdir = ""; $i < $count; $i++) { |
|
87 | + $chdir .= "../"; |
|
88 | + } |
|
76 | 89 | $chdir = self::normalize($chdir); |
77 | 90 | |
78 | 91 | $dir = getcwd(); |
79 | - if (($dir === false) || !@chdir($chdir)) |
|
80 | - return false; |
|
92 | + if (($dir === false) || !@chdir($chdir)) { |
|
93 | + return false; |
|
94 | + } |
|
81 | 95 | $rdir = getcwd(); |
82 | 96 | chdir($dir); |
83 | 97 | return ($rdir !== false) ? self::normalize($rdir . "/$url") : false; |
@@ -92,22 +106,29 @@ discard block |
||
92 | 106 | * @param string $path |
93 | 107 | * @return string */ |
94 | 108 | |
95 | - static function normalize($path) { |
|
109 | + static function normalize($path) |
|
110 | + { |
|
96 | 111 | if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") { |
97 | 112 | $path = preg_replace('/([^\\\])\\\([^\\\])/', "$1/$2", $path); |
98 | - if (substr($path, -1) == "\\") $path = substr($path, 0, -1); |
|
99 | - if (substr($path, 0, 1) == "\\") $path = "/" . substr($path, 1); |
|
113 | + if (substr($path, -1) == "\\") { |
|
114 | + $path = substr($path, 0, -1); |
|
115 | + } |
|
116 | + if (substr($path, 0, 1) == "\\") { |
|
117 | + $path = "/" . substr($path, 1); |
|
118 | + } |
|
100 | 119 | } |
101 | 120 | |
102 | 121 | $path = preg_replace('/\/+/s', "/", $path); |
103 | 122 | |
104 | 123 | $path = "/$path"; |
105 | - if (substr($path, -1) != "/") |
|
106 | - $path .= "/"; |
|
124 | + if (substr($path, -1) != "/") { |
|
125 | + $path .= "/"; |
|
126 | + } |
|
107 | 127 | |
108 | 128 | $expr = '/\/([^\/]{1}|[^\.\/]{2}|[^\/]{3,})\/\.\.\//s'; |
109 | - while (preg_match($expr, $path)) |
|
110 | - $path = preg_replace($expr, "/", $path); |
|
129 | + while (preg_match($expr, $path)) { |
|
130 | + $path = preg_replace($expr, "/", $path); |
|
131 | + } |
|
111 | 132 | |
112 | 133 | $path = substr($path, 0, -1); |
113 | 134 | $path = substr($path, 1); |
@@ -118,11 +139,13 @@ discard block |
||
118 | 139 | * @param string $path |
119 | 140 | * @return string */ |
120 | 141 | |
121 | - static function urlPathEncode($path) { |
|
142 | + static function urlPathEncode($path) |
|
143 | + { |
|
122 | 144 | $path = self::normalize($path); |
123 | 145 | $encoded = ""; |
124 | - foreach (explode("/", $path) as $dir) |
|
125 | - $encoded .= rawurlencode($dir) . "/"; |
|
146 | + foreach (explode("/", $path) as $dir) { |
|
147 | + $encoded .= rawurlencode($dir) . "/"; |
|
148 | + } |
|
126 | 149 | $encoded = substr($encoded, 0, -1); |
127 | 150 | return $encoded; |
128 | 151 | } |
@@ -131,11 +154,13 @@ discard block |
||
131 | 154 | * @param string $path |
132 | 155 | * @return string */ |
133 | 156 | |
134 | - static function urlPathDecode($path) { |
|
157 | + static function urlPathDecode($path) |
|
158 | + { |
|
135 | 159 | $path = self::normalize($path); |
136 | 160 | $decoded = ""; |
137 | - foreach (explode("/", $path) as $dir) |
|
138 | - $decoded .= rawurldecode($dir) . "/"; |
|
161 | + foreach (explode("/", $path) as $dir) { |
|
162 | + $decoded .= rawurldecode($dir) . "/"; |
|
163 | + } |
|
139 | 164 | $decoded = substr($decoded, 0, -1); |
140 | 165 | return $decoded; |
141 | 166 | } |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class file { |
|
15 | +class file |
|
16 | +{ |
|
16 | 17 | |
17 | 18 | static $MIME = array( |
18 | 19 | 'ai' => 'application/postscript', |
@@ -105,10 +106,12 @@ discard block |
||
105 | 106 | * @param string $dir |
106 | 107 | * @return bool */ |
107 | 108 | |
108 | - static function isWritable($filename) { |
|
109 | + static function isWritable($filename) |
|
110 | + { |
|
109 | 111 | $filename = path::normalize($filename); |
110 | - if (!is_file($filename) || (false === ($fp = @fopen($filename, 'a+')))) |
|
111 | - return false; |
|
112 | + if (!is_file($filename) || (false === ($fp = @fopen($filename, 'a+')))) { |
|
113 | + return false; |
|
114 | + } |
|
112 | 115 | fclose($fp); |
113 | 116 | return true; |
114 | 117 | } |
@@ -118,7 +121,8 @@ discard block |
||
118 | 121 | * @param bool $toLower |
119 | 122 | * @return string */ |
120 | 123 | |
121 | - static function getExtension($filename, $toLower=true) { |
|
124 | + static function getExtension($filename, $toLower=true) |
|
125 | + { |
|
122 | 126 | return preg_match('/^.*\.([^\.]*)$/s', $filename, $patt) |
123 | 127 | ? ($toLower ? strtolower($patt[1]) : $patt[1]) : ""; |
124 | 128 | } |
@@ -134,7 +138,8 @@ discard block |
||
134 | 138 | * @param string $magic |
135 | 139 | * @return string */ |
136 | 140 | |
137 | - static function getMimeType($filename, $magic=null) { |
|
141 | + static function getMimeType($filename, $magic=null) |
|
142 | + { |
|
138 | 143 | if (class_exists("finfo")) { |
139 | 144 | $finfo = ($magic === null) |
140 | 145 | ? new finfo(FILEINFO_MIME) |
@@ -170,12 +175,15 @@ discard block |
||
170 | 175 | * @param string $tpl |
171 | 176 | * @return string */ |
172 | 177 | |
173 | - static function getInexistantFilename($filename, $dir=null, $tpl=null) { |
|
174 | - if ($tpl === null) $tpl = "{name}({sufix}){ext}"; |
|
178 | + static function getInexistantFilename($filename, $dir=null, $tpl=null) |
|
179 | + { |
|
180 | + if ($tpl === null) { |
|
181 | + $tpl = "{name}({sufix}){ext}"; |
|
182 | + } |
|
175 | 183 | $fullPath = ($dir === null); |
176 | - if ($fullPath) |
|
177 | - $dir = path::normalize(dirname($filename)); |
|
178 | - else { |
|
184 | + if ($fullPath) { |
|
185 | + $dir = path::normalize(dirname($filename)); |
|
186 | + } else { |
|
179 | 187 | $fdir = dirname($filename); |
180 | 188 | $dir = strlen($fdir) |
181 | 189 | ? path::normalize("$dir/$fdir") |
@@ -187,8 +195,9 @@ discard block |
||
187 | 195 | $tpl = str_replace('{name}', $name, $tpl); |
188 | 196 | $tpl = str_replace('{ext}', (strlen($ext) ? ".$ext" : ""), $tpl); |
189 | 197 | $i = 1; $file = "$dir/$filename"; |
190 | - while (file_exists($file)) |
|
191 | - $file = "$dir/" . str_replace('{sufix}', $i++, $tpl); |
|
198 | + while (file_exists($file)) { |
|
199 | + $file = "$dir/" . str_replace('{sufix}', $i++, $tpl); |
|
200 | + } |
|
192 | 201 | |
193 | 202 | return $fullPath |
194 | 203 | ? $file |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -abstract class image { |
|
15 | +abstract class image |
|
16 | +{ |
|
16 | 17 | const DEFAULT_JPEG_QUALITY = 75; |
17 | 18 | |
18 | 19 | /** Image resource or object |
@@ -41,7 +42,8 @@ discard block |
||
41 | 42 | * @param string $property |
42 | 43 | * @return mixed */ |
43 | 44 | |
44 | - final public function __get($property) { |
|
45 | + final public function __get($property) |
|
46 | + { |
|
45 | 47 | return property_exists($this, $property) ? $this->$property : null; |
46 | 48 | } |
47 | 49 | |
@@ -57,14 +59,16 @@ discard block |
||
57 | 59 | * @param mixed $image |
58 | 60 | * @param array $options */ |
59 | 61 | |
60 | - public function __construct($image, array $options=array()) { |
|
62 | + public function __construct($image, array $options=array()) |
|
63 | + { |
|
61 | 64 | $this->image = $this->width = $this->height = null; |
62 | 65 | $imageDetails = $this->buildImage($image); |
63 | 66 | |
64 | - if ($imageDetails !== false) |
|
65 | - list($this->image, $this->width, $this->height) = $imageDetails; |
|
66 | - else |
|
67 | - $this->initError = true; |
|
67 | + if ($imageDetails !== false) { |
|
68 | + list($this->image, $this->width, $this->height) = $imageDetails; |
|
69 | + } else { |
|
70 | + $this->initError = true; |
|
71 | + } |
|
68 | 72 | $this->options = $options; |
69 | 73 | } |
70 | 74 | |
@@ -75,7 +79,8 @@ discard block |
||
75 | 79 | * @param mixed $image |
76 | 80 | * @return object */ |
77 | 81 | |
78 | - final static function factory($driver, $image, array $options=array()) { |
|
82 | + final static function factory($driver, $image, array $options=array()) |
|
83 | + { |
|
79 | 84 | $class = "image_$driver"; |
80 | 85 | return new $class($image, $options); |
81 | 86 | } |
@@ -86,14 +91,18 @@ discard block |
||
86 | 91 | * @param array $drivers |
87 | 92 | * @return string */ |
88 | 93 | |
89 | - final static function getDriver(array $drivers=array('gd')) { |
|
94 | + final static function getDriver(array $drivers=array('gd')) |
|
95 | + { |
|
90 | 96 | foreach ($drivers as $driver) { |
91 | - if (!preg_match('/^[a-z0-9\_]+$/i', $driver)) |
|
92 | - continue; |
|
97 | + if (!preg_match('/^[a-z0-9\_]+$/i', $driver)) { |
|
98 | + continue; |
|
99 | + } |
|
93 | 100 | $class = "image_$driver"; |
94 | 101 | if (class_exists($class) && method_exists($class, "available")) { |
95 | 102 | eval("\$avail = $class::available();"); |
96 | - if ($avail) return $driver; |
|
103 | + if ($avail) { |
|
104 | + return $driver; |
|
105 | + } |
|
97 | 106 | } |
98 | 107 | } |
99 | 108 | return false; |
@@ -105,7 +114,8 @@ discard block |
||
105 | 114 | * @param mixed $image |
106 | 115 | * @return array */ |
107 | 116 | |
108 | - final protected function buildImage($image) { |
|
117 | + final protected function buildImage($image) |
|
118 | + { |
|
109 | 119 | $class = get_class($this); |
110 | 120 | |
111 | 121 | if ($image instanceof $class) { |
@@ -118,8 +128,9 @@ discard block |
||
118 | 128 | list($key, $height) = each($image); |
119 | 129 | $img = $this->getBlankImage($width, $height); |
120 | 130 | |
121 | - } else |
|
122 | - $img = $this->getImage($image, $width, $height); |
|
131 | + } else { |
|
132 | + $img = $this->getImage($image, $width, $height); |
|
133 | + } |
|
123 | 134 | |
124 | 135 | return ($img !== false) |
125 | 136 | ? array($img, $width, $height) |
@@ -131,9 +142,12 @@ discard block |
||
131 | 142 | * @param integer $resizedHeight |
132 | 143 | * @return integer */ |
133 | 144 | |
134 | - final public function getPropWidth($resizedHeight) { |
|
145 | + final public function getPropWidth($resizedHeight) |
|
146 | + { |
|
135 | 147 | $width = round(($this->width * $resizedHeight) / $this->height); |
136 | - if (!$width) $width = 1; |
|
148 | + if (!$width) { |
|
149 | + $width = 1; |
|
150 | + } |
|
137 | 151 | return $width; |
138 | 152 | } |
139 | 153 | |
@@ -142,9 +156,12 @@ discard block |
||
142 | 156 | * @param integer $resizedWidth |
143 | 157 | * @return integer */ |
144 | 158 | |
145 | - final public function getPropHeight($resizedWidth) { |
|
159 | + final public function getPropHeight($resizedWidth) |
|
160 | + { |
|
146 | 161 | $height = round(($this->height * $resizedWidth) / $this->width); |
147 | - if (!$height) $height = 1; |
|
162 | + if (!$height) { |
|
163 | + $height = 1; |
|
164 | + } |
|
148 | 165 | return $height; |
149 | 166 | } |
150 | 167 | |
@@ -153,13 +170,17 @@ discard block |
||
153 | 170 | * static method should be implemented into driver classes like abstract |
154 | 171 | * methods |
155 | 172 | * @return bool */ |
156 | - static function available() { return false; } |
|
173 | + static function available() |
|
174 | + { |
|
175 | +return false; } |
|
157 | 176 | |
158 | 177 | /** Checks if file is an image. This static method should be implemented into |
159 | 178 | * driver classes like abstract methods |
160 | 179 | * @param string $file |
161 | 180 | * @return bool */ |
162 | - static function checkImage($file) { return false; } |
|
181 | + static function checkImage($file) |
|
182 | + { |
|
183 | +return false; } |
|
163 | 184 | |
164 | 185 | /** Resize image. Should return TRUE on success or FALSE on failure |
165 | 186 | * @param integer $width |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class httpCache { |
|
15 | +class httpCache |
|
16 | +{ |
|
16 | 17 | const DEFAULT_TYPE = "text/html"; |
17 | 18 | const DEFAULT_EXPIRE = 604800; // in seconds |
18 | 19 | |
@@ -25,15 +26,20 @@ discard block |
||
25 | 26 | * @param integer $expire |
26 | 27 | * @param array $headers */ |
27 | 28 | |
28 | - static function file($file, $type=null, $expire=null, array $headers=null) { |
|
29 | + static function file($file, $type=null, $expire=null, array $headers=null) |
|
30 | + { |
|
29 | 31 | $mtime = @filemtime($file); |
30 | - if ($mtime !== false) self::checkMTime($mtime); |
|
32 | + if ($mtime !== false) { |
|
33 | + self::checkMTime($mtime); |
|
34 | + } |
|
31 | 35 | |
32 | 36 | if ($type === null) { |
33 | 37 | $magic = ((substr($type, 0, 1) == "/") || preg_match('/^[a-z]\:/i', $type)) |
34 | 38 | ? $type : null; |
35 | 39 | $type = file::getMimeType($file, $magic); |
36 | - if (!$type) $type = null; |
|
40 | + if (!$type) { |
|
41 | + $type = null; |
|
42 | + } |
|
37 | 43 | } |
38 | 44 | |
39 | 45 | self::content(@file_get_contents($file), $mtime, $type, $expire, $headers, false); |
@@ -47,10 +53,17 @@ discard block |
||
47 | 53 | * @param array $headers |
48 | 54 | * @param bool $checkMTime */ |
49 | 55 | |
50 | - static function content($content, $mtime, $type=null, $expire=null, array $headers=null, $checkMTime=true) { |
|
51 | - if ($checkMTime) self::checkMTime($mtime); |
|
52 | - if ($type === null) $type = self::DEFAULT_TYPE; |
|
53 | - if ($expire === null) $expire = self::DEFAULT_EXPIRE; |
|
56 | + static function content($content, $mtime, $type=null, $expire=null, array $headers=null, $checkMTime=true) |
|
57 | + { |
|
58 | + if ($checkMTime) { |
|
59 | + self::checkMTime($mtime); |
|
60 | + } |
|
61 | + if ($type === null) { |
|
62 | + $type = self::DEFAULT_TYPE; |
|
63 | + } |
|
64 | + if ($expire === null) { |
|
65 | + $expire = self::DEFAULT_EXPIRE; |
|
66 | + } |
|
54 | 67 | $size = strlen($content); |
55 | 68 | $expires = gmdate("D, d M Y H:i:s", time() + $expire) . " GMT"; |
56 | 69 | header("Content-Type: $type"); |
@@ -58,7 +71,9 @@ discard block |
||
58 | 71 | header("Cache-Control: max-age=$expire"); |
59 | 72 | header("Pragma: !invalid"); |
60 | 73 | header("Content-Length: $size"); |
61 | - if ($headers !== null) foreach ($headers as $header) header($header); |
|
74 | + if ($headers !== null) { |
|
75 | + foreach ($headers as $header) header($header); |
|
76 | + } |
|
62 | 77 | echo $content; |
63 | 78 | } |
64 | 79 | |
@@ -68,7 +83,8 @@ discard block |
||
68 | 83 | * the PHP to be configured as Apache module. |
69 | 84 | * @param integer $mtime */ |
70 | 85 | |
71 | - static function checkMTime($mtime, $sendHeaders=null) { |
|
86 | + static function checkMTime($mtime, $sendHeaders=null) |
|
87 | + { |
|
72 | 88 | header("Last-Modified: " . gmdate("D, d M Y H:i:s", $mtime) . " GMT"); |
73 | 89 | |
74 | 90 | $headers = function_exists("getallheaders") |
@@ -82,11 +98,12 @@ discard block |
||
82 | 98 | $client_mtime = @strtotime($client_mtime[0]); |
83 | 99 | if ($client_mtime >= $mtime) { |
84 | 100 | header('HTTP/1.1 304 Not Modified'); |
85 | - if (is_array($sendHeaders) && count($sendHeaders)) |
|
86 | - foreach ($sendHeaders as $header) |
|
101 | + if (is_array($sendHeaders) && count($sendHeaders)) { |
|
102 | + foreach ($sendHeaders as $header) |
|
87 | 103 | header($header); |
88 | - elseif ($sendHeaders !== null) |
|
89 | - header($sendHeaders); |
|
104 | + } elseif ($sendHeaders !== null) { |
|
105 | + header($sendHeaders); |
|
106 | + } |
|
90 | 107 | |
91 | 108 | |
92 | 109 | die; |