1
|
|
|
<?php |
2
|
|
|
namespace XoopsModules\Smallworld; |
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
|
|
|
|
24
|
|
|
//include_once $GLOBALS['xoops']->path('include/common.php'); |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class SmallWorldUser |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @Check if user has profile |
32
|
|
|
* @param int $userID |
33
|
|
|
* @return int |
34
|
|
|
*/ |
35
|
|
|
public function checkIfProfile($userID) |
36
|
|
|
{ |
37
|
|
|
global $xoopsUser, $xoopsDB; |
38
|
|
|
$i = 0; |
|
|
|
|
39
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . $userID . "'"; |
40
|
|
|
$result = $xoopsDB->queryF($sql); |
41
|
|
|
$i = $xoopsDB->getRowsNum($result); |
42
|
|
|
if ($xoopsUser) { |
43
|
|
|
// If xoopsuser but no smallworld profile |
44
|
|
|
if (0 == $i) { |
45
|
|
|
$i = 1; |
46
|
|
|
} else { |
47
|
|
|
// if xoopsuser and has profile |
48
|
|
|
$i = 2; |
49
|
|
|
} |
50
|
|
|
} else { |
51
|
|
|
// if not xoopsUser ie anonymous user |
52
|
|
|
$i = 0; |
53
|
|
|
} |
54
|
|
|
return $i; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @Create user |
59
|
|
|
* @param int $userid |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
View Code Duplication |
public function createUser($userid) |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
global $xoopsUser, $xoopsDB; |
65
|
|
|
$a = new $xoopsUser($userid); |
66
|
|
|
$b = $a->uname(); |
|
|
|
|
67
|
|
|
$sql = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_user') . ' (userid) VALUES (' . (int)$userid . ')'; |
68
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @Check is user is smallworld user |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
|
|
public function chkUser() |
76
|
|
|
{ |
77
|
|
|
global $xoopsUser, $xoopsTpl; |
78
|
|
|
$greeting = '<br>'; |
79
|
|
|
$greeting .= _SMALLWORLD_NOTYETUSER_GREETING . ' ' . $xoopsUser->uname() . '.<br><br>'; |
80
|
|
|
$greeting .= _SMALLWORLD_NOTYETUSER_BOXTEXT; |
81
|
|
|
|
82
|
|
|
$xoopsTpl->assign('notyetusercontent', $greeting); |
83
|
|
|
$xoopsTpl->assign('check', 0); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @Check is user is friend |
88
|
|
|
* @param int $user |
89
|
|
|
* @param int $userID |
90
|
|
|
* @return array|int |
|
|
|
|
91
|
|
|
*/ |
92
|
|
|
public function friendcheck($user, $userID) |
93
|
|
|
{ |
94
|
|
|
global $xoopsUser, $xoopsDB; |
95
|
|
|
$respons = []; |
96
|
|
|
if ($user == $userID) { |
97
|
|
|
$respons[0] = 2; |
98
|
|
|
return $respons; |
99
|
|
|
} |
100
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . (int)$user . "' AND you = '" . (int)$userID . "'"; |
101
|
|
|
$result = $xoopsDB->query($sql); |
102
|
|
|
$i = $xoopsDB->getRowsNum($result); |
103
|
|
|
if (0 == $i) { |
104
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE you = '" . (int)$user . "' AND me = '" . (int)$userID . "'"; |
105
|
|
|
$result = $xoopsDB->query($sql); |
106
|
|
|
$i = $xoopsDB->getRowsNum($result); |
107
|
|
|
} |
108
|
|
View Code Duplication |
while ($row = $xoopsDB->fetchArray($result)) { |
|
|
|
|
109
|
|
|
if (0 == $i and '' == $i) { |
110
|
|
|
$respons[0] = 0; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if (1 == $i and 1 == $row['status']) { |
114
|
|
|
$respons[0] = 1; |
115
|
|
|
} |
116
|
|
|
if (1 == $i and 2 == $row['status']) { |
117
|
|
|
$respons[0] = 2; |
118
|
|
|
} |
119
|
|
|
return $respons; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @Get name from userid |
125
|
|
|
* @param int $userID |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
public function getName($userID) |
129
|
|
|
{ |
130
|
|
|
global $xoopsUser, $xoopsDB; |
131
|
|
|
$name = ''; |
132
|
|
|
$sql = 'SELECT username FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . (int)$userID . "'"; |
133
|
|
|
$result = $xoopsDB->queryF($sql); |
134
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
135
|
|
|
$name = $row['username']; |
136
|
|
|
} |
137
|
|
|
return $name; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @Check if user is follower |
142
|
|
|
* @param int $userid |
143
|
|
|
* @param int $friendid |
144
|
|
|
* @return int |
|
|
|
|
145
|
|
|
*/ |
146
|
|
|
public function following_or($userid, $friendid) |
147
|
|
|
{ |
148
|
|
|
global $xoopsDB, $xoopsUser; |
149
|
|
|
$respons[0] = 0; |
|
|
|
|
150
|
|
|
if ($userid != $friendid) { |
151
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_followers') . " WHERE me = '" . (int)$userid . "' AND you = '" . (int)$friendid . "'"; |
152
|
|
|
$result = $xoopsDB->query($sql); |
153
|
|
|
$i = $xoopsDB->getRowsNum($result); |
154
|
|
View Code Duplication |
while ($row = $xoopsDB->fetchArray($result)) { |
|
|
|
|
155
|
|
|
if (0 == $i) { |
156
|
|
|
$respons[0] = 0; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
if (1 == $i and 1 == $row['status']) { |
160
|
|
|
$respons[0] = 1; |
161
|
|
|
} |
162
|
|
|
if (1 == $i and 2 == $row['status']) { |
163
|
|
|
$respons[0] = 2; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
} else { |
167
|
|
|
} |
168
|
|
|
return $respons; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @Get requests |
173
|
|
|
* @param int $userid |
174
|
|
|
* @return array |
175
|
|
|
*/ |
176
|
|
|
public function getRequests($userid) |
177
|
|
|
{ |
178
|
|
|
global $xoopsDB, $xoopsUser; |
179
|
|
|
$msg = []; |
180
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE you = '" . (int)$userid . "' AND status = '1'"; |
181
|
|
|
$result = $xoopsDB->queryF($sql); |
182
|
|
|
$i = $xoopsDB->getRowsNum($result); |
|
|
|
|
183
|
|
|
$db = new SmallWorldDB; |
|
|
|
|
184
|
|
|
$Wall = new WallUpdates(); |
185
|
|
|
$myavatar = $Wall->Gravatar($userid); |
|
|
|
|
186
|
|
|
$start = 0; |
187
|
|
View Code Duplication |
while ($row = $xoopsDB->fetchArray($result) and $start <= count($row)) { |
|
|
|
|
188
|
|
|
$msg[$start]['friendname'] = $this->getName($row['me']); |
189
|
|
|
$msg[$start]['img'] = $Wall->Gravatar($row['me']); |
|
|
|
|
190
|
|
|
$msg[$start]['friendimage'] = "<img src='" . XOOPS_UPLOAD_URL . '/' . $msg[$start]['img'] . "' height='40px'>"; |
191
|
|
|
$msg[$start]['frienddate'] = date('d-m-Y', $row['date']); |
192
|
|
|
$msg[$start]['accept'] = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(1,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_ACCEPT . '</a>'; |
193
|
|
|
$msg[$start]['deny'] = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(-1,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_DENY . '</a>'; |
194
|
|
|
$msg[$start]['later'] = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(0,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_LATER . '</a>'; |
195
|
|
|
$msg[$start]['cnt'] = $start; |
196
|
|
|
++$start; |
197
|
|
|
} |
198
|
|
|
return $msg; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @Get partner |
203
|
|
|
* @param string $name |
204
|
|
|
* @return int |
205
|
|
|
*/ |
206
|
|
|
public function spousexist($name) |
207
|
|
|
{ |
208
|
|
|
global $xoopsUser, $xoopsDB; |
209
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE username = '" . $name . "'"; |
210
|
|
|
$result = $xoopsDB->queryF($sql); |
211
|
|
|
$i = $xoopsDB->getRowsNum($result); |
212
|
|
|
return $i; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Get all users |
217
|
|
|
* @return array |
218
|
|
|
*/ |
|
|
|
|
219
|
|
|
|
220
|
|
|
public function allUsers() |
221
|
|
|
{ |
222
|
|
|
global $xoopsDB; |
223
|
|
|
$sql = 'SELECT userid FROM ' . $xoopsDB->prefix('smallworld_user') . ' ORDER BY userid'; |
224
|
|
|
$result = $xoopsDB->queryF($sql); |
225
|
|
|
$i = $xoopsDB->getRowsNum($result); |
226
|
|
|
if (0 != $i) { |
227
|
|
|
while ($r = $xoopsDB->fetchArray($result)) { |
228
|
|
|
$data[] = $r; |
|
|
|
|
229
|
|
|
} |
230
|
|
|
if (!empty($data)) { |
231
|
|
|
return Smallworld_array_flatten($data, 0); |
232
|
|
|
} |
233
|
|
|
} else { |
234
|
|
|
//redirect_header(XOOPS_URL . "/modules/smallworld/register.php"); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.