XoopsModules25x /
suico
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | /* |
||
| 5 | You may not change or alter any portion of this comment or credits |
||
| 6 | of supporting developers from this source code or any supporting source code |
||
| 7 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, |
||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 12 | */ |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @category Module |
||
| 16 | * @package suico |
||
| 17 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 18 | * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
| 19 | * @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
||
| 20 | */ |
||
| 21 | |||
| 22 | use Xmf\Request; |
||
| 23 | use XoopsModules\Suico\{ |
||
| 24 | Image, |
||
| 25 | ImageHandler |
||
| 26 | }; |
||
| 27 | /** @var Image $picture */ |
||
| 28 | |||
| 29 | require __DIR__ . '/header.php'; |
||
| 30 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
| 31 | redirect_header('index.php', 3, _MD_SUICO_TOKENEXPIRED); |
||
| 32 | } |
||
| 33 | /** |
||
| 34 | * Creating the factory loading the picture changing its caption |
||
| 35 | */ |
||
| 36 | $imageFactory = new ImageHandler( |
||
| 37 | $xoopsDB |
||
| 38 | ); |
||
| 39 | $picture = $imageFactory->create(false); |
||
| 40 | $picture->load(Request::getString('image_id', '', 'POST')); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 41 | $uid = (int)$xoopsUser->getVar('uid'); |
||
| 42 | $image = XOOPS_ROOT_PATH . '/uploads/suico/images/' . 'thumb_' . $picture->getVar('filename'); |
||
| 43 | $avatar = 'av' . $uid . '_' . time() . '.jpg'; |
||
| 44 | $imageavatar = XOOPS_ROOT_PATH . '/uploads/avatars/' . $avatar; |
||
| 45 | if (!copy($image, $imageavatar)) { |
||
| 46 | echo 'failed to copy $file...\n'; |
||
| 47 | } |
||
| 48 | $xoopsUser->setVar('user_avatar', 'avatars/' . $avatar); |
||
| 49 | $userHandler = new \XoopsUserHandler($xoopsDB); |
||
| 50 | /** |
||
| 51 | * Verifying who's the owner to allow changes |
||
| 52 | */ |
||
| 53 | if ($uid === (int)$picture->getVar('uid_owner')) { |
||
| 54 | if ($userHandler->insert($xoopsUser)) { |
||
| 55 | redirect_header('album.php', 2, _MD_SUICO_AVATAR_EDITED); |
||
| 56 | } else { |
||
| 57 | redirect_header('album.php', 2, _MD_SUICO_ERROR); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | require dirname(__DIR__, 2) . '/footer.php'; |
||
| 61 |