Completed
Push — master ( 3a75d1...df92f9 )
by
unknown
01:39
created

include/functions.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

Code
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
 * @package      \XoopsModules\Smallworld
16
 * @license      GNU GPL (https://www.gnu.org/licenses/gpl-2.0.html/)
17
 * @copyright    The XOOPS Project (https://xoops.org)
18
 * @copyright    2011 Culex
19
 * @author       Michael Albertsen (http://culex.dk) <[email protected]>
20
 * @link         https://github.com/XoopsModules25x/smallworld
21
 * @since        1.0
22
 */
23
24
use Xmf\FilterInput;
25
use XoopsModules\Smallworld;
26
use XoopsModules\Smallworld\Constants;
27
use XoopsModules\Smallworld\Helper;
28
29
//require_once __DIR__ . '/common.php';
30
include dirname(__DIR__) . '/preloads/autoloader.php';
31
32
/**
33
 * Get array of timestamps based on the timetype configured in preferences
34
 *
35
 * @return array
36
 */
37
function SmallworldGetTimestampsToForm()
38
{
39
    $timearray = []; // init time array
40
    $end       = date('Y');
41
    $start     = $end - 120; // set to 120 years ago
42
    for ($i = $start; $i <= $end; ++$i) {
43
        $timearray[$i] = $i;
44
    }
45
    ksort($timearray);
46
47
    return $timearray;
48
}
49
50
/**
51
 * Clean vars or arrays
52
 *
53
 * If array check for magicQuotes.
54
 * Pass string to XoopsModules\Smallworld\MyFunctions\cleanupString function
55
 *
56
 * @param array|string $text
57
 * @return array|mixed
58
 */
59
function smallworld_cleanup($text)
60
{
61
    if (is_array($text)) {
62
        foreach ($text as $key => $value) {
63
            $text[$key] = smallworld_cleanup_string($value);
64
        }
65
    } else {
66
        $text = smallworld_cleanup_string($text);
67
    }
68
69
    return $text;
70
}
71
72
/**
73
 * Sanitize string
74
 *
75
 * @param $text
76
 * @return mixed
77
 */
78
function smallworld_cleanup_string($text)
79
{
80
    /** @var \MyTextSanitizer $myts */
81
    $myts = \MyTextSanitizer::getInstance();
82
    $text = $myts->displayTarea($text, $html = 1, $smiley = 1, $xcode = 1, $image = 1, $br = 1);
83
84
    return $text;
85
}
86
87
/**
88
 * Clean Array for mysql insertion
89
 *
90
 * @param string|array $text
91
 * @return string|array
92
 */
93
function smallworld_sanitize($text)
94
{
95
    $retVal = [];
96
    if (is_array($text) && 0 < count($text)) {
97
        foreach ($text as $key => $value) {
98
            $retVal[$key] = smallworld_sanitize_string($value);
99
        }
100
    } else {
101
        $retVal = smallworld_sanitize_string($text);
102
    }
103
104
    return $retVal;
105
}
106
107
/**
108
 * Santize string for insert into dB
109
 *
110
 * @param $value
111
 * @return mixed
112
 */
113
function smallworld_sanitize_string($value)
114
{
115
    return $GLOBALS['xoopsDB']->escape($value);
116
}
117
118
/**
119
 * @deprecated
120
 *
121
 * @param $array
122
 * @return array
123
 */
124
function smallworld_DateOfArray($array)
125
{
126
    $data = [];
127
    foreach ($array as $k => $v) {
128
        $data[$k] = strtotime($v);
129
    }
130
131
    return $data;
132
}
133
134
/**
135
 * YearOfArray
136
 *
137
 * @todo - figure out what this is suppose to do,
138
 * currently it doesn't really do anything.
139
 *
140
 * @param $array
141
 * @return array
142
 */
143
function smallworld_YearOfArray($array)
144
{
145
    $data = [];
146
    foreach ($array as $k => $v) {
147
        $data[$k] = $v;
148
    }
149
150
    return $data;
151
}
152
153
/**
154
 * Create an index file in
155
 *
156
 * @deprecated - no longer used
157
 * @param $folderUrl
158
 */
159
function smallworld_CreateIndexFiles($folder)
160
{
161
    file_put_contents($folder . 'index.html', '<script>history.go(-1);</script>');
162
}
163
164
/**
165
 * @deprecated
166
 * @param string $glue
167
 * @param array  $pieces
168
 * @return string
169
 */
170
function smallworld_ImplodeArray($glue, $pieces)
171
{
172
    return implode($glue, $pieces);
173
}
174
175
/** Recursively reduces deep arrays to single-dimensional arrays
176
 *
177
 * $preserve_keys: (0=>never, 1=>strings, 2=>always)
178
 *
179
 * @param       $array
180
 * @param int   $preserve_keys
181
 * @param array $newArray
182
 * @return array
183
 */
184
function smallworld_array_flatten($array, $preserve_keys = 1, &$newArray = [])
185
{
186
    foreach ($array as $key => $child) {
187
        if (is_array($child)) {
188
            $newArray = smallworld_array_flatten($child, $preserve_keys, $newArray);
189
        } elseif ($preserve_keys + is_string($key) > 1) {
190
            $newArray[$key] = $child;
191
        } else {
192
            $newArray[] = $child;
193
        }
194
    }
195
196
    return $newArray;
197
}
198
199
/*
200
 * Calculate years from date format (YYYY-MM-DD)
201
 *
202
 * @param string $birth
203
 * @return int
204
 */
205
function smallworld_Birthday($birth)
206
{
207
    list($year, $month, $day) = explode('-', $birth);
208
    $yearDiff  = date('Y') - $year;
209
    $monthDiff = date('m') - $month;
210
    $dayDiff   = date('d') - $day;
211
    if (0 == $monthDiff) {
212
        if ($dayDiff < 0) {
213
            $yearDiff--;
214
        }
215
    }
216
    if ($monthDiff < 0) {
217
        $yearDiff--;
218
    }
219
220
    return $yearDiff;
221
}
222
223
/**
224
 * Get SW userid from username
225
 *
226
 * @deprecated - use Smallworld\SwUserHandler::getByName() method instead
227
 * @param $check
228
 * @return bool|int
229
 */
230
function smallworld_isset_or($check)
231
{
232
    $depMsg = __FUNCTION__ . " is deprecated, use SwUserHandler::getByName() instead";
233 View Code Duplication
    if (isset($GLOBALS['xoopsLogger'])) {
234
        $GLOBALS['xoopsLogger']->addDeprecated($depMsg);
235
    } else {
236
        trigger_error($depMsg, E_USER_WARNING);
237
    }
238
    $query  = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . " WHERE username = '" . $check . "' LIMIT 1";
239
    $result = $GLOBALS['xoopsDB']->queryF($query);
240
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
241
        if ('' == $row['userid']) {
242
            return false;
243
        }
244
245
        return $row['userid'];
246
    }
247
}
248
249
//Srinivas Tamada http://9lessons.info
250
//Loading Comments link with load_updates.php
251
/**
252
 * @param $session_time
253
 * @return string
254
 */
255
function smallworld_time_stamp($session_time)
256
{
257
    $time_difference = time() - $session_time;
258
    $seconds         = $time_difference;
259
    $minutes         = round($time_difference / 60);
260
    $hours           = round($time_difference / 3600);
261
    $days            = round($time_difference / 86400);
262
    $weeks           = round($time_difference / 604800);
263
    $months          = round($time_difference / 2419200);
264
    $years           = round($time_difference / 29030400);
265
    if ($seconds <= 60) {
266
        $t = (string)$seconds . _SMALLWORLD_SECONDSAGO;
267
    } elseif ($minutes <= 60) {
268
        if (1 == $minutes) {
269
            $t = _SMALLWORLD_ONEMINUTEAGO;
270
        } else {
271
            $t = (string)$minutes . _SMALLWORLD_MINUTESAGO;
272
        }
273
    } elseif ($hours <= 24) {
274
        if (1 == $hours) {
275
            $t = _SMALLWORLD_ONEHOURAGO;
276
        } else {
277
            $t = (string)$hours . _SMALLWORLD_HOURSAGO;
278
        }
279
    } elseif ($days <= 7) {
280
        if (1 == $days) {
281
            $t = _SMALLWORLD_ONEDAYAGO;
282
        } else {
283
            $t = (string)$days . _SMALLWORLD_DAYSAGO;
284
        }
285
    } elseif ($weeks <= 4) {
286
        if (1 == $weeks) {
287
            $t = _SMALLWORLD_ONEWEEKAGO;
288
        } else {
289
            $t = (string)$weeks . _SMALLWORLD_WEEKSAGO;
290
        }
291
    } elseif ($months <= 12) {
292
        if (1 == $months) {
293
            $t = _SMALLWORLD_ONEMONTHAGO;
294
        } else {
295
            $t = (string)$months . _SMALLWORLD_MONTHSAGO;
296
        }
297
    } else {
298
        if (1 == $years) {
299
            $t = _SMALLWORLD_ONEYEARAGO;
300
        } else {
301
            $t = (string)$years . _SMALLWORLD_YEARSAGO;
302
        }
303
    }
304
305
    return $t;
306
}
307
308
/**
309
 * Return only url/link
310
 *
311
 * if url is image link return <img>
312
 *
313
 * @param string $text
314
 * @param int $uid user id
315
 * @return string
316
 */
317
function smallworld_tolink($text, $uid)
318
{
319
	$helper = Helper::getInstance();
320
    $ext        = mb_substr($text, -4, 4);
321
    $ext2       = mb_substr($text, -5, 5);
322
    $xUser      = new \XoopsUser($uid);
323
    $xUserUname = $xUser->uname();
324
    $gallery    = $helper->url('galleryshow.php?username=' . $xUserUname);
325
326
    if (in_array(strtolower($ext), ['.jpg', '.bmp', '.gif', '.png']) || in_array(strtolower($ext2), ['.jpeg'])) {
327
        if (false !== mb_strpos($text, 'UPLIMAGE')) {
328
            $text = str_replace('UPLIMAGE', '', $text);
329
            $text = preg_replace(
330
                '/(((f|ht){1}tps?:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
331
                '<span class="smallworldUplImgTxt"><br><img class="smallworldAttImg" src="\\1"><br><br><a id="smallworldUplImgLnk" href="' . $gallery . '" target="_SELF">' . $xUserUname . _SMALLWORLD_UPLOADEDSOMEIMAGES . '</a><br></span>',
332
                $text
333
            );
334
            //$text = preg_replace('/(((f|ht){1}tps:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', '<a href="\\1">lala</a>', $text);
335
            $text = preg_replace(
336
                '/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
337
                '\\1<span class="smallworldUplImgTxt"><br><img class="smallworldAttImg" src="//\\2"><br><br><a id="smallworldUplImgLnk" href="' . $gallery . '" target="_SELF">' . $xUserUname . _SMALLWORLD_UPLOADEDSOMEIMAGES . '</a><br></span>',
338
                $text
339
            );
340
            $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
341
        } else {
342
            $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);
343
            $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);
344
            $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);
345
            $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
346
        }
347
    } else {
348
        $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
349
        $text = ' ' . $text;
350
        $text = str_replace('UPLIMAGE', '', $text);
351
    }
352
353
    return linkify_twitter_status($text);
354
}
355
356
/**
357
 * @param $text
358
 * @return mixed
359
 */
360
function smallworld_stripWordsKeepUrl($text)
361
{
362
    preg_replace('/(((f|ht){1}tps:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', '<div class=".embed"><a href="\\1">\\1</a></div>', $text);
363
364
    return $text;
365
}
366
367
/**
368
 * Get social image and link HTML
369
 *
370
 * @param int $num
371
 * @param string $name
372
 * @return string
373
 */
374
function smallworld_sociallinks($num, $name)
375
{
376
    /** @var \XoopsModules\Smallworld\Helper $helper */
377
    $helper = Helper::getInstance();
378
    switch ($num) {
379 View Code Duplication
        case 0:
380
            $image = '<img title="Msn" id="Smallworld_socialnetworkimg" src="' . $helper->url('assets/images/socialnetworkicons/msn.png') . '">';
381
            $link  = '<a title="Msn" id="Smallworld_socialnetwork" target="_blank" href="http://members.msn.com/' . $name . '">';
382
            break;
383 View Code Duplication
        case 1:
384
            $image = '<img title="facebook" id="Smallworld_socialnetworkimg" src="' . $helper->url('assets/images/socialnetworkicons/facebook.png') . '">';
385
            $link  = '<a title="facebook" id="Smallworld_socialnetwork" target="_blank" href="http://www.facebook.com/' . $name . '">';
386
            break;
387 View Code Duplication
        case 2:
388
            $image = '<img title="GooglePlus" id="Smallworld_socialnetworkimg" src="' . $helper->url('assets/images/socialnetworkicons/googleplus.png') . '">';
389
            $link  = '<a title="GooglePlus" id="Smallworld_socialnetwork" target="_blank" href="https://plus.google.com/' . $name . '">';
390
            break;
391 View Code Duplication
        case 3:
392
            $image = '<img title="icq" id="Smallworld_socialnetworkimg" src="' . $helper->url('assets/images/socialnetworkicons/icq.png') . '">';
393
            $link  = '<a title="icq" id="Smallworld_socialnetwork" target="_blank" href="http://www.icq.com/people/' . $name . '/">';
394
            break;
395 View Code Duplication
        case 4:
396
            $image = '<img title="Skype" id="Smallworld_socialnetworkimg" src="' . $helper->url('assets/images/socialnetworkicons/skype.png') . '">';
397
            $link  = '<a title="Skype" id="Smallworld_socialnetwork" target="_blank" href="skype:' . $name . '?userinfo">';
398
            break;
399 View Code Duplication
        case 5:
400
            $image = '<img title="Twitter" id="Smallworld_socialnetworkimg" src="' . $helper->url('assets/images/socialnetworkicons/twitter.png') . '">';
401
            $link  = '<a title="Twitter" id="Smallworld_socialnetwork" target="_blank" href="http://twitter.com/#!/' . $name . '">';
402
            break;
403 View Code Duplication
        case 6:
404
            $image = '<img title="MySpace" id="Smallworld_socialnetworkimg" src="' . $helper->url('assets/images/socialnetworkicons/myspace.png') . '">';
405
            $link  = '<a title="MySpace" id="Smallworld_socialnetwork" target="_blank" href="http://www.myspace.com/' . $name . '">';
406
            break;
407 View Code Duplication
        case 7:
408
            $image = '<img title="XOOPS" id="Smallworld_socialnetworkimg" src="' . $helper->url('assets/images/socialnetworkicons/xoops.png') . '">';
409
            $link  = '<a title="XOOPS" id="Smallworld_socialnetwork" target="_blank" href="https://xoops.org/modules/profile/userinfo.php?uid=' . $name . '">';
410
            break;
411 View Code Duplication
        case 8:
412
            $image = '<img title="Yahoo Messenger" id="Smallworld_socialnetworkimg" src="' . $helper->url('assets/images/socialnetworkicons/yahoo.png') . '">';
413
            $link  = '<a title="Yahoo Messenger" id="Smallworld_socialnetwork" target="_blank" href="ymsgr:sendim?' . $name . '">';
414
            break;
415 View Code Duplication
        case 9:
416
            $image = '<img title="Youtube" id="Smallworld_socialnetworkimg" src="' . $helper->url('assets/images/socialnetworkicons/youtube.png') . '">';
417
            $link  = '<a title="Youtube" id="Smallworld_socialnetwork" target="_blank" href="http://www.youtube.com/user/' . $name . '">';
418
            break;
419
    }
420
421
    return $image . $link;
422
}
423
424
/**
425
 * @param string $option name of config option to read
426
 * @param string $repmodule name of module
427
 * @param bool   $flushFirst true causes configs to be loaded again, false read from cache
428
 * @return bool|mixed
429
 */
430
function smallworld_GetModuleOption($option = null, $repmodule = 'smallworld', $flushFirst = false)
431
{
432
    static $modOptions = [];
433
    if ($flushFirst) { // clears the 'cache', forces reload of configs
434
        $modOptions = [];
435
    }
436
    if (!array_key_exists($repmodule, $modOptions)) {
437
        //this module's options aren't set
438
        $modHelper = Helper::getInstance()->getHelper($repmodule);
439
        if (!$modHelper instanceof \Xmf\Module\Helper) { // check to see if module is installed & active
440
            return null;
441
        }
442
        // first time to get configs for this module so read them all into an array
443
        $modOptions[$repmodule] = $modHelper->getConfig();
444
        // now return the specific config/option requested
445 View Code Duplication
        if (null == $option) { // return the array if no specific option was requested
446
            return $modOptions[$repmodule];
447
        } elseif (isset($modOptions[$repmodule][$option])) {
448
            return $modOptions[$repmodule][$option];
449
        } else {
450
            return null;
451
        }
452 View Code Duplication
    } else {
453
        // module options are in 'cache' so see if the one requested is valid
454
        if (null == $option) { // return the array if no specific option was requested
455
            return $modOptions[$repmodule];
456
        } elseif (isset($modOptions[$repmodule][$option])) {
457
            return $modOptions[$repmodule][$option];
458
        } else {
459
            return null;
460
        }
461
    }
462
463
    return null;
464
/*
465
    static $tbloptions = [];
466
    if (is_array($tbloptions) && array_key_exists($option, $tbloptions)) {
467
        return $tbloptions[$option];
468
    }
469
    $retval = false;
470
    if (isset($GLOBALS['xoopsModuleConfig']) && (is_object($GLOBALS['xoopsModule']) && $GLOBALS['xoopsModule']->getVar('dirname') == $repmodule && $GLOBALS['xoopsModule']->getVar('isactive'))) {
471
        if (isset($GLOBALS['xoopsModuleConfig'][$option])) {
472
            $retval = $GLOBALS['xoopsModuleConfig'][$option];
473
        }
474
    } else {
475
        $moduleHandler = xoops_getHandler('module');
476
        $module        = $moduleHandler->getByDirname($repmodule);
477
        $configHandler = xoops_getHandler('config');
478
        if ($module) {
479
            $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
480
            if (isset($moduleConfig[$option])) {
481
                $retval = $moduleConfig[$option];
482
            }
483
        }
484
    }
485
    $tbloptions[$option] = $retval;
486
487
    return $retval;
488
    */
489
}
490
491
/**
492
 * Check image extension and users gender.
493
 *
494
 * If image is legal image extension return avatar, else return default gender based image
495
 * @deprecated
496
 * @param int    $userid
497
 * @param string $image
498
 * @return string
499
 */
500
function smallworld_getAvatarLink($userid, $image)
501
{
502
    $depMsg = __FUNCTION__ . " is deprecated use SwUserHandler::getAvatarLink() instead.";
503 View Code Duplication
    if (isset($GLOBALS['xoopsLogger'])) {
504
        $GLOBALS['xoopsLogger']->addDeprecated($depMsg);
505
    } else {
506
        trigger_error($depMsg, E_USER_WARNING);
507
    }
508
    $ext     = pathinfo(mb_strtolower($image), PATHINFO_EXTENSION);
509
    $sql     = 'SELECT gender FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . " WHERE userid = '" . (int)$userid . "'";
510
    $result  = $GLOBALS['xoopsDB']->queryF($sql);
511
    //$counter = $GLOBALS['xoopsDB']->getRowsNum($result);
512
    $gender  = Constants::GENDER_UNKNOWN;
513
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
514
        $gender = $row['gender'];
515
    }
516
517
    if (preg_match('/avatars/i', $image)) {
518
        $link = XOOPS_UPLOAD_URL . '/' . $image;
519
    } else {
520
        $link = $image;
521
    }
522
523 View Code Duplication
    if (in_array($ext, ['jpg', 'bmp', 'gif', 'png', 'jpeg']) || '' == $image || 'blank.gif' == $image) {
524
        switch ($gender) {
525
            case Constants::FEMALE:
526
                $pict = 'ano_woman.png';
527
                break;
528
            case Constants::MALE:
529
                $pict = 'ano_man.png';
530
                break;
531
            case Constants::GENDER_UNKNOWN:
532
            default:
533
                $pict = 'genderless.png';
534
                break;
535
        }
536
        $link = Helper::getInstance()->url("assets/images/{$pict}");
537
    }
538
539
    return $link;
540
}
541
542
/**
543
 * Check if Xim module is installed and active
544
 *
545
 * @return bool
546
 */
547
function smallworld_checkForXim()
548
{
549
    $ximHelper = Helper::getInstance()->getHelper('xim');
550
551
    return ($ximHelper instanceof \Xmf\Module\Helper) ? true : false;
552
    /*
553
    $filename = XOOPS_ROOT_PATH . '/modules/xim/chat.php';
554
    if (file_exists($filename)) {
555
        return true;
556
    }
557
558
    return false;
559
    */
560
}
561
562
/**
563
 * Get version number of xim module if exists
564
 *
565
 * @return int $version returns 0 if not found
566
 */
567
function smallworld_XIMversion()
568
{
569
    $version   = 0; // init version var
570
    $ximHelper = Helper::getInstance()->getHelper('xim');
571
    if ($ximHelper instanceof \Xmf\Module\Helper) {
572
        $version = $ximHelper->getModule()->version();
573
    }
574
    /*
575
    $sql    = 'SELECT version FROM ' . $GLOBALS['xoopsDB']->prefix('modules') . " WHERE dirname = 'xim'";
576
    $result = $GLOBALS['xoopsDB']->queryF($sql);
577
    if ($GLOBALS['xoopsDB']->getRowsNum($result) > 0) {
578
        while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
579
            $version = $r['version'];
580
        }
581
    } else {
582
        $version = 0;
583
    }
584
    */
585
    return $version;
586
}
587
588
/**
589
* Input: Message Id,
590
*
591
* Return owner of thread (original poster)
592
* Return Integer
593
*/
594
/**
595
 * @param $msg_id_fk
596
 * @return bool|int false if not found, integer of uid otherwise
597
 */
598 View Code Duplication
function smallworld_getOwnerFromComment($msg_id_fk)
599
{
600
    $owner = false;
601
    /** @todo looks like this should have LIMIT set to 1 to reduce execution time & possible ambiguity */
602
    $sql    = 'SELECT uid_fk FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_messages') . " WHERE msg_id = '" . $msg_id_fk . "'";
603
    $result = $GLOBALS['xoopsDB']->queryF($sql);
604
    while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
605
        $owner = $r['uid_fk'];
606
    }
607
608
    return $owner;
609
}
610
611
/**
612
 * Get username from userID
613
 *
614
 * @deprecated - moved to SwUserHandler::getName() method
615
 * @param $userID
616
 * @return array
617
 */
618
function smallworld_getName($userID)
619
{
620
    $depMsg = __FUNCTION__ . " is deprecated, use SwUserHandler::getName() instead";
621 View Code Duplication
    if (isset($GLOBALS['xoopsLogger'])) {
622
        $GLOBALS['xoopsLogger']->addDeprecated($depMsg);
623
    } else {
624
        trigger_error($depMsg, E_USER_WARNING);
625
    }
626
627
    $name = [];
628
    $sql    = 'SELECT username FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . " WHERE userid = '" . (int)$userID . "'";
629
    $result = $GLOBALS['xoopsDB']->queryF($sql);
630
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
631
        $name = $row['username'];
632
    }
633
634
    return $name;
635
}
636
637
/**
638
 * Check if user has been taken down for inspection by admin
639
 *
640
 * @param int $userid user to check
641
 * @return array
642
 */
643
function smallworld_isInspected($userid)
644
{
645
    $data   = [];
646
    $sql    = 'SELECT inspect_start, inspect_stop FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_admin') . " WHERE userid = '" . (int)$userid . "' AND (inspect_start+inspect_stop) > " . time() . '';
647
    $result = $GLOBALS['xoopsDB']->queryF($sql);
648
    if ($GLOBALS['xoopsDB']->getRowsNum($result) > 0) {
649
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
650
            $data['inspect']   = 'yes';
651
            $data['totaltime'] = ($row['inspect_start'] + $row['inspect_stop']) - time();
652
        }
653
    } else {
654
        $data['inspect'] = 'no';
655
    }
656
657
    return $data;
658
}
659
660
/**
661
 * Auto delete all inspects from DB where time has passed
662
 *
663
 * inspect_start + inspect_stop - time() is deleted if negative intval
664
 *
665
 * @return bool
666
 */
667 View Code Duplication
function SmallworldDeleteOldInspects()
668
{
669
    $sql    = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('smallworld_admin') . " SET inspect_start = '', inspect_stop = '' WHERE (inspect_start+inspect_stop) <= " . time() . '';
670
    $result = $GLOBALS['xoopsDB']->queryF($sql);
671
672
    return ($result) ? true : false;
673
}
674
675
/**
676
 * Function to get sum of users in your following array
677
 *
678
 * Used to calculate new message flash in jQuery intval fetch
679
 *
680
 * @return int
681
 */
682
function smallworld_getCountFriendMessagesEtc()
683
{
684
    $total     = 0;
685
    $wall      = new Smallworld\WallUpdates();
686
    $userid    = $GLOBALS['xoopsUser']->uid();
687
    $followers = smallworld_array_flatten($wall->getFollowers($userid), 0);
688
    if (1 == Helper::getInstance()->getConfig('usersownpostscount')) {
689
        $followers[] = $userid;
690
    }
691
    if (0 < count($followers)) {
692
        $ids    = implode(',', $followers);
693
        $sql    = 'SELECT COUNT(*) AS total '
694
                  . ' FROM ( '
695
                  . ' SELECT com_id , COUNT( * ) AS comments FROM '
696
                  . $GLOBALS['xoopsDB']->prefix('smallworld_comments')
697
                  . " WHERE uid_fk IN ($ids) GROUP BY com_id "
698
                  . ' UNION ALL '
699
                  . ' SELECT msg_id , COUNT( * ) AS messages FROM '
700
                  . $GLOBALS['xoopsDB']->prefix('smallworld_messages')
701
                  . " WHERE uid_fk IN ($ids) GROUP BY msg_id "
702
                  . ' ) as d';
703
        $result = $GLOBALS['xoopsDB']->queryF($sql);
704
        while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
705
            $total = $r['total'];
706
        }
707
    }
708
709
    return (int)$total;
710
}
711
712
/**
713
 * Function to get sum of users in you following array
714
 *
715
 * Used to calculate new message flash in jQuery intval fetch
716
 *
717
 *@ deprecated - not used
718
 * @param $id
719
 * @return mixed
720
 */
721
function smallworld_countUsersMessages($id)
722
{
723
    $id     = int($id);
724
    $total  = 0;
725
    if (0 < $id ) {
726
        $sql    = 'SELECT COUNT(*) AS total '
727
                . ' FROM ( ' . ' SELECT com_id , COUNT( * ) AS comments FROM '
728
                . $GLOBALS['xoopsDB']->prefix('smallworld_comments')
729
                . ' WHERE uid_fk = ' . (int)$id
730
                . ' GROUP BY com_id ' . ' UNION ALL '
731
                . ' SELECT msg_id , COUNT( * ) AS messages FROM '
732
                . $GLOBALS['xoopsDB']->prefix('smallworld_messages')
733
                . ' WHERE uid_fk = ' . (int)$id . 'group BY msg_id ' . ' ) AS d';
734
        $result = $GLOBALS['xoopsDB']->queryF($sql);
735
        while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
736
            $total = $r['total'];
737
        }
738
    }
739
740
    return $total;
741
}
742
743
/**
744
 * Get the three newest members to array
745
 *
746
 * @deprecated - no longer used
747
 * @return array
748
 */
749
function smallworld_Stats_newest()
750
{
751
    $depMsg = __FUNCTION__ . " is deprecated";
752 View Code Duplication
    if (isset($GLOBALS['xoopsLogger'])) {
753
        $GLOBALS['xoopsLogger']->addDeprecated($depMsg);
754
    } else {
755
        trigger_error($depMsg, E_USER_WARNING);
756
    }
757
    $swUserHandler = Helper::getInstance()->getHandler('SwUser');
758
    $nu     = [];
759
    $sql    = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . ' ORDER BY regdate DESC LIMIT 3';
760
    $result = $GLOBALS['xoopsDB']->queryF($sql);
761
    if ($GLOBALS['xoopsDB']->getRowsNum($result) > 0) {
762
        $i = 0;
763
        while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
764
            $nu[$i]['userid']         = $r['userid'];
765
            $nu[$i]['username']       = $r['username'];
766
            $nu[$i]['regdate']        = date('d-m-Y', $r['regdate']);
767
            $nu[$i]['username_link']  = "<a href = '" . $helper->url('userprofile.php?username=' . $r['username']) . "'>";
768
            $nu[$i]['username_link']  .= $r['username'] . ' (' . $r['realname'] . ') [' . $nu[$i]['regdate'] . '] </a>';
769
            $nu[$i]['userimage']      = $r['userimage'];
770
            $nu[$i]['userimage_link'] = $swUserHandler->getAvatarLink($r['userid'], $swUserHandler->gravatar($r['userid']));
771
            ++$i;
772
        }
773
    }
774
775
    return $nu;
776
}
777
778
//Avatar Image
779
/**
780
 * @deprecated - use Smallworld\SwUserHandler::gravatar()
781
 * @param $uid
782
 * @return string
783
 */
784
function smallworld_Gravatar($uid)
785
{
786
    $depMsg = __FUNCTION__ . " is deprecated use SwUserHandler::gravatar() instead.";
787 View Code Duplication
    if (isset($GLOBALS['xoopsLogger'])) {
788
        $GLOBALS['xoopsLogger']->addDeprecated($depMsg);
789
    } else {
790
        trigger_error($depMsg, E_USER_WARNING);
791
    }
792
    $image  = '';
793
    $sql    = 'SELECT userimage FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . " WHERE userid = '" . (int)$uid . "'";
794
    $result = $GLOBALS['xoopsDB']->queryF($sql);
795
    while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
796
        $image = $r['userimage'];
797
    }
798
799
    $image = ('' == $image || 'blank.gif' === $image) ? smallworld_getAvatarLink($uid, $image) : $image;
800
801
    $type = [
802
        1 => 'jpg',
803
        2 => 'jpeg',
804
        3 => 'png',
805
        4 => 'gif',
806
    ];
807
808
    $ext = explode('.', $image);
809
810
    $avatar = '';
811 View Code Duplication
    if (array_key_exists(1, $ext) && in_array(mb_strtolower($ext[1]), $type)) {
812
        $avatar = '';
813
    }
814
815
    return $avatar;
816
}
817
818
// find user with most posted messages
819
/**
820
 * @return array
821
 */
822
function smallworld_mostactiveusers_allround()
823
{
824
    $msg     = [];
825
    $sql     = 'SELECT uid_fk, COUNT( * ) as cnt ';
826
    $sql     .= 'FROM ( ';
827
    $sql     .= 'SELECT uid_fk ';
828
    $sql     .= 'FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_messages') . ' ';
829
    $sql     .= 'UNION ALL SELECT uid_fk ';
830
    $sql     .= 'FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_comments') . ' ';
831
    $sql     .= ') AS u ';
832
    $sql     .= 'GROUP BY uid_fk ';
833
    $sql     .= 'ORDER BY count( * ) DESC limit 3';
834
    $result  = $GLOBALS['xoopsDB']->queryF($sql);
835
    $counter = $GLOBALS['xoopsDB']->getRowsNum($result);
836
    if ($counter < 1) {
837
    } else {
838
        $helper        = Helper::getInstance();
839
        $swUserHandler = $helper->getHandler('SwUser');
840
        $counter = 1;
841
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
842
            $msg[$counter]['counter']       = $counter;
843
            $msg[$counter]['img']           = $swUserHandler->getAvatarLink($row['uid_fk'], $swUserHandler->gravatar($row['uid_fk']));
844
            $msg[$counter]['msgs']          = _SMALLWORLD_TOTALPOSTS . ' : ' . $row['cnt'];
845
            $msg[$counter]['cnt']           = $row['cnt'];
846
            $msg[$counter]['username']      = $GLOBALS['xoopsUser']->getUnameFromId($row['uid_fk']);
847
            $msg[$counter]['username_link'] = "<a href = '" . $helper->url('userprofile.php?username=' . $msg[$counter]['username']) . "'>";
848
            $msg[$counter]['username_link'] .= $msg[$counter]['username'] . ' (' . $msg[$counter]['msgs'] . ')</a>';
849
            ++$counter;
850
        }
851
    }
852
853
    return $msg;
854
}
855
856
// Find worst rated users overall
857
/**
858
 * @return array
859
 */
860 View Code Duplication
function smallworld_worstratedusers()
861
{
862
    $swUserHandler = Helper::getInstance()->getHandler('SwUser');
863
    $array   = [];
864
    $counter = 1;
865
    $sql     = 'SELECT owner, (';
866
    $sql     .= 'sum( up ) - sum( down )';
867
    $sql     .= ') AS total';
868
    $sql     .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_vote') . '';
869
    $sql     .= ' GROUP BY owner ORDER by total ASC LIMIT 5';
870
    $result  = $GLOBALS['xoopsDB']->queryF($sql);
871
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
872
        $array[$counter]['counter']   = $counter;
873
        $array[$counter]['img']       = $swUserHandler->getAvatarLink($row['owner'], $swUserHandler->gravatar($row['owner']));
874
        $array[$counter]['user']      = $GLOBALS['xoopsUser']->getUnameFromId($row['owner']);
875
        $array[$counter]['rating']    = $row['total'];
876
        $array[$counter]['user_link'] = "<a href = '" . Helper::getInstance()->url('userprofile.php?username=' . $array[$counter]['user']) . "'>";
877
        $array[$counter]['user_link'] .= $array[$counter]['user'] . ' (' . $array[$counter]['rating'] . ')</a>';
878
        ++$counter;
879
    }
880
881
    return $array;
882
}
883
884
// Find best rated users overall
885
/**
886
 * @return array
887
 */
888 View Code Duplication
function smallworld_topratedusers()
889
{
890
    $swUserHandler = Helper::getInstance()->getHandler('SwUser');
891
    $array   = [];
892
    $counter = 1;
893
    $sql     = 'SELECT owner, (';
894
    $sql     .= 'sum( up ) - sum( down )';
895
    $sql     .= ') AS total';
896
    $sql     .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_vote') . '';
897
    $sql     .= ' GROUP BY owner ORDER by total DESC LIMIT 5';
898
    $result  = $GLOBALS['xoopsDB']->queryF($sql);
899
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
900
        $array[$counter]['counter']   = $counter;
901
        $array[$counter]['img']       = $swUserHandler->getAvatarLink($row['owner'], $swUserHandler->gravatar($row['owner']));
902
        $array[$counter]['user']      = $GLOBALS['xoopsUser']->getUnameFromId($row['owner']);
903
        $array[$counter]['rating']    = $row['total'];
904
        $array[$counter]['user_link'] = "<a href = '" . Helper::getInstance()->url('userprofile.php?username=' . $array[$counter]['user']) . "'>";
905
        $array[$counter]['user_link'] .= $array[$counter]['user'] . ' (' . $array[$counter]['rating'] . ')</a>';
906
        ++$counter;
907
    }
908
909
    return $array;
910
}
911
912
/**
913
 * @return array
914
 */
915
function smallworld_nextBirthdays()
916
{
917
    $swUserHandler = Helper::getInstance()->getHandler('SwUser');
918
    $now       = date('d-m');
919
    $res       = [];
920
    $sql       = 'SELECT userid, username, userimage, realname, birthday, CURDATE(),'
921
               . ' DATE_FORMAT(birthday, "%d / %m") AS daymon , '
922
               . ' (YEAR(CURDATE())-YEAR(birthday))'
923
               . ' - (RIGHT(CURDATE(),5)<RIGHT(birthday,5))'
924
               . ' AS age_now'
925
               . ' FROM '
926
               . $GLOBALS['xoopsDB']->prefix('smallworld_user')
927
               . ' WHERE right(birthday,5) = right(CURDATE(),5)'
928
               . ' ORDER BY MONTH( birthday ) , DAY( birthday ) '
929
               . ' LIMIT 10 ';
930
    $result    = $GLOBALS['xoopsDB']->queryF($sql);
931
    $counter   = $GLOBALS['xoopsDB']->getRowsNum($result);
932
    $i         = 0;
933
    while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
934
        $res[$i]['amount']        = $counter;
935
        $res[$i]['userid']        = $r['userid'];
936
        $res[$i]['userimage']     = $swUserHandler->getAvatarLink($r['userid'], $swUserHandler->gravatar($r['userid']));
937
        $res[$i]['birthday']      = $r['daymon'];
938
        $res[$i]['agenow']        = $r['age_now'];
939
        $res[$i]['username']      = $GLOBALS['xoopsUser']->getUnameFromId($r['userid']);
940
        $res[$i]['username_link'] = "<a href = '" . Helper::getInstance()->url('userprofile.php?username=' . $res[$i]['username']) . "'>";
941
        $res[$i]['username_link'] .= $res[$i]['username'] . ' (' . $r['daymon'] . ') ' . $r['age_now'] . ' ' . _SMALLWORLD_BDAY_YEARS;
942
        $res[$i]['username_link'] .= '</a>';
943
        ++$i;
944
    }
945
946
    return $res;
947
}
948
949
/*
950
 * Return date format (YYYY-MM-DD) for MySql
951
 * @param date $stringDate
952
 * $returns date
953
*/
954
/**
955
 * @param $stringDate
956
 * @return string
957
 */
958 View Code Duplication
function smallworld_euroToUsDate($stringDate)
959
{
960
    if (0 != $stringDate || '' != $stringDate) {
961
        $theData = explode('-', trim($stringDate));
962
        $ret     = $theData[2] . '-' . $theData[1] . '-' . $theData[0];
963
964
        return $ret;
965
    }
966
967
    return '1900-01-01';
968
}
969
970
/*
971
 * Return date format (DD-MM-YYYY) for display
972
 * @param date $stringDate
973
 * $returns date
974
*/
975
/**
976
 * @param $stringDate
977
 * @return string
978
 */
979 View Code Duplication
function smallworld_UsToEuroDate($stringDate)
980
{
981
    if (0 != $stringDate || '' != $stringDate) {
982
        $theData = explode('-', trim($stringDate));
983
        $ret     = $theData[2] . '-' . $theData[1] . '-' . $theData[0];
984
985
        return $ret;
986
    }
987
988
    return '01-01-1900';
989
}
990
991
/**
992
 * @return array
993
 */
994
function smallworld_sp()
995
{
996
    $sp = [0 => ['spimage' => "<img id='smallworld_img_sp' src='" . Helper::getInstance()->url('assets/images/sp.png') . "' height='30px' width='30px' >"]];
997
    return $sp;
998
}
999
1000
//Check privacy settings in permapage
1001
/**
1002
 * @param $id
1003
 * @return mixed
1004
 */
1005 View Code Duplication
function smallworldCheckPriv($id)
1006
{
1007
    $public = 'SELECT priv FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_messages') . ' WHERE msg_id = ' . $id . '';
1008
    $result = $GLOBALS['xoopsDB']->queryF($public);
1009
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
1010
        $priv = $row['priv'];
1011
    }
1012
1013
    return $priv;
1014
}
1015
1016
/**
1017
 * Function to calculate remaining seconds until user's birthday
1018
 *
1019
 * Input $d : date('Y-m-d') format
1020
 * return seconds until date at midnight, or
1021
 * return 0 if date ('Y-m-d') is equal to today
1022
 *
1023
 * @param $d
1024
 * @return bool|int|string
1025
 */
1026
function smallworldNextBDaySecs($d)
1027
{
1028
    $olddate   = mb_substr($d, 4);
1029
    $exactdate = date('Y') . '' . $olddate;
1030
    $newdate   = date('Y') . '' . $olddate . ' 00:00:00';
1031
    $nextyear  = date('Y') + 1 . '' . $olddate . ' 00:00:00';
1032
    if ($exactdate != date('Y-m-d')) {
1033
        if ($newdate > date('Y-m-d H:i:s')) {
1034
            $start_ts = strtotime($newdate);
1035
            $end_ts   = strtotime(date('Y-m-d H:i:s'));
1036
            $diff     = $end_ts - $start_ts;
1037
            $n        = round($diff);
1038
            $return   = mb_substr($n, 1);
1039
1040
            return $return;
1041
        }
1042
        $start_ts = strtotime($nextyear);
1043
        $end_ts   = strtotime(date('Y-m-d H:i:s'));
1044
        $diff     = $end_ts - $start_ts;
1045
        $n        = round($diff);
1046
        $return   = mb_substr($n, 1);
1047
1048
        return $return;
1049
    }
1050
1051
    return 0;
1052
}
1053
1054
/**
1055
 * Function to get value from xoopsConfig array
1056
/**
1057
 * @param string $key
1058
 * @param array $array
1059
 * @return int
1060
 */
1061
function smallworldGetValfromArray($key, $array)
1062
{
1063
    $ret = 0;
1064
    $ar  = Helper::getInstance()->getConfig($array);
1065
    if (in_array($key, $ar, true)) {
1066
        $ret = 1;
1067
    }
1068
1069
    return $ret;
1070
}
1071
1072
/**
1073
 * Resize images proportionally
1074
 *
1075
 * Using imagesize($imageurl) returns $img[0], $img[1]
1076
 * Target = new max height or width in px
1077
 *
1078
 * @param int $width
1079
 * @param int $height
1080
 * @param int $target
1081
 * @return string returns the new sizes in html image tag format
1082
 */
1083
function smallworld_imageResize($width, $height, $target)
1084
{
1085
    //takes the larger size of the width and height and applies the
1086
    //formula accordingly...this is so this script will work
1087
    //dynamically with any size image
1088
    if ($width > $height) {
1089
        $percentage = ($target / $width);
1090
    } else {
1091
        $percentage = ($target / $height);
1092
    }
1093
    //gets the new value and applies the percentage, then rounds the value
1094
    $width  = round($width * $percentage);
1095
    $height = round($height * $percentage);
1096
    //returns the new sizes in html image tag format...this is so you
1097
    //can plug this function inside an image tag and just get the
1098
1099
    return "width='{$width}' height='{$height}'";
1100
}
1101
1102
/**
1103
 * Fetch image width and height
1104
 *
1105
 * will attempt to use the getimagesize method first, then curl
1106
 *
1107
 * @param int $w
1108
 * @param int $h
1109
 * @param string $url
1110
 * @returns array
1111
 * @return array
1112
 */
1113
function smallworld_getImageSize($w, $h, $url)
1114
{
1115
    $bn        = basename($url);
1116
    $w         = (int)$w;
1117
    $h         = (int)$h;
1118
    $imagesize = [0 => '0', 1 => '0']; // init image size
1119
1120
    if ('blank.gif' !== $bn
1121
        && 'blank.png' !== $bn
1122
        && 'blank.jpg' !== $bn
1123
        && 'image_missing.png' !== $bn)
1124
    {
1125
        $imagesize = [0 => $w, 1 => $h];
1126
        if (ini_get('allow_url_fopen')) {
1127
            $imagesize = getimagesize($url);
1128
        }
1129
1130
        if (!ini_get('allow_url_fopen')) {
1131
            $imagesize = [0 => $w, 1 => $h];
1132
            if (function_exists('curl_init')) {
1133
                $ch = curl_init();
1134
                curl_setopt($ch, CURLOPT_URL, $url);
1135
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1136
                $result       = curl_exec($ch);
1137
                $img          = imagecreatefromstring($result);
1138
                $imagesize[0] = imagesx($img);
1139
                $imagesize[1] = imagesy($img);
1140
            }
1141
        }
1142
    }
1143
1144
    return $imagesize;
1145
}
1146
1147
/**
1148
 * Check whether requests are set or not
1149
 *
1150
 * If not return '' else return false
1151
 *
1152
 * @param string $req
1153
 * @returns string or void
1154
 * @return string|null
1155
 * @return string|null
1156
 */
1157
function smallworld_isset($req)
1158
{
1159
    return (isset($req) && !empty($req)) ? $req : '';
1160
}
1161
1162
/**
1163
 * Do db query for images upload last 5 minutes by spec. userid and return random
1164
 * @param int $userid
1165
 * @return bool|string  false if no image found
1166
 */
1167 View Code Duplication
function smallworld_getRndImg($userid)
1168
{
1169
    $sql    = 'SELECT imgname FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_images')
1170
            . ' WHERE userid = ' . (int)$userid . ' AND time BETWEEN UNIX_TIMESTAMP( ) - 3000 AND UNIX_TIMESTAMP() ORDER BY rand() LIMIT 1';
1171
    $result = $GLOBALS['xoopsDB']->queryF($sql);
1172
    while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
1173
        $img = $r['imgname'];
1174
    }
1175
    if (!empty($img)) {
1176
        return $img;
1177
    }
1178
1179
    return false;
1180
}
1181
1182
/**
1183
 * Get url of smallworld
1184
 *
1185
 * @returns string
1186
 */
1187
function smallworld_getHostRequest()
1188
{
1189
    $protocol   = false === mb_stripos($_SERVER['SERVER_PROTOCOL'], 'https') ? 'http' : 'https';
1190
    $host       = $_SERVER['HTTP_HOST'];
1191
    $script     = $_SERVER['SCRIPT_NAME'];
1192
    $params     = $_SERVER['QUERY_STRING'];
1193
    $currentUrl = $protocol . '://' . $host;
1194
1195
    return $currentUrl;
1196
}
1197
1198
/**
1199
 * Get htmlentities
1200
 *
1201
 * @param string $text
1202
 * @return string translated string to utf-8
1203
 */
1204
function smallworld_decodeEntities($text)
1205
{
1206
    $text = html_entity_decode($text, ENT_QUOTES, 'ISO-8859-1'); /**{@internal NOTE: UTF-8 does not work!}} */
1207
    $text = preg_replace('/&#(\d+);/me', 'chr(\\1)', $text); #decimal notation
1208
    $text = preg_replace('/&#x([a-f0-9]+);/mei', 'chr(0x\\1)', $text);  #hex notation
1209
    return $text;
1210
}
1211
1212
/**
1213
 * Get string and shorten so contains only # of chars
1214
 *
1215
 * @param string $text
1216
 * @param int $numChars
1217
 * @return string
1218
 */
1219
function smallworld_shortenText($text, $numChars)
1220
{
1221
    $text .= ' ';
1222
    $text = mb_substr($text, 0, $numChars);
1223
    $text = mb_substr($text, 0, mb_strrpos($text, ' '));
1224
    $text .= '...';
1225
1226
    return $text;
1227
}
1228
1229
/**
1230
 * Get language file if constants are not defined
1231
 *
1232
 * @param string $def
1233
 * @param string $file
1234
 * @return void
1235
 */
1236
function smallworld_isDefinedLanguage($def, $file)
1237
{
1238
    /** @var \XoopsModules\Smallworld\Helper $helper */
1239
    $helper = Helper::getInstance();
1240
    if (!defined($def)) {
1241
        // language files (main.php)
1242
        if (file_exists($helper->path('language/' . $GLOBALS['xoopsConfig']['language'] . '/' . $file))) {
1243
            require_once $helper->path('language/' . $GLOBALS['xoopsConfig']['language'] . '/' . $file);
1244
        } else {
1245
            // fallback english
1246
            require_once $helper->path('language/english/' . $file);
1247
        }
1248
    }
1249
}
1250
1251
/**
1252
 * @Check if smallworld is for private or public access
1253
 * return value for config
1254
 */
1255
function smallworld_checkPrivateOrPublic()
1256
{
1257
    $opt                   = [];
1258
    $helper                = \XoopsModules\Smallworld\Helper::getInstance();
1259
    $set                   = $helper->getConfig('smallworldprivorpub');
1260
    $opt['access']         = (0 !== $set) ? Constants::HAS_ACCESS : Constants::NO_ACCESS;
1261
    $opt['xoopsuser']      = Constants::IS_NOT_USER;
1262
    $opt['smallworlduser'] = Constants::IS_NOT_USER;
1263
1264
    if ($GLOBALS['xoopsUser'] && ($GLOBALS['xoopsUser'] instanceof \XoopsUser)) {
1265
        $id                    = $GLOBALS['xoopsUser']->uid();
1266
        //$user                  = new \XoopsUser($id);
1267
        //$check                 = new \XoopsModules\Smallworld\User();
1268
        //$profile               = $check->checkIfProfile($id);
1269
        $swUserHandler         = $helper->getHandler('SwUser');
1270
        $profile               = $swUserHandler->checkIfProfile($id);
1271
        $opt['xoopsuser']      = Constants::IS_USER;
1272
        $opt['smallworlduser'] = (Constants::PROFILE_HAS_BOTH !== $profile) ? Constants::IS_NOT_USER : Constants::IS_USER;
1273
    }
1274
1275
    return $opt;
1276
}
1277
1278
/**
1279
 * Get an array of all Users
1280
 *
1281
 * @todo move this to Smallworld\SwUserHandler class
1282
 * @return array 'userid' as keys, 'username' as values
1283
 */
1284
function smallworld_xv_getGroupd()
1285
{
1286
    /** @var \XoopsModules\Smallworld\Helper $helper */
1287
    $helper          = Helper::getInstance();
1288
    $helper->loadLanguage('modinfo');
1289
    $swUserHandler   = $helper->getHandler('SwUser');
1290
    $criteria        = new \Criteria('');
1291
    $criteria->setSort('userid');
1292
    $criteria->order = 'ASC';
1293
    $userObjArray    = $swUserHandler->getAll($criteria, ['userid', 'username'], false);
1294
    $retArray        = [0 => _MI_SMALLWORLD_ALL]; // initialize the array
1295
    foreach ($userObjArray as $swUser) {
1296
        $retArray[$swUser['userid']] = $swUser['username'];
1297
    }
1298
1299
    return $retArray;
1300
    /*
1301
    $db     = \XoopsDatabaseFactory::getDatabaseConnection();
1302
    $sql    = 'SELECT userid, username FROM ' . $db->prefix('smallworld_user') . ' ORDER BY userid';
1303
    $result = $db->queryF($sql);
1304
    $num    = $db->getRowsNum($result);
1305
    if (0 == $num) {
1306
        $ndata = [0 => _MI_SMALLWORLD_ALL];
1307
    } else {
1308
        while (false !== ($r = $db->fetchArray($result))) {
1309
            $data[$r['userid']] = $r['username'];
1310
        }
1311
        $ndata = array_merge([0 => _MI_SMALLWORLD_ALL], $data);
1312
    }
1313
1314
    return $ndata;
1315
    */
1316
}
1317
1318
/**
1319
 * Set javascript vars to theme using various values
1320
 * Return void
1321
 */
1322
function smallworld_SetCoreScript()
1323
{
1324
    /** @var \XoopsModules\Smallworld\Helper $helper */
1325
    $helper = Helper::getInstance();
1326
1327
    // IF logged in define xoops / smallworld user id
1328
    $myId = ($GLOBALS['xoopsUser'] && ($GLOBALS['xoopsUser'] instanceof \XoopsUser)) ? $GLOBALS['xoopsUser']->uid() : Constants::DEFAULT_UID;
1329
1330
    // Check if option is et to allow public reading
1331
    $pub    = smallworld_checkPrivateOrPublic();
1332
    $access = $pub['access'];
1333
1334
    // GET various variables from language folder
1335
    if (file_exists($helper->path('language/' . $GLOBALS['xoopsConfig']['language'] . '/js/variables.js'))) {
1336
        $GLOBALS['xoTheme']->addScript($helper->url('language/' . $GLOBALS['xoopsConfig']['language'] . '/js/variables.js'));
1337
    } else {
1338
        $GLOBALS['xoTheme']->addScript($helper->url('language/english/js/variables.js'));
1339
    }
1340
1341
    // Check if USER is smallworld-registered user
1342
    $chkUser = new Smallworld\User();
1343
    //$profile = ($GLOBALS['xoopsUser'] && ($GLOBALS['xoopsUser'] instanceof \XoopsUser)) ? $chkUser->checkIfProfile($myId) : Constants::DEFAULT_UID;
1344
    $swUserHandler = $helper->getHandler('SwUser');
1345
    $profile       = $swUserHandler->checkIfProfile($myId);
1346
1347
    // Check if there are requests pending
1348
    $count_invit = ($GLOBALS['xoopsUser'] && ($GLOBALS['xoopsUser'] instanceof \XoopsUser)) ? count($chkUser->getRequests($myId)) : Constants::DEFAULT_UID;
1349
1350
    // Get module config for validation and place in javascript
1351
    $validate = $helper->getConfig('validationstrength');
1352
1353
    // Check to see if smallworld should use username links to point to default xoops or smallworld
1354
    $takeoverlinks   = $helper->getConfig('takeoveruserlinks');
1355
    $fieldstoshow    = array_flip($helper->getConfig('smallworldusethesefields'));
1356
    $useverification = $helper->getConfig('smallworldmandatoryfields');
1357
    $smallworldUV    = implode(',', $useverification);
1358
1359
    // Use googlemaps ?
1360
    $googlemaps = $helper->getConfig('smallworldUseGoogleMaps');
1361
1362
    // Get users messages count based on users followerArray
1363
    $getUserMsgNum = ($GLOBALS['xoopsUser'] && ($GLOBALS['xoopsUser'] instanceof \XoopsUser)) ? smallworld_getCountFriendMessagesEtc() : 0;
1364
1365
    // Check if request url is with www or without
1366
    $urltest   = smallworld_getHostRequest();
1367
    $xoops_url = XOOPS_URL;
1368
    if (false === mb_strpos($urltest, 'www.')) {
1369
        $xoops_url = str_replace('www.', '', $xoops_url);
1370
    }
1371
1372
    // Set javascript vars but only if not already defined.
1373
    // Check prevents multiple loads
1374
    $script = 'var Smallworld_myID;' . "\n";
1375
    $script .= "if (typeof Smallworld_myID === 'undefined') {" . "\n";
1376
    $script .= "var smallworld_url = '" . $xoops_url . '/modules/smallworld/' . "';\n";
1377
    $script .= "var smallworld_uploaddir = '" . $xoops_url . '/uploads/avatars/' . "';\n";
1378
    $script .= 'var smallworld_urlReferer = document.referrer;' . "\n";
1379
    $script .= "var xoops_smallworld = jQuery.noConflict();\n";
1380
    $script .= 'var Smallworld_myID = ' . $myId . ";\n";
1381
    $script .= 'var Smallworld_userHasProfile = ' . $profile . ";\n";
1382
    $script .= 'var smallworldTakeOverLinks = ' . $takeoverlinks . ";\n";
1383
    $script .= 'var Smallworld_geocomplete = ' . $googlemaps . ";\n";
1384
    $script .= "var smallworldVerString = '" . $smallworldUV . "';\n";
1385
    $script .= "var smallworlduseverification = new Array();\n";
1386
    $script .= "smallworlduseverification = smallworldVerString.split(',');\n";
1387
    $script .= 'var Smallworld_hasmessages = ' . $count_invit . ";\n";
1388
	//smallworldvalidationstrenght
1389
    $script .= 'var smallworldvalidationstrength = ' . $validate . ";\n";
1390
    $script .= 'var smallworld_getFriendsMsgComCount = ' . $getUserMsgNum . ";\n";
1391
    //$script .= "var $ = jQuery();\n";
1392
    $script .= '}' . "\n";
1393
    $GLOBALS['xoTheme']->addScript('', '', $script);
1394
1395
    // Include geolocate styling
1396
    if (1 == $googlemaps) {
1397
        //$GLOBALS['xoTheme']->addScript('https://maps.googleapis.com/maps/api/js?sensor=false&language=' . _LANGCODE);
1398
        //$GLOBALS['xoTheme']->addScript($helper->url('assets/js/osm_birth.js'));
1399
        //$GLOBALS['xoTheme']->addScript($helper->url('assets/js/osm_now.js'));
1400
    }
1401
1402
    smallworld_includeScripts();
1403
}
1404
1405
/**
1406
 * Include script files based on $page
1407
 */
1408
function smallworld_includeScripts()
1409
{
1410
    /** @var \XoopsModules\Smallworld\Helper $helper */
1411
    $helper = Helper::getInstance();
1412
    $page = basename($_SERVER['PHP_SELF'], '.php');
1413
    switch ($page) {
1414 View Code Duplication
        case 'register':
1415
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.colorbox.js'));
1416
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.validate.js'));
1417
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.validation.functions.js'));
1418
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.stepy.js'));
1419
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.elastic.source.js'));
1420
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/smallworld.css'));
1421
			$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/esri-leaflet-geocoder.css'));
1422
			$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/leaflet.css'));
1423
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/leaflet.js'));
1424
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/osm_birth.js'));
1425
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/osm_now.js'));
1426
			
1427
            break;
1428 View Code Duplication
        case 'publicindex':
1429
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.oembed.js'));
1430
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.elastic.source.js'));
1431
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/wall.js'));
1432
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/ajaxupload.3.5.js'));
1433
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.avatar_helper.js'));
1434
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jssocials.min.js'));
1435
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/jssocials.js'));
1436
1437
			$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/jssocials-theme-minima.css'));
1438
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/oembed.css'));
1439
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.colorbox.js'));
1440
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/smallworld.css'));
1441
            break;
1442 View Code Duplication
        case 'permalink':
1443
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.oembed.js'));
1444
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/wall.js'));
1445
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/oembed.css'));
1446
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/smallworld.css'));
1447
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.innerfade.js'));
1448
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.elastic.source.js'));
1449
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jssocials.min.js'));
1450
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/jssocials.js'));
1451
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/jssocials.shares.js'));
1452
			$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/jssocials-theme-minima.css'));
1453
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.colorbox.js'));
1454
            break;
1455
        case 'index':
1456
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.oembed.js'));
1457
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.elastic.source.js'));
1458
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/wall.js'));
1459
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/ajaxupload.3.5.js'));
1460
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.avatar_helper.js'));
1461
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jssocials.min.js'));
1462
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/jssocials.js'));
1463
1464
			$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/jssocials-theme-minima.css'));
1465
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/oembed.css'));
1466
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.colorbox.js'));
1467
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/tag-it.js'));
1468
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/smallworld.css'));
1469
            break;
1470
        case 'img_upload':
1471
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/uploader/bootstrap.min.css'));
1472
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/uploader/style.css'));
1473
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/uploader/bootstrap-responsive.min.css'));
1474
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/uploader/bootstrap-image-gallery.min.css'));
1475
1476
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/vendor/jquery.ui.widget.js'));
1477
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/uploader/tmpl.js'));
1478
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/uploader/load-image.js'));
1479
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/uploader/canvas-to-blob.js'));
1480
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/uploader/bootstrap.js'));
1481
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/uploader/bootstrap-image-gallery.js'));
1482
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.iframe-transport.js'));
1483
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.fileupload.js'));
1484
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.fileupload-fp.js'));
1485
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.fileupload-ui.js'));
1486
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/main.js'));
1487
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.colorbox.js'));
1488
            break;
1489
        case 'galleryshow':
1490
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/galleriffic-5.css'));
1491
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.galleriffic.js'));
1492
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.history.js'));
1493
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.opacityrollover.js'));
1494
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/gallery_mod.js'));
1495
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.innerfade.js'));
1496
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.colorbox.js'));
1497
            break;
1498 View Code Duplication
        case 'friends':
1499
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/apprise-1.5.full.js'));
1500
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/jquery.fileupload-ui.css'));
1501
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/oembed.css'));
1502
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.oembed.js'));
1503
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/wall.js'));
1504
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/ajaxupload.3.5.js'));
1505
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.avatar_helper.js'));
1506
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.innerfade.js'));
1507
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.colorbox.js'));
1508
            //$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/colorbox.css'));
1509
            break;
1510 View Code Duplication
        case 'editprofile':
1511
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.colorbox.js'));
1512
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.validate.js'));
1513
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.validation.functions.js'));
1514
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.stepy.js'));
1515
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.elastic.source.js'));
1516
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/smallworld.css'));
1517
			$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/esri-leaflet-geocoder.css'));
1518
			$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/leaflet.css'));
1519
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/leaflet.js'));
1520
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/osm_birth.js'));
1521
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/osm_now.js'));
1522
		
1523
            break;
1524 View Code Duplication
        case 'smallworldshare':
1525
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.oembed.js'));
1526
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/wall.js'));
1527
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.innerfade.js'));
1528
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jssocials.min.js'));
1529
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/jssocials.js'));
1530
1531
			$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/jssocials-theme-minima.css'));
1532
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/oembed.css'));
1533
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/smallworld.css'));
1534
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.colorbox.js'));
1535
            break;
1536
        case 'userprofile':
1537
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/apprise-1.5.full.js'));
1538
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/jquery.fileupload-ui.css'));
1539
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/oembed.css'));
1540
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.oembed.js'));
1541
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/wall.js'));
1542
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/ajaxupload.3.5.js'));
1543
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.avatar_helper.js'));
1544
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jssocials.min.js'));
1545
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/jssocials.js'));
1546
1547
			$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/jssocials-theme-minima.css'));
1548
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.colorbox.js'));
1549
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.elastic.source.js'));
1550
            $GLOBALS['xoTheme']->addScript($helper->url('assets/js/jquery.countdown.js'));
1551
            $GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/smallworld.css'));
1552
			$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/esri-leaflet-geocoder.css'));
1553
			$GLOBALS['xoTheme']->addStylesheet($helper->url('assets/css/leaflet.css'));
1554
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/leaflet.js'));			
1555
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/osm_birth.js'));
1556
			$GLOBALS['xoTheme']->addScript($helper->url('assets/js/osm_now.js'));			
1557
            break;
1558
    }
1559
}
1560
1561
/**
1562
 * Check if permission is set for userid to post publicly
1563
 *
1564
 * @return array
0 ignored issues
show
Should the return type not be string|array?

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...
1565
 */
1566
function smallworld_checkUserPubPostPerm()
1567
{
1568
	$check      = new Smallworld\User;
1569
    $helper     = Helper::getInstance();
1570
    $userPerPub = $helper->getConfig('smallworldshowPoPubPage');
1571
	$number = number_format($userPerPub[0], 0);  // userPerPub for some reason returned int as string ?!?!
1572
    $pub = ($number > 0) ? $number : $check->allUsers();
0 ignored issues
show
Deprecated Code introduced by
The method XoopsModules\Smallworld\User::allUsers() has been deprecated with message: - functionality moved to SwUserHandler::allUsers()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1573
    /*
1574
    $check      = new Smallworld\User();
1575
    $userPerPub = smallworld_GetModuleOption('smallworldshowPoPubPage');
1576
    $allUsers   = $check->allUsers();
1577
    if (0 != $userPerPub[0]) {
1578
        $pub = $userPerPub;
1579
    } else {
1580
        $pub = $check->allUsers();
1581
    }
1582
    */
1583
    return $pub;
1584
}
1585
1586
/**
1587
 * Change @username to urls
1588
 *
1589
 * @param string|null $status_text
1590
 * @return string $status_text
1591
 */
1592
function linkify_twitter_status($status_text)
1593
{
1594
    // linkify twitter users
1595
    //$keywords = preg_split("/[\s,]+/", "hypertext language, programming");
1596
    $status_text = preg_replace('/(^|\s)@(\w+)/', '\1<a href="' . XOOPS_URL . '/modules/smallworld/userprofile.php?username=\2">' . '@\2</a> ', $status_text);
1597
1598
    return $status_text;
1599
}
1600
1601
/**
1602
 * Extract users from @tags
1603
 * @param $name
1604
 * @return array @users
1605
 */
1606 View Code Duplication
function smallworld_getUidFromName($name)
1607
{
1608
    $id     = [];
1609
    $sql    = 'SELECT userid FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . " WHERE username = '" . $name . "'";
1610
    $result = $GLOBALS['xoopsDB']->queryF($sql);
1611
    while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
1612
        $id = $r['userid'];
1613
    }
1614
1615
    return $id;
1616
}
1617
1618
/**
1619
 * Extract users from @tags
1620
 * @param        $txt
1621
 * @param        $sender
1622
 * @param string $permalink
1623
 * @throws \phpmailerException
1624
 */
1625
function smallworld_getTagUsers($txt, $sender, $permalink = '')
1626
{
1627
    $dBase = new Smallworld\SwDatabase();
1628
    $mail  = new Smallworld\Mail();
1629
    preg_match_all('/@([a-zA-Z0-9]+|\\[[a-zA-Z0-9]+\\])/', $txt, $matches);
1630
    $users = array_unique($matches[1]);
1631
    foreach ($users as $user) {
1632
        $uid    = smallworld_getUidFromName($user);
1633
        $notify = json_decode($dBase->getSettings($uid), true);
1634
        if (isset($notify['notify'])) {
1635
            if (0 != $notify['notify']) {
1636
                $mail->sendMails($sender, $uid, 'tag', $permalink, [$txt]);
1637
            }
1638
        }
1639
    }
1640
}
1641
1642
/**
1643
 * Function to get count of messages in wall
1644
 * @param int $uid
1645
 * @return int $count
1646
 */
1647
function smallworld_countUserWallMsges($uid)
1648
{
1649
    $db     = \XoopsDatabaseFactory::getDatabaseConnection();
1650
    $sql    = 'SELECT message FROM ' . $db->prefix('smallworld_messages') . " WHERE uid_fk='" . $uid . "'";
1651
    $result = $db->queryF($sql);
1652
    $count  = $db->getRowsNum($result);
1653
1654
    return $count;
1655
}
1656