Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like fileController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use fileController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class fileController extends file |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Initialization |
||
| 11 | * @return void |
||
| 12 | */ |
||
| 13 | function init() |
||
| 14 | { |
||
| 15 | } |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Upload attachments in the editor |
||
| 19 | * |
||
| 20 | * Determine the upload target srl from editor_sequence and uploadTargetSrl variables. |
||
| 21 | * Create and return the UploadTargetSrl if not exists so that UI can use the value |
||
| 22 | * for sync. |
||
| 23 | * |
||
| 24 | * @return void |
||
| 25 | */ |
||
| 26 | function procFileUpload() |
||
| 27 | { |
||
| 28 | Context::setRequestMethod('JSON'); |
||
| 29 | $file_info = $_FILES['Filedata']; |
||
| 30 | |||
| 31 | // An error appears if not a normally uploaded file |
||
| 32 | if(!is_uploaded_file($file_info['tmp_name'])) exit(); |
||
| 33 | |||
| 34 | // Basic variables setting |
||
| 35 | $oFileModel = getModel('file'); |
||
|
|
|||
| 36 | $editor_sequence = Context::get('editor_sequence'); |
||
| 37 | $upload_target_srl = intval(Context::get('uploadTargetSrl')); |
||
| 38 | if(!$upload_target_srl) $upload_target_srl = intval(Context::get('upload_target_srl')); |
||
| 39 | $module_srl = $this->module_srl; |
||
| 40 | // Exit a session if there is neither upload permission nor information |
||
| 41 | if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
||
| 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; |
||
| 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(); |
||
| 46 | |||
| 47 | $output = $this->insertFile($file_info, $module_srl, $upload_target_srl); |
||
| 48 | Context::setResponseMethod('JSON'); |
||
| 49 | if($output->error != '0') $this->stop($output->message); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Iframe upload attachments |
||
| 54 | * |
||
| 55 | * @return Object |
||
| 56 | */ |
||
| 57 | function procFileIframeUpload() |
||
| 58 | { |
||
| 59 | // Basic variables setting |
||
| 60 | $editor_sequence = Context::get('editor_sequence'); |
||
| 61 | $callback = Context::get('callback'); |
||
| 62 | $module_srl = $this->module_srl; |
||
| 63 | $upload_target_srl = intval(Context::get('uploadTargetSrl')); |
||
| 64 | if(!$upload_target_srl) $upload_target_srl = intval(Context::get('upload_target_srl')); |
||
| 65 | |||
| 66 | // Exit a session if there is neither upload permission nor information |
||
| 67 | if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
||
| 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; |
||
| 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(); |
||
| 72 | // Delete and then attempt to re-upload if file_srl is requested |
||
| 73 | $file_srl = Context::get('file_srl'); |
||
| 74 | if($file_srl) $this->deleteFile($file_srl); |
||
| 75 | |||
| 76 | $file_info = Context::get('Filedata'); |
||
| 77 | // An error appears if not a normally uploaded file |
||
| 78 | if(is_uploaded_file($file_info['tmp_name'])) { |
||
| 79 | $output = $this->insertFile($file_info, $module_srl, $upload_target_srl); |
||
| 80 | Context::set('uploaded_fileinfo',$output); |
||
| 81 | } |
||
| 82 | |||
| 83 | Context::set('layout','none'); |
||
| 84 | |||
| 85 | $this->setTemplatePath($this->module_path.'tpl'); |
||
| 86 | $this->setTemplateFile('iframe'); |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Image resize |
||
| 91 | * |
||
| 92 | * @return Object |
||
| 93 | */ |
||
| 94 | function procFileImageResize() |
||
| 95 | { |
||
| 96 | $file_srl = Context::get('file_srl'); |
||
| 97 | $width = Context::get('width'); |
||
| 98 | $height = Context::get('height'); |
||
| 99 | |||
| 100 | if(!$file_srl || !$width) |
||
| 101 | { |
||
| 102 | return new Object(-1,'msg_invalid_request'); |
||
| 103 | } |
||
| 104 | |||
| 105 | $oFileModel = getModel('file'); |
||
| 106 | $fileInfo = $oFileModel->getFile($file_srl); |
||
| 107 | if(!$fileInfo || $fileInfo->direct_download != 'Y') |
||
| 108 | { |
||
| 109 | return new Object(-1,'msg_invalid_request'); |
||
| 110 | } |
||
| 111 | |||
| 112 | $source_src = $fileInfo->uploaded_filename; |
||
| 113 | $output_src = $source_src . '.resized' . strrchr($source_src,'.'); |
||
| 114 | |||
| 115 | if(!$height) $height = $width-1; |
||
| 116 | |||
| 117 | if(FileHandler::createImageFile($source_src,$output_src,$width,$height,'','ratio')) |
||
| 118 | { |
||
| 119 | $output = new stdClass(); |
||
| 120 | $output->info = getimagesize($output_src); |
||
| 121 | $output->src = $output_src; |
||
| 122 | } |
||
| 123 | else |
||
| 124 | { |
||
| 125 | return new Object(-1,'msg_invalid_request'); |
||
| 126 | } |
||
| 127 | |||
| 128 | $this->add('resized_info',$output); |
||
| 129 | } |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Download Attachment |
||
| 133 | * |
||
| 134 | * <pre> |
||
| 135 | * Receive a request directly |
||
| 136 | * file_srl: File sequence |
||
| 137 | * sid : value in DB for comparison, No download if not matched |
||
| 138 | * |
||
| 139 | * This method call trigger 'file.downloadFile'. |
||
| 140 | * before, after. |
||
| 141 | * Trigger object contains: |
||
| 142 | * - download_url |
||
| 143 | * - file_srl |
||
| 144 | * - upload_target_srl |
||
| 145 | * - upload_target_type |
||
| 146 | * - sid |
||
| 147 | * - module_srl |
||
| 148 | * - member_srl |
||
| 149 | * - download_count |
||
| 150 | * - direct_download |
||
| 151 | * - source_filename |
||
| 152 | * - uploaded_filename |
||
| 153 | * - file_size |
||
| 154 | * - comment |
||
| 155 | * - isvalid |
||
| 156 | * - regdate |
||
| 157 | * - ipaddress |
||
| 158 | * </pre> |
||
| 159 | * |
||
| 160 | * return void |
||
| 161 | */ |
||
| 162 | function procFileDownload() |
||
| 163 | { |
||
| 164 | $oFileModel = getModel('file'); |
||
| 165 | |||
| 166 | if(isset($this->grant->access) && $this->grant->access !== true) return new Object(-1, 'msg_not_permitted'); |
||
| 167 | |||
| 168 | $file_srl = Context::get('file_srl'); |
||
| 169 | $sid = Context::get('sid'); |
||
| 170 | $logged_info = Context::get('logged_info'); |
||
| 171 | // Get file information from the DB |
||
| 172 | $columnList = array('file_srl', 'sid', 'isvalid', 'source_filename', 'module_srl', 'uploaded_filename', 'file_size', 'member_srl', 'upload_target_srl', 'upload_target_type'); |
||
| 173 | $file_obj = $oFileModel->getFile($file_srl, $columnList); |
||
| 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'); |
||
| 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'); |
||
| 178 | // File name |
||
| 179 | $filename = $file_obj->source_filename; |
||
| 180 | $file_module_config = $oFileModel->getFileModuleConfig($file_obj->module_srl); |
||
| 181 | // Not allow the file outlink |
||
| 182 | if($file_module_config->allow_outlink == 'N') |
||
| 183 | { |
||
| 184 | // Handles extension to allow outlink |
||
| 185 | View Code Duplication | if($file_module_config->allow_outlink_format) |
|
| 186 | { |
||
| 187 | $allow_outlink_format_array = array(); |
||
| 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; |
||
| 190 | |||
| 191 | foreach($allow_outlink_format_array as $val) |
||
| 192 | { |
||
| 193 | $val = trim($val); |
||
| 194 | if(preg_match("/\.{$val}$/i", $filename)) |
||
| 195 | { |
||
| 196 | $file_module_config->allow_outlink = 'Y'; |
||
| 197 | break; |
||
| 198 | } |
||
| 199 | } |
||
| 200 | } |
||
| 201 | // Sites that outlink is allowed |
||
| 202 | if($file_module_config->allow_outlink != 'Y') |
||
| 203 | { |
||
| 204 | $referer = parse_url($_SERVER["HTTP_REFERER"]); |
||
| 205 | if($referer['host'] != $_SERVER['HTTP_HOST']) |
||
| 206 | { |
||
| 207 | View Code Duplication | if($file_module_config->allow_outlink_site) |
|
| 208 | { |
||
| 209 | $allow_outlink_site_array = array(); |
||
| 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; |
||
| 212 | |||
| 213 | foreach($allow_outlink_site_array as $val) |
||
| 214 | { |
||
| 215 | $site = parse_url(trim($val)); |
||
| 216 | if($site['host'] == $referer['host']) |
||
| 217 | { |
||
| 218 | $file_module_config->allow_outlink = 'Y'; |
||
| 219 | break; |
||
| 220 | } |
||
| 221 | } |
||
| 222 | } |
||
| 223 | } |
||
| 224 | else $file_module_config->allow_outlink = 'Y'; |
||
| 225 | } |
||
| 226 | if($file_module_config->allow_outlink != 'Y') return $this->stop('msg_not_allowed_outlink'); |
||
| 227 | } |
||
| 228 | |||
| 229 | // Check if a permission for file download is granted |
||
| 230 | $downloadGrantCount = 0; |
||
| 231 | if(is_array($file_module_config->download_grant)) |
||
| 232 | { |
||
| 233 | foreach($file_module_config->download_grant AS $value) |
||
| 234 | if($value) $downloadGrantCount++; |
||
| 235 | } |
||
| 236 | |||
| 237 | View Code Duplication | if(is_array($file_module_config->download_grant) && $downloadGrantCount>0) |
|
| 238 | { |
||
| 239 | if(!Context::get('is_logged')) return $this->stop('msg_not_permitted_download'); |
||
| 240 | $logged_info = Context::get('logged_info'); |
||
| 241 | if($logged_info->is_admin != 'Y') |
||
| 242 | { |
||
| 243 | $oModuleModel =& getModel('module'); |
||
| 244 | $columnList = array('module_srl', 'site_srl'); |
||
| 245 | $module_info = $oModuleModel->getModuleInfoByModuleSrl($file_obj->module_srl, $columnList); |
||
| 246 | |||
| 247 | if(!$oModuleModel->isSiteAdmin($logged_info, $module_info->site_srl)) |
||
| 248 | { |
||
| 249 | $oMemberModel =& getModel('member'); |
||
| 250 | $member_groups = $oMemberModel->getMemberGroups($logged_info->member_srl, $module_info->site_srl); |
||
| 251 | |||
| 252 | $is_permitted = false; |
||
| 253 | for($i=0;$i<count($file_module_config->download_grant);$i++) |
||
| 254 | { |
||
| 255 | $group_srl = $file_module_config->download_grant[$i]; |
||
| 256 | if($member_groups[$group_srl]) |
||
| 257 | { |
||
| 258 | $is_permitted = true; |
||
| 259 | break; |
||
| 260 | } |
||
| 261 | } |
||
| 262 | if(!$is_permitted) return $this->stop('msg_not_permitted_download'); |
||
| 263 | } |
||
| 264 | } |
||
| 265 | } |
||
| 266 | // Call a trigger (before) |
||
| 267 | $output = ModuleHandler::triggerCall('file.downloadFile', 'before', $file_obj); |
||
| 268 | if(!$output->toBool()) return $this->stop(($output->message)?$output->message:'msg_not_permitted_download'); |
||
| 269 | |||
| 270 | |||
| 271 | // 다운로드 후 (가상) |
||
| 272 | // Increase download_count |
||
| 273 | $args = new stdClass(); |
||
| 274 | $args->file_srl = $file_srl; |
||
| 275 | executeQuery('file.updateFileDownloadCount', $args); |
||
| 276 | // Call a trigger (after) |
||
| 277 | $output = ModuleHandler::triggerCall('file.downloadFile', 'after', $file_obj); |
||
| 278 | |||
| 279 | $random = new Password(); |
||
| 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)); |
||
| 282 | Context::close(); |
||
| 283 | exit(); |
||
| 284 | |||
| 285 | } |
||
| 286 | |||
| 287 | public function procFileOutput() |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Delete an attachment from the editor |
||
| 367 | * |
||
| 368 | * @return Object |
||
| 369 | */ |
||
| 370 | function procFileDelete() |
||
| 371 | { |
||
| 372 | // Basic variable setting(upload_target_srl and module_srl set) |
||
| 373 | $editor_sequence = Context::get('editor_sequence'); |
||
| 374 | $file_srl = Context::get('file_srl'); |
||
| 375 | $file_srls = Context::get('file_srls'); |
||
| 376 | if($file_srls) $file_srl = $file_srls; |
||
| 377 | // Exit a session if there is neither upload permission nor information |
||
| 378 | if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
||
| 379 | |||
| 380 | $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
||
| 381 | |||
| 382 | $logged_info = Context::get('logged_info'); |
||
| 383 | $oFileModel = getModel('file'); |
||
| 384 | |||
| 385 | $srls = explode(',',$file_srl); |
||
| 386 | if(!count($srls)) return; |
||
| 387 | |||
| 388 | for($i=0;$i<count($srls);$i++) |
||
| 389 | { |
||
| 390 | $srl = (int)$srls[$i]; |
||
| 391 | if(!$srl) continue; |
||
| 392 | |||
| 393 | $args = new stdClass; |
||
| 394 | $args->file_srl = $srl; |
||
| 395 | $output = executeQuery('file.getFile', $args); |
||
| 396 | if(!$output->toBool()) continue; |
||
| 397 | |||
| 398 | $file_info = $output->data; |
||
| 399 | if(!$file_info) continue; |
||
| 400 | |||
| 401 | $file_grant = $oFileModel->getFileGrant($file_info, $logged_info); |
||
| 402 | |||
| 403 | if(!$file_grant->is_deletable) continue; |
||
| 404 | |||
| 405 | if($upload_target_srl && $file_srl) $output = $this->deleteFile($file_srl); |
||
| 406 | } |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * get file list |
||
| 411 | * |
||
| 412 | * @return Object |
||
| 413 | */ |
||
| 414 | function procFileGetList() |
||
| 415 | { |
||
| 416 | if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted'); |
||
| 417 | $fileSrls = Context::get('file_srls'); |
||
| 418 | if($fileSrls) $fileSrlList = explode(',', $fileSrls); |
||
| 419 | |||
| 420 | global $lang; |
||
| 421 | if(count($fileSrlList) > 0) |
||
| 422 | { |
||
| 423 | $oFileModel = getModel('file'); |
||
| 424 | $fileList = $oFileModel->getFile($fileSrlList); |
||
| 425 | if(!is_array($fileList)) $fileList = array($fileList); |
||
| 426 | |||
| 427 | if(is_array($fileList)) |
||
| 428 | { |
||
| 429 | foreach($fileList AS $key=>$value) |
||
| 430 | { |
||
| 431 | $value->human_file_size = FileHandler::filesize($value->file_size); |
||
| 432 | if($value->isvalid=='Y') $value->validName = $lang->is_valid; |
||
| 433 | else $value->validName = $lang->is_stand_by; |
||
| 434 | } |
||
| 435 | } |
||
| 436 | } |
||
| 437 | else |
||
| 438 | { |
||
| 439 | $fileList = array(); |
||
| 440 | $this->setMessage($lang->no_files); |
||
| 441 | } |
||
| 442 | |||
| 443 | $this->add('file_list', $fileList); |
||
| 444 | } |
||
| 445 | /** |
||
| 446 | * A trigger to return numbers of attachments in the upload_target_srl (document_srl) |
||
| 447 | * |
||
| 448 | * @param object $obj Trigger object |
||
| 449 | * @return Object |
||
| 450 | */ |
||
| 451 | View Code Duplication | function triggerCheckAttached(&$obj) |
|
| 452 | { |
||
| 453 | $document_srl = $obj->document_srl; |
||
| 454 | if(!$document_srl) return new Object(); |
||
| 455 | // Get numbers of attachments |
||
| 456 | $oFileModel = getModel('file'); |
||
| 457 | $obj->uploaded_count = $oFileModel->getFilesCount($document_srl); |
||
| 458 | |||
| 459 | return new Object(); |
||
| 460 | } |
||
| 461 | |||
| 462 | /** |
||
| 463 | * A trigger to link the attachment with the upload_target_srl (document_srl) |
||
| 464 | * |
||
| 465 | * @param object $obj Trigger object |
||
| 466 | * @return Object |
||
| 467 | */ |
||
| 468 | function triggerAttachFiles(&$obj) |
||
| 469 | { |
||
| 470 | $document_srl = $obj->document_srl; |
||
| 471 | if(!$document_srl) return new Object(); |
||
| 472 | |||
| 473 | $output = $this->setFilesValid($document_srl); |
||
| 474 | if(!$output->toBool()) return $output; |
||
| 475 | |||
| 476 | return new Object(); |
||
| 477 | } |
||
| 478 | |||
| 479 | /** |
||
| 480 | * A trigger to delete the attachment in the upload_target_srl (document_srl) |
||
| 481 | * |
||
| 482 | * @param object $obj Trigger object |
||
| 483 | * @return Object |
||
| 484 | */ |
||
| 485 | function triggerDeleteAttached(&$obj) |
||
| 486 | { |
||
| 487 | $document_srl = $obj->document_srl; |
||
| 488 | if(!$document_srl) return new Object(); |
||
| 489 | |||
| 490 | $output = $this->deleteFiles($document_srl); |
||
| 491 | return $output; |
||
| 492 | } |
||
| 493 | |||
| 494 | /** |
||
| 495 | * A trigger to return numbers of attachments in the upload_target_srl (comment_srl) |
||
| 496 | * |
||
| 497 | * @param object $obj Trigger object |
||
| 498 | * @return Object |
||
| 499 | */ |
||
| 500 | View Code Duplication | function triggerCommentCheckAttached(&$obj) |
|
| 501 | { |
||
| 502 | $comment_srl = $obj->comment_srl; |
||
| 503 | if(!$comment_srl) return new Object(); |
||
| 504 | // Get numbers of attachments |
||
| 505 | $oFileModel = getModel('file'); |
||
| 506 | $obj->uploaded_count = $oFileModel->getFilesCount($comment_srl); |
||
| 507 | |||
| 508 | return new Object(); |
||
| 509 | } |
||
| 510 | |||
| 511 | /** |
||
| 512 | * A trigger to link the attachment with the upload_target_srl (comment_srl) |
||
| 513 | * |
||
| 514 | * @param object $obj Trigger object |
||
| 515 | * @return Object |
||
| 516 | */ |
||
| 517 | function triggerCommentAttachFiles(&$obj) |
||
| 518 | { |
||
| 519 | $comment_srl = $obj->comment_srl; |
||
| 520 | $uploaded_count = $obj->uploaded_count; |
||
| 521 | if(!$comment_srl || !$uploaded_count) return new Object(); |
||
| 522 | |||
| 523 | $output = $this->setFilesValid($comment_srl); |
||
| 524 | if(!$output->toBool()) return $output; |
||
| 525 | |||
| 526 | return new Object(); |
||
| 527 | } |
||
| 528 | |||
| 529 | /** |
||
| 530 | * A trigger to delete the attachment in the upload_target_srl (comment_srl) |
||
| 531 | * |
||
| 532 | * @param object $obj Trigger object |
||
| 533 | * @return Object |
||
| 534 | */ |
||
| 535 | function triggerCommentDeleteAttached(&$obj) |
||
| 536 | { |
||
| 537 | $comment_srl = $obj->comment_srl; |
||
| 538 | if(!$comment_srl) return new Object(); |
||
| 539 | |||
| 540 | if($obj->isMoveToTrash) return new Object(); |
||
| 541 | |||
| 542 | $output = $this->deleteFiles($comment_srl); |
||
| 543 | return $output; |
||
| 544 | } |
||
| 545 | |||
| 546 | /** |
||
| 547 | * A trigger to delete all the attachements when deleting the module |
||
| 548 | * |
||
| 549 | * @param object $obj Trigger object |
||
| 550 | * @return Object |
||
| 551 | */ |
||
| 552 | function triggerDeleteModuleFiles(&$obj) |
||
| 553 | { |
||
| 554 | $module_srl = $obj->module_srl; |
||
| 555 | if(!$module_srl) return new Object(); |
||
| 556 | |||
| 557 | $oFileController = getAdminController('file'); |
||
| 558 | return $oFileController->deleteModuleFiles($module_srl); |
||
| 559 | } |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Upload enabled |
||
| 563 | * |
||
| 564 | * @param int $editor_sequence |
||
| 565 | * @param int $upload_target_srl |
||
| 566 | * @return void |
||
| 567 | */ |
||
| 568 | function setUploadInfo($editor_sequence, $upload_target_srl=0) |
||
| 569 | { |
||
| 570 | if(!isset($_SESSION['upload_info'][$editor_sequence])) |
||
| 571 | { |
||
| 572 | $_SESSION['upload_info'][$editor_sequence] = new stdClass(); |
||
| 573 | } |
||
| 574 | $_SESSION['upload_info'][$editor_sequence]->enabled = true; |
||
| 575 | $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl; |
||
| 576 | } |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Set the attachements of the upload_target_srl to be valid |
||
| 580 | * By changing its state to valid when a document is inserted, it prevents from being considered as a unnecessary file |
||
| 581 | * |
||
| 582 | * @param int $upload_target_srl |
||
| 583 | * @return Object |
||
| 584 | */ |
||
| 585 | function setFilesValid($upload_target_srl) |
||
| 586 | { |
||
| 587 | $args = new stdClass(); |
||
| 588 | $args->upload_target_srl = $upload_target_srl; |
||
| 589 | return executeQuery('file.updateFileValid', $args); |
||
| 590 | } |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Add an attachement |
||
| 594 | * |
||
| 595 | * <pre> |
||
| 596 | * This method call trigger 'file.insertFile'. |
||
| 597 | * |
||
| 598 | * Before trigger object contains: |
||
| 599 | * - module_srl |
||
| 600 | * - upload_target_srl |
||
| 601 | * |
||
| 602 | * After trigger object contains: |
||
| 603 | * - file_srl |
||
| 604 | * - upload_target_srl |
||
| 605 | * - module_srl |
||
| 606 | * - direct_download |
||
| 607 | * - source_filename |
||
| 608 | * - uploaded_filename |
||
| 609 | * - donwload_count |
||
| 610 | * - file_size |
||
| 611 | * - comment |
||
| 612 | * - member_srl |
||
| 613 | * - sid |
||
| 614 | * </pre> |
||
| 615 | * |
||
| 616 | * @param object $file_info PHP file information array |
||
| 617 | * @param int $module_srl Sequence of module to upload file |
||
| 618 | * @param int $upload_target_srl Sequence of target to upload file |
||
| 619 | * @param int $download_count Initial download count |
||
| 620 | * @param bool $manual_insert If set true, pass validation check |
||
| 621 | * @return Object |
||
| 622 | */ |
||
| 623 | function insertFile($file_info, $module_srl, $upload_target_srl, $download_count = 0, $manual_insert = false) |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Delete the attachment |
||
| 775 | * |
||
| 776 | * <pre> |
||
| 777 | * This method call trigger 'file.deleteFile'. |
||
| 778 | * Before, after trigger object contains: |
||
| 779 | * - download_url |
||
| 780 | * - file_srl |
||
| 781 | * - upload_target_srl |
||
| 782 | * - upload_target_type |
||
| 783 | * - sid |
||
| 784 | * - module_srl |
||
| 785 | * - member_srl |
||
| 786 | * - download_count |
||
| 787 | * - direct_download |
||
| 788 | * - source_filename |
||
| 789 | * - uploaded_filename |
||
| 790 | * - file_size |
||
| 791 | * - comment |
||
| 792 | * - isvalid |
||
| 793 | * - regdate |
||
| 794 | * - ipaddress |
||
| 795 | * </pre> |
||
| 796 | * |
||
| 797 | * @param int $file_srl Sequence of file to delete |
||
| 798 | * @return Object |
||
| 799 | */ |
||
| 800 | function deleteFile($file_srl) |
||
| 858 | |||
| 859 | /** |
||
| 860 | * Delete all attachments of a particular document |
||
| 861 | * |
||
| 862 | * @param int $upload_target_srl Upload target srl to delete files |
||
| 863 | * @return Object |
||
| 864 | */ |
||
| 865 | function deleteFiles($upload_target_srl) |
||
| 900 | |||
| 901 | /** |
||
| 902 | * Move an attachement to the other document |
||
| 903 | * |
||
| 904 | * @param int $source_srl Sequence of target to move |
||
| 905 | * @param int $target_module_srl New squence of module |
||
| 906 | * @param int $target_srl New sequence of target |
||
| 907 | * @return void |
||
| 908 | */ |
||
| 909 | function moveFile($source_srl, $target_module_srl, $target_srl) |
||
| 951 | |||
| 952 | public function procFileSetCoverImage() |
||
| 997 | |||
| 998 | /** |
||
| 999 | * Find the attachment where a key is upload_target_srl and then return java script code |
||
| 1000 | * |
||
| 1001 | * @deprecated |
||
| 1002 | * @param int $editor_sequence |
||
| 1003 | * @param int $upload_target_srl |
||
| 1004 | * @return void |
||
| 1005 | */ |
||
| 1006 | function printUploadedFileList($editor_sequence, $upload_target_srl) |
||
| 1010 | |||
| 1011 | View Code Duplication | function triggerCopyModule(&$obj) |
|
| 1025 | } |
||
| 1026 | /* End of file file.controller.php */ |
||
| 1029 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.