@@ -29,24 +29,24 @@ 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 | - if($output->error != '0') $this->stop($output->message); |
|
| 49 | + if ($output->error != '0') $this->stop($output->message); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -61,26 +61,26 @@ discard block |
||
| 61 | 61 | $callback = Context::get('callback'); |
| 62 | 62 | $module_srl = $this->module_srl; |
| 63 | 63 | $upload_target_srl = intval(Context::get('uploadTargetSrl')); |
| 64 | - if(!$upload_target_srl) $upload_target_srl = intval(Context::get('upload_target_srl')); |
|
| 64 | + if (!$upload_target_srl) $upload_target_srl = intval(Context::get('upload_target_srl')); |
|
| 65 | 65 | |
| 66 | 66 | // Exit a session if there is neither upload permission nor information |
| 67 | - if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
| 67 | + if (!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
| 68 | 68 | // Extract from session information if upload_target_srl is not specified |
| 69 | - if(!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
|
| 69 | + if (!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
|
| 70 | 70 | // Create if upload_target_srl is not defined in the session information |
| 71 | - if(!$upload_target_srl) $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
|
| 71 | + if (!$upload_target_srl) $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
|
| 72 | 72 | // Delete and then attempt to re-upload if file_srl is requested |
| 73 | 73 | $file_srl = Context::get('file_srl'); |
| 74 | - if($file_srl) $this->deleteFile($file_srl); |
|
| 74 | + if ($file_srl) $this->deleteFile($file_srl); |
|
| 75 | 75 | |
| 76 | 76 | $file_info = Context::get('Filedata'); |
| 77 | 77 | // An error appears if not a normally uploaded file |
| 78 | - if(is_uploaded_file($file_info['tmp_name'])) { |
|
| 78 | + if (is_uploaded_file($file_info['tmp_name'])) { |
|
| 79 | 79 | $output = $this->insertFile($file_info, $module_srl, $upload_target_srl); |
| 80 | - Context::set('uploaded_fileinfo',$output); |
|
| 80 | + Context::set('uploaded_fileinfo', $output); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - Context::set('layout','none'); |
|
| 83 | + Context::set('layout', 'none'); |
|
| 84 | 84 | |
| 85 | 85 | $this->setTemplatePath($this->module_path.'tpl'); |
| 86 | 86 | $this->setTemplateFile('iframe'); |
@@ -97,24 +97,24 @@ discard block |
||
| 97 | 97 | $width = Context::get('width'); |
| 98 | 98 | $height = Context::get('height'); |
| 99 | 99 | |
| 100 | - if(!$file_srl || !$width) |
|
| 100 | + if (!$file_srl || !$width) |
|
| 101 | 101 | { |
| 102 | - return new Object(-1,'msg_invalid_request'); |
|
| 102 | + return new Object(-1, 'msg_invalid_request'); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | $oFileModel = getModel('file'); |
| 106 | 106 | $fileInfo = $oFileModel->getFile($file_srl); |
| 107 | - if(!$fileInfo || $fileInfo->direct_download != 'Y') |
|
| 107 | + if (!$fileInfo || $fileInfo->direct_download != 'Y') |
|
| 108 | 108 | { |
| 109 | - return new Object(-1,'msg_invalid_request'); |
|
| 109 | + return new Object(-1, 'msg_invalid_request'); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | $source_src = $fileInfo->uploaded_filename; |
| 113 | - $output_src = $source_src . '.resized' . strrchr($source_src,'.'); |
|
| 113 | + $output_src = $source_src.'.resized'.strrchr($source_src, '.'); |
|
| 114 | 114 | |
| 115 | - if(!$height) $height = $width-1; |
|
| 115 | + if (!$height) $height = $width - 1; |
|
| 116 | 116 | |
| 117 | - if(FileHandler::createImageFile($source_src,$output_src,$width,$height,'','ratio')) |
|
| 117 | + if (FileHandler::createImageFile($source_src, $output_src, $width, $height, '', 'ratio')) |
|
| 118 | 118 | { |
| 119 | 119 | $output = new stdClass(); |
| 120 | 120 | $output->info = getimagesize($output_src); |
@@ -122,10 +122,10 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | else |
| 124 | 124 | { |
| 125 | - return new Object(-1,'msg_invalid_request'); |
|
| 125 | + return new Object(-1, 'msg_invalid_request'); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $this->add('resized_info',$output); |
|
| 128 | + $this->add('resized_info', $output); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | { |
| 164 | 164 | $oFileModel = getModel('file'); |
| 165 | 165 | |
| 166 | - if(isset($this->grant->access) && $this->grant->access !== true) return new Object(-1, 'msg_not_permitted'); |
|
| 166 | + if (isset($this->grant->access) && $this->grant->access !== true) return new Object(-1, 'msg_not_permitted'); |
|
| 167 | 167 | |
| 168 | 168 | $file_srl = Context::get('file_srl'); |
| 169 | 169 | $sid = Context::get('sid'); |
@@ -172,26 +172,26 @@ discard block |
||
| 172 | 172 | $columnList = array('file_srl', 'sid', 'isvalid', 'source_filename', 'module_srl', 'uploaded_filename', 'file_size', 'member_srl', 'upload_target_srl', 'upload_target_type'); |
| 173 | 173 | $file_obj = $oFileModel->getFile($file_srl, $columnList); |
| 174 | 174 | // If the requested file information is incorrect, an error that file cannot be found appears |
| 175 | - if($file_obj->file_srl!=$file_srl || $file_obj->sid!=$sid) return $this->stop('msg_file_not_found'); |
|
| 175 | + if ($file_obj->file_srl != $file_srl || $file_obj->sid != $sid) return $this->stop('msg_file_not_found'); |
|
| 176 | 176 | // Notify that file download is not allowed when standing-by(Only a top-administrator is permitted) |
| 177 | - if($logged_info->is_admin != 'Y' && $file_obj->isvalid!='Y') return $this->stop('msg_not_permitted_download'); |
|
| 177 | + if ($logged_info->is_admin != 'Y' && $file_obj->isvalid != 'Y') return $this->stop('msg_not_permitted_download'); |
|
| 178 | 178 | // File name |
| 179 | 179 | $filename = $file_obj->source_filename; |
| 180 | 180 | $file_module_config = $oFileModel->getFileModuleConfig($file_obj->module_srl); |
| 181 | 181 | // Not allow the file outlink |
| 182 | - if($file_module_config->allow_outlink == 'N') |
|
| 182 | + if ($file_module_config->allow_outlink == 'N') |
|
| 183 | 183 | { |
| 184 | 184 | // Handles extension to allow outlink |
| 185 | - if($file_module_config->allow_outlink_format) |
|
| 185 | + if ($file_module_config->allow_outlink_format) |
|
| 186 | 186 | { |
| 187 | 187 | $allow_outlink_format_array = array(); |
| 188 | 188 | $allow_outlink_format_array = explode(',', $file_module_config->allow_outlink_format); |
| 189 | - if(!is_array($allow_outlink_format_array)) $allow_outlink_format_array[0] = $file_module_config->allow_outlink_format; |
|
| 189 | + if (!is_array($allow_outlink_format_array)) $allow_outlink_format_array[0] = $file_module_config->allow_outlink_format; |
|
| 190 | 190 | |
| 191 | - foreach($allow_outlink_format_array as $val) |
|
| 191 | + foreach ($allow_outlink_format_array as $val) |
|
| 192 | 192 | { |
| 193 | 193 | $val = trim($val); |
| 194 | - if(preg_match("/\.{$val}$/i", $filename)) |
|
| 194 | + if (preg_match("/\.{$val}$/i", $filename)) |
|
| 195 | 195 | { |
| 196 | 196 | $file_module_config->allow_outlink = 'Y'; |
| 197 | 197 | break; |
@@ -199,21 +199,21 @@ discard block |
||
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | // Sites that outlink is allowed |
| 202 | - if($file_module_config->allow_outlink != 'Y') |
|
| 202 | + if ($file_module_config->allow_outlink != 'Y') |
|
| 203 | 203 | { |
| 204 | 204 | $referer = parse_url($_SERVER["HTTP_REFERER"]); |
| 205 | - if($referer['host'] != $_SERVER['HTTP_HOST']) |
|
| 205 | + if ($referer['host'] != $_SERVER['HTTP_HOST']) |
|
| 206 | 206 | { |
| 207 | - if($file_module_config->allow_outlink_site) |
|
| 207 | + if ($file_module_config->allow_outlink_site) |
|
| 208 | 208 | { |
| 209 | 209 | $allow_outlink_site_array = array(); |
| 210 | 210 | $allow_outlink_site_array = explode("\n", $file_module_config->allow_outlink_site); |
| 211 | - if(!is_array($allow_outlink_site_array)) $allow_outlink_site_array[0] = $file_module_config->allow_outlink_site; |
|
| 211 | + if (!is_array($allow_outlink_site_array)) $allow_outlink_site_array[0] = $file_module_config->allow_outlink_site; |
|
| 212 | 212 | |
| 213 | - foreach($allow_outlink_site_array as $val) |
|
| 213 | + foreach ($allow_outlink_site_array as $val) |
|
| 214 | 214 | { |
| 215 | 215 | $site = parse_url(trim($val)); |
| 216 | - if($site['host'] == $referer['host']) |
|
| 216 | + if ($site['host'] == $referer['host']) |
|
| 217 | 217 | { |
| 218 | 218 | $file_module_config->allow_outlink = 'Y'; |
| 219 | 219 | break; |
@@ -223,49 +223,49 @@ discard block |
||
| 223 | 223 | } |
| 224 | 224 | else $file_module_config->allow_outlink = 'Y'; |
| 225 | 225 | } |
| 226 | - if($file_module_config->allow_outlink != 'Y') return $this->stop('msg_not_allowed_outlink'); |
|
| 226 | + if ($file_module_config->allow_outlink != 'Y') return $this->stop('msg_not_allowed_outlink'); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | // Check if a permission for file download is granted |
| 230 | 230 | $downloadGrantCount = 0; |
| 231 | - if(is_array($file_module_config->download_grant)) |
|
| 231 | + if (is_array($file_module_config->download_grant)) |
|
| 232 | 232 | { |
| 233 | - foreach($file_module_config->download_grant AS $value) |
|
| 234 | - if($value) $downloadGrantCount++; |
|
| 233 | + foreach ($file_module_config->download_grant AS $value) |
|
| 234 | + if ($value) $downloadGrantCount++; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - if(is_array($file_module_config->download_grant) && $downloadGrantCount>0) |
|
| 237 | + if (is_array($file_module_config->download_grant) && $downloadGrantCount > 0) |
|
| 238 | 238 | { |
| 239 | - if(!Context::get('is_logged')) return $this->stop('msg_not_permitted_download'); |
|
| 239 | + if (!Context::get('is_logged')) return $this->stop('msg_not_permitted_download'); |
|
| 240 | 240 | $logged_info = Context::get('logged_info'); |
| 241 | - if($logged_info->is_admin != 'Y') |
|
| 241 | + if ($logged_info->is_admin != 'Y') |
|
| 242 | 242 | { |
| 243 | - $oModuleModel =& getModel('module'); |
|
| 243 | + $oModuleModel = & getModel('module'); |
|
| 244 | 244 | $columnList = array('module_srl', 'site_srl'); |
| 245 | 245 | $module_info = $oModuleModel->getModuleInfoByModuleSrl($file_obj->module_srl, $columnList); |
| 246 | 246 | |
| 247 | - if(!$oModuleModel->isSiteAdmin($logged_info, $module_info->site_srl)) |
|
| 247 | + if (!$oModuleModel->isSiteAdmin($logged_info, $module_info->site_srl)) |
|
| 248 | 248 | { |
| 249 | - $oMemberModel =& getModel('member'); |
|
| 249 | + $oMemberModel = & getModel('member'); |
|
| 250 | 250 | $member_groups = $oMemberModel->getMemberGroups($logged_info->member_srl, $module_info->site_srl); |
| 251 | 251 | |
| 252 | 252 | $is_permitted = false; |
| 253 | - for($i=0;$i<count($file_module_config->download_grant);$i++) |
|
| 253 | + for ($i = 0; $i < count($file_module_config->download_grant); $i++) |
|
| 254 | 254 | { |
| 255 | 255 | $group_srl = $file_module_config->download_grant[$i]; |
| 256 | - if($member_groups[$group_srl]) |
|
| 256 | + if ($member_groups[$group_srl]) |
|
| 257 | 257 | { |
| 258 | 258 | $is_permitted = true; |
| 259 | 259 | break; |
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | - if(!$is_permitted) return $this->stop('msg_not_permitted_download'); |
|
| 262 | + if (!$is_permitted) return $this->stop('msg_not_permitted_download'); |
|
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | // Call a trigger (before) |
| 267 | 267 | $output = ModuleHandler::triggerCall('file.downloadFile', 'before', $file_obj); |
| 268 | - if(!$output->toBool()) return $this->stop(($output->message)?$output->message:'msg_not_permitted_download'); |
|
| 268 | + if (!$output->toBool()) return $this->stop(($output->message) ? $output->message : 'msg_not_permitted_download'); |
|
| 269 | 269 | |
| 270 | 270 | |
| 271 | 271 | // 다운로드 후 (가상) |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | |
| 279 | 279 | $random = new Password(); |
| 280 | 280 | $file_key = $_SESSION['__XE_FILE_KEY__'][$file_srl] = $random->createSecureSalt(32, 'hex'); |
| 281 | - header('Location: '.getNotEncodedUrl('', 'act', 'procFileOutput','file_srl',$file_srl,'file_key',$file_key)); |
|
| 281 | + header('Location: '.getNotEncodedUrl('', 'act', 'procFileOutput', 'file_srl', $file_srl, 'file_key', $file_key)); |
|
| 282 | 282 | Context::close(); |
| 283 | 283 | exit(); |
| 284 | 284 | |
@@ -289,18 +289,18 @@ discard block |
||
| 289 | 289 | $oFileModel = getModel('file'); |
| 290 | 290 | $file_srl = Context::get('file_srl'); |
| 291 | 291 | $file_key = Context::get('file_key'); |
| 292 | - if(strstr($_SERVER['HTTP_USER_AGENT'], "Android")) $is_android = true; |
|
| 292 | + if (strstr($_SERVER['HTTP_USER_AGENT'], "Android")) $is_android = true; |
|
| 293 | 293 | |
| 294 | - if($is_android && $_SESSION['__XE_FILE_KEY_AND__'][$file_srl]) $session_key = '__XE_FILE_KEY_AND__'; |
|
| 294 | + if ($is_android && $_SESSION['__XE_FILE_KEY_AND__'][$file_srl]) $session_key = '__XE_FILE_KEY_AND__'; |
|
| 295 | 295 | else $session_key = '__XE_FILE_KEY__'; |
| 296 | 296 | $columnList = array('source_filename', 'uploaded_filename', 'file_size'); |
| 297 | 297 | $file_obj = $oFileModel->getFile($file_srl, $columnList); |
| 298 | 298 | |
| 299 | 299 | $uploaded_filename = $file_obj->uploaded_filename; |
| 300 | 300 | |
| 301 | - if(!file_exists($uploaded_filename)) return $this->stop('msg_file_not_found'); |
|
| 301 | + if (!file_exists($uploaded_filename)) return $this->stop('msg_file_not_found'); |
|
| 302 | 302 | |
| 303 | - if(!$file_key || $_SESSION[$session_key][$file_srl] != $file_key) |
|
| 303 | + if (!$file_key || $_SESSION[$session_key][$file_srl] != $file_key) |
|
| 304 | 304 | { |
| 305 | 305 | unset($_SESSION[$session_key][$file_srl]); |
| 306 | 306 | return $this->stop('msg_invalid_request'); |
@@ -308,28 +308,28 @@ discard block |
||
| 308 | 308 | |
| 309 | 309 | $file_size = $file_obj->file_size; |
| 310 | 310 | $filename = $file_obj->source_filename; |
| 311 | - if(preg_match('#(?:Chrome|Edge)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 11) |
|
| 311 | + if (preg_match('#(?:Chrome|Edge)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 11) |
|
| 312 | 312 | { |
| 313 | - $filename_param = "filename*=UTF-8''" . rawurlencode($filename) . '; filename="' . rawurlencode($filename) . '"'; |
|
| 313 | + $filename_param = "filename*=UTF-8''".rawurlencode($filename).'; filename="'.rawurlencode($filename).'"'; |
|
| 314 | 314 | } |
| 315 | - elseif(preg_match('#(?:Firefox|Safari|Trident)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 6) |
|
| 315 | + elseif (preg_match('#(?:Firefox|Safari|Trident)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 6) |
|
| 316 | 316 | { |
| 317 | - $filename_param = "filename*=UTF-8''" . rawurlencode($filename) . '; filename="' . rawurlencode($filename) . '"'; |
|
| 317 | + $filename_param = "filename*=UTF-8''".rawurlencode($filename).'; filename="'.rawurlencode($filename).'"'; |
|
| 318 | 318 | } |
| 319 | 319 | // Filename encoding for browsers that do not support RFC 5987 |
| 320 | - elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) |
|
| 320 | + elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) |
|
| 321 | 321 | { |
| 322 | 322 | $filename = rawurlencode($filename); |
| 323 | - $filename_param = 'filename="' . preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1) . '"'; |
|
| 323 | + $filename_param = 'filename="'.preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1).'"'; |
|
| 324 | 324 | } |
| 325 | 325 | else |
| 326 | 326 | { |
| 327 | - $filename_param = 'filename="' . $filename . '"'; |
|
| 327 | + $filename_param = 'filename="'.$filename.'"'; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - if($is_android) |
|
| 330 | + if ($is_android) |
|
| 331 | 331 | { |
| 332 | - if($_SESSION['__XE_FILE_KEY__'][$file_srl]) $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
|
| 332 | + if ($_SESSION['__XE_FILE_KEY__'][$file_srl]) $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | unset($_SESSION[$session_key][$file_srl]); |
@@ -337,21 +337,21 @@ discard block |
||
| 337 | 337 | Context::close(); |
| 338 | 338 | |
| 339 | 339 | $fp = fopen($uploaded_filename, 'rb'); |
| 340 | - if(!$fp) return $this->stop('msg_file_not_found'); |
|
| 340 | + if (!$fp) return $this->stop('msg_file_not_found'); |
|
| 341 | 341 | |
| 342 | 342 | header("Cache-Control: "); |
| 343 | 343 | header("Pragma: "); |
| 344 | 344 | header("Content-Type: application/octet-stream"); |
| 345 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
| 345 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); |
|
| 346 | 346 | |
| 347 | - header("Content-Length: " .(string)($file_size)); |
|
| 348 | - header('Content-Disposition: attachment; ' . $filename_param); |
|
| 347 | + header("Content-Length: ".(string) ($file_size)); |
|
| 348 | + header('Content-Disposition: attachment; '.$filename_param); |
|
| 349 | 349 | header("Content-Transfer-Encoding: binary\n"); |
| 350 | 350 | |
| 351 | 351 | // if file size is lager than 10MB, use fread function (#18675748) |
| 352 | - if(filesize($uploaded_filename) > 1024 * 1024) |
|
| 352 | + if (filesize($uploaded_filename) > 1024 * 1024) |
|
| 353 | 353 | { |
| 354 | - while(!feof($fp)) echo fread($fp, 1024); |
|
| 354 | + while (!feof($fp)) echo fread($fp, 1024); |
|
| 355 | 355 | fclose($fp); |
| 356 | 356 | } |
| 357 | 357 | else |
@@ -373,36 +373,36 @@ discard block |
||
| 373 | 373 | $editor_sequence = Context::get('editor_sequence'); |
| 374 | 374 | $file_srl = Context::get('file_srl'); |
| 375 | 375 | $file_srls = Context::get('file_srls'); |
| 376 | - if($file_srls) $file_srl = $file_srls; |
|
| 376 | + if ($file_srls) $file_srl = $file_srls; |
|
| 377 | 377 | // Exit a session if there is neither upload permission nor information |
| 378 | - if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
| 378 | + if (!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
| 379 | 379 | |
| 380 | 380 | $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
| 381 | 381 | |
| 382 | 382 | $logged_info = Context::get('logged_info'); |
| 383 | 383 | $oFileModel = getModel('file'); |
| 384 | 384 | |
| 385 | - $srls = explode(',',$file_srl); |
|
| 386 | - if(!count($srls)) return; |
|
| 385 | + $srls = explode(',', $file_srl); |
|
| 386 | + if (!count($srls)) return; |
|
| 387 | 387 | |
| 388 | - for($i=0;$i<count($srls);$i++) |
|
| 388 | + for ($i = 0; $i < count($srls); $i++) |
|
| 389 | 389 | { |
| 390 | - $srl = (int)$srls[$i]; |
|
| 391 | - if(!$srl) continue; |
|
| 390 | + $srl = (int) $srls[$i]; |
|
| 391 | + if (!$srl) continue; |
|
| 392 | 392 | |
| 393 | 393 | $args = new stdClass; |
| 394 | 394 | $args->file_srl = $srl; |
| 395 | 395 | $output = executeQuery('file.getFile', $args); |
| 396 | - if(!$output->toBool()) continue; |
|
| 396 | + if (!$output->toBool()) continue; |
|
| 397 | 397 | |
| 398 | 398 | $file_info = $output->data; |
| 399 | - if(!$file_info) continue; |
|
| 399 | + if (!$file_info) continue; |
|
| 400 | 400 | |
| 401 | 401 | $file_grant = $oFileModel->getFileGrant($file_info, $logged_info); |
| 402 | 402 | |
| 403 | - if(!$file_grant->is_deletable) continue; |
|
| 403 | + if (!$file_grant->is_deletable) continue; |
|
| 404 | 404 | |
| 405 | - if($upload_target_srl && $file_srl) $output = $this->deleteFile($file_srl); |
|
| 405 | + if ($upload_target_srl && $file_srl) $output = $this->deleteFile($file_srl); |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
@@ -413,23 +413,23 @@ discard block |
||
| 413 | 413 | */ |
| 414 | 414 | function procFileGetList() |
| 415 | 415 | { |
| 416 | - if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted'); |
|
| 416 | + if (!Context::get('is_logged')) return new Object(-1, 'msg_not_permitted'); |
|
| 417 | 417 | $fileSrls = Context::get('file_srls'); |
| 418 | - if($fileSrls) $fileSrlList = explode(',', $fileSrls); |
|
| 418 | + if ($fileSrls) $fileSrlList = explode(',', $fileSrls); |
|
| 419 | 419 | |
| 420 | 420 | global $lang; |
| 421 | - if(count($fileSrlList) > 0) |
|
| 421 | + if (count($fileSrlList) > 0) |
|
| 422 | 422 | { |
| 423 | 423 | $oFileModel = getModel('file'); |
| 424 | 424 | $fileList = $oFileModel->getFile($fileSrlList); |
| 425 | - if(!is_array($fileList)) $fileList = array($fileList); |
|
| 425 | + if (!is_array($fileList)) $fileList = array($fileList); |
|
| 426 | 426 | |
| 427 | - if(is_array($fileList)) |
|
| 427 | + if (is_array($fileList)) |
|
| 428 | 428 | { |
| 429 | - foreach($fileList AS $key=>$value) |
|
| 429 | + foreach ($fileList AS $key=>$value) |
|
| 430 | 430 | { |
| 431 | 431 | $value->human_file_size = FileHandler::filesize($value->file_size); |
| 432 | - if($value->isvalid=='Y') $value->validName = $lang->is_valid; |
|
| 432 | + if ($value->isvalid == 'Y') $value->validName = $lang->is_valid; |
|
| 433 | 433 | else $value->validName = $lang->is_stand_by; |
| 434 | 434 | } |
| 435 | 435 | } |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | function triggerCheckAttached(&$obj) |
| 452 | 452 | { |
| 453 | 453 | $document_srl = $obj->document_srl; |
| 454 | - if(!$document_srl) return new Object(); |
|
| 454 | + if (!$document_srl) return new Object(); |
|
| 455 | 455 | // Get numbers of attachments |
| 456 | 456 | $oFileModel = getModel('file'); |
| 457 | 457 | $obj->uploaded_count = $oFileModel->getFilesCount($document_srl); |
@@ -468,10 +468,10 @@ discard block |
||
| 468 | 468 | function triggerAttachFiles(&$obj) |
| 469 | 469 | { |
| 470 | 470 | $document_srl = $obj->document_srl; |
| 471 | - if(!$document_srl) return new Object(); |
|
| 471 | + if (!$document_srl) return new Object(); |
|
| 472 | 472 | |
| 473 | 473 | $output = $this->setFilesValid($document_srl); |
| 474 | - if(!$output->toBool()) return $output; |
|
| 474 | + if (!$output->toBool()) return $output; |
|
| 475 | 475 | |
| 476 | 476 | return new Object(); |
| 477 | 477 | } |
@@ -485,7 +485,7 @@ discard block |
||
| 485 | 485 | function triggerDeleteAttached(&$obj) |
| 486 | 486 | { |
| 487 | 487 | $document_srl = $obj->document_srl; |
| 488 | - if(!$document_srl) return new Object(); |
|
| 488 | + if (!$document_srl) return new Object(); |
|
| 489 | 489 | |
| 490 | 490 | $output = $this->deleteFiles($document_srl); |
| 491 | 491 | return $output; |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | function triggerCommentCheckAttached(&$obj) |
| 501 | 501 | { |
| 502 | 502 | $comment_srl = $obj->comment_srl; |
| 503 | - if(!$comment_srl) return new Object(); |
|
| 503 | + if (!$comment_srl) return new Object(); |
|
| 504 | 504 | // Get numbers of attachments |
| 505 | 505 | $oFileModel = getModel('file'); |
| 506 | 506 | $obj->uploaded_count = $oFileModel->getFilesCount($comment_srl); |
@@ -518,10 +518,10 @@ discard block |
||
| 518 | 518 | { |
| 519 | 519 | $comment_srl = $obj->comment_srl; |
| 520 | 520 | $uploaded_count = $obj->uploaded_count; |
| 521 | - if(!$comment_srl || !$uploaded_count) return new Object(); |
|
| 521 | + if (!$comment_srl || !$uploaded_count) return new Object(); |
|
| 522 | 522 | |
| 523 | 523 | $output = $this->setFilesValid($comment_srl); |
| 524 | - if(!$output->toBool()) return $output; |
|
| 524 | + if (!$output->toBool()) return $output; |
|
| 525 | 525 | |
| 526 | 526 | return new Object(); |
| 527 | 527 | } |
@@ -535,9 +535,9 @@ discard block |
||
| 535 | 535 | function triggerCommentDeleteAttached(&$obj) |
| 536 | 536 | { |
| 537 | 537 | $comment_srl = $obj->comment_srl; |
| 538 | - if(!$comment_srl) return new Object(); |
|
| 538 | + if (!$comment_srl) return new Object(); |
|
| 539 | 539 | |
| 540 | - if($obj->isMoveToTrash) return new Object(); |
|
| 540 | + if ($obj->isMoveToTrash) return new Object(); |
|
| 541 | 541 | |
| 542 | 542 | $output = $this->deleteFiles($comment_srl); |
| 543 | 543 | return $output; |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | function triggerDeleteModuleFiles(&$obj) |
| 553 | 553 | { |
| 554 | 554 | $module_srl = $obj->module_srl; |
| 555 | - if(!$module_srl) return new Object(); |
|
| 555 | + if (!$module_srl) return new Object(); |
|
| 556 | 556 | |
| 557 | 557 | $oFileController = getAdminController('file'); |
| 558 | 558 | return $oFileController->deleteModuleFiles($module_srl); |
@@ -565,9 +565,9 @@ discard block |
||
| 565 | 565 | * @param int $upload_target_srl |
| 566 | 566 | * @return void |
| 567 | 567 | */ |
| 568 | - function setUploadInfo($editor_sequence, $upload_target_srl=0) |
|
| 568 | + function setUploadInfo($editor_sequence, $upload_target_srl = 0) |
|
| 569 | 569 | { |
| 570 | - if(!isset($_SESSION['upload_info'][$editor_sequence])) |
|
| 570 | + if (!isset($_SESSION['upload_info'][$editor_sequence])) |
|
| 571 | 571 | { |
| 572 | 572 | $_SESSION['upload_info'][$editor_sequence] = new stdClass(); |
| 573 | 573 | } |
@@ -627,36 +627,36 @@ discard block |
||
| 627 | 627 | $trigger_obj->module_srl = $module_srl; |
| 628 | 628 | $trigger_obj->upload_target_srl = $upload_target_srl; |
| 629 | 629 | $output = ModuleHandler::triggerCall('file.insertFile', 'before', $trigger_obj); |
| 630 | - if(!$output->toBool()) return $output; |
|
| 630 | + if (!$output->toBool()) return $output; |
|
| 631 | 631 | |
| 632 | 632 | // A workaround for Firefox upload bug |
| 633 | - if(preg_match('/^=\?UTF-8\?B\?(.+)\?=$/i', $file_info['name'], $match)) |
|
| 633 | + if (preg_match('/^=\?UTF-8\?B\?(.+)\?=$/i', $file_info['name'], $match)) |
|
| 634 | 634 | { |
| 635 | 635 | $file_info['name'] = base64_decode(strtr($match[1], ':', '/')); |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - if(!$manual_insert) |
|
| 638 | + if (!$manual_insert) |
|
| 639 | 639 | { |
| 640 | 640 | // Get the file configurations |
| 641 | 641 | $logged_info = Context::get('logged_info'); |
| 642 | - if($logged_info->is_admin != 'Y') |
|
| 642 | + if ($logged_info->is_admin != 'Y') |
|
| 643 | 643 | { |
| 644 | 644 | $oFileModel = getModel('file'); |
| 645 | 645 | $config = $oFileModel->getFileConfig($module_srl); |
| 646 | 646 | |
| 647 | 647 | // check file type |
| 648 | - if(isset($config->allowed_filetypes) && $config->allowed_filetypes !== '*.*') |
|
| 648 | + if (isset($config->allowed_filetypes) && $config->allowed_filetypes !== '*.*') |
|
| 649 | 649 | { |
| 650 | 650 | $filetypes = explode(';', $config->allowed_filetypes); |
| 651 | 651 | $ext = array(); |
| 652 | - foreach($filetypes as $item) { |
|
| 652 | + foreach ($filetypes as $item) { |
|
| 653 | 653 | $item = explode('.', $item); |
| 654 | 654 | $ext[] = strtolower($item[1]); |
| 655 | 655 | } |
| 656 | 656 | $uploaded_ext = explode('.', $file_info['name']); |
| 657 | 657 | $uploaded_ext = strtolower(array_pop($uploaded_ext)); |
| 658 | 658 | |
| 659 | - if(!in_array($uploaded_ext, $ext)) |
|
| 659 | + if (!in_array($uploaded_ext, $ext)) |
|
| 660 | 660 | { |
| 661 | 661 | return $this->stop('msg_not_allowed_filetype'); |
| 662 | 662 | } |
@@ -665,63 +665,63 @@ discard block |
||
| 665 | 665 | $allowed_filesize = $config->allowed_filesize * 1024 * 1024; |
| 666 | 666 | $allowed_attach_size = $config->allowed_attach_size * 1024 * 1024; |
| 667 | 667 | // An error appears if file size exceeds a limit |
| 668 | - if($allowed_filesize < filesize($file_info['tmp_name'])) return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 668 | + if ($allowed_filesize < filesize($file_info['tmp_name'])) return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 669 | 669 | // Get total file size of all attachements (from DB) |
| 670 | 670 | $size_args = new stdClass; |
| 671 | 671 | $size_args->upload_target_srl = $upload_target_srl; |
| 672 | 672 | $output = executeQuery('file.getAttachedFileSize', $size_args); |
| 673 | - $attached_size = (int)$output->data->attached_size + filesize($file_info['tmp_name']); |
|
| 674 | - if($attached_size > $allowed_attach_size) return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 673 | + $attached_size = (int) $output->data->attached_size + filesize($file_info['tmp_name']); |
|
| 674 | + if ($attached_size > $allowed_attach_size) return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | // https://github.com/xpressengine/xe-core/issues/1713 |
| 679 | - $file_info['name'] = preg_replace('/\.(php|phtm|phar|html?|cgi|pl|exe|jsp|asp|inc)/i', '$0-x',$file_info['name']); |
|
| 679 | + $file_info['name'] = preg_replace('/\.(php|phtm|phar|html?|cgi|pl|exe|jsp|asp|inc)/i', '$0-x', $file_info['name']); |
|
| 680 | 680 | $file_info['name'] = removeHackTag($file_info['name']); |
| 681 | - $file_info['name'] = str_replace(array('<','>'),array('%3C','%3E'),$file_info['name']); |
|
| 681 | + $file_info['name'] = str_replace(array('<', '>'), array('%3C', '%3E'), $file_info['name']); |
|
| 682 | 682 | |
| 683 | 683 | // Get random number generator |
| 684 | 684 | $random = new Password(); |
| 685 | 685 | |
| 686 | 686 | // Set upload path by checking if the attachement is an image or other kinds of file |
| 687 | - if(preg_match("/\.(jpe?g|gif|png|wm[va]|mpe?g|avi|swf|flv|mp[1-4]|as[fx]|wav|midi?|moo?v|qt|r[am]{1,2}|m4v)$/i", $file_info['name'])) |
|
| 687 | + if (preg_match("/\.(jpe?g|gif|png|wm[va]|mpe?g|avi|swf|flv|mp[1-4]|as[fx]|wav|midi?|moo?v|qt|r[am]{1,2}|m4v)$/i", $file_info['name'])) |
|
| 688 | 688 | { |
| 689 | - $path = sprintf("./files/attach/images/%s/%s", $module_srl,getNumberingPath($upload_target_srl,3)); |
|
| 689 | + $path = sprintf("./files/attach/images/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3)); |
|
| 690 | 690 | |
| 691 | 691 | // special character to '_' |
| 692 | 692 | // change to random file name. because window php bug. window php is not recognize unicode character file name - by cherryfilter |
| 693 | - $ext = substr(strrchr($file_info['name'],'.'),1); |
|
| 693 | + $ext = substr(strrchr($file_info['name'], '.'), 1); |
|
| 694 | 694 | //$_filename = preg_replace('/[#$&*?+%"\']/', '_', $file_info['name']); |
| 695 | 695 | $_filename = $random->createSecureSalt(32, 'hex').'.'.$ext; |
| 696 | 696 | $filename = $path.$_filename; |
| 697 | 697 | $idx = 1; |
| 698 | - while(file_exists($filename)) |
|
| 698 | + while (file_exists($filename)) |
|
| 699 | 699 | { |
| 700 | - $filename = $path.preg_replace('/\.([a-z0-9]+)$/i','_'.$idx.'.$1',$_filename); |
|
| 700 | + $filename = $path.preg_replace('/\.([a-z0-9]+)$/i', '_'.$idx.'.$1', $_filename); |
|
| 701 | 701 | $idx++; |
| 702 | 702 | } |
| 703 | 703 | $direct_download = 'Y'; |
| 704 | 704 | } |
| 705 | 705 | else |
| 706 | 706 | { |
| 707 | - $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl,3)); |
|
| 707 | + $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3)); |
|
| 708 | 708 | $filename = $path.$random->createSecureSalt(32, 'hex'); |
| 709 | 709 | $direct_download = 'N'; |
| 710 | 710 | } |
| 711 | 711 | // Create a directory |
| 712 | - if(!FileHandler::makeDir($path)) return new Object(-1,'msg_not_permitted_create'); |
|
| 712 | + if (!FileHandler::makeDir($path)) return new Object(-1, 'msg_not_permitted_create'); |
|
| 713 | 713 | |
| 714 | 714 | // Check uploaded file |
| 715 | - if(!checkUploadedFile($file_info['tmp_name'])) return new Object(-1,'msg_file_upload_error'); |
|
| 715 | + if (!checkUploadedFile($file_info['tmp_name'])) return new Object(-1, 'msg_file_upload_error'); |
|
| 716 | 716 | |
| 717 | 717 | // Get random number generator |
| 718 | 718 | $random = new Password(); |
| 719 | 719 | |
| 720 | 720 | // Move the file |
| 721 | - if($manual_insert) |
|
| 721 | + if ($manual_insert) |
|
| 722 | 722 | { |
| 723 | 723 | @copy($file_info['tmp_name'], $filename); |
| 724 | - if(!file_exists($filename)) |
|
| 724 | + if (!file_exists($filename)) |
|
| 725 | 725 | { |
| 726 | 726 | $filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
| 727 | 727 | @copy($file_info['tmp_name'], $filename); |
@@ -729,10 +729,10 @@ discard block |
||
| 729 | 729 | } |
| 730 | 730 | else |
| 731 | 731 | { |
| 732 | - if(!@move_uploaded_file($file_info['tmp_name'], $filename)) |
|
| 732 | + if (!@move_uploaded_file($file_info['tmp_name'], $filename)) |
|
| 733 | 733 | { |
| 734 | 734 | $filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
| 735 | - if(!@move_uploaded_file($file_info['tmp_name'], $filename)) return new Object(-1,'msg_file_upload_error'); |
|
| 735 | + if (!@move_uploaded_file($file_info['tmp_name'], $filename)) return new Object(-1, 'msg_file_upload_error'); |
|
| 736 | 736 | } |
| 737 | 737 | } |
| 738 | 738 | // Get member information |
@@ -753,10 +753,10 @@ discard block |
||
| 753 | 753 | $args->sid = $random->createSecureSalt(32, 'hex'); |
| 754 | 754 | |
| 755 | 755 | $output = executeQuery('file.insertFile', $args); |
| 756 | - if(!$output->toBool()) return $output; |
|
| 756 | + if (!$output->toBool()) return $output; |
|
| 757 | 757 | // Call a trigger (after) |
| 758 | 758 | $trigger_output = ModuleHandler::triggerCall('file.insertFile', 'after', $args); |
| 759 | - if(!$trigger_output->toBool()) return $trigger_output; |
|
| 759 | + if (!$trigger_output->toBool()) return $trigger_output; |
|
| 760 | 760 | |
| 761 | 761 | $_SESSION['__XE_UPLOADING_FILES_INFO__'][$args->file_srl] = true; |
| 762 | 762 | |
@@ -799,18 +799,18 @@ discard block |
||
| 799 | 799 | */ |
| 800 | 800 | function deleteFile($file_srl) |
| 801 | 801 | { |
| 802 | - if(!$file_srl) return; |
|
| 802 | + if (!$file_srl) return; |
|
| 803 | 803 | |
| 804 | 804 | $srls = (is_array($file_srl)) ? $file_srl : explode(',', $file_srl); |
| 805 | - if(!count($srls)) return; |
|
| 805 | + if (!count($srls)) return; |
|
| 806 | 806 | |
| 807 | 807 | $oDocumentController = getController('document'); |
| 808 | 808 | $documentSrlList = array(); |
| 809 | 809 | |
| 810 | - foreach($srls as $srl) |
|
| 810 | + foreach ($srls as $srl) |
|
| 811 | 811 | { |
| 812 | - $srl = (int)$srl; |
|
| 813 | - if(!$srl) |
|
| 812 | + $srl = (int) $srl; |
|
| 813 | + if (!$srl) |
|
| 814 | 814 | { |
| 815 | 815 | continue; |
| 816 | 816 | } |
@@ -819,14 +819,14 @@ discard block |
||
| 819 | 819 | $args->file_srl = $srl; |
| 820 | 820 | $output = executeQuery('file.getFile', $args); |
| 821 | 821 | |
| 822 | - if(!$output->toBool() || !$output->data) |
|
| 822 | + if (!$output->toBool() || !$output->data) |
|
| 823 | 823 | { |
| 824 | 824 | continue; |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | $file_info = $output->data; |
| 828 | 828 | |
| 829 | - if($file_info->upload_target_srl) |
|
| 829 | + if ($file_info->upload_target_srl) |
|
| 830 | 830 | { |
| 831 | 831 | $documentSrlList[] = $file_info->upload_target_srl; |
| 832 | 832 | } |
@@ -837,15 +837,15 @@ discard block |
||
| 837 | 837 | // Call a trigger (before) |
| 838 | 838 | $trigger_obj = $output->data; |
| 839 | 839 | $output = ModuleHandler::triggerCall('file.deleteFile', 'before', $trigger_obj); |
| 840 | - if(!$output->toBool()) return $output; |
|
| 840 | + if (!$output->toBool()) return $output; |
|
| 841 | 841 | |
| 842 | 842 | // Remove from the DB |
| 843 | 843 | $output = executeQuery('file.deleteFile', $args); |
| 844 | - if(!$output->toBool()) return $output; |
|
| 844 | + if (!$output->toBool()) return $output; |
|
| 845 | 845 | |
| 846 | 846 | // Call a trigger (after) |
| 847 | 847 | $trigger_output = ModuleHandler::triggerCall('file.deleteFile', 'after', $trigger_obj); |
| 848 | - if(!$trigger_output->toBool()) return $trigger_output; |
|
| 848 | + if (!$trigger_output->toBool()) return $trigger_output; |
|
| 849 | 849 | |
| 850 | 850 | // If successfully deleted, remove the file |
| 851 | 851 | FileHandler::removeFile($uploaded_filename); |
@@ -869,28 +869,28 @@ discard block |
||
| 869 | 869 | $columnList = array('file_srl', 'uploaded_filename', 'module_srl'); |
| 870 | 870 | $file_list = $oFileModel->getFiles($upload_target_srl, $columnList); |
| 871 | 871 | // Success returned if no attachement exists |
| 872 | - if(!is_array($file_list)||!count($file_list)) return new Object(); |
|
| 872 | + if (!is_array($file_list) || !count($file_list)) return new Object(); |
|
| 873 | 873 | |
| 874 | 874 | // Delete the file |
| 875 | 875 | $path = array(); |
| 876 | 876 | $file_count = count($file_list); |
| 877 | - for($i=0;$i<$file_count;$i++) |
|
| 877 | + for ($i = 0; $i < $file_count; $i++) |
|
| 878 | 878 | { |
| 879 | 879 | $this->deleteFile($file_list[$i]->file_srl); |
| 880 | 880 | |
| 881 | 881 | $uploaded_filename = $file_list[$i]->uploaded_filename; |
| 882 | 882 | $path_info = pathinfo($uploaded_filename); |
| 883 | - if(!in_array($path_info['dirname'], $path)) $path[] = $path_info['dirname']; |
|
| 883 | + if (!in_array($path_info['dirname'], $path)) $path[] = $path_info['dirname']; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | // Remove from the DB |
| 887 | 887 | $args = new stdClass(); |
| 888 | 888 | $args->upload_target_srl = $upload_target_srl; |
| 889 | 889 | $output = executeQuery('file.deleteFiles', $args); |
| 890 | - if(!$output->toBool()) return $output; |
|
| 890 | + if (!$output->toBool()) return $output; |
|
| 891 | 891 | |
| 892 | 892 | // Remove a file directory of the document |
| 893 | - for($i=0, $c=count($path); $i<$c; $i++) |
|
| 893 | + for ($i = 0, $c = count($path); $i < $c; $i++) |
|
| 894 | 894 | { |
| 895 | 895 | FileHandler::removeBlankDir($path[$i]); |
| 896 | 896 | } |
@@ -908,23 +908,23 @@ discard block |
||
| 908 | 908 | */ |
| 909 | 909 | function moveFile($source_srl, $target_module_srl, $target_srl) |
| 910 | 910 | { |
| 911 | - if($source_srl == $target_srl) return; |
|
| 911 | + if ($source_srl == $target_srl) return; |
|
| 912 | 912 | |
| 913 | 913 | $oFileModel = getModel('file'); |
| 914 | 914 | $file_list = $oFileModel->getFiles($source_srl); |
| 915 | - if(!$file_list) return; |
|
| 915 | + if (!$file_list) return; |
|
| 916 | 916 | |
| 917 | 917 | $file_count = count($file_list); |
| 918 | 918 | |
| 919 | - for($i=0;$i<$file_count;$i++) |
|
| 919 | + for ($i = 0; $i < $file_count; $i++) |
|
| 920 | 920 | { |
| 921 | 921 | unset($file_info); |
| 922 | 922 | $file_info = $file_list[$i]; |
| 923 | 923 | $old_file = $file_info->uploaded_filename; |
| 924 | 924 | // Determine the file path by checking if the file is an image or other kinds |
| 925 | - if(preg_match("/\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp1|mp2|mp3|mp4|asf|wav|asx|mid|midi|asf|mov|moov|qt|rm|ram|ra|rmm|m4v)$/i", $file_info->source_filename)) |
|
| 925 | + if (preg_match("/\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp1|mp2|mp3|mp4|asf|wav|asx|mid|midi|asf|mov|moov|qt|rm|ram|ra|rmm|m4v)$/i", $file_info->source_filename)) |
|
| 926 | 926 | { |
| 927 | - $path = sprintf("./files/attach/images/%s/%s/", $target_module_srl,$target_srl); |
|
| 927 | + $path = sprintf("./files/attach/images/%s/%s/", $target_module_srl, $target_srl); |
|
| 928 | 928 | $new_file = $path.$file_info->source_filename; |
| 929 | 929 | } |
| 930 | 930 | else |
@@ -934,7 +934,7 @@ discard block |
||
| 934 | 934 | $new_file = $path.$random->createSecureSalt(32, 'hex'); |
| 935 | 935 | } |
| 936 | 936 | // Pass if a target document to move is same |
| 937 | - if($old_file == $new_file) continue; |
|
| 937 | + if ($old_file == $new_file) continue; |
|
| 938 | 938 | // Create a directory |
| 939 | 939 | FileHandler::makeDir($path); |
| 940 | 940 | // Move the file |
@@ -954,18 +954,18 @@ discard block |
||
| 954 | 954 | $vars = Context::getRequestVars(); |
| 955 | 955 | $logged_info = Context::get('logged_info'); |
| 956 | 956 | |
| 957 | - if(!$vars->editor_sequence) return new Object(-1, 'msg_invalid_request'); |
|
| 957 | + if (!$vars->editor_sequence) return new Object(-1, 'msg_invalid_request'); |
|
| 958 | 958 | |
| 959 | 959 | $upload_target_srl = $_SESSION['upload_info'][$vars->editor_sequence]->upload_target_srl; |
| 960 | 960 | |
| 961 | 961 | $oFileModel = getModel('file'); |
| 962 | 962 | $file_info = $oFileModel->getFile($vars->file_srl); |
| 963 | 963 | |
| 964 | - if(!$file_info) return new Object(-1, 'msg_not_founded'); |
|
| 964 | + if (!$file_info) return new Object(-1, 'msg_not_founded'); |
|
| 965 | 965 | |
| 966 | - if(!$this->manager && !$file_info->member_srl === $logged_info->member_srl) return new Object(-1, 'msg_not_permitted'); |
|
| 966 | + if (!$this->manager && !$file_info->member_srl === $logged_info->member_srl) return new Object(-1, 'msg_not_permitted'); |
|
| 967 | 967 | |
| 968 | - $args = new stdClass(); |
|
| 968 | + $args = new stdClass(); |
|
| 969 | 969 | $args->file_srl = $vars->file_srl; |
| 970 | 970 | $args->upload_target_srl = $upload_target_srl; |
| 971 | 971 | |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | |
| 975 | 975 | $args->cover_image = 'N'; |
| 976 | 976 | $output = executeQuery('file.updateClearCoverImage', $args); |
| 977 | - if(!$output->toBool()) |
|
| 977 | + if (!$output->toBool()) |
|
| 978 | 978 | { |
| 979 | 979 | $oDB->rollback(); |
| 980 | 980 | return $output; |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | |
| 983 | 983 | $args->cover_image = 'Y'; |
| 984 | 984 | $output = executeQuery('file.updateCoverImage', $args); |
| 985 | - if(!$output->toBool()) |
|
| 985 | + if (!$output->toBool()) |
|
| 986 | 986 | { |
| 987 | 987 | $oDB->rollback(); |
| 988 | 988 | return $output; |
@@ -1014,9 +1014,9 @@ discard block |
||
| 1014 | 1014 | $fileConfig = $oModuleModel->getModulePartConfig('file', $obj->originModuleSrl); |
| 1015 | 1015 | |
| 1016 | 1016 | $oModuleController = getController('module'); |
| 1017 | - if(is_array($obj->moduleSrlList)) |
|
| 1017 | + if (is_array($obj->moduleSrlList)) |
|
| 1018 | 1018 | { |
| 1019 | - foreach($obj->moduleSrlList AS $key=>$moduleSrl) |
|
| 1019 | + foreach ($obj->moduleSrlList AS $key=>$moduleSrl) |
|
| 1020 | 1020 | { |
| 1021 | 1021 | $oModuleController->insertModulePartConfig('file', $moduleSrl, $fileConfig); |
| 1022 | 1022 | } |
@@ -29,24 +29,36 @@ 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'); |
| 49 | - if($output->error != '0') $this->stop($output->message); |
|
| 59 | + if($output->error != '0') { |
|
| 60 | + $this->stop($output->message); |
|
| 61 | + } |
|
| 50 | 62 | } |
| 51 | 63 | |
| 52 | 64 | /** |
@@ -61,17 +73,27 @@ discard block |
||
| 61 | 73 | $callback = Context::get('callback'); |
| 62 | 74 | $module_srl = $this->module_srl; |
| 63 | 75 | $upload_target_srl = intval(Context::get('uploadTargetSrl')); |
| 64 | - if(!$upload_target_srl) $upload_target_srl = intval(Context::get('upload_target_srl')); |
|
| 76 | + if(!$upload_target_srl) { |
|
| 77 | + $upload_target_srl = intval(Context::get('upload_target_srl')); |
|
| 78 | + } |
|
| 65 | 79 | |
| 66 | 80 | // Exit a session if there is neither upload permission nor information |
| 67 | - if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
| 81 | + if(!$_SESSION['upload_info'][$editor_sequence]->enabled) { |
|
| 82 | + exit(); |
|
| 83 | + } |
|
| 68 | 84 | // Extract from session information if upload_target_srl is not specified |
| 69 | - if(!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
|
| 85 | + if(!$upload_target_srl) { |
|
| 86 | + $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
|
| 87 | + } |
|
| 70 | 88 | // Create if upload_target_srl is not defined in the session information |
| 71 | - if(!$upload_target_srl) $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
|
| 89 | + if(!$upload_target_srl) { |
|
| 90 | + $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
|
| 91 | + } |
|
| 72 | 92 | // Delete and then attempt to re-upload if file_srl is requested |
| 73 | 93 | $file_srl = Context::get('file_srl'); |
| 74 | - if($file_srl) $this->deleteFile($file_srl); |
|
| 94 | + if($file_srl) { |
|
| 95 | + $this->deleteFile($file_srl); |
|
| 96 | + } |
|
| 75 | 97 | |
| 76 | 98 | $file_info = Context::get('Filedata'); |
| 77 | 99 | // An error appears if not a normally uploaded file |
@@ -112,15 +134,16 @@ discard block |
||
| 112 | 134 | $source_src = $fileInfo->uploaded_filename; |
| 113 | 135 | $output_src = $source_src . '.resized' . strrchr($source_src,'.'); |
| 114 | 136 | |
| 115 | - if(!$height) $height = $width-1; |
|
| 137 | + if(!$height) { |
|
| 138 | + $height = $width-1; |
|
| 139 | + } |
|
| 116 | 140 | |
| 117 | 141 | if(FileHandler::createImageFile($source_src,$output_src,$width,$height,'','ratio')) |
| 118 | 142 | { |
| 119 | 143 | $output = new stdClass(); |
| 120 | 144 | $output->info = getimagesize($output_src); |
| 121 | 145 | $output->src = $output_src; |
| 122 | - } |
|
| 123 | - else |
|
| 146 | + } else |
|
| 124 | 147 | { |
| 125 | 148 | return new Object(-1,'msg_invalid_request'); |
| 126 | 149 | } |
@@ -163,7 +186,9 @@ discard block |
||
| 163 | 186 | { |
| 164 | 187 | $oFileModel = getModel('file'); |
| 165 | 188 | |
| 166 | - if(isset($this->grant->access) && $this->grant->access !== true) return new Object(-1, 'msg_not_permitted'); |
|
| 189 | + if(isset($this->grant->access) && $this->grant->access !== true) { |
|
| 190 | + return new Object(-1, 'msg_not_permitted'); |
|
| 191 | + } |
|
| 167 | 192 | |
| 168 | 193 | $file_srl = Context::get('file_srl'); |
| 169 | 194 | $sid = Context::get('sid'); |
@@ -172,9 +197,13 @@ discard block |
||
| 172 | 197 | $columnList = array('file_srl', 'sid', 'isvalid', 'source_filename', 'module_srl', 'uploaded_filename', 'file_size', 'member_srl', 'upload_target_srl', 'upload_target_type'); |
| 173 | 198 | $file_obj = $oFileModel->getFile($file_srl, $columnList); |
| 174 | 199 | // If the requested file information is incorrect, an error that file cannot be found appears |
| 175 | - if($file_obj->file_srl!=$file_srl || $file_obj->sid!=$sid) return $this->stop('msg_file_not_found'); |
|
| 200 | + if($file_obj->file_srl!=$file_srl || $file_obj->sid!=$sid) { |
|
| 201 | + return $this->stop('msg_file_not_found'); |
|
| 202 | + } |
|
| 176 | 203 | // Notify that file download is not allowed when standing-by(Only a top-administrator is permitted) |
| 177 | - if($logged_info->is_admin != 'Y' && $file_obj->isvalid!='Y') return $this->stop('msg_not_permitted_download'); |
|
| 204 | + if($logged_info->is_admin != 'Y' && $file_obj->isvalid!='Y') { |
|
| 205 | + return $this->stop('msg_not_permitted_download'); |
|
| 206 | + } |
|
| 178 | 207 | // File name |
| 179 | 208 | $filename = $file_obj->source_filename; |
| 180 | 209 | $file_module_config = $oFileModel->getFileModuleConfig($file_obj->module_srl); |
@@ -186,7 +215,9 @@ discard block |
||
| 186 | 215 | { |
| 187 | 216 | $allow_outlink_format_array = array(); |
| 188 | 217 | $allow_outlink_format_array = explode(',', $file_module_config->allow_outlink_format); |
| 189 | - if(!is_array($allow_outlink_format_array)) $allow_outlink_format_array[0] = $file_module_config->allow_outlink_format; |
|
| 218 | + if(!is_array($allow_outlink_format_array)) { |
|
| 219 | + $allow_outlink_format_array[0] = $file_module_config->allow_outlink_format; |
|
| 220 | + } |
|
| 190 | 221 | |
| 191 | 222 | foreach($allow_outlink_format_array as $val) |
| 192 | 223 | { |
@@ -208,7 +239,9 @@ discard block |
||
| 208 | 239 | { |
| 209 | 240 | $allow_outlink_site_array = array(); |
| 210 | 241 | $allow_outlink_site_array = explode("\n", $file_module_config->allow_outlink_site); |
| 211 | - if(!is_array($allow_outlink_site_array)) $allow_outlink_site_array[0] = $file_module_config->allow_outlink_site; |
|
| 242 | + if(!is_array($allow_outlink_site_array)) { |
|
| 243 | + $allow_outlink_site_array[0] = $file_module_config->allow_outlink_site; |
|
| 244 | + } |
|
| 212 | 245 | |
| 213 | 246 | foreach($allow_outlink_site_array as $val) |
| 214 | 247 | { |
@@ -220,23 +253,29 @@ discard block |
||
| 220 | 253 | } |
| 221 | 254 | } |
| 222 | 255 | } |
| 256 | + } else { |
|
| 257 | + $file_module_config->allow_outlink = 'Y'; |
|
| 223 | 258 | } |
| 224 | - else $file_module_config->allow_outlink = 'Y'; |
|
| 225 | 259 | } |
| 226 | - if($file_module_config->allow_outlink != 'Y') return $this->stop('msg_not_allowed_outlink'); |
|
| 260 | + if($file_module_config->allow_outlink != 'Y') { |
|
| 261 | + return $this->stop('msg_not_allowed_outlink'); |
|
| 262 | + } |
|
| 227 | 263 | } |
| 228 | 264 | |
| 229 | 265 | // Check if a permission for file download is granted |
| 230 | 266 | $downloadGrantCount = 0; |
| 231 | 267 | if(is_array($file_module_config->download_grant)) |
| 232 | 268 | { |
| 233 | - foreach($file_module_config->download_grant AS $value) |
|
| 234 | - if($value) $downloadGrantCount++; |
|
| 269 | + foreach($file_module_config->download_grant AS $value) { |
|
| 270 | + if($value) $downloadGrantCount++; |
|
| 271 | + } |
|
| 235 | 272 | } |
| 236 | 273 | |
| 237 | 274 | if(is_array($file_module_config->download_grant) && $downloadGrantCount>0) |
| 238 | 275 | { |
| 239 | - if(!Context::get('is_logged')) return $this->stop('msg_not_permitted_download'); |
|
| 276 | + if(!Context::get('is_logged')) { |
|
| 277 | + return $this->stop('msg_not_permitted_download'); |
|
| 278 | + } |
|
| 240 | 279 | $logged_info = Context::get('logged_info'); |
| 241 | 280 | if($logged_info->is_admin != 'Y') |
| 242 | 281 | { |
@@ -259,13 +298,17 @@ discard block |
||
| 259 | 298 | break; |
| 260 | 299 | } |
| 261 | 300 | } |
| 262 | - if(!$is_permitted) return $this->stop('msg_not_permitted_download'); |
|
| 301 | + if(!$is_permitted) { |
|
| 302 | + return $this->stop('msg_not_permitted_download'); |
|
| 303 | + } |
|
| 263 | 304 | } |
| 264 | 305 | } |
| 265 | 306 | } |
| 266 | 307 | // Call a trigger (before) |
| 267 | 308 | $output = ModuleHandler::triggerCall('file.downloadFile', 'before', $file_obj); |
| 268 | - if(!$output->toBool()) return $this->stop(($output->message)?$output->message:'msg_not_permitted_download'); |
|
| 309 | + if(!$output->toBool()) { |
|
| 310 | + return $this->stop(($output->message)?$output->message:'msg_not_permitted_download'); |
|
| 311 | + } |
|
| 269 | 312 | |
| 270 | 313 | |
| 271 | 314 | // 다운로드 후 (가상) |
@@ -289,16 +332,23 @@ discard block |
||
| 289 | 332 | $oFileModel = getModel('file'); |
| 290 | 333 | $file_srl = Context::get('file_srl'); |
| 291 | 334 | $file_key = Context::get('file_key'); |
| 292 | - if(strstr($_SERVER['HTTP_USER_AGENT'], "Android")) $is_android = true; |
|
| 335 | + if(strstr($_SERVER['HTTP_USER_AGENT'], "Android")) { |
|
| 336 | + $is_android = true; |
|
| 337 | + } |
|
| 293 | 338 | |
| 294 | - if($is_android && $_SESSION['__XE_FILE_KEY_AND__'][$file_srl]) $session_key = '__XE_FILE_KEY_AND__'; |
|
| 295 | - else $session_key = '__XE_FILE_KEY__'; |
|
| 339 | + if($is_android && $_SESSION['__XE_FILE_KEY_AND__'][$file_srl]) { |
|
| 340 | + $session_key = '__XE_FILE_KEY_AND__'; |
|
| 341 | + } else { |
|
| 342 | + $session_key = '__XE_FILE_KEY__'; |
|
| 343 | + } |
|
| 296 | 344 | $columnList = array('source_filename', 'uploaded_filename', 'file_size'); |
| 297 | 345 | $file_obj = $oFileModel->getFile($file_srl, $columnList); |
| 298 | 346 | |
| 299 | 347 | $uploaded_filename = $file_obj->uploaded_filename; |
| 300 | 348 | |
| 301 | - if(!file_exists($uploaded_filename)) return $this->stop('msg_file_not_found'); |
|
| 349 | + if(!file_exists($uploaded_filename)) { |
|
| 350 | + return $this->stop('msg_file_not_found'); |
|
| 351 | + } |
|
| 302 | 352 | |
| 303 | 353 | if(!$file_key || $_SESSION[$session_key][$file_srl] != $file_key) |
| 304 | 354 | { |
@@ -311,8 +361,7 @@ discard block |
||
| 311 | 361 | if(preg_match('#(?:Chrome|Edge)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 11) |
| 312 | 362 | { |
| 313 | 363 | $filename_param = "filename*=UTF-8''" . rawurlencode($filename) . '; filename="' . rawurlencode($filename) . '"'; |
| 314 | - } |
|
| 315 | - elseif(preg_match('#(?:Firefox|Safari|Trident)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 6) |
|
| 364 | + } elseif(preg_match('#(?:Firefox|Safari|Trident)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 6) |
|
| 316 | 365 | { |
| 317 | 366 | $filename_param = "filename*=UTF-8''" . rawurlencode($filename) . '; filename="' . rawurlencode($filename) . '"'; |
| 318 | 367 | } |
@@ -321,15 +370,16 @@ discard block |
||
| 321 | 370 | { |
| 322 | 371 | $filename = rawurlencode($filename); |
| 323 | 372 | $filename_param = 'filename="' . preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1) . '"'; |
| 324 | - } |
|
| 325 | - else |
|
| 373 | + } else |
|
| 326 | 374 | { |
| 327 | 375 | $filename_param = 'filename="' . $filename . '"'; |
| 328 | 376 | } |
| 329 | 377 | |
| 330 | 378 | if($is_android) |
| 331 | 379 | { |
| 332 | - if($_SESSION['__XE_FILE_KEY__'][$file_srl]) $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
|
| 380 | + if($_SESSION['__XE_FILE_KEY__'][$file_srl]) { |
|
| 381 | + $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
|
| 382 | + } |
|
| 333 | 383 | } |
| 334 | 384 | |
| 335 | 385 | unset($_SESSION[$session_key][$file_srl]); |
@@ -337,7 +387,9 @@ discard block |
||
| 337 | 387 | Context::close(); |
| 338 | 388 | |
| 339 | 389 | $fp = fopen($uploaded_filename, 'rb'); |
| 340 | - if(!$fp) return $this->stop('msg_file_not_found'); |
|
| 390 | + if(!$fp) { |
|
| 391 | + return $this->stop('msg_file_not_found'); |
|
| 392 | + } |
|
| 341 | 393 | |
| 342 | 394 | header("Cache-Control: "); |
| 343 | 395 | header("Pragma: "); |
@@ -351,10 +403,11 @@ discard block |
||
| 351 | 403 | // if file size is lager than 10MB, use fread function (#18675748) |
| 352 | 404 | if(filesize($uploaded_filename) > 1024 * 1024) |
| 353 | 405 | { |
| 354 | - while(!feof($fp)) echo fread($fp, 1024); |
|
| 406 | + while(!feof($fp)) { |
|
| 407 | + echo fread($fp, 1024); |
|
| 408 | + } |
|
| 355 | 409 | fclose($fp); |
| 356 | - } |
|
| 357 | - else |
|
| 410 | + } else |
|
| 358 | 411 | { |
| 359 | 412 | fpassthru($fp); |
| 360 | 413 | } |
@@ -373,9 +426,13 @@ discard block |
||
| 373 | 426 | $editor_sequence = Context::get('editor_sequence'); |
| 374 | 427 | $file_srl = Context::get('file_srl'); |
| 375 | 428 | $file_srls = Context::get('file_srls'); |
| 376 | - if($file_srls) $file_srl = $file_srls; |
|
| 429 | + if($file_srls) { |
|
| 430 | + $file_srl = $file_srls; |
|
| 431 | + } |
|
| 377 | 432 | // Exit a session if there is neither upload permission nor information |
| 378 | - if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
| 433 | + if(!$_SESSION['upload_info'][$editor_sequence]->enabled) { |
|
| 434 | + exit(); |
|
| 435 | + } |
|
| 379 | 436 | |
| 380 | 437 | $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
| 381 | 438 | |
@@ -383,26 +440,38 @@ discard block |
||
| 383 | 440 | $oFileModel = getModel('file'); |
| 384 | 441 | |
| 385 | 442 | $srls = explode(',',$file_srl); |
| 386 | - if(!count($srls)) return; |
|
| 443 | + if(!count($srls)) { |
|
| 444 | + return; |
|
| 445 | + } |
|
| 387 | 446 | |
| 388 | 447 | for($i=0;$i<count($srls);$i++) |
| 389 | 448 | { |
| 390 | 449 | $srl = (int)$srls[$i]; |
| 391 | - if(!$srl) continue; |
|
| 450 | + if(!$srl) { |
|
| 451 | + continue; |
|
| 452 | + } |
|
| 392 | 453 | |
| 393 | 454 | $args = new stdClass; |
| 394 | 455 | $args->file_srl = $srl; |
| 395 | 456 | $output = executeQuery('file.getFile', $args); |
| 396 | - if(!$output->toBool()) continue; |
|
| 457 | + if(!$output->toBool()) { |
|
| 458 | + continue; |
|
| 459 | + } |
|
| 397 | 460 | |
| 398 | 461 | $file_info = $output->data; |
| 399 | - if(!$file_info) continue; |
|
| 462 | + if(!$file_info) { |
|
| 463 | + continue; |
|
| 464 | + } |
|
| 400 | 465 | |
| 401 | 466 | $file_grant = $oFileModel->getFileGrant($file_info, $logged_info); |
| 402 | 467 | |
| 403 | - if(!$file_grant->is_deletable) continue; |
|
| 468 | + if(!$file_grant->is_deletable) { |
|
| 469 | + continue; |
|
| 470 | + } |
|
| 404 | 471 | |
| 405 | - if($upload_target_srl && $file_srl) $output = $this->deleteFile($file_srl); |
|
| 472 | + if($upload_target_srl && $file_srl) { |
|
| 473 | + $output = $this->deleteFile($file_srl); |
|
| 474 | + } |
|
| 406 | 475 | } |
| 407 | 476 | } |
| 408 | 477 | |
@@ -413,28 +482,36 @@ discard block |
||
| 413 | 482 | */ |
| 414 | 483 | function procFileGetList() |
| 415 | 484 | { |
| 416 | - if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted'); |
|
| 485 | + if(!Context::get('is_logged')) { |
|
| 486 | + return new Object(-1,'msg_not_permitted'); |
|
| 487 | + } |
|
| 417 | 488 | $fileSrls = Context::get('file_srls'); |
| 418 | - if($fileSrls) $fileSrlList = explode(',', $fileSrls); |
|
| 489 | + if($fileSrls) { |
|
| 490 | + $fileSrlList = explode(',', $fileSrls); |
|
| 491 | + } |
|
| 419 | 492 | |
| 420 | 493 | global $lang; |
| 421 | 494 | if(count($fileSrlList) > 0) |
| 422 | 495 | { |
| 423 | 496 | $oFileModel = getModel('file'); |
| 424 | 497 | $fileList = $oFileModel->getFile($fileSrlList); |
| 425 | - if(!is_array($fileList)) $fileList = array($fileList); |
|
| 498 | + if(!is_array($fileList)) { |
|
| 499 | + $fileList = array($fileList); |
|
| 500 | + } |
|
| 426 | 501 | |
| 427 | 502 | if(is_array($fileList)) |
| 428 | 503 | { |
| 429 | 504 | foreach($fileList AS $key=>$value) |
| 430 | 505 | { |
| 431 | 506 | $value->human_file_size = FileHandler::filesize($value->file_size); |
| 432 | - if($value->isvalid=='Y') $value->validName = $lang->is_valid; |
|
| 433 | - else $value->validName = $lang->is_stand_by; |
|
| 507 | + if($value->isvalid=='Y') { |
|
| 508 | + $value->validName = $lang->is_valid; |
|
| 509 | + } else { |
|
| 510 | + $value->validName = $lang->is_stand_by; |
|
| 511 | + } |
|
| 434 | 512 | } |
| 435 | 513 | } |
| 436 | - } |
|
| 437 | - else |
|
| 514 | + } else |
|
| 438 | 515 | { |
| 439 | 516 | $fileList = array(); |
| 440 | 517 | $this->setMessage($lang->no_files); |
@@ -451,7 +528,9 @@ discard block |
||
| 451 | 528 | function triggerCheckAttached(&$obj) |
| 452 | 529 | { |
| 453 | 530 | $document_srl = $obj->document_srl; |
| 454 | - if(!$document_srl) return new Object(); |
|
| 531 | + if(!$document_srl) { |
|
| 532 | + return new Object(); |
|
| 533 | + } |
|
| 455 | 534 | // Get numbers of attachments |
| 456 | 535 | $oFileModel = getModel('file'); |
| 457 | 536 | $obj->uploaded_count = $oFileModel->getFilesCount($document_srl); |
@@ -468,10 +547,14 @@ discard block |
||
| 468 | 547 | function triggerAttachFiles(&$obj) |
| 469 | 548 | { |
| 470 | 549 | $document_srl = $obj->document_srl; |
| 471 | - if(!$document_srl) return new Object(); |
|
| 550 | + if(!$document_srl) { |
|
| 551 | + return new Object(); |
|
| 552 | + } |
|
| 472 | 553 | |
| 473 | 554 | $output = $this->setFilesValid($document_srl); |
| 474 | - if(!$output->toBool()) return $output; |
|
| 555 | + if(!$output->toBool()) { |
|
| 556 | + return $output; |
|
| 557 | + } |
|
| 475 | 558 | |
| 476 | 559 | return new Object(); |
| 477 | 560 | } |
@@ -485,7 +568,9 @@ discard block |
||
| 485 | 568 | function triggerDeleteAttached(&$obj) |
| 486 | 569 | { |
| 487 | 570 | $document_srl = $obj->document_srl; |
| 488 | - if(!$document_srl) return new Object(); |
|
| 571 | + if(!$document_srl) { |
|
| 572 | + return new Object(); |
|
| 573 | + } |
|
| 489 | 574 | |
| 490 | 575 | $output = $this->deleteFiles($document_srl); |
| 491 | 576 | return $output; |
@@ -500,7 +585,9 @@ discard block |
||
| 500 | 585 | function triggerCommentCheckAttached(&$obj) |
| 501 | 586 | { |
| 502 | 587 | $comment_srl = $obj->comment_srl; |
| 503 | - if(!$comment_srl) return new Object(); |
|
| 588 | + if(!$comment_srl) { |
|
| 589 | + return new Object(); |
|
| 590 | + } |
|
| 504 | 591 | // Get numbers of attachments |
| 505 | 592 | $oFileModel = getModel('file'); |
| 506 | 593 | $obj->uploaded_count = $oFileModel->getFilesCount($comment_srl); |
@@ -518,10 +605,14 @@ discard block |
||
| 518 | 605 | { |
| 519 | 606 | $comment_srl = $obj->comment_srl; |
| 520 | 607 | $uploaded_count = $obj->uploaded_count; |
| 521 | - if(!$comment_srl || !$uploaded_count) return new Object(); |
|
| 608 | + if(!$comment_srl || !$uploaded_count) { |
|
| 609 | + return new Object(); |
|
| 610 | + } |
|
| 522 | 611 | |
| 523 | 612 | $output = $this->setFilesValid($comment_srl); |
| 524 | - if(!$output->toBool()) return $output; |
|
| 613 | + if(!$output->toBool()) { |
|
| 614 | + return $output; |
|
| 615 | + } |
|
| 525 | 616 | |
| 526 | 617 | return new Object(); |
| 527 | 618 | } |
@@ -535,9 +626,13 @@ discard block |
||
| 535 | 626 | function triggerCommentDeleteAttached(&$obj) |
| 536 | 627 | { |
| 537 | 628 | $comment_srl = $obj->comment_srl; |
| 538 | - if(!$comment_srl) return new Object(); |
|
| 629 | + if(!$comment_srl) { |
|
| 630 | + return new Object(); |
|
| 631 | + } |
|
| 539 | 632 | |
| 540 | - if($obj->isMoveToTrash) return new Object(); |
|
| 633 | + if($obj->isMoveToTrash) { |
|
| 634 | + return new Object(); |
|
| 635 | + } |
|
| 541 | 636 | |
| 542 | 637 | $output = $this->deleteFiles($comment_srl); |
| 543 | 638 | return $output; |
@@ -552,7 +647,9 @@ discard block |
||
| 552 | 647 | function triggerDeleteModuleFiles(&$obj) |
| 553 | 648 | { |
| 554 | 649 | $module_srl = $obj->module_srl; |
| 555 | - if(!$module_srl) return new Object(); |
|
| 650 | + if(!$module_srl) { |
|
| 651 | + return new Object(); |
|
| 652 | + } |
|
| 556 | 653 | |
| 557 | 654 | $oFileController = getAdminController('file'); |
| 558 | 655 | return $oFileController->deleteModuleFiles($module_srl); |
@@ -627,7 +724,9 @@ discard block |
||
| 627 | 724 | $trigger_obj->module_srl = $module_srl; |
| 628 | 725 | $trigger_obj->upload_target_srl = $upload_target_srl; |
| 629 | 726 | $output = ModuleHandler::triggerCall('file.insertFile', 'before', $trigger_obj); |
| 630 | - if(!$output->toBool()) return $output; |
|
| 727 | + if(!$output->toBool()) { |
|
| 728 | + return $output; |
|
| 729 | + } |
|
| 631 | 730 | |
| 632 | 731 | // A workaround for Firefox upload bug |
| 633 | 732 | if(preg_match('/^=\?UTF-8\?B\?(.+)\?=$/i', $file_info['name'], $match)) |
@@ -665,13 +764,17 @@ discard block |
||
| 665 | 764 | $allowed_filesize = $config->allowed_filesize * 1024 * 1024; |
| 666 | 765 | $allowed_attach_size = $config->allowed_attach_size * 1024 * 1024; |
| 667 | 766 | // An error appears if file size exceeds a limit |
| 668 | - if($allowed_filesize < filesize($file_info['tmp_name'])) return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 767 | + if($allowed_filesize < filesize($file_info['tmp_name'])) { |
|
| 768 | + return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 769 | + } |
|
| 669 | 770 | // Get total file size of all attachements (from DB) |
| 670 | 771 | $size_args = new stdClass; |
| 671 | 772 | $size_args->upload_target_srl = $upload_target_srl; |
| 672 | 773 | $output = executeQuery('file.getAttachedFileSize', $size_args); |
| 673 | 774 | $attached_size = (int)$output->data->attached_size + filesize($file_info['tmp_name']); |
| 674 | - if($attached_size > $allowed_attach_size) return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 775 | + if($attached_size > $allowed_attach_size) { |
|
| 776 | + return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 777 | + } |
|
| 675 | 778 | } |
| 676 | 779 | } |
| 677 | 780 | |
@@ -701,18 +804,21 @@ discard block |
||
| 701 | 804 | $idx++; |
| 702 | 805 | } |
| 703 | 806 | $direct_download = 'Y'; |
| 704 | - } |
|
| 705 | - else |
|
| 807 | + } else |
|
| 706 | 808 | { |
| 707 | 809 | $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl,3)); |
| 708 | 810 | $filename = $path.$random->createSecureSalt(32, 'hex'); |
| 709 | 811 | $direct_download = 'N'; |
| 710 | 812 | } |
| 711 | 813 | // Create a directory |
| 712 | - if(!FileHandler::makeDir($path)) return new Object(-1,'msg_not_permitted_create'); |
|
| 814 | + if(!FileHandler::makeDir($path)) { |
|
| 815 | + return new Object(-1,'msg_not_permitted_create'); |
|
| 816 | + } |
|
| 713 | 817 | |
| 714 | 818 | // Check uploaded file |
| 715 | - if(!checkUploadedFile($file_info['tmp_name'])) return new Object(-1,'msg_file_upload_error'); |
|
| 819 | + if(!checkUploadedFile($file_info['tmp_name'])) { |
|
| 820 | + return new Object(-1,'msg_file_upload_error'); |
|
| 821 | + } |
|
| 716 | 822 | |
| 717 | 823 | // Get random number generator |
| 718 | 824 | $random = new Password(); |
@@ -726,13 +832,14 @@ discard block |
||
| 726 | 832 | $filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
| 727 | 833 | @copy($file_info['tmp_name'], $filename); |
| 728 | 834 | } |
| 729 | - } |
|
| 730 | - else |
|
| 835 | + } else |
|
| 731 | 836 | { |
| 732 | 837 | if(!@move_uploaded_file($file_info['tmp_name'], $filename)) |
| 733 | 838 | { |
| 734 | 839 | $filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
| 735 | - if(!@move_uploaded_file($file_info['tmp_name'], $filename)) return new Object(-1,'msg_file_upload_error'); |
|
| 840 | + if(!@move_uploaded_file($file_info['tmp_name'], $filename)) { |
|
| 841 | + return new Object(-1,'msg_file_upload_error'); |
|
| 842 | + } |
|
| 736 | 843 | } |
| 737 | 844 | } |
| 738 | 845 | // Get member information |
@@ -753,10 +860,14 @@ discard block |
||
| 753 | 860 | $args->sid = $random->createSecureSalt(32, 'hex'); |
| 754 | 861 | |
| 755 | 862 | $output = executeQuery('file.insertFile', $args); |
| 756 | - if(!$output->toBool()) return $output; |
|
| 863 | + if(!$output->toBool()) { |
|
| 864 | + return $output; |
|
| 865 | + } |
|
| 757 | 866 | // Call a trigger (after) |
| 758 | 867 | $trigger_output = ModuleHandler::triggerCall('file.insertFile', 'after', $args); |
| 759 | - if(!$trigger_output->toBool()) return $trigger_output; |
|
| 868 | + if(!$trigger_output->toBool()) { |
|
| 869 | + return $trigger_output; |
|
| 870 | + } |
|
| 760 | 871 | |
| 761 | 872 | $_SESSION['__XE_UPLOADING_FILES_INFO__'][$args->file_srl] = true; |
| 762 | 873 | |
@@ -799,10 +910,14 @@ discard block |
||
| 799 | 910 | */ |
| 800 | 911 | function deleteFile($file_srl) |
| 801 | 912 | { |
| 802 | - if(!$file_srl) return; |
|
| 913 | + if(!$file_srl) { |
|
| 914 | + return; |
|
| 915 | + } |
|
| 803 | 916 | |
| 804 | 917 | $srls = (is_array($file_srl)) ? $file_srl : explode(',', $file_srl); |
| 805 | - if(!count($srls)) return; |
|
| 918 | + if(!count($srls)) { |
|
| 919 | + return; |
|
| 920 | + } |
|
| 806 | 921 | |
| 807 | 922 | $oDocumentController = getController('document'); |
| 808 | 923 | $documentSrlList = array(); |
@@ -837,15 +952,21 @@ discard block |
||
| 837 | 952 | // Call a trigger (before) |
| 838 | 953 | $trigger_obj = $output->data; |
| 839 | 954 | $output = ModuleHandler::triggerCall('file.deleteFile', 'before', $trigger_obj); |
| 840 | - if(!$output->toBool()) return $output; |
|
| 955 | + if(!$output->toBool()) { |
|
| 956 | + return $output; |
|
| 957 | + } |
|
| 841 | 958 | |
| 842 | 959 | // Remove from the DB |
| 843 | 960 | $output = executeQuery('file.deleteFile', $args); |
| 844 | - if(!$output->toBool()) return $output; |
|
| 961 | + if(!$output->toBool()) { |
|
| 962 | + return $output; |
|
| 963 | + } |
|
| 845 | 964 | |
| 846 | 965 | // Call a trigger (after) |
| 847 | 966 | $trigger_output = ModuleHandler::triggerCall('file.deleteFile', 'after', $trigger_obj); |
| 848 | - if(!$trigger_output->toBool()) return $trigger_output; |
|
| 967 | + if(!$trigger_output->toBool()) { |
|
| 968 | + return $trigger_output; |
|
| 969 | + } |
|
| 849 | 970 | |
| 850 | 971 | // If successfully deleted, remove the file |
| 851 | 972 | FileHandler::removeFile($uploaded_filename); |
@@ -869,7 +990,9 @@ discard block |
||
| 869 | 990 | $columnList = array('file_srl', 'uploaded_filename', 'module_srl'); |
| 870 | 991 | $file_list = $oFileModel->getFiles($upload_target_srl, $columnList); |
| 871 | 992 | // Success returned if no attachement exists |
| 872 | - if(!is_array($file_list)||!count($file_list)) return new Object(); |
|
| 993 | + if(!is_array($file_list)||!count($file_list)) { |
|
| 994 | + return new Object(); |
|
| 995 | + } |
|
| 873 | 996 | |
| 874 | 997 | // Delete the file |
| 875 | 998 | $path = array(); |
@@ -880,14 +1003,18 @@ discard block |
||
| 880 | 1003 | |
| 881 | 1004 | $uploaded_filename = $file_list[$i]->uploaded_filename; |
| 882 | 1005 | $path_info = pathinfo($uploaded_filename); |
| 883 | - if(!in_array($path_info['dirname'], $path)) $path[] = $path_info['dirname']; |
|
| 1006 | + if(!in_array($path_info['dirname'], $path)) { |
|
| 1007 | + $path[] = $path_info['dirname']; |
|
| 1008 | + } |
|
| 884 | 1009 | } |
| 885 | 1010 | |
| 886 | 1011 | // Remove from the DB |
| 887 | 1012 | $args = new stdClass(); |
| 888 | 1013 | $args->upload_target_srl = $upload_target_srl; |
| 889 | 1014 | $output = executeQuery('file.deleteFiles', $args); |
| 890 | - if(!$output->toBool()) return $output; |
|
| 1015 | + if(!$output->toBool()) { |
|
| 1016 | + return $output; |
|
| 1017 | + } |
|
| 891 | 1018 | |
| 892 | 1019 | // Remove a file directory of the document |
| 893 | 1020 | for($i=0, $c=count($path); $i<$c; $i++) |
@@ -908,11 +1035,15 @@ discard block |
||
| 908 | 1035 | */ |
| 909 | 1036 | function moveFile($source_srl, $target_module_srl, $target_srl) |
| 910 | 1037 | { |
| 911 | - if($source_srl == $target_srl) return; |
|
| 1038 | + if($source_srl == $target_srl) { |
|
| 1039 | + return; |
|
| 1040 | + } |
|
| 912 | 1041 | |
| 913 | 1042 | $oFileModel = getModel('file'); |
| 914 | 1043 | $file_list = $oFileModel->getFiles($source_srl); |
| 915 | - if(!$file_list) return; |
|
| 1044 | + if(!$file_list) { |
|
| 1045 | + return; |
|
| 1046 | + } |
|
| 916 | 1047 | |
| 917 | 1048 | $file_count = count($file_list); |
| 918 | 1049 | |
@@ -926,15 +1057,16 @@ discard block |
||
| 926 | 1057 | { |
| 927 | 1058 | $path = sprintf("./files/attach/images/%s/%s/", $target_module_srl,$target_srl); |
| 928 | 1059 | $new_file = $path.$file_info->source_filename; |
| 929 | - } |
|
| 930 | - else |
|
| 1060 | + } else |
|
| 931 | 1061 | { |
| 932 | 1062 | $path = sprintf("./files/attach/binaries/%s/%s/", $target_module_srl, $target_srl); |
| 933 | 1063 | $random = new Password(); |
| 934 | 1064 | $new_file = $path.$random->createSecureSalt(32, 'hex'); |
| 935 | 1065 | } |
| 936 | 1066 | // Pass if a target document to move is same |
| 937 | - if($old_file == $new_file) continue; |
|
| 1067 | + if($old_file == $new_file) { |
|
| 1068 | + continue; |
|
| 1069 | + } |
|
| 938 | 1070 | // Create a directory |
| 939 | 1071 | FileHandler::makeDir($path); |
| 940 | 1072 | // Move the file |
@@ -954,16 +1086,22 @@ discard block |
||
| 954 | 1086 | $vars = Context::getRequestVars(); |
| 955 | 1087 | $logged_info = Context::get('logged_info'); |
| 956 | 1088 | |
| 957 | - if(!$vars->editor_sequence) return new Object(-1, 'msg_invalid_request'); |
|
| 1089 | + if(!$vars->editor_sequence) { |
|
| 1090 | + return new Object(-1, 'msg_invalid_request'); |
|
| 1091 | + } |
|
| 958 | 1092 | |
| 959 | 1093 | $upload_target_srl = $_SESSION['upload_info'][$vars->editor_sequence]->upload_target_srl; |
| 960 | 1094 | |
| 961 | 1095 | $oFileModel = getModel('file'); |
| 962 | 1096 | $file_info = $oFileModel->getFile($vars->file_srl); |
| 963 | 1097 | |
| 964 | - if(!$file_info) return new Object(-1, 'msg_not_founded'); |
|
| 1098 | + if(!$file_info) { |
|
| 1099 | + return new Object(-1, 'msg_not_founded'); |
|
| 1100 | + } |
|
| 965 | 1101 | |
| 966 | - if(!$this->manager && !$file_info->member_srl === $logged_info->member_srl) return new Object(-1, 'msg_not_permitted'); |
|
| 1102 | + if(!$this->manager && !$file_info->member_srl === $logged_info->member_srl) { |
|
| 1103 | + return new Object(-1, 'msg_not_permitted'); |
|
| 1104 | + } |
|
| 967 | 1105 | |
| 968 | 1106 | $args = new stdClass(); |
| 969 | 1107 | $args->file_srl = $vars->file_srl; |