|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @category Module |
|
14
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
15
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
16
|
|
|
* @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
use Xmf\Request; |
|
|
|
|
|
|
20
|
|
|
use XoopsModules\Suico\{ |
|
21
|
|
|
Image, |
|
22
|
|
|
ImageHandler |
|
23
|
|
|
}; |
|
24
|
|
|
/** @var Image $picture */ |
|
25
|
|
|
require __DIR__ . '/header.php'; |
|
26
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
|
27
|
|
|
redirect_header('index.php', 3, _MD_SUICO_TOKENEXPIRED); |
|
28
|
|
|
} |
|
29
|
|
|
/** |
|
30
|
|
|
* Creating the factory loading the picture changing its caption |
|
31
|
|
|
*/ |
|
32
|
|
|
/** @var ImageHandler $imageFactory */ |
|
33
|
|
|
$imageFactory = new ImageHandler( |
|
34
|
|
|
$xoopsDB |
|
35
|
|
|
); |
|
36
|
|
|
$picture = $imageFactory->create(false); |
|
37
|
|
|
$picture->load(Request::getString('image_id', '', 'POST')); |
|
38
|
|
|
$uid = (int)$xoopsUser->getVar('uid'); |
|
39
|
|
|
$image = XOOPS_ROOT_PATH . '/uploads/suico/images/' . 'thumb_' . $picture->getVar('filename'); |
|
40
|
|
|
$avatar = 'av' . $uid . '_' . time() . '.jpg'; |
|
41
|
|
|
$imageavatar = XOOPS_ROOT_PATH . '/uploads/avatars/' . $avatar; |
|
42
|
|
|
if (!copy($image, $imageavatar)) { |
|
43
|
|
|
echo 'failed to copy $file...\n'; |
|
44
|
|
|
} |
|
45
|
|
|
$xoopsUser->setVar('user_avatar', 'avatars/' . $avatar); |
|
46
|
|
|
$userHandler = new \XoopsUserHandler($xoopsDB); |
|
47
|
|
|
/** |
|
48
|
|
|
* Verifying who's the owner to allow changes |
|
49
|
|
|
*/ |
|
50
|
|
|
if ($uid === (int)$picture->getVar('uid_owner')) { |
|
51
|
|
|
if ($userHandler->insert($xoopsUser)) { |
|
52
|
|
|
redirect_header('album.php', 2, _MD_SUICO_AVATAR_EDITED); |
|
53
|
|
|
} else { |
|
54
|
|
|
redirect_header('album.php', 2, _MD_SUICO_ERROR); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
require \dirname(__DIR__, 2) . '/footer.php'; |
|
58
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: