@@ -29,30 +29,30 @@ discard block |
||
29 | 29 | $file_info = $_FILES['Filedata']; |
30 | 30 | |
31 | 31 | // An error appears if not a normally uploaded file |
32 | - if(!is_uploaded_file($file_info['tmp_name'])) exit(); |
|
32 | + if (!is_uploaded_file($file_info['tmp_name'])) exit(); |
|
33 | 33 | |
34 | 34 | // Basic variables setting |
35 | 35 | $oFileModel = getModel('file'); |
36 | 36 | $editor_sequence = Context::get('editor_sequence'); |
37 | 37 | $upload_target_srl = intval(Context::get('uploadTargetSrl')); |
38 | - if(!$upload_target_srl) $upload_target_srl = intval(Context::get('upload_target_srl')); |
|
38 | + if (!$upload_target_srl) $upload_target_srl = intval(Context::get('upload_target_srl')); |
|
39 | 39 | $module_srl = $this->module_srl; |
40 | 40 | // Exit a session if there is neither upload permission nor information |
41 | - if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
41 | + if (!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
42 | 42 | // Extract from session information if upload_target_srl is not specified |
43 | - if(!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
|
43 | + if (!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
|
44 | 44 | // Create if upload_target_srl is not defined in the session information |
45 | - if(!$upload_target_srl) $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
|
45 | + if (!$upload_target_srl) $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
|
46 | 46 | |
47 | 47 | $output = $this->insertFile($file_info, $module_srl, $upload_target_srl); |
48 | 48 | Context::setResponseMethod('JSON'); |
49 | - $this->add('file_srl',$output->get('file_srl')); |
|
50 | - $this->add('file_size',$output->get('file_size')); |
|
51 | - $this->add('direct_download',$output->get('direct_download')); |
|
52 | - $this->add('source_filename',$output->get('source_filename')); |
|
53 | - $this->add('download_url',$output->get('uploaded_filename')); |
|
54 | - $this->add('upload_target_srl',$output->get('upload_target_srl')); |
|
55 | - if($output->error != '0') $this->stop($output->message); |
|
49 | + $this->add('file_srl', $output->get('file_srl')); |
|
50 | + $this->add('file_size', $output->get('file_size')); |
|
51 | + $this->add('direct_download', $output->get('direct_download')); |
|
52 | + $this->add('source_filename', $output->get('source_filename')); |
|
53 | + $this->add('download_url', $output->get('uploaded_filename')); |
|
54 | + $this->add('upload_target_srl', $output->get('upload_target_srl')); |
|
55 | + if ($output->error != '0') $this->stop($output->message); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -67,24 +67,24 @@ discard block |
||
67 | 67 | $callback = Context::get('callback'); |
68 | 68 | $module_srl = $this->module_srl; |
69 | 69 | $upload_target_srl = intval(Context::get('uploadTargetSrl')); |
70 | - if(!$upload_target_srl) $upload_target_srl = intval(Context::get('upload_target_srl')); |
|
70 | + if (!$upload_target_srl) $upload_target_srl = intval(Context::get('upload_target_srl')); |
|
71 | 71 | |
72 | 72 | // Exit a session if there is neither upload permission nor information |
73 | - if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
73 | + if (!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
74 | 74 | // Extract from session information if upload_target_srl is not specified |
75 | - if(!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
|
75 | + if (!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
|
76 | 76 | // Create if upload_target_srl is not defined in the session information |
77 | - if(!$upload_target_srl) $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
|
77 | + if (!$upload_target_srl) $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
|
78 | 78 | |
79 | 79 | // Delete and then attempt to re-upload if file_srl is requested |
80 | 80 | $file_srl = Context::get('file_srl'); |
81 | - if($file_srl) |
|
81 | + if ($file_srl) |
|
82 | 82 | { |
83 | 83 | $oFileModel = getModel('file'); |
84 | 84 | $logged_info = Context::get('logged_info'); |
85 | 85 | $file_info = $oFileModel->getFile($file_srl); |
86 | 86 | $file_grant = $oFileModel->getFileGrant($file_info, $logged_info); |
87 | - if($file_info->file_srl == $file_srl && $file_grant->is_deletable) |
|
87 | + if ($file_info->file_srl == $file_srl && $file_grant->is_deletable) |
|
88 | 88 | { |
89 | 89 | $this->deleteFile($file_srl); |
90 | 90 | } |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | |
93 | 93 | $file_info = Context::get('Filedata'); |
94 | 94 | // An error appears if not a normally uploaded file |
95 | - if(is_uploaded_file($file_info['tmp_name'])) { |
|
95 | + if (is_uploaded_file($file_info['tmp_name'])) { |
|
96 | 96 | $output = $this->insertFile($file_info, $module_srl, $upload_target_srl); |
97 | - Context::set('uploaded_fileinfo',$output); |
|
97 | + Context::set('uploaded_fileinfo', $output); |
|
98 | 98 | } |
99 | 99 | |
100 | - Context::set('layout','none'); |
|
100 | + Context::set('layout', 'none'); |
|
101 | 101 | |
102 | 102 | $this->setTemplatePath($this->module_path.'tpl'); |
103 | 103 | $this->setTemplateFile('iframe'); |
@@ -114,24 +114,24 @@ discard block |
||
114 | 114 | $width = Context::get('width'); |
115 | 115 | $height = Context::get('height'); |
116 | 116 | |
117 | - if(!$file_srl || !$width) |
|
117 | + if (!$file_srl || !$width) |
|
118 | 118 | { |
119 | - return new Object(-1,'msg_invalid_request'); |
|
119 | + return new Object(-1, 'msg_invalid_request'); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $oFileModel = getModel('file'); |
123 | 123 | $fileInfo = $oFileModel->getFile($file_srl); |
124 | - if(!$fileInfo || $fileInfo->direct_download != 'Y') |
|
124 | + if (!$fileInfo || $fileInfo->direct_download != 'Y') |
|
125 | 125 | { |
126 | - return new Object(-1,'msg_invalid_request'); |
|
126 | + return new Object(-1, 'msg_invalid_request'); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | $source_src = $fileInfo->uploaded_filename; |
130 | - $output_src = $source_src . '.resized' . strrchr($source_src,'.'); |
|
130 | + $output_src = $source_src.'.resized'.strrchr($source_src, '.'); |
|
131 | 131 | |
132 | - if(!$height) $height = $width-1; |
|
132 | + if (!$height) $height = $width - 1; |
|
133 | 133 | |
134 | - if(FileHandler::createImageFile($source_src,$output_src,$width,$height,'','ratio')) |
|
134 | + if (FileHandler::createImageFile($source_src, $output_src, $width, $height, '', 'ratio')) |
|
135 | 135 | { |
136 | 136 | $output = new stdClass(); |
137 | 137 | $output->info = getimagesize($output_src); |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | } |
140 | 140 | else |
141 | 141 | { |
142 | - return new Object(-1,'msg_invalid_request'); |
|
142 | + return new Object(-1, 'msg_invalid_request'); |
|
143 | 143 | } |
144 | 144 | |
145 | - $this->add('resized_info',$output); |
|
145 | + $this->add('resized_info', $output); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | { |
181 | 181 | $oFileModel = getModel('file'); |
182 | 182 | |
183 | - if(isset($this->grant->access) && $this->grant->access !== true) return new Object(-1, 'msg_not_permitted'); |
|
183 | + if (isset($this->grant->access) && $this->grant->access !== true) return new Object(-1, 'msg_not_permitted'); |
|
184 | 184 | |
185 | 185 | $file_srl = Context::get('file_srl'); |
186 | 186 | $sid = Context::get('sid'); |
@@ -189,26 +189,26 @@ discard block |
||
189 | 189 | $columnList = array('file_srl', 'sid', 'isvalid', 'source_filename', 'module_srl', 'uploaded_filename', 'file_size', 'member_srl', 'upload_target_srl', 'upload_target_type'); |
190 | 190 | $file_obj = $oFileModel->getFile($file_srl, $columnList); |
191 | 191 | // If the requested file information is incorrect, an error that file cannot be found appears |
192 | - if($file_obj->file_srl!=$file_srl || $file_obj->sid!=$sid) return $this->stop('msg_file_not_found'); |
|
192 | + if ($file_obj->file_srl != $file_srl || $file_obj->sid != $sid) return $this->stop('msg_file_not_found'); |
|
193 | 193 | // Notify that file download is not allowed when standing-by(Only a top-administrator is permitted) |
194 | - if($logged_info->is_admin != 'Y' && $file_obj->isvalid!='Y') return $this->stop('msg_not_permitted_download'); |
|
194 | + if ($logged_info->is_admin != 'Y' && $file_obj->isvalid != 'Y') return $this->stop('msg_not_permitted_download'); |
|
195 | 195 | // File name |
196 | 196 | $filename = $file_obj->source_filename; |
197 | 197 | $file_module_config = $oFileModel->getFileModuleConfig($file_obj->module_srl); |
198 | 198 | // Not allow the file outlink |
199 | - if($file_module_config->allow_outlink == 'N') |
|
199 | + if ($file_module_config->allow_outlink == 'N') |
|
200 | 200 | { |
201 | 201 | // Handles extension to allow outlink |
202 | - if($file_module_config->allow_outlink_format) |
|
202 | + if ($file_module_config->allow_outlink_format) |
|
203 | 203 | { |
204 | 204 | $allow_outlink_format_array = array(); |
205 | 205 | $allow_outlink_format_array = explode(',', $file_module_config->allow_outlink_format); |
206 | - if(!is_array($allow_outlink_format_array)) $allow_outlink_format_array[0] = $file_module_config->allow_outlink_format; |
|
206 | + if (!is_array($allow_outlink_format_array)) $allow_outlink_format_array[0] = $file_module_config->allow_outlink_format; |
|
207 | 207 | |
208 | - foreach($allow_outlink_format_array as $val) |
|
208 | + foreach ($allow_outlink_format_array as $val) |
|
209 | 209 | { |
210 | 210 | $val = trim($val); |
211 | - if(preg_match("/\.{$val}$/i", $filename)) |
|
211 | + if (preg_match("/\.{$val}$/i", $filename)) |
|
212 | 212 | { |
213 | 213 | $file_module_config->allow_outlink = 'Y'; |
214 | 214 | break; |
@@ -216,21 +216,21 @@ discard block |
||
216 | 216 | } |
217 | 217 | } |
218 | 218 | // Sites that outlink is allowed |
219 | - if($file_module_config->allow_outlink != 'Y') |
|
219 | + if ($file_module_config->allow_outlink != 'Y') |
|
220 | 220 | { |
221 | 221 | $referer = parse_url($_SERVER["HTTP_REFERER"]); |
222 | - if($referer['host'] != $_SERVER['HTTP_HOST']) |
|
222 | + if ($referer['host'] != $_SERVER['HTTP_HOST']) |
|
223 | 223 | { |
224 | - if($file_module_config->allow_outlink_site) |
|
224 | + if ($file_module_config->allow_outlink_site) |
|
225 | 225 | { |
226 | 226 | $allow_outlink_site_array = array(); |
227 | 227 | $allow_outlink_site_array = explode("\n", $file_module_config->allow_outlink_site); |
228 | - if(!is_array($allow_outlink_site_array)) $allow_outlink_site_array[0] = $file_module_config->allow_outlink_site; |
|
228 | + if (!is_array($allow_outlink_site_array)) $allow_outlink_site_array[0] = $file_module_config->allow_outlink_site; |
|
229 | 229 | |
230 | - foreach($allow_outlink_site_array as $val) |
|
230 | + foreach ($allow_outlink_site_array as $val) |
|
231 | 231 | { |
232 | 232 | $site = parse_url(trim($val)); |
233 | - if($site['host'] == $referer['host']) |
|
233 | + if ($site['host'] == $referer['host']) |
|
234 | 234 | { |
235 | 235 | $file_module_config->allow_outlink = 'Y'; |
236 | 236 | break; |
@@ -240,49 +240,49 @@ discard block |
||
240 | 240 | } |
241 | 241 | else $file_module_config->allow_outlink = 'Y'; |
242 | 242 | } |
243 | - if($file_module_config->allow_outlink != 'Y') return $this->stop('msg_not_allowed_outlink'); |
|
243 | + if ($file_module_config->allow_outlink != 'Y') return $this->stop('msg_not_allowed_outlink'); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | // Check if a permission for file download is granted |
247 | 247 | $downloadGrantCount = 0; |
248 | - if(is_array($file_module_config->download_grant)) |
|
248 | + if (is_array($file_module_config->download_grant)) |
|
249 | 249 | { |
250 | - foreach($file_module_config->download_grant AS $value) |
|
251 | - if($value) $downloadGrantCount++; |
|
250 | + foreach ($file_module_config->download_grant AS $value) |
|
251 | + if ($value) $downloadGrantCount++; |
|
252 | 252 | } |
253 | 253 | |
254 | - if(is_array($file_module_config->download_grant) && $downloadGrantCount>0) |
|
254 | + if (is_array($file_module_config->download_grant) && $downloadGrantCount > 0) |
|
255 | 255 | { |
256 | - if(!Context::get('is_logged')) return $this->stop('msg_not_permitted_download'); |
|
256 | + if (!Context::get('is_logged')) return $this->stop('msg_not_permitted_download'); |
|
257 | 257 | $logged_info = Context::get('logged_info'); |
258 | - if($logged_info->is_admin != 'Y') |
|
258 | + if ($logged_info->is_admin != 'Y') |
|
259 | 259 | { |
260 | - $oModuleModel =& getModel('module'); |
|
260 | + $oModuleModel = & getModel('module'); |
|
261 | 261 | $columnList = array('module_srl', 'site_srl'); |
262 | 262 | $module_info = $oModuleModel->getModuleInfoByModuleSrl($file_obj->module_srl, $columnList); |
263 | 263 | |
264 | - if(!$oModuleModel->isSiteAdmin($logged_info, $module_info->site_srl)) |
|
264 | + if (!$oModuleModel->isSiteAdmin($logged_info, $module_info->site_srl)) |
|
265 | 265 | { |
266 | - $oMemberModel =& getModel('member'); |
|
266 | + $oMemberModel = & getModel('member'); |
|
267 | 267 | $member_groups = $oMemberModel->getMemberGroups($logged_info->member_srl, $module_info->site_srl); |
268 | 268 | |
269 | 269 | $is_permitted = false; |
270 | - for($i=0;$i<count($file_module_config->download_grant);$i++) |
|
270 | + for ($i = 0; $i < count($file_module_config->download_grant); $i++) |
|
271 | 271 | { |
272 | 272 | $group_srl = $file_module_config->download_grant[$i]; |
273 | - if($member_groups[$group_srl]) |
|
273 | + if ($member_groups[$group_srl]) |
|
274 | 274 | { |
275 | 275 | $is_permitted = true; |
276 | 276 | break; |
277 | 277 | } |
278 | 278 | } |
279 | - if(!$is_permitted) return $this->stop('msg_not_permitted_download'); |
|
279 | + if (!$is_permitted) return $this->stop('msg_not_permitted_download'); |
|
280 | 280 | } |
281 | 281 | } |
282 | 282 | } |
283 | 283 | // Call a trigger (before) |
284 | 284 | $output = ModuleHandler::triggerCall('file.downloadFile', 'before', $file_obj); |
285 | - if(!$output->toBool()) return $this->stop(($output->message)?$output->message:'msg_not_permitted_download'); |
|
285 | + if (!$output->toBool()) return $this->stop(($output->message) ? $output->message : 'msg_not_permitted_download'); |
|
286 | 286 | |
287 | 287 | |
288 | 288 | // 다운로드 후 (가상) |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | |
296 | 296 | $random = new Password(); |
297 | 297 | $file_key = $_SESSION['__XE_FILE_KEY__'][$file_srl] = $random->createSecureSalt(32, 'hex'); |
298 | - header('Location: '.getNotEncodedUrl('', 'act', 'procFileOutput','file_srl',$file_srl,'file_key',$file_key)); |
|
298 | + header('Location: '.getNotEncodedUrl('', 'act', 'procFileOutput', 'file_srl', $file_srl, 'file_key', $file_key)); |
|
299 | 299 | Context::close(); |
300 | 300 | exit(); |
301 | 301 | |
@@ -306,18 +306,18 @@ discard block |
||
306 | 306 | $oFileModel = getModel('file'); |
307 | 307 | $file_srl = Context::get('file_srl'); |
308 | 308 | $file_key = Context::get('file_key'); |
309 | - if(strstr($_SERVER['HTTP_USER_AGENT'], "Android")) $is_android = true; |
|
309 | + if (strstr($_SERVER['HTTP_USER_AGENT'], "Android")) $is_android = true; |
|
310 | 310 | |
311 | - if($is_android && $_SESSION['__XE_FILE_KEY_AND__'][$file_srl]) $session_key = '__XE_FILE_KEY_AND__'; |
|
311 | + if ($is_android && $_SESSION['__XE_FILE_KEY_AND__'][$file_srl]) $session_key = '__XE_FILE_KEY_AND__'; |
|
312 | 312 | else $session_key = '__XE_FILE_KEY__'; |
313 | 313 | $columnList = array('source_filename', 'uploaded_filename', 'file_size'); |
314 | 314 | $file_obj = $oFileModel->getFile($file_srl, $columnList); |
315 | 315 | |
316 | 316 | $uploaded_filename = $file_obj->uploaded_filename; |
317 | 317 | |
318 | - if(!file_exists($uploaded_filename)) return $this->stop('msg_file_not_found'); |
|
318 | + if (!file_exists($uploaded_filename)) return $this->stop('msg_file_not_found'); |
|
319 | 319 | |
320 | - if(!$file_key || $_SESSION[$session_key][$file_srl] != $file_key) |
|
320 | + if (!$file_key || $_SESSION[$session_key][$file_srl] != $file_key) |
|
321 | 321 | { |
322 | 322 | unset($_SESSION[$session_key][$file_srl]); |
323 | 323 | return $this->stop('msg_invalid_request'); |
@@ -326,34 +326,34 @@ discard block |
||
326 | 326 | $file_size = $file_obj->file_size; |
327 | 327 | $filename = $file_obj->source_filename; |
328 | 328 | |
329 | - if(preg_match('#(?:Chrome|Edge)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 11) |
|
329 | + if (preg_match('#(?:Chrome|Edge)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 11) |
|
330 | 330 | { |
331 | - if($is_android && preg_match('#\bwv\b|(?:Version|Browser)/\d+#', $_SERVER['HTTP_USER_AGENT'])) |
|
331 | + if ($is_android && preg_match('#\bwv\b|(?:Version|Browser)/\d+#', $_SERVER['HTTP_USER_AGENT'])) |
|
332 | 332 | { |
333 | - $filename_param = 'filename="' . $filename . '"'; |
|
333 | + $filename_param = 'filename="'.$filename.'"'; |
|
334 | 334 | } |
335 | 335 | else |
336 | 336 | { |
337 | - $filename_param = "filename*=UTF-8''" . rawurlencode($filename) . '; filename="' . rawurlencode($filename) . '"'; |
|
337 | + $filename_param = "filename*=UTF-8''".rawurlencode($filename).'; filename="'.rawurlencode($filename).'"'; |
|
338 | 338 | } |
339 | 339 | } |
340 | - elseif(preg_match('#(?:Firefox|Safari|Trident)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 6) |
|
340 | + elseif (preg_match('#(?:Firefox|Safari|Trident)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 6) |
|
341 | 341 | { |
342 | - $filename_param = "filename*=UTF-8''" . rawurlencode($filename) . '; filename="' . rawurlencode($filename) . '"'; |
|
342 | + $filename_param = "filename*=UTF-8''".rawurlencode($filename).'; filename="'.rawurlencode($filename).'"'; |
|
343 | 343 | } |
344 | - elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) |
|
344 | + elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) |
|
345 | 345 | { |
346 | 346 | $filename = rawurlencode($filename); |
347 | - $filename_param = 'filename="' . preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1) . '"'; |
|
347 | + $filename_param = 'filename="'.preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1).'"'; |
|
348 | 348 | } |
349 | 349 | else |
350 | 350 | { |
351 | - $filename_param = 'filename="' . $filename . '"'; |
|
351 | + $filename_param = 'filename="'.$filename.'"'; |
|
352 | 352 | } |
353 | 353 | |
354 | - if($is_android) |
|
354 | + if ($is_android) |
|
355 | 355 | { |
356 | - if($_SESSION['__XE_FILE_KEY__'][$file_srl]) $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
|
356 | + if ($_SESSION['__XE_FILE_KEY__'][$file_srl]) $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | unset($_SESSION[$session_key][$file_srl]); |
@@ -361,21 +361,21 @@ discard block |
||
361 | 361 | Context::close(); |
362 | 362 | |
363 | 363 | $fp = fopen($uploaded_filename, 'rb'); |
364 | - if(!$fp) return $this->stop('msg_file_not_found'); |
|
364 | + if (!$fp) return $this->stop('msg_file_not_found'); |
|
365 | 365 | |
366 | 366 | header("Cache-Control: "); |
367 | 367 | header("Pragma: "); |
368 | 368 | header("Content-Type: application/octet-stream"); |
369 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
369 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); |
|
370 | 370 | |
371 | - header("Content-Length: " .(string)($file_size)); |
|
372 | - header('Content-Disposition: attachment; ' . $filename_param); |
|
371 | + header("Content-Length: ".(string) ($file_size)); |
|
372 | + header('Content-Disposition: attachment; '.$filename_param); |
|
373 | 373 | header("Content-Transfer-Encoding: binary\n"); |
374 | 374 | |
375 | 375 | // if file size is lager than 10MB, use fread function (#18675748) |
376 | - if($file_size > 1024 * 1024) |
|
376 | + if ($file_size > 1024 * 1024) |
|
377 | 377 | { |
378 | - while(!feof($fp)) echo fread($fp, 1024); |
|
378 | + while (!feof($fp)) echo fread($fp, 1024); |
|
379 | 379 | fclose($fp); |
380 | 380 | } |
381 | 381 | else |
@@ -397,36 +397,36 @@ discard block |
||
397 | 397 | $editor_sequence = Context::get('editor_sequence'); |
398 | 398 | $file_srl = Context::get('file_srl'); |
399 | 399 | $file_srls = Context::get('file_srls'); |
400 | - if($file_srls) $file_srl = $file_srls; |
|
400 | + if ($file_srls) $file_srl = $file_srls; |
|
401 | 401 | // Exit a session if there is neither upload permission nor information |
402 | - if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
402 | + if (!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
403 | 403 | |
404 | 404 | $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
405 | 405 | |
406 | 406 | $logged_info = Context::get('logged_info'); |
407 | 407 | $oFileModel = getModel('file'); |
408 | 408 | |
409 | - $srls = explode(',',$file_srl); |
|
410 | - if(!count($srls)) return; |
|
409 | + $srls = explode(',', $file_srl); |
|
410 | + if (!count($srls)) return; |
|
411 | 411 | |
412 | - for($i=0;$i<count($srls);$i++) |
|
412 | + for ($i = 0; $i < count($srls); $i++) |
|
413 | 413 | { |
414 | - $srl = (int)$srls[$i]; |
|
415 | - if(!$srl) continue; |
|
414 | + $srl = (int) $srls[$i]; |
|
415 | + if (!$srl) continue; |
|
416 | 416 | |
417 | 417 | $args = new stdClass; |
418 | 418 | $args->file_srl = $srl; |
419 | 419 | $output = executeQuery('file.getFile', $args); |
420 | - if(!$output->toBool()) continue; |
|
420 | + if (!$output->toBool()) continue; |
|
421 | 421 | |
422 | 422 | $file_info = $output->data; |
423 | - if(!$file_info) continue; |
|
423 | + if (!$file_info) continue; |
|
424 | 424 | |
425 | 425 | $file_grant = $oFileModel->getFileGrant($file_info, $logged_info); |
426 | 426 | |
427 | - if(!$file_grant->is_deletable) continue; |
|
427 | + if (!$file_grant->is_deletable) continue; |
|
428 | 428 | |
429 | - if($upload_target_srl && $file_srl) $output = $this->deleteFile($file_srl); |
|
429 | + if ($upload_target_srl && $file_srl) $output = $this->deleteFile($file_srl); |
|
430 | 430 | } |
431 | 431 | } |
432 | 432 | |
@@ -437,32 +437,32 @@ discard block |
||
437 | 437 | */ |
438 | 438 | function procFileGetList() |
439 | 439 | { |
440 | - if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted'); |
|
440 | + if (!Context::get('is_logged')) return new Object(-1, 'msg_not_permitted'); |
|
441 | 441 | |
442 | 442 | $oModuleModel = getModel('module'); |
443 | 443 | |
444 | 444 | $logged_info = Context::get('logged_info'); |
445 | - if($logged_info->is_admin !== 'Y' && !$oModuleModel->isSiteAdmin($logged_info)) |
|
445 | + if ($logged_info->is_admin !== 'Y' && !$oModuleModel->isSiteAdmin($logged_info)) |
|
446 | 446 | { |
447 | 447 | return new Object(-1, 'msg_not_permitted'); |
448 | 448 | } |
449 | 449 | |
450 | 450 | $fileSrls = Context::get('file_srls'); |
451 | - if($fileSrls) $fileSrlList = explode(',', $fileSrls); |
|
451 | + if ($fileSrls) $fileSrlList = explode(',', $fileSrls); |
|
452 | 452 | |
453 | 453 | global $lang; |
454 | - if(count($fileSrlList) > 0) |
|
454 | + if (count($fileSrlList) > 0) |
|
455 | 455 | { |
456 | 456 | $oFileModel = getModel('file'); |
457 | 457 | $fileList = $oFileModel->getFile($fileSrlList); |
458 | - if(!is_array($fileList)) $fileList = array($fileList); |
|
458 | + if (!is_array($fileList)) $fileList = array($fileList); |
|
459 | 459 | |
460 | - if(is_array($fileList)) |
|
460 | + if (is_array($fileList)) |
|
461 | 461 | { |
462 | - foreach($fileList AS $key=>$value) |
|
462 | + foreach ($fileList AS $key=>$value) |
|
463 | 463 | { |
464 | 464 | $value->human_file_size = FileHandler::filesize($value->file_size); |
465 | - if($value->isvalid=='Y') $value->validName = $lang->is_valid; |
|
465 | + if ($value->isvalid == 'Y') $value->validName = $lang->is_valid; |
|
466 | 466 | else $value->validName = $lang->is_stand_by; |
467 | 467 | } |
468 | 468 | } |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | function triggerCheckAttached(&$obj) |
485 | 485 | { |
486 | 486 | $document_srl = $obj->document_srl; |
487 | - if(!$document_srl) return new Object(); |
|
487 | + if (!$document_srl) return new Object(); |
|
488 | 488 | // Get numbers of attachments |
489 | 489 | $oFileModel = getModel('file'); |
490 | 490 | $obj->uploaded_count = $oFileModel->getFilesCount($document_srl); |
@@ -501,10 +501,10 @@ discard block |
||
501 | 501 | function triggerAttachFiles(&$obj) |
502 | 502 | { |
503 | 503 | $document_srl = $obj->document_srl; |
504 | - if(!$document_srl) return new Object(); |
|
504 | + if (!$document_srl) return new Object(); |
|
505 | 505 | |
506 | 506 | $output = $this->setFilesValid($document_srl); |
507 | - if(!$output->toBool()) return $output; |
|
507 | + if (!$output->toBool()) return $output; |
|
508 | 508 | |
509 | 509 | return new Object(); |
510 | 510 | } |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | function triggerDeleteAttached(&$obj) |
519 | 519 | { |
520 | 520 | $document_srl = $obj->document_srl; |
521 | - if(!$document_srl) return new Object(); |
|
521 | + if (!$document_srl) return new Object(); |
|
522 | 522 | |
523 | 523 | $output = $this->deleteFiles($document_srl); |
524 | 524 | return $output; |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | function triggerCommentCheckAttached(&$obj) |
534 | 534 | { |
535 | 535 | $comment_srl = $obj->comment_srl; |
536 | - if(!$comment_srl) return new Object(); |
|
536 | + if (!$comment_srl) return new Object(); |
|
537 | 537 | // Get numbers of attachments |
538 | 538 | $oFileModel = getModel('file'); |
539 | 539 | $obj->uploaded_count = $oFileModel->getFilesCount($comment_srl); |
@@ -551,10 +551,10 @@ discard block |
||
551 | 551 | { |
552 | 552 | $comment_srl = $obj->comment_srl; |
553 | 553 | $uploaded_count = $obj->uploaded_count; |
554 | - if(!$comment_srl || !$uploaded_count) return new Object(); |
|
554 | + if (!$comment_srl || !$uploaded_count) return new Object(); |
|
555 | 555 | |
556 | 556 | $output = $this->setFilesValid($comment_srl); |
557 | - if(!$output->toBool()) return $output; |
|
557 | + if (!$output->toBool()) return $output; |
|
558 | 558 | |
559 | 559 | return new Object(); |
560 | 560 | } |
@@ -568,9 +568,9 @@ discard block |
||
568 | 568 | function triggerCommentDeleteAttached(&$obj) |
569 | 569 | { |
570 | 570 | $comment_srl = $obj->comment_srl; |
571 | - if(!$comment_srl) return new Object(); |
|
571 | + if (!$comment_srl) return new Object(); |
|
572 | 572 | |
573 | - if($obj->isMoveToTrash) return new Object(); |
|
573 | + if ($obj->isMoveToTrash) return new Object(); |
|
574 | 574 | |
575 | 575 | $output = $this->deleteFiles($comment_srl); |
576 | 576 | return $output; |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | function triggerDeleteModuleFiles(&$obj) |
586 | 586 | { |
587 | 587 | $module_srl = $obj->module_srl; |
588 | - if(!$module_srl) return new Object(); |
|
588 | + if (!$module_srl) return new Object(); |
|
589 | 589 | |
590 | 590 | $oFileController = getAdminController('file'); |
591 | 591 | return $oFileController->deleteModuleFiles($module_srl); |
@@ -598,9 +598,9 @@ discard block |
||
598 | 598 | * @param int $upload_target_srl |
599 | 599 | * @return void |
600 | 600 | */ |
601 | - function setUploadInfo($editor_sequence, $upload_target_srl=0) |
|
601 | + function setUploadInfo($editor_sequence, $upload_target_srl = 0) |
|
602 | 602 | { |
603 | - if(!isset($_SESSION['upload_info'][$editor_sequence])) |
|
603 | + if (!isset($_SESSION['upload_info'][$editor_sequence])) |
|
604 | 604 | { |
605 | 605 | $_SESSION['upload_info'][$editor_sequence] = new stdClass(); |
606 | 606 | } |
@@ -660,36 +660,36 @@ discard block |
||
660 | 660 | $trigger_obj->module_srl = $module_srl; |
661 | 661 | $trigger_obj->upload_target_srl = $upload_target_srl; |
662 | 662 | $output = ModuleHandler::triggerCall('file.insertFile', 'before', $trigger_obj); |
663 | - if(!$output->toBool()) return $output; |
|
663 | + if (!$output->toBool()) return $output; |
|
664 | 664 | |
665 | 665 | // A workaround for Firefox upload bug |
666 | - if(preg_match('/^=\?UTF-8\?B\?(.+)\?=$/i', $file_info['name'], $match)) |
|
666 | + if (preg_match('/^=\?UTF-8\?B\?(.+)\?=$/i', $file_info['name'], $match)) |
|
667 | 667 | { |
668 | 668 | $file_info['name'] = base64_decode(strtr($match[1], ':', '/')); |
669 | 669 | } |
670 | 670 | |
671 | - if(!$manual_insert) |
|
671 | + if (!$manual_insert) |
|
672 | 672 | { |
673 | 673 | // Get the file configurations |
674 | 674 | $logged_info = Context::get('logged_info'); |
675 | - if($logged_info->is_admin != 'Y') |
|
675 | + if ($logged_info->is_admin != 'Y') |
|
676 | 676 | { |
677 | 677 | $oFileModel = getModel('file'); |
678 | 678 | $config = $oFileModel->getFileConfig($module_srl); |
679 | 679 | |
680 | 680 | // check file type |
681 | - if(isset($config->allowed_filetypes) && $config->allowed_filetypes !== '*.*') |
|
681 | + if (isset($config->allowed_filetypes) && $config->allowed_filetypes !== '*.*') |
|
682 | 682 | { |
683 | 683 | $filetypes = explode(';', $config->allowed_filetypes); |
684 | 684 | $ext = array(); |
685 | - foreach($filetypes as $item) { |
|
685 | + foreach ($filetypes as $item) { |
|
686 | 686 | $item = explode('.', $item); |
687 | 687 | $ext[] = strtolower($item[1]); |
688 | 688 | } |
689 | 689 | $uploaded_ext = explode('.', $file_info['name']); |
690 | 690 | $uploaded_ext = strtolower(array_pop($uploaded_ext)); |
691 | 691 | |
692 | - if(!in_array($uploaded_ext, $ext)) |
|
692 | + if (!in_array($uploaded_ext, $ext)) |
|
693 | 693 | { |
694 | 694 | return $this->stop('msg_not_allowed_filetype'); |
695 | 695 | } |
@@ -698,63 +698,63 @@ discard block |
||
698 | 698 | $allowed_filesize = $config->allowed_filesize * 1024 * 1024; |
699 | 699 | $allowed_attach_size = $config->allowed_attach_size * 1024 * 1024; |
700 | 700 | // An error appears if file size exceeds a limit |
701 | - if($allowed_filesize < filesize($file_info['tmp_name'])) return new Object(-1, 'msg_exceeds_limit_size'); |
|
701 | + if ($allowed_filesize < filesize($file_info['tmp_name'])) return new Object(-1, 'msg_exceeds_limit_size'); |
|
702 | 702 | // Get total file size of all attachements (from DB) |
703 | 703 | $size_args = new stdClass; |
704 | 704 | $size_args->upload_target_srl = $upload_target_srl; |
705 | 705 | $output = executeQuery('file.getAttachedFileSize', $size_args); |
706 | - $attached_size = (int)$output->data->attached_size + filesize($file_info['tmp_name']); |
|
707 | - if($attached_size > $allowed_attach_size) return new Object(-1, 'msg_exceeds_limit_size'); |
|
706 | + $attached_size = (int) $output->data->attached_size + filesize($file_info['tmp_name']); |
|
707 | + if ($attached_size > $allowed_attach_size) return new Object(-1, 'msg_exceeds_limit_size'); |
|
708 | 708 | } |
709 | 709 | } |
710 | 710 | |
711 | 711 | // https://github.com/xpressengine/xe-core/issues/1713 |
712 | - $file_info['name'] = preg_replace('/\.(php|phtm|phar|html?|cgi|pl|exe|jsp|asp|inc)/i', '$0-x',$file_info['name']); |
|
712 | + $file_info['name'] = preg_replace('/\.(php|phtm|phar|html?|cgi|pl|exe|jsp|asp|inc)/i', '$0-x', $file_info['name']); |
|
713 | 713 | $file_info['name'] = removeHackTag($file_info['name']); |
714 | - $file_info['name'] = str_replace(array('<','>'),array('%3C','%3E'),$file_info['name']); |
|
714 | + $file_info['name'] = str_replace(array('<', '>'), array('%3C', '%3E'), $file_info['name']); |
|
715 | 715 | |
716 | 716 | // Get random number generator |
717 | 717 | $random = new Password(); |
718 | 718 | |
719 | 719 | // Set upload path by checking if the attachement is an image or other kinds of file |
720 | - if(preg_match("/\.(jpe?g|gif|png|wm[va]|mpe?g|avi|flv|mp[1-4]|as[fx]|wav|midi?|moo?v|qt|r[am]{1,2}|m4v)$/i", $file_info['name'])) |
|
720 | + if (preg_match("/\.(jpe?g|gif|png|wm[va]|mpe?g|avi|flv|mp[1-4]|as[fx]|wav|midi?|moo?v|qt|r[am]{1,2}|m4v)$/i", $file_info['name'])) |
|
721 | 721 | { |
722 | - $path = sprintf("./files/attach/images/%s/%s", $module_srl,getNumberingPath($upload_target_srl,3)); |
|
722 | + $path = sprintf("./files/attach/images/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3)); |
|
723 | 723 | |
724 | 724 | // special character to '_' |
725 | 725 | // change to random file name. because window php bug. window php is not recognize unicode character file name - by cherryfilter |
726 | - $ext = substr(strrchr($file_info['name'],'.'),1); |
|
726 | + $ext = substr(strrchr($file_info['name'], '.'), 1); |
|
727 | 727 | //$_filename = preg_replace('/[#$&*?+%"\']/', '_', $file_info['name']); |
728 | 728 | $_filename = $random->createSecureSalt(32, 'hex').'.'.$ext; |
729 | 729 | $filename = $path.$_filename; |
730 | 730 | $idx = 1; |
731 | - while(file_exists($filename)) |
|
731 | + while (file_exists($filename)) |
|
732 | 732 | { |
733 | - $filename = $path.preg_replace('/\.([a-z0-9]+)$/i','_'.$idx.'.$1',$_filename); |
|
733 | + $filename = $path.preg_replace('/\.([a-z0-9]+)$/i', '_'.$idx.'.$1', $_filename); |
|
734 | 734 | $idx++; |
735 | 735 | } |
736 | 736 | $direct_download = 'Y'; |
737 | 737 | } |
738 | 738 | else |
739 | 739 | { |
740 | - $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl,3)); |
|
740 | + $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3)); |
|
741 | 741 | $filename = $path.$random->createSecureSalt(32, 'hex'); |
742 | 742 | $direct_download = 'N'; |
743 | 743 | } |
744 | 744 | // Create a directory |
745 | - if(!FileHandler::makeDir($path)) return new Object(-1,'msg_not_permitted_create'); |
|
745 | + if (!FileHandler::makeDir($path)) return new Object(-1, 'msg_not_permitted_create'); |
|
746 | 746 | |
747 | 747 | // Check uploaded file |
748 | - if(!checkUploadedFile($file_info['tmp_name'])) return new Object(-1,'msg_file_upload_error'); |
|
748 | + if (!checkUploadedFile($file_info['tmp_name'])) return new Object(-1, 'msg_file_upload_error'); |
|
749 | 749 | |
750 | 750 | // Get random number generator |
751 | 751 | $random = new Password(); |
752 | 752 | |
753 | 753 | // Move the file |
754 | - if($manual_insert) |
|
754 | + if ($manual_insert) |
|
755 | 755 | { |
756 | 756 | @copy($file_info['tmp_name'], $filename); |
757 | - if(!file_exists($filename)) |
|
757 | + if (!file_exists($filename)) |
|
758 | 758 | { |
759 | 759 | $filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
760 | 760 | @copy($file_info['tmp_name'], $filename); |
@@ -762,10 +762,10 @@ discard block |
||
762 | 762 | } |
763 | 763 | else |
764 | 764 | { |
765 | - if(!@move_uploaded_file($file_info['tmp_name'], $filename)) |
|
765 | + if (!@move_uploaded_file($file_info['tmp_name'], $filename)) |
|
766 | 766 | { |
767 | 767 | $filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
768 | - if(!@move_uploaded_file($file_info['tmp_name'], $filename)) return new Object(-1,'msg_file_upload_error'); |
|
768 | + if (!@move_uploaded_file($file_info['tmp_name'], $filename)) return new Object(-1, 'msg_file_upload_error'); |
|
769 | 769 | } |
770 | 770 | } |
771 | 771 | // Get member information |
@@ -786,10 +786,10 @@ discard block |
||
786 | 786 | $args->sid = $random->createSecureSalt(32, 'hex'); |
787 | 787 | |
788 | 788 | $output = executeQuery('file.insertFile', $args); |
789 | - if(!$output->toBool()) return $output; |
|
789 | + if (!$output->toBool()) return $output; |
|
790 | 790 | // Call a trigger (after) |
791 | 791 | $trigger_output = ModuleHandler::triggerCall('file.insertFile', 'after', $args); |
792 | - if(!$trigger_output->toBool()) return $trigger_output; |
|
792 | + if (!$trigger_output->toBool()) return $trigger_output; |
|
793 | 793 | |
794 | 794 | $_SESSION['__XE_UPLOADING_FILES_INFO__'][$args->file_srl] = true; |
795 | 795 | |
@@ -832,18 +832,18 @@ discard block |
||
832 | 832 | */ |
833 | 833 | function deleteFile($file_srl) |
834 | 834 | { |
835 | - if(!$file_srl) return; |
|
835 | + if (!$file_srl) return; |
|
836 | 836 | |
837 | 837 | $srls = (is_array($file_srl)) ? $file_srl : explode(',', $file_srl); |
838 | - if(!count($srls)) return; |
|
838 | + if (!count($srls)) return; |
|
839 | 839 | |
840 | 840 | $oDocumentController = getController('document'); |
841 | 841 | $documentSrlList = array(); |
842 | 842 | |
843 | - foreach($srls as $srl) |
|
843 | + foreach ($srls as $srl) |
|
844 | 844 | { |
845 | - $srl = (int)$srl; |
|
846 | - if(!$srl) |
|
845 | + $srl = (int) $srl; |
|
846 | + if (!$srl) |
|
847 | 847 | { |
848 | 848 | continue; |
849 | 849 | } |
@@ -852,14 +852,14 @@ discard block |
||
852 | 852 | $args->file_srl = $srl; |
853 | 853 | $output = executeQuery('file.getFile', $args); |
854 | 854 | |
855 | - if(!$output->toBool() || !$output->data) |
|
855 | + if (!$output->toBool() || !$output->data) |
|
856 | 856 | { |
857 | 857 | continue; |
858 | 858 | } |
859 | 859 | |
860 | 860 | $file_info = $output->data; |
861 | 861 | |
862 | - if($file_info->upload_target_srl) |
|
862 | + if ($file_info->upload_target_srl) |
|
863 | 863 | { |
864 | 864 | $documentSrlList[] = $file_info->upload_target_srl; |
865 | 865 | } |
@@ -870,15 +870,15 @@ discard block |
||
870 | 870 | // Call a trigger (before) |
871 | 871 | $trigger_obj = $output->data; |
872 | 872 | $output = ModuleHandler::triggerCall('file.deleteFile', 'before', $trigger_obj); |
873 | - if(!$output->toBool()) return $output; |
|
873 | + if (!$output->toBool()) return $output; |
|
874 | 874 | |
875 | 875 | // Remove from the DB |
876 | 876 | $output = executeQuery('file.deleteFile', $args); |
877 | - if(!$output->toBool()) return $output; |
|
877 | + if (!$output->toBool()) return $output; |
|
878 | 878 | |
879 | 879 | // Call a trigger (after) |
880 | 880 | $trigger_output = ModuleHandler::triggerCall('file.deleteFile', 'after', $trigger_obj); |
881 | - if(!$trigger_output->toBool()) return $trigger_output; |
|
881 | + if (!$trigger_output->toBool()) return $trigger_output; |
|
882 | 882 | |
883 | 883 | // If successfully deleted, remove the file |
884 | 884 | FileHandler::removeFile($uploaded_filename); |
@@ -902,28 +902,28 @@ discard block |
||
902 | 902 | $columnList = array('file_srl', 'uploaded_filename', 'module_srl'); |
903 | 903 | $file_list = $oFileModel->getFiles($upload_target_srl, $columnList); |
904 | 904 | // Success returned if no attachement exists |
905 | - if(!is_array($file_list)||!count($file_list)) return new Object(); |
|
905 | + if (!is_array($file_list) || !count($file_list)) return new Object(); |
|
906 | 906 | |
907 | 907 | // Delete the file |
908 | 908 | $path = array(); |
909 | 909 | $file_count = count($file_list); |
910 | - for($i=0;$i<$file_count;$i++) |
|
910 | + for ($i = 0; $i < $file_count; $i++) |
|
911 | 911 | { |
912 | 912 | $this->deleteFile($file_list[$i]->file_srl); |
913 | 913 | |
914 | 914 | $uploaded_filename = $file_list[$i]->uploaded_filename; |
915 | 915 | $path_info = pathinfo($uploaded_filename); |
916 | - if(!in_array($path_info['dirname'], $path)) $path[] = $path_info['dirname']; |
|
916 | + if (!in_array($path_info['dirname'], $path)) $path[] = $path_info['dirname']; |
|
917 | 917 | } |
918 | 918 | |
919 | 919 | // Remove from the DB |
920 | 920 | $args = new stdClass(); |
921 | 921 | $args->upload_target_srl = $upload_target_srl; |
922 | 922 | $output = executeQuery('file.deleteFiles', $args); |
923 | - if(!$output->toBool()) return $output; |
|
923 | + if (!$output->toBool()) return $output; |
|
924 | 924 | |
925 | 925 | // Remove a file directory of the document |
926 | - for($i=0, $c=count($path); $i<$c; $i++) |
|
926 | + for ($i = 0, $c = count($path); $i < $c; $i++) |
|
927 | 927 | { |
928 | 928 | FileHandler::removeBlankDir($path[$i]); |
929 | 929 | } |
@@ -941,23 +941,23 @@ discard block |
||
941 | 941 | */ |
942 | 942 | function moveFile($source_srl, $target_module_srl, $target_srl) |
943 | 943 | { |
944 | - if($source_srl == $target_srl) return; |
|
944 | + if ($source_srl == $target_srl) return; |
|
945 | 945 | |
946 | 946 | $oFileModel = getModel('file'); |
947 | 947 | $file_list = $oFileModel->getFiles($source_srl); |
948 | - if(!$file_list) return; |
|
948 | + if (!$file_list) return; |
|
949 | 949 | |
950 | 950 | $file_count = count($file_list); |
951 | 951 | |
952 | - for($i=0;$i<$file_count;$i++) |
|
952 | + for ($i = 0; $i < $file_count; $i++) |
|
953 | 953 | { |
954 | 954 | unset($file_info); |
955 | 955 | $file_info = $file_list[$i]; |
956 | 956 | $old_file = $file_info->uploaded_filename; |
957 | 957 | // Determine the file path by checking if the file is an image or other kinds |
958 | - if(preg_match("/\.(asf|asf|asx|avi|flv|gif|jpeg|jpg|m4a|m4v|mid|midi|moov|mov|mp1|mp2|mp3|mp4|mpeg|mpg|ogg|png|qt|ra|ram|rm|rmm|wav|webm|webp|wma|wmv)$/i", $file_info->source_filename)) |
|
958 | + if (preg_match("/\.(asf|asf|asx|avi|flv|gif|jpeg|jpg|m4a|m4v|mid|midi|moov|mov|mp1|mp2|mp3|mp4|mpeg|mpg|ogg|png|qt|ra|ram|rm|rmm|wav|webm|webp|wma|wmv)$/i", $file_info->source_filename)) |
|
959 | 959 | { |
960 | - $path = sprintf("./files/attach/images/%s/%s/", $target_module_srl,$target_srl); |
|
960 | + $path = sprintf("./files/attach/images/%s/%s/", $target_module_srl, $target_srl); |
|
961 | 961 | $new_file = $path.$file_info->source_filename; |
962 | 962 | } |
963 | 963 | else |
@@ -967,7 +967,7 @@ discard block |
||
967 | 967 | $new_file = $path.$random->createSecureSalt(32, 'hex'); |
968 | 968 | } |
969 | 969 | // Pass if a target document to move is same |
970 | - if($old_file == $new_file) continue; |
|
970 | + if ($old_file == $new_file) continue; |
|
971 | 971 | // Create a directory |
972 | 972 | FileHandler::makeDir($path); |
973 | 973 | // Move the file |
@@ -987,18 +987,18 @@ discard block |
||
987 | 987 | $vars = Context::getRequestVars(); |
988 | 988 | $logged_info = Context::get('logged_info'); |
989 | 989 | |
990 | - if(!$vars->editor_sequence) return new Object(-1, 'msg_invalid_request'); |
|
990 | + if (!$vars->editor_sequence) return new Object(-1, 'msg_invalid_request'); |
|
991 | 991 | |
992 | 992 | $upload_target_srl = $_SESSION['upload_info'][$vars->editor_sequence]->upload_target_srl; |
993 | 993 | |
994 | 994 | $oFileModel = getModel('file'); |
995 | 995 | $file_info = $oFileModel->getFile($vars->file_srl); |
996 | 996 | |
997 | - if(!$file_info) return new Object(-1, 'msg_not_founded'); |
|
997 | + if (!$file_info) return new Object(-1, 'msg_not_founded'); |
|
998 | 998 | |
999 | - if(!$this->manager && !$file_info->member_srl === $logged_info->member_srl) return new Object(-1, 'msg_not_permitted'); |
|
999 | + if (!$this->manager && !$file_info->member_srl === $logged_info->member_srl) return new Object(-1, 'msg_not_permitted'); |
|
1000 | 1000 | |
1001 | - $args = new stdClass(); |
|
1001 | + $args = new stdClass(); |
|
1002 | 1002 | $args->file_srl = $vars->file_srl; |
1003 | 1003 | $args->upload_target_srl = $upload_target_srl; |
1004 | 1004 | |
@@ -1007,18 +1007,18 @@ discard block |
||
1007 | 1007 | |
1008 | 1008 | $args->cover_image = 'N'; |
1009 | 1009 | $output = executeQuery('file.updateClearCoverImage', $args); |
1010 | - if(!$output->toBool()) |
|
1010 | + if (!$output->toBool()) |
|
1011 | 1011 | { |
1012 | 1012 | $oDB->rollback(); |
1013 | 1013 | return $output; |
1014 | 1014 | } |
1015 | 1015 | |
1016 | - if($file_info->cover_image != 'Y') |
|
1016 | + if ($file_info->cover_image != 'Y') |
|
1017 | 1017 | { |
1018 | 1018 | |
1019 | 1019 | $args->cover_image = 'Y'; |
1020 | 1020 | $output = executeQuery('file.updateCoverImage', $args); |
1021 | - if(!$output->toBool()) |
|
1021 | + if (!$output->toBool()) |
|
1022 | 1022 | { |
1023 | 1023 | $oDB->rollback(); |
1024 | 1024 | return $output; |
@@ -1028,7 +1028,7 @@ discard block |
||
1028 | 1028 | |
1029 | 1029 | $oDB->commit(); |
1030 | 1030 | |
1031 | - $this->add('is_cover',$args->cover_image); |
|
1031 | + $this->add('is_cover', $args->cover_image); |
|
1032 | 1032 | |
1033 | 1033 | // 썸네일 삭제 |
1034 | 1034 | $thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($upload_target_srl, 3)); |
@@ -1054,9 +1054,9 @@ discard block |
||
1054 | 1054 | $fileConfig = $oModuleModel->getModulePartConfig('file', $obj->originModuleSrl); |
1055 | 1055 | |
1056 | 1056 | $oModuleController = getController('module'); |
1057 | - if(is_array($obj->moduleSrlList)) |
|
1057 | + if (is_array($obj->moduleSrlList)) |
|
1058 | 1058 | { |
1059 | - foreach($obj->moduleSrlList AS $key=>$moduleSrl) |
|
1059 | + foreach ($obj->moduleSrlList AS $key=>$moduleSrl) |
|
1060 | 1060 | { |
1061 | 1061 | $oModuleController->insertModulePartConfig('file', $moduleSrl, $fileConfig); |
1062 | 1062 | } |
@@ -29,20 +29,30 @@ discard block |
||
29 | 29 | $file_info = $_FILES['Filedata']; |
30 | 30 | |
31 | 31 | // An error appears if not a normally uploaded file |
32 | - if(!is_uploaded_file($file_info['tmp_name'])) exit(); |
|
32 | + if(!is_uploaded_file($file_info['tmp_name'])) { |
|
33 | + exit(); |
|
34 | + } |
|
33 | 35 | |
34 | 36 | // Basic variables setting |
35 | 37 | $oFileModel = getModel('file'); |
36 | 38 | $editor_sequence = Context::get('editor_sequence'); |
37 | 39 | $upload_target_srl = intval(Context::get('uploadTargetSrl')); |
38 | - if(!$upload_target_srl) $upload_target_srl = intval(Context::get('upload_target_srl')); |
|
40 | + if(!$upload_target_srl) { |
|
41 | + $upload_target_srl = intval(Context::get('upload_target_srl')); |
|
42 | + } |
|
39 | 43 | $module_srl = $this->module_srl; |
40 | 44 | // Exit a session if there is neither upload permission nor information |
41 | - if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
45 | + if(!$_SESSION['upload_info'][$editor_sequence]->enabled) { |
|
46 | + exit(); |
|
47 | + } |
|
42 | 48 | // Extract from session information if upload_target_srl is not specified |
43 | - if(!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
|
49 | + if(!$upload_target_srl) { |
|
50 | + $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
|
51 | + } |
|
44 | 52 | // Create if upload_target_srl is not defined in the session information |
45 | - if(!$upload_target_srl) $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
|
53 | + if(!$upload_target_srl) { |
|
54 | + $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
|
55 | + } |
|
46 | 56 | |
47 | 57 | $output = $this->insertFile($file_info, $module_srl, $upload_target_srl); |
48 | 58 | Context::setResponseMethod('JSON'); |
@@ -52,7 +62,9 @@ discard block |
||
52 | 62 | $this->add('source_filename',$output->get('source_filename')); |
53 | 63 | $this->add('download_url',$output->get('uploaded_filename')); |
54 | 64 | $this->add('upload_target_srl',$output->get('upload_target_srl')); |
55 | - if($output->error != '0') $this->stop($output->message); |
|
65 | + if($output->error != '0') { |
|
66 | + $this->stop($output->message); |
|
67 | + } |
|
56 | 68 | } |
57 | 69 | |
58 | 70 | /** |
@@ -67,14 +79,22 @@ discard block |
||
67 | 79 | $callback = Context::get('callback'); |
68 | 80 | $module_srl = $this->module_srl; |
69 | 81 | $upload_target_srl = intval(Context::get('uploadTargetSrl')); |
70 | - if(!$upload_target_srl) $upload_target_srl = intval(Context::get('upload_target_srl')); |
|
82 | + if(!$upload_target_srl) { |
|
83 | + $upload_target_srl = intval(Context::get('upload_target_srl')); |
|
84 | + } |
|
71 | 85 | |
72 | 86 | // Exit a session if there is neither upload permission nor information |
73 | - if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
87 | + if(!$_SESSION['upload_info'][$editor_sequence]->enabled) { |
|
88 | + exit(); |
|
89 | + } |
|
74 | 90 | // Extract from session information if upload_target_srl is not specified |
75 | - if(!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
|
91 | + if(!$upload_target_srl) { |
|
92 | + $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
|
93 | + } |
|
76 | 94 | // Create if upload_target_srl is not defined in the session information |
77 | - if(!$upload_target_srl) $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
|
95 | + if(!$upload_target_srl) { |
|
96 | + $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
|
97 | + } |
|
78 | 98 | |
79 | 99 | // Delete and then attempt to re-upload if file_srl is requested |
80 | 100 | $file_srl = Context::get('file_srl'); |
@@ -129,15 +149,16 @@ discard block |
||
129 | 149 | $source_src = $fileInfo->uploaded_filename; |
130 | 150 | $output_src = $source_src . '.resized' . strrchr($source_src,'.'); |
131 | 151 | |
132 | - if(!$height) $height = $width-1; |
|
152 | + if(!$height) { |
|
153 | + $height = $width-1; |
|
154 | + } |
|
133 | 155 | |
134 | 156 | if(FileHandler::createImageFile($source_src,$output_src,$width,$height,'','ratio')) |
135 | 157 | { |
136 | 158 | $output = new stdClass(); |
137 | 159 | $output->info = getimagesize($output_src); |
138 | 160 | $output->src = $output_src; |
139 | - } |
|
140 | - else |
|
161 | + } else |
|
141 | 162 | { |
142 | 163 | return new Object(-1,'msg_invalid_request'); |
143 | 164 | } |
@@ -180,7 +201,9 @@ discard block |
||
180 | 201 | { |
181 | 202 | $oFileModel = getModel('file'); |
182 | 203 | |
183 | - if(isset($this->grant->access) && $this->grant->access !== true) return new Object(-1, 'msg_not_permitted'); |
|
204 | + if(isset($this->grant->access) && $this->grant->access !== true) { |
|
205 | + return new Object(-1, 'msg_not_permitted'); |
|
206 | + } |
|
184 | 207 | |
185 | 208 | $file_srl = Context::get('file_srl'); |
186 | 209 | $sid = Context::get('sid'); |
@@ -189,9 +212,13 @@ discard block |
||
189 | 212 | $columnList = array('file_srl', 'sid', 'isvalid', 'source_filename', 'module_srl', 'uploaded_filename', 'file_size', 'member_srl', 'upload_target_srl', 'upload_target_type'); |
190 | 213 | $file_obj = $oFileModel->getFile($file_srl, $columnList); |
191 | 214 | // If the requested file information is incorrect, an error that file cannot be found appears |
192 | - if($file_obj->file_srl!=$file_srl || $file_obj->sid!=$sid) return $this->stop('msg_file_not_found'); |
|
215 | + if($file_obj->file_srl!=$file_srl || $file_obj->sid!=$sid) { |
|
216 | + return $this->stop('msg_file_not_found'); |
|
217 | + } |
|
193 | 218 | // Notify that file download is not allowed when standing-by(Only a top-administrator is permitted) |
194 | - if($logged_info->is_admin != 'Y' && $file_obj->isvalid!='Y') return $this->stop('msg_not_permitted_download'); |
|
219 | + if($logged_info->is_admin != 'Y' && $file_obj->isvalid!='Y') { |
|
220 | + return $this->stop('msg_not_permitted_download'); |
|
221 | + } |
|
195 | 222 | // File name |
196 | 223 | $filename = $file_obj->source_filename; |
197 | 224 | $file_module_config = $oFileModel->getFileModuleConfig($file_obj->module_srl); |
@@ -203,7 +230,9 @@ discard block |
||
203 | 230 | { |
204 | 231 | $allow_outlink_format_array = array(); |
205 | 232 | $allow_outlink_format_array = explode(',', $file_module_config->allow_outlink_format); |
206 | - if(!is_array($allow_outlink_format_array)) $allow_outlink_format_array[0] = $file_module_config->allow_outlink_format; |
|
233 | + if(!is_array($allow_outlink_format_array)) { |
|
234 | + $allow_outlink_format_array[0] = $file_module_config->allow_outlink_format; |
|
235 | + } |
|
207 | 236 | |
208 | 237 | foreach($allow_outlink_format_array as $val) |
209 | 238 | { |
@@ -225,7 +254,9 @@ discard block |
||
225 | 254 | { |
226 | 255 | $allow_outlink_site_array = array(); |
227 | 256 | $allow_outlink_site_array = explode("\n", $file_module_config->allow_outlink_site); |
228 | - if(!is_array($allow_outlink_site_array)) $allow_outlink_site_array[0] = $file_module_config->allow_outlink_site; |
|
257 | + if(!is_array($allow_outlink_site_array)) { |
|
258 | + $allow_outlink_site_array[0] = $file_module_config->allow_outlink_site; |
|
259 | + } |
|
229 | 260 | |
230 | 261 | foreach($allow_outlink_site_array as $val) |
231 | 262 | { |
@@ -237,23 +268,29 @@ discard block |
||
237 | 268 | } |
238 | 269 | } |
239 | 270 | } |
271 | + } else { |
|
272 | + $file_module_config->allow_outlink = 'Y'; |
|
240 | 273 | } |
241 | - else $file_module_config->allow_outlink = 'Y'; |
|
242 | 274 | } |
243 | - if($file_module_config->allow_outlink != 'Y') return $this->stop('msg_not_allowed_outlink'); |
|
275 | + if($file_module_config->allow_outlink != 'Y') { |
|
276 | + return $this->stop('msg_not_allowed_outlink'); |
|
277 | + } |
|
244 | 278 | } |
245 | 279 | |
246 | 280 | // Check if a permission for file download is granted |
247 | 281 | $downloadGrantCount = 0; |
248 | 282 | if(is_array($file_module_config->download_grant)) |
249 | 283 | { |
250 | - foreach($file_module_config->download_grant AS $value) |
|
251 | - if($value) $downloadGrantCount++; |
|
284 | + foreach($file_module_config->download_grant AS $value) { |
|
285 | + if($value) $downloadGrantCount++; |
|
286 | + } |
|
252 | 287 | } |
253 | 288 | |
254 | 289 | if(is_array($file_module_config->download_grant) && $downloadGrantCount>0) |
255 | 290 | { |
256 | - if(!Context::get('is_logged')) return $this->stop('msg_not_permitted_download'); |
|
291 | + if(!Context::get('is_logged')) { |
|
292 | + return $this->stop('msg_not_permitted_download'); |
|
293 | + } |
|
257 | 294 | $logged_info = Context::get('logged_info'); |
258 | 295 | if($logged_info->is_admin != 'Y') |
259 | 296 | { |
@@ -276,13 +313,17 @@ discard block |
||
276 | 313 | break; |
277 | 314 | } |
278 | 315 | } |
279 | - if(!$is_permitted) return $this->stop('msg_not_permitted_download'); |
|
316 | + if(!$is_permitted) { |
|
317 | + return $this->stop('msg_not_permitted_download'); |
|
318 | + } |
|
280 | 319 | } |
281 | 320 | } |
282 | 321 | } |
283 | 322 | // Call a trigger (before) |
284 | 323 | $output = ModuleHandler::triggerCall('file.downloadFile', 'before', $file_obj); |
285 | - if(!$output->toBool()) return $this->stop(($output->message)?$output->message:'msg_not_permitted_download'); |
|
324 | + if(!$output->toBool()) { |
|
325 | + return $this->stop(($output->message)?$output->message:'msg_not_permitted_download'); |
|
326 | + } |
|
286 | 327 | |
287 | 328 | |
288 | 329 | // 다운로드 후 (가상) |
@@ -306,16 +347,23 @@ discard block |
||
306 | 347 | $oFileModel = getModel('file'); |
307 | 348 | $file_srl = Context::get('file_srl'); |
308 | 349 | $file_key = Context::get('file_key'); |
309 | - if(strstr($_SERVER['HTTP_USER_AGENT'], "Android")) $is_android = true; |
|
350 | + if(strstr($_SERVER['HTTP_USER_AGENT'], "Android")) { |
|
351 | + $is_android = true; |
|
352 | + } |
|
310 | 353 | |
311 | - if($is_android && $_SESSION['__XE_FILE_KEY_AND__'][$file_srl]) $session_key = '__XE_FILE_KEY_AND__'; |
|
312 | - else $session_key = '__XE_FILE_KEY__'; |
|
354 | + if($is_android && $_SESSION['__XE_FILE_KEY_AND__'][$file_srl]) { |
|
355 | + $session_key = '__XE_FILE_KEY_AND__'; |
|
356 | + } else { |
|
357 | + $session_key = '__XE_FILE_KEY__'; |
|
358 | + } |
|
313 | 359 | $columnList = array('source_filename', 'uploaded_filename', 'file_size'); |
314 | 360 | $file_obj = $oFileModel->getFile($file_srl, $columnList); |
315 | 361 | |
316 | 362 | $uploaded_filename = $file_obj->uploaded_filename; |
317 | 363 | |
318 | - if(!file_exists($uploaded_filename)) return $this->stop('msg_file_not_found'); |
|
364 | + if(!file_exists($uploaded_filename)) { |
|
365 | + return $this->stop('msg_file_not_found'); |
|
366 | + } |
|
319 | 367 | |
320 | 368 | if(!$file_key || $_SESSION[$session_key][$file_srl] != $file_key) |
321 | 369 | { |
@@ -331,29 +379,27 @@ discard block |
||
331 | 379 | if($is_android && preg_match('#\bwv\b|(?:Version|Browser)/\d+#', $_SERVER['HTTP_USER_AGENT'])) |
332 | 380 | { |
333 | 381 | $filename_param = 'filename="' . $filename . '"'; |
334 | - } |
|
335 | - else |
|
382 | + } else |
|
336 | 383 | { |
337 | 384 | $filename_param = "filename*=UTF-8''" . rawurlencode($filename) . '; filename="' . rawurlencode($filename) . '"'; |
338 | 385 | } |
339 | - } |
|
340 | - elseif(preg_match('#(?:Firefox|Safari|Trident)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 6) |
|
386 | + } elseif(preg_match('#(?:Firefox|Safari|Trident)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 6) |
|
341 | 387 | { |
342 | 388 | $filename_param = "filename*=UTF-8''" . rawurlencode($filename) . '; filename="' . rawurlencode($filename) . '"'; |
343 | - } |
|
344 | - elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) |
|
389 | + } elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) |
|
345 | 390 | { |
346 | 391 | $filename = rawurlencode($filename); |
347 | 392 | $filename_param = 'filename="' . preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1) . '"'; |
348 | - } |
|
349 | - else |
|
393 | + } else |
|
350 | 394 | { |
351 | 395 | $filename_param = 'filename="' . $filename . '"'; |
352 | 396 | } |
353 | 397 | |
354 | 398 | if($is_android) |
355 | 399 | { |
356 | - if($_SESSION['__XE_FILE_KEY__'][$file_srl]) $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
|
400 | + if($_SESSION['__XE_FILE_KEY__'][$file_srl]) { |
|
401 | + $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
|
402 | + } |
|
357 | 403 | } |
358 | 404 | |
359 | 405 | unset($_SESSION[$session_key][$file_srl]); |
@@ -361,7 +407,9 @@ discard block |
||
361 | 407 | Context::close(); |
362 | 408 | |
363 | 409 | $fp = fopen($uploaded_filename, 'rb'); |
364 | - if(!$fp) return $this->stop('msg_file_not_found'); |
|
410 | + if(!$fp) { |
|
411 | + return $this->stop('msg_file_not_found'); |
|
412 | + } |
|
365 | 413 | |
366 | 414 | header("Cache-Control: "); |
367 | 415 | header("Pragma: "); |
@@ -375,10 +423,11 @@ discard block |
||
375 | 423 | // if file size is lager than 10MB, use fread function (#18675748) |
376 | 424 | if($file_size > 1024 * 1024) |
377 | 425 | { |
378 | - while(!feof($fp)) echo fread($fp, 1024); |
|
426 | + while(!feof($fp)) { |
|
427 | + echo fread($fp, 1024); |
|
428 | + } |
|
379 | 429 | fclose($fp); |
380 | - } |
|
381 | - else |
|
430 | + } else |
|
382 | 431 | { |
383 | 432 | fpassthru($fp); |
384 | 433 | } |
@@ -397,9 +446,13 @@ discard block |
||
397 | 446 | $editor_sequence = Context::get('editor_sequence'); |
398 | 447 | $file_srl = Context::get('file_srl'); |
399 | 448 | $file_srls = Context::get('file_srls'); |
400 | - if($file_srls) $file_srl = $file_srls; |
|
449 | + if($file_srls) { |
|
450 | + $file_srl = $file_srls; |
|
451 | + } |
|
401 | 452 | // Exit a session if there is neither upload permission nor information |
402 | - if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
453 | + if(!$_SESSION['upload_info'][$editor_sequence]->enabled) { |
|
454 | + exit(); |
|
455 | + } |
|
403 | 456 | |
404 | 457 | $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
405 | 458 | |
@@ -407,26 +460,38 @@ discard block |
||
407 | 460 | $oFileModel = getModel('file'); |
408 | 461 | |
409 | 462 | $srls = explode(',',$file_srl); |
410 | - if(!count($srls)) return; |
|
463 | + if(!count($srls)) { |
|
464 | + return; |
|
465 | + } |
|
411 | 466 | |
412 | 467 | for($i=0;$i<count($srls);$i++) |
413 | 468 | { |
414 | 469 | $srl = (int)$srls[$i]; |
415 | - if(!$srl) continue; |
|
470 | + if(!$srl) { |
|
471 | + continue; |
|
472 | + } |
|
416 | 473 | |
417 | 474 | $args = new stdClass; |
418 | 475 | $args->file_srl = $srl; |
419 | 476 | $output = executeQuery('file.getFile', $args); |
420 | - if(!$output->toBool()) continue; |
|
477 | + if(!$output->toBool()) { |
|
478 | + continue; |
|
479 | + } |
|
421 | 480 | |
422 | 481 | $file_info = $output->data; |
423 | - if(!$file_info) continue; |
|
482 | + if(!$file_info) { |
|
483 | + continue; |
|
484 | + } |
|
424 | 485 | |
425 | 486 | $file_grant = $oFileModel->getFileGrant($file_info, $logged_info); |
426 | 487 | |
427 | - if(!$file_grant->is_deletable) continue; |
|
488 | + if(!$file_grant->is_deletable) { |
|
489 | + continue; |
|
490 | + } |
|
428 | 491 | |
429 | - if($upload_target_srl && $file_srl) $output = $this->deleteFile($file_srl); |
|
492 | + if($upload_target_srl && $file_srl) { |
|
493 | + $output = $this->deleteFile($file_srl); |
|
494 | + } |
|
430 | 495 | } |
431 | 496 | } |
432 | 497 | |
@@ -437,7 +502,9 @@ discard block |
||
437 | 502 | */ |
438 | 503 | function procFileGetList() |
439 | 504 | { |
440 | - if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted'); |
|
505 | + if(!Context::get('is_logged')) { |
|
506 | + return new Object(-1,'msg_not_permitted'); |
|
507 | + } |
|
441 | 508 | |
442 | 509 | $oModuleModel = getModel('module'); |
443 | 510 | |
@@ -448,26 +515,32 @@ discard block |
||
448 | 515 | } |
449 | 516 | |
450 | 517 | $fileSrls = Context::get('file_srls'); |
451 | - if($fileSrls) $fileSrlList = explode(',', $fileSrls); |
|
518 | + if($fileSrls) { |
|
519 | + $fileSrlList = explode(',', $fileSrls); |
|
520 | + } |
|
452 | 521 | |
453 | 522 | global $lang; |
454 | 523 | if(count($fileSrlList) > 0) |
455 | 524 | { |
456 | 525 | $oFileModel = getModel('file'); |
457 | 526 | $fileList = $oFileModel->getFile($fileSrlList); |
458 | - if(!is_array($fileList)) $fileList = array($fileList); |
|
527 | + if(!is_array($fileList)) { |
|
528 | + $fileList = array($fileList); |
|
529 | + } |
|
459 | 530 | |
460 | 531 | if(is_array($fileList)) |
461 | 532 | { |
462 | 533 | foreach($fileList AS $key=>$value) |
463 | 534 | { |
464 | 535 | $value->human_file_size = FileHandler::filesize($value->file_size); |
465 | - if($value->isvalid=='Y') $value->validName = $lang->is_valid; |
|
466 | - else $value->validName = $lang->is_stand_by; |
|
536 | + if($value->isvalid=='Y') { |
|
537 | + $value->validName = $lang->is_valid; |
|
538 | + } else { |
|
539 | + $value->validName = $lang->is_stand_by; |
|
540 | + } |
|
467 | 541 | } |
468 | 542 | } |
469 | - } |
|
470 | - else |
|
543 | + } else |
|
471 | 544 | { |
472 | 545 | $fileList = array(); |
473 | 546 | $this->setMessage($lang->no_files); |
@@ -484,7 +557,9 @@ discard block |
||
484 | 557 | function triggerCheckAttached(&$obj) |
485 | 558 | { |
486 | 559 | $document_srl = $obj->document_srl; |
487 | - if(!$document_srl) return new Object(); |
|
560 | + if(!$document_srl) { |
|
561 | + return new Object(); |
|
562 | + } |
|
488 | 563 | // Get numbers of attachments |
489 | 564 | $oFileModel = getModel('file'); |
490 | 565 | $obj->uploaded_count = $oFileModel->getFilesCount($document_srl); |
@@ -501,10 +576,14 @@ discard block |
||
501 | 576 | function triggerAttachFiles(&$obj) |
502 | 577 | { |
503 | 578 | $document_srl = $obj->document_srl; |
504 | - if(!$document_srl) return new Object(); |
|
579 | + if(!$document_srl) { |
|
580 | + return new Object(); |
|
581 | + } |
|
505 | 582 | |
506 | 583 | $output = $this->setFilesValid($document_srl); |
507 | - if(!$output->toBool()) return $output; |
|
584 | + if(!$output->toBool()) { |
|
585 | + return $output; |
|
586 | + } |
|
508 | 587 | |
509 | 588 | return new Object(); |
510 | 589 | } |
@@ -518,7 +597,9 @@ discard block |
||
518 | 597 | function triggerDeleteAttached(&$obj) |
519 | 598 | { |
520 | 599 | $document_srl = $obj->document_srl; |
521 | - if(!$document_srl) return new Object(); |
|
600 | + if(!$document_srl) { |
|
601 | + return new Object(); |
|
602 | + } |
|
522 | 603 | |
523 | 604 | $output = $this->deleteFiles($document_srl); |
524 | 605 | return $output; |
@@ -533,7 +614,9 @@ discard block |
||
533 | 614 | function triggerCommentCheckAttached(&$obj) |
534 | 615 | { |
535 | 616 | $comment_srl = $obj->comment_srl; |
536 | - if(!$comment_srl) return new Object(); |
|
617 | + if(!$comment_srl) { |
|
618 | + return new Object(); |
|
619 | + } |
|
537 | 620 | // Get numbers of attachments |
538 | 621 | $oFileModel = getModel('file'); |
539 | 622 | $obj->uploaded_count = $oFileModel->getFilesCount($comment_srl); |
@@ -551,10 +634,14 @@ discard block |
||
551 | 634 | { |
552 | 635 | $comment_srl = $obj->comment_srl; |
553 | 636 | $uploaded_count = $obj->uploaded_count; |
554 | - if(!$comment_srl || !$uploaded_count) return new Object(); |
|
637 | + if(!$comment_srl || !$uploaded_count) { |
|
638 | + return new Object(); |
|
639 | + } |
|
555 | 640 | |
556 | 641 | $output = $this->setFilesValid($comment_srl); |
557 | - if(!$output->toBool()) return $output; |
|
642 | + if(!$output->toBool()) { |
|
643 | + return $output; |
|
644 | + } |
|
558 | 645 | |
559 | 646 | return new Object(); |
560 | 647 | } |
@@ -568,9 +655,13 @@ discard block |
||
568 | 655 | function triggerCommentDeleteAttached(&$obj) |
569 | 656 | { |
570 | 657 | $comment_srl = $obj->comment_srl; |
571 | - if(!$comment_srl) return new Object(); |
|
658 | + if(!$comment_srl) { |
|
659 | + return new Object(); |
|
660 | + } |
|
572 | 661 | |
573 | - if($obj->isMoveToTrash) return new Object(); |
|
662 | + if($obj->isMoveToTrash) { |
|
663 | + return new Object(); |
|
664 | + } |
|
574 | 665 | |
575 | 666 | $output = $this->deleteFiles($comment_srl); |
576 | 667 | return $output; |
@@ -585,7 +676,9 @@ discard block |
||
585 | 676 | function triggerDeleteModuleFiles(&$obj) |
586 | 677 | { |
587 | 678 | $module_srl = $obj->module_srl; |
588 | - if(!$module_srl) return new Object(); |
|
679 | + if(!$module_srl) { |
|
680 | + return new Object(); |
|
681 | + } |
|
589 | 682 | |
590 | 683 | $oFileController = getAdminController('file'); |
591 | 684 | return $oFileController->deleteModuleFiles($module_srl); |
@@ -660,7 +753,9 @@ discard block |
||
660 | 753 | $trigger_obj->module_srl = $module_srl; |
661 | 754 | $trigger_obj->upload_target_srl = $upload_target_srl; |
662 | 755 | $output = ModuleHandler::triggerCall('file.insertFile', 'before', $trigger_obj); |
663 | - if(!$output->toBool()) return $output; |
|
756 | + if(!$output->toBool()) { |
|
757 | + return $output; |
|
758 | + } |
|
664 | 759 | |
665 | 760 | // A workaround for Firefox upload bug |
666 | 761 | if(preg_match('/^=\?UTF-8\?B\?(.+)\?=$/i', $file_info['name'], $match)) |
@@ -698,13 +793,17 @@ discard block |
||
698 | 793 | $allowed_filesize = $config->allowed_filesize * 1024 * 1024; |
699 | 794 | $allowed_attach_size = $config->allowed_attach_size * 1024 * 1024; |
700 | 795 | // An error appears if file size exceeds a limit |
701 | - if($allowed_filesize < filesize($file_info['tmp_name'])) return new Object(-1, 'msg_exceeds_limit_size'); |
|
796 | + if($allowed_filesize < filesize($file_info['tmp_name'])) { |
|
797 | + return new Object(-1, 'msg_exceeds_limit_size'); |
|
798 | + } |
|
702 | 799 | // Get total file size of all attachements (from DB) |
703 | 800 | $size_args = new stdClass; |
704 | 801 | $size_args->upload_target_srl = $upload_target_srl; |
705 | 802 | $output = executeQuery('file.getAttachedFileSize', $size_args); |
706 | 803 | $attached_size = (int)$output->data->attached_size + filesize($file_info['tmp_name']); |
707 | - if($attached_size > $allowed_attach_size) return new Object(-1, 'msg_exceeds_limit_size'); |
|
804 | + if($attached_size > $allowed_attach_size) { |
|
805 | + return new Object(-1, 'msg_exceeds_limit_size'); |
|
806 | + } |
|
708 | 807 | } |
709 | 808 | } |
710 | 809 | |
@@ -734,18 +833,21 @@ discard block |
||
734 | 833 | $idx++; |
735 | 834 | } |
736 | 835 | $direct_download = 'Y'; |
737 | - } |
|
738 | - else |
|
836 | + } else |
|
739 | 837 | { |
740 | 838 | $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl,3)); |
741 | 839 | $filename = $path.$random->createSecureSalt(32, 'hex'); |
742 | 840 | $direct_download = 'N'; |
743 | 841 | } |
744 | 842 | // Create a directory |
745 | - if(!FileHandler::makeDir($path)) return new Object(-1,'msg_not_permitted_create'); |
|
843 | + if(!FileHandler::makeDir($path)) { |
|
844 | + return new Object(-1,'msg_not_permitted_create'); |
|
845 | + } |
|
746 | 846 | |
747 | 847 | // Check uploaded file |
748 | - if(!checkUploadedFile($file_info['tmp_name'])) return new Object(-1,'msg_file_upload_error'); |
|
848 | + if(!checkUploadedFile($file_info['tmp_name'])) { |
|
849 | + return new Object(-1,'msg_file_upload_error'); |
|
850 | + } |
|
749 | 851 | |
750 | 852 | // Get random number generator |
751 | 853 | $random = new Password(); |
@@ -759,13 +861,14 @@ discard block |
||
759 | 861 | $filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
760 | 862 | @copy($file_info['tmp_name'], $filename); |
761 | 863 | } |
762 | - } |
|
763 | - else |
|
864 | + } else |
|
764 | 865 | { |
765 | 866 | if(!@move_uploaded_file($file_info['tmp_name'], $filename)) |
766 | 867 | { |
767 | 868 | $filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
768 | - if(!@move_uploaded_file($file_info['tmp_name'], $filename)) return new Object(-1,'msg_file_upload_error'); |
|
869 | + if(!@move_uploaded_file($file_info['tmp_name'], $filename)) { |
|
870 | + return new Object(-1,'msg_file_upload_error'); |
|
871 | + } |
|
769 | 872 | } |
770 | 873 | } |
771 | 874 | // Get member information |
@@ -786,10 +889,14 @@ discard block |
||
786 | 889 | $args->sid = $random->createSecureSalt(32, 'hex'); |
787 | 890 | |
788 | 891 | $output = executeQuery('file.insertFile', $args); |
789 | - if(!$output->toBool()) return $output; |
|
892 | + if(!$output->toBool()) { |
|
893 | + return $output; |
|
894 | + } |
|
790 | 895 | // Call a trigger (after) |
791 | 896 | $trigger_output = ModuleHandler::triggerCall('file.insertFile', 'after', $args); |
792 | - if(!$trigger_output->toBool()) return $trigger_output; |
|
897 | + if(!$trigger_output->toBool()) { |
|
898 | + return $trigger_output; |
|
899 | + } |
|
793 | 900 | |
794 | 901 | $_SESSION['__XE_UPLOADING_FILES_INFO__'][$args->file_srl] = true; |
795 | 902 | |
@@ -832,10 +939,14 @@ discard block |
||
832 | 939 | */ |
833 | 940 | function deleteFile($file_srl) |
834 | 941 | { |
835 | - if(!$file_srl) return; |
|
942 | + if(!$file_srl) { |
|
943 | + return; |
|
944 | + } |
|
836 | 945 | |
837 | 946 | $srls = (is_array($file_srl)) ? $file_srl : explode(',', $file_srl); |
838 | - if(!count($srls)) return; |
|
947 | + if(!count($srls)) { |
|
948 | + return; |
|
949 | + } |
|
839 | 950 | |
840 | 951 | $oDocumentController = getController('document'); |
841 | 952 | $documentSrlList = array(); |
@@ -870,15 +981,21 @@ discard block |
||
870 | 981 | // Call a trigger (before) |
871 | 982 | $trigger_obj = $output->data; |
872 | 983 | $output = ModuleHandler::triggerCall('file.deleteFile', 'before', $trigger_obj); |
873 | - if(!$output->toBool()) return $output; |
|
984 | + if(!$output->toBool()) { |
|
985 | + return $output; |
|
986 | + } |
|
874 | 987 | |
875 | 988 | // Remove from the DB |
876 | 989 | $output = executeQuery('file.deleteFile', $args); |
877 | - if(!$output->toBool()) return $output; |
|
990 | + if(!$output->toBool()) { |
|
991 | + return $output; |
|
992 | + } |
|
878 | 993 | |
879 | 994 | // Call a trigger (after) |
880 | 995 | $trigger_output = ModuleHandler::triggerCall('file.deleteFile', 'after', $trigger_obj); |
881 | - if(!$trigger_output->toBool()) return $trigger_output; |
|
996 | + if(!$trigger_output->toBool()) { |
|
997 | + return $trigger_output; |
|
998 | + } |
|
882 | 999 | |
883 | 1000 | // If successfully deleted, remove the file |
884 | 1001 | FileHandler::removeFile($uploaded_filename); |
@@ -902,7 +1019,9 @@ discard block |
||
902 | 1019 | $columnList = array('file_srl', 'uploaded_filename', 'module_srl'); |
903 | 1020 | $file_list = $oFileModel->getFiles($upload_target_srl, $columnList); |
904 | 1021 | // Success returned if no attachement exists |
905 | - if(!is_array($file_list)||!count($file_list)) return new Object(); |
|
1022 | + if(!is_array($file_list)||!count($file_list)) { |
|
1023 | + return new Object(); |
|
1024 | + } |
|
906 | 1025 | |
907 | 1026 | // Delete the file |
908 | 1027 | $path = array(); |
@@ -913,14 +1032,18 @@ discard block |
||
913 | 1032 | |
914 | 1033 | $uploaded_filename = $file_list[$i]->uploaded_filename; |
915 | 1034 | $path_info = pathinfo($uploaded_filename); |
916 | - if(!in_array($path_info['dirname'], $path)) $path[] = $path_info['dirname']; |
|
1035 | + if(!in_array($path_info['dirname'], $path)) { |
|
1036 | + $path[] = $path_info['dirname']; |
|
1037 | + } |
|
917 | 1038 | } |
918 | 1039 | |
919 | 1040 | // Remove from the DB |
920 | 1041 | $args = new stdClass(); |
921 | 1042 | $args->upload_target_srl = $upload_target_srl; |
922 | 1043 | $output = executeQuery('file.deleteFiles', $args); |
923 | - if(!$output->toBool()) return $output; |
|
1044 | + if(!$output->toBool()) { |
|
1045 | + return $output; |
|
1046 | + } |
|
924 | 1047 | |
925 | 1048 | // Remove a file directory of the document |
926 | 1049 | for($i=0, $c=count($path); $i<$c; $i++) |
@@ -941,11 +1064,15 @@ discard block |
||
941 | 1064 | */ |
942 | 1065 | function moveFile($source_srl, $target_module_srl, $target_srl) |
943 | 1066 | { |
944 | - if($source_srl == $target_srl) return; |
|
1067 | + if($source_srl == $target_srl) { |
|
1068 | + return; |
|
1069 | + } |
|
945 | 1070 | |
946 | 1071 | $oFileModel = getModel('file'); |
947 | 1072 | $file_list = $oFileModel->getFiles($source_srl); |
948 | - if(!$file_list) return; |
|
1073 | + if(!$file_list) { |
|
1074 | + return; |
|
1075 | + } |
|
949 | 1076 | |
950 | 1077 | $file_count = count($file_list); |
951 | 1078 | |
@@ -959,15 +1086,16 @@ discard block |
||
959 | 1086 | { |
960 | 1087 | $path = sprintf("./files/attach/images/%s/%s/", $target_module_srl,$target_srl); |
961 | 1088 | $new_file = $path.$file_info->source_filename; |
962 | - } |
|
963 | - else |
|
1089 | + } else |
|
964 | 1090 | { |
965 | 1091 | $path = sprintf("./files/attach/binaries/%s/%s/", $target_module_srl, $target_srl); |
966 | 1092 | $random = new Password(); |
967 | 1093 | $new_file = $path.$random->createSecureSalt(32, 'hex'); |
968 | 1094 | } |
969 | 1095 | // Pass if a target document to move is same |
970 | - if($old_file == $new_file) continue; |
|
1096 | + if($old_file == $new_file) { |
|
1097 | + continue; |
|
1098 | + } |
|
971 | 1099 | // Create a directory |
972 | 1100 | FileHandler::makeDir($path); |
973 | 1101 | // Move the file |
@@ -987,16 +1115,22 @@ discard block |
||
987 | 1115 | $vars = Context::getRequestVars(); |
988 | 1116 | $logged_info = Context::get('logged_info'); |
989 | 1117 | |
990 | - if(!$vars->editor_sequence) return new Object(-1, 'msg_invalid_request'); |
|
1118 | + if(!$vars->editor_sequence) { |
|
1119 | + return new Object(-1, 'msg_invalid_request'); |
|
1120 | + } |
|
991 | 1121 | |
992 | 1122 | $upload_target_srl = $_SESSION['upload_info'][$vars->editor_sequence]->upload_target_srl; |
993 | 1123 | |
994 | 1124 | $oFileModel = getModel('file'); |
995 | 1125 | $file_info = $oFileModel->getFile($vars->file_srl); |
996 | 1126 | |
997 | - if(!$file_info) return new Object(-1, 'msg_not_founded'); |
|
1127 | + if(!$file_info) { |
|
1128 | + return new Object(-1, 'msg_not_founded'); |
|
1129 | + } |
|
998 | 1130 | |
999 | - if(!$this->manager && !$file_info->member_srl === $logged_info->member_srl) return new Object(-1, 'msg_not_permitted'); |
|
1131 | + if(!$this->manager && !$file_info->member_srl === $logged_info->member_srl) { |
|
1132 | + return new Object(-1, 'msg_not_permitted'); |
|
1133 | + } |
|
1000 | 1134 | |
1001 | 1135 | $args = new stdClass(); |
1002 | 1136 | $args->file_srl = $vars->file_srl; |