This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace XoopsModules\Smallworld; |
||
4 | |||
5 | /* |
||
6 | * You may not change or alter any portion of this comment or credits |
||
7 | * of supporting developers from this source code or any supporting source code |
||
8 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
9 | * |
||
10 | * This program is distributed in the hope that it will be useful, |
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
13 | */ |
||
14 | /** |
||
15 | * SmallWorld |
||
16 | * |
||
17 | * @package \XoopsModules\SmallWorld |
||
18 | * @license GNU GPL (https://www.gnu.org/licenses/gpl-2.0.html/) |
||
19 | * @copyright The XOOPS Project (https://xoops.org) |
||
20 | * @copyright 2011 Culex |
||
21 | * @author Michael Albertsen (http://culex.dk) <[email protected]> |
||
22 | * @link https://github.com/XoopsModules25x/smallworld |
||
23 | */ |
||
24 | |||
25 | use XoopsModules\Smallworld\Constants; |
||
26 | |||
27 | /** |
||
28 | * Public Wall Updates Class |
||
29 | * |
||
30 | * SmallWorld - Moderated and fitted from the tutorial by Srinivas Tamada http://9lessons.info |
||
31 | * Provides wall update methods |
||
32 | */ |
||
33 | class PublicWallUpdates |
||
34 | { |
||
35 | /** |
||
36 | * Get an array of Admin Moderators |
||
37 | * |
||
38 | * @deprecated - not used |
||
39 | * @return array |
||
40 | */ |
||
41 | private function getAdminModerators() |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
42 | { |
||
43 | $sql = 'SELECT userid |
||
44 | FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . ' su |
||
45 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('groups_users_link') . ' xu ON su.userid = xu.uid |
||
46 | WHERE xu.uid IN (1)'; |
||
47 | $result = $GLOBALS['xoopsDB']->queryF($sql); |
||
48 | $data = []; |
||
49 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
50 | $data[] = $row; |
||
51 | } |
||
52 | |||
53 | return $data; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Get array of users being inspected |
||
58 | * |
||
59 | * @return int|string |
||
60 | */ |
||
61 | public function inspected() |
||
62 | { |
||
63 | $sql = 'SELECT userid FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_admin') . ' WHERE (inspect_start+inspect_stop) > ' . time() . ''; |
||
64 | $result = $GLOBALS['xoopsDB']->queryF($sql); |
||
65 | $data = []; |
||
66 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
67 | $data[] = $row; |
||
68 | } |
||
69 | $sub = !empty($data) ? implode(',', smallworld_array_flatten(array_unique($data), 0)) : 0; |
||
70 | |||
71 | return $sub; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Get array of updates |
||
76 | * |
||
77 | * @param string|int $last |
||
78 | * @param array $moderators |
||
79 | * @return array|bool |
||
80 | */ |
||
81 | public function Updates($last, $moderators) |
||
82 | { |
||
83 | /** @var \XoopsModules\Smallworld\Helper $helper */ |
||
84 | $helper = Helper::getInstance(); |
||
85 | $moderators = is_array($moderators) ? $moderators : [$moderators]; |
||
86 | $hm = $helper->getConfig('msgtoshow'); |
||
87 | //$set = smallworld_checkPrivateOrPublic(); |
||
88 | $mods = implode(',', smallworld_array_flatten(array_unique($moderators), 0)); |
||
89 | $inspected = $this->inspected(); |
||
90 | $perm = $helper->getConfig('smallworldshowPoPubPage'); |
||
0 ignored issues
–
show
$perm is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
91 | $data = []; // init data array |
||
92 | if ('' == $mods && 0 == $inspected) { // nothing here |
||
93 | return $data; |
||
94 | } |
||
95 | if (0 == $last) { |
||
96 | $query = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' |
||
97 | . $GLOBALS['xoopsDB']->prefix('smallworld_messages') |
||
98 | . ' M, ' |
||
99 | . $GLOBALS['xoopsDB']->prefix('smallworld_user') |
||
100 | . ' U WHERE M.uid_fk=U.userid AND M.uid_fk IN (' |
||
101 | . $mods |
||
102 | . ') AND M.uid_fk NOT IN (' |
||
103 | . $inspected |
||
104 | . ") AND M.priv = '0'"; |
||
105 | View Code Duplication | } elseif ($last > 0) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
106 | $query = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' |
||
107 | . $GLOBALS['xoopsDB']->prefix('smallworld_messages') |
||
108 | . ' M, ' |
||
109 | . $GLOBALS['xoopsDB']->prefix('smallworld_user') |
||
110 | . ' U WHERE M.uid_fk=U.userid AND M.uid_fk IN (' |
||
111 | . $mods |
||
112 | . ') AND M.uid_fk NOT IN (' |
||
113 | . $inspected |
||
114 | . ") AND M.priv = '0' AND M.msg_id < '" |
||
115 | . $last |
||
116 | . "' ORDER BY created DESC LIMIT {$hm}"; |
||
117 | } elseif ('a' == $last) { |
||
118 | $query = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' |
||
119 | . $GLOBALS['xoopsDB']->prefix('smallworld_messages') |
||
120 | . ' M, ' |
||
121 | . $GLOBALS['xoopsDB']->prefix('smallworld_user') |
||
122 | . ' U WHERE M.uid_fk=U.userid AND M.uid_fk IN (' |
||
123 | . $mods |
||
124 | . ') AND M.uid_fk NOT IN (' |
||
125 | . $inspected |
||
126 | . ") AND M.priv = '0'" |
||
127 | . " ORDER BY by M.msg_id DESC LIMIT {$hm}"; |
||
128 | } |
||
129 | |||
130 | if ($last <= 0 || ('a' == $last)) { |
||
131 | $query .= " ORDER BY created DESC LIMIT {$hm}"; |
||
0 ignored issues
–
show
The variable
$query does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
132 | } |
||
133 | |||
134 | $result = $GLOBALS['xoopsDB']->queryF($query); |
||
135 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
136 | $data[] = $row; |
||
137 | } |
||
138 | |||
139 | return $data; |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Get comments based on msg id |
||
144 | * |
||
145 | * @param int $msg_id |
||
146 | * @return array |
||
147 | */ |
||
148 | public function Comments($msg_id) |
||
149 | { |
||
150 | $data = []; // initialize return array |
||
151 | $inspected = $this->inspected(); |
||
152 | $query = 'SELECT C.msg_id_fk, C.com_id, C.uid_fk, C.comment, C.created, U.username FROM ' |
||
153 | . $GLOBALS['xoopsDB']->prefix('smallworld_comments') |
||
154 | . ' C, ' |
||
155 | . $GLOBALS['xoopsDB']->prefix('smallworld_user') |
||
156 | . " U WHERE C.uid_fk=U.userid AND C.msg_id_fk='" |
||
157 | . (int)$msg_id |
||
158 | . "' AND C.uid_fk NOT IN (" |
||
159 | . $inspected |
||
160 | . ') ORDER BY C.com_id ASC '; |
||
161 | $result = $GLOBALS['xoopsDB']->queryF($query); |
||
162 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
163 | $data[] = $row; |
||
164 | } |
||
165 | |||
166 | return $data; |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * Get user image based on uid |
||
171 | * |
||
172 | * @param int $uid |
||
173 | * @return string |
||
174 | */ |
||
175 | public function Gravatar($uid) |
||
176 | { |
||
177 | $depMsg = get_class() . __FUNCTION__ . " is deprecated use SwUserHandler::gravatar() instead."; |
||
178 | View Code Duplication | if (isset($GLOBALS['xoopsLogger'])) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
179 | $GLOBALS['xoopsLogger']->addDeprecated($depMsg); |
||
180 | } else { |
||
181 | trigger_error($depMsg, E_USER_WARNING); |
||
182 | } |
||
183 | |||
184 | $image = $avatar = ''; |
||
185 | $swUserHandler = \XoopsModules\Smallworld\Helper::getInstance()->getHandler('SwUser'); |
||
186 | $criteria = new \Criteria('userid', (int)$uid); |
||
187 | $criteria->setLimit(1); |
||
188 | $swUser = $swUserHandler->getAll($criteria, ['userimage'], false); |
||
189 | if (0 < count($swUser)) { |
||
190 | $image = $swUser['userimage']; |
||
191 | } |
||
192 | /* |
||
193 | $sql = 'SELECT userimage FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . " WHERE userid = '" . (int)$uid . "'"; |
||
194 | $result = $GLOBALS['xoopsDB']->queryF($sql); |
||
195 | while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
196 | $image = $r['userimage']; |
||
197 | } |
||
198 | */ |
||
199 | if ('blank.gif' === $image) { |
||
200 | $image = $swUserHandler->getAvatarLink($uid, $image); |
||
201 | } |
||
202 | |||
203 | //$image = ($image == '' || $image == 'blank.gif') ? $swUserHandler->getAvatarLink($uid, $image) : $image; |
||
204 | |||
205 | $type = [ |
||
206 | 1 => 'jpg', |
||
207 | 2 => 'jpeg', |
||
208 | 3 => 'png', |
||
209 | 4 => 'gif', |
||
210 | ]; |
||
211 | |||
212 | $ext = explode('.', $image); |
||
213 | View Code Duplication | if (array_key_exists(1, $ext) && in_array(mb_strtolower($ext[1]), $type)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
214 | $avatar = $image; |
||
215 | } |
||
216 | |||
217 | return $avatar; |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * Count all votes |
||
222 | * |
||
223 | * @param int $type - not used |
||
224 | * @param int $val - not used |
||
225 | * @param int $msgid |
||
226 | * @return int |
||
227 | */ |
||
228 | View Code Duplication | public function countVotes($type, $val, $msgid) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
229 | { |
||
230 | $sum = 0; |
||
231 | $query = 'SELECT SUM(' . $val . ') AS sum FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_vote') . " WHERE msg_id = '" . (int)$msgid . "' AND com_id = '0'"; |
||
232 | $result = $GLOBALS['xoopsDB']->queryF($query); |
||
233 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
234 | $sum = $row['sum']; |
||
235 | } |
||
236 | |||
237 | return (int)$sum; // make sure it's an integer - not sure this is really necessary |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * Count comments votes |
||
242 | * |
||
243 | * @param int $type - not used |
||
244 | * @param int $val - not used |
||
245 | * @param int $comid |
||
246 | * @param int $msgid |
||
247 | * @returns int |
||
248 | */ |
||
249 | View Code Duplication | public function countVotesCom($type, $val, $comid, $msgid) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
250 | { |
||
251 | $sum = 0; |
||
252 | $query = 'SELECT SUM(' . $val . ') AS sum FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_vote') . " WHERE com_id = '" . (int)$comid . "' AND msg_id = '" . (int)$msgid . "'"; |
||
253 | $result = $GLOBALS['xoopsDB']->queryF($query); |
||
254 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
255 | $sum = $row['sum']; |
||
256 | } |
||
257 | |||
258 | return (int)$sum; |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * @Check is user is friend |
||
263 | * @param int $userid |
||
264 | * @param string $type |
||
265 | * @param int $comid |
||
266 | * @param int $msgid |
||
267 | * @return int |
||
268 | */ |
||
269 | public function hasVoted($userid, $type, $comid, $msgid) |
||
270 | { |
||
271 | if ('msg' === $type) { |
||
272 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_vote') . " WHERE com_id = '0' AND msg_id = '" . (int)$msgid . "' AND user_id = '" . (int)$userid . "'"; |
||
273 | } else { |
||
274 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_vote') . " WHERE com_id = '" . (int)$comid . "' AND msg_id = '" . (int)$msgid . "' AND user_id = '" . (int)$userid . "'"; |
||
275 | } |
||
276 | $result = $GLOBALS['xoopsDB']->queryF($sql); |
||
277 | $i = $GLOBALS['xoopsDB']->getRowsNum($result); |
||
278 | |||
279 | return $i; |
||
280 | } |
||
281 | |||
282 | /** |
||
283 | * @count messages per user |
||
284 | * @param int $userid |
||
285 | * @return int |
||
286 | */ |
||
287 | View Code Duplication | public function countMsges($userid) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
288 | { |
||
289 | $sql = 'SELECT (SELECT COUNT(*) FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_comments') . " WHERE uid_fk = '" . $userid . "') + (SELECT COUNT(*) FROM " . $GLOBALS['xoopsDB']->prefix('smallworld_messages') . " WHERE uid_fk = '" . $userid . "')"; |
||
290 | $result = $GLOBALS['xoopsDB']->queryF($sql); |
||
291 | $sum = $GLOBALS['xoopsDB']->fetchRow($result); |
||
292 | |||
293 | return $sum[0]; |
||
294 | } |
||
295 | |||
296 | /** |
||
297 | * Show permaling updates |
||
298 | * |
||
299 | * @todo ensure "something" is always returned |
||
300 | * @param int $updid |
||
301 | * @param int $uid |
||
302 | * @param int $ownerID |
||
303 | * @return array|bool |
||
0 ignored issues
–
show
|
|||
304 | */ |
||
305 | View Code Duplication | public function updatesPermalink($updid, $uid, $ownerID) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
306 | { |
||
307 | $query = 'SELECT M.msg_id, M.uid_fk, M.message, M.created, M.priv, U.username FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_messages') . ' M, ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . " U WHERE M.uid_fk=U.userid AND M.uid_fk='" . $ownerID . "'"; |
||
308 | $query .= " AND M.msg_id = '" . $updid . "'"; |
||
309 | $query .= ' order by M.created DESC LIMIT 1'; |
||
310 | $result = $GLOBALS['xoopsDB']->queryF($query); |
||
311 | $count = $GLOBALS['xoopsDB']->getRowsNum($result); |
||
312 | if ($count < 1) { |
||
313 | return false; |
||
314 | } |
||
315 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
316 | $data[] = $row; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
317 | } |
||
318 | if (!empty($data)) { |
||
319 | return $data; |
||
320 | } |
||
321 | } |
||
322 | |||
323 | /** |
||
324 | * Get share link |
||
325 | * |
||
326 | * @todo ensure "something" is always returned |
||
327 | * @param int $updid |
||
328 | * @param int $ownerID |
||
329 | * @return array|bool |
||
0 ignored issues
–
show
|
|||
330 | */ |
||
331 | View Code Duplication | public function updatesSharelink($updid, $ownerID) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
332 | { |
||
333 | $query = 'SELECT M.msg_id, M.uid_fk, M.message, M.created, M.priv, U.username FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_messages') . ' M, ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . " U WHERE M.uid_fk=U.userid AND M.uid_fk='" . $ownerID . "' AND M.priv = 0"; |
||
334 | $query .= " AND M.msg_id = '" . $updid . "'"; |
||
335 | $query .= ' order by created DESC LIMIT 1'; |
||
336 | $result = $GLOBALS['xoopsDB']->queryF($query); |
||
337 | $count = $GLOBALS['xoopsDB']->getRowsNum($result); |
||
338 | if ($count < 1) { |
||
339 | return false; |
||
340 | } |
||
341 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
342 | $data[] = $row; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
343 | } |
||
344 | if (!empty($data)) { |
||
345 | return $data; |
||
346 | } |
||
347 | } |
||
348 | |||
349 | /** |
||
350 | * @Get sharing link |
||
351 | * @param int $id |
||
352 | * @param int $priv |
||
353 | * @return string |
||
354 | */ |
||
355 | View Code Duplication | public function getSharing($id, $priv) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
356 | { |
||
357 | $text = ''; |
||
358 | if (1 !== $priv) { |
||
359 | $text = " | <span class='smallworld_share' id='smallworld_share'>"; |
||
360 | $text .= "<a class='share' id='share-page" . $id . "' href='javascript:void(0);'>" . _SMALLWORLD_SHARELINK . '</a></span>'; |
||
361 | } |
||
362 | |||
363 | return $text; |
||
364 | } |
||
365 | |||
366 | /** |
||
367 | * @Get content for sharing div |
||
368 | * @param int $id |
||
369 | * @param int $priv |
||
370 | * @param string $permalink |
||
371 | * @param string $desc |
||
372 | * @param string $username |
||
373 | * @return string |
||
374 | */ |
||
375 | public function getSharingDiv($id, $priv, $permalink, $desc, $username) |
||
376 | { |
||
377 | $text = ''; |
||
378 | if (1 != $priv) { |
||
379 | $text = "<div style='display: none;' class='smallworld_bookmarks' id='share-page' name='share-page" . $id . "'>"; |
||
380 | $text .= "<span name='share-page" . $id . "' rel1='" . $desc . "' rel2= '" . $username . "' rel=" . $permalink . " id='basicBookmark' title='" . _SMALLWORLD_SHAREBOX_TITLE . "'>"; |
||
381 | $text .= '</span></div>'; |
||
382 | } |
||
383 | |||
384 | return $text; |
||
385 | } |
||
386 | |||
387 | /** |
||
388 | * Parse update and comments array to template for public updates |
||
389 | * |
||
390 | * @param array $updatesarray |
||
391 | * @param int $id |
||
392 | * #return void |
||
393 | */ |
||
394 | public function parsePubArray($updatesarray, $id) |
||
395 | { |
||
396 | /** |
||
397 | * @var \XoopsModules\Smallworld\Helper $helper |
||
398 | * @var \XoopsModules\Smallworld\SwUserHandler $swUserHandler |
||
399 | */ |
||
400 | $helper = Helper::getInstance(); |
||
401 | $wm = []; |
||
402 | $check = new User(); |
||
403 | $swDB = new SwDatabase(); |
||
404 | $swUserHandler = $helper->getHandler('SwUser'); |
||
405 | $profile = $swUserHandler->checkIfProfile($id); |
||
406 | $myavatar = $swUserHandler->gravatar($id); |
||
407 | $myavatarlink = $swUserHandler->getAvatarLink($id, $myavatar); |
||
408 | $myavatar_size = smallworld_getImageSize(80, 100, $myavatarlink); |
||
409 | $myavatar_highwide = smallworld_imageResize($myavatar_size[0], $myavatar_size[1], 100); |
||
410 | $user_img = "<img src='" . $swUserHandler->getAvatarLink($id, $myavatar) . "' id='smallworld_user_img' " . $myavatar_highwide . '>'; |
||
411 | |||
412 | $GLOBALS['xoopsTpl']->assign([ |
||
413 | 'myavatar' => $myavatar, |
||
414 | 'myavatarlink' => $myavatarlink, |
||
415 | 'myavatar_highwide' => $myavatar_highwide, |
||
416 | 'avatar' => $user_img |
||
417 | ]); |
||
418 | |||
419 | foreach ($updatesarray as $data) { |
||
420 | // Is update's user a friend ? |
||
421 | $frU = $check->friendcheck($id, $data['uid_fk']); |
||
422 | $USW = ['posts' => 0, 'comments' => 0]; |
||
0 ignored issues
–
show
$USW is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
423 | |||
424 | View Code Duplication | if ($helper->isUserAdmin() || $data['uid_fk'] == $id) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
425 | $USW = ['posts' => 1, 'comments' => 1]; |
||
426 | $frU[0] = 2; |
||
427 | } else { |
||
428 | $USW = json_decode($swDB->getSettings($data['uid_fk']), true); |
||
429 | } |
||
430 | |||
431 | $wm['msg_id'] = $data['msg_id']; |
||
432 | $wm['orimessage'] = (1 == $USW['posts'] || $profile >= Constants::PROFILE_HAS_BOTH) ? str_replace(["\r", "\n"], '', smallworld_stripWordsKeepUrl($data['message'])) : ''; |
||
433 | $wm['message'] = (1 == $USW['posts'] || $profile >= Constants::PROFILE_HAS_BOTH) ? smallworld_tolink(htmlspecialchars_decode($data['message']), $data['uid_fk']) : _SMALLWORLD_MESSAGE_PRIVSETPOSTS; |
||
434 | $wm['message'] = smallworld_cleanup($wm['message']); |
||
435 | $wm['created'] = smallworld_time_stamp($data['created']); |
||
436 | $wm['username'] = $data['username']; |
||
437 | $wm['uid_fk'] = $data['uid_fk']; |
||
438 | $wm['priv'] = $data['priv']; |
||
439 | $wm['avatar'] = $swUserHandler->gravatar($data['uid_fk']); |
||
440 | $wm['avatar_link'] = $swUserHandler->getAvatarLink($data['uid_fk'], $wm['avatar']); |
||
441 | $wm['avatar_size'] = smallworld_getImageSize(80, 100, $wm['avatar_link']); |
||
442 | $wm['avatar_highwide'] = smallworld_imageResize($wm['avatar_size'][0], $wm['avatar_size'][1], 50); |
||
443 | $wm['vote_up'] = $this->countVotes('msg', 'up', $data['msg_id']); |
||
444 | $wm['vote_down'] = $this->countVotes('msg', 'down', $data['msg_id']); |
||
445 | $wm['sharelinkurl'] = $helper->url("smallworldshare.php?ownerid={$data['uid_fk']}"); |
||
446 | $wm['sharelinkurl'] .= '&updid=' . $data['msg_id'] . ''; |
||
447 | $wm['usernameTitle'] = $wm['username'] . _SMALLWORLD_UPDATEONSITEMETA . $GLOBALS['xoopsConfig']['sitename']; |
||
448 | View Code Duplication | if (1 == $USW['posts'] || $profile >= Constants::PROFILE_HAS_BOTH) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
449 | $wm['sharelink'] = $this->getSharing($wm['msg_id'], $wm['priv']); |
||
450 | } else { |
||
451 | $wm['sharelink'] = $this->getSharing($wm['msg_id'], 1); |
||
452 | } |
||
453 | |||
454 | View Code Duplication | if (1 == $USW['posts'] || $profile >= Constants::PROFILE_HAS_BOTH) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
455 | $wm['sharediv'] = $this->getSharingDiv($wm['msg_id'], $wm['priv'], $wm['sharelinkurl'], $wm['orimessage'], $wm['usernameTitle']); |
||
456 | } else { |
||
457 | $wm['sharediv'] = $this->getSharingDiv($wm['msg_id'], 1, $wm['sharelinkurl'], $wm['orimessage'], $wm['usernameTitle']); |
||
458 | } |
||
459 | $wm['linkimage'] = $helper->url('assets/images/link.png'); |
||
460 | $wm['permalink'] = $helper->url("permalink.php?ownerid={$data['uid_fk']}&updid={$data['msg_id']}"); |
||
461 | $wm['commentsarray'] = $this->Comments($data['msg_id']); |
||
462 | |||
463 | View Code Duplication | if (2 == $frU[0] || 1 == $USW['posts']) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
464 | $GLOBALS['xoopsTpl']->append('walldata', $wm); |
||
465 | } |
||
466 | |||
467 | foreach ($wm['commentsarray'] as $cdata) { |
||
468 | // Is comment user a friend ? |
||
469 | $frC = $check->friendcheck($id, $cdata['uid_fk']); |
||
470 | $USC = ['posts' => 0, 'comments' => 0]; |
||
0 ignored issues
–
show
$USC is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
471 | |||
472 | View Code Duplication | if ($helper->isUserAdmin() || $cdata['uid_fk'] == $id) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
473 | $USC = ['posts' => 1, 'comments' => 1]; |
||
474 | $frC[0] = Constants::PROFILE_HAS_BOTH; |
||
475 | } else { |
||
476 | $USC = json_decode($swDB->getSettings($cdata['uid_fk']), true); |
||
477 | } |
||
478 | |||
479 | $wc['msg_id_fk'] = $cdata['msg_id_fk']; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$wc was never initialized. Although not strictly required by PHP, it is generally a good practice to add $wc = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
480 | $wc['com_id'] = $cdata['com_id']; |
||
481 | $wc['comment'] = (1 == $USC['comments'] || $profile >= Constants::PROFILE_HAS_BOTH) ? smallworld_tolink(htmlspecialchars_decode($cdata['comment']), $cdata['uid_fk']) : _SMALLWORLD_MESSAGE_PRIVSETCOMMENTS; |
||
482 | $wc['comment'] = smallworld_cleanup($wc['comment']); |
||
483 | $wc['time'] = smallworld_time_stamp($cdata['created']); |
||
484 | $wc['username'] = $cdata['username']; |
||
485 | $wc['uid'] = $cdata['uid_fk']; |
||
486 | $wc['myavatar'] = $swUserHandler->gravatar($id); |
||
487 | $wc['myavatar_link'] = $swUserHandler->getAvatarLink($id, $wc['myavatar']); |
||
488 | $wc['avatar_size'] = smallworld_getImageSize(80, 100, $wc['myavatar_link']); |
||
489 | $wc['avatar_highwide'] = smallworld_imageResize($wc['avatar_size'][0], $wc['avatar_size'][1], 35); |
||
490 | $wc['cface'] = $swUserHandler->gravatar($cdata['uid_fk']); |
||
491 | $wc['avatar_link'] = $swUserHandler->getAvatarLink($cdata['uid_fk'], $wc['cface']); |
||
492 | $wc['vote_up'] = $this->countVotesCom('com', 'up', $cdata['msg_id_fk'], $cdata['com_id']); |
||
493 | $wc['vote_down'] = $this->countVotesCom('com', 'down', $cdata['msg_id_fk'], $cdata['com_id']); |
||
494 | |||
495 | View Code Duplication | if (Constants::PROFILE_HAS_BOTH == $frC[0] || 1 == $USC['comments']) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
496 | $GLOBALS['xoopsTpl']->append('comm', $wc); |
||
497 | } |
||
498 | } |
||
499 | } |
||
500 | } |
||
501 | } |
||
502 |