Queries   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
c 0
b 0
f 0
dl 0
loc 62
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
B grabEntries() 0 37 6
A loadModule() 0 10 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
/**
26
 * About this RSSFit plug-in
27
 * Author: Richard Griffith <[email protected]>
28
 * Requirements (or Tested with):
29
 *  Module: Queries https://github.com/geekwright/queries
30
 *  Version: 1.0
31
 *  RSSFit verision: 1.3
32
 *  XOOPS version: 2.5.9
33
 */
34
if (!\defined('RSSFIT_ROOT_PATH')) {
35
    exit();
36
}
37
38
/**
39
 * Class Queries
40
 * @package XoopsModules\Rssfit\Plugins
41
 */
42
class Queries
43
{
44
    public $dirname = 'queries';
45
    public $modname;
46
    public $grab;
47
    public $module;
48
49
    /**
50
     * @return \XoopsModule
51
     */
52
    public function loadModule():?\XoopsModule
53
    {
54
        $mod = $GLOBALS['module_handler']->getByDirname($this->dirname);
55
        if (!$mod || !$mod->getVar('isactive')) {
56
            return null;
57
        }
58
        $this->modname = $mod->getVar('name');
59
        $this->module = $mod;    // optional, remove this line if there is nothing
60
        // to do with module info when grabbing entries
61
        return $mod;
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    public function grabEntries(\XoopsMySQLDatabase $xoopsDB):?array
68
    {
69
        $myts = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
70
        $ret  = null;
71
72
        $i = -1;
73
        $lasttime = false;
0 ignored issues
show
Unused Code introduced by
The assignment to $lasttime is dead and can be removed.
Loading history...
74
        $lastuser = false;
0 ignored issues
show
Unused Code introduced by
The assignment to $lastuser is dead and can be removed.
Loading history...
75
        $limit = 10 * $this->grab;
76
77
        $sql = 'SELECT id, title, posted, querytext FROM ' . $xoopsDB->prefix('queries_query');
78
        $sql .= ' WHERE approved=1 ORDER BY posted DESC ';
79
80
        $result = $xoopsDB->query($sql, $limit, 0);
81
        if ($result instanceof \mysqli_result) {
82
            $ret = [];
83
            while (false !== ($row = $xoopsDB->fetchArray($result))) {
84
                ++$i;
85
                if ($i <= $this->grab) {
86
                    $desc = $row['querytext'];
87
                    if (mb_strlen($desc) > 200) {
88
                        $desc = mb_substr($desc, 0, 200) . '...';
89
                    }
90
                    $link                   = XOOPS_URL . '/modules/queries/view.php?id=' . $row['id'];
91
                    $ret[$i]['title']       = $this->modname . ': ' . $row['title'];
92
                    $ret[$i]['link']        = $link;
93
                    $ret[$i]['timestamp']   = $row['posted'];
94
                    $ret[$i]['guid']        = $link;
95
                    $ret[$i]['category']    = $this->modname;
96
                    $ret[$i]['description'] = $desc;
97
                }
98
                if ($i > $this->grab) {
99
                    break;
100
                }
101
            }
102
        }
103
        return $ret;
104
    }
105
}
106