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
|
|
|
RelgroupuserHandler, |
22
|
|
|
GroupsHandler |
23
|
|
|
}; |
24
|
|
|
|
25
|
|
|
require __DIR__ . '/header.php'; |
26
|
|
|
/** |
27
|
|
|
* Modules class includes |
28
|
|
|
*/ |
29
|
|
|
//require_once __DIR__ . '/class/Friendrequest.php'; |
30
|
|
|
//require_once __DIR__ . '/class/Relgroupuser.php'; |
31
|
|
|
//require_once __DIR__ . '/class/Groups.php'; |
32
|
|
|
/** |
33
|
|
|
* Factories of groups |
34
|
|
|
*/ |
35
|
|
|
$relgroupuserFactory = new RelgroupuserHandler($xoopsDB); |
36
|
|
|
$groupsFactory = new GroupsHandler($xoopsDB); |
37
|
|
|
$marker = Request::getInt('marker', 0, 'POST'); |
38
|
|
|
if (1 == $marker) { //if (1 === $marker) { |
39
|
|
|
/** |
40
|
|
|
* Verify Token |
41
|
|
|
*/ |
42
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
43
|
|
|
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_TOKENEXPIRED); |
44
|
|
|
} |
45
|
|
|
if (0 !== \Xmf\Request::getInt('group_id', 0)) { |
46
|
|
|
$groupsObject = $groupsHandler->get(Request::getInt('group_id', 0)); |
47
|
|
|
} else { |
48
|
|
|
$groupsObject = $groupsHandler->create(); |
49
|
|
|
} |
50
|
|
|
// Form save fields |
51
|
|
|
$groupsObject->setVar('owner_uid', (int)$xoopsUser->getVar('uid')); |
52
|
|
|
$groupsObject->setVar('group_title', Request::getString('group_title', '', 'POST')); |
53
|
|
|
$groupsObject->setVar('group_desc', Request::getString('group_desc', '', 'POST')); |
54
|
|
|
// $dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('date_created', '', 'POST')); |
55
|
|
|
// $groupsObject->setVar('date_created', $dateTimeObj->getTimestamp()); |
56
|
|
|
// $dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('date_updated', '', 'POST')); |
57
|
|
|
// $groupsObject->setVar('date_updated', $dateTimeObj->getTimestamp()); |
58
|
|
|
$groupsObject->setVar('date_created', \time()); |
59
|
|
|
$groupsObject->setVar('date_updated', \time()); |
60
|
|
|
require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
61
|
|
|
$uploadDir = XOOPS_UPLOAD_PATH . '/suico/groups/'; |
62
|
|
|
$uploader = new \XoopsMediaUploader( |
63
|
|
|
$uploadDir, |
64
|
|
|
$helper->getConfig('mimetypes'), |
65
|
|
|
$helper->getConfig('maxsize'), |
66
|
|
|
null, |
67
|
|
|
null |
68
|
|
|
); |
69
|
|
|
if ($uploader->fetchMedia(Request::getArray('xoops_upload_file', '', 'POST')[0])) { |
70
|
|
|
//$extension = preg_replace( '/^.+\.([^.]+)$/sU' , '' , $_FILES['attachedfile']['name']); |
71
|
|
|
//$imgName = str_replace(' ', '', $_POST['group_img']).'.'.$extension; |
72
|
|
|
$uploader->setPrefix('group_img_'); |
73
|
|
|
$uploader->fetchMedia(Request::getArray('xoops_upload_file', '', 'POST')[0]); |
74
|
|
|
if ($uploader->upload()) { |
75
|
|
|
$groupsObject->setVar('group_img', $uploader->getSavedFileName()); |
76
|
|
|
} else { |
77
|
|
|
$errors = $uploader->getErrors(); |
78
|
|
|
redirect_header('javascript:history.go(-1)', 3, $errors); |
79
|
|
|
} |
80
|
|
|
} else { |
81
|
|
|
$groupsObject->setVar('group_img', Request::getVar('group_img', '')); |
82
|
|
|
} |
83
|
|
|
if ($groupsHandler->insert($groupsObject)) { |
84
|
|
|
//add membership info for the group |
85
|
|
|
$relgroupuser = $relgroupuserFactory->create(); |
86
|
|
|
$relgroupuser->setVar('rel_group_id', $xoopsDB->getInsertId()); |
87
|
|
|
$relgroupuser->setVar('rel_user_uid', $xoopsUser->getVar('uid')); |
88
|
|
|
$relgroupuserFactory->insert($relgroupuser); |
89
|
|
|
$group_id = $relgroupuser->getVar('rel_group_id', $xoopsDB->getInsertId()); |
90
|
|
|
redirect_header('group.php?group_id=' . $group_id . '', 500, _MD_SUICO_GROUP_CREATED); |
91
|
|
|
redirect_header('groups.php?op=list', 2, _MD_SUICO_GROUP_SAVED); |
92
|
|
|
} else { |
93
|
|
|
redirect_header( |
94
|
|
|
XOOPS_URL . '/modules/suico/groups.php?uid=' . (int)$xoopsUser->getVar('uid'), |
95
|
|
|
2, |
96
|
|
|
_MD_SUICO_ERROR |
97
|
|
|
); |
98
|
|
|
$group_img = !empty($_POST['group_img']) ? Request::getString('group_img', '', 'POST') : ''; |
99
|
|
|
$path_upload = XOOPS_UPLOAD_PATH . '/suico/groups'; |
100
|
|
|
$pictwidth = $helper->getConfig('resized_width'); |
101
|
|
|
$pictheight = $helper->getConfig('resized_height'); |
102
|
|
|
$thumbwidth = $helper->getConfig('thumb_width'); |
103
|
|
|
$thumbheight = $helper->getConfig('thumb_height'); |
104
|
|
|
$maxfilebytes = $helper->getConfig('maxfilesize'); |
105
|
|
|
$maxfileheight = $helper->getConfig('max_original_height'); |
106
|
|
|
$maxfilewidth = $helper->getConfig('max_original_width'); |
107
|
|
|
if ($groupsFactory->receiveGroup( |
108
|
|
|
$group_title, |
109
|
|
|
$group_desc, |
110
|
|
|
'', |
111
|
|
|
$path_upload, |
112
|
|
|
$maxfilebytes, |
113
|
|
|
$maxfilewidth, |
114
|
|
|
$maxfileheight |
115
|
|
|
)) { |
116
|
|
|
//add membership info for the group |
117
|
|
|
$relgroupuser = $relgroupuserFactory->create(); |
118
|
|
|
$relgroupuser->setVar('rel_group_id', $xoopsDB->getInsertId()); |
119
|
|
|
$relgroupuser->setVar('rel_user_uid', $xoopsUser->getVar('uid')); |
120
|
|
|
$relgroupuserFactory->insert2($relgroupuser); |
121
|
|
|
$group_id = $relgroupuser->getVar('rel_group_id', $xoopsDB->getInsertId()); |
122
|
|
|
redirect_header('group.php?group_id=' . $group_id . '', 500, _MD_SUICO_GROUP_CREATED); |
123
|
|
|
} else { |
124
|
|
|
$groupsFactory->renderFormSubmit(120000, $xoopsTpl); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} else { |
128
|
|
|
$groupsFactory->renderFormSubmit(120000, $xoopsTpl); |
129
|
|
|
} |
130
|
|
|
/** |
131
|
|
|
* Close page |
132
|
|
|
*/ |
133
|
|
|
require \dirname(__DIR__, 2) . '/footer.php'; |
134
|
|
|
|
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: