| 1: | <?php |
| 2: | |
| 3: | /** |
| 4: | * SystemFineImUploadHandler class to work with ajaxfineupload.php endpoint |
| 5: | * to facilitate uploads for the system image manager |
| 6: | * |
| 7: | * Do not use or reference this directly from your client-side code. |
| 8: | * Instead, this should be required via the endpoint.php or endpoint-cors.php |
| 9: | * file(s). |
| 10: | * |
| 11: | * @license MIT License (MIT) |
| 12: | * @copyright Copyright (c) 2015-present, Widen Enterprises, Inc. |
| 13: | * @link https://github.com/FineUploader/php-traditional-server |
| 14: | * |
| 15: | * The MIT License (MIT) |
| 16: | * |
| 17: | * Copyright (c) 2015-present, Widen Enterprises, Inc. |
| 18: | * |
| 19: | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 20: | * of this software and associated documentation files (the "Software"), to deal |
| 21: | * in the Software without restriction, including without limitation the rights |
| 22: | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 23: | * copies of the Software, and to permit persons to whom the Software is |
| 24: | * furnished to do so, subject to the following conditions: |
| 25: | * |
| 26: | * The above copyright notice and this permission notice shall be included in all |
| 27: | * copies or substantial portions of the Software. |
| 28: | * |
| 29: | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 30: | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 31: | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 32: | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 33: | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 34: | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 35: | * SOFTWARE. |
| 36: | */ |
| 37: | |
| 38: | class SystemFineAvatarUploadHandler extends SystemFineUploadHandler |
| 39: | { |
| 40: | /** |
| 41: | * XoopsFineAvatarUploadHandler constructor. |
| 42: | * @param stdClass $claims claims passed in JWT header |
| 43: | */ |
| 44: | public function __construct(\stdClass $claims) |
| 45: | { |
| 46: | parent::__construct($claims); |
| 47: | $this->allowedMimeTypes = array('image/gif', 'image/jpeg', 'image/png'); |
| 48: | $this->allowedExtensions = array('gif', 'jpeg', 'jpg', 'png'); |
| 49: | } |
| 50: | |
| 51: | protected function storeUploadedFile($target, $mimeType, $uuid) |
| 52: | { |
| 53: | $pathParts = pathinfo($this->getName()); |
| 54: | $avatarName = uniqid('savt', true) . '.' . strtolower($pathParts['extension']); |
| 55: | $avatarNicename = str_replace(array('_','-'), ' ', $pathParts['filename']); |
| 56: | $avatarPath = XOOPS_ROOT_PATH . '/uploads/avatars/' . $avatarName; |
| 57: | |
| 58: | if (false === move_uploaded_file($_FILES[$this->inputName]['tmp_name'], $avatarPath)) { |
| 59: | return false; |
| 60: | } |
| 61: | /** @var XoopsAvatarHandler $avt_handler */ |
| 62: | $avt_handler = xoops_getHandler('avatar'); |
| 63: | $avatar = $avt_handler->create(); |
| 64: | |
| 65: | $avatar->setVar('avatar_file', 'avatars/' . $avatarName); |
| 66: | $avatar->setVar('avatar_name', $avatarNicename); |
| 67: | $avatar->setVar('avatar_mimetype', $mimeType); |
| 68: | $avatar->setVar('avatar_created', time()); |
| 69: | $avatar->setVar('avatar_display', 1); |
| 70: | $avatar->setVar('avatar_weight', 0); |
| 71: | $avatar->setVar('avatar_type', 's'); |
| 72: | if (!$avt_handler->insert($avatar)) { |
| 73: | return array( |
| 74: | 'error' => sprintf(_FAILSAVEIMG, $avatar->getVar('avatar_name')) |
| 75: | ); |
| 76: | } |
| 77: | return array('success'=> true, "uuid" => $uuid); |
| 78: | } |
| 79: | } |
| 80: |