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