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
|
|
|
FriendrequestHandler |
22
|
|
|
}; |
23
|
|
|
|
24
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'suico_index.tpl'; |
25
|
|
|
require __DIR__ . '/header.php'; |
26
|
|
|
/** |
27
|
|
|
* Modules class includes |
28
|
|
|
*/ |
29
|
|
|
//require_once __DIR__ . '/class/Friendrequest.php'; |
30
|
|
|
/** |
31
|
|
|
* Factory of friendrequests created |
32
|
|
|
*/ |
33
|
|
|
$friendrequestFactory = new FriendrequestHandler($xoopsDB); |
34
|
|
|
/** |
35
|
|
|
* Getting the uid of the user which user want to ask to be friend |
36
|
|
|
*/ |
37
|
|
|
$friendrequestfrom_uid = $_POST['friendrequestfrom_uid']; |
38
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
39
|
|
|
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_TOKENEXPIRED); |
40
|
|
|
} |
41
|
|
|
//Verify if the user has already asked for friendship or if the user he s asking to be a friend has already asked him |
42
|
|
|
$criteria = new CriteriaCompo( |
43
|
|
|
new Criteria( |
44
|
|
|
'friendrequestto_uid', |
45
|
|
|
$friendrequestfrom_uid |
46
|
|
|
) |
47
|
|
|
); |
48
|
|
|
$criteria->add(new Criteria('friendrequester_uid', $xoopsUser->getVar('uid'))); |
49
|
|
|
if ($friendrequestFactory->getCount($criteria) > 0) { |
50
|
|
|
redirect_header( |
51
|
|
|
XOOPS_URL . '/modules/suico/index.php?uid=' . Request::getInt('friendrequestfrom_uid', 0, 'POST'), |
52
|
|
|
3, |
53
|
|
|
_MD_SUICO_ALREADY_FRIEND_REQUESTFROM |
54
|
|
|
); |
55
|
|
|
} else { |
56
|
|
|
$criteria2 = new CriteriaCompo(new Criteria('friendrequester_uid', $friendrequestfrom_uid)); |
57
|
|
|
$criteria2->add(new Criteria('friendrequestto_uid', $xoopsUser->getVar('uid'))); |
58
|
|
|
if ($friendrequestFactory->getCount($criteria2) > 0) { |
59
|
|
|
redirect_header( |
60
|
|
|
XOOPS_URL . '/modules/suico/index.php?uid=' . Request::getInt('friendrequestfrom_uid', 0, 'POST'), |
61
|
|
|
3, |
62
|
|
|
_MD_SUICO_ALREADY_FRIEND_REQUESTFROM |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
/** |
67
|
|
|
* create the friendrequest in database |
68
|
|
|
*/ |
69
|
|
|
$newFriendrequest = $friendrequestFactory->create(true); |
70
|
|
|
$newFriendrequest->setVar('friendrequester_uid', $xoopsUser->getVar('uid')); |
71
|
|
|
$newFriendrequest->setVar('friendrequestto_uid', Request::getInt('friendrequestfrom_uid', 0, 'POST')); |
72
|
|
|
if ($friendrequestFactory->insert2($newFriendrequest)) { |
73
|
|
|
$extra_tags['X_OWNER_NAME'] = $xoopsUser->getVar('uname'); |
74
|
|
|
$extra_tags['X_OWNER_UID'] = $xoopsUser->getVar('uid'); |
75
|
|
|
/** @var \XoopsNotificationHandler $notificationHandler */ |
76
|
|
|
$notificationHandler = xoops_getHandler('notification'); |
77
|
|
|
$notificationHandler->triggerEvent('friendship', Request::getInt('friendrequestfrom_uid', 0, 'POST'), 'new_friendship', $extra_tags); |
78
|
|
|
redirect_header( |
79
|
|
|
XOOPS_URL . '/modules/suico/index.php?uid=' . Request::getInt('friendrequestfrom_uid', 0, 'POST'), |
80
|
|
|
3, |
81
|
|
|
_MD_SUICO_FRIENDREQUEST_FROM |
82
|
|
|
); |
83
|
|
|
} else { |
84
|
|
|
redirect_header( |
85
|
|
|
XOOPS_URL . '/modules/suico/index.php?uid=' . $xoopsUser->getVar('uid'), |
86
|
|
|
3, |
87
|
|
|
_MD_SUICO_ERROR |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
/** |
91
|
|
|
* Close page |
92
|
|
|
*/ |
93
|
|
|
require \dirname(__DIR__, 2) . '/footer.php'; |
94
|
|
|
|
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: