1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) XEHub <https://www.xehub.io> */ |
3
|
|
|
/** |
4
|
|
|
* Controller class of the file module |
5
|
|
|
* @author XEHub ([email protected]) |
6
|
|
|
*/ |
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 = Context::get('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
|
|
|
$this->add('file_srl',$output->get('file_srl')); |
50
|
|
|
$this->add('file_size',$output->get('file_size')); |
51
|
|
|
$this->add('direct_download',$output->get('direct_download')); |
52
|
|
|
$this->add('source_filename',$output->get('source_filename')); |
53
|
|
|
$this->add('upload_target_srl',$output->get('upload_target_srl')); |
54
|
|
|
$this->add('download_url',$output->get('uploaded_filename')); |
55
|
|
|
|
56
|
|
|
if($output->get('direct_download') === 'Y') |
57
|
|
|
{ |
58
|
|
|
$this->add('download_url',$output->get('uploaded_filename')); |
59
|
|
|
} |
60
|
|
|
else |
61
|
|
|
{ |
62
|
|
|
$this->add('download_url',$oFileModel->getDownloadUrl($output->get('file_srl'), $output->get('sid'), $module_srl)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if($output->error != '0') { |
66
|
|
|
$this->stop($output->message); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Iframe upload attachments |
72
|
|
|
* |
73
|
|
|
* @return BaseObject |
74
|
|
|
*/ |
75
|
|
|
function procFileIframeUpload() |
76
|
|
|
{ |
77
|
|
|
// Basic variables setting |
78
|
|
|
$editor_sequence = Context::get('editor_sequence'); |
79
|
|
|
$callback = Context::get('callback'); |
|
|
|
|
80
|
|
|
$module_srl = $this->module_srl; |
81
|
|
|
$upload_target_srl = intval(Context::get('uploadTargetSrl')); |
82
|
|
|
if(!$upload_target_srl) $upload_target_srl = intval(Context::get('upload_target_srl')); |
83
|
|
|
|
84
|
|
|
// Exit a session if there is neither upload permission nor information |
85
|
|
|
if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
86
|
|
|
// Extract from session information if upload_target_srl is not specified |
87
|
|
|
if(!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
88
|
|
|
// Create if upload_target_srl is not defined in the session information |
89
|
|
|
if(!$upload_target_srl) $_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl = getNextSequence(); |
90
|
|
|
|
91
|
|
|
// Delete and then attempt to re-upload if file_srl is requested |
92
|
|
|
$file_srl = Context::get('file_srl'); |
93
|
|
|
if($file_srl) |
94
|
|
|
{ |
95
|
|
|
$oFileModel = getModel('file'); |
96
|
|
|
$logged_info = Context::get('logged_info'); |
97
|
|
|
$file_info = $oFileModel->getFile($file_srl); |
98
|
|
|
$file_grant = $oFileModel->getFileGrant($file_info, $logged_info); |
99
|
|
|
if($file_info->file_srl == $file_srl && $file_grant->is_deletable) |
100
|
|
|
{ |
101
|
|
|
$this->deleteFile($file_srl); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$file_info = Context::get('Filedata'); |
106
|
|
|
// An error appears if not a normally uploaded file |
107
|
|
|
if(is_uploaded_file($file_info['tmp_name'])) { |
108
|
|
|
$output = $this->insertFile($file_info, $module_srl, $upload_target_srl); |
|
|
|
|
109
|
|
|
Context::set('uploaded_fileinfo',$output); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
Context::set('layout','none'); |
113
|
|
|
|
114
|
|
|
$this->setTemplatePath($this->module_path.'tpl'); |
115
|
|
|
$this->setTemplateFile('iframe'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Image resize |
120
|
|
|
* |
121
|
|
|
* @return BaseObject |
122
|
|
|
*/ |
123
|
|
|
function procFileImageResize() |
124
|
|
|
{ |
125
|
|
|
$file_srl = Context::get('file_srl'); |
126
|
|
|
$width = Context::get('width'); |
127
|
|
|
$height = Context::get('height'); |
128
|
|
|
|
129
|
|
|
if(!$file_srl || !$width) |
130
|
|
|
{ |
131
|
|
|
return new BaseObject(-1,'msg_invalid_request'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$oFileModel = getModel('file'); |
135
|
|
|
$fileInfo = $oFileModel->getFile($file_srl); |
136
|
|
|
if(!$fileInfo || $fileInfo->direct_download != 'Y') |
137
|
|
|
{ |
138
|
|
|
return new BaseObject(-1,'msg_invalid_request'); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
$source_src = $fileInfo->uploaded_filename; |
142
|
|
|
$output_src = $source_src . '.resized' . strrchr($source_src,'.'); |
143
|
|
|
|
144
|
|
|
if(!$height) $height = $width-1; |
145
|
|
|
|
146
|
|
|
if(FileHandler::createImageFile($source_src,$output_src,$width,$height,'','ratio')) |
147
|
|
|
{ |
148
|
|
|
$output = new stdClass(); |
149
|
|
|
$output->info = getimagesize($output_src); |
150
|
|
|
$output->src = $output_src; |
151
|
|
|
} |
152
|
|
|
else |
153
|
|
|
{ |
154
|
|
|
return new BaseObject(-1,'msg_invalid_request'); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$this->add('resized_info',$output); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Download Attachment |
162
|
|
|
* |
163
|
|
|
* <pre> |
164
|
|
|
* Receive a request directly |
165
|
|
|
* file_srl: File sequence |
166
|
|
|
* sid : value in DB for comparison, No download if not matched |
167
|
|
|
* |
168
|
|
|
* This method call trigger 'file.downloadFile'. |
169
|
|
|
* before, after. |
170
|
|
|
* Trigger object contains: |
171
|
|
|
* - download_url |
172
|
|
|
* - file_srl |
173
|
|
|
* - upload_target_srl |
174
|
|
|
* - upload_target_type |
175
|
|
|
* - sid |
176
|
|
|
* - module_srl |
177
|
|
|
* - member_srl |
178
|
|
|
* - download_count |
179
|
|
|
* - direct_download |
180
|
|
|
* - source_filename |
181
|
|
|
* - uploaded_filename |
182
|
|
|
* - file_size |
183
|
|
|
* - comment |
184
|
|
|
* - isvalid |
185
|
|
|
* - regdate |
186
|
|
|
* - ipaddress |
187
|
|
|
* </pre> |
188
|
|
|
* |
189
|
|
|
* return void |
190
|
|
|
*/ |
191
|
|
|
function procFileDownload() |
192
|
|
|
{ |
193
|
|
|
$oFileModel = getModel('file'); |
194
|
|
|
|
195
|
|
|
if(isset($this->grant->access) && $this->grant->access !== true) return new BaseObject(-1, 'msg_not_permitted'); |
|
|
|
|
196
|
|
|
|
197
|
|
|
$file_srl = Context::get('file_srl'); |
198
|
|
|
$sid = Context::get('sid'); |
199
|
|
|
$logged_info = Context::get('logged_info'); |
200
|
|
|
// Get file information from the DB |
201
|
|
|
$columnList = array('file_srl', 'sid', 'isvalid', 'source_filename', 'module_srl', 'uploaded_filename', 'file_size', 'member_srl', 'upload_target_srl', 'upload_target_type'); |
202
|
|
|
$file_obj = $oFileModel->getFile($file_srl, $columnList); |
203
|
|
|
// If the requested file information is incorrect, an error that file cannot be found appears |
204
|
|
|
if($file_obj->file_srl!=$file_srl || $file_obj->sid!=$sid) return $this->stop('msg_file_not_found'); |
205
|
|
|
// Notify that file download is not allowed when standing-by(Only a top-administrator is permitted) |
206
|
|
|
if($logged_info->is_admin != 'Y' && $file_obj->isvalid!='Y') return $this->stop('msg_not_permitted_download'); |
207
|
|
|
// File name |
208
|
|
|
$filename = $file_obj->source_filename; |
209
|
|
|
$file_module_config = $oFileModel->getFileModuleConfig($file_obj->module_srl); |
210
|
|
|
// Not allow the file outlink |
211
|
|
|
if($file_module_config->allow_outlink == 'N') |
212
|
|
|
{ |
213
|
|
|
// Handles extension to allow outlink |
214
|
|
View Code Duplication |
if($file_module_config->allow_outlink_format) |
215
|
|
|
{ |
216
|
|
|
$allow_outlink_format_array = array(); |
|
|
|
|
217
|
|
|
$allow_outlink_format_array = explode(',', $file_module_config->allow_outlink_format); |
218
|
|
|
if(!is_array($allow_outlink_format_array)) $allow_outlink_format_array[0] = $file_module_config->allow_outlink_format; |
219
|
|
|
|
220
|
|
|
foreach($allow_outlink_format_array as $val) |
221
|
|
|
{ |
222
|
|
|
$val = trim($val); |
223
|
|
|
if(preg_match("/\.{$val}$/i", $filename)) |
224
|
|
|
{ |
225
|
|
|
$file_module_config->allow_outlink = 'Y'; |
226
|
|
|
break; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
// Sites that outlink is allowed |
231
|
|
|
if($file_module_config->allow_outlink != 'Y') |
232
|
|
|
{ |
233
|
|
|
$referer = parse_url($_SERVER["HTTP_REFERER"]); |
234
|
|
|
if($referer['host'] != $_SERVER['HTTP_HOST']) |
235
|
|
|
{ |
236
|
|
View Code Duplication |
if($file_module_config->allow_outlink_site) |
237
|
|
|
{ |
238
|
|
|
$allow_outlink_site_array = array(); |
|
|
|
|
239
|
|
|
$allow_outlink_site_array = explode("\n", $file_module_config->allow_outlink_site); |
240
|
|
|
if(!is_array($allow_outlink_site_array)) $allow_outlink_site_array[0] = $file_module_config->allow_outlink_site; |
241
|
|
|
|
242
|
|
|
foreach($allow_outlink_site_array as $val) |
243
|
|
|
{ |
244
|
|
|
$site = parse_url(trim($val)); |
245
|
|
|
if($site['host'] == $referer['host']) |
246
|
|
|
{ |
247
|
|
|
$file_module_config->allow_outlink = 'Y'; |
248
|
|
|
break; |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
else $file_module_config->allow_outlink = 'Y'; |
254
|
|
|
} |
255
|
|
|
if($file_module_config->allow_outlink != 'Y') return $this->stop('msg_not_allowed_outlink'); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
// Check if a permission for file download is granted |
259
|
|
|
$downloadGrantCount = 0; |
260
|
|
|
if(is_array($file_module_config->download_grant)) |
261
|
|
|
{ |
262
|
|
|
foreach($file_module_config->download_grant AS $value) |
263
|
|
|
if($value) $downloadGrantCount++; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
View Code Duplication |
if(is_array($file_module_config->download_grant) && $downloadGrantCount>0) |
267
|
|
|
{ |
268
|
|
|
if(!Context::get('is_logged')) return $this->stop('msg_not_permitted_download'); |
269
|
|
|
$logged_info = Context::get('logged_info'); |
270
|
|
|
if($logged_info->is_admin != 'Y') |
271
|
|
|
{ |
272
|
|
|
$oModuleModel =& getModel('module'); |
273
|
|
|
$columnList = array('module_srl', 'site_srl'); |
274
|
|
|
$module_info = $oModuleModel->getModuleInfoByModuleSrl($file_obj->module_srl, $columnList); |
275
|
|
|
|
276
|
|
|
if(!$oModuleModel->isSiteAdmin($logged_info, $module_info->site_srl)) |
277
|
|
|
{ |
278
|
|
|
$oMemberModel =& getModel('member'); |
279
|
|
|
$member_groups = $oMemberModel->getMemberGroups($logged_info->member_srl, $module_info->site_srl); |
280
|
|
|
|
281
|
|
|
$is_permitted = false; |
282
|
|
|
for($i=0;$i<count($file_module_config->download_grant);$i++) |
|
|
|
|
283
|
|
|
{ |
284
|
|
|
$group_srl = $file_module_config->download_grant[$i]; |
285
|
|
|
if($member_groups[$group_srl]) |
286
|
|
|
{ |
287
|
|
|
$is_permitted = true; |
288
|
|
|
break; |
289
|
|
|
} |
290
|
|
|
} |
291
|
|
|
if(!$is_permitted) return $this->stop('msg_not_permitted_download'); |
292
|
|
|
} |
293
|
|
|
} |
294
|
|
|
} |
295
|
|
|
// Call a trigger (before) |
296
|
|
|
$output = ModuleHandler::triggerCall('file.downloadFile', 'before', $file_obj); |
297
|
|
|
if(!$output->toBool()) return $this->stop(($output->message)?$output->message:'msg_not_permitted_download'); |
298
|
|
|
|
299
|
|
|
|
300
|
|
|
// 다운로드 후 (가상) |
301
|
|
|
// Increase download_count |
302
|
|
|
$args = new stdClass(); |
303
|
|
|
$args->file_srl = $file_srl; |
304
|
|
|
executeQuery('file.updateFileDownloadCount', $args); |
305
|
|
|
// Call a trigger (after) |
306
|
|
|
$output = ModuleHandler::triggerCall('file.downloadFile', 'after', $file_obj); |
|
|
|
|
307
|
|
|
|
308
|
|
|
$random = new Password(); |
309
|
|
|
$file_key = $_SESSION['__XE_FILE_KEY__'][$file_srl] = $random->createSecureSalt(32, 'hex'); |
310
|
|
|
header('Location: '.getNotEncodedUrl('', 'act', 'procFileOutput','file_srl',$file_srl,'file_key',$file_key)); |
311
|
|
|
Context::close(); |
312
|
|
|
exit(); |
313
|
|
|
|
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
public function procFileOutput() |
317
|
|
|
{ |
318
|
|
|
$oFileModel = getModel('file'); |
319
|
|
|
$file_srl = Context::get('file_srl'); |
320
|
|
|
$file_key = Context::get('file_key'); |
321
|
|
|
if(strstr($_SERVER['HTTP_USER_AGENT'], "Android")) $is_android = true; |
322
|
|
|
|
323
|
|
|
if($is_android && $_SESSION['__XE_FILE_KEY_AND__'][$file_srl]) $session_key = '__XE_FILE_KEY_AND__'; |
|
|
|
|
324
|
|
|
else $session_key = '__XE_FILE_KEY__'; |
325
|
|
|
$columnList = array('source_filename', 'uploaded_filename', 'file_size'); |
326
|
|
|
$file_obj = $oFileModel->getFile($file_srl, $columnList); |
327
|
|
|
|
328
|
|
|
$uploaded_filename = $file_obj->uploaded_filename; |
329
|
|
|
|
330
|
|
|
if(!file_exists($uploaded_filename)) return $this->stop('msg_file_not_found'); |
331
|
|
|
|
332
|
|
|
if(!$file_key || $_SESSION[$session_key][$file_srl] != $file_key) |
333
|
|
|
{ |
334
|
|
|
unset($_SESSION[$session_key][$file_srl]); |
335
|
|
|
return $this->stop('msg_invalid_request'); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
$file_size = $file_obj->file_size; |
339
|
|
|
$filename = $file_obj->source_filename; |
340
|
|
|
|
341
|
|
|
if(preg_match('#(?:Chrome|Edge)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 11) |
342
|
|
|
{ |
343
|
|
|
if($is_android && preg_match('#\bwv\b|(?:Version|Browser)/\d+#', $_SERVER['HTTP_USER_AGENT'])) |
344
|
|
|
{ |
345
|
|
|
$filename_param = 'filename="' . $filename . '"'; |
346
|
|
|
} |
347
|
|
|
else |
348
|
|
|
{ |
349
|
|
|
$filename_param = sprintf('filename="%s"; filename*=UTF-8\'\'%s', $filename, rawurlencode($filename)); |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
elseif(preg_match('#(?:Firefox|Safari|Trident)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 6) |
353
|
|
|
{ |
354
|
|
|
$filename_param = sprintf('filename="%s"; filename*=UTF-8\'\'%s', $filename, rawurlencode($filename)); |
355
|
|
|
} |
356
|
|
|
elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) |
357
|
|
|
{ |
358
|
|
|
$filename = rawurlencode($filename); |
359
|
|
|
$filename_param = 'filename="' . preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1) . '"'; |
360
|
|
|
} |
361
|
|
|
else |
362
|
|
|
{ |
363
|
|
|
$filename_param = 'filename="' . $filename . '"'; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
if($is_android) |
367
|
|
|
{ |
368
|
|
|
if($_SESSION['__XE_FILE_KEY__'][$file_srl]) $_SESSION['__XE_FILE_KEY_AND__'][$file_srl] = $file_key; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
unset($_SESSION[$session_key][$file_srl]); |
372
|
|
|
|
373
|
|
|
Context::close(); |
374
|
|
|
|
375
|
|
|
$fp = fopen($uploaded_filename, 'rb'); |
376
|
|
|
if(!$fp) return $this->stop('msg_file_not_found'); |
377
|
|
|
|
378
|
|
|
header("Cache-Control: "); |
379
|
|
|
header("Pragma: "); |
380
|
|
|
header("Content-Type: application/octet-stream"); |
381
|
|
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
382
|
|
|
|
383
|
|
|
header("Content-Length: " .(string)($file_size)); |
384
|
|
|
header('Content-Disposition: attachment; ' . $filename_param); |
385
|
|
|
header("Content-Transfer-Encoding: binary\n"); |
386
|
|
|
|
387
|
|
|
// if file size is lager than 10MB, use fread function (#18675748) |
388
|
|
|
if($file_size > 1024 * 1024) |
389
|
|
|
{ |
390
|
|
|
while(!feof($fp)) echo fread($fp, 1024); |
391
|
|
|
fclose($fp); |
392
|
|
|
} |
393
|
|
|
else |
394
|
|
|
{ |
395
|
|
|
fpassthru($fp); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
exit(); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Delete an attachment from the editor |
403
|
|
|
* |
404
|
|
|
* @return BaseObject |
405
|
|
|
*/ |
406
|
|
|
function procFileDelete() |
407
|
|
|
{ |
408
|
|
|
// Basic variable setting(upload_target_srl and module_srl set) |
409
|
|
|
$editor_sequence = Context::get('editor_sequence'); |
410
|
|
|
$file_srl = Context::get('file_srl'); |
411
|
|
|
$file_srls = Context::get('file_srls'); |
412
|
|
|
if($file_srls) $file_srl = $file_srls; |
413
|
|
|
// Exit a session if there is neither upload permission nor information |
414
|
|
|
if(!$_SESSION['upload_info'][$editor_sequence]->enabled) exit(); |
415
|
|
|
|
416
|
|
|
$upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
417
|
|
|
|
418
|
|
|
$logged_info = Context::get('logged_info'); |
419
|
|
|
$oFileModel = getModel('file'); |
420
|
|
|
|
421
|
|
|
$srls = explode(',',$file_srl); |
422
|
|
|
if(!count($srls)) return; |
423
|
|
|
|
424
|
|
|
for($i=0;$i<count($srls);$i++) |
|
|
|
|
425
|
|
|
{ |
426
|
|
|
$srl = (int)$srls[$i]; |
427
|
|
|
if(!$srl) continue; |
428
|
|
|
|
429
|
|
|
$args = new stdClass; |
430
|
|
|
$args->file_srl = $srl; |
431
|
|
|
$output = executeQuery('file.getFile', $args); |
432
|
|
|
if(!$output->toBool()) continue; |
433
|
|
|
|
434
|
|
|
$file_info = $output->data; |
435
|
|
|
if(!$file_info) continue; |
436
|
|
|
|
437
|
|
|
$file_grant = $oFileModel->getFileGrant($file_info, $logged_info); |
438
|
|
|
|
439
|
|
|
if(!$file_grant->is_deletable) continue; |
440
|
|
|
|
441
|
|
|
if($upload_target_srl && $file_srl) $output = $this->deleteFile($file_srl); |
|
|
|
|
442
|
|
|
} |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* get file list |
447
|
|
|
* |
448
|
|
|
* @return BaseObject |
449
|
|
|
*/ |
450
|
|
|
function procFileGetList() |
451
|
|
|
{ |
452
|
|
|
if(!Context::get('is_logged')) return new BaseObject(-1,'msg_not_permitted'); |
453
|
|
|
|
454
|
|
|
$oModuleModel = getModel('module'); |
455
|
|
|
|
456
|
|
|
$logged_info = Context::get('logged_info'); |
457
|
|
|
if($logged_info->is_admin !== 'Y' && !$oModuleModel->isSiteAdmin($logged_info)) |
458
|
|
|
{ |
459
|
|
|
return new BaseObject(-1, 'msg_not_permitted'); |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
$fileSrls = Context::get('file_srls'); |
463
|
|
|
if($fileSrls) $fileSrlList = explode(',', $fileSrls); |
464
|
|
|
|
465
|
|
|
global $lang; |
466
|
|
|
if(count($fileSrlList) > 0) |
467
|
|
|
{ |
468
|
|
|
$oFileModel = getModel('file'); |
469
|
|
|
$fileList = $oFileModel->getFile($fileSrlList); |
|
|
|
|
470
|
|
|
if(!is_array($fileList)) $fileList = array($fileList); |
471
|
|
|
|
472
|
|
|
if(is_array($fileList)) |
473
|
|
|
{ |
474
|
|
|
foreach($fileList AS $key=>$value) |
475
|
|
|
{ |
476
|
|
|
$value->human_file_size = FileHandler::filesize($value->file_size); |
477
|
|
|
if($value->isvalid=='Y') $value->validName = $lang->is_valid; |
478
|
|
|
else $value->validName = $lang->is_stand_by; |
479
|
|
|
} |
480
|
|
|
} |
481
|
|
|
} |
482
|
|
|
else |
483
|
|
|
{ |
484
|
|
|
$fileList = array(); |
485
|
|
|
$this->setMessage($lang->no_files); |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
$this->add('file_list', $fileList); |
489
|
|
|
} |
490
|
|
|
/** |
491
|
|
|
* A trigger to return numbers of attachments in the upload_target_srl (document_srl) |
492
|
|
|
* |
493
|
|
|
* @param object $obj Trigger object |
494
|
|
|
* @return BaseObject |
495
|
|
|
*/ |
496
|
|
View Code Duplication |
function triggerCheckAttached(&$obj) |
|
|
|
|
497
|
|
|
{ |
498
|
|
|
$document_srl = $obj->document_srl; |
499
|
|
|
if(!$document_srl) return new BaseObject(); |
500
|
|
|
// Get numbers of attachments |
501
|
|
|
$oFileModel = getModel('file'); |
502
|
|
|
$obj->uploaded_count = $oFileModel->getFilesCount($document_srl); |
503
|
|
|
|
504
|
|
|
return new BaseObject(); |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
/** |
508
|
|
|
* A trigger to link the attachment with the upload_target_srl (document_srl) |
509
|
|
|
* |
510
|
|
|
* @param object $obj Trigger object |
511
|
|
|
* @return BaseObject |
512
|
|
|
*/ |
513
|
|
|
function triggerAttachFiles(&$obj) |
514
|
|
|
{ |
515
|
|
|
$document_srl = $obj->document_srl; |
516
|
|
|
if(!$document_srl) return new BaseObject(); |
517
|
|
|
|
518
|
|
|
$output = $this->setFilesValid($document_srl); |
519
|
|
|
if(!$output->toBool()) return $output; |
520
|
|
|
|
521
|
|
|
return new BaseObject(); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* A trigger to delete the attachment in the upload_target_srl (document_srl) |
526
|
|
|
* |
527
|
|
|
* @param object $obj Trigger object |
528
|
|
|
* @return BaseObject |
529
|
|
|
*/ |
530
|
|
|
function triggerDeleteAttached(&$obj) |
531
|
|
|
{ |
532
|
|
|
$document_srl = $obj->document_srl; |
533
|
|
|
if(!$document_srl) return new BaseObject(); |
534
|
|
|
|
535
|
|
|
$output = $this->deleteFiles($document_srl); |
536
|
|
|
return $output; |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
/** |
540
|
|
|
* A trigger to return numbers of attachments in the upload_target_srl (comment_srl) |
541
|
|
|
* |
542
|
|
|
* @param object $obj Trigger object |
543
|
|
|
* @return BaseObject |
544
|
|
|
*/ |
545
|
|
View Code Duplication |
function triggerCommentCheckAttached(&$obj) |
|
|
|
|
546
|
|
|
{ |
547
|
|
|
$comment_srl = $obj->comment_srl; |
548
|
|
|
if(!$comment_srl) return new BaseObject(); |
549
|
|
|
// Get numbers of attachments |
550
|
|
|
$oFileModel = getModel('file'); |
551
|
|
|
$obj->uploaded_count = $oFileModel->getFilesCount($comment_srl); |
552
|
|
|
|
553
|
|
|
return new BaseObject(); |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
/** |
557
|
|
|
* A trigger to link the attachment with the upload_target_srl (comment_srl) |
558
|
|
|
* |
559
|
|
|
* @param object $obj Trigger object |
560
|
|
|
* @return BaseObject |
561
|
|
|
*/ |
562
|
|
|
function triggerCommentAttachFiles(&$obj) |
563
|
|
|
{ |
564
|
|
|
$comment_srl = $obj->comment_srl; |
565
|
|
|
$uploaded_count = $obj->uploaded_count; |
566
|
|
|
if(!$comment_srl || !$uploaded_count) return new BaseObject(); |
567
|
|
|
|
568
|
|
|
$output = $this->setFilesValid($comment_srl); |
569
|
|
|
if(!$output->toBool()) return $output; |
570
|
|
|
|
571
|
|
|
return new BaseObject(); |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
/** |
575
|
|
|
* A trigger to delete the attachment in the upload_target_srl (comment_srl) |
576
|
|
|
* |
577
|
|
|
* @param object $obj Trigger object |
578
|
|
|
* @return BaseObject |
579
|
|
|
*/ |
580
|
|
|
function triggerCommentDeleteAttached(&$obj) |
581
|
|
|
{ |
582
|
|
|
$comment_srl = $obj->comment_srl; |
583
|
|
|
if(!$comment_srl) return new BaseObject(); |
584
|
|
|
|
585
|
|
|
if($obj->isMoveToTrash) return new BaseObject(); |
586
|
|
|
|
587
|
|
|
$output = $this->deleteFiles($comment_srl); |
588
|
|
|
return $output; |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
/** |
592
|
|
|
* A trigger to delete all the attachements when deleting the module |
593
|
|
|
* |
594
|
|
|
* @param object $obj Trigger object |
595
|
|
|
* @return BaseObject |
596
|
|
|
*/ |
597
|
|
|
function triggerDeleteModuleFiles(&$obj) |
598
|
|
|
{ |
599
|
|
|
$module_srl = $obj->module_srl; |
600
|
|
|
if(!$module_srl) return new BaseObject(); |
601
|
|
|
|
602
|
|
|
$oFileController = getAdminController('file'); |
603
|
|
|
return $oFileController->deleteModuleFiles($module_srl); |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
/** |
607
|
|
|
* Upload enabled |
608
|
|
|
* |
609
|
|
|
* @param int $editor_sequence |
610
|
|
|
* @param int $upload_target_srl |
611
|
|
|
* @return void |
612
|
|
|
*/ |
613
|
|
|
function setUploadInfo($editor_sequence, $upload_target_srl=0) |
614
|
|
|
{ |
615
|
|
|
if(!isset($_SESSION['upload_info'][$editor_sequence])) |
616
|
|
|
{ |
617
|
|
|
$_SESSION['upload_info'][$editor_sequence] = new stdClass(); |
618
|
|
|
} |
619
|
|
|
$_SESSION['upload_info'][$editor_sequence]->enabled = true; |
620
|
|
|
$_SESSION['upload_info'][$editor_sequence]->upload_target_srl = $upload_target_srl; |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
/** |
624
|
|
|
* Set the attachements of the upload_target_srl to be valid |
625
|
|
|
* By changing its state to valid when a document is inserted, it prevents from being considered as a unnecessary file |
626
|
|
|
* |
627
|
|
|
* @param int $upload_target_srl |
628
|
|
|
* @return BaseObject |
629
|
|
|
*/ |
630
|
|
|
function setFilesValid($upload_target_srl) |
631
|
|
|
{ |
632
|
|
|
$args = new stdClass(); |
633
|
|
|
$args->upload_target_srl = $upload_target_srl; |
634
|
|
|
return executeQuery('file.updateFileValid', $args); |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
/** |
638
|
|
|
* Add an attachement |
639
|
|
|
* |
640
|
|
|
* <pre> |
641
|
|
|
* This method call trigger 'file.insertFile'. |
642
|
|
|
* |
643
|
|
|
* Before trigger object contains: |
644
|
|
|
* - module_srl |
645
|
|
|
* - upload_target_srl |
646
|
|
|
* |
647
|
|
|
* After trigger object contains: |
648
|
|
|
* - file_srl |
649
|
|
|
* - upload_target_srl |
650
|
|
|
* - module_srl |
651
|
|
|
* - direct_download |
652
|
|
|
* - source_filename |
653
|
|
|
* - uploaded_filename |
654
|
|
|
* - donwload_count |
655
|
|
|
* - file_size |
656
|
|
|
* - comment |
657
|
|
|
* - member_srl |
658
|
|
|
* - sid |
659
|
|
|
* </pre> |
660
|
|
|
* |
661
|
|
|
* @param object $file_info PHP file information array |
662
|
|
|
* @param int $module_srl Sequence of module to upload file |
663
|
|
|
* @param int $upload_target_srl Sequence of target to upload file |
664
|
|
|
* @param int $download_count Initial download count |
665
|
|
|
* @param bool $manual_insert If set true, pass validation check |
666
|
|
|
* @return BaseObject |
667
|
|
|
*/ |
668
|
|
|
function insertFile($file_info, $module_srl, $upload_target_srl, $download_count = 0, $manual_insert = false) |
669
|
|
|
{ |
670
|
|
|
// Call a trigger (before) |
671
|
|
|
$trigger_obj = new stdClass; |
672
|
|
|
$trigger_obj->module_srl = $module_srl; |
673
|
|
|
$trigger_obj->upload_target_srl = $upload_target_srl; |
674
|
|
|
$output = ModuleHandler::triggerCall('file.insertFile', 'before', $trigger_obj); |
675
|
|
|
if(!$output->toBool()) return $output; |
676
|
|
|
|
677
|
|
|
// A workaround for Firefox upload bug |
678
|
|
|
if(preg_match('/^=\?UTF-8\?B\?(.+)\?=$/i', $file_info['name'], $match)) |
679
|
|
|
{ |
680
|
|
|
$file_info['name'] = base64_decode(strtr($match[1], ':', '/')); |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
if(!$manual_insert) |
684
|
|
|
{ |
685
|
|
|
// Get the file configurations |
686
|
|
|
$logged_info = Context::get('logged_info'); |
687
|
|
|
if($logged_info->is_admin != 'Y') |
688
|
|
|
{ |
689
|
|
|
$oFileModel = getModel('file'); |
690
|
|
|
$config = $oFileModel->getFileConfig($module_srl); |
691
|
|
|
|
692
|
|
|
// check file type |
693
|
|
|
if(isset($config->allowed_filetypes) && $config->allowed_filetypes !== '*.*') |
694
|
|
|
{ |
695
|
|
|
$filetypes = explode(';', $config->allowed_filetypes); |
696
|
|
|
$ext = array(); |
697
|
|
|
foreach($filetypes as $item) { |
698
|
|
|
$item = explode('.', $item); |
699
|
|
|
$ext[] = strtolower($item[1]); |
700
|
|
|
} |
701
|
|
|
$uploaded_ext = explode('.', $file_info['name']); |
702
|
|
|
$uploaded_ext = strtolower(array_pop($uploaded_ext)); |
703
|
|
|
|
704
|
|
|
if(!in_array($uploaded_ext, $ext)) |
705
|
|
|
{ |
706
|
|
|
return $this->stop('msg_not_allowed_filetype'); |
707
|
|
|
} |
708
|
|
|
} |
709
|
|
|
|
710
|
|
|
$allowed_filesize = $config->allowed_filesize * 1024 * 1024; |
711
|
|
|
$allowed_attach_size = $config->allowed_attach_size * 1024 * 1024; |
712
|
|
|
// An error appears if file size exceeds a limit |
713
|
|
|
if($allowed_filesize < filesize($file_info['tmp_name'])) return new BaseObject(-1, 'msg_exceeds_limit_size'); |
714
|
|
|
// Get total file size of all attachements (from DB) |
715
|
|
|
$size_args = new stdClass; |
716
|
|
|
$size_args->upload_target_srl = $upload_target_srl; |
717
|
|
|
$output = executeQuery('file.getAttachedFileSize', $size_args); |
718
|
|
|
$attached_size = (int)$output->data->attached_size + filesize($file_info['tmp_name']); |
719
|
|
|
if($attached_size > $allowed_attach_size) return new BaseObject(-1, 'msg_exceeds_limit_size'); |
720
|
|
|
} |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
// https://github.com/xpressengine/xe-core/issues/1713 |
724
|
|
|
$file_info['name'] = preg_replace('/\.((ph(p|t|ar)?[0-9]?|p?html?|cgi|pl|exe|(?:a|j)sp|inc).*)$/i', '$0-x',$file_info['name']); |
725
|
|
|
$file_info['name'] = removeHackTag($file_info['name']); |
726
|
|
|
$file_info['name'] = str_replace(array('<','>'),array('%3C','%3E'),$file_info['name']); |
727
|
|
|
$file_info['name'] = str_replace('&', '&', $file_info['name']); |
728
|
|
|
|
729
|
|
|
// Get random number generator |
730
|
|
|
$random = new Password(); |
731
|
|
|
|
732
|
|
|
// Set upload path by checking if the attachement is an image or other kinds of file |
733
|
|
|
if(preg_match("/\.(jpe?g|gif|png|wm[va]|mpe?g|avi|flv|mp[1-4]|as[fx]|wav|midi?|moo?v|qt|r[am]{1,2}|m4v)$/i", $file_info['name'])) |
734
|
|
|
{ |
735
|
|
|
$path = sprintf("./files/attach/images/%s/%s", $module_srl,getNumberingPath($upload_target_srl,3)); |
736
|
|
|
|
737
|
|
|
// special character to '_' |
738
|
|
|
// change to random file name. because window php bug. window php is not recognize unicode character file name - by cherryfilter |
739
|
|
|
$ext = substr(strrchr($file_info['name'],'.'),1); |
740
|
|
|
//$_filename = preg_replace('/[#$&*?+%"\']/', '_', $file_info['name']); |
741
|
|
|
$_filename = $random->createSecureSalt(32, 'hex').'.'.$ext; |
742
|
|
|
$filename = $path.$_filename; |
743
|
|
|
$idx = 1; |
744
|
|
View Code Duplication |
while(file_exists($filename)) |
745
|
|
|
{ |
746
|
|
|
$filename = $path.preg_replace('/\.([a-z0-9]+)$/i','_'.$idx.'.$1',$_filename); |
747
|
|
|
$idx++; |
748
|
|
|
} |
749
|
|
|
$direct_download = 'Y'; |
750
|
|
|
} |
751
|
|
View Code Duplication |
else |
752
|
|
|
{ |
753
|
|
|
$path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl,3)); |
754
|
|
|
$filename = $path.$random->createSecureSalt(32, 'hex'); |
755
|
|
|
$direct_download = 'N'; |
756
|
|
|
} |
757
|
|
|
// Create a directory |
758
|
|
|
if(!FileHandler::makeDir($path)) return new BaseObject(-1,'msg_not_permitted_create'); |
|
|
|
|
759
|
|
|
|
760
|
|
|
// Check uploaded file |
761
|
|
|
if(!$manual_insert && !checkUploadedFile($file_info['tmp_name'], $file_info['name'])) return new BaseObject(-1,'msg_file_upload_error'); |
762
|
|
|
|
763
|
|
|
// Get random number generator |
764
|
|
|
$random = new Password(); |
765
|
|
|
|
766
|
|
|
// Move the file |
767
|
|
|
if($manual_insert) |
768
|
|
|
{ |
769
|
|
|
@copy($file_info['tmp_name'], $filename); |
|
|
|
|
770
|
|
|
if(!file_exists($filename)) |
771
|
|
|
{ |
772
|
|
|
$filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
|
|
|
|
773
|
|
|
@copy($file_info['tmp_name'], $filename); |
|
|
|
|
774
|
|
|
} |
775
|
|
|
} |
776
|
|
|
else |
777
|
|
|
{ |
778
|
|
|
if(!@move_uploaded_file($file_info['tmp_name'], $filename)) |
779
|
|
|
{ |
780
|
|
|
$filename = $path.$random->createSecureSalt(32, 'hex').'.'.$ext; |
781
|
|
|
if(!@move_uploaded_file($file_info['tmp_name'], $filename)) return new BaseObject(-1,'msg_file_upload_error'); |
782
|
|
|
} |
783
|
|
|
} |
784
|
|
|
// Get member information |
785
|
|
|
$oMemberModel = getModel('member'); |
786
|
|
|
$member_srl = $oMemberModel->getLoggedMemberSrl(); |
787
|
|
|
// List file information |
788
|
|
|
$args = new stdClass; |
789
|
|
|
$args->file_srl = getNextSequence(); |
790
|
|
|
$args->upload_target_srl = $upload_target_srl; |
791
|
|
|
$args->module_srl = $module_srl; |
792
|
|
|
$args->direct_download = $direct_download; |
793
|
|
|
$args->source_filename = $file_info['name']; |
794
|
|
|
$args->uploaded_filename = $filename; |
795
|
|
|
$args->download_count = $download_count; |
796
|
|
|
$args->file_size = @filesize($filename); |
797
|
|
|
$args->comment = NULL; |
798
|
|
|
$args->member_srl = $member_srl; |
799
|
|
|
$args->sid = $random->createSecureSalt(32, 'hex'); |
800
|
|
|
|
801
|
|
|
$output = executeQuery('file.insertFile', $args); |
802
|
|
|
if(!$output->toBool()) return $output; |
803
|
|
|
// Call a trigger (after) |
804
|
|
|
$trigger_output = ModuleHandler::triggerCall('file.insertFile', 'after', $args); |
805
|
|
|
if(!$trigger_output->toBool()) return $trigger_output; |
806
|
|
|
|
807
|
|
|
$_SESSION['__XE_UPLOADING_FILES_INFO__'][$args->file_srl] = true; |
808
|
|
|
|
809
|
|
|
$output->add('file_srl', $args->file_srl); |
810
|
|
|
$output->add('file_size', $args->file_size); |
811
|
|
|
$output->add('sid', $args->sid); |
812
|
|
|
$output->add('direct_download', $args->direct_download); |
813
|
|
|
$output->add('source_filename', $args->source_filename); |
814
|
|
|
$output->add('upload_target_srl', $upload_target_srl); |
815
|
|
|
$output->add('uploaded_filename', $args->uploaded_filename); |
816
|
|
|
return $output; |
817
|
|
|
} |
818
|
|
|
|
819
|
|
|
/** |
820
|
|
|
* Delete the attachment |
821
|
|
|
* |
822
|
|
|
* <pre> |
823
|
|
|
* This method call trigger 'file.deleteFile'. |
824
|
|
|
* Before, after trigger object contains: |
825
|
|
|
* - download_url |
826
|
|
|
* - file_srl |
827
|
|
|
* - upload_target_srl |
828
|
|
|
* - upload_target_type |
829
|
|
|
* - sid |
830
|
|
|
* - module_srl |
831
|
|
|
* - member_srl |
832
|
|
|
* - download_count |
833
|
|
|
* - direct_download |
834
|
|
|
* - source_filename |
835
|
|
|
* - uploaded_filename |
836
|
|
|
* - file_size |
837
|
|
|
* - comment |
838
|
|
|
* - isvalid |
839
|
|
|
* - regdate |
840
|
|
|
* - ipaddress |
841
|
|
|
* </pre> |
842
|
|
|
* |
843
|
|
|
* @param int $file_srl Sequence of file to delete |
844
|
|
|
* @return BaseObject |
845
|
|
|
*/ |
846
|
|
|
function deleteFile($file_srl) |
847
|
|
|
{ |
848
|
|
|
if(!$file_srl) return; |
849
|
|
|
|
850
|
|
|
$srls = (is_array($file_srl)) ? $file_srl : explode(',', $file_srl); |
851
|
|
|
if(!count($srls)) return; |
852
|
|
|
|
853
|
|
|
$oDocumentController = getController('document'); |
854
|
|
|
$documentSrlList = array(); |
855
|
|
|
|
856
|
|
|
foreach($srls as $srl) |
857
|
|
|
{ |
858
|
|
|
$srl = (int)$srl; |
859
|
|
|
if(!$srl) |
860
|
|
|
{ |
861
|
|
|
continue; |
862
|
|
|
} |
863
|
|
|
|
864
|
|
|
$args = new stdClass(); |
865
|
|
|
$args->file_srl = $srl; |
866
|
|
|
$output = executeQuery('file.getFile', $args); |
867
|
|
|
|
868
|
|
|
if(!$output->toBool() || !$output->data) |
869
|
|
|
{ |
870
|
|
|
continue; |
871
|
|
|
} |
872
|
|
|
|
873
|
|
|
$file_info = $output->data; |
874
|
|
|
|
875
|
|
|
if($file_info->upload_target_srl) |
876
|
|
|
{ |
877
|
|
|
$documentSrlList[] = $file_info->upload_target_srl; |
878
|
|
|
} |
879
|
|
|
|
880
|
|
|
$source_filename = $output->data->source_filename; |
|
|
|
|
881
|
|
|
$uploaded_filename = $output->data->uploaded_filename; |
882
|
|
|
|
883
|
|
|
// Call a trigger (before) |
884
|
|
|
$trigger_obj = $output->data; |
885
|
|
|
$output = ModuleHandler::triggerCall('file.deleteFile', 'before', $trigger_obj); |
886
|
|
|
if(!$output->toBool()) return $output; |
887
|
|
|
|
888
|
|
|
// Remove from the DB |
889
|
|
|
$output = executeQuery('file.deleteFile', $args); |
890
|
|
|
if(!$output->toBool()) return $output; |
891
|
|
|
|
892
|
|
|
// Call a trigger (after) |
893
|
|
|
$trigger_output = ModuleHandler::triggerCall('file.deleteFile', 'after', $trigger_obj); |
894
|
|
|
if(!$trigger_output->toBool()) return $trigger_output; |
895
|
|
|
|
896
|
|
|
// If successfully deleted, remove the file |
897
|
|
|
FileHandler::removeFile($uploaded_filename); |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
$oDocumentController->updateUploaedCount($documentSrlList); |
901
|
|
|
|
902
|
|
|
return $output; |
|
|
|
|
903
|
|
|
} |
904
|
|
|
|
905
|
|
|
/** |
906
|
|
|
* Delete all attachments of a particular document |
907
|
|
|
* |
908
|
|
|
* @param int $upload_target_srl Upload target srl to delete files |
909
|
|
|
* @return BaseObject |
910
|
|
|
*/ |
911
|
|
|
function deleteFiles($upload_target_srl) |
912
|
|
|
{ |
913
|
|
|
// Get a list of attachements |
914
|
|
|
$oFileModel = getModel('file'); |
915
|
|
|
$columnList = array('file_srl', 'uploaded_filename', 'module_srl'); |
916
|
|
|
$file_list = $oFileModel->getFiles($upload_target_srl, $columnList); |
917
|
|
|
// Success returned if no attachement exists |
918
|
|
|
if(!is_array($file_list)||!count($file_list)) return new BaseObject(); |
919
|
|
|
|
920
|
|
|
// Delete the file |
921
|
|
|
$path = array(); |
922
|
|
|
$file_count = count($file_list); |
923
|
|
View Code Duplication |
for($i=0;$i<$file_count;$i++) |
924
|
|
|
{ |
925
|
|
|
$this->deleteFile($file_list[$i]->file_srl); |
926
|
|
|
|
927
|
|
|
$uploaded_filename = $file_list[$i]->uploaded_filename; |
928
|
|
|
$path_info = pathinfo($uploaded_filename); |
929
|
|
|
if(!in_array($path_info['dirname'], $path)) $path[] = $path_info['dirname']; |
930
|
|
|
} |
931
|
|
|
|
932
|
|
|
// Remove from the DB |
933
|
|
|
$args = new stdClass(); |
934
|
|
|
$args->upload_target_srl = $upload_target_srl; |
935
|
|
|
$output = executeQuery('file.deleteFiles', $args); |
936
|
|
|
if(!$output->toBool()) return $output; |
937
|
|
|
|
938
|
|
|
// Remove a file directory of the document |
939
|
|
View Code Duplication |
for($i=0, $c=count($path); $i<$c; $i++) |
940
|
|
|
{ |
941
|
|
|
FileHandler::removeBlankDir($path[$i]); |
942
|
|
|
} |
943
|
|
|
|
944
|
|
|
return $output; |
945
|
|
|
} |
946
|
|
|
|
947
|
|
|
/** |
948
|
|
|
* Move an attachement to the other document |
949
|
|
|
* |
950
|
|
|
* @param int $source_srl Sequence of target to move |
951
|
|
|
* @param int $target_module_srl New squence of module |
952
|
|
|
* @param int $target_srl New sequence of target |
953
|
|
|
* @return void |
954
|
|
|
*/ |
955
|
|
|
function moveFile($source_srl, $target_module_srl, $target_srl) |
956
|
|
|
{ |
957
|
|
|
if($source_srl == $target_srl) return; |
958
|
|
|
|
959
|
|
|
$oFileModel = getModel('file'); |
960
|
|
|
$file_list = $oFileModel->getFiles($source_srl); |
961
|
|
|
if(!$file_list) return; |
962
|
|
|
|
963
|
|
|
$file_count = count($file_list); |
964
|
|
|
|
965
|
|
|
for($i=0;$i<$file_count;$i++) |
966
|
|
|
{ |
967
|
|
|
unset($file_info); |
968
|
|
|
$file_info = $file_list[$i]; |
969
|
|
|
$old_file = $file_info->uploaded_filename; |
970
|
|
|
// Determine the file path by checking if the file is an image or other kinds |
971
|
|
|
if(preg_match("/\.(asf|asf|asx|avi|flv|gif|jpeg|jpg|m4a|m4v|mid|midi|moov|mov|mp1|mp2|mp3|mp4|mpeg|mpg|ogg|png|qt|ra|ram|rm|rmm|wav|webm|webp|wma|wmv)$/i", $file_info->source_filename)) |
972
|
|
|
{ |
973
|
|
|
$path = sprintf("./files/attach/images/%s/%s/", $target_module_srl,$target_srl); |
974
|
|
|
$new_file = $path.$file_info->source_filename; |
975
|
|
|
} |
976
|
|
|
else |
977
|
|
|
{ |
978
|
|
|
$path = sprintf("./files/attach/binaries/%s/%s/", $target_module_srl, $target_srl); |
979
|
|
|
$random = new Password(); |
980
|
|
|
$new_file = $path.$random->createSecureSalt(32, 'hex'); |
981
|
|
|
} |
982
|
|
|
// Pass if a target document to move is same |
983
|
|
|
if($old_file == $new_file) continue; |
984
|
|
|
// Create a directory |
985
|
|
|
FileHandler::makeDir($path); |
986
|
|
|
// Move the file |
987
|
|
|
FileHandler::rename($old_file, $new_file); |
988
|
|
|
// Update DB information |
989
|
|
|
$args = new stdClass; |
990
|
|
|
$args->file_srl = $file_info->file_srl; |
991
|
|
|
$args->uploaded_filename = $new_file; |
992
|
|
|
$args->module_srl = $file_info->module_srl; |
993
|
|
|
$args->upload_target_srl = $target_srl; |
994
|
|
|
executeQuery('file.updateFile', $args); |
995
|
|
|
} |
996
|
|
|
} |
997
|
|
|
|
998
|
|
|
public function procFileSetCoverImage() |
999
|
|
|
{ |
1000
|
|
|
$vars = Context::getRequestVars(); |
1001
|
|
|
$logged_info = Context::get('logged_info'); |
1002
|
|
|
|
1003
|
|
|
if(!$vars->editor_sequence) return new BaseObject(-1, 'msg_invalid_request'); |
|
|
|
|
1004
|
|
|
|
1005
|
|
|
$upload_target_srl = $_SESSION['upload_info'][$vars->editor_sequence]->upload_target_srl; |
1006
|
|
|
|
1007
|
|
|
$oFileModel = getModel('file'); |
1008
|
|
|
$file_info = $oFileModel->getFile($vars->file_srl); |
|
|
|
|
1009
|
|
|
|
1010
|
|
|
if(!$file_info) return new BaseObject(-1, 'msg_not_founded'); |
1011
|
|
|
|
1012
|
|
|
if(!$this->manager && !$file_info->member_srl === $logged_info->member_srl) return new BaseObject(-1, 'msg_not_permitted'); |
|
|
|
|
1013
|
|
|
|
1014
|
|
|
$args = new stdClass(); |
1015
|
|
|
$args->file_srl = $vars->file_srl; |
1016
|
|
|
$args->upload_target_srl = $upload_target_srl; |
1017
|
|
|
|
1018
|
|
|
$oDB = &DB::getInstance(); |
1019
|
|
|
$oDB->begin(); |
1020
|
|
|
|
1021
|
|
|
$args->cover_image = 'N'; |
1022
|
|
|
$output = executeQuery('file.updateClearCoverImage', $args); |
1023
|
|
|
if(!$output->toBool()) |
1024
|
|
|
{ |
1025
|
|
|
$oDB->rollback(); |
1026
|
|
|
return $output; |
1027
|
|
|
} |
1028
|
|
|
|
1029
|
|
|
if($file_info->cover_image != 'Y') |
1030
|
|
|
{ |
1031
|
|
|
|
1032
|
|
|
$args->cover_image = 'Y'; |
1033
|
|
|
$output = executeQuery('file.updateCoverImage', $args); |
1034
|
|
|
if(!$output->toBool()) |
1035
|
|
|
{ |
1036
|
|
|
$oDB->rollback(); |
1037
|
|
|
return $output; |
1038
|
|
|
} |
1039
|
|
|
|
1040
|
|
|
} |
1041
|
|
|
|
1042
|
|
|
$oDB->commit(); |
1043
|
|
|
|
1044
|
|
|
$this->add('is_cover',$args->cover_image); |
1045
|
|
|
|
1046
|
|
|
// 썸네일 삭제 |
1047
|
|
|
$thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($upload_target_srl, 3)); |
1048
|
|
|
Filehandler::removeFilesInDir($thumbnail_path); |
1049
|
|
|
} |
1050
|
|
|
|
1051
|
|
|
/** |
1052
|
|
|
* Find the attachment where a key is upload_target_srl and then return java script code |
1053
|
|
|
* |
1054
|
|
|
* @deprecated |
1055
|
|
|
* @param int $editor_sequence |
1056
|
|
|
* @param int $upload_target_srl |
1057
|
|
|
* @return void |
1058
|
|
|
*/ |
1059
|
|
|
function printUploadedFileList($editor_sequence, $upload_target_srl) |
|
|
|
|
1060
|
|
|
{ |
1061
|
|
|
return; |
1062
|
|
|
} |
1063
|
|
|
|
1064
|
|
View Code Duplication |
function triggerCopyModule(&$obj) |
|
|
|
|
1065
|
|
|
{ |
1066
|
|
|
$oModuleModel = getModel('module'); |
1067
|
|
|
$fileConfig = $oModuleModel->getModulePartConfig('file', $obj->originModuleSrl); |
1068
|
|
|
|
1069
|
|
|
$oModuleController = getController('module'); |
1070
|
|
|
if(is_array($obj->moduleSrlList)) |
1071
|
|
|
{ |
1072
|
|
|
foreach($obj->moduleSrlList AS $key=>$moduleSrl) |
1073
|
|
|
{ |
1074
|
|
|
$oModuleController->insertModulePartConfig('file', $moduleSrl, $fileConfig); |
1075
|
|
|
} |
1076
|
|
|
} |
1077
|
|
|
} |
1078
|
|
|
} |
1079
|
|
|
/* End of file file.controller.php */ |
1080
|
|
|
/* Location: ./modules/file/file.controller.php */ |
1081
|
|
|
|
1082
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: