@@ -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,28 +61,28 @@ 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 | - $this->setTemplatePath($this->module_path.'tpl'); |
|
| 85 | + $this->setTemplatePath($this->module_path . 'tpl'); |
|
| 86 | 86 | $this->setTemplateFile('iframe'); |
| 87 | 87 | } |
| 88 | 88 | |
@@ -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,15 +308,15 @@ discard block |
||
| 308 | 308 | |
| 309 | 309 | $file_size = $file_obj->file_size; |
| 310 | 310 | $filename = $file_obj->source_filename; |
| 311 | - if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE || (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== FALSE && strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== FALSE && strpos($_SERVER['HTTP_USER_AGENT'], 'rv:') !== FALSE)) |
|
| 311 | + if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE || (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== FALSE && strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== FALSE && strpos($_SERVER['HTTP_USER_AGENT'], 'rv:') !== FALSE)) |
|
| 312 | 312 | { |
| 313 | 313 | $filename = rawurlencode($filename); |
| 314 | 314 | $filename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1); |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - if($is_android) |
|
| 317 | + if ($is_android) |
|
| 318 | 318 | { |
| 319 | - if($_SESSION['__XE_FILE_KEY__'][$file_srl]) $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
|
| 319 | + if ($_SESSION['__XE_FILE_KEY__'][$file_srl]) $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | unset($_SESSION[$session_key][$file_srl]); |
@@ -324,35 +324,35 @@ discard block |
||
| 324 | 324 | Context::close(); |
| 325 | 325 | |
| 326 | 326 | $fp = fopen($uploaded_filename, 'rb'); |
| 327 | - if(!$fp) return $this->stop('msg_file_not_found'); |
|
| 327 | + if (!$fp) return $this->stop('msg_file_not_found'); |
|
| 328 | 328 | |
| 329 | 329 | header("Cache-Control: "); |
| 330 | 330 | header("Pragma: "); |
| 331 | 331 | header("Content-Type: application/octet-stream"); |
| 332 | 332 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
| 333 | 333 | |
| 334 | - header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
| 334 | + header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
| 335 | 335 | header("Content-Transfer-Encoding: binary\n"); |
| 336 | 336 | |
| 337 | - if(isset($_SERVER['HTTP_RANGE'])) |
|
| 337 | + if (isset($_SERVER['HTTP_RANGE'])) |
|
| 338 | 338 | { |
| 339 | 339 | $ranges = array_map('intval', explode('-', substr($_SERVER['HTTP_RANGE'], 6))); |
| 340 | 340 | |
| 341 | - if(!$ranges[1]) |
|
| 341 | + if (!$ranges[1]) |
|
| 342 | 342 | { |
| 343 | 343 | $ranges[1] = $size - 1; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | header('HTTP/1.1 206 Partial Content'); |
| 347 | 347 | header('Accept-Ranges: bytes'); |
| 348 | - header('Content-Length: ' . ($ranges[1] - $ranges[0]+1)); |
|
| 348 | + header('Content-Length: ' . ($ranges[1] - $ranges[0] + 1)); |
|
| 349 | 349 | |
| 350 | 350 | header(sprintf('Content-Range: bytes %d-%d/%d', $ranges[0], $ranges[1], $size)); |
| 351 | 351 | $chunkSize = 8192; |
| 352 | 352 | |
| 353 | 353 | fseek($fp, $ranges[0]); |
| 354 | - while(true) { |
|
| 355 | - if(ftell($fp) >= $ranges[1]) { |
|
| 354 | + while (true) { |
|
| 355 | + if (ftell($fp) >= $ranges[1]) { |
|
| 356 | 356 | break; |
| 357 | 357 | } |
| 358 | 358 | echo fread($fp, $chunkSize); |
@@ -362,11 +362,11 @@ discard block |
||
| 362 | 362 | } |
| 363 | 363 | else |
| 364 | 364 | { |
| 365 | - header("Content-Length: " .(string)($file_size)); |
|
| 365 | + header("Content-Length: " . (string) ($file_size)); |
|
| 366 | 366 | // if file size is lager than 10MB, use fread function (#18675748) |
| 367 | - if($file_size > 1024 * 1024) |
|
| 367 | + if ($file_size > 1024 * 1024) |
|
| 368 | 368 | { |
| 369 | - while(!feof($fp)) echo fread($fp, 1024); |
|
| 369 | + while (!feof($fp)) echo fread($fp, 1024); |
|
| 370 | 370 | fclose($fp); |
| 371 | 371 | } |
| 372 | 372 | else |
@@ -389,36 +389,36 @@ discard block |
||
| 389 | 389 | $editor_sequence = Context::get('editor_sequence'); |
| 390 | 390 | $file_srl = Context::get('file_srl'); |
| 391 | 391 | $file_srls = Context::get('file_srls'); |
| 392 | - if($file_srls) $file_srl = $file_srls; |
|
| 392 | + if ($file_srls) $file_srl = $file_srls; |
|
| 393 | 393 | // Exit a session if there is neither upload permission nor information |
| 394 | - if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
| 394 | + if (!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
| 395 | 395 | |
| 396 | 396 | $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
| 397 | 397 | |
| 398 | 398 | $logged_info = Context::get('logged_info'); |
| 399 | 399 | $oFileModel = getModel('file'); |
| 400 | 400 | |
| 401 | - $srls = explode(',',$file_srl); |
|
| 402 | - if(!count($srls)) return; |
|
| 401 | + $srls = explode(',', $file_srl); |
|
| 402 | + if (!count($srls)) return; |
|
| 403 | 403 | |
| 404 | - for($i=0;$i<count($srls);$i++) |
|
| 404 | + for ($i = 0; $i < count($srls); $i++) |
|
| 405 | 405 | { |
| 406 | - $srl = (int)$srls[$i]; |
|
| 407 | - if(!$srl) continue; |
|
| 406 | + $srl = (int) $srls[$i]; |
|
| 407 | + if (!$srl) continue; |
|
| 408 | 408 | |
| 409 | 409 | $args = new stdClass; |
| 410 | 410 | $args->file_srl = $srl; |
| 411 | 411 | $output = executeQuery('file.getFile', $args); |
| 412 | - if(!$output->toBool()) continue; |
|
| 412 | + if (!$output->toBool()) continue; |
|
| 413 | 413 | |
| 414 | 414 | $file_info = $output->data; |
| 415 | - if(!$file_info) continue; |
|
| 415 | + if (!$file_info) continue; |
|
| 416 | 416 | |
| 417 | 417 | $file_grant = $oFileModel->getFileGrant($file_info, $logged_info); |
| 418 | 418 | |
| 419 | - if(!$file_grant->is_deletable) continue; |
|
| 419 | + if (!$file_grant->is_deletable) continue; |
|
| 420 | 420 | |
| 421 | - if($upload_target_srl && $file_srl) $output = $this->deleteFile($file_srl); |
|
| 421 | + if ($upload_target_srl && $file_srl) $output = $this->deleteFile($file_srl); |
|
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | |
@@ -429,23 +429,23 @@ discard block |
||
| 429 | 429 | */ |
| 430 | 430 | function procFileGetList() |
| 431 | 431 | { |
| 432 | - if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted'); |
|
| 432 | + if (!Context::get('is_logged')) return new Object(-1, 'msg_not_permitted'); |
|
| 433 | 433 | $fileSrls = Context::get('file_srls'); |
| 434 | - if($fileSrls) $fileSrlList = explode(',', $fileSrls); |
|
| 434 | + if ($fileSrls) $fileSrlList = explode(',', $fileSrls); |
|
| 435 | 435 | |
| 436 | 436 | global $lang; |
| 437 | - if(count($fileSrlList) > 0) |
|
| 437 | + if (count($fileSrlList) > 0) |
|
| 438 | 438 | { |
| 439 | 439 | $oFileModel = getModel('file'); |
| 440 | 440 | $fileList = $oFileModel->getFile($fileSrlList); |
| 441 | - if(!is_array($fileList)) $fileList = array($fileList); |
|
| 441 | + if (!is_array($fileList)) $fileList = array($fileList); |
|
| 442 | 442 | |
| 443 | - if(is_array($fileList)) |
|
| 443 | + if (is_array($fileList)) |
|
| 444 | 444 | { |
| 445 | - foreach($fileList AS $key=>$value) |
|
| 445 | + foreach ($fileList AS $key=>$value) |
|
| 446 | 446 | { |
| 447 | 447 | $value->human_file_size = FileHandler::filesize($value->file_size); |
| 448 | - if($value->isvalid=='Y') $value->validName = $lang->is_valid; |
|
| 448 | + if ($value->isvalid == 'Y') $value->validName = $lang->is_valid; |
|
| 449 | 449 | else $value->validName = $lang->is_stand_by; |
| 450 | 450 | } |
| 451 | 451 | } |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | function triggerCheckAttached(&$obj) |
| 468 | 468 | { |
| 469 | 469 | $document_srl = $obj->document_srl; |
| 470 | - if(!$document_srl) return new Object(); |
|
| 470 | + if (!$document_srl) return new Object(); |
|
| 471 | 471 | // Get numbers of attachments |
| 472 | 472 | $oFileModel = getModel('file'); |
| 473 | 473 | $obj->uploaded_count = $oFileModel->getFilesCount($document_srl); |
@@ -484,10 +484,10 @@ discard block |
||
| 484 | 484 | function triggerAttachFiles(&$obj) |
| 485 | 485 | { |
| 486 | 486 | $document_srl = $obj->document_srl; |
| 487 | - if(!$document_srl) return new Object(); |
|
| 487 | + if (!$document_srl) return new Object(); |
|
| 488 | 488 | |
| 489 | 489 | $output = $this->setFilesValid($document_srl); |
| 490 | - if(!$output->toBool()) return $output; |
|
| 490 | + if (!$output->toBool()) return $output; |
|
| 491 | 491 | |
| 492 | 492 | return new Object(); |
| 493 | 493 | } |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | function triggerDeleteAttached(&$obj) |
| 502 | 502 | { |
| 503 | 503 | $document_srl = $obj->document_srl; |
| 504 | - if(!$document_srl) return new Object(); |
|
| 504 | + if (!$document_srl) return new Object(); |
|
| 505 | 505 | |
| 506 | 506 | $output = $this->deleteFiles($document_srl); |
| 507 | 507 | return $output; |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | function triggerCommentCheckAttached(&$obj) |
| 517 | 517 | { |
| 518 | 518 | $comment_srl = $obj->comment_srl; |
| 519 | - if(!$comment_srl) return new Object(); |
|
| 519 | + if (!$comment_srl) return new Object(); |
|
| 520 | 520 | // Get numbers of attachments |
| 521 | 521 | $oFileModel = getModel('file'); |
| 522 | 522 | $obj->uploaded_count = $oFileModel->getFilesCount($comment_srl); |
@@ -534,10 +534,10 @@ discard block |
||
| 534 | 534 | { |
| 535 | 535 | $comment_srl = $obj->comment_srl; |
| 536 | 536 | $uploaded_count = $obj->uploaded_count; |
| 537 | - if(!$comment_srl || !$uploaded_count) return new Object(); |
|
| 537 | + if (!$comment_srl || !$uploaded_count) return new Object(); |
|
| 538 | 538 | |
| 539 | 539 | $output = $this->setFilesValid($comment_srl); |
| 540 | - if(!$output->toBool()) return $output; |
|
| 540 | + if (!$output->toBool()) return $output; |
|
| 541 | 541 | |
| 542 | 542 | return new Object(); |
| 543 | 543 | } |
@@ -551,9 +551,9 @@ discard block |
||
| 551 | 551 | function triggerCommentDeleteAttached(&$obj) |
| 552 | 552 | { |
| 553 | 553 | $comment_srl = $obj->comment_srl; |
| 554 | - if(!$comment_srl) return new Object(); |
|
| 554 | + if (!$comment_srl) return new Object(); |
|
| 555 | 555 | |
| 556 | - if($obj->isMoveToTrash) return new Object(); |
|
| 556 | + if ($obj->isMoveToTrash) return new Object(); |
|
| 557 | 557 | |
| 558 | 558 | $output = $this->deleteFiles($comment_srl); |
| 559 | 559 | return $output; |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | function triggerDeleteModuleFiles(&$obj) |
| 569 | 569 | { |
| 570 | 570 | $module_srl = $obj->module_srl; |
| 571 | - if(!$module_srl) return new Object(); |
|
| 571 | + if (!$module_srl) return new Object(); |
|
| 572 | 572 | |
| 573 | 573 | $oFileController = getAdminController('file'); |
| 574 | 574 | return $oFileController->deleteModuleFiles($module_srl); |
@@ -581,9 +581,9 @@ discard block |
||
| 581 | 581 | * @param int $upload_target_srl |
| 582 | 582 | * @return void |
| 583 | 583 | */ |
| 584 | - function setUploadInfo($editor_sequence, $upload_target_srl=0) |
|
| 584 | + function setUploadInfo($editor_sequence, $upload_target_srl = 0) |
|
| 585 | 585 | { |
| 586 | - if(!isset($_SESSION['upload_info'][$editor_sequence])) |
|
| 586 | + if (!isset($_SESSION['upload_info'][$editor_sequence])) |
|
| 587 | 587 | { |
| 588 | 588 | $_SESSION['upload_info'][$editor_sequence] = new stdClass(); |
| 589 | 589 | } |
@@ -643,36 +643,36 @@ discard block |
||
| 643 | 643 | $trigger_obj->module_srl = $module_srl; |
| 644 | 644 | $trigger_obj->upload_target_srl = $upload_target_srl; |
| 645 | 645 | $output = ModuleHandler::triggerCall('file.insertFile', 'before', $trigger_obj); |
| 646 | - if(!$output->toBool()) return $output; |
|
| 646 | + if (!$output->toBool()) return $output; |
|
| 647 | 647 | |
| 648 | 648 | // A workaround for Firefox upload bug |
| 649 | - if(preg_match('/^=\?UTF-8\?B\?(.+)\?=$/i', $file_info['name'], $match)) |
|
| 649 | + if (preg_match('/^=\?UTF-8\?B\?(.+)\?=$/i', $file_info['name'], $match)) |
|
| 650 | 650 | { |
| 651 | 651 | $file_info['name'] = base64_decode(strtr($match[1], ':', '/')); |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | - if(!$manual_insert) |
|
| 654 | + if (!$manual_insert) |
|
| 655 | 655 | { |
| 656 | 656 | // Get the file configurations |
| 657 | 657 | $logged_info = Context::get('logged_info'); |
| 658 | - if($logged_info->is_admin != 'Y') |
|
| 658 | + if ($logged_info->is_admin != 'Y') |
|
| 659 | 659 | { |
| 660 | 660 | $oFileModel = getModel('file'); |
| 661 | 661 | $config = $oFileModel->getFileConfig($module_srl); |
| 662 | 662 | |
| 663 | 663 | // check file type |
| 664 | - if(isset($config->allowed_filetypes) && $config->allowed_filetypes !== '*.*') |
|
| 664 | + if (isset($config->allowed_filetypes) && $config->allowed_filetypes !== '*.*') |
|
| 665 | 665 | { |
| 666 | 666 | $filetypes = explode(';', $config->allowed_filetypes); |
| 667 | 667 | $ext = array(); |
| 668 | - foreach($filetypes as $item) { |
|
| 668 | + foreach ($filetypes as $item) { |
|
| 669 | 669 | $item = explode('.', $item); |
| 670 | 670 | $ext[] = strtolower($item[1]); |
| 671 | 671 | } |
| 672 | 672 | $uploaded_ext = explode('.', $file_info['name']); |
| 673 | 673 | $uploaded_ext = strtolower(array_pop($uploaded_ext)); |
| 674 | 674 | |
| 675 | - if(!in_array($uploaded_ext, $ext)) |
|
| 675 | + if (!in_array($uploaded_ext, $ext)) |
|
| 676 | 676 | { |
| 677 | 677 | return $this->stop('msg_not_allowed_filetype'); |
| 678 | 678 | } |
@@ -681,74 +681,74 @@ discard block |
||
| 681 | 681 | $allowed_filesize = $config->allowed_filesize * 1024 * 1024; |
| 682 | 682 | $allowed_attach_size = $config->allowed_attach_size * 1024 * 1024; |
| 683 | 683 | // An error appears if file size exceeds a limit |
| 684 | - if($allowed_filesize < filesize($file_info['tmp_name'])) return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 684 | + if ($allowed_filesize < filesize($file_info['tmp_name'])) return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 685 | 685 | // Get total file size of all attachements (from DB) |
| 686 | 686 | $size_args = new stdClass; |
| 687 | 687 | $size_args->upload_target_srl = $upload_target_srl; |
| 688 | 688 | $output = executeQuery('file.getAttachedFileSize', $size_args); |
| 689 | - $attached_size = (int)$output->data->attached_size + filesize($file_info['tmp_name']); |
|
| 690 | - if($attached_size > $allowed_attach_size) return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 689 | + $attached_size = (int) $output->data->attached_size + filesize($file_info['tmp_name']); |
|
| 690 | + if ($attached_size > $allowed_attach_size) return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 691 | 691 | } |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | // https://github.com/xpressengine/xe-core/issues/1713 |
| 695 | - $file_info['name'] = preg_replace('/\.(php|phtm|phar|html?|cgi|pl|exe|jsp|asp|inc)/i', '$0-x',$file_info['name']); |
|
| 695 | + $file_info['name'] = preg_replace('/\.(php|phtm|phar|html?|cgi|pl|exe|jsp|asp|inc)/i', '$0-x', $file_info['name']); |
|
| 696 | 696 | $file_info['name'] = removeHackTag($file_info['name']); |
| 697 | - $file_info['name'] = str_replace(array('<','>'),array('%3C','%3E'),$file_info['name']); |
|
| 697 | + $file_info['name'] = str_replace(array('<', '>'), array('%3C', '%3E'), $file_info['name']); |
|
| 698 | 698 | |
| 699 | 699 | // Get random number generator |
| 700 | 700 | $random = new Password(); |
| 701 | 701 | |
| 702 | 702 | // Set upload path by checking if the attachement is an image or other kinds of file |
| 703 | - 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'])) |
|
| 703 | + 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'])) |
|
| 704 | 704 | { |
| 705 | - $path = sprintf("./files/attach/images/%s/%s", $module_srl,getNumberingPath($upload_target_srl,3)); |
|
| 705 | + $path = sprintf("./files/attach/images/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3)); |
|
| 706 | 706 | |
| 707 | 707 | // special character to '_' |
| 708 | 708 | // change to random file name. because window php bug. window php is not recognize unicode character file name - by cherryfilter |
| 709 | - $ext = substr(strrchr($file_info['name'],'.'),1); |
|
| 709 | + $ext = substr(strrchr($file_info['name'], '.'), 1); |
|
| 710 | 710 | //$_filename = preg_replace('/[#$&*?+%"\']/', '_', $file_info['name']); |
| 711 | - $_filename = $random->createSecureSalt(32, 'hex').'.'.$ext; |
|
| 712 | - $filename = $path.$_filename; |
|
| 711 | + $_filename = $random->createSecureSalt(32, 'hex') . '.' . $ext; |
|
| 712 | + $filename = $path . $_filename; |
|
| 713 | 713 | $idx = 1; |
| 714 | - while(file_exists($filename)) |
|
| 714 | + while (file_exists($filename)) |
|
| 715 | 715 | { |
| 716 | - $filename = $path.preg_replace('/\.([a-z0-9]+)$/i','_'.$idx.'.$1',$_filename); |
|
| 716 | + $filename = $path . preg_replace('/\.([a-z0-9]+)$/i', '_' . $idx . '.$1', $_filename); |
|
| 717 | 717 | $idx++; |
| 718 | 718 | } |
| 719 | 719 | $direct_download = 'Y'; |
| 720 | 720 | } |
| 721 | 721 | else |
| 722 | 722 | { |
| 723 | - $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl,3)); |
|
| 724 | - $filename = $path.$random->createSecureSalt(32, 'hex'); |
|
| 723 | + $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3)); |
|
| 724 | + $filename = $path . $random->createSecureSalt(32, 'hex'); |
|
| 725 | 725 | $direct_download = 'N'; |
| 726 | 726 | } |
| 727 | 727 | // Create a directory |
| 728 | - if(!FileHandler::makeDir($path)) return new Object(-1,'msg_not_permitted_create'); |
|
| 728 | + if (!FileHandler::makeDir($path)) return new Object(-1, 'msg_not_permitted_create'); |
|
| 729 | 729 | |
| 730 | 730 | // Check uploaded file |
| 731 | - if(!checkUploadedFile($file_info['tmp_name'])) return new Object(-1,'msg_file_upload_error'); |
|
| 731 | + if (!checkUploadedFile($file_info['tmp_name'])) return new Object(-1, 'msg_file_upload_error'); |
|
| 732 | 732 | |
| 733 | 733 | // Get random number generator |
| 734 | 734 | $random = new Password(); |
| 735 | 735 | |
| 736 | 736 | // Move the file |
| 737 | - if($manual_insert) |
|
| 737 | + if ($manual_insert) |
|
| 738 | 738 | { |
| 739 | 739 | @copy($file_info['tmp_name'], $filename); |
| 740 | - if(!file_exists($filename)) |
|
| 740 | + if (!file_exists($filename)) |
|
| 741 | 741 | { |
| 742 | - $filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
|
| 742 | + $filename = $path . $random->createSecureSalt(32, 'hex') . '.' . $ext; |
|
| 743 | 743 | @copy($file_info['tmp_name'], $filename); |
| 744 | 744 | } |
| 745 | 745 | } |
| 746 | 746 | else |
| 747 | 747 | { |
| 748 | - if(!@move_uploaded_file($file_info['tmp_name'], $filename)) |
|
| 748 | + if (!@move_uploaded_file($file_info['tmp_name'], $filename)) |
|
| 749 | 749 | { |
| 750 | - $filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
|
| 751 | - if(!@move_uploaded_file($file_info['tmp_name'], $filename)) return new Object(-1,'msg_file_upload_error'); |
|
| 750 | + $filename = $path . $random->createSecureSalt(32, 'hex') . '.' . $ext; |
|
| 751 | + if (!@move_uploaded_file($file_info['tmp_name'], $filename)) return new Object(-1, 'msg_file_upload_error'); |
|
| 752 | 752 | } |
| 753 | 753 | } |
| 754 | 754 | // Get member information |
@@ -769,10 +769,10 @@ discard block |
||
| 769 | 769 | $args->sid = $random->createSecureSalt(32, 'hex'); |
| 770 | 770 | |
| 771 | 771 | $output = executeQuery('file.insertFile', $args); |
| 772 | - if(!$output->toBool()) return $output; |
|
| 772 | + if (!$output->toBool()) return $output; |
|
| 773 | 773 | // Call a trigger (after) |
| 774 | 774 | $trigger_output = ModuleHandler::triggerCall('file.insertFile', 'after', $args); |
| 775 | - if(!$trigger_output->toBool()) return $trigger_output; |
|
| 775 | + if (!$trigger_output->toBool()) return $trigger_output; |
|
| 776 | 776 | |
| 777 | 777 | $_SESSION['__XE_UPLOADING_FILES_INFO__'][$args->file_srl] = true; |
| 778 | 778 | |
@@ -815,18 +815,18 @@ discard block |
||
| 815 | 815 | */ |
| 816 | 816 | function deleteFile($file_srl) |
| 817 | 817 | { |
| 818 | - if(!$file_srl) return; |
|
| 818 | + if (!$file_srl) return; |
|
| 819 | 819 | |
| 820 | 820 | $srls = (is_array($file_srl)) ? $file_srl : explode(',', $file_srl); |
| 821 | - if(!count($srls)) return; |
|
| 821 | + if (!count($srls)) return; |
|
| 822 | 822 | |
| 823 | 823 | $oDocumentController = getController('document'); |
| 824 | 824 | $documentSrlList = array(); |
| 825 | 825 | |
| 826 | - foreach($srls as $srl) |
|
| 826 | + foreach ($srls as $srl) |
|
| 827 | 827 | { |
| 828 | - $srl = (int)$srl; |
|
| 829 | - if(!$srl) |
|
| 828 | + $srl = (int) $srl; |
|
| 829 | + if (!$srl) |
|
| 830 | 830 | { |
| 831 | 831 | continue; |
| 832 | 832 | } |
@@ -835,14 +835,14 @@ discard block |
||
| 835 | 835 | $args->file_srl = $srl; |
| 836 | 836 | $output = executeQuery('file.getFile', $args); |
| 837 | 837 | |
| 838 | - if(!$output->toBool() || !$output->data) |
|
| 838 | + if (!$output->toBool() || !$output->data) |
|
| 839 | 839 | { |
| 840 | 840 | continue; |
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | $file_info = $output->data; |
| 844 | 844 | |
| 845 | - if($file_info->upload_target_srl) |
|
| 845 | + if ($file_info->upload_target_srl) |
|
| 846 | 846 | { |
| 847 | 847 | $documentSrlList[] = $file_info->upload_target_srl; |
| 848 | 848 | } |
@@ -853,15 +853,15 @@ discard block |
||
| 853 | 853 | // Call a trigger (before) |
| 854 | 854 | $trigger_obj = $output->data; |
| 855 | 855 | $output = ModuleHandler::triggerCall('file.deleteFile', 'before', $trigger_obj); |
| 856 | - if(!$output->toBool()) return $output; |
|
| 856 | + if (!$output->toBool()) return $output; |
|
| 857 | 857 | |
| 858 | 858 | // Remove from the DB |
| 859 | 859 | $output = executeQuery('file.deleteFile', $args); |
| 860 | - if(!$output->toBool()) return $output; |
|
| 860 | + if (!$output->toBool()) return $output; |
|
| 861 | 861 | |
| 862 | 862 | // Call a trigger (after) |
| 863 | 863 | $trigger_output = ModuleHandler::triggerCall('file.deleteFile', 'after', $trigger_obj); |
| 864 | - if(!$trigger_output->toBool()) return $trigger_output; |
|
| 864 | + if (!$trigger_output->toBool()) return $trigger_output; |
|
| 865 | 865 | |
| 866 | 866 | // If successfully deleted, remove the file |
| 867 | 867 | FileHandler::removeFile($uploaded_filename); |
@@ -885,28 +885,28 @@ discard block |
||
| 885 | 885 | $columnList = array('file_srl', 'uploaded_filename', 'module_srl'); |
| 886 | 886 | $file_list = $oFileModel->getFiles($upload_target_srl, $columnList); |
| 887 | 887 | // Success returned if no attachement exists |
| 888 | - if(!is_array($file_list)||!count($file_list)) return new Object(); |
|
| 888 | + if (!is_array($file_list) || !count($file_list)) return new Object(); |
|
| 889 | 889 | |
| 890 | 890 | // Delete the file |
| 891 | 891 | $path = array(); |
| 892 | 892 | $file_count = count($file_list); |
| 893 | - for($i=0;$i<$file_count;$i++) |
|
| 893 | + for ($i = 0; $i < $file_count; $i++) |
|
| 894 | 894 | { |
| 895 | 895 | $this->deleteFile($file_list[$i]->file_srl); |
| 896 | 896 | |
| 897 | 897 | $uploaded_filename = $file_list[$i]->uploaded_filename; |
| 898 | 898 | $path_info = pathinfo($uploaded_filename); |
| 899 | - if(!in_array($path_info['dirname'], $path)) $path[] = $path_info['dirname']; |
|
| 899 | + if (!in_array($path_info['dirname'], $path)) $path[] = $path_info['dirname']; |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | // Remove from the DB |
| 903 | 903 | $args = new stdClass(); |
| 904 | 904 | $args->upload_target_srl = $upload_target_srl; |
| 905 | 905 | $output = executeQuery('file.deleteFiles', $args); |
| 906 | - if(!$output->toBool()) return $output; |
|
| 906 | + if (!$output->toBool()) return $output; |
|
| 907 | 907 | |
| 908 | 908 | // Remove a file directory of the document |
| 909 | - for($i=0, $c=count($path); $i<$c; $i++) |
|
| 909 | + for ($i = 0, $c = count($path); $i < $c; $i++) |
|
| 910 | 910 | { |
| 911 | 911 | FileHandler::removeBlankDir($path[$i]); |
| 912 | 912 | } |
@@ -924,33 +924,33 @@ discard block |
||
| 924 | 924 | */ |
| 925 | 925 | function moveFile($source_srl, $target_module_srl, $target_srl) |
| 926 | 926 | { |
| 927 | - if($source_srl == $target_srl) return; |
|
| 927 | + if ($source_srl == $target_srl) return; |
|
| 928 | 928 | |
| 929 | 929 | $oFileModel = getModel('file'); |
| 930 | 930 | $file_list = $oFileModel->getFiles($source_srl); |
| 931 | - if(!$file_list) return; |
|
| 931 | + if (!$file_list) return; |
|
| 932 | 932 | |
| 933 | 933 | $file_count = count($file_list); |
| 934 | 934 | |
| 935 | - for($i=0;$i<$file_count;$i++) |
|
| 935 | + for ($i = 0; $i < $file_count; $i++) |
|
| 936 | 936 | { |
| 937 | 937 | unset($file_info); |
| 938 | 938 | $file_info = $file_list[$i]; |
| 939 | 939 | $old_file = $file_info->uploaded_filename; |
| 940 | 940 | // Determine the file path by checking if the file is an image or other kinds |
| 941 | - 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)) |
|
| 941 | + 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)) |
|
| 942 | 942 | { |
| 943 | - $path = sprintf("./files/attach/images/%s/%s/", $target_module_srl,$target_srl); |
|
| 944 | - $new_file = $path.$file_info->source_filename; |
|
| 943 | + $path = sprintf("./files/attach/images/%s/%s/", $target_module_srl, $target_srl); |
|
| 944 | + $new_file = $path . $file_info->source_filename; |
|
| 945 | 945 | } |
| 946 | 946 | else |
| 947 | 947 | { |
| 948 | 948 | $path = sprintf("./files/attach/binaries/%s/%s/", $target_module_srl, $target_srl); |
| 949 | 949 | $random = new Password(); |
| 950 | - $new_file = $path.$random->createSecureSalt(32, 'hex'); |
|
| 950 | + $new_file = $path . $random->createSecureSalt(32, 'hex'); |
|
| 951 | 951 | } |
| 952 | 952 | // Pass if a target document to move is same |
| 953 | - if($old_file == $new_file) continue; |
|
| 953 | + if ($old_file == $new_file) continue; |
|
| 954 | 954 | // Create a directory |
| 955 | 955 | FileHandler::makeDir($path); |
| 956 | 956 | // Move the file |
@@ -970,18 +970,18 @@ discard block |
||
| 970 | 970 | $vars = Context::getRequestVars(); |
| 971 | 971 | $logged_info = Context::get('logged_info'); |
| 972 | 972 | |
| 973 | - if(!$vars->editor_sequence) return new Object(-1, 'msg_invalid_request'); |
|
| 973 | + if (!$vars->editor_sequence) return new Object(-1, 'msg_invalid_request'); |
|
| 974 | 974 | |
| 975 | 975 | $upload_target_srl = $_SESSION['upload_info'][$vars->editor_sequence]->upload_target_srl; |
| 976 | 976 | |
| 977 | 977 | $oFileModel = getModel('file'); |
| 978 | 978 | $file_info = $oFileModel->getFile($vars->file_srl); |
| 979 | 979 | |
| 980 | - if(!$file_info) return new Object(-1, 'msg_not_founded'); |
|
| 980 | + if (!$file_info) return new Object(-1, 'msg_not_founded'); |
|
| 981 | 981 | |
| 982 | - if(!$this->manager && !$file_info->member_srl === $logged_info->member_srl) return new Object(-1, 'msg_not_permitted'); |
|
| 982 | + if (!$this->manager && !$file_info->member_srl === $logged_info->member_srl) return new Object(-1, 'msg_not_permitted'); |
|
| 983 | 983 | |
| 984 | - $args = new stdClass(); |
|
| 984 | + $args = new stdClass(); |
|
| 985 | 985 | $args->file_srl = $vars->file_srl; |
| 986 | 986 | $args->upload_target_srl = $upload_target_srl; |
| 987 | 987 | |
@@ -990,7 +990,7 @@ discard block |
||
| 990 | 990 | |
| 991 | 991 | $args->cover_image = 'N'; |
| 992 | 992 | $output = executeQuery('file.updateClearCoverImage', $args); |
| 993 | - if(!$output->toBool()) |
|
| 993 | + if (!$output->toBool()) |
|
| 994 | 994 | { |
| 995 | 995 | $oDB->rollback(); |
| 996 | 996 | return $output; |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | |
| 999 | 999 | $args->cover_image = 'Y'; |
| 1000 | 1000 | $output = executeQuery('file.updateCoverImage', $args); |
| 1001 | - if(!$output->toBool()) |
|
| 1001 | + if (!$output->toBool()) |
|
| 1002 | 1002 | { |
| 1003 | 1003 | $oDB->rollback(); |
| 1004 | 1004 | return $output; |
@@ -1030,9 +1030,9 @@ discard block |
||
| 1030 | 1030 | $fileConfig = $oModuleModel->getModulePartConfig('file', $obj->originModuleSrl); |
| 1031 | 1031 | |
| 1032 | 1032 | $oModuleController = getController('module'); |
| 1033 | - if(is_array($obj->moduleSrlList)) |
|
| 1033 | + if (is_array($obj->moduleSrlList)) |
|
| 1034 | 1034 | { |
| 1035 | - foreach($obj->moduleSrlList AS $key=>$moduleSrl) |
|
| 1035 | + foreach ($obj->moduleSrlList AS $key=>$moduleSrl) |
|
| 1036 | 1036 | { |
| 1037 | 1037 | $oModuleController->insertModulePartConfig('file', $moduleSrl, $fileConfig); |
| 1038 | 1038 | } |
@@ -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 | { |
@@ -316,7 +366,9 @@ discard block |
||
| 316 | 366 | |
| 317 | 367 | if($is_android) |
| 318 | 368 | { |
| 319 | - if($_SESSION['__XE_FILE_KEY__'][$file_srl]) $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
|
| 369 | + if($_SESSION['__XE_FILE_KEY__'][$file_srl]) { |
|
| 370 | + $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
|
| 371 | + } |
|
| 320 | 372 | } |
| 321 | 373 | |
| 322 | 374 | unset($_SESSION[$session_key][$file_srl]); |
@@ -324,7 +376,9 @@ discard block |
||
| 324 | 376 | Context::close(); |
| 325 | 377 | |
| 326 | 378 | $fp = fopen($uploaded_filename, 'rb'); |
| 327 | - if(!$fp) return $this->stop('msg_file_not_found'); |
|
| 379 | + if(!$fp) { |
|
| 380 | + return $this->stop('msg_file_not_found'); |
|
| 381 | + } |
|
| 328 | 382 | |
| 329 | 383 | header("Cache-Control: "); |
| 330 | 384 | header("Pragma: "); |
@@ -359,17 +413,17 @@ discard block |
||
| 359 | 413 | @ob_flush(); |
| 360 | 414 | flush(); |
| 361 | 415 | } |
| 362 | - } |
|
| 363 | - else |
|
| 416 | + } else |
|
| 364 | 417 | { |
| 365 | 418 | header("Content-Length: " .(string)($file_size)); |
| 366 | 419 | // if file size is lager than 10MB, use fread function (#18675748) |
| 367 | 420 | if($file_size > 1024 * 1024) |
| 368 | 421 | { |
| 369 | - while(!feof($fp)) echo fread($fp, 1024); |
|
| 422 | + while(!feof($fp)) { |
|
| 423 | + echo fread($fp, 1024); |
|
| 424 | + } |
|
| 370 | 425 | fclose($fp); |
| 371 | - } |
|
| 372 | - else |
|
| 426 | + } else |
|
| 373 | 427 | { |
| 374 | 428 | fpassthru($fp); |
| 375 | 429 | } |
@@ -389,9 +443,13 @@ discard block |
||
| 389 | 443 | $editor_sequence = Context::get('editor_sequence'); |
| 390 | 444 | $file_srl = Context::get('file_srl'); |
| 391 | 445 | $file_srls = Context::get('file_srls'); |
| 392 | - if($file_srls) $file_srl = $file_srls; |
|
| 446 | + if($file_srls) { |
|
| 447 | + $file_srl = $file_srls; |
|
| 448 | + } |
|
| 393 | 449 | // Exit a session if there is neither upload permission nor information |
| 394 | - if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
|
| 450 | + if(!$_SESSION['upload_info'][$editor_sequence]->enabled) { |
|
| 451 | + exit(); |
|
| 452 | + } |
|
| 395 | 453 | |
| 396 | 454 | $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
| 397 | 455 | |
@@ -399,26 +457,38 @@ discard block |
||
| 399 | 457 | $oFileModel = getModel('file'); |
| 400 | 458 | |
| 401 | 459 | $srls = explode(',',$file_srl); |
| 402 | - if(!count($srls)) return; |
|
| 460 | + if(!count($srls)) { |
|
| 461 | + return; |
|
| 462 | + } |
|
| 403 | 463 | |
| 404 | 464 | for($i=0;$i<count($srls);$i++) |
| 405 | 465 | { |
| 406 | 466 | $srl = (int)$srls[$i]; |
| 407 | - if(!$srl) continue; |
|
| 467 | + if(!$srl) { |
|
| 468 | + continue; |
|
| 469 | + } |
|
| 408 | 470 | |
| 409 | 471 | $args = new stdClass; |
| 410 | 472 | $args->file_srl = $srl; |
| 411 | 473 | $output = executeQuery('file.getFile', $args); |
| 412 | - if(!$output->toBool()) continue; |
|
| 474 | + if(!$output->toBool()) { |
|
| 475 | + continue; |
|
| 476 | + } |
|
| 413 | 477 | |
| 414 | 478 | $file_info = $output->data; |
| 415 | - if(!$file_info) continue; |
|
| 479 | + if(!$file_info) { |
|
| 480 | + continue; |
|
| 481 | + } |
|
| 416 | 482 | |
| 417 | 483 | $file_grant = $oFileModel->getFileGrant($file_info, $logged_info); |
| 418 | 484 | |
| 419 | - if(!$file_grant->is_deletable) continue; |
|
| 485 | + if(!$file_grant->is_deletable) { |
|
| 486 | + continue; |
|
| 487 | + } |
|
| 420 | 488 | |
| 421 | - if($upload_target_srl && $file_srl) $output = $this->deleteFile($file_srl); |
|
| 489 | + if($upload_target_srl && $file_srl) { |
|
| 490 | + $output = $this->deleteFile($file_srl); |
|
| 491 | + } |
|
| 422 | 492 | } |
| 423 | 493 | } |
| 424 | 494 | |
@@ -429,28 +499,36 @@ discard block |
||
| 429 | 499 | */ |
| 430 | 500 | function procFileGetList() |
| 431 | 501 | { |
| 432 | - if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted'); |
|
| 502 | + if(!Context::get('is_logged')) { |
|
| 503 | + return new Object(-1,'msg_not_permitted'); |
|
| 504 | + } |
|
| 433 | 505 | $fileSrls = Context::get('file_srls'); |
| 434 | - if($fileSrls) $fileSrlList = explode(',', $fileSrls); |
|
| 506 | + if($fileSrls) { |
|
| 507 | + $fileSrlList = explode(',', $fileSrls); |
|
| 508 | + } |
|
| 435 | 509 | |
| 436 | 510 | global $lang; |
| 437 | 511 | if(count($fileSrlList) > 0) |
| 438 | 512 | { |
| 439 | 513 | $oFileModel = getModel('file'); |
| 440 | 514 | $fileList = $oFileModel->getFile($fileSrlList); |
| 441 | - if(!is_array($fileList)) $fileList = array($fileList); |
|
| 515 | + if(!is_array($fileList)) { |
|
| 516 | + $fileList = array($fileList); |
|
| 517 | + } |
|
| 442 | 518 | |
| 443 | 519 | if(is_array($fileList)) |
| 444 | 520 | { |
| 445 | 521 | foreach($fileList AS $key=>$value) |
| 446 | 522 | { |
| 447 | 523 | $value->human_file_size = FileHandler::filesize($value->file_size); |
| 448 | - if($value->isvalid=='Y') $value->validName = $lang->is_valid; |
|
| 449 | - else $value->validName = $lang->is_stand_by; |
|
| 524 | + if($value->isvalid=='Y') { |
|
| 525 | + $value->validName = $lang->is_valid; |
|
| 526 | + } else { |
|
| 527 | + $value->validName = $lang->is_stand_by; |
|
| 528 | + } |
|
| 450 | 529 | } |
| 451 | 530 | } |
| 452 | - } |
|
| 453 | - else |
|
| 531 | + } else |
|
| 454 | 532 | { |
| 455 | 533 | $fileList = array(); |
| 456 | 534 | $this->setMessage($lang->no_files); |
@@ -467,7 +545,9 @@ discard block |
||
| 467 | 545 | function triggerCheckAttached(&$obj) |
| 468 | 546 | { |
| 469 | 547 | $document_srl = $obj->document_srl; |
| 470 | - if(!$document_srl) return new Object(); |
|
| 548 | + if(!$document_srl) { |
|
| 549 | + return new Object(); |
|
| 550 | + } |
|
| 471 | 551 | // Get numbers of attachments |
| 472 | 552 | $oFileModel = getModel('file'); |
| 473 | 553 | $obj->uploaded_count = $oFileModel->getFilesCount($document_srl); |
@@ -484,10 +564,14 @@ discard block |
||
| 484 | 564 | function triggerAttachFiles(&$obj) |
| 485 | 565 | { |
| 486 | 566 | $document_srl = $obj->document_srl; |
| 487 | - if(!$document_srl) return new Object(); |
|
| 567 | + if(!$document_srl) { |
|
| 568 | + return new Object(); |
|
| 569 | + } |
|
| 488 | 570 | |
| 489 | 571 | $output = $this->setFilesValid($document_srl); |
| 490 | - if(!$output->toBool()) return $output; |
|
| 572 | + if(!$output->toBool()) { |
|
| 573 | + return $output; |
|
| 574 | + } |
|
| 491 | 575 | |
| 492 | 576 | return new Object(); |
| 493 | 577 | } |
@@ -501,7 +585,9 @@ discard block |
||
| 501 | 585 | function triggerDeleteAttached(&$obj) |
| 502 | 586 | { |
| 503 | 587 | $document_srl = $obj->document_srl; |
| 504 | - if(!$document_srl) return new Object(); |
|
| 588 | + if(!$document_srl) { |
|
| 589 | + return new Object(); |
|
| 590 | + } |
|
| 505 | 591 | |
| 506 | 592 | $output = $this->deleteFiles($document_srl); |
| 507 | 593 | return $output; |
@@ -516,7 +602,9 @@ discard block |
||
| 516 | 602 | function triggerCommentCheckAttached(&$obj) |
| 517 | 603 | { |
| 518 | 604 | $comment_srl = $obj->comment_srl; |
| 519 | - if(!$comment_srl) return new Object(); |
|
| 605 | + if(!$comment_srl) { |
|
| 606 | + return new Object(); |
|
| 607 | + } |
|
| 520 | 608 | // Get numbers of attachments |
| 521 | 609 | $oFileModel = getModel('file'); |
| 522 | 610 | $obj->uploaded_count = $oFileModel->getFilesCount($comment_srl); |
@@ -534,10 +622,14 @@ discard block |
||
| 534 | 622 | { |
| 535 | 623 | $comment_srl = $obj->comment_srl; |
| 536 | 624 | $uploaded_count = $obj->uploaded_count; |
| 537 | - if(!$comment_srl || !$uploaded_count) return new Object(); |
|
| 625 | + if(!$comment_srl || !$uploaded_count) { |
|
| 626 | + return new Object(); |
|
| 627 | + } |
|
| 538 | 628 | |
| 539 | 629 | $output = $this->setFilesValid($comment_srl); |
| 540 | - if(!$output->toBool()) return $output; |
|
| 630 | + if(!$output->toBool()) { |
|
| 631 | + return $output; |
|
| 632 | + } |
|
| 541 | 633 | |
| 542 | 634 | return new Object(); |
| 543 | 635 | } |
@@ -551,9 +643,13 @@ discard block |
||
| 551 | 643 | function triggerCommentDeleteAttached(&$obj) |
| 552 | 644 | { |
| 553 | 645 | $comment_srl = $obj->comment_srl; |
| 554 | - if(!$comment_srl) return new Object(); |
|
| 646 | + if(!$comment_srl) { |
|
| 647 | + return new Object(); |
|
| 648 | + } |
|
| 555 | 649 | |
| 556 | - if($obj->isMoveToTrash) return new Object(); |
|
| 650 | + if($obj->isMoveToTrash) { |
|
| 651 | + return new Object(); |
|
| 652 | + } |
|
| 557 | 653 | |
| 558 | 654 | $output = $this->deleteFiles($comment_srl); |
| 559 | 655 | return $output; |
@@ -568,7 +664,9 @@ discard block |
||
| 568 | 664 | function triggerDeleteModuleFiles(&$obj) |
| 569 | 665 | { |
| 570 | 666 | $module_srl = $obj->module_srl; |
| 571 | - if(!$module_srl) return new Object(); |
|
| 667 | + if(!$module_srl) { |
|
| 668 | + return new Object(); |
|
| 669 | + } |
|
| 572 | 670 | |
| 573 | 671 | $oFileController = getAdminController('file'); |
| 574 | 672 | return $oFileController->deleteModuleFiles($module_srl); |
@@ -643,7 +741,9 @@ discard block |
||
| 643 | 741 | $trigger_obj->module_srl = $module_srl; |
| 644 | 742 | $trigger_obj->upload_target_srl = $upload_target_srl; |
| 645 | 743 | $output = ModuleHandler::triggerCall('file.insertFile', 'before', $trigger_obj); |
| 646 | - if(!$output->toBool()) return $output; |
|
| 744 | + if(!$output->toBool()) { |
|
| 745 | + return $output; |
|
| 746 | + } |
|
| 647 | 747 | |
| 648 | 748 | // A workaround for Firefox upload bug |
| 649 | 749 | if(preg_match('/^=\?UTF-8\?B\?(.+)\?=$/i', $file_info['name'], $match)) |
@@ -681,13 +781,17 @@ discard block |
||
| 681 | 781 | $allowed_filesize = $config->allowed_filesize * 1024 * 1024; |
| 682 | 782 | $allowed_attach_size = $config->allowed_attach_size * 1024 * 1024; |
| 683 | 783 | // An error appears if file size exceeds a limit |
| 684 | - if($allowed_filesize < filesize($file_info['tmp_name'])) return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 784 | + if($allowed_filesize < filesize($file_info['tmp_name'])) { |
|
| 785 | + return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 786 | + } |
|
| 685 | 787 | // Get total file size of all attachements (from DB) |
| 686 | 788 | $size_args = new stdClass; |
| 687 | 789 | $size_args->upload_target_srl = $upload_target_srl; |
| 688 | 790 | $output = executeQuery('file.getAttachedFileSize', $size_args); |
| 689 | 791 | $attached_size = (int)$output->data->attached_size + filesize($file_info['tmp_name']); |
| 690 | - if($attached_size > $allowed_attach_size) return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 792 | + if($attached_size > $allowed_attach_size) { |
|
| 793 | + return new Object(-1, 'msg_exceeds_limit_size'); |
|
| 794 | + } |
|
| 691 | 795 | } |
| 692 | 796 | } |
| 693 | 797 | |
@@ -717,18 +821,21 @@ discard block |
||
| 717 | 821 | $idx++; |
| 718 | 822 | } |
| 719 | 823 | $direct_download = 'Y'; |
| 720 | - } |
|
| 721 | - else |
|
| 824 | + } else |
|
| 722 | 825 | { |
| 723 | 826 | $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl,3)); |
| 724 | 827 | $filename = $path.$random->createSecureSalt(32, 'hex'); |
| 725 | 828 | $direct_download = 'N'; |
| 726 | 829 | } |
| 727 | 830 | // Create a directory |
| 728 | - if(!FileHandler::makeDir($path)) return new Object(-1,'msg_not_permitted_create'); |
|
| 831 | + if(!FileHandler::makeDir($path)) { |
|
| 832 | + return new Object(-1,'msg_not_permitted_create'); |
|
| 833 | + } |
|
| 729 | 834 | |
| 730 | 835 | // Check uploaded file |
| 731 | - if(!checkUploadedFile($file_info['tmp_name'])) return new Object(-1,'msg_file_upload_error'); |
|
| 836 | + if(!checkUploadedFile($file_info['tmp_name'])) { |
|
| 837 | + return new Object(-1,'msg_file_upload_error'); |
|
| 838 | + } |
|
| 732 | 839 | |
| 733 | 840 | // Get random number generator |
| 734 | 841 | $random = new Password(); |
@@ -742,13 +849,14 @@ discard block |
||
| 742 | 849 | $filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
| 743 | 850 | @copy($file_info['tmp_name'], $filename); |
| 744 | 851 | } |
| 745 | - } |
|
| 746 | - else |
|
| 852 | + } else |
|
| 747 | 853 | { |
| 748 | 854 | if(!@move_uploaded_file($file_info['tmp_name'], $filename)) |
| 749 | 855 | { |
| 750 | 856 | $filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
| 751 | - if(!@move_uploaded_file($file_info['tmp_name'], $filename)) return new Object(-1,'msg_file_upload_error'); |
|
| 857 | + if(!@move_uploaded_file($file_info['tmp_name'], $filename)) { |
|
| 858 | + return new Object(-1,'msg_file_upload_error'); |
|
| 859 | + } |
|
| 752 | 860 | } |
| 753 | 861 | } |
| 754 | 862 | // Get member information |
@@ -769,10 +877,14 @@ discard block |
||
| 769 | 877 | $args->sid = $random->createSecureSalt(32, 'hex'); |
| 770 | 878 | |
| 771 | 879 | $output = executeQuery('file.insertFile', $args); |
| 772 | - if(!$output->toBool()) return $output; |
|
| 880 | + if(!$output->toBool()) { |
|
| 881 | + return $output; |
|
| 882 | + } |
|
| 773 | 883 | // Call a trigger (after) |
| 774 | 884 | $trigger_output = ModuleHandler::triggerCall('file.insertFile', 'after', $args); |
| 775 | - if(!$trigger_output->toBool()) return $trigger_output; |
|
| 885 | + if(!$trigger_output->toBool()) { |
|
| 886 | + return $trigger_output; |
|
| 887 | + } |
|
| 776 | 888 | |
| 777 | 889 | $_SESSION['__XE_UPLOADING_FILES_INFO__'][$args->file_srl] = true; |
| 778 | 890 | |
@@ -815,10 +927,14 @@ discard block |
||
| 815 | 927 | */ |
| 816 | 928 | function deleteFile($file_srl) |
| 817 | 929 | { |
| 818 | - if(!$file_srl) return; |
|
| 930 | + if(!$file_srl) { |
|
| 931 | + return; |
|
| 932 | + } |
|
| 819 | 933 | |
| 820 | 934 | $srls = (is_array($file_srl)) ? $file_srl : explode(',', $file_srl); |
| 821 | - if(!count($srls)) return; |
|
| 935 | + if(!count($srls)) { |
|
| 936 | + return; |
|
| 937 | + } |
|
| 822 | 938 | |
| 823 | 939 | $oDocumentController = getController('document'); |
| 824 | 940 | $documentSrlList = array(); |
@@ -853,15 +969,21 @@ discard block |
||
| 853 | 969 | // Call a trigger (before) |
| 854 | 970 | $trigger_obj = $output->data; |
| 855 | 971 | $output = ModuleHandler::triggerCall('file.deleteFile', 'before', $trigger_obj); |
| 856 | - if(!$output->toBool()) return $output; |
|
| 972 | + if(!$output->toBool()) { |
|
| 973 | + return $output; |
|
| 974 | + } |
|
| 857 | 975 | |
| 858 | 976 | // Remove from the DB |
| 859 | 977 | $output = executeQuery('file.deleteFile', $args); |
| 860 | - if(!$output->toBool()) return $output; |
|
| 978 | + if(!$output->toBool()) { |
|
| 979 | + return $output; |
|
| 980 | + } |
|
| 861 | 981 | |
| 862 | 982 | // Call a trigger (after) |
| 863 | 983 | $trigger_output = ModuleHandler::triggerCall('file.deleteFile', 'after', $trigger_obj); |
| 864 | - if(!$trigger_output->toBool()) return $trigger_output; |
|
| 984 | + if(!$trigger_output->toBool()) { |
|
| 985 | + return $trigger_output; |
|
| 986 | + } |
|
| 865 | 987 | |
| 866 | 988 | // If successfully deleted, remove the file |
| 867 | 989 | FileHandler::removeFile($uploaded_filename); |
@@ -885,7 +1007,9 @@ discard block |
||
| 885 | 1007 | $columnList = array('file_srl', 'uploaded_filename', 'module_srl'); |
| 886 | 1008 | $file_list = $oFileModel->getFiles($upload_target_srl, $columnList); |
| 887 | 1009 | // Success returned if no attachement exists |
| 888 | - if(!is_array($file_list)||!count($file_list)) return new Object(); |
|
| 1010 | + if(!is_array($file_list)||!count($file_list)) { |
|
| 1011 | + return new Object(); |
|
| 1012 | + } |
|
| 889 | 1013 | |
| 890 | 1014 | // Delete the file |
| 891 | 1015 | $path = array(); |
@@ -896,14 +1020,18 @@ discard block |
||
| 896 | 1020 | |
| 897 | 1021 | $uploaded_filename = $file_list[$i]->uploaded_filename; |
| 898 | 1022 | $path_info = pathinfo($uploaded_filename); |
| 899 | - if(!in_array($path_info['dirname'], $path)) $path[] = $path_info['dirname']; |
|
| 1023 | + if(!in_array($path_info['dirname'], $path)) { |
|
| 1024 | + $path[] = $path_info['dirname']; |
|
| 1025 | + } |
|
| 900 | 1026 | } |
| 901 | 1027 | |
| 902 | 1028 | // Remove from the DB |
| 903 | 1029 | $args = new stdClass(); |
| 904 | 1030 | $args->upload_target_srl = $upload_target_srl; |
| 905 | 1031 | $output = executeQuery('file.deleteFiles', $args); |
| 906 | - if(!$output->toBool()) return $output; |
|
| 1032 | + if(!$output->toBool()) { |
|
| 1033 | + return $output; |
|
| 1034 | + } |
|
| 907 | 1035 | |
| 908 | 1036 | // Remove a file directory of the document |
| 909 | 1037 | for($i=0, $c=count($path); $i<$c; $i++) |
@@ -924,11 +1052,15 @@ discard block |
||
| 924 | 1052 | */ |
| 925 | 1053 | function moveFile($source_srl, $target_module_srl, $target_srl) |
| 926 | 1054 | { |
| 927 | - if($source_srl == $target_srl) return; |
|
| 1055 | + if($source_srl == $target_srl) { |
|
| 1056 | + return; |
|
| 1057 | + } |
|
| 928 | 1058 | |
| 929 | 1059 | $oFileModel = getModel('file'); |
| 930 | 1060 | $file_list = $oFileModel->getFiles($source_srl); |
| 931 | - if(!$file_list) return; |
|
| 1061 | + if(!$file_list) { |
|
| 1062 | + return; |
|
| 1063 | + } |
|
| 932 | 1064 | |
| 933 | 1065 | $file_count = count($file_list); |
| 934 | 1066 | |
@@ -942,15 +1074,16 @@ discard block |
||
| 942 | 1074 | { |
| 943 | 1075 | $path = sprintf("./files/attach/images/%s/%s/", $target_module_srl,$target_srl); |
| 944 | 1076 | $new_file = $path.$file_info->source_filename; |
| 945 | - } |
|
| 946 | - else |
|
| 1077 | + } else |
|
| 947 | 1078 | { |
| 948 | 1079 | $path = sprintf("./files/attach/binaries/%s/%s/", $target_module_srl, $target_srl); |
| 949 | 1080 | $random = new Password(); |
| 950 | 1081 | $new_file = $path.$random->createSecureSalt(32, 'hex'); |
| 951 | 1082 | } |
| 952 | 1083 | // Pass if a target document to move is same |
| 953 | - if($old_file == $new_file) continue; |
|
| 1084 | + if($old_file == $new_file) { |
|
| 1085 | + continue; |
|
| 1086 | + } |
|
| 954 | 1087 | // Create a directory |
| 955 | 1088 | FileHandler::makeDir($path); |
| 956 | 1089 | // Move the file |
@@ -970,16 +1103,22 @@ discard block |
||
| 970 | 1103 | $vars = Context::getRequestVars(); |
| 971 | 1104 | $logged_info = Context::get('logged_info'); |
| 972 | 1105 | |
| 973 | - if(!$vars->editor_sequence) return new Object(-1, 'msg_invalid_request'); |
|
| 1106 | + if(!$vars->editor_sequence) { |
|
| 1107 | + return new Object(-1, 'msg_invalid_request'); |
|
| 1108 | + } |
|
| 974 | 1109 | |
| 975 | 1110 | $upload_target_srl = $_SESSION['upload_info'][$vars->editor_sequence]->upload_target_srl; |
| 976 | 1111 | |
| 977 | 1112 | $oFileModel = getModel('file'); |
| 978 | 1113 | $file_info = $oFileModel->getFile($vars->file_srl); |
| 979 | 1114 | |
| 980 | - if(!$file_info) return new Object(-1, 'msg_not_founded'); |
|
| 1115 | + if(!$file_info) { |
|
| 1116 | + return new Object(-1, 'msg_not_founded'); |
|
| 1117 | + } |
|
| 981 | 1118 | |
| 982 | - if(!$this->manager && !$file_info->member_srl === $logged_info->member_srl) return new Object(-1, 'msg_not_permitted'); |
|
| 1119 | + if(!$this->manager && !$file_info->member_srl === $logged_info->member_srl) { |
|
| 1120 | + return new Object(-1, 'msg_not_permitted'); |
|
| 1121 | + } |
|
| 983 | 1122 | |
| 984 | 1123 | $args = new stdClass(); |
| 985 | 1124 | $args->file_srl = $vars->file_srl; |