|
1
|
|
|
<?php |
|
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
|
|
|
* SmallWorld |
|
14
|
|
|
* |
|
15
|
|
|
* @package \XoopsModules\Smallworld |
|
16
|
|
|
* @license GNU GPL (https://www.gnu.org/licenses/gpl-2.0.html/) |
|
17
|
|
|
* @copyright The XOOPS Project (https://xoops.org) |
|
18
|
|
|
* @copyright 2011 Culex |
|
19
|
|
|
* @author Michael Albertsen (http://culex.dk) <[email protected]> |
|
20
|
|
|
* @link https://github.com/XoopsModules25x/smallworld |
|
21
|
|
|
* @since 1.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
use Xmf\Request; |
|
25
|
|
|
use XoopsModules\Smallworld; |
|
26
|
|
|
use XoopsModules\Smallworld\Constants; |
|
27
|
|
|
|
|
28
|
|
|
require_once __DIR__ . '/header.php'; |
|
29
|
|
|
|
|
30
|
|
|
/** @var \XoopsModules\Smallworld\Helper $helper */ |
|
31
|
|
|
require_once $helper->path('include/functions.php'); |
|
32
|
|
|
$GLOBALS['xoopsLogger']->activated = false; |
|
33
|
|
|
|
|
34
|
|
|
$friend = Request::getInt('friend', 0, 'POST'); |
|
35
|
|
|
$check = new Smallworld\User(); |
|
36
|
|
|
//$friendProfile = $check->checkIfProfile($friend); |
|
37
|
|
|
/** @var \XoopsModules\Smallworld\SwUserHandler $swUserHandler */ |
|
38
|
|
|
$swUserHandler = $helper->getHandler('SwUser'); |
|
39
|
|
|
$friendProfile = $swUserHandler->checkIfProfile($friend); |
|
40
|
|
|
|
|
41
|
|
|
if (Constants::PROFILE_HAS_BOTH > $friendProfile) { |
|
42
|
|
|
$helper->redirect('index.php', 3, _SMALLWORLD_NOUSER_ERROR); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$swDB = new Smallworld\SwDatabase; |
|
46
|
|
|
$mail = new Smallworld\Mail(); |
|
47
|
|
|
$stat = Request::getInt('stat', 0, 'POST'); |
|
48
|
|
|
$invitation = Request::getInt('invitation', 0, 'POST'); |
|
49
|
|
|
$myUid = Request::getInt('myUid', 0, 'POST'); |
|
50
|
|
|
$friendName = $swUserHandler->getName($friend); |
|
|
|
|
|
|
51
|
|
|
$yourName = $swUserHandler->getName($myUid); |
|
|
|
|
|
|
52
|
|
|
$USC = json_decode($swDB->getSettings($friend), true); |
|
53
|
|
|
|
|
54
|
|
|
switch ($invitation) { |
|
55
|
|
|
case 1: |
|
56
|
|
|
$friendshipExists = $check->friendcheck($myUid, $friend); |
|
57
|
|
|
if (0 == $friendshipExists[0]) { |
|
58
|
|
|
$resultMsg = _SMALLWORLD_JSON_ADDFRIEND . $friendName . _SMALLWORLD_JSON_REQUEST_PENDING; |
|
59
|
|
View Code Duplication |
if (0 != $helper->getConfig('smallworldusemailnotis')) { |
|
|
|
|
|
|
60
|
|
|
if (1 == $USC['notify']) { |
|
61
|
|
|
$mail->sendMails($friend, $friend, 'friendshipfollow', $link = null, []); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
$swDB->toogleFriendInvite($friendshipExists, $friend, $myUid); |
|
|
|
|
|
|
65
|
|
|
echo json_encode(['error' => 'no', 'msg' => $resultMsg, 'msgChange' => _SMALLWORLD_JSON_CANCELFR_TEXT]); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if ($friendshipExists[0] > 0 and $friendshipExists[0] < 2) { |
|
69
|
|
|
$resultMsg = _SMALLWORLD_JSON_CANCEL_ADDFRIEND . $friendName; |
|
70
|
|
|
$swDB->toogleFriendInvite($friendshipExists, $friend, $myUid); |
|
|
|
|
|
|
71
|
|
|
echo json_encode(['error' => 'no', 'msg' => $resultMsg, 'msgChange' => _SMALLWORLD_JSON_ADDFR_TEXT]); |
|
72
|
|
|
} |
|
73
|
|
|
if (Constants::PROFILE_HAS_BOTH == $friendshipExists[0]) { |
|
74
|
|
|
$resultMsg = _SMALLWORLD_JSON_DELETE_FRIEND_START . $friendName . _SMALLWORLD_JSON_DELETE_FRIEND_END; |
|
75
|
|
|
$swDB->toogleFriendInvite($friendshipExists, $friend, $myUid); |
|
|
|
|
|
|
76
|
|
|
echo json_encode(['error' => 'no', 'msg' => $resultMsg, 'msgChange' => _SMALLWORLD_JSON_ADDFR_TEXT]); |
|
77
|
|
|
} |
|
78
|
|
|
break; |
|
79
|
|
|
case 2: |
|
80
|
|
|
// Used for followers |
|
81
|
|
|
$following = $check->following_or($myUid, $friend); |
|
82
|
|
|
|
|
83
|
|
View Code Duplication |
if (0 == $following[0]) { |
|
84
|
|
|
$resultMsgFollow = _SMALLWORLD_JSON_FOLLOWINGFRIEND . $friendName . _SMALLWORLD_JSON_FOLLOWINGFRIEND_DESC; |
|
85
|
|
|
$swDB->toogleFollow($following[0], $myUid, $friend); |
|
86
|
|
|
echo json_encode(['error' => 'no', 'msg' => $resultMsgFollow, 'msgChange' => _SMALLWORLD_JSON_FLNO_TEXT]); |
|
87
|
|
|
} |
|
88
|
|
View Code Duplication |
if (0 < $following[0]) { |
|
89
|
|
|
$resultMsgFollow = _SMALLWORLD_JSON_UNFOLLOWINGFRIEND . $friendName . _SMALLWORLD_JSON_UNFOLLOWINGFRIEND_DESC; |
|
90
|
|
|
$swDB->toogleFollow($following[0], $myUid, $friend); |
|
91
|
|
|
echo json_encode(['error' => 'no', 'msg' => $resultMsgFollow, 'msgChange' => _SMALLWORLD_JSON_FLYES_TEXT]); |
|
92
|
|
|
} |
|
93
|
|
|
break; |
|
94
|
|
|
case 3: |
|
95
|
|
|
// Used for accept/deny friendship requests |
|
96
|
|
View Code Duplication |
if ($stat > 0) { |
|
97
|
|
|
// Friendship is accepted (update status in mysql) |
|
98
|
|
|
$swDB->setFriendshitStat(1, $myUid, $friend); |
|
|
|
|
|
|
99
|
|
|
$acceptMsg = _SMALLWORLD_JSON_DELETE_FRIEND_START . $friendName . _SMALLWORLD_JSON_DELETE_FRIEND_END; |
|
100
|
|
|
echo json_encode(['error' => 'no', 'msg' => $acceptMsg, 'msgChange' => _SMALLWORLD_JSON_REMOVEFR_TEXT]); |
|
101
|
|
|
} |
|
102
|
|
View Code Duplication |
if ($stat < 0) { |
|
103
|
|
|
// friendship is denied (delete from mysql) |
|
104
|
|
|
$swDB->setFriendshitStat(-1, $myUid, $friend); |
|
|
|
|
|
|
105
|
|
|
$acceptMsg = _SMALLWORLD_JSON_ADDFRIEND . $friendName . _SMALLWORLD_JSON_REQUEST_PENDING; |
|
106
|
|
|
echo json_encode(['error' => 'no', 'msg' => $acceptMsg, 'msgChange' => _SMALLWORLD_JSON_ADDFR_TEXT]); |
|
107
|
|
|
} |
|
108
|
|
|
break; |
|
109
|
|
|
} |
|
110
|
|
|
|