1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) NAVER <http://www.navercorp.com> */ |
3
|
|
|
/** |
4
|
|
|
* Model class of the file module |
5
|
|
|
* @author NAVER ([email protected]) |
6
|
|
|
*/ |
7
|
|
|
class fileModel extends file |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Initialization |
11
|
|
|
* @return void |
12
|
|
|
*/ |
13
|
|
|
function init() |
14
|
|
|
{ |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Return a file list attached in the document |
19
|
|
|
* |
20
|
|
|
* It is used when a file list of the upload_target_srl is requested for creating/updating a document. |
21
|
|
|
* Attempt to replace with sever-side session if upload_target_srl is not yet determined |
22
|
|
|
* |
23
|
|
|
* @return void |
24
|
|
|
*/ |
25
|
|
|
function getFileList() |
26
|
|
|
{ |
27
|
|
|
$oModuleModel = getModel('module'); |
28
|
|
|
|
29
|
|
|
$mid = Context::get('mid'); |
|
|
|
|
30
|
|
|
$editor_sequence = Context::get('editor_sequence'); |
31
|
|
|
$upload_target_srl = Context::get('upload_target_srl'); |
32
|
|
|
if(!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; |
33
|
|
|
|
34
|
|
|
if($upload_target_srl) |
35
|
|
|
{ |
36
|
|
|
$oDocumentModel = getModel('document'); |
37
|
|
|
$oCommentModel = getModel('comment'); |
38
|
|
|
$logged_info = Context::get('logged_info'); |
39
|
|
|
|
40
|
|
|
$oDocument = $oDocumentModel->getDocument($upload_target_srl); |
41
|
|
|
|
42
|
|
|
// comment 권한 확인 |
43
|
|
|
if(!$oDocument->isExists()) |
44
|
|
|
{ |
45
|
|
|
$oComment = $oCommentModel->getComment($upload_target_srl); |
46
|
|
View Code Duplication |
if($oComment->isExists() && $oComment->isSecret() && !$oComment->isGranted()) |
47
|
|
|
{ |
48
|
|
|
return new Object(-1, 'msg_not_permitted'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$oDocument = $oDocumentModel->getDocument($oComment->get('document_srl')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// document 권한 확인 |
55
|
|
View Code Duplication |
if($oDocument->isExists() && $oDocument->isSecret() && !$oDocument->isGranted()) |
56
|
|
|
{ |
57
|
|
|
return new Object(-1, 'msg_not_permitted'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
// 모듈 권한 확인 |
61
|
|
|
if($oDocument->isExists()) |
62
|
|
|
{ |
63
|
|
|
$grant = $oModuleModel->getGrant($oModuleModel->getModuleInfoByModuleSrl($oDocument->get('module_srl')), $logged_info); |
64
|
|
|
if(!$grant->access) |
65
|
|
|
{ |
66
|
|
|
return new Object(-1, 'msg_not_permitted'); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$tmp_files = $this->getFiles($upload_target_srl); |
71
|
|
|
if(!$tmp_files) $tmp_files = array(); |
|
|
|
|
72
|
|
|
|
73
|
|
|
foreach($tmp_files as $file_info) |
74
|
|
|
{ |
75
|
|
|
if(!$file_info->file_srl) continue; |
76
|
|
|
|
77
|
|
|
$obj = new stdClass; |
78
|
|
|
$obj->file_srl = $file_info->file_srl; |
79
|
|
|
$obj->source_filename = $file_info->source_filename; |
80
|
|
|
$obj->file_size = $file_info->file_size; |
81
|
|
|
$obj->disp_file_size = FileHandler::filesize($file_info->file_size); |
82
|
|
|
if($file_info->direct_download=='N') $obj->download_url = $this->getDownloadUrl($file_info->file_srl, $file_info->sid, $file_info->module_srl); |
83
|
|
|
else $obj->download_url = str_replace('./', '', $file_info->uploaded_filename); |
84
|
|
|
$obj->direct_download = $file_info->direct_download; |
85
|
|
|
$obj->cover_image = ($file_info->cover_image === 'Y') ? true : false; |
86
|
|
|
$files[] = $obj; |
|
|
|
|
87
|
|
|
$attached_size += $file_info->file_size; |
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
else |
91
|
|
|
{ |
92
|
|
|
$upload_target_srl = 0; |
93
|
|
|
$attached_size = 0; |
94
|
|
|
$files = array(); |
95
|
|
|
} |
96
|
|
|
// Display upload status |
97
|
|
|
$upload_status = $this->getUploadStatus($attached_size); |
98
|
|
|
// Check remained file size until upload complete |
99
|
|
|
//$config = $oModuleModel->getModuleInfoByMid($mid); //perhaps config varialbles not used |
100
|
|
|
|
101
|
|
|
$file_config = $this->getUploadConfig(); |
102
|
|
|
$left_size = $file_config->allowed_attach_size*1024*1024 - $attached_size; |
103
|
|
|
// Settings of required information |
104
|
|
|
$attached_size = FileHandler::filesize($attached_size); |
105
|
|
|
$allowed_attach_size = FileHandler::filesize($file_config->allowed_attach_size*1024*1024); |
106
|
|
|
$allowed_filesize = FileHandler::filesize($file_config->allowed_filesize*1024*1024); |
107
|
|
|
$allowed_filetypes = $file_config->allowed_filetypes; |
108
|
|
|
$this->add("files",$files); |
|
|
|
|
109
|
|
|
$this->add("editor_sequence",$editor_sequence); |
110
|
|
|
$this->add("upload_target_srl",$upload_target_srl); |
111
|
|
|
$this->add("upload_status",$upload_status); |
112
|
|
|
$this->add("left_size",$left_size); |
113
|
|
|
$this->add('attached_size', $attached_size); |
114
|
|
|
$this->add('allowed_attach_size', $allowed_attach_size); |
115
|
|
|
$this->add('allowed_filesize', $allowed_filesize); |
116
|
|
|
$this->add('allowed_filetypes', $allowed_filetypes); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Return number of attachments which belongs to a specific document |
121
|
|
|
* |
122
|
|
|
* @param int $upload_target_srl The sequence to get a number of files |
123
|
|
|
* @return int Returns a number of files |
124
|
|
|
*/ |
125
|
|
|
function getFilesCount($upload_target_srl) |
126
|
|
|
{ |
127
|
|
|
$args = new stdClass(); |
128
|
|
|
$args->upload_target_srl = $upload_target_srl; |
129
|
|
|
$output = executeQuery('file.getFilesCount', $args); |
130
|
|
|
return (int)$output->data->count; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get a download path |
135
|
|
|
* |
136
|
|
|
* @param int $file_srl The sequence of file to get url |
137
|
|
|
* @param string $sid |
138
|
|
|
* @return string Returns a url |
139
|
|
|
*/ |
140
|
|
|
function getDownloadUrl($file_srl, $sid, $module_srl="") |
141
|
|
|
{ |
142
|
|
|
return sprintf('?module=%s&act=%s&file_srl=%s&sid=%s&module_srl=%s', 'file', 'procFileDownload', $file_srl, $sid, $module_srl); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Get file configurations |
147
|
|
|
* |
148
|
|
|
* @param int $module_srl If set this, returns specific module's configuration. Otherwise returns global configuration. |
149
|
|
|
* @return object Returns configuration. |
150
|
|
|
*/ |
151
|
|
|
function getFileConfig($module_srl = null) |
152
|
|
|
{ |
153
|
|
|
// Get configurations (using module model object) |
154
|
|
|
$oModuleModel = getModel('module'); |
155
|
|
|
|
156
|
|
|
$file_module_config = $oModuleModel->getModuleConfig('file'); |
157
|
|
|
|
158
|
|
|
if($module_srl) $file_config = $oModuleModel->getModulePartConfig('file',$module_srl); |
|
|
|
|
159
|
|
|
if(!$file_config) $file_config = $file_module_config; |
|
|
|
|
160
|
|
|
|
161
|
|
|
$config = new stdClass(); |
162
|
|
|
|
163
|
|
|
if($file_config) |
164
|
|
|
{ |
165
|
|
|
$config->allowed_filesize = $file_config->allowed_filesize; |
166
|
|
|
$config->allowed_attach_size = $file_config->allowed_attach_size; |
167
|
|
|
$config->allowed_filetypes = $file_config->allowed_filetypes; |
168
|
|
|
$config->download_grant = $file_config->download_grant; |
169
|
|
|
$config->allow_outlink = $file_config->allow_outlink; |
170
|
|
|
$config->allow_outlink_site = $file_config->allow_outlink_site; |
171
|
|
|
$config->allow_outlink_format = $file_config->allow_outlink_format; |
172
|
|
|
} |
173
|
|
|
// Property for all files comes first than each property |
174
|
|
|
if(!$config->allowed_filesize) $config->allowed_filesize = $file_module_config->allowed_filesize; |
175
|
|
|
if(!$config->allowed_attach_size) $config->allowed_attach_size = $file_module_config->allowed_attach_size; |
176
|
|
|
if(!$config->allowed_filetypes) $config->allowed_filetypes = $file_module_config->allowed_filetypes; |
177
|
|
|
if(!$config->allow_outlink) $config->allow_outlink = $file_module_config->allow_outlink; |
178
|
|
|
if(!$config->allow_outlink_site) $config->allow_outlink_site = $file_module_config->allow_outlink_site; |
179
|
|
|
if(!$config->allow_outlink_format) $config->allow_outlink_format = $file_module_config->allow_outlink_format; |
180
|
|
|
if(!$config->download_grant) $config->download_grant = $file_module_config->download_grant; |
181
|
|
|
// Default setting if not exists |
182
|
|
|
if(!$config->allowed_filesize) $config->allowed_filesize = '2'; |
183
|
|
|
if(!$config->allowed_attach_size) $config->allowed_attach_size = '3'; |
184
|
|
|
if(!$config->allowed_filetypes) $config->allowed_filetypes = '*.*'; |
185
|
|
|
if(!$config->allow_outlink) $config->allow_outlink = 'Y'; |
186
|
|
|
if(!$config->download_grant) $config->download_grant = array(); |
187
|
|
|
|
188
|
|
|
$size = ini_get('upload_max_filesize'); |
189
|
|
|
$unit = strtolower($size[strlen($size) - 1]); |
190
|
|
|
$size = (float)$size; |
191
|
|
|
if($unit == 'g') $size *= 1024; |
192
|
|
|
if($unit == 'k') $size /= 1024; |
193
|
|
|
|
194
|
|
|
if($config->allowed_filesize > $size) |
195
|
|
|
{ |
196
|
|
|
$config->allowed_filesize = $size; |
197
|
|
|
} |
198
|
|
|
if($config->allowed_attach_size > $size) |
199
|
|
|
{ |
200
|
|
|
$config->allowed_attach_size = $size; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
return $config; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Get file information |
208
|
|
|
* |
209
|
|
|
* @param int $file_srl The sequence of file to get information |
210
|
|
|
* @param array $columnList The list of columns to get from DB |
211
|
|
|
* @return Object|object|array If error returns an instance of Object. If result set is one returns a object that contins file information. If result set is more than one returns array of object. |
212
|
|
|
*/ |
213
|
|
|
function getFile($file_srl, $columnList = array()) |
214
|
|
|
{ |
215
|
|
|
$args = new stdClass(); |
216
|
|
|
$args->file_srl = $file_srl; |
217
|
|
|
$output = executeQueryArray('file.getFile', $args, $columnList); |
218
|
|
|
if(!$output->toBool()) return $output; |
219
|
|
|
|
220
|
|
|
// old version compatibility |
221
|
|
|
if(count($output->data) == 1) |
222
|
|
|
{ |
223
|
|
|
$file = $output->data[0]; |
224
|
|
|
$file->download_url = $this->getDownloadUrl($file->file_srl, $file->sid, $file->module_srl); |
225
|
|
|
|
226
|
|
|
return $file; |
227
|
|
|
} |
228
|
|
|
else |
229
|
|
|
{ |
230
|
|
|
$fileList = array(); |
231
|
|
|
|
232
|
|
|
if(is_array($output->data)) |
233
|
|
|
{ |
234
|
|
|
foreach($output->data as $key=>$value) |
235
|
|
|
{ |
236
|
|
|
$file = $value; |
237
|
|
|
$file->download_url = $this->getDownloadUrl($file->file_srl, $file->sid, $file->module_srl); |
238
|
|
|
$fileList[] = $file; |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
return $fileList; |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Return all files which belong to a specific document |
247
|
|
|
* |
248
|
|
|
* @param int $upload_target_srl The sequence of target to get file list |
249
|
|
|
* @param array $columnList The list of columns to get from DB |
250
|
|
|
* @param string $sortIndex The column that used as sort index |
251
|
|
|
* @return array Returns array of object that contains file information. If no result returns null. |
252
|
|
|
*/ |
253
|
|
|
function getFiles($upload_target_srl, $columnList = array(), $sortIndex = 'file_srl', $ckValid = false) |
254
|
|
|
{ |
255
|
|
|
$args = new stdClass(); |
256
|
|
|
$args->upload_target_srl = $upload_target_srl; |
257
|
|
|
$args->sort_index = $sortIndex; |
258
|
|
|
if($ckValid) $args->isvalid = 'Y'; |
259
|
|
|
$output = executeQueryArray('file.getFiles', $args, $columnList); |
260
|
|
|
if(!$output->data) return; |
261
|
|
|
|
262
|
|
|
$file_list = $output->data; |
263
|
|
|
|
264
|
|
|
if($file_list && !is_array($file_list)) $file_list = array($file_list); |
265
|
|
|
|
266
|
|
|
foreach ($file_list as &$file) |
267
|
|
|
{ |
268
|
|
|
$file->source_filename = stripslashes($file->source_filename); |
269
|
|
|
$file->source_filename = htmlspecialchars($file->source_filename); |
270
|
|
|
$file->download_url = $this->getDownloadUrl($file->file_srl, $file->sid, $file->module_srl); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
return $file_list; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Return configurations of the attachement (it automatically checks if an administrator is) |
278
|
|
|
* |
279
|
|
|
* @return object Returns a file configuration of current module. If user is admin, returns PHP's max file size and allow all file types. |
280
|
|
|
*/ |
281
|
|
|
function getUploadConfig() |
282
|
|
|
{ |
283
|
|
|
$logged_info = Context::get('logged_info'); |
284
|
|
|
|
285
|
|
|
$module_srl = Context::get('module_srl'); |
286
|
|
|
// Get the current module if module_srl doesn't exist |
287
|
|
|
if(!$module_srl) |
288
|
|
|
{ |
289
|
|
|
$current_module_info = Context::get('current_module_info'); |
290
|
|
|
$module_srl = $current_module_info->module_srl; |
291
|
|
|
} |
292
|
|
|
$file_config = $this->getFileConfig($module_srl); |
293
|
|
|
|
294
|
|
|
if($logged_info->is_admin == 'Y') |
295
|
|
|
{ |
296
|
|
|
$iniPostMaxSize = FileHandler::returnbytes(ini_get('post_max_size')); |
297
|
|
|
$iniUploadMaxSize = FileHandler::returnbytes(ini_get('upload_max_filesize')); |
298
|
|
|
$size = min($iniPostMaxSize, $iniUploadMaxSize) / 1048576; |
299
|
|
|
$file_config->allowed_attach_size = $size; |
300
|
|
|
$file_config->allowed_filesize = $size; |
301
|
|
|
$file_config->allowed_filetypes = '*.*'; |
302
|
|
|
} |
303
|
|
|
return $file_config; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Return messages for file upload and it depends whether an admin is or not |
308
|
|
|
* |
309
|
|
|
* @param int $attached_size |
310
|
|
|
* @return string |
311
|
|
|
*/ |
312
|
|
|
function getUploadStatus($attached_size = 0) |
313
|
|
|
{ |
314
|
|
|
$file_config = $this->getUploadConfig(); |
315
|
|
|
// Display upload status |
316
|
|
|
$upload_status = sprintf( |
317
|
|
|
'%s : %s/ %s<br /> %s : %s (%s : %s)', |
318
|
|
|
Context::getLang('allowed_attach_size'), |
319
|
|
|
FileHandler::filesize($attached_size), |
320
|
|
|
FileHandler::filesize($file_config->allowed_attach_size*1024*1024), |
321
|
|
|
Context::getLang('allowed_filesize'), |
322
|
|
|
FileHandler::filesize($file_config->allowed_filesize*1024*1024), |
323
|
|
|
Context::getLang('allowed_filetypes'), |
324
|
|
|
$file_config->allowed_filetypes |
325
|
|
|
); |
326
|
|
|
return $upload_status; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Return file configuration of the module |
331
|
|
|
* |
332
|
|
|
* @param int $module_srl The sequence of module to get configuration |
333
|
|
|
* @return object |
334
|
|
|
*/ |
335
|
|
|
function getFileModuleConfig($module_srl) |
336
|
|
|
{ |
337
|
|
|
return $this->getFileConfig($module_srl); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Returns a grant of file |
342
|
|
|
* |
343
|
|
|
* @param object $file_info The file information to get grant |
344
|
|
|
* @param object $member_info The member information to get grant |
345
|
|
|
* @return object Returns a grant of file |
346
|
|
|
*/ |
347
|
|
|
function getFileGrant($file_info, $member_info) |
348
|
|
|
{ |
349
|
|
|
if(!$file_info) return null; |
350
|
|
|
|
351
|
|
|
if($_SESSION['__XE_UPLOADING_FILES_INFO__'][$file_info->file_srl]) |
352
|
|
|
{ |
353
|
|
|
$file_grant->is_deletable = true; |
|
|
|
|
354
|
|
|
return $file_grant; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
$oModuleModel = getModel('module'); |
358
|
|
|
$grant = $oModuleModel->getGrant($oModuleModel->getModuleInfoByModuleSrl($file_info->module_srl), $member_info); |
359
|
|
|
|
360
|
|
|
$oDocumentModel = getModel('document'); |
361
|
|
|
$oDocument = $oDocumentModel->getDocument($file_info->upload_target_srl); |
362
|
|
|
if($oDocument->isExists()) $document_grant = $oDocument->isGranted(); |
363
|
|
|
|
364
|
|
|
$file_grant->is_deletable = ($document_grant || $member_info->is_admin == 'Y' || $member_info->member_srl == $file_info->member_srl || $grant->manager); |
|
|
|
|
365
|
|
|
|
366
|
|
|
return $file_grant; |
367
|
|
|
} |
368
|
|
|
} |
369
|
|
|
/* End of file file.model.php */ |
370
|
|
|
/* Location: ./modules/file/file.model.php */ |
371
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.