|
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
|
|
|
FriendshipHandler |
|
23
|
|
|
}; |
|
24
|
|
|
|
|
25
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'suico_index.tpl'; |
|
26
|
|
|
require __DIR__ . '/header.php'; |
|
27
|
|
|
//require_once __DIR__ . '/class/Friendrequest.php'; |
|
28
|
|
|
//require_once __DIR__ . '/class/Friendship.php'; |
|
29
|
|
|
/** |
|
30
|
|
|
* Factory of friendrequests created |
|
31
|
|
|
*/ |
|
32
|
|
|
$friendrequestFactory = new FriendrequestHandler($xoopsDB); |
|
33
|
|
|
$friendshipFactory = new FriendshipHandler($xoopsDB); |
|
34
|
|
|
$friendrequest_id = Request::getInt('friendrequest_id', 0, 'POST'); |
|
35
|
|
|
$friendship_level = Request::getInt('level', 0, 'POST'); |
|
36
|
|
|
$uid = (int)$xoopsUser->getVar('uid'); |
|
37
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
|
38
|
|
|
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_TOKENEXPIRED); |
|
39
|
|
|
} |
|
40
|
|
|
$criteria = new CriteriaCompo(new Criteria('friendreq_id', $friendrequest_id)); |
|
41
|
|
|
$criteria->add(new Criteria('friendrequestto_uid', $uid)); |
|
42
|
|
|
if ($friendrequestFactory->getCount($criteria) > 0) { |
|
43
|
|
|
if (($friendship_level > 0) && ($friendrequest = $friendrequestFactory->getObjects($criteria))) { |
|
44
|
|
|
$friend1_uid = $friendrequest[0]->getVar('friendrequester_uid'); |
|
45
|
|
|
$friend2_uid = $friendrequest[0]->getVar('friendrequestto_uid'); |
|
46
|
|
|
$newfriendship1 = $friendshipFactory->create(true); |
|
47
|
|
|
$newfriendship1->setVar('level', 3); |
|
48
|
|
|
$newfriendship1->setVar('friend1_uid', $friend1_uid); |
|
49
|
|
|
$newfriendship1->setVar('friend2_uid', $friend2_uid); |
|
50
|
|
|
$newfriendship2 = $friendshipFactory->create(true); |
|
51
|
|
|
$newfriendship2->setVar('level', $friendship_level); |
|
52
|
|
|
$newfriendship2->setVar('friend1_uid', $friend2_uid); |
|
53
|
|
|
$newfriendship2->setVar('friend2_uid', $friend1_uid); |
|
54
|
|
|
$friendrequestFactory->deleteAll($criteria); |
|
55
|
|
|
$friendshipFactory->insert2($newfriendship1); |
|
56
|
|
|
$friendshipFactory->insert2($newfriendship2); |
|
57
|
|
|
redirect_header(XOOPS_URL . '/modules/suico/friends.php?uid=' . $friend2_uid, 3, _MD_SUICO_FRIENDMADE); |
|
58
|
|
|
} else { |
|
59
|
|
|
if (0 === $friendship_level) { |
|
60
|
|
|
$friendrequestFactory->deleteAll($criteria); |
|
61
|
|
|
redirect_header(XOOPS_URL . '/modules/suico/index.php?uid=' . $uid, 3, _MD_SUICO_FRIENDSHIP_NOTACCEPTED); |
|
62
|
|
|
} |
|
63
|
|
|
redirect_header(XOOPS_URL . '/modules/suico/index.php?uid=' . $uid, 3, _MD_SUICO_ERROR); |
|
64
|
|
|
} |
|
65
|
|
|
} else { |
|
66
|
|
|
redirect_header(XOOPS_URL . '/modules/suico/index.php?uid=' . $uid, 3, _MD_SUICO_ERROR); |
|
67
|
|
|
} |
|
68
|
|
|
require \dirname(__DIR__, 2) . '/footer.php'; |
|
69
|
|
|
|
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: