Completed
Pull Request — master (#5)
by Michael
01:57
created

functions.php ➔ smallworld_sociallinks()   F

Complexity

Conditions 11
Paths 1024

Size

Total Lines 45

Duplication

Lines 40
Ratio 88.89 %

Importance

Changes 0
Metric Value
cc 11
nc 1024
nop 2
dl 40
loc 45
rs 3.15
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
23
use Xmf\Request;
24
use XoopsModules\Smallworld;
25
26
//require_once __DIR__ . '/common.php';
27
28
/*
29
Get array of timestamps based on the timetype configured in preferences
30
*/
31
/**
32
 * @return array
33
 */
34
function SmallworldGetTimestampsToForm()
35
{
36
    $timearray = [];
37
    $start     = 1900;
38
    $end       = date('Y');
39
    for ($i = $start; $i <= $end; ++$i) {
40
        $key             = $i;
41
        $timearray[$key] = $i;
42
    }
43
    ksort($timearray);
44
45
    return $timearray;
46
}
47
48
// Clean vars or arrays
49
// If array check for magicQuotes.
50
// Pass string to Smallworld_cleanup_string
51
/**
52
 * @param $text
53
 * @return array|mixed
54
 */
55
function smallworld_cleanup($text)
56
{
57 View Code Duplication
    if (is_array($text)) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
58
        foreach ($text as $key => $value) {
59
            $text[$key] = smallworld_cleanup_string($value);
60
        }
61
    } else {
62
        $text = smallworld_cleanup_string($text);
63
    }
64
65
    return $text;
66
}
67
68
// Sanitize string
69
/**
70
 * @param $text
71
 * @return mixed
72
 */
73
function smallworld_cleanup_string($text)
74
{
75
    $myts = MyTextSanitizer::getInstance();
76
    $text = $myts->displayTarea($text, $html = 1, $smiley = 1, $xcode = 1, $image = 1, $br = 1);
77
78
    return $text;
79
}
80
81
// clean Array for mysql insertion
82
// or send string to Smallworld_sanitize_string
83
/**
84
 * @param $text
85
 * @return array|mixed
86
 */
87
function smallworld_sanitize($text)
88
{
89 View Code Duplication
    if (is_array($text)) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
90
        foreach ($text as $key => $value) {
91
            $text[$key] = smallworld_sanitize_string($value);
92
        }
93
    } else {
94
        $text = smallworld_sanitize_string($text);
95
    }
96
97
    return $text;
98
}
99
100
/**
101
 * @param $value
102
 * @return mixed
103
 */
104
function smallworld_sanitize_string($value)
105
{
106
    $myts = MyTextSanitizer::getInstance();
107
    if (get_magic_quotes_gpc()) {
108
        $value = $myts->stripSlashesGPC($value);
109
    } else {
110
        $value = $GLOBALS['xoopsDB']->escape($value);
111
    }
112
113
    return $value;
114
}
115
116
/**
117
 * @param $array
118
 * @return array
119
 */
120
function smallworld_DateOfArray($array)
121
{
122
    $data = [];
123
    foreach ($array as $k => $v) {
124
        $data[$k] = strtotime($v);
125
    }
126
127
    return $data;
128
}
129
130
/**
131
 * @param $array
132
 * @return array
133
 */
134
function smallworld_YearOfArray($array)
135
{
136
    $data = [];
137
    foreach ($array as $k => $v) {
138
        $data[$k] = $v;
139
    }
140
141
    return $data;
142
}
143
144
/**
145
 * @param $folderUrl
146
 */
147
function smallworld_CreateIndexFiles($folderUrl)
148
{
149
    $myts = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
$myts 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 $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.

Loading history...
150
    file_put_contents($folderUrl . 'index.html', '<script>history.go(-1);</script>');
151
}
152
153
/**
154
 * @param string $glue
155
 * @param        $pieces
156
 * @return string
157
 */
158
function smallworld_ImplodeArray($glue, $pieces)
159
{
160
    return implode($glue, $pieces);
161
}
162
163
// recursively reduces deep arrays to single-dimensional arrays
164
// $preserve_keys: (0=>never, 1=>strings, 2=>always)
165
/**
166
 * @param       $array
167
 * @param int   $preserve_keys
168
 * @param array $newArray
169
 * @return array
170
 */
171
function smallworld_array_flatten($array, $preserve_keys = 1, &$newArray = [])
172
{
173
    foreach ($array as $key => $child) {
174
        if (is_array($child)) {
175
            $newArray = smallworld_array_flatten($child, $preserve_keys, $newArray);
176
        } elseif ($preserve_keys + is_string($key) > 1) {
177
            $newArray[$key] = $child;
178
        } else {
179
            $newArray[] = $child;
180
        }
181
    }
182
183
    return $newArray;
184
}
185
186
/*
187
 * Calculate years from date format (YYYY-MM-DD)
188
 * @param date $birth
189
 * @returns integer
190
 */
191
/**
192
 * @param $birth
193
 * @return false|string
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|double?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
194
 */
195
function smallworld_Birthday($birth)
196
{
197
    list($year, $month, $day) = explode('-', $birth);
198
    $yearDiff  = date('Y') - $year;
199
    $monthDiff = date('m') - $month;
200
    $dayDiff   = date('d') - $day;
201
    if (0 == $monthDiff) {
202
        if ($dayDiff < 0) {
203
            $yearDiff--;
204
        }
205
    }
206
    if ($monthDiff < 0) {
207
        $yearDiff--;
208
    }
209
210
    return $yearDiff;
211
}
212
213
/**
214
 * @param $check
215
 * @return bool
216
 */
217 View Code Duplication
function smallworld_isset_or($check)
0 ignored issues
show
Duplication introduced by
This function 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.

Loading history...
218
{
219
    global $xoopsDB, $xoopsUser;
220
    $query  = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE username = '" . $check . "'";
221
    $result = $xoopsDB->queryF($query);
222
    while (false !== ($row = $xoopsDB->fetchArray($result))) {
223
        if ('' == $row['userid']) {
224
            return false;
225
        }
226
227
        return $row['userid'];
228
    }
229
}
230
231
//Srinivas Tamada http://9lessons.info
232
//Loading Comments link with load_updates.php
233
/**
234
 * @param $session_time
235
 * @return string
236
 */
237
function smallworld_time_stamp($session_time)
238
{
239
    global $xoopsConfig;
240
    $time_difference = time() - $session_time;
241
    $seconds         = $time_difference;
242
    $minutes         = round($time_difference / 60);
243
    $hours           = round($time_difference / 3600);
244
    $days            = round($time_difference / 86400);
245
    $weeks           = round($time_difference / 604800);
246
    $months          = round($time_difference / 2419200);
247
    $years           = round($time_difference / 29030400);
248
    if ($seconds <= 60) {
249
        $t = (string)$seconds . _SMALLWORLD_SECONDSAGO;
250
    } elseif ($minutes <= 60) {
251
        if (1 == $minutes) {
252
            $t = _SMALLWORLD_ONEMINUTEAGO;
253
        } else {
254
            $t = (string)$minutes . _SMALLWORLD_MINUTESAGO;
255
        }
256
    } elseif ($hours <= 24) {
257
        if (1 == $hours) {
258
            $t = _SMALLWORLD_ONEHOURAGO;
259
        } else {
260
            $t = (string)$hours . _SMALLWORLD_HOURSAGO;
261
        }
262
    } elseif ($days <= 7) {
263
        if (1 == $days) {
264
            $t = _SMALLWORLD_ONEDAYAGO;
265
        } else {
266
            $t = (string)$days . _SMALLWORLD_DAYSAGO;
267
        }
268
    } elseif ($weeks <= 4) {
269
        if (1 == $weeks) {
270
            $t = _SMALLWORLD_ONEWEEKAGO;
271
        } else {
272
            $t = (string)$weeks . _SMALLWORLD_WEEKSAGO;
273
        }
274
    } elseif ($months <= 12) {
275
        if (1 == $months) {
276
            $t = _SMALLWORLD_ONEMONTHAGO;
277
        } else {
278
            $t = (string)$months . _SMALLWORLD_MONTHSAGO;
279
        }
280
    } else {
281
        if (1 == $years) {
282
            $t = _SMALLWORLD_ONEYEARAGO;
283
        } else {
284
            $t = (string)$years . _SMALLWORLD_YEARSAGO;
285
        }
286
    }
287
288
    return $t;
289
}
290
291
// Return only url/link
292
// If url is image link return <img>
293
/**
294
 * @param $text
295
 * @param $uid
296
 * @return string
297
 */
298
function smallworld_tolink($text, $uid)
299
{
300
    global $xoopsUser;
301
    $ext       = mb_substr($text, -4, 4);
302
    $ext2      = mb_substr($text, -5, 5);
303
    $xoopsUser = new \XoopsUser($uid);
304
    $usr       = new $xoopsUser($uid);
305
306
    $userID   = $xoopsUser->getVar('uid');
307
    $user     = new \XoopsUser($userID);
308
    $username = $user->getVar('uname');
309
    $gallery  = XOOPS_URL . '/modules/smallworld/galleryshow.php?username=' . $usr->getVar('uname');
310
311
    if (in_array($ext, ['.jpg', '.bmp', '.gif', '.png']) || in_array($ext, ['.JPG', '.BMP', '.GIF', '.PNG']) || in_array($ext2, ['.jpeg'])) {
312
        if (false !== mb_strpos($text, 'UPLIMAGE')) {
313
            $text = str_replace('UPLIMAGE', '', $text);
314
            $text = preg_replace(
315
                '/(((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
316
                '<span class="smallworldUplImgTxt"><br><img class="smallworldAttImg" src="\\1"><br><br><a id="smallworldUplImgLnk" href="' . $gallery . '" target="_SELF">' . $usr->getVar('uname') . _SMALLWORLD_UPLOADEDSOMEIMAGES . '</a><br></span>',
317
                $text
318
            );
319
            $text = preg_replace('/(((f|ht){1}tps:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', '<a href="\\1">lala</a>', $text);
320
            $text = preg_replace(
321
                '/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
322
                '\\1<span class="smallworldUplImgTxt"><br><img class="smallworldAttImg" src="//\\2"><br><br><a id="smallworldUplImgLnk" href="' . $gallery . '" target="_SELF">' . $username . _SMALLWORLD_UPLOADEDSOMEIMAGES . '</a><br></span>',
323
                $text
324
            );
325
            $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
326
        } else {
327
            $text = preg_replace('/(((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', '<img class="smallworldAttImg" src="\\1"><a class="smallworldAttImgTxt" href="\\1">' . _SMALLWORLD_CLICKIMAGETHUMB . ' </a><br>', $text);
328
            $text = preg_replace('/(((f|ht){1}tps:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', '<img class="smallworldAttImg" src="\\1"><a class="smallworldAttImgTxt" href="\\1">' . _SMALLWORLD_CLICKIMAGETHUMB . ' </a><br>', $text);
329
            $text = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', '\\1<img class="smallworldAttImg" src="//\\2"><a class="smallworldAttImgTxt" href="//\\2">' . _SMALLWORLD_CLICKIMAGETHUMB . '</a><br>', $text);
330
            $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
331
        }
332
    } else {
333
        $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
334
        $text = ' ' . $text;
335
        $text = str_replace('UPLIMAGE', '', $text);
336
    }
337
338
    return linkify_twitter_status($text);
339
}
340
341
/**
342
 * @param $text
343
 * @return mixed
344
 */
345
function smallworld_stripWordsKeepUrl($text)
346
{
347
    preg_replace('/(((f|ht){1}tps:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', '<div class=".embed"><a href="\\1">\\1</a></div>', $text);
348
349
    return $text;
350
}
351
352
/**
353
 * @param $num
354
 * @param $name
355
 * @return string
356
 */
357
function smallworld_sociallinks($num, $name)
358
{
359 View Code Duplication
    if (0 == $num) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
360
        $image = '<img title="Msn" id="Smallworld_socialnetworkimg" src="' . XOOPS_URL . '/modules/smallworld/assets/images/socialnetworkicons/msn.png">';
361
        $link  = '<a title="Msn" id="Smallworld_socialnetwork" target="_blank" href="http://members.msn.com/' . $name . '">';
362
    }
363 View Code Duplication
    if (1 == $num) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
364
        $image = '<img title="facebook" id="Smallworld_socialnetworkimg" src="' . XOOPS_URL . '/modules/smallworld/assets/images/socialnetworkicons/facebook.png">';
365
        $link  = '<a title="facebook" id="Smallworld_socialnetwork" target="_blank" href="http://www.facebook.com/' . $name . '">';
366
    }
367 View Code Duplication
    if (2 == $num) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
368
        $image = '<img title="GooglePlus" id="Smallworld_socialnetworkimg" src="' . XOOPS_URL . '/modules/smallworld/assets/images/socialnetworkicons/googleplus.png">';
369
        $link  = '<a title="GooglePlus" id="Smallworld_socialnetwork" target="_blank" href="https://plus.google.com/' . $name . '">';
370
    }
371 View Code Duplication
    if (3 == $num) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
372
        $image = '<img title="Icq" id="Smallworld_socialnetworkimg" src="' . XOOPS_URL . '/modules/smallworld/assets/images/socialnetworkicons/icq.png">';
373
        $link  = '<a title="icq" id="Smallworld_socialnetwork" target="_blank" href="http://www.icq.com/people/' . $name . '/">';
374
    }
375 View Code Duplication
    if (4 == $num) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
376
        $image = '<img title="Skype" id="Smallworld_socialnetworkimg" src="' . XOOPS_URL . '/modules/smallworld/assets/images/socialnetworkicons/skype.png">';
377
        $link  = '<a title="Skype" id="Smallworld_socialnetwork" target="_blank" href="skype:' . $name . '?userinfo">';
378
    }
379 View Code Duplication
    if (5 == $num) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
380
        $image = '<img title="Twitter" id="Smallworld_socialnetworkimg" src="' . XOOPS_URL . '/modules/smallworld/assets/images/socialnetworkicons/twitter.png">';
381
        $link  = '<a title="Twitter" id="Smallworld_socialnetwork" target="_blank" href="http://twitter.com/#!/' . $name . '">';
382
    }
383 View Code Duplication
    if (6 == $num) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
384
        $image = '<img title="MySpace" id="Smallworld_socialnetworkimg" src="' . XOOPS_URL . '/modules/smallworld/assets/images/socialnetworkicons/myspace.png">';
385
        $link  = '<a title="MySpace" id="Smallworld_socialnetwork" target="_blank" href="http://www.myspace.com/' . $name . '">';
386
    }
387 View Code Duplication
    if (7 == $num) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
388
        $image = '<img title="Xoops" id="Smallworld_socialnetworkimg" src="' . XOOPS_URL . '/modules/smallworld/assets/images/socialnetworkicons/xoops.png">';
389
        $link  = '<a title="Xoops" id="Smallworld_socialnetwork" target="_blank" href="https://xoops.org/modules/profile/userinfo.php?uid=' . $name . '">';
390
    }
391 View Code Duplication
    if (8 == $num) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
392
        $image = '<img title="Yahoo Messenger" id="Smallworld_socialnetworkimg" src="' . XOOPS_URL . '/modules/smallworld/assets/images/socialnetworkicons/yahoo.png">';
393
        $link  = '<a title="Yahoo Messenger" id="Smallworld_socialnetwork" target="_blank" href="ymsgr:sendim?' . $name . '">';
394
    }
395 View Code Duplication
    if (9 == $num) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
396
        $image = '<img title="Youtube" id="Smallworld_socialnetworkimg" src="' . XOOPS_URL . '/modules/smallworld/assets/images/socialnetworkicons/youtube.png">';
397
        $link  = '<a title="Youtube" id="Smallworld_socialnetwork" target="_blank" href="http://www.youtube.com/user/' . $name . '">';
398
    }
399
400
    return $image . $link;
0 ignored issues
show
Bug introduced by
The variable $image 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $link 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
401
}
402
403
/**
404
 * @param        $option
405
 * @param string $repmodule
406
 * @return bool|mixed
407
 */
408
function smallworld_GetModuleOption($option, $repmodule = 'smallworld')
409
{
410
    global $xoopsModuleConfig, $xoopsModule;
411
    static $tbloptions = [];
412
    if (is_array($tbloptions) && array_key_exists($option, $tbloptions)) {
413
        return $tbloptions[$option];
414
    }
415
    $retval = false;
416
    if (isset($xoopsModuleConfig) && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule && $xoopsModule->getVar('isactive'))) {
417
        if (isset($xoopsModuleConfig[$option])) {
418
            $retval = $xoopsModuleConfig[$option];
419
        }
420
    } else {
421
        $moduleHandler = xoops_getHandler('module');
422
        $module        = $moduleHandler->getByDirname($repmodule);
423
        $configHandler = xoops_getHandler('config');
424
        if ($module) {
425
            $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
426
            if (isset($moduleConfig[$option])) {
427
                $retval = $moduleConfig[$option];
428
            }
429
        }
430
    }
431
    $tbloptions[$option] = $retval;
432
433
    return $retval;
434
}
435
436
/**
437
 * Check image extension and users gender. If image is legal image extension return avatar,
438
 * else return default gender based image
439
 * @param int    $userid
440
 * @param string $image
441
 * @returns string
442
 * @return string
443
 * @return string
444
 */
445
function smallworld_getAvatarLink($userid, $image)
446
{
447
    global $xoopsUser, $xoopsDB;
448
    $ext     = pathinfo(mb_strtolower($image), PATHINFO_EXTENSION);
449
    $sql     = 'SELECT gender FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . (int)$userid . "'";
450
    $result  = $xoopsDB->queryF($sql);
451
    $counter = $xoopsDB->getRowsNum($result);
452
    if (0 == $counter) {
453
        $gender = '';
454
    } else {
455
        while (false !== ($row = $xoopsDB->fetchArray($result))) {
456
            $gender = $row['gender'];
457
        }
458
    }
459
460
    //$image = ($image == 'blank.gif') ? '' : $image;
461
462
    if (preg_match('/avatars/i', $image)) {
463
        $link = XOOPS_UPLOAD_URL . '/' . $image;
464
    } else {
465
        $link = $image;
466
    }
467
468
    if (in_array($ext, ['jpg', 'bmp', 'gif', 'png', 'jpeg']) || '' == $image || 'blank.gif' == $image) {
469
        if ('1' == $gender) {
0 ignored issues
show
Bug introduced by
The variable $gender 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
470
            $link = XOOPS_URL . '/modules/smallworld/assets/images/ano_woman.png';
471
        }
472
473
        if ('2' == $gender) {
474
            $link = XOOPS_URL . '/modules/smallworld/assets/images/ano_man.png';
475
        }
476
477
        if ('' == $gender) {
478
            $link = XOOPS_URL . '/modules/smallworld/assets/images/genderless.png';
479
        }
480
    }
481
    //echo $link."<br>";
482
    return $link;
483
}
484
485
/**
486
 * @return bool
487
 */
488
function smallworld_checkForXim()
489
{
490
    $filename = XOOPS_ROOT_PATH . '/modules/xim/chat.php';
491
    if (file_exists($filename)) {
492
        return true;
493
    }
494
495
    return false;
496
}
497
498
/**
499
 * Get version number of xim if exists
500
 * @return int $version
501
 */
502 View Code Duplication
function smallworld_XIMversion()
0 ignored issues
show
Duplication introduced by
This function 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.

Loading history...
503
{
504
    global $xoopsDB;
505
    $sql    = 'SELECT version FROM ' . $xoopsDB->prefix('modules') . " WHERE dirname = 'xim'";
506
    $result = $xoopsDB->queryF($sql);
507
    if ($xoopsDB->getRowsNum($result) > 0) {
508
        while (false !== ($r = $xoopsDB->fetchArray($result))) {
509
            $version = $r['version'];
510
        }
511
    } else {
512
        $version = 0;
513
    }
514
515
    return $version;
0 ignored issues
show
Bug introduced by
The variable $version 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
516
}
517
518
/*
519
* Input: Message Id,
520
* Return owner of thread (original poster)
521
* Return Integer
522
*/
523
/**
524
 * @param $msg_id_fk
525
 * @return mixed
526
 */
527 View Code Duplication
function smallworld_getOwnerFromComment($msg_id_fk)
0 ignored issues
show
Duplication introduced by
This function 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.

Loading history...
528
{
529
    global $xoopsDB;
530
    $sql    = 'SELECT uid_fk FROM ' . $xoopsDB->prefix('smallworld_messages') . " WHERE msg_id = '" . $msg_id_fk . "'";
531
    $result = $xoopsDB->queryF($sql);
532
    while (false !== ($r = $xoopsDB->fetchArray($result))) {
533
        $owner = $r['uid_fk'];
534
    }
535
536
    return $owner;
0 ignored issues
show
Bug introduced by
The variable $owner 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
537
}
538
539
// Get username from userID
540
/**
541
 * @param $userID
542
 * @return mixed
543
 */
544 View Code Duplication
function smallworld_getName($userID)
0 ignored issues
show
Duplication introduced by
This function 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.

Loading history...
545
{
546
    global $xoopsUser, $xoopsDB;
547
    $sql    = 'SELECT username FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . (int)$userID . "'";
548
    $result = $xoopsDB->queryF($sql);
549
    while (false !== ($row = $xoopsDB->fetchArray($result))) {
550
        $name = $row['username'];
551
    }
552
553
    return $name;
0 ignored issues
show
Bug introduced by
The variable $name 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
554
}
555
556
// Check if user has been taken down for inspection by admin
557
// Userid = user id of user to check
558
// return array
559
/**
560
 * @param $userid
561
 * @return array
562
 */
563
function smallworld_isInspected($userid)
564
{
565
    global $xoopsDB;
566
    $data   = [];
567
    $sql    = 'SELECT inspect_start, inspect_stop FROM ' . $xoopsDB->prefix('smallworld_admin') . " WHERE userid = '" . $userid . "' AND (inspect_start+inspect_stop) > " . time() . '';
568
    $result = $xoopsDB->queryF($sql);
569
    if ($xoopsDB->getRowsNum($result) > 0) {
570
        while (false !== ($row = $xoopsDB->fetchArray($result))) {
571
            $data['inspect']   = 'yes';
572
            $data['totaltime'] = ($row['inspect_start'] + $row['inspect_stop']) - time();
573
        }
574
    } else {
575
        $data['inspect'] = 'no';
576
    }
577
578
    return $data;
579
}
580
581
// Auto delete all inspects from DB where time has passed
582
// inspect_start + inspect_stop - time() is deleted if negative intval
583
function SmallworldDeleteOldInspects()
584
{
585
    global $xoopsDB;
586
    $sql    = 'UPDATE ' . $xoopsDB->prefix('smallworld_admin') . " SET inspect_start = '', inspect_stop = '' WHERE (inspect_start+inspect_stop) <= " . time() . '';
587
    $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$result 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 $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.

Loading history...
588
}
589
590
// Function to get sum of users in you following array
591
// Used to calculate new message flash in jQuery intval fetch
592
/**
593
 * @return mixed
594
 */
595
function smallworld_getCountFriendMessagesEtc()
596
{
597
    global $xoopsUser, $xoopsDB;
598
    $user      = new \XoopsUser();
0 ignored issues
show
Unused Code introduced by
$user 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 $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.

Loading history...
599
    $wall      = new Smallworld\WallUpdates();
600
    $userid    = $xoopsUser->getVar('uid');
601
    $followers = smallworld_array_flatten($wall->getFollowers($userid), 0);
602
    if (1 == smallworld_GetModuleOption('usersownpostscount', $repmodule = 'smallworld')) {
603
        $followers[] = $userid;
604
    }
605
    $ids    = implode(',', $followers);
606
    $sql    = 'SELECT COUNT(*) AS total '
607
              . ' FROM ( '
608
              . ' SELECT com_id , count( * ) as comments FROM '
609
              . $xoopsDB->prefix('smallworld_comments')
610
              . " WHERE uid_fk IN ($ids) Group by com_id "
611
              . ' UNION ALL '
612
              . ' Select msg_id , count( * ) as messages FROM '
613
              . $xoopsDB->prefix('smallworld_messages')
614
              . " WHERE uid_fk IN ($ids) group by msg_id "
615
              . ' ) as d';
616
    $result = $xoopsDB->queryF($sql);
617
    while (false !== ($r = $xoopsDB->fetchArray($result))) {
618
        $total = $r['total'];
619
    }
620
621
    return $total;
0 ignored issues
show
Bug introduced by
The variable $total 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
622
}
623
624
// Function to get sum of users in you following array
625
// Used to calculate new message flash in jQuery intval fetch
626
/**
627
 * @param $id
628
 * @return mixed
629
 */
630
function smallworld_countUsersMessages($id)
631
{
632
    global $xoopsUser, $xoopsDB;
633
    $user   = new \XoopsUser();
0 ignored issues
show
Unused Code introduced by
$user 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 $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.

Loading history...
634
    $wall   = new Smallworld\WallUpdates();
0 ignored issues
show
Unused Code introduced by
$wall 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 $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.

Loading history...
635
    $sql    = 'SELECT COUNT(*) AS total ' . ' FROM ( ' . ' SELECT com_id , count( * ) AS comments FROM ' . $xoopsDB->prefix('smallworld_comments') . ' WHERE uid_fk = ' . (int)$id . ' GROUP BY com_id ' . ' UNION ALL ' . ' SELECT msg_id , count( * ) AS messages FROM ' . $xoopsDB->prefix(
636
            'smallworld_messages'
637
        ) . ' WHERE uid_fk = ' . (int)$id . 'group BY msg_id ' . ' ) AS d';
638
    $result = $xoopsDB->queryF($sql);
639
    while (false !== ($r = $xoopsDB->fetchArray($result))) {
640
        $total = $r['total'];
641
    }
642
643
    return $total;
0 ignored issues
show
Bug introduced by
The variable $total 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
644
}
645
646
// Get the three newest members to array
647
/**
648
 * @return array
649
 */
650
function smallworld_Stats_newest()
651
{
652
    global $xoopsDB, $xoopsUser;
653
    $nu     = [];
654
    $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . ' ORDER BY regdate DESC LIMIT 3';
655
    $result = $xoopsDB->queryF($sql);
656
    if ($xoopsDB->getRowsNum($result) > 0) {
657
        $i = 0;
658
        while (false !== ($r = $xoopsDB->fetchArray($result))) {
659
            $nu[$i]['userid']         = $r['userid'];
660
            $nu[$i]['username']       = $r['username'];
661
            $nu[$i]['regdate']        = date('d-m-Y', $r['regdate']);
662
            $nu[$i]['username_link']  = "<a href = '" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $r['username'] . "'>";
663
            $nu[$i]['username_link']  .= $r['username'] . ' (' . $r['realname'] . ') [' . $nu[$i]['regdate'] . '] </a>';
664
            $nu[$i]['userimage']      = $r['userimage'];
665
            $nu[$i]['userimage_link'] = smallworld_getAvatarLink($r['userid'], smallworld_Gravatar($r['userid']));
666
            ++$i;
667
        }
668
    }
669
670
    return $nu;
671
}
672
673
//Avatar Image
674
/**
675
 * @param $uid
676
 * @return string
677
 */
678 View Code Duplication
function smallworld_Gravatar($uid)
0 ignored issues
show
Duplication introduced by
This function 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.

Loading history...
679
{
680
    global $xoopsUser, $xoopsDB;
681
    $image  = '';
682
    $sql    = 'SELECT userimage FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . $uid . "'";
683
    $result = $xoopsDB->queryF($sql);
684
    while (false !== ($r = $xoopsDB->fetchArray($result))) {
685
        $image = $r['userimage'];
686
    }
687
688
    $image = ('' == $image || 'blank.gif' === $image) ? smallworld_getAvatarLink($uid, $image) : $image;
689
690
    $type = [
691
        1 => 'jpg',
692
        2 => 'jpeg',
693
        3 => 'png',
694
        4 => 'gif',
695
    ];
696
697
    $ext = explode('.', $image);
698
699
    if (@!in_array(mb_strtolower($ext[1]), $type) || '' == $image) {
700
        $avatar = '';
701
    } else {
702
        $avatar = $image;
703
    }
704
705
    return $avatar;
706
}
707
708
// find user with most posted messages
709
/**
710
 * @return array
711
 */
712
function smallworld_mostactiveusers_allround()
713
{
714
    global $xoopsDB, $xoopsUser;
715
    $msg     = [];
716
    $sql     = 'SELECT uid_fk, COUNT( * ) as cnt ';
717
    $sql     .= 'FROM ( ';
718
    $sql     .= 'SELECT uid_fk ';
719
    $sql     .= 'FROM ' . $xoopsDB->prefix('smallworld_messages') . ' ';
720
    $sql     .= 'UNION ALL SELECT uid_fk ';
721
    $sql     .= 'FROM ' . $xoopsDB->prefix('smallworld_comments') . ' ';
722
    $sql     .= ') AS u ';
723
    $sql     .= 'GROUP BY uid_fk ';
724
    $sql     .= 'ORDER BY count( * ) DESC limit 3';
725
    $result  = $xoopsDB->queryF($sql);
726
    $counter = $xoopsDB->getRowsNum($result);
727
    if ($counter < 1) {
728
    } else {
729
        $counter = 1;
730
        while (false !== ($row = $xoopsDB->fetchArray($result))) {
731
            $msg[$counter]['counter']       = $counter;
732
            $msg[$counter]['img']           = smallworld_getAvatarLink($row['uid_fk'], smallworld_Gravatar($row['uid_fk']));
733
            $msg[$counter]['msgs']          = _SMALLWORLD_TOTALPOSTS . ' : ' . $row['cnt'];
734
            $msg[$counter]['cnt']           = $row['cnt'];
735
            $msg[$counter]['username']      = $xoopsUser->getUnameFromId($row['uid_fk']);
736
            $msg[$counter]['username_link'] = "<a href = '" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $msg[$counter]['username'] . "'>";
737
            $msg[$counter]['username_link'] .= $msg[$counter]['username'] . ' (' . $msg[$counter]['msgs'] . ')</a>';
738
            ++$counter;
739
        }
740
    }
741
742
    return $msg;
743
}
744
745
// Find worst rated users overall
746
/**
747
 * @return array
748
 */
749 View Code Duplication
function smallworld_worstratedusers()
0 ignored issues
show
Duplication introduced by
This function 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.

Loading history...
750
{
751
    global $xoopsUser, $xoopsDB;
752
    $array   = [];
753
    $counter = 1;
754
    $sql     = 'SELECT owner, (';
755
    $sql     .= 'sum( up ) - sum( down )';
756
    $sql     .= ') AS total';
757
    $sql     .= ' FROM ' . $xoopsDB->prefix('smallworld_vote') . '';
758
    $sql     .= ' GROUP BY owner ORDER by total ASC LIMIT 5';
759
    $result  = $xoopsDB->queryF($sql);
760
    while (false !== ($row = $xoopsDB->fetchArray($result))) {
761
        $array[$counter]['counter']   = $counter;
762
        $array[$counter]['img']       = smallworld_getAvatarLink($row['owner'], smallworld_Gravatar($row['owner']));
763
        $array[$counter]['user']      = $xoopsUser->getUnameFromId($row['owner']);
764
        $array[$counter]['rating']    = $row['total'];
765
        $array[$counter]['user_link'] = "<a href = '" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $array[$counter]['user'] . "'>";
766
        $array[$counter]['user_link'] .= $array[$counter]['user'] . ' (' . $array[$counter]['rating'] . ')</a>';
767
        ++$counter;
768
    }
769
770
    return $array;
771
}
772
773
// Find best rated users overall
774
/**
775
 * @return array
776
 */
777 View Code Duplication
function smallworld_topratedusers()
0 ignored issues
show
Duplication introduced by
This function 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.

Loading history...
778
{
779
    global $xoopsUser, $xoopsDB;
780
    $array   = [];
781
    $counter = 1;
782
    $sql     = 'SELECT owner, (';
783
    $sql     .= 'sum( up ) - sum( down )';
784
    $sql     .= ') AS total';
785
    $sql     .= ' FROM ' . $xoopsDB->prefix('smallworld_vote') . '';
786
    $sql     .= ' GROUP BY owner ORDER by total DESC LIMIT 5';
787
    $result  = $xoopsDB->queryF($sql);
788
    while (false !== ($row = $xoopsDB->fetchArray($result))) {
789
        $array[$counter]['counter']   = $counter;
790
        $array[$counter]['img']       = smallworld_getAvatarLink($row['owner'], smallworld_Gravatar($row['owner']));
791
        $array[$counter]['user']      = $xoopsUser->getUnameFromId($row['owner']);
792
        $array[$counter]['rating']    = $row['total'];
793
        $array[$counter]['user_link'] = "<a href = '" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $array[$counter]['user'] . "'>";
794
        $array[$counter]['user_link'] .= $array[$counter]['user'] . ' (' . $array[$counter]['rating'] . ')</a>';
795
        ++$counter;
796
    }
797
798
    return $array;
799
}
800
801
/**
802
 * @return array
803
 */
804
function smallworld_nextBirthdays()
805
{
806
    global $xoopsDB, $xoopsUser;
807
    $now     = date('d-m');
0 ignored issues
show
Unused Code introduced by
$now 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 $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.

Loading history...
808
    $res     = [];
809
    $sql     = 'SELECT userid, username, userimage, realname, birthday, CURDATE(),'
810
               . ' DATE_FORMAT(birthday, "%d / %m") AS daymon , '
811
               . ' (YEAR(CURDATE())-YEAR(birthday))'
812
               . ' - (RIGHT(CURDATE(),5)<RIGHT(birthday,5))'
813
               . ' AS age_now'
814
               . ' FROM '
815
               . $xoopsDB->prefix('smallworld_user')
816
               . ' WHERE right(birthday,5) = right(CURDATE(),5)'
817
               . ' ORDER BY MONTH( birthday ) , DAY( birthday ) '
818
               . ' LIMIT 10 ';
819
    $result  = $xoopsDB->queryF($sql);
820
    $counter = $xoopsDB->getRowsNum($result);
821
    $i       = 0;
822
    while (false !== ($r = $xoopsDB->fetchArray($result))) {
823
        $res[$i]['amount']        = $counter;
824
        $res[$i]['userid']        = $r['userid'];
825
        $res[$i]['userimage']     = smallworld_getAvatarLink($r['userid'], smallworld_Gravatar($r['userid']));
826
        $res[$i]['birthday']      = $r['daymon'];
827
        $res[$i]['agenow']        = $r['age_now'];
828
        $res[$i]['username']      = $xoopsUser->getUnameFromId($r['userid']);
829
        $res[$i]['username_link'] = "<a href = '" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $res[$i]['username'] . "'>";
830
        $res[$i]['username_link'] .= $res[$i]['username'] . ' (' . $r['daymon'] . ') ' . $r['age_now'] . ' ' . _SMALLWORLD_BDAY_YEARS;
831
        $res[$i]['username_link'] .= '</a>';
832
        ++$i;
833
    }
834
835
    return $res;
836
}
837
838
/*
839
 * Return date format (YYYY-MM-DD) for MySql
840
 * @param date $stringDate
841
 * $returns date
842
*/
843
/**
844
 * @param $stringDate
845
 * @return string
846
 */
847 View Code Duplication
function smallworld_euroToUsDate($stringDate)
0 ignored issues
show
Duplication introduced by
This function 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.

Loading history...
848
{
849
    if (0 != $stringDate || '' != $stringDate) {
850
        $theData = explode('-', trim($stringDate));
851
        $ret     = $theData[2] . '-' . $theData[1] . '-' . $theData[0];
852
853
        return $ret;
854
    }
855
856
    return '1900-01-01';
857
}
858
859
/*
860
 * Return date format (DD-MM-YYYY) for display
861
 * @param date $stringDate
862
 * $returns date
863
*/
864
/**
865
 * @param $stringDate
866
 * @return string
867
 */
868 View Code Duplication
function smallworld_UsToEuroDate($stringDate)
0 ignored issues
show
Duplication introduced by
This function 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.

Loading history...
869
{
870
    if (0 != $stringDate || '' != $stringDate) {
871
        $theData = explode('-', trim($stringDate));
872
        $ret     = $theData[2] . '-' . $theData[1] . '-' . $theData[0];
873
874
        return $ret;
875
    }
876
877
    return '01-01-1900';
878
}
879
880
/**
881
 * @return array
882
 */
883
function smallworld_sp()
884
{
885
    $sp               = [];
886
    $sp[0]['spimage'] = "<img id = 'smallworld_img_sp' src = '" . XOOPS_URL . "/modules/smallworld/assets/images/sp.png' height='30px' width='30px' >";
887
888
    return $sp;
889
}
890
891
//Check privacy settings in permapage
892
/**
893
 * @param $id
894
 * @return mixed
895
 */
896 View Code Duplication
function smallworldCheckPriv($id)
0 ignored issues
show
Duplication introduced by
This function 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.

Loading history...
897
{
898
    global $xoopsDB;
899
    $public = 'SELECT priv FROM ' . $xoopsDB->prefix('smallworld_messages') . ' WHERE msg_id = ' . $id . '';
900
    $result = $xoopsDB->queryF($public);
901
    while (false !== ($row = $xoopsDB->fetchArray($result))) {
902
        $priv = $row['priv'];
903
    }
904
905
    return $priv;
0 ignored issues
show
Bug introduced by
The variable $priv 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
906
}
907
908
// Function to calculate remaining seconds until user's birthday
909
// Input $d : date('Y-m-d') format
910
// return seconds until date at midnight, or
911
// return 0 if date ('Y-m-d') is equal to today
912
/**
913
 * @param $d
914
 * @return bool|int|string
915
 */
916
function smallworldNextBDaySecs($d)
917
{
918
    $olddate   = mb_substr($d, 4);
919
    $exactdate = date('Y') . '' . $olddate;
920
    $newdate   = date('Y') . '' . $olddate . ' 00:00:00';
921
    $nextyear  = date('Y') + 1 . '' . $olddate . ' 00:00:00';
922
    if ($exactdate != date('Y-m-d')) {
923
        if ($newdate > date('Y-m-d H:i:s')) {
924
            $start_ts = strtotime($newdate);
925
            $end_ts   = strtotime(date('Y-m-d H:i:s'));
926
            $diff     = $end_ts - $start_ts;
927
            $n        = round($diff);
928
            $return   = mb_substr($n, 1);
929
930
            return $return;
931
        }
932
        $start_ts = strtotime($nextyear);
933
        $end_ts   = strtotime(date('Y-m-d H:i:s'));
934
        $diff     = $end_ts - $start_ts;
935
        $n        = round($diff);
936
        $return   = mb_substr($n, 1);
937
938
        return $return;
939
    }
940
941
    return 0;
942
}
943
944
//Function to get value from xoopsConfig array
945
/**
946
 * @param $key
947
 * @param $array
948
 * @return int
949
 */
950
function smallworldGetValfromArray($key, $array)
951
{
952
    $ar  = smallworld_GetModuleOption($array, $repmodule = 'smallworld');
953
    $ret = 0;
0 ignored issues
show
Unused Code introduced by
$ret 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 $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.

Loading history...
954
    if (in_array($key, $ar, true)) {
955
        $ret = 1;
956
957
        return $ret;
958
    }
959
960
    return 0;
961
}
962
963
//Function to resize images proportionally
964
// Using imagesize($imageurl) returns $img[0], $img[1]
965
// Target = new max height or width in px
966
/**
967
 * @param $width
968
 * @param $height
969
 * @param $target
970
 * @return string
971
 */
972
function smallworld_imageResize($width, $height, $target)
973
{
974
    //takes the larger size of the width and height and applies the
975
    //formula accordingly...this is so this script will work
976
    //dynamically with any size image
977
    if ($width > $height) {
978
        $percentage = ($target / $width);
979
    } else {
980
        $percentage = ($target / $height);
981
    }
982
    //gets the new value and applies the percentage, then rounds the value
983
    $width  = round($width * $percentage);
984
    $height = round($height * $percentage);
985
    //returns the new sizes in html image tag format...this is so you
986
    //can plug this function inside an image tag and just get the
987
988
    return "width=\"$width\" height=\"$height\"";
989
}
990
991
/**
992
 * Fetch image width and height
993
 * will attempt to use the getimagesiz method first, then curl
994
 * @param int $w
995
 * @param int $h
996
 * @param string|\http\Url $url
997
 * @returns array
998
 * @return array|false|string[]
999
 * @return array|false|string[]
1000
 */
1001
function smallworld_getImageSize($w, $h, $url)
1002
{
1003
    $bn = basename($url);
1004
    if ('blank.gif' !== $bn
1005
        || 'blank.png' !== $bn
1006
        || 'blank.jpg' !== $bn
1007
        || 'image_missing.png' !== $bn) {
1008
        if (ini_get('allow_url_fopen')) {
1009
            $imagesize = getimagesize($url);
1010
        } else {
1011
            $imagesize['0'] = $w;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$imagesize was never initialized. Although not strictly required by PHP, it is generally a good practice to add $imagesize = 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 $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

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.

Loading history...
1012
            $imagesize['1'] = $h;
1013
        }
1014
1015
        if (!ini_get('allow_url_fopen')) {
1016
            if (function_exists('curl_init')) {
1017
                $ch = curl_init();
1018
                curl_setopt($ch, CURLOPT_URL, $url);
1019
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1020
                $result         = curl_exec($ch);
1021
                $img            = imagecreatefromstring($result);
1022
                $imagesize['0'] = imagesx($img);
1023
                $imagesize['1'] = imagesy($img);
1024
            } else {
1025
                $imagesize['0'] = $w;
1026
                $imagesize['1'] = $h;
1027
            }
1028
        }
1029
1030
        return $imagesize;
1031
    }
1032
1033
    return [0 => '0', 1 => '0'];
1034
}
1035
1036
/**
1037
 * Check weather requests are set or not
1038
 * If not return '' else return false
1039
 * @param string $req
1040
 * @returns string or void
1041
 * @return string|null
1042
 * @return string|null
1043
 */
1044
function smallworld_isset($req)
1045
{
1046
    if (isset($req) || !empty($req)) {
1047
        return $req;
1048
    }
1049
1050
    return '';
1051
}
1052
1053
/**
1054
 * @do db query for images upload last 5 minutes by spec. userid and return random
1055
 * @param int $userid
1056
 * @returns string
1057
 * @return bool|mixed
1058
 * @return bool|mixed
1059
 */
1060 View Code Duplication
function smallworld_getRndImg($userid)
0 ignored issues
show
Duplication introduced by
This function 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.

Loading history...
1061
{
1062
    global $xoopsDB;
1063
    $sql    = 'SELECT imgname FROM ' . $xoopsDB->prefix('smallworld_images') . ' WHERE userid = ' . $userid . ' AND time BETWEEN UNIX_TIMESTAMP( ) - 3000 AND UNIX_TIMESTAMP() ORDER BY rand() LIMIT 1';
1064
    $result = $xoopsDB->queryF($sql);
1065
    while (false !== ($r = $xoopsDB->fetchArray($result))) {
1066
        $img = $r['imgname'];
1067
    }
1068
    if (!empty($img)) {
1069
        return $img;
1070
    }
1071
1072
    return false;
1073
}
1074
1075
/**
1076
 * @Get url of smallworld
1077
 * @returns string
1078
 */
1079
function smallworld_getHostRequest()
1080
{
1081
    $protocol   = false === mb_stripos($_SERVER['SERVER_PROTOCOL'], 'https') ? 'http' : 'https';
1082
    $host       = $_SERVER['HTTP_HOST'];
1083
    $script     = $_SERVER['SCRIPT_NAME'];
0 ignored issues
show
Unused Code introduced by
$script 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 $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.

Loading history...
1084
    $params     = $_SERVER['QUERY_STRING'];
0 ignored issues
show
Unused Code introduced by
$params 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 $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.

Loading history...
1085
    $currentUrl = $protocol . '://' . $host;
1086
1087
    return $currentUrl;
1088
}
1089
1090
/**
1091
 * @Get htmlentities
1092
 * @param $text
1093
 * @return string translated string to utf-8
1094
 */
1095
function smallworld_decodeEntities($text)
1096
{
1097
    $text = html_entity_decode($text, ENT_QUOTES, 'ISO-8859-1'); #NOTE: UTF-8 does not work!
1098
    $text = preg_replace('/&#(\d+);/me', 'chr(\\1)', $text); #decimal notation
1099
    $text = preg_replace('/&#x([a-f0-9]+);/mei', 'chr(0x\\1)', $text);  #hex notation
1100
    return $text;
1101
}
1102
1103
/**
1104
 * @Get string and shorten so contains only ? chars
1105
 * @param $text
1106
 * @param $chars
1107
 * @return string
1108
 */
1109
function smallworld_shortenText($text, $chars)
1110
{
1111
    $text .= ' ';
1112
    $text = mb_substr($text, 0, $chars);
1113
    $text = mb_substr($text, 0, mb_strrpos($text, ' '));
1114
    $text .= '...';
1115
1116
    return $text;
1117
}
1118
1119
/**
1120
 * @Get languagefile if constants are not defined
1121
 * @param $def
1122
 * @param $file
1123
 * return file include
1124
 */
1125
function smallworld_isDefinedLanguage($def, $file)
1126
{
1127
    global $xoopsConfig;
1128
    if (!defined($def)) {
1129
        // language files (main.php)
1130
        if (file_exists(XOOPS_ROOT_PATH . '/modules/smallworld/language/' . $xoopsConfig['language'] . '/' . $file)) {
1131
            require_once XOOPS_ROOT_PATH . '/modules/smallworld/language/' . $xoopsConfig['language'] . '/' . $file;
1132
        } else {
1133
            // fallback english
1134
            require_once XOOPS_ROOT_PATH . '/modules/smallworld/language/english/' . '/' . $file;
1135
        }
1136
    }
1137
}
1138
1139
/**
1140
 * @Check if smallworld is for private or public access
1141
 * return value for config
1142
 */
1143
function smallworld_checkPrivateOrPublic()
1144
{
1145
    global $xoopsUser;
1146
    $opt = [];
1147
    $set = smallworld_GetModuleOption('smallworldprivorpub', $repmodule = 'smallworld');
1148
    if (0 != $set) {
1149
        $opt['access'] = 1;
1150
    } else {
1151
        $opt['access'] = 0;
1152
    }
1153
    if ($xoopsUser) {
1154
        $id               = $xoopsUser->getVar('uid');
1155
        $user             = new \XoopsUser($id);
0 ignored issues
show
Unused Code introduced by
$user 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 $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.

Loading history...
1156
        $check            = new \XoopsModules\Smallworld\User();
1157
        $profile          = $check->checkIfProfile($id);
1158
        $opt['xoopsuser'] = 1;
1159
        if (0 != $profile) {
1160
            $opt['smallworlduser'] = 1;
1161
        } else {
1162
            $opt['smallworlduser'] = 0;
1163
        }
1164
    } else {
1165
        $opt['xoopsuser']      = 0;
1166
        $opt['smallworlduser'] = 0;
1167
    }
1168
1169
    return $opt;
1170
}
1171
1172
/**
1173
 * @return array of groups
1174
 * return array
1175
 */
1176
function smallworld_xv_getGroupd()
1177
{
1178
    $db     = \XoopsDatabaseFactory::getDatabaseConnection();
1179
    $myts   = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
$myts 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 $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.

Loading history...
1180
    $sql    = 'SELECT userid, username FROM ' . $db->prefix('smallworld_user') . ' ORDER BY userid';
1181
    $result = $db->queryF($sql);
1182
    $num    = $db->getRowsNum($result);
1183
    if (0 == $num) {
1184
        $ndata = [0 => _MI_SMALLWORLD_ALL];
1185
    } else {
1186
        while (false !== ($r = $db->fetchArray($result))) {
1187
            $data[$r['userid']] = $r['username'];
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 $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

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.

Loading history...
1188
        }
1189
        $ndata = array_merge([0 => _MI_SMALLWORLD_ALL], $data);
0 ignored issues
show
Bug introduced by
The variable $data 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1190
    }
1191
1192
    return $ndata;
1193
}
1194
1195
/**
1196
 * Set javascript vars to theme using various values
1197
 * Return void
1198
 */
1199
function smallworld_SetCoreScript()
1200
{
1201
    global $xoopsUser, $xoopsConfig, $xoTheme;
1202
1203
    $moduleHandler = xoops_getHandler('module');
1204
    $module        = $moduleHandler->getByDirname('smallworld');
1205
    $configHandler = xoops_getHandler('config');
1206
    if ($module) {
1207
        $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
1208
    }
1209
1210
    // IF logged in define xoops / smallworld user id
1211
    $myid = $xoopsUser ? $xoopsUser->getVar('uid') : 0;
1212
1213
    // Check if option is et to allow public reading
1214
    $pub    = smallworld_checkPrivateOrPublic();
1215
    $access = $pub['access'];
0 ignored issues
show
Unused Code introduced by
$access 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 $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.

Loading history...
1216
1217
    // GET various variables from language folder
1218 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/modules/smallworld/language/' . $xoopsConfig['language'] . '/js/variables.js')) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
1219
        $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/language/' . $xoopsConfig['language'] . '/js/variables.js');
1220
    } else {
1221
        $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/language/english/js/variables.js');
1222
    }
1223
1224
    // Check if USER is smallworld-registered user
1225
    $chkUser = new Smallworld\User();
1226
    $ChkProf = $xoopsUser ? $chkUser->checkIfProfile($myid) : 0;
1227
1228
    // Check if there are requests pending
1229
    $count_invit = $xoopsUser ? count($chkUser->getRequests($myid)) : 0;
1230
1231
    // Get module config for validation and place in javascript
1232
    $validate = $moduleConfig['validationstrenght'];
0 ignored issues
show
Bug introduced by
The variable $moduleConfig 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1233
1234
    // Check to see if smallworld should use username links to point to default xoops or smallworld
1235
    $takeoverlinks   = $moduleConfig['takeoveruserlinks'];
1236
    $fieldstoshow    = array_flip(smallworld_GetModuleOption('smallworldusethesefields', $repmodule = 'smallworld'));
0 ignored issues
show
Unused Code introduced by
$fieldstoshow 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 $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.

Loading history...
1237
    $useverification = smallworld_GetModuleOption('smallworldmandatoryfields', $repmodule = 'smallworld');
1238
    $smallworldUV    = implode(',', $useverification);
1239
1240
    // Use googlemaps ?
1241
    $googlemaps = $moduleConfig['smallworldUseGoogleMaps'];
1242
1243
    // Get users messages count based on users followerArray
1244
    $getUserMsgNum = $xoopsUser ? smallworld_getCountFriendMessagesEtc() : 0;
1245
1246
    // Check if request url is with www or without
1247
    $urltest   = smallworld_getHostRequest();
1248
    $xoops_url = XOOPS_URL;
1249
    if (false === mb_strpos($urltest, 'www.')) {
1250
        $xoops_url = str_replace('www.', '', $xoops_url);
1251
    }
1252
1253
    // Set javascript vars but only if not already defined.
1254
    // Check prevents multible loads
1255
    $script = 'var Smallworld_myID;' . "\n";
1256
    $script .= "if (typeof Smallworld_myID === 'undefined') {" . "\n";
1257
    $script .= "var smallworld_url = '" . $xoops_url . '/modules/smallworld/' . "';\n";
1258
    $script .= "var smallworld_uploaddir = '" . $xoops_url . '/uploads/avatars/' . "';\n";
1259
    $script .= 'var smallworld_urlReferer = document.referrer;' . "\n";
1260
    $script .= "var xoops_smallworld = jQuery.noConflict();\n";
1261
    $script .= 'var Smallworld_myID = ' . $myid . ";\n";
1262
    $script .= 'var Smallworld_userHasProfile = ' . $ChkProf . ";\n";
1263
    $script .= 'var smallworldTakeOverLinks = ' . $takeoverlinks . ";\n";
1264
    $script .= 'var Smallworld_geocomplete = ' . $googlemaps . ";\n";
1265
    $script .= "var smallworldVerString = '" . $smallworldUV . "';\n";
1266
    $script .= "var smallworlduseverification = new Array();\n";
1267
    $script .= "smallworlduseverification = smallworldVerString.split(',');\n";
1268
    $script .= 'var Smallworld_hasmessages = ' . $count_invit . ";\n";
1269
    $script .= 'var smallworldvalidationstrenght = ' . $validate . ";\n";
1270
    $script .= 'var smallworld_getFriendsMsgComCount = ' . $getUserMsgNum . ";\n";
1271
    //$script .= "var $ = jQuery();\n";
1272
    $script .= '}' . "\n";
1273
    $xoTheme->addScript('', '', $script);
1274
1275
    // Include geolocate styling
1276
    if (1 == $googlemaps) {
1277
        $xoTheme->addScript('https://maps.googleapis.com/maps/api/js?sensor=false&language=' . _LANGCODE);
1278
        $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/ui.geo_autocomplete.js');
1279
        $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/ui.geo_autocomplete_now.js');
1280
    }
1281
1282
    smallworld_includeScripts();
1283
}
1284
1285
/**
1286
 * Include script files based on $page
1287
 */
1288
function smallworld_includeScripts()
1289
{
1290
    global $xoopsUser, $xoopsConfig, $xoTheme;
1291
    $page = basename($_SERVER['PHP_SELF'], '.php');
1292
    switch ($page) {
1293 View Code Duplication
        case 'register':
0 ignored issues
show
Duplication introduced by
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.

Loading history...
1294
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.colorbox.js');
1295
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.validate.js');
1296
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.validation.functions.js');
1297
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.stepy.js');
1298
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.elastic.source.js');
1299
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/smallworld.css');
1300
            break;
1301 View Code Duplication
        case 'publicindex':
0 ignored issues
show
Duplication introduced by
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.

Loading history...
1302
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.oembed.js');
1303
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.elastic.source.js');
1304
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/wall.js');
1305
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/ajaxupload.3.5.js');
1306
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.avatar_helper.js');
1307
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.bookmark.js');
1308
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/oembed.css');
1309
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.colorbox.js');
1310
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/smallworld.css');
1311
            break;
1312 View Code Duplication
        case 'permalink':
0 ignored issues
show
Duplication introduced by
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.

Loading history...
1313
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.oembed.js');
1314
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/wall.js');
1315
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/oembed.css');
1316
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/smallworld.css');
1317
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.innerfade.js');
1318
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.elastic.source.js');
1319
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.bookmark.js');
1320
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.colorbox.js');
1321
            break;
1322 View Code Duplication
        case 'index':
0 ignored issues
show
Duplication introduced by
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.

Loading history...
1323
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.oembed.js');
1324
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.elastic.source.js');
1325
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/wall.js');
1326
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/ajaxupload.3.5.js');
1327
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.avatar_helper.js');
1328
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.bookmark.js');
1329
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/oembed.css');
1330
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.colorbox.js');
1331
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/tag-it.js');
1332
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/smallworld.css');
1333
            break;
1334
        case 'img_upload':
1335
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/uploader/bootstrap.min.css');
1336
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/uploader/style.css');
1337
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/uploader/bootstrap-responsive.min.css');
1338
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/uploader/bootstrap-image-gallery.min.css');
1339
1340
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/vendor/jquery.ui.widget.js');
1341
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/uploader/tmpl.js');
1342
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/uploader/load-image.js');
1343
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/uploader/canvas-to-blob.js');
1344
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/uploader/bootstrap.js');
1345
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/uploader/bootstrap-image-gallery.js');
1346
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.iframe-transport.js');
1347
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.fileupload.js');
1348
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.fileupload-fp.js');
1349
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.fileupload-ui.js');
1350
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/main.js');
1351
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.colorbox.js');
1352
            break;
1353 View Code Duplication
        case 'galleryshow':
0 ignored issues
show
Duplication introduced by
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.

Loading history...
1354
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/galleriffic-5.css');
1355
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.galleriffic.js');
1356
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.history.js');
1357
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.opacityrollover.js');
1358
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/gallery_mod.js');
1359
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.innerfade.js');
1360
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.colorbox.js');
1361
            break;
1362 View Code Duplication
        case 'friends':
0 ignored issues
show
Duplication introduced by
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.

Loading history...
1363
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/apprise-1.5.full.js');
1364
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/jquery.fileupload-ui.css');
1365
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/oembed.css');
1366
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.oembed.js');
1367
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/wall.js');
1368
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/ajaxupload.3.5.js');
1369
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.avatar_helper.js');
1370
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.innerfade.js');
1371
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.colorbox.js');
1372
            //$xoTheme->addStylesheet(XOOPS_URL.'/modules/smallworld/assets/css/colorbox.css');
1373
            break;
1374 View Code Duplication
        case 'editprofile':
0 ignored issues
show
Duplication introduced by
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.

Loading history...
1375
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.colorbox.js');
1376
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.validate.js');
1377
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.validation.functions.js');
1378
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.stepy.js');
1379
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.elastic.source.js');
1380
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/smallworld.css');
1381
            break;
1382 View Code Duplication
        case 'smallworldshare':
0 ignored issues
show
Duplication introduced by
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.

Loading history...
1383
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.oembed.js');
1384
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/wall.js');
1385
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.innerfade.js');
1386
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/assets/js/jquery.bookmark.js');
1387
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/oembed.css');
1388
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/smallworld.css');
1389
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/js/jquery.colorbox.js');
1390
            break;
1391
        case 'userprofile':
1392
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/js/apprise-1.5.full.js');
1393
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/jquery.fileupload-ui.css');
1394
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/oembed.css');
1395
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/js/jquery.oembed.js');
1396
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/js/wall.js');
1397
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/js/ajaxupload.3.5.js');
1398
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/js/jquery.avatar_helper.js');
1399
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/js/jquery.bookmark.js');
1400
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/js/jquery.colorbox.js');
1401
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/js/jquery.elastic.source.js');
1402
            $xoTheme->addScript(XOOPS_URL . '/modules/smallworld/js/jquery.countdown.js');
1403
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/smallworld/assets/css/smallworld.css');
1404
            break;
1405
    }
1406
}
1407
1408
/**
1409
 * Check if permission is set for userid to post publicly
1410
 * @return array
1411
 */
1412
function smallworld_checkUserPubPostPerm()
1413
{
1414
    global $xoopsUser, $xoopsModule;
1415
    $check      = new Smallworld\User();
1416
    $UserPerPub = smallworld_GetModuleOption('smallworldshowPoPubPage');
1417
    $allUsers   = $check->allUsers();
0 ignored issues
show
Unused Code introduced by
$allUsers 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 $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.

Loading history...
1418
    if (0 != $UserPerPub[0]) {
1419
        $pub = $UserPerPub;
1420
    } else {
1421
        $pub = $check->allUsers();
1422
    }
1423
1424
    return $pub;
1425
}
1426
1427
/**
1428
 * Change @username to urls
1429
 * @param string|null $status_text
1430
 * @return string $status_text
1431
 */
1432
function linkify_twitter_status($status_text)
1433
{
1434
    // linkify twitter users
1435
    //$keywords = preg_split("/[\s,]+/", "hypertext language, programming");
1436
    $status_text = preg_replace('/(^|\s)@(\w+)/', '\1<a href="' . XOOPS_URL . '/modules/smallworld/userprofile.php?username=\2">' . '@\2</a> ', $status_text);
1437
1438
    return $status_text;
1439
}
1440
1441
/**
1442
 * Extract users from @tags
1443
 * @param $name
1444
 * @return array @users
1445
 */
1446 View Code Duplication
function smallworld_getUidFromName($name)
0 ignored issues
show
Duplication introduced by
This function 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.

Loading history...
1447
{
1448
    global $xoopsDB;
1449
    $sql    = 'SELECT userid FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE username = '" . $name . "'";
1450
    $result = $xoopsDB->queryF($sql);
1451
    while (false !== ($r = $xoopsDB->fetchArray($result))) {
1452
        $id = $r['userid'];
1453
    }
1454
1455
    return $id;
0 ignored issues
show
Bug introduced by
The variable $id 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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1456
}
1457
1458
/**
1459
 * Extract users from @tags
1460
 * @param        $txt
1461
 * @param        $sender
1462
 * @param string $permalink
1463
 * @throws \phpmailerException
1464
 */
1465
function smallworld_getTagUsers($txt, $sender, $permalink = '')
1466
{
1467
    $dBase = new Smallworld\SwDatabase();
1468
    $mail  = new Smallworld\Mail();
1469
    preg_match_all('/@([a-zA-Z0-9]+|\\[[a-zA-Z0-9]+\\])/', $txt, $matches);
1470
    $users = array_unique($matches[1]);
1471
    foreach ($users as $user) {
1472
        $uid    = smallworld_getUidFromName($user);
1473
        $notify = json_decode($dBase->getSettings($uid), true);
1474
        if (isset($notify['notify'])) {
1475
            if (0 != $notify['notify']) {
1476
                $mail->sendMails($sender, $uid, 'tag', $link = $permalink, [$txt]);
1477
            }
1478
        }
1479
    }
1480
}
1481
1482
/**
1483
 * Function to get count of messages in wall
1484
 * @param int $uid
1485
 * @return int $count
1486
 */
1487
function smallworld_countUserWallMsges($uid)
1488
{
1489
    $db     = \XoopsDatabaseFactory::getDatabaseConnection();
1490
    $sql    = 'SELECT message FROM ' . $db->prefix('smallworld_messages') . " WHERE uid_fk='" . $uid . "'";
1491
    $result = $db->queryF($sql);
1492
    $count  = $db->getRowsNum($result);
1493
1494
    return $count;
1495
}
1496