|
1
|
|
|
<?php namespace XoopsModules\Smallworld; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* You may not change or alter any portion of this comment or credits |
|
5
|
|
|
* of supporting developers from this source code or any supporting source code |
|
6
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
* |
|
8
|
|
|
* This program is distributed in the hope that it will be useful, |
|
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* SmallWorld |
|
15
|
|
|
* |
|
16
|
|
|
* @copyright The XOOPS Project (https://xoops.org) |
|
17
|
|
|
* @copyright 2011 Culex |
|
18
|
|
|
* @license GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/) |
|
19
|
|
|
* @package SmallWorld |
|
20
|
|
|
* @since 1.0 |
|
21
|
|
|
* @author Michael Albertsen (http://culex.dk) <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
//include_once $GLOBALS['xoops']->path('include/common.php'); |
|
24
|
|
|
|
|
25
|
|
|
use XoopsModules\Smallworld; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Class User |
|
29
|
|
|
* @package XoopsModules\Smallworld |
|
30
|
|
|
*/ |
|
31
|
|
|
class User |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @Check if user has profile |
|
36
|
|
|
* @param int $userID |
|
37
|
|
|
* @return int |
|
38
|
|
|
*/ |
|
39
|
|
|
public function checkIfProfile($userID) |
|
40
|
|
|
{ |
|
41
|
|
|
global $xoopsUser, $xoopsDB; |
|
42
|
|
|
$i = 0; |
|
|
|
|
|
|
43
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . $userID . "'"; |
|
44
|
|
|
$result = $xoopsDB->queryF($sql); |
|
45
|
|
|
$i = $xoopsDB->getRowsNum($result); |
|
46
|
|
|
if ($xoopsUser) { |
|
47
|
|
|
// If xoopsuser but no smallworld profile |
|
48
|
|
|
if (0 == $i) { |
|
49
|
|
|
$i = 1; |
|
50
|
|
|
} else { |
|
51
|
|
|
// if xoopsuser and has profile |
|
52
|
|
|
$i = 2; |
|
53
|
|
|
} |
|
54
|
|
|
} else { |
|
55
|
|
|
// if not xoopsUser ie anonymous user |
|
56
|
|
|
$i = 0; |
|
57
|
|
|
} |
|
58
|
|
|
return $i; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @Create user |
|
63
|
|
|
* @param int $userid |
|
64
|
|
|
* @return void |
|
65
|
|
|
*/ |
|
66
|
|
|
public function createUser($userid) |
|
67
|
|
|
{ |
|
68
|
|
|
global $xoopsUser, $xoopsDB; |
|
69
|
|
|
$a = new $xoopsUser($userid); |
|
70
|
|
|
$b = $a->uname(); |
|
|
|
|
|
|
71
|
|
|
$sql = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_user') . ' (userid) VALUES (' . (int)$userid . ')'; |
|
72
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @Check is user is smallworld user |
|
77
|
|
|
* @return void |
|
78
|
|
|
*/ |
|
79
|
|
|
public function chkUser() |
|
80
|
|
|
{ |
|
81
|
|
|
global $xoopsUser, $xoopsTpl; |
|
82
|
|
|
$greeting = '<br>'; |
|
83
|
|
|
$greeting .= _SMALLWORLD_NOTYETUSER_GREETING . ' ' . $xoopsUser->uname() . '.<br><br>'; |
|
84
|
|
|
$greeting .= _SMALLWORLD_NOTYETUSER_BOXTEXT; |
|
85
|
|
|
|
|
86
|
|
|
$xoopsTpl->assign('notyetusercontent', $greeting); |
|
87
|
|
|
$xoopsTpl->assign('check', 0); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @Check is user is friend |
|
92
|
|
|
* @param int $user |
|
93
|
|
|
* @param int $userID |
|
94
|
|
|
* @return array|int |
|
|
|
|
|
|
95
|
|
|
*/ |
|
96
|
|
|
public function friendcheck($user, $userID) |
|
97
|
|
|
{ |
|
98
|
|
|
global $xoopsUser, $xoopsDB; |
|
99
|
|
|
$respons = []; |
|
100
|
|
|
if ($user == $userID) { |
|
101
|
|
|
$respons[0] = 2; |
|
102
|
|
|
return $respons; |
|
103
|
|
|
} |
|
104
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . (int)$user . "' AND you = '" . (int)$userID . "'"; |
|
105
|
|
|
$result = $xoopsDB->query($sql); |
|
106
|
|
|
$i = $xoopsDB->getRowsNum($result); |
|
107
|
|
|
if (0 == $i) { |
|
108
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE you = '" . (int)$user . "' AND me = '" . (int)$userID . "'"; |
|
109
|
|
|
$result = $xoopsDB->query($sql); |
|
110
|
|
|
$i = $xoopsDB->getRowsNum($result); |
|
111
|
|
|
} |
|
112
|
|
View Code Duplication |
while ($row = $xoopsDB->fetchArray($result)) { |
|
|
|
|
|
|
113
|
|
|
if (0 == $i && '' == $i) { |
|
114
|
|
|
$respons[0] = 0; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
if (1 == $i && 1 == $row['status']) { |
|
118
|
|
|
$respons[0] = 1; |
|
119
|
|
|
} |
|
120
|
|
|
if (1 == $i && 2 == $row['status']) { |
|
121
|
|
|
$respons[0] = 2; |
|
122
|
|
|
} |
|
123
|
|
|
return $respons; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @Get name from userid |
|
129
|
|
|
* @param int $userID |
|
130
|
|
|
* @return string |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getName($userID) |
|
133
|
|
|
{ |
|
134
|
|
|
global $xoopsUser, $xoopsDB; |
|
135
|
|
|
$name = ''; |
|
136
|
|
|
$sql = 'SELECT username FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . (int)$userID . "'"; |
|
137
|
|
|
$result = $xoopsDB->queryF($sql); |
|
138
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
|
139
|
|
|
$name = $row['username']; |
|
140
|
|
|
} |
|
141
|
|
|
return $name; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @Check if user is follower |
|
146
|
|
|
* @param int $userid |
|
147
|
|
|
* @param int $friendid |
|
148
|
|
|
* @return int |
|
|
|
|
|
|
149
|
|
|
*/ |
|
150
|
|
|
public function following_or($userid, $friendid) |
|
151
|
|
|
{ |
|
152
|
|
|
global $xoopsDB, $xoopsUser; |
|
153
|
|
|
$respons[0] = 0; |
|
|
|
|
|
|
154
|
|
|
if ($userid != $friendid) { |
|
155
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_followers') . " WHERE me = '" . (int)$userid . "' AND you = '" . (int)$friendid . "'"; |
|
156
|
|
|
$result = $xoopsDB->query($sql); |
|
157
|
|
|
$i = $xoopsDB->getRowsNum($result); |
|
158
|
|
View Code Duplication |
while ($row = $xoopsDB->fetchArray($result)) { |
|
|
|
|
|
|
159
|
|
|
if (0 == $i) { |
|
160
|
|
|
$respons[0] = 0; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
if (1 == $i && 1 == $row['status']) { |
|
164
|
|
|
$respons[0] = 1; |
|
165
|
|
|
} |
|
166
|
|
|
if (1 == $i && 2 == $row['status']) { |
|
167
|
|
|
$respons[0] = 2; |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
} else { |
|
171
|
|
|
} |
|
172
|
|
|
return $respons; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* @Get requests |
|
177
|
|
|
* @param int $userid |
|
178
|
|
|
* @return array |
|
179
|
|
|
*/ |
|
180
|
|
|
public function getRequests($userid) |
|
181
|
|
|
{ |
|
182
|
|
|
global $xoopsDB, $xoopsUser; |
|
183
|
|
|
$msg = []; |
|
184
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE you = '" . (int)$userid . "' AND status = '1'"; |
|
185
|
|
|
$result = $xoopsDB->queryF($sql); |
|
186
|
|
|
$i = $xoopsDB->getRowsNum($result); |
|
|
|
|
|
|
187
|
|
|
$db = new \XoopsModules\Smallworld\SwDatabase(); |
|
|
|
|
|
|
188
|
|
|
$Wall = new \XoopsModules\Smallworld\WallUpdates(); |
|
189
|
|
|
$myavatar = $Wall->Gravatar($userid); |
|
|
|
|
|
|
190
|
|
|
$start = 0; |
|
191
|
|
|
while ($row = $xoopsDB->fetchArray($result) && $start <= count($row)) { |
|
|
|
|
|
|
192
|
|
|
$msg[$start]['friendname'] = $this->getName($row['me']); |
|
193
|
|
|
$msg[$start]['img'] = $Wall->Gravatar($row['me']); |
|
194
|
|
|
$msg[$start]['friendimage'] = "<img src='" . XOOPS_UPLOAD_URL . '/' . $msg[$start]['img'] . "' height='40px'>"; |
|
195
|
|
|
$msg[$start]['frienddate'] = date('d-m-Y', $row['date']); |
|
196
|
|
|
$msg[$start]['accept'] = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(1,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_ACCEPT . '</a>'; |
|
197
|
|
|
$msg[$start]['deny'] = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(-1,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_DENY . '</a>'; |
|
198
|
|
|
$msg[$start]['later'] = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(0,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_LATER . '</a>'; |
|
199
|
|
|
$msg[$start]['cnt'] = $start; |
|
200
|
|
|
++$start; |
|
201
|
|
|
} |
|
202
|
|
|
return $msg; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @Get partner |
|
207
|
|
|
* @param string $name |
|
208
|
|
|
* @return int |
|
209
|
|
|
*/ |
|
210
|
|
|
public function spousexist($name) |
|
211
|
|
|
{ |
|
212
|
|
|
global $xoopsUser, $xoopsDB; |
|
213
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE username = '" . $name . "'"; |
|
214
|
|
|
$result = $xoopsDB->queryF($sql); |
|
215
|
|
|
$i = $xoopsDB->getRowsNum($result); |
|
216
|
|
|
return $i; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Get all users |
|
221
|
|
|
* @return array |
|
222
|
|
|
*/ |
|
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
public function allUsers() |
|
225
|
|
|
{ |
|
226
|
|
|
global $xoopsDB; |
|
227
|
|
|
$sql = 'SELECT userid FROM ' . $xoopsDB->prefix('smallworld_user') . ' ORDER BY userid'; |
|
228
|
|
|
$result = $xoopsDB->queryF($sql); |
|
229
|
|
|
$i = $xoopsDB->getRowsNum($result); |
|
230
|
|
|
if (0 != $i) { |
|
231
|
|
|
while ($r = $xoopsDB->fetchArray($result)) { |
|
232
|
|
|
$data[] = $r; |
|
|
|
|
|
|
233
|
|
|
} |
|
234
|
|
|
if (!empty($data)) { |
|
235
|
|
|
return Smallworld_array_flatten($data, 0); |
|
236
|
|
|
} |
|
237
|
|
|
} else { |
|
238
|
|
|
//redirect_header(XOOPS_URL . "/modules/smallworld/register.php"); |
|
239
|
|
|
} |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.