@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | 'active' |
33 | 33 | ); |
34 | 34 | |
35 | -if($modx->hasPermission('edit_template') || $modx->hasPermission('edit_snippet') || $modx->hasPermission('edit_chunk') || $modx->hasPermission('edit_plugin') || $modx->hasPermission('file_manager')) { |
|
35 | +if($modx->hasPermission('edit_template') || $modx->hasPermission('edit_snippet') || $modx->hasPermission('edit_chunk') || $modx->hasPermission('edit_plugin') || $modx->hasPermission('file_manager')) { |
|
36 | 36 | $sitemenu['elements'] = array( |
37 | 37 | 'elements', |
38 | 38 | 'main', |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | ); |
49 | 49 | } |
50 | 50 | |
51 | -if($modx->hasPermission('exec_module')) { |
|
51 | +if($modx->hasPermission('exec_module')) { |
|
52 | 52 | $sitemenu['modules'] = array( |
53 | 53 | 'modules', |
54 | 54 | 'main', |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | ); |
65 | 65 | } |
66 | 66 | |
67 | -if($modx->hasPermission('edit_user') || $modx->hasPermission('edit_web_user') || $modx->hasPermission('edit_role') || $modx->hasPermission('access_permissions') || $modx->hasPermission('web_access_permissions')) { |
|
67 | +if($modx->hasPermission('edit_user') || $modx->hasPermission('edit_web_user') || $modx->hasPermission('edit_role') || $modx->hasPermission('access_permissions') || $modx->hasPermission('web_access_permissions')) { |
|
68 | 68 | $sitemenu['users'] = array( |
69 | 69 | 'users', |
70 | 70 | 'main', |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
83 | -if($modx->hasPermission('empty_cache') || $modx->hasPermission('bk_manager') || $modx->hasPermission('remove_locks') || $modx->hasPermission('import_static') || $modx->hasPermission('export_static')) { |
|
83 | +if($modx->hasPermission('empty_cache') || $modx->hasPermission('bk_manager') || $modx->hasPermission('remove_locks') || $modx->hasPermission('import_static') || $modx->hasPermission('export_static')) { |
|
84 | 84 | $sitemenu['tools'] = array( |
85 | 85 | 'tools', |
86 | 86 | 'main', |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | $tab = 0; |
100 | -if($modx->hasPermission('edit_template')) { |
|
100 | +if($modx->hasPermission('edit_template')) { |
|
101 | 101 | $sitemenu['element_templates'] = array( |
102 | 102 | 'element_templates', |
103 | 103 | 'elements', |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | 'dropdown-toggle' |
113 | 113 | ); |
114 | 114 | } |
115 | -if($modx->hasPermission('edit_template') && $modx->hasPermission('edit_snippet') && $modx->hasPermission('edit_chunk') && $modx->hasPermission('edit_plugin')) { |
|
115 | +if($modx->hasPermission('edit_template') && $modx->hasPermission('edit_snippet') && $modx->hasPermission('edit_chunk') && $modx->hasPermission('edit_plugin')) { |
|
116 | 116 | $sitemenu['element_tplvars'] = array( |
117 | 117 | 'element_tplvars', |
118 | 118 | 'elements', |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | 'dropdown-toggle' |
128 | 128 | ); |
129 | 129 | } |
130 | -if($modx->hasPermission('edit_chunk')) { |
|
130 | +if($modx->hasPermission('edit_chunk')) { |
|
131 | 131 | $sitemenu['element_htmlsnippets'] = array( |
132 | 132 | 'element_htmlsnippets', |
133 | 133 | 'elements', |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | 'dropdown-toggle' |
143 | 143 | ); |
144 | 144 | } |
145 | -if($modx->hasPermission('edit_snippet')) { |
|
145 | +if($modx->hasPermission('edit_snippet')) { |
|
146 | 146 | $sitemenu['element_snippets'] = array( |
147 | 147 | 'element_snippets', |
148 | 148 | 'elements', |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | 'dropdown-toggle' |
158 | 158 | ); |
159 | 159 | } |
160 | -if($modx->hasPermission('edit_plugin')) { |
|
160 | +if($modx->hasPermission('edit_plugin')) { |
|
161 | 161 | $sitemenu['element_plugins'] = array( |
162 | 162 | 'element_plugins', |
163 | 163 | 'elements', |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | } |
175 | 175 | //$sitemenu['element_categories'] = array('element_categories','elements',$_lang['element_categories'],'index.php?a=76&tab=5',$_lang['element_categories'],'','new_template,edit_template,new_snippet,edit_snippet,new_chunk,edit_chunk,new_plugin,edit_plugin','main',1,60,''); |
176 | 176 | |
177 | -if($modx->hasPermission('file_manager')) { |
|
177 | +if($modx->hasPermission('file_manager')) { |
|
178 | 178 | $sitemenu['manage_files'] = array( |
179 | 179 | 'manage_files', |
180 | 180 | 'elements', |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | '' |
190 | 190 | ); |
191 | 191 | } |
192 | -if($modx->hasPermission('category_manager')) { |
|
192 | +if($modx->hasPermission('category_manager')) { |
|
193 | 193 | $sitemenu['manage_categories'] = array( |
194 | 194 | 'manage_categories', |
195 | 195 | 'elements', |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | // Modules Menu Items |
209 | -if($modx->hasPermission('new_module') || $modx->hasPermission('edit_module') || $modx->hasPermission('save_module')) { |
|
209 | +if($modx->hasPermission('new_module') || $modx->hasPermission('edit_module') || $modx->hasPermission('save_module')) { |
|
210 | 210 | $sitemenu['new_module'] = array( |
211 | 211 | 'new_module', |
212 | 212 | 'modules', |
@@ -222,19 +222,19 @@ discard block |
||
222 | 222 | ); |
223 | 223 | } |
224 | 224 | |
225 | -if($modx->hasPermission('exec_module')) { |
|
226 | - if($_SESSION['mgrRole'] != 1 && !empty($modx->config['use_udperms'])) { |
|
225 | +if($modx->hasPermission('exec_module')) { |
|
226 | + if($_SESSION['mgrRole'] != 1 && !empty($modx->config['use_udperms'])) { |
|
227 | 227 | $rs = $modx->db->query('SELECT DISTINCT sm.id, sm.name, sm.icon, mg.member |
228 | 228 | FROM ' . $modx->getFullTableName('site_modules') . ' AS sm |
229 | 229 | LEFT JOIN ' . $modx->getFullTableName('site_module_access') . ' AS sma ON sma.module = sm.id |
230 | 230 | LEFT JOIN ' . $modx->getFullTableName('member_groups') . ' AS mg ON sma.usergroup = mg.user_group |
231 | 231 | WHERE (mg.member IS NULL OR mg.member = ' . $modx->getLoginUserID() . ') AND sm.disabled != 1 AND sm.locked != 1 |
232 | 232 | ORDER BY sm.name'); |
233 | - } else { |
|
233 | + } else { |
|
234 | 234 | $rs = $modx->db->select('*', $modx->getFullTableName('site_modules'), 'disabled != 1', 'name'); |
235 | 235 | } |
236 | - if($modx->db->getRecordCount($rs)) { |
|
237 | - while ($row = $modx->db->getRow($rs)) { |
|
236 | + if($modx->db->getRecordCount($rs)) { |
|
237 | + while ($row = $modx->db->getRow($rs)) { |
|
238 | 238 | $sitemenu['module' . $row['id']] = array( |
239 | 239 | 'module' . $row['id'], |
240 | 240 | 'modules', |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | |
255 | 255 | // security menu items (users) |
256 | 256 | |
257 | -if($modx->hasPermission('edit_user')) { |
|
257 | +if($modx->hasPermission('edit_user')) { |
|
258 | 258 | $sitemenu['user_management_title'] = array( |
259 | 259 | 'user_management_title', |
260 | 260 | 'users', |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | ); |
271 | 271 | } |
272 | 272 | |
273 | -if($modx->hasPermission('edit_web_user')) { |
|
273 | +if($modx->hasPermission('edit_web_user')) { |
|
274 | 274 | $sitemenu['web_user_management_title'] = array( |
275 | 275 | 'web_user_management_title', |
276 | 276 | 'users', |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | ); |
287 | 287 | } |
288 | 288 | |
289 | -if($modx->hasPermission('edit_role')) { |
|
289 | +if($modx->hasPermission('edit_role')) { |
|
290 | 290 | $sitemenu['role_management_title'] = array( |
291 | 291 | 'role_management_title', |
292 | 292 | 'users', |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | ); |
303 | 303 | } |
304 | 304 | |
305 | -if($modx->hasPermission('access_permissions')) { |
|
305 | +if($modx->hasPermission('access_permissions')) { |
|
306 | 306 | $sitemenu['manager_permissions'] = array( |
307 | 307 | 'manager_permissions', |
308 | 308 | 'users', |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | ); |
319 | 319 | } |
320 | 320 | |
321 | -if($modx->hasPermission('web_access_permissions')) { |
|
321 | +if($modx->hasPermission('web_access_permissions')) { |
|
322 | 322 | $sitemenu['web_permissions'] = array( |
323 | 323 | 'web_permissions', |
324 | 324 | 'users', |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | '' |
375 | 375 | ); |
376 | 376 | |
377 | -if($modx->hasPermission('bk_manager')) { |
|
377 | +if($modx->hasPermission('bk_manager')) { |
|
378 | 378 | $sitemenu['bk_manager'] = array( |
379 | 379 | 'bk_manager', |
380 | 380 | 'tools', |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | ); |
391 | 391 | } |
392 | 392 | |
393 | -if($modx->hasPermission('remove_locks')) { |
|
393 | +if($modx->hasPermission('remove_locks')) { |
|
394 | 394 | $sitemenu['remove_locks'] = array( |
395 | 395 | 'remove_locks', |
396 | 396 | 'tools', |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | ); |
407 | 407 | } |
408 | 408 | |
409 | -if($modx->hasPermission('import_static')) { |
|
409 | +if($modx->hasPermission('import_static')) { |
|
410 | 410 | $sitemenu['import_site'] = array( |
411 | 411 | 'import_site', |
412 | 412 | 'tools', |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | ); |
423 | 423 | } |
424 | 424 | |
425 | -if($modx->hasPermission('export_static')) { |
|
425 | +if($modx->hasPermission('export_static')) { |
|
426 | 426 | $sitemenu['export_site'] = array( |
427 | 427 | 'export_site', |
428 | 428 | 'tools', |
@@ -439,19 +439,21 @@ discard block |
||
439 | 439 | } |
440 | 440 | |
441 | 441 | $menu = $modx->invokeEvent("OnManagerMenuPrerender", array('menu' => $sitemenu)); |
442 | -if(is_array($menu)) { |
|
442 | +if(is_array($menu)) { |
|
443 | 443 | $newmenu = array(); |
444 | - foreach($menu as $item){ |
|
445 | - if(is_array(unserialize($item))){ |
|
444 | + foreach($menu as $item) { |
|
445 | + if(is_array(unserialize($item))) { |
|
446 | 446 | $newmenu = array_merge($newmenu, unserialize($item)); |
447 | 447 | } |
448 | 448 | } |
449 | - if(count($newmenu)> 0) $sitemenu = $newmenu; |
|
450 | -} |
|
449 | + if(count($newmenu)> 0) { |
|
450 | + $sitemenu = $newmenu; |
|
451 | + } |
|
452 | + } |
|
451 | 453 | |
452 | -if(file_exists(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/includes/menu.class.inc.php')) { |
|
454 | +if(file_exists(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/includes/menu.class.inc.php')) { |
|
453 | 455 | include_once(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/includes/menu.class.inc.php'); |
454 | -} else { |
|
456 | +} else { |
|
455 | 457 | include_once(MODX_MANAGER_PATH . 'includes/menu.class.inc.php'); |
456 | 458 | } |
457 | 459 | $menu = new EVOmenu(); |
@@ -1,10 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class DATEPICKER { |
|
4 | - function __construct() { |
|
3 | +class DATEPICKER |
|
4 | +{ |
|
5 | + function __construct() |
|
6 | + { |
|
5 | 7 | } |
6 | 8 | |
7 | - function getDP() { |
|
9 | + function getDP() |
|
10 | + { |
|
8 | 11 | global $modx, $_lang; |
9 | 12 | |
10 | 13 | $tpl = file_get_contents(dirname(__FILE__) . '/datepicker.tpl'); |
@@ -12,17 +12,20 @@ |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class type_img { |
|
15 | +class type_img |
|
16 | +{ |
|
16 | 17 | |
17 | - public function checkFile($file, array $config) { |
|
18 | + public function checkFile($file, array $config) |
|
19 | + { |
|
18 | 20 | |
19 | 21 | $driver = isset($config['imageDriversPriority']) |
20 | 22 | ? image::getDriver(explode(" ", $config['imageDriversPriority'])) : "gd"; |
21 | 23 | |
22 | 24 | $img = image::factory($driver, $file); |
23 | 25 | |
24 | - if ($img->initError) |
|
25 | - return "Unknown image format/encoding."; |
|
26 | + if ($img->initError) { |
|
27 | + return "Unknown image format/encoding."; |
|
28 | + } |
|
26 | 29 | |
27 | 30 | return true; |
28 | 31 | } |
@@ -12,20 +12,25 @@ |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class type_mime { |
|
15 | +class type_mime |
|
16 | +{ |
|
16 | 17 | |
17 | - public function checkFile($file, array $config) { |
|
18 | - if (!class_exists("finfo")) |
|
19 | - return "Fileinfo PECL extension is missing."; |
|
18 | + public function checkFile($file, array $config) |
|
19 | + { |
|
20 | + if (!class_exists("finfo")) { |
|
21 | + return "Fileinfo PECL extension is missing."; |
|
22 | + } |
|
20 | 23 | |
21 | - if (!isset($config['params'])) |
|
22 | - return "Undefined MIME types."; |
|
24 | + if (!isset($config['params'])) { |
|
25 | + return "Undefined MIME types."; |
|
26 | + } |
|
23 | 27 | |
24 | 28 | $finfo = strlen($config['mime_magic']) |
25 | 29 | ? new finfo(FILEINFO_MIME, $config['mime_magic']) |
26 | 30 | : new finfo(FILEINFO_MIME); |
27 | - if (!$finfo) |
|
28 | - return "Opening fileinfo database failed."; |
|
31 | + if (!$finfo) { |
|
32 | + return "Opening fileinfo database failed."; |
|
33 | + } |
|
29 | 34 | |
30 | 35 | $type = $finfo->file($file); |
31 | 36 | $type = substr($type, 0, strrpos($type, ";")); |
@@ -41,17 +41,20 @@ discard block |
||
41 | 41 | $_GET['langCode'] = $modx_lang_attribute; |
42 | 42 | |
43 | 43 | // PHP VERSION CHECK |
44 | -if (substr(PHP_VERSION, 0, strpos(PHP_VERSION, '.')) < 5) |
|
44 | +if (substr(PHP_VERSION, 0, strpos(PHP_VERSION, '.')) < 5) { |
|
45 | 45 | die("You are using PHP " . PHP_VERSION . " when KCFinder require at least version 5! Some systems has an option to change the active PHP version. Please refer to your hosting provider or upgrade your PHP distribution."); |
46 | +} |
|
46 | 47 | |
47 | 48 | |
48 | 49 | // SAFE MODE CHECK |
49 | -if (ini_get("safe_mode")) |
|
50 | +if (ini_get("safe_mode")) { |
|
50 | 51 | die("The \"safe_mode\" PHP ini setting is turned on! You cannot run KCFinder in safe mode."); |
52 | +} |
|
51 | 53 | |
52 | 54 | |
53 | 55 | // MAGIC AUTOLOAD CLASSES FUNCTION |
54 | -function autoloadda9d06472ccb71b84928677ce2a6ca89($class) { |
|
56 | +function autoloadda9d06472ccb71b84928677ce2a6ca89($class) |
|
57 | +{ |
|
55 | 58 | static $classes = null; |
56 | 59 | if ($classes === null) { |
57 | 60 | $classes = array( |
@@ -84,7 +87,8 @@ discard block |
||
84 | 87 | // json_encode() IMPLEMENTATION IF JSON EXTENSION IS MISSING |
85 | 88 | if (!function_exists("json_encode")) { |
86 | 89 | |
87 | - function kcfinder_json_string_encode($string) { |
|
90 | + function kcfinder_json_string_encode($string) |
|
91 | + { |
|
88 | 92 | return '"' . |
89 | 93 | str_replace('/', "\\/", |
90 | 94 | str_replace("\t", "\\t", |
@@ -95,37 +99,43 @@ discard block |
||
95 | 99 | $string)))))) . '"'; |
96 | 100 | } |
97 | 101 | |
98 | - function json_encode($data) { |
|
102 | + function json_encode($data) |
|
103 | + { |
|
99 | 104 | |
100 | 105 | if (is_array($data)) { |
101 | 106 | $ret = array(); |
102 | 107 | |
103 | 108 | // OBJECT |
104 | 109 | if (array_keys($data) !== range(0, count($data) - 1)) { |
105 | - foreach ($data as $key => $val) |
|
106 | - $ret[] = kcfinder_json_string_encode($key) . ':' . json_encode($val); |
|
110 | + foreach ($data as $key => $val) { |
|
111 | + $ret[] = kcfinder_json_string_encode($key) . ':' . json_encode($val); |
|
112 | + } |
|
107 | 113 | return "{" . implode(",", $ret) . "}"; |
108 | 114 | |
109 | 115 | // ARRAY |
110 | 116 | } else { |
111 | - foreach ($data as $val) |
|
112 | - $ret[] = json_encode($val); |
|
117 | + foreach ($data as $val) { |
|
118 | + $ret[] = json_encode($val); |
|
119 | + } |
|
113 | 120 | return "[" . implode(",", $ret) . "]"; |
114 | 121 | } |
115 | 122 | |
116 | 123 | // BOOLEAN OR NULL |
117 | - } elseif (is_bool($data) || ($data === null)) |
|
118 | - return ($data === null) |
|
124 | + } elseif (is_bool($data) || ($data === null)) { |
|
125 | + return ($data === null) |
|
119 | 126 | ? "null" |
120 | 127 | : ($data ? "true" : "false"); |
128 | + } |
|
121 | 129 | |
122 | 130 | // FLOAT |
123 | - elseif (is_float($data)) |
|
124 | - return rtrim(rtrim(number_format($data, 14, ".", ""), "0"), "."); |
|
131 | + elseif (is_float($data)) { |
|
132 | + return rtrim(rtrim(number_format($data, 14, ".", ""), "0"), "."); |
|
133 | + } |
|
125 | 134 | |
126 | 135 | // INTEGER |
127 | - elseif (is_int($data)) |
|
128 | - return $data; |
|
136 | + elseif (is_int($data)) { |
|
137 | + return $data; |
|
138 | + } |
|
129 | 139 | |
130 | 140 | // STRING |
131 | 141 | return kcfinder_json_string_encode($data); |
@@ -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 | } |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class uploader { |
|
15 | +class uploader |
|
16 | +{ |
|
16 | 17 | |
17 | 18 | /** Release version */ |
18 | 19 | const VERSION = "2.54"; |
@@ -104,17 +105,21 @@ discard block |
||
104 | 105 | /** Magic method which allows read-only access to protected or private class properties |
105 | 106 | * @param string $property |
106 | 107 | * @return mixed */ |
107 | - public function __get($property) { |
|
108 | + public function __get($property) |
|
109 | + { |
|
108 | 110 | return property_exists($this, $property) ? $this->$property : null; |
109 | 111 | } |
110 | 112 | |
111 | - public function __construct($modx) { |
|
113 | + public function __construct($modx) |
|
114 | + { |
|
112 | 115 | |
113 | 116 | //MODX |
114 | 117 | try { |
115 | 118 | if ($modx instanceof DocumentParser) { |
116 | 119 | $this->modx = $modx; |
117 | - } else throw new Exception('MODX should be instance of DocumentParser'); |
|
120 | + } else { |
|
121 | + throw new Exception('MODX should be instance of DocumentParser'); |
|
122 | + } |
|
118 | 123 | } catch (Exception $e) { |
119 | 124 | die($e->getMessage()); |
120 | 125 | } |
@@ -129,26 +134,34 @@ discard block |
||
129 | 134 | // SET CMS INTEGRATION ATTRIBUTE |
130 | 135 | if (isset($this->get['cms']) && |
131 | 136 | in_array($this->get['cms'], array("drupal")) |
132 | - ) |
|
133 | - $this->cms = $this->get['cms']; |
|
137 | + ) { |
|
138 | + $this->cms = $this->get['cms']; |
|
139 | + } |
|
134 | 140 | |
135 | 141 | // LINKING UPLOADED FILE |
136 | - if (count($_FILES)) |
|
137 | - $this->file = &$_FILES[key($_FILES)]; |
|
142 | + if (count($_FILES)) { |
|
143 | + $this->file = &$_FILES[key($_FILES)]; |
|
144 | + } |
|
138 | 145 | |
139 | 146 | // LOAD DEFAULT CONFIGURATION |
140 | 147 | require "config.php"; |
141 | 148 | |
142 | 149 | // SETTING UP SESSION |
143 | - if (isset($_CONFIG['_sessionLifetime'])) |
|
144 | - ini_set('session.gc_maxlifetime', $_CONFIG['_sessionLifetime'] * 60); |
|
145 | - if (isset($_CONFIG['_sessionDir'])) |
|
146 | - ini_set('session.save_path', $_CONFIG['_sessionDir']); |
|
147 | - if (isset($_CONFIG['_sessionDomain'])) |
|
148 | - ini_set('session.cookie_domain', $_CONFIG['_sessionDomain']); |
|
150 | + if (isset($_CONFIG['_sessionLifetime'])) { |
|
151 | + ini_set('session.gc_maxlifetime', $_CONFIG['_sessionLifetime'] * 60); |
|
152 | + } |
|
153 | + if (isset($_CONFIG['_sessionDir'])) { |
|
154 | + ini_set('session.save_path', $_CONFIG['_sessionDir']); |
|
155 | + } |
|
156 | + if (isset($_CONFIG['_sessionDomain'])) { |
|
157 | + ini_set('session.cookie_domain', $_CONFIG['_sessionDomain']); |
|
158 | + } |
|
149 | 159 | switch ($this->cms) { |
150 | 160 | case "drupal": break; |
151 | - default: if (!session_id()) session_start(); break; |
|
161 | + default: if (!session_id()) { |
|
162 | + session_start(); |
|
163 | + } |
|
164 | + break; |
|
152 | 165 | } |
153 | 166 | |
154 | 167 | // RELOAD DEFAULT CONFIGURATION |
@@ -159,31 +172,37 @@ discard block |
||
159 | 172 | if (isset($_CONFIG['_sessionVar']) && |
160 | 173 | is_array($_CONFIG['_sessionVar']) |
161 | 174 | ) { |
162 | - foreach ($_CONFIG['_sessionVar'] as $key => $val) |
|
163 | - if ((substr($key, 0, 1) != "_") && isset($_CONFIG[$key])) |
|
175 | + foreach ($_CONFIG['_sessionVar'] as $key => $val) { |
|
176 | + if ((substr($key, 0, 1) != "_") && isset($_CONFIG[$key])) |
|
164 | 177 | $this->config[$key] = $val; |
165 | - if (!isset($this->config['_sessionVar']['self'])) |
|
166 | - $this->config['_sessionVar']['self'] = array(); |
|
178 | + } |
|
179 | + if (!isset($this->config['_sessionVar']['self'])) { |
|
180 | + $this->config['_sessionVar']['self'] = array(); |
|
181 | + } |
|
167 | 182 | $this->session = &$this->config['_sessionVar']['self']; |
168 | - } else |
|
169 | - $this->session = &$_SESSION; |
|
183 | + } else { |
|
184 | + $this->session = &$_SESSION; |
|
185 | + } |
|
170 | 186 | |
171 | 187 | // IMAGE DRIVER INIT |
172 | 188 | if (isset($this->config['imageDriversPriority'])) { |
173 | 189 | $this->config['imageDriversPriority'] = |
174 | 190 | text::clearWhitespaces($this->config['imageDriversPriority']); |
175 | 191 | $driver = image::getDriver(explode(' ', $this->config['imageDriversPriority'])); |
176 | - if ($driver !== false) |
|
177 | - $this->imageDriver = $driver; |
|
192 | + if ($driver !== false) { |
|
193 | + $this->imageDriver = $driver; |
|
194 | + } |
|
178 | 195 | } |
179 | 196 | if ((!isset($driver) || ($driver === false)) && |
180 | 197 | (image::getDriver(array($this->imageDriver)) === false) |
181 | - ) |
|
182 | - die("Cannot find any of the supported PHP image extensions!"); |
|
198 | + ) { |
|
199 | + die("Cannot find any of the supported PHP image extensions!"); |
|
200 | + } |
|
183 | 201 | |
184 | 202 | // WATERMARK INIT |
185 | - if (isset($this->config['watermark']) && is_string($this->config['watermark'])) |
|
186 | - $this->config['watermark'] = array('file' => $this->config['watermark']); |
|
203 | + if (isset($this->config['watermark']) && is_string($this->config['watermark'])) { |
|
204 | + $this->config['watermark'] = array('file' => $this->config['watermark']); |
|
205 | + } |
|
187 | 206 | |
188 | 207 | // GET TYPE DIRECTORY |
189 | 208 | $this->types = &$this->config['types']; |
@@ -197,9 +216,10 @@ discard block |
||
197 | 216 | |
198 | 217 | // LOAD TYPE DIRECTORY SPECIFIC CONFIGURATION IF EXISTS |
199 | 218 | if (is_array($this->types[$this->type])) { |
200 | - foreach ($this->types[$this->type] as $key => $val) |
|
201 | - if (in_array($key, $this->typeSettings)) |
|
219 | + foreach ($this->types[$this->type] as $key => $val) { |
|
220 | + if (in_array($key, $this->typeSettings)) |
|
202 | 221 | $this->config[$key] = $val; |
222 | + } |
|
203 | 223 | $this->types[$this->type] = isset($this->types[$this->type]['type']) |
204 | 224 | ? $this->types[$this->type]['type'] : ""; |
205 | 225 | } |
@@ -209,12 +229,14 @@ discard block |
||
209 | 229 | $ip = '/^' . implode('\.', array($ip, $ip, $ip, $ip)) . '$/'; |
210 | 230 | if (preg_match($ip, $_SERVER['HTTP_HOST']) || |
211 | 231 | preg_match('/^[^\.]+$/', $_SERVER['HTTP_HOST']) |
212 | - ) |
|
213 | - $this->config['cookieDomain'] = ""; |
|
214 | - elseif (!strlen($this->config['cookieDomain'])) |
|
215 | - $this->config['cookieDomain'] = $_SERVER['HTTP_HOST']; |
|
216 | - if (!strlen($this->config['cookiePath'])) |
|
217 | - $this->config['cookiePath'] = "/"; |
|
232 | + ) { |
|
233 | + $this->config['cookieDomain'] = ""; |
|
234 | + } elseif (!strlen($this->config['cookieDomain'])) { |
|
235 | + $this->config['cookieDomain'] = $_SERVER['HTTP_HOST']; |
|
236 | + } |
|
237 | + if (!strlen($this->config['cookiePath'])) { |
|
238 | + $this->config['cookiePath'] = "/"; |
|
239 | + } |
|
218 | 240 | |
219 | 241 | // UPLOAD FOLDER INIT |
220 | 242 | |
@@ -250,26 +272,30 @@ discard block |
||
250 | 272 | $this->typeDir = "{$this->config['uploadDir']}/{$this->type}"; |
251 | 273 | $this->typeURL = "{$this->config['uploadURL']}/{$this->type}"; |
252 | 274 | } |
253 | - if (!is_dir($this->config['uploadDir'])) |
|
254 | - @mkdir($this->config['uploadDir'], $this->config['dirPerms']); |
|
275 | + if (!is_dir($this->config['uploadDir'])) { |
|
276 | + @mkdir($this->config['uploadDir'], $this->config['dirPerms']); |
|
277 | + } |
|
255 | 278 | |
256 | 279 | // HOST APPLICATIONS INIT |
257 | - if (isset($this->get['CKEditorFuncNum'])) |
|
258 | - $this->opener['CKEditor']['funcNum'] = $this->get['CKEditorFuncNum']; |
|
280 | + if (isset($this->get['CKEditorFuncNum'])) { |
|
281 | + $this->opener['CKEditor']['funcNum'] = $this->get['CKEditorFuncNum']; |
|
282 | + } |
|
259 | 283 | if (isset($this->get['opener']) && |
260 | 284 | (strtolower($this->get['opener']) == "tinymce") && |
261 | 285 | isset($this->config['_tinyMCEPath']) && |
262 | 286 | strlen($this->config['_tinyMCEPath']) |
263 | - ) |
|
264 | - $this->opener['TinyMCE'] = true; |
|
287 | + ) { |
|
288 | + $this->opener['TinyMCE'] = true; |
|
289 | + } |
|
265 | 290 | |
266 | 291 | // LOCALIZATION |
267 | - foreach ($this->langInputNames as $key) |
|
268 | - if (isset($this->get[$key]) && |
|
292 | + foreach ($this->langInputNames as $key) { |
|
293 | + if (isset($this->get[$key]) && |
|
269 | 294 | preg_match('/^[a-z][a-z\._\-]*$/i', $this->get[$key]) && |
270 | 295 | file_exists("lang/" . strtolower($this->get[$key]) . ".php") |
271 | 296 | ) { |
272 | 297 | $this->lang = $this->get[$key]; |
298 | + } |
|
273 | 299 | break; |
274 | 300 | } |
275 | 301 | $this->localize($this->lang); |
@@ -280,31 +306,39 @@ discard block |
||
280 | 306 | ) { |
281 | 307 | $htaccess = "{$this->config['uploadDir']}/.htaccess"; |
282 | 308 | if (!file_exists($htaccess)) { |
283 | - if (!@file_put_contents($htaccess, $this->get_htaccess())) |
|
284 | - $this->backMsg("Cannot write to upload folder. {$this->config['uploadDir']}"); |
|
309 | + if (!@file_put_contents($htaccess, $this->get_htaccess())) { |
|
310 | + $this->backMsg("Cannot write to upload folder. {$this->config['uploadDir']}"); |
|
311 | + } |
|
285 | 312 | } else { |
286 | - if (false === ($data = @file_get_contents($htaccess))) |
|
287 | - $this->backMsg("Cannot read .htaccess"); |
|
288 | - if (($data != $this->get_htaccess()) && !@file_put_contents($htaccess, $data)) |
|
289 | - $this->backMsg("Incorrect .htaccess file. Cannot rewrite it!"); |
|
313 | + if (false === ($data = @file_get_contents($htaccess))) { |
|
314 | + $this->backMsg("Cannot read .htaccess"); |
|
315 | + } |
|
316 | + if (($data != $this->get_htaccess()) && !@file_put_contents($htaccess, $data)) { |
|
317 | + $this->backMsg("Incorrect .htaccess file. Cannot rewrite it!"); |
|
318 | + } |
|
290 | 319 | } |
291 | 320 | } |
292 | 321 | |
293 | 322 | // CHECK & CREATE UPLOAD FOLDER |
294 | 323 | if (!is_dir($this->typeDir)) { |
295 | - if (!mkdir($this->typeDir, $this->config['dirPerms'])) |
|
296 | - $this->backMsg("Cannot create {dir} folder.", array('dir' => $this->type)); |
|
297 | - } elseif (!is_readable($this->typeDir)) |
|
298 | - $this->backMsg("Cannot read upload folder."); |
|
324 | + if (!mkdir($this->typeDir, $this->config['dirPerms'])) { |
|
325 | + $this->backMsg("Cannot create {dir} folder.", array('dir' => $this->type)); |
|
326 | + } |
|
327 | + } elseif (!is_readable($this->typeDir)) { |
|
328 | + $this->backMsg("Cannot read upload folder."); |
|
329 | + } |
|
299 | 330 | } |
300 | 331 | |
301 | - public function upload() { |
|
332 | + public function upload() |
|
333 | + { |
|
302 | 334 | $config = &$this->config; |
303 | 335 | $file = &$this->file; |
304 | 336 | $url = $message = ""; |
305 | 337 | |
306 | 338 | if ($config['disabled'] || !$config['access']['files']['upload']) { |
307 | - if (isset($file['tmp_name'])) @unlink($file['tmp_name']); |
|
339 | + if (isset($file['tmp_name'])) { |
|
340 | + @unlink($file['tmp_name']); |
|
341 | + } |
|
308 | 342 | $message = $this->label("You don't have permissions to upload files."); |
309 | 343 | |
310 | 344 | } elseif (true === ($message = $this->checkUploadedFile())) { |
@@ -315,9 +349,9 @@ discard block |
||
315 | 349 | (false !== ($gdir = $this->checkInputDir($this->get['dir']))) |
316 | 350 | ) { |
317 | 351 | $udir = path::normalize("$dir$gdir"); |
318 | - if (substr($udir, 0, strlen($dir)) !== $dir) |
|
319 | - $message = $this->label("Unknown error."); |
|
320 | - else { |
|
352 | + if (substr($udir, 0, strlen($dir)) !== $dir) { |
|
353 | + $message = $this->label("Unknown error."); |
|
354 | + } else { |
|
321 | 355 | $l = strlen($dir); |
322 | 356 | $dir = "$udir/"; |
323 | 357 | $udir = substr($udir, $l); |
@@ -325,8 +359,9 @@ discard block |
||
325 | 359 | } |
326 | 360 | |
327 | 361 | if (!strlen($message)) { |
328 | - if (!is_dir(path::normalize($dir))) |
|
329 | - @mkdir(path::normalize($dir), $this->config['dirPerms'], true); |
|
362 | + if (!is_dir(path::normalize($dir))) { |
|
363 | + @mkdir(path::normalize($dir), $this->config['dirPerms'], true); |
|
364 | + } |
|
330 | 365 | |
331 | 366 | $filename = $this->normalizeFilename($file['name']); |
332 | 367 | $target = file::getInexistantFilename($dir . $filename); |
@@ -334,21 +369,25 @@ discard block |
||
334 | 369 | if (!@move_uploaded_file($file['tmp_name'], $target) && |
335 | 370 | !@rename($file['tmp_name'], $target) && |
336 | 371 | !@copy($file['tmp_name'], $target) |
337 | - ) |
|
338 | - $message = $this->label("Cannot move uploaded file to target folder."); |
|
339 | - else { |
|
340 | - if (function_exists('chmod')) |
|
341 | - @chmod($target, $this->config['filePerms']); |
|
372 | + ) { |
|
373 | + $message = $this->label("Cannot move uploaded file to target folder."); |
|
374 | + } else { |
|
375 | + if (function_exists('chmod')) { |
|
376 | + @chmod($target, $this->config['filePerms']); |
|
377 | + } |
|
342 | 378 | $this->makeThumb($target); |
343 | 379 | $url = $this->typeURL; |
344 | - if (isset($udir)) $url .= "/$udir"; |
|
380 | + if (isset($udir)) { |
|
381 | + $url .= "/$udir"; |
|
382 | + } |
|
345 | 383 | $url .= "/" . basename($target); |
346 | 384 | if (preg_match('/^([a-z]+)\:\/\/([^\/^\:]+)(\:(\d+))?\/(.+)$/', $url, $patt)) { |
347 | 385 | list($unused, $protocol, $domain, $unused, $port, $path) = $patt; |
348 | 386 | $base = "$protocol://$domain" . (strlen($port) ? ":$port" : "") . "/"; |
349 | 387 | $url = $base . path::urlPathEncode($path); |
350 | - } else |
|
351 | - $url = path::urlPathEncode($url); |
|
388 | + } else { |
|
389 | + $url = path::urlPathEncode($url); |
|
390 | + } |
|
352 | 391 | } |
353 | 392 | } |
354 | 393 | } |
@@ -356,16 +395,19 @@ discard block |
||
356 | 395 | if (strlen($message) && |
357 | 396 | isset($this->file['tmp_name']) && |
358 | 397 | file_exists($this->file['tmp_name']) |
359 | - ) |
|
360 | - @unlink($this->file['tmp_name']); |
|
398 | + ) { |
|
399 | + @unlink($this->file['tmp_name']); |
|
400 | + } |
|
361 | 401 | |
362 | - if (strlen($message) && method_exists($this, 'errorMsg')) |
|
363 | - $this->errorMsg($message); |
|
402 | + if (strlen($message) && method_exists($this, 'errorMsg')) { |
|
403 | + $this->errorMsg($message); |
|
404 | + } |
|
364 | 405 | $this->callBack($url, $message); |
365 | 406 | } |
366 | 407 | |
367 | 408 | |
368 | - protected function getTransaliasSettings() { |
|
409 | + protected function getTransaliasSettings() |
|
410 | + { |
|
369 | 411 | global $modx; |
370 | 412 | |
371 | 413 | // Cleaning uploaded filename? |
@@ -385,7 +427,8 @@ discard block |
||
385 | 427 | } |
386 | 428 | |
387 | 429 | |
388 | - protected function normalizeFilename($filename) { |
|
430 | + protected function normalizeFilename($filename) |
|
431 | + { |
|
389 | 432 | if ($this->getTransaliasSettings()) { |
390 | 433 | $format = strrchr($filename, "."); |
391 | 434 | $filename = str_replace($format, "", $filename); |
@@ -394,16 +437,19 @@ discard block |
||
394 | 437 | return $filename; |
395 | 438 | } |
396 | 439 | |
397 | - protected function normalizeDirname($dirname) { |
|
440 | + protected function normalizeDirname($dirname) |
|
441 | + { |
|
398 | 442 | return $this->modx->stripAlias($dirname); |
399 | 443 | } |
400 | 444 | |
401 | - protected function checkUploadedFile(array $aFile=null) { |
|
445 | + protected function checkUploadedFile(array $aFile=null) |
|
446 | + { |
|
402 | 447 | $config = &$this->config; |
403 | 448 | $file = ($aFile === null) ? $this->file : $aFile; |
404 | 449 | |
405 | - if (!is_array($file) || !isset($file['name'])) |
|
406 | - return $this->label("Unknown error"); |
|
450 | + if (!is_array($file) || !isset($file['name'])) { |
|
451 | + return $this->label("Unknown error"); |
|
452 | + } |
|
407 | 453 | |
408 | 454 | if (is_array($file['name'])) { |
409 | 455 | foreach ($file['name'] as $i => $name) { |
@@ -412,8 +458,9 @@ discard block |
||
412 | 458 | 'tmp_name' => $file['tmp_name'][$i], |
413 | 459 | 'error' => $file['error'][$i] |
414 | 460 | )); |
415 | - if ($return !== true) |
|
416 | - return "$name: $return"; |
|
461 | + if ($return !== true) { |
|
462 | + return "$name: $return"; |
|
463 | + } |
|
417 | 464 | } |
418 | 465 | return true; |
419 | 466 | } |
@@ -422,8 +469,8 @@ discard block |
||
422 | 469 | $typePatt = strtolower(text::clearWhitespaces($this->types[$this->type])); |
423 | 470 | |
424 | 471 | // CHECK FOR UPLOAD ERRORS |
425 | - if ($file['error']) |
|
426 | - return |
|
472 | + if ($file['error']) { |
|
473 | + return |
|
427 | 474 | ($file['error'] == UPLOAD_ERR_INI_SIZE) ? |
428 | 475 | $this->label("The uploaded file exceeds {size} bytes.", |
429 | 476 | array('size' => ini_get('upload_max_filesize'))) : ( |
@@ -440,14 +487,17 @@ discard block |
||
440 | 487 | $this->label("Failed to write file.") : |
441 | 488 | $this->label("Unknown error.") |
442 | 489 | ))))); |
490 | + } |
|
443 | 491 | |
444 | 492 | // HIDDEN FILENAMES CHECK |
445 | - elseif (substr($file['name'], 0, 1) == ".") |
|
446 | - return $this->label("File name shouldn't begins with '.'"); |
|
493 | + elseif (substr($file['name'], 0, 1) == ".") { |
|
494 | + return $this->label("File name shouldn't begins with '.'"); |
|
495 | + } |
|
447 | 496 | |
448 | 497 | // EXTENSION CHECK |
449 | - elseif (!$this->validateExtension($extension, $this->type)) |
|
450 | - return $this->label("Denied file extension."); |
|
498 | + elseif (!$this->validateExtension($extension, $this->type)) { |
|
499 | + return $this->label("Denied file extension."); |
|
500 | + } |
|
451 | 501 | |
452 | 502 | // SPECIAL DIRECTORY TYPES CHECK (e.g. *img) |
453 | 503 | elseif (preg_match('/^\*([^ ]+)(.*)?$/s', $typePatt, $patt)) { |
@@ -457,70 +507,84 @@ discard block |
||
457 | 507 | $type = new $class(); |
458 | 508 | $cfg = $config; |
459 | 509 | $cfg['filename'] = $file['name']; |
460 | - if (strlen($params)) |
|
461 | - $cfg['params'] = trim($params); |
|
510 | + if (strlen($params)) { |
|
511 | + $cfg['params'] = trim($params); |
|
512 | + } |
|
462 | 513 | $response = $type->checkFile($file['tmp_name'], $cfg); |
463 | - if ($response !== true) |
|
464 | - return $this->label($response); |
|
465 | - } else |
|
466 | - return $this->label("Non-existing directory type."); |
|
514 | + if ($response !== true) { |
|
515 | + return $this->label($response); |
|
516 | + } |
|
517 | + } else { |
|
518 | + return $this->label("Non-existing directory type."); |
|
519 | + } |
|
467 | 520 | } |
468 | 521 | |
469 | 522 | // IMAGE RESIZE |
470 | 523 | $img = image::factory($this->imageDriver, $file['tmp_name']); |
471 | - if (!$img->initError && !$this->imageResize($img, $file['tmp_name'])) |
|
472 | - return $this->label("The image is too big and/or cannot be resized."); |
|
524 | + if (!$img->initError && !$this->imageResize($img, $file['tmp_name'])) { |
|
525 | + return $this->label("The image is too big and/or cannot be resized."); |
|
526 | + } |
|
473 | 527 | |
474 | 528 | |
475 | 529 | // CHECK FOR MODX MAX FILE SIZE |
476 | 530 | $actualfilesize=filesize($file['tmp_name']); |
477 | - if (isset($this->config['maxfilesize']) && $actualfilesize > $this->config['maxfilesize']) |
|
478 | - return $this->label("File is too big: ".$actualfilesize." Bytes. (max ".$this->config['maxfilesize']." Bytes)"); |
|
531 | + if (isset($this->config['maxfilesize']) && $actualfilesize > $this->config['maxfilesize']) { |
|
532 | + return $this->label("File is too big: ".$actualfilesize." Bytes. (max ".$this->config['maxfilesize']." Bytes)"); |
|
533 | + } |
|
479 | 534 | |
480 | 535 | return true; |
481 | 536 | } |
482 | 537 | |
483 | - protected function checkInputDir($dir, $inclType=true, $existing=true) { |
|
538 | + protected function checkInputDir($dir, $inclType=true, $existing=true) |
|
539 | + { |
|
484 | 540 | $dir = path::normalize($dir); |
485 | - if (substr($dir, 0, 1) == "/") |
|
486 | - $dir = substr($dir, 1); |
|
541 | + if (substr($dir, 0, 1) == "/") { |
|
542 | + $dir = substr($dir, 1); |
|
543 | + } |
|
487 | 544 | |
488 | - if ((substr($dir, 0, 1) == ".") || (substr(basename($dir), 0, 1) == ".")) |
|
489 | - return false; |
|
545 | + if ((substr($dir, 0, 1) == ".") || (substr(basename($dir), 0, 1) == ".")) { |
|
546 | + return false; |
|
547 | + } |
|
490 | 548 | |
491 | 549 | if ($inclType) { |
492 | 550 | $first = explode("/", $dir); |
493 | 551 | $first = $first[0]; |
494 | - if ($first != $this->type) |
|
495 | - return false; |
|
552 | + if ($first != $this->type) { |
|
553 | + return false; |
|
554 | + } |
|
496 | 555 | $return = $this->removeTypeFromPath($dir); |
497 | 556 | } else { |
498 | 557 | $return = $dir; |
499 | 558 | $dir = "{$this->type}/$dir"; |
500 | 559 | } |
501 | 560 | |
502 | - if (!$existing) |
|
503 | - return $return; |
|
561 | + if (!$existing) { |
|
562 | + return $return; |
|
563 | + } |
|
504 | 564 | |
505 | 565 | $path = "{$this->config['uploadDir']}/$dir"; |
506 | 566 | return (is_dir($path) && is_readable($path)) ? $return : false; |
507 | 567 | } |
508 | 568 | |
509 | - protected function validateExtension($ext, $type) { |
|
569 | + protected function validateExtension($ext, $type) |
|
570 | + { |
|
510 | 571 | $ext = trim(strtolower($ext)); |
511 | - if (!isset($this->types[$type])) |
|
512 | - return false; |
|
572 | + if (!isset($this->types[$type])) { |
|
573 | + return false; |
|
574 | + } |
|
513 | 575 | |
514 | 576 | $exts = strtolower(text::clearWhitespaces($this->config['deniedExts'])); |
515 | 577 | if (strlen($exts)) { |
516 | 578 | $exts = explode(" ", $exts); |
517 | - if (in_array($ext, $exts)) |
|
518 | - return false; |
|
579 | + if (in_array($ext, $exts)) { |
|
580 | + return false; |
|
581 | + } |
|
519 | 582 | } |
520 | 583 | |
521 | 584 | $exts = trim($this->types[$type]); |
522 | - if (!strlen($exts) || substr($exts, 0, 1) == "*") |
|
523 | - return true; |
|
585 | + if (!strlen($exts) || substr($exts, 0, 1) == "*") { |
|
586 | + return true; |
|
587 | + } |
|
524 | 588 | |
525 | 589 | if (substr($exts, 0, 1) == "!") { |
526 | 590 | $exts = explode(" ", trim(strtolower(substr($exts, 1)))); |
@@ -531,26 +595,32 @@ discard block |
||
531 | 595 | return in_array($ext, $exts); |
532 | 596 | } |
533 | 597 | |
534 | - protected function getTypeFromPath($path) { |
|
598 | + protected function getTypeFromPath($path) |
|
599 | + { |
|
535 | 600 | return preg_match('/^([^\/]*)\/.*$/', $path, $patt) |
536 | 601 | ? $patt[1] : $path; |
537 | 602 | } |
538 | 603 | |
539 | - protected function removeTypeFromPath($path) { |
|
604 | + protected function removeTypeFromPath($path) |
|
605 | + { |
|
540 | 606 | return preg_match('/^[^\/]*\/(.*)$/', $path, $patt) |
541 | 607 | ? $patt[1] : ""; |
542 | 608 | } |
543 | 609 | |
544 | - protected function imageResize($image, $file=null) { |
|
610 | + protected function imageResize($image, $file=null) |
|
611 | + { |
|
545 | 612 | |
546 | 613 | if (!($image instanceof image)) { |
547 | 614 | $img = image::factory($this->imageDriver, $image); |
548 | - if ($img->initError) return false; |
|
615 | + if ($img->initError) { |
|
616 | + return false; |
|
617 | + } |
|
549 | 618 | $file = $image; |
550 | - } elseif ($file === null) |
|
551 | - return false; |
|
552 | - else |
|
553 | - $img = $image; |
|
619 | + } elseif ($file === null) { |
|
620 | + return false; |
|
621 | + } else { |
|
622 | + $img = $image; |
|
623 | + } |
|
554 | 624 | |
555 | 625 | $orientation = 1; |
556 | 626 | if (function_exists("exif_read_data")) { |
@@ -572,8 +642,9 @@ discard block |
||
572 | 642 | ) |
573 | 643 | ) && |
574 | 644 | ($orientation == 1) |
575 | - ) |
|
576 | - return true; |
|
645 | + ) { |
|
646 | + return true; |
|
647 | + } |
|
577 | 648 | |
578 | 649 | |
579 | 650 | // PROPORTIONAL RESIZE |
@@ -593,15 +664,17 @@ discard block |
||
593 | 664 | $width = $img->getPropWidth($height); |
594 | 665 | } |
595 | 666 | |
596 | - if (isset($width) && isset($height) && !$img->resize($width, $height)) |
|
597 | - return false; |
|
667 | + if (isset($width) && isset($height) && !$img->resize($width, $height)) { |
|
668 | + return false; |
|
669 | + } |
|
598 | 670 | |
599 | 671 | // RESIZE TO FIT |
600 | 672 | } elseif ( |
601 | 673 | $this->config['maxImageWidth'] && $this->config['maxImageHeight'] && |
602 | 674 | !$img->resizeFit($this->config['maxImageWidth'], $this->config['maxImageHeight']) |
603 | - ) |
|
604 | - return false; |
|
675 | + ) { |
|
676 | + return false; |
|
677 | + } |
|
605 | 678 | |
606 | 679 | // AUTO FLIP AND ROTATE FROM EXIF |
607 | 680 | if ((($orientation == 2) && !$img->flipHorizontal()) || |
@@ -611,11 +684,13 @@ discard block |
||
611 | 684 | (($orientation == 6) && !$img->rotate(90)) || |
612 | 685 | (($orientation == 7) && (!$img->flipHorizontal() || !$img->rotate(90))) || |
613 | 686 | (($orientation == 8) && !$img->rotate(270)) |
614 | - ) |
|
615 | - return false; |
|
616 | - if (($orientation >= 2) && ($orientation <= 8) && ($this->imageDriver == "imagick")) |
|
617 | - try { |
|
687 | + ) { |
|
688 | + return false; |
|
689 | + } |
|
690 | + if (($orientation >= 2) && ($orientation <= 8) && ($this->imageDriver == "imagick")) { |
|
691 | + try { |
|
618 | 692 | $img->image->setImageProperty('exif:Orientation', "1"); |
693 | + } |
|
619 | 694 | } catch (Exception $e) {} |
620 | 695 | |
621 | 696 | // WATERMARK |
@@ -646,22 +721,26 @@ discard block |
||
646 | 721 | |
647 | 722 | } |
648 | 723 | |
649 | - protected function makeThumb($file, $overwrite=true) { |
|
724 | + protected function makeThumb($file, $overwrite=true) |
|
725 | + { |
|
650 | 726 | $img = image::factory($this->imageDriver, $file); |
651 | 727 | |
652 | 728 | // Drop files which are not images |
653 | - if ($img->initError) |
|
654 | - return true; |
|
729 | + if ($img->initError) { |
|
730 | + return true; |
|
731 | + } |
|
655 | 732 | |
656 | 733 | $thumb = substr($file, strlen($this->config['uploadDir'])); |
657 | 734 | $thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb; |
658 | 735 | $thumb = path::normalize($thumb); |
659 | 736 | $thumbDir = dirname($thumb); |
660 | - if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) |
|
661 | - return false; |
|
737 | + if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) { |
|
738 | + return false; |
|
739 | + } |
|
662 | 740 | |
663 | - if (!$overwrite && is_file($thumb)) |
|
664 | - return true; |
|
741 | + if (!$overwrite && is_file($thumb)) { |
|
742 | + return true; |
|
743 | + } |
|
665 | 744 | |
666 | 745 | // Images with smaller resolutions than thumbnails |
667 | 746 | /*if (($img->width <= $this->config['thumbWidth']) && |
@@ -674,8 +753,9 @@ discard block |
||
674 | 753 | |
675 | 754 | // Resize image |
676 | 755 | } else */ |
677 | - if (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) |
|
678 | - return false; |
|
756 | + if (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) { |
|
757 | + return false; |
|
758 | + } |
|
679 | 759 | |
680 | 760 | if ( $this->imageDriver == 'gd' ) { |
681 | 761 | $width = imagesx( $img->image ); |
@@ -697,7 +777,8 @@ discard block |
||
697 | 777 | )); |
698 | 778 | } |
699 | 779 | |
700 | - protected function localize($langCode) { |
|
780 | + protected function localize($langCode) |
|
781 | + { |
|
701 | 782 | require "lang/{$langCode}.php"; |
702 | 783 | setlocale(LC_ALL, $lang['_locale']); |
703 | 784 | $this->charset = $lang['_charset']; |
@@ -712,27 +793,34 @@ discard block |
||
712 | 793 | $this->labels = $lang; |
713 | 794 | } |
714 | 795 | |
715 | - protected function label($string, array $data=null) { |
|
796 | + protected function label($string, array $data=null) |
|
797 | + { |
|
716 | 798 | $return = isset($this->labels[$string]) ? $this->labels[$string] : $string; |
717 | - if (is_array($data)) |
|
718 | - foreach ($data as $key => $val) |
|
799 | + if (is_array($data)) { |
|
800 | + foreach ($data as $key => $val) |
|
719 | 801 | $return = str_replace("{{$key}}", $val, $return); |
802 | + } |
|
720 | 803 | return $return; |
721 | 804 | } |
722 | 805 | |
723 | - protected function backMsg($message, array $data=null) { |
|
806 | + protected function backMsg($message, array $data=null) |
|
807 | + { |
|
724 | 808 | $message = $this->label($message, $data); |
725 | - if (isset($this->file['tmp_name']) && file_exists($this->file['tmp_name'])) |
|
726 | - @unlink($this->file['tmp_name']); |
|
809 | + if (isset($this->file['tmp_name']) && file_exists($this->file['tmp_name'])) { |
|
810 | + @unlink($this->file['tmp_name']); |
|
811 | + } |
|
727 | 812 | $this->callBack("", $message); |
728 | 813 | die; |
729 | 814 | } |
730 | 815 | |
731 | - protected function callBack($url, $message="") { |
|
816 | + protected function callBack($url, $message="") |
|
817 | + { |
|
732 | 818 | $message = text::jsValue($message); |
733 | 819 | $CKfuncNum = isset($this->opener['CKEditor']['funcNum']) |
734 | 820 | ? $this->opener['CKEditor']['funcNum'] : 0; |
735 | - if (!$CKfuncNum) $CKfuncNum = 0; |
|
821 | + if (!$CKfuncNum) { |
|
822 | + $CKfuncNum = 0; |
|
823 | + } |
|
736 | 824 | header("Content-Type: text/html; charset={$this->charset}"); |
737 | 825 | |
738 | 826 | ?><html> |
@@ -769,7 +857,8 @@ discard block |
||
769 | 857 | |
770 | 858 | } |
771 | 859 | |
772 | - protected function get_htaccess() { |
|
860 | + protected function get_htaccess() |
|
861 | + { |
|
773 | 862 | return "<IfModule mod_php4.c> |
774 | 863 | php_value engine off |
775 | 864 | </IfModule> |
@@ -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}"; |