|
99 | 99 | $category_list = $oDocumentModel->getCategoryList($this->module_srl);
|
100 | 100 |
|
101 | 101 | // Specifies a temporary file storage
|
102 |
| - $tmp_uploaded_path = sprintf(_XE_PATH_ . 'files/cache/blogapi/%s/%s/', $this->mid, $user_id); |
103 |
| - $uploaded_target_path = sprintf(_XE_PATH_ . 'files/cache/blogapi/%s/%s/', $this->mid, $user_id); |
| 102 | + $logged_info = Context::get('logged_info'); |
| 103 | + $mediaPath = sprintf('files/cache/blogapi/%s/%s/', $this->mid, $logged_info->member_srl); |
| 104 | + $mediaAbsPath = _XE_PATH_ . $mediaPath; |
| 105 | + $mediaUrlPath = Context::getRequestUri() . $mediaPath; |
104 | 106 |
|
105 | 107 | switch($method_name)
|
106 | 108 | {
|
|
167 | 169 | foreach($fileinfo as $key => $val)
|
168 | 170 | {
|
169 | 171 | $nodename = (string)$val->name;
|
170 |
| - if($nodename == 'bits') |
| 172 | + if($nodename === 'bits') |
| 173 | + { |
171 | 174 | $filedata = base64_decode((string)$val->value->base64);
|
172 |
| - elseif($nodename == 'name') |
173 |
| - $filename = (string)$val->value->string; |
| 175 | + } |
| 176 | + else if($nodename === 'name') |
| 177 | + { |
| 178 | + $filename = pathinfo((string)$val->value->string, PATHINFO_BASENAME); |
| 179 | + } |
174 | 180 | }
|
175 | 181 |
|
176 |
| - $tmp_arr = explode('/', $filename); |
177 |
| - $filename = array_pop($tmp_arr); |
| 182 | + if($logged_info->is_admin != 'Y') |
| 183 | + { |
| 184 | + // check file type |
| 185 | + if(isset($file_module_config->allowed_filetypes) && $file_module_config->allowed_filetypes !== '*.*') |
| 186 | + { |
| 187 | + $filetypes = explode(';', $file_module_config->allowed_filetypes); |
| 188 | + $ext = array(); |
| 189 | + |
| 190 | + foreach($filetypes as $item) |
| 191 | + { |
| 192 | + $item = explode('.', $item); |
| 193 | + $ext[] = strtolower(array_pop($item)); |
| 194 | + } |
| 195 | + |
| 196 | + $uploaded_ext = explode('.', $filename); |
| 197 | + $uploaded_ext = strtolower(array_pop($uploaded_ext)); |
178 | 198 |
|
179 |
| - FileHandler::makeDir($tmp_uploaded_path); |
| 199 | + if(!in_array($uploaded_ext, $ext)) |
| 200 | + { |
| 201 | + printContent(getXmlRpcFailure(1, 'Not allowed file type')); |
| 202 | + break; |
| 203 | + } |
| 204 | + } |
| 205 | + |
| 206 | + $allowed_filesize = $file_module_config->allowed_filesize * 1024 * 1024; |
| 207 | + if($allowed_filesize < strlen($filedata)) |
| 208 | + { |
| 209 | + printContent(getXmlRpcFailure(1, 'This file exceeds the attachment limit')); |
| 210 | + break; |
| 211 | + } |
| 212 | + } |
180 | 213 |
|
181 |
| - $target_filename = sprintf('%s%s', $tmp_uploaded_path, $filename); |
| 214 | + $temp_filename = Password::createSecureSalt(12, 'alnum'); |
| 215 | + $target_filename = sprintf('%s%s', $mediaAbsPath, $temp_filename); |
| 216 | + FileHandler::makeDir($mediaAbsPath); |
182 | 217 | FileHandler::writeFile($target_filename, $filedata);
|
183 |
| - $obj = new stdClass(); |
184 |
| - $obj->url = Context::getRequestUri() . $target_filename; |
| 218 | + FileHandler::writeFile($target_filename . '_source_filename', $filename); |
185 | 219 |
|
| 220 | + $obj = new stdClass(); |
| 221 | + $obj->url = Context::getRequestUri() . $mediaPath . $temp_filename; |
186 | 222 | $content = getXmlRpcResponse($obj);
|
187 | 223 | printContent($content);
|
188 | 224 | break;
|
|
291 | 327 | $obj->module_srl = $this->module_srl;
|
292 | 328 |
|
293 | 329 | // Attachment
|
294 |
| - if(is_dir($tmp_uploaded_path)) |
| 330 | + if(is_dir($mediaAbsPath)) |
295 | 331 | {
|
296 |
| - $file_list = FileHandler::readDir($tmp_uploaded_path); |
| 332 | + $file_list = FileHandler::readDir($mediaAbsPath, '/(_source_filename)$/is'); |
297 | 333 | $file_count = count($file_list);
|
298 | 334 | if($file_count)
|
299 | 335 | {
|
300 | 336 | $oFileController = getController('file');
|
301 |
| - for($i = 0; $i < $file_count; $i++) |
| 337 | + $oFileModel = getModel('file'); |
| 338 | + foreach($file_list as $file) |
302 | 339 | {
|
303 |
| - $file_info['tmp_name'] = sprintf('%s%s', $tmp_uploaded_path, $file_list[$i]); |
304 |
| - $file_info['name'] = $file_list[$i]; |
| 340 | + $filename = FileHandler::readFile($mediaAbsPath . $file); |
| 341 | + $temp_filename = str_replace('_source_filename', '', $file); |
| 342 | + |
| 343 | + $file_info = array(); |
| 344 | + $file_info['tmp_name'] = sprintf('%s%s', $mediaAbsPath, $temp_filename); |
| 345 | + $file_info['name'] = $filename; |
305 | 346 | $fileOutput = $oFileController->insertFile($file_info, $this->module_srl, $document_srl, 0, true);
|
306 |
| - $uploaded_filename = $fileOutput->get('uploaded_filename'); |
307 |
| - $source_filename = $fileOutput->get('source_filename'); |
308 |
| - $obj->content = str_replace($uploaded_target_path . $source_filename, sprintf('/files/attach/images/%s/%s%s', $this->module_srl, getNumberingPath($document_srl, 3), $uploaded_filename), $obj->content); |
| 347 | + |
| 348 | + if($fileOutput->get('direct_download') === 'N') |
| 349 | + { |
| 350 | + $replace_url = Context::getRequestUri() . $oFileModel->getDownloadUrl($fileOutput->file_srl, $fileOutput->sid, $this->module_srl); |
| 351 | + } |
| 352 | + else |
| 353 | + { |
| 354 | + $replace_url = Context::getRequestUri() . $fileOutput->get('uploaded_filename'); |
| 355 | + } |
| 356 | + |
| 357 | + $obj->content = str_replace($mediaUrlPath . $temp_filename, $replace_url, $obj->content); |
309 | 358 | }
|
310 | 359 | $obj->uploaded_count = $file_count;
|
311 | 360 | }
|
|
332 | 381 | {
|
333 | 382 | $content = getXmlRpcResponse(strval($document_srl));
|
334 | 383 | }
|
335 |
| - FileHandler::removeDir($tmp_uploaded_path); |
| 384 | + FileHandler::removeDir($mediaAbsPath); |
336 | 385 |
|
337 | 386 | printContent($content);
|
338 | 387 | break;
|
|
404 | 453 | // Document srl
|
405 | 454 | $obj->document_srl = $document_srl;
|
406 | 455 | $obj->module_srl = $this->module_srl;
|
| 456 | + |
407 | 457 | // Attachment
|
408 |
| - if(is_dir($tmp_uploaded_path)) |
| 458 | + if(is_dir($mediaAbsPath)) |
409 | 459 | {
|
410 |
| - $file_list = FileHandler::readDir($tmp_uploaded_path); |
| 460 | + $file_list = FileHandler::readDir($mediaAbsPath, '/(_source_filename)$/is'); |
411 | 461 | $file_count = count($file_list);
|
412 | 462 | if($file_count)
|
413 | 463 | {
|
414 | 464 | $oFileController = getController('file');
|
415 |
| - for($i = 0; $i < $file_count; $i++) |
| 465 | + $oFileModel = getModel('file'); |
| 466 | + foreach($file_list as $file) |
416 | 467 | {
|
417 |
| - $file_info['tmp_name'] = sprintf('%s%s', $tmp_uploaded_path, $file_list[$i]); |
418 |
| - $file_info['name'] = $file_list[$i]; |
419 |
| - |
420 |
| - $moved_filename = sprintf('./files/attach/images/%s/%s/%s', $this->module_srl, $document_srl, $file_info['name']); |
421 |
| - if(file_exists($moved_filename)) |
422 |
| - continue; |
| 468 | + $filename = FileHandler::readFile($mediaAbsPath . $file); |
| 469 | + $temp_filename = str_replace('_source_filename', '', $file); |
423 | 470 |
|
| 471 | + $file_info = array(); |
| 472 | + $file_info['tmp_name'] = sprintf('%s%s', $mediaAbsPath, $temp_filename); |
| 473 | + $file_info['name'] = $filename; |
424 | 474 | $fileOutput = $oFileController->insertFile($file_info, $this->module_srl, $document_srl, 0, true);
|
425 |
| - $uploaded_filename = $fileOutput->get('uploaded_filename'); |
426 |
| - $source_filename = $fileOutput->get('source_filename'); |
427 |
| - $obj->content = str_replace($uploaded_target_path . $source_filename, sprintf('/files/attach/images/%s/%s%s', $this->module_srl, getNumberingPath($document_srl, 3), $uploaded_filename), $obj->content); |
| 475 | + |
| 476 | + if($fileOutput->get('direct_download') === 'N') |
| 477 | + { |
| 478 | + $replace_url = Context::getRequestUri() . $oFileModel->getDownloadUrl($fileOutput->file_srl, $fileOutput->sid, $this->module_srl); |
| 479 | + } |
| 480 | + else |
| 481 | + { |
| 482 | + $replace_url = Context::getRequestUri() . $fileOutput->get('uploaded_filename'); |
| 483 | + } |
| 484 | + |
| 485 | + $obj->content = str_replace($mediaUrlPath . $temp_filename, $replace_url, $obj->content); |
428 | 486 | }
|
429 | 487 | $obj->uploaded_count += $file_count;
|
430 | 488 | }
|
|
440 | 498 | else
|
441 | 499 | {
|
442 | 500 | $content = getXmlRpcResponse(true);
|
443 |
| - FileHandler::removeDir($tmp_uploaded_path); |
| 501 | + FileHandler::removeDir($mediaAbsPath); |
444 | 502 | }
|
445 | 503 |
|
446 | 504 | printContent($content);
|
|
0 commit comments