Weblinks   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 46
c 0
b 0
f 0
dl 0
loc 74
rs 10
wmc 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A grabEntries() 0 27 3
A myGetUnameFromId() 0 22 4
A loadModule() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Rssfit\Plugins;
6
7
/*
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
17
/**
18
 * @copyright    XOOPS Project (https://xoops.org)
19
 * @license      GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
20
 * @package      RSSFit - Extendable XML news feed generator
21
 * @author       NS Tai (aka tuff) <http://www.brandycoke.com>
22
 * @author       XOOPS Development Team
23
 */
24
/*
25
* About this RSSFit plug-in
26
* Author: tuff <http://www.brandycoke.com>
27
* Requirements (Tested with):
28
*  Module: MyLinks <https://xoops.org>
29
*  Version: 1.1
30
*  RSSFit verision: 1.2 / 1.5
31
*  XOOPS version: 2.0.13.2 / 2.2.3
32
*/
33
34
if (!\defined('RSSFIT_ROOT_PATH')) {
35
    exit();
36
}
37
38
/**
39
 * Class Weblinks
40
 * @package XoopsModules\Rssfit\Plugins
41
 */
42
class Weblinks
43
{
44
    public $dirname = 'weblinks';
45
    public $modname;
46
    public $grab;
47
48
    /**
49
     * @return \XoopsModule
50
     */
51
    public function loadModule():?\XoopsModule
52
    {
53
        $mod = $GLOBALS['module_handler']->getByDirname($this->dirname);
54
        if (!$mod || !$mod->getVar('isactive')) {
55
            return null;
56
        }
57
        $this->modname = $mod->getVar('name');
58
59
        return $mod;
60
    }
61
62
    public function myGetUnameFromId(int $uid): string
63
    {
64
        static $thisUser = false;
65
        static $lastUid = false;
66
        static $lastName = '';
67
68
        if ($lastUid == $uid) {
69
            return $lastName;
70
        }
71
72
        if (!\is_object($thisUser)) {
73
            $memberHandler = \xoops_getHandler('member');
74
            $thisUser = $memberHandler->getUser($uid);
0 ignored issues
show
Bug introduced by
The method getUser() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsAvatarHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
            /** @scrutinizer ignore-call */ 
75
            $thisUser = $memberHandler->getUser($uid);
Loading history...
75
        }
76
        $name = \htmlspecialchars($thisUser->getVar('name'), \ENT_QUOTES | \ENT_HTML5);
77
        if ('' == $name) {
78
            $name = \htmlspecialchars($thisUser->getVar('uname'), \ENT_QUOTES | \ENT_HTML5);
79
        }
80
        $lastUid = $uid;
81
        $lastName = $name;
82
83
        return $name;
84
    }
85
86
    /**
87
     * @return array
88
     */
89
    public function grabEntries(\XoopsMySQLDatabase $xoopsDB):?array
90
    {
91
        $myts = \MyTextSanitizer::getInstance();
92
        $ret  = null;
93
        $i = 0;
94
        $sql = 'SELECT lid, title, time_update, description, url, uid FROM ' . $xoopsDB->prefix('weblinks_link') . '  ORDER BY time_update DESC';
95
        $result = $xoopsDB->query($sql, $this->grab, 0);
96
        if ($result instanceof \mysqli_result) {
97
            $ret = [];
98
            while (false !== ($row = $xoopsDB->fetchArray($result))) {
99
                $title                  = $row['title'];
100
                $name                   = $this->myGetUnameFromId($row['uid']);
101
                $ret[$i]['title']       = $this->modname . ': ' . $title;
102
                $link                   = XOOPS_URL . '/modules/' . $this->dirname . '/singlelink.php?lid=' . $row['lid'] . '&amp;keywords=';
103
                $ret[$i]['link']        = $link;
104
                $ret[$i]['timestamp']   = $row['time_update'];
105
                $desc                   = '<p><a href="' . $row['url'] . '"><b>' . $title . '</b></a><br> ';
106
                $desc                   .= 'Submitted by: <i>' . $name . '</i><br>';
107
                $desc                   .= $myts->displayTarea($row['description']) . '</p><br clear="all">';
108
                $ret[$i]['description'] = $desc;
109
                $ret[$i]['guid']        = $link;
110
                $ret[$i]['category']    = $this->modname;
111
                $ret[$i]['domain']      = XOOPS_URL . '/modules/' . $this->dirname . '/';
112
                $i++;
113
            }
114
        }
115
        return $ret;
116
    }
117
}
118