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
|
|
|
ImageHandler |
22
|
|
|
}; |
23
|
|
|
|
24
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'suico_index.tpl'; |
25
|
|
|
require __DIR__ . '/header.php'; |
26
|
|
|
//require_once \dirname(__DIR__, 2) . '/header.php'; |
27
|
|
|
/** |
28
|
|
|
* Modules class includes |
29
|
|
|
*/ |
30
|
|
|
//require_once __DIR__ . '/class/Image.php'; |
31
|
|
|
/** |
32
|
|
|
* Factory of pictures created |
33
|
|
|
*/ |
34
|
|
|
$imageFactory = new ImageHandler($xoopsDB); |
35
|
|
|
/** |
36
|
|
|
* Getting the title |
37
|
|
|
*/ |
38
|
|
|
$title = Request::getString('title', '', 'POST'); |
39
|
|
|
$caption = Request::getString('caption', '', 'POST'); |
40
|
|
|
/** |
41
|
|
|
* Getting parameters defined in admin side |
42
|
|
|
*/ |
43
|
|
|
$path_upload = XOOPS_ROOT_PATH . '/uploads/suico/images'; |
44
|
|
|
$pictwidth = $helper->getConfig('resized_width'); |
45
|
|
|
$pictheight = $helper->getConfig('resized_height'); |
46
|
|
|
$thumbwidth = $helper->getConfig('thumb_width'); |
47
|
|
|
$thumbheight = $helper->getConfig('thumb_height'); |
48
|
|
|
$maxfilebytes = $helper->getConfig('maxfilesize'); |
49
|
|
|
$maxfileheight = $helper->getConfig('max_original_height'); |
50
|
|
|
$maxfilewidth = $helper->getConfig('max_original_width'); |
51
|
|
|
/** |
52
|
|
|
* If we are receiving a file |
53
|
|
|
*/ |
54
|
|
|
if ('sel_photo' === Request::getArray('xoops_upload_file', '', 'POST')[0]) { |
55
|
|
|
/** |
56
|
|
|
* Verify Token |
57
|
|
|
*/ |
58
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
59
|
|
|
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_TOKENEXPIRED); |
60
|
|
|
} |
61
|
|
|
ini_set('memory_limit', '50M'); |
62
|
|
|
/** |
63
|
|
|
* Try to upload picture resize it insert in database and then redirect to index |
64
|
|
|
*/ |
65
|
|
|
if ($imageFactory->receivePicture( |
66
|
|
|
$title, |
67
|
|
|
$caption, |
68
|
|
|
$path_upload, |
69
|
|
|
$thumbwidth, |
70
|
|
|
$thumbheight, |
71
|
|
|
$pictwidth, |
72
|
|
|
$pictheight, |
73
|
|
|
$maxfilebytes, |
74
|
|
|
$maxfilewidth, |
75
|
|
|
$maxfileheight |
76
|
|
|
)) { |
77
|
|
|
$extra_tags['X_OWNER_NAME'] = $xoopsUser->getVar('uname'); |
78
|
|
|
$extra_tags['X_OWNER_UID'] = $xoopsUser->getVar('uid'); |
79
|
|
|
/** @var \XoopsNotificationHandler $notificationHandler */ |
80
|
|
|
$notificationHandler = xoops_getHandler('notification'); |
81
|
|
|
$notificationHandler->triggerEvent('picture', $xoopsUser->getVar('uid'), 'new_picture', $extra_tags); |
82
|
|
|
//header("Location: ".XOOPS_URL."/modules/suico/index.php?uid=".$xoopsUser->getVar('uid')); |
83
|
|
|
$imageId = $imageFactory->db->getInsertId(); |
84
|
|
|
redirect_header( |
85
|
|
|
XOOPS_URL . '/modules/suico/album.php?uid=' . $xoopsUser->getVar('uid') . '#' . $imageId, |
86
|
|
|
3, |
87
|
|
|
_MD_SUICO_UPLOADED |
88
|
|
|
); |
89
|
|
|
} else { |
90
|
|
|
redirect_header( |
91
|
|
|
XOOPS_URL . '/modules/suico/album.php?uid=' . $xoopsUser->getVar('uid'), |
92
|
|
|
3, |
93
|
|
|
_MD_SUICO_ERROR |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
/** |
98
|
|
|
* Close page |
99
|
|
|
*/ |
100
|
|
|
require \dirname(__DIR__, 2) . '/footer.php'; |
101
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are 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.php
However, as
OtherDir/Foo.php
does 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: