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
|
|
|
* @copyright The XOOPS Project (https://xoops.org) |
16
|
|
|
* @copyright 2011 Culex |
17
|
|
|
* @license GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/) |
18
|
|
|
* @package SmallWorld |
19
|
|
|
* @since 1.0 |
20
|
|
|
* @author Michael Albertsen (http://culex.dk) <[email protected]> |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
class SmallWorldUser |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @Check if user has profile |
27
|
|
|
* @param int $userID |
28
|
|
|
* @return int |
29
|
|
|
*/ |
30
|
|
|
public function CheckIfProfile($userID) |
31
|
|
|
{ |
32
|
|
|
global $xoopsUser, $xoopsDB; |
33
|
|
|
$i = 0; |
|
|
|
|
34
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . $userID . "'"; |
35
|
|
|
$result = $xoopsDB->queryF($sql); |
36
|
|
|
$i = $xoopsDB->getRowsNum($result); |
37
|
|
|
if ($xoopsUser) { |
38
|
|
|
// If xoopsuser but no smallworld profile |
39
|
|
|
if (0 == $i) { |
40
|
|
|
$i = 1; |
41
|
|
|
} else { |
42
|
|
|
// if xoopsuser and has profile |
43
|
|
|
$i = 2; |
44
|
|
|
} |
45
|
|
|
} else { |
46
|
|
|
// if not xoopsUser ie anonymous user |
47
|
|
|
$i = 0; |
48
|
|
|
} |
49
|
|
|
return $i; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @Create user |
54
|
|
|
* @param int $userid |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
public function createUser($userid) |
58
|
|
|
{ |
59
|
|
|
global $xoopsUser, $xoopsDB; |
60
|
|
|
$a = new $xoopsUser($userid); |
61
|
|
|
$b = $a->uname(); |
|
|
|
|
62
|
|
|
$sql = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_user') . ' (userid) VALUES (' . (int)$userid . ')'; |
63
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Check is user is smallworld user |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
public function chkUser() |
71
|
|
|
{ |
72
|
|
|
global $xoopsUser, $xoopsTpl; |
73
|
|
|
$greeting = '<br>'; |
74
|
|
|
$greeting .= _SMALLWORLD_NOTYETUSER_GREETING . ' ' . $xoopsUser->uname() . '.<br><br>'; |
75
|
|
|
$greeting .= _SMALLWORLD_NOTYETUSER_BOXTEXT; |
76
|
|
|
|
77
|
|
|
$xoopsTpl->assign('notyetusercontent', $greeting); |
78
|
|
|
$xoopsTpl->assign('check', 0); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @Check is user is friend |
83
|
|
|
* @param int $user |
84
|
|
|
* @param int $userID |
85
|
|
|
* @return array|int |
|
|
|
|
86
|
|
|
*/ |
87
|
|
|
public function friendcheck($user, $userID) |
88
|
|
|
{ |
89
|
|
|
global $xoopsUser, $xoopsDB; |
90
|
|
|
$respons = []; |
91
|
|
|
if ($user == $userID) { |
92
|
|
|
$respons[0] = 2; |
93
|
|
|
return $respons; |
94
|
|
|
} |
95
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . (int)$user . "' AND you = '" . (int)$userID . "'"; |
96
|
|
|
$result = $xoopsDB->query($sql); |
97
|
|
|
$i = $xoopsDB->getRowsNum($result); |
98
|
|
|
if (0 == $i) { |
99
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE you = '" . (int)$user . "' AND me = '" . (int)$userID . "'"; |
100
|
|
|
$result = $xoopsDB->query($sql); |
101
|
|
|
$i = $xoopsDB->getRowsNum($result); |
102
|
|
|
} |
103
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
104
|
|
|
if (0 == $i and '' == $i) { |
105
|
|
|
$respons[0] = 0; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if (1 == $i and 1 == $row['status']) { |
109
|
|
|
$respons[0] = 1; |
110
|
|
|
} |
111
|
|
|
if (1 == $i and 2 == $row['status']) { |
112
|
|
|
$respons[0] = 2; |
113
|
|
|
} |
114
|
|
|
return $respons; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @Get name from userid |
120
|
|
|
* @param int $userID |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
public function getName($userID) |
124
|
|
|
{ |
125
|
|
|
global $xoopsUser, $xoopsDB; |
126
|
|
|
$sql = 'SELECT username FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . (int)$userID . "'"; |
127
|
|
|
$result = $xoopsDB->queryF($sql); |
128
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
129
|
|
|
$name = $row['username']; |
130
|
|
|
} |
131
|
|
|
return $name; |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @Check if user is follower |
136
|
|
|
* @param int $userid |
137
|
|
|
* @param int $friendid |
138
|
|
|
* @return int |
|
|
|
|
139
|
|
|
*/ |
140
|
|
|
public function following_or($userid, $friendid) |
141
|
|
|
{ |
142
|
|
|
global $xoopsDB, $xoopsUser; |
143
|
|
|
$respons[0] = 0; |
|
|
|
|
144
|
|
|
if ($userid != $friendid) { |
145
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_followers') . " WHERE me = '" . (int)$userid . "' AND you = '" . (int)$friendid . "'"; |
146
|
|
|
$result = $xoopsDB->query($sql); |
147
|
|
|
$i = $xoopsDB->getRowsNum($result); |
148
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
149
|
|
|
if (0 == $i) { |
150
|
|
|
$respons[0] = 0; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
if (1 == $i and 1 == $row['status']) { |
154
|
|
|
$respons[0] = 1; |
155
|
|
|
} |
156
|
|
|
if (1 == $i and 2 == $row['status']) { |
157
|
|
|
$respons[0] = 2; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
} else { |
161
|
|
|
} |
162
|
|
|
return $respons; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @Get requests |
167
|
|
|
* @param int $userid |
168
|
|
|
* @return array |
169
|
|
|
*/ |
170
|
|
|
public function getRequests($userid) |
171
|
|
|
{ |
172
|
|
|
global $xoopsDB, $xoopsUser; |
173
|
|
|
$msg = []; |
174
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE you = '" . (int)$userid . "' AND status = '1'"; |
175
|
|
|
$result = $xoopsDB->queryF($sql); |
176
|
|
|
$i = $xoopsDB->getRowsNum($result); |
|
|
|
|
177
|
|
|
$db = new SmallWorldDB; |
|
|
|
|
178
|
|
|
$Wall = new Wall_Updates(); |
179
|
|
|
$myavatar = $Wall->Gravatar($userid); |
|
|
|
|
180
|
|
|
$start = 0; |
181
|
|
|
while ($row = $xoopsDB->fetchArray($result) and $start <= count($row)) { |
182
|
|
|
$msg[$start]['friendname'] = $this->getName($row['me']); |
183
|
|
|
$msg[$start]['img'] = $Wall->Gravatar($row['me']); |
184
|
|
|
$msg[$start]['friendimage'] = "<img src='" . XOOPS_UPLOAD_URL . '/' . $msg[$start]['img'] . "' height='40px'>"; |
185
|
|
|
$msg[$start]['frienddate'] = date('d-m-Y', $row['date']); |
186
|
|
|
$msg[$start]['accept'] = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(1,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_ACCEPT . '</a>'; |
187
|
|
|
$msg[$start]['deny'] = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(-1,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_DENY . '</a>'; |
188
|
|
|
$msg[$start]['later'] = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(0,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_LATER . '</a>'; |
189
|
|
|
$msg[$start]['cnt'] = $start; |
190
|
|
|
++$start; |
191
|
|
|
} |
192
|
|
|
return $msg; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @Get partner |
197
|
|
|
* @param string $name |
198
|
|
|
* @return int |
199
|
|
|
*/ |
200
|
|
|
public function spousexist($name) |
201
|
|
|
{ |
202
|
|
|
global $xoopsUser, $xoopsDB; |
203
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE username = '" . $name . "'"; |
204
|
|
|
$result = $xoopsDB->queryF($sql); |
205
|
|
|
$i = $xoopsDB->getRowsNum($result); |
206
|
|
|
return $i; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Get all users |
211
|
|
|
* @return array |
212
|
|
|
*/ |
|
|
|
|
213
|
|
|
|
214
|
|
|
public function allUsers() |
215
|
|
|
{ |
216
|
|
|
global $xoopsDB; |
217
|
|
|
$sql = 'SELECT userid FROM ' . $xoopsDB->prefix('smallworld_user') . ' ORDER BY userid'; |
218
|
|
|
$result = $xoopsDB->queryF($sql); |
219
|
|
|
$i = $xoopsDB->getRowsNum($result); |
220
|
|
|
if (0 != $i) { |
221
|
|
|
while ($r = $xoopsDB->fetchArray($result)) { |
222
|
|
|
$data[] = $r; |
|
|
|
|
223
|
|
|
} |
224
|
|
|
if (!empty($data)) { |
225
|
|
|
return Smallworld_array_flatten($data, 0); |
226
|
|
|
} |
227
|
|
|
} else { |
228
|
|
|
//redirect_header(XOOPS_URL . "/modules/smallworld/register.php"); |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.