Pical   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A loadModule() 0 14 4
A grabEntries() 0 21 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: jayjay <http://www.sint-niklaas.be>
28
 * Requirements (Tested with):
29
 *  Module: piCal <https://xoops.org>
30
 *  Version: 1.0
31
 *  RSSFit version: 1.21
32
 *  XOOPS version: 2.0.18.1
33
 */
34
35
use XoopsModules\Rssfit\{
36
    AbstractPlugin
37
};
38
39
//use XoopsModules\Pical\Helper as PluginHelper;
40
41
if (!\defined('RSSFIT_ROOT_PATH')) {
42
    exit();
43
}
44
45
/**
46
 * Class Pical
47
 */
48
final class Pical extends AbstractPlugin
49
{
50
    public function __construct() {
51
        $this->dirname = 'pical';
52
    }
53
54
    public function loadModule(): ?\XoopsModule
55
    {
56
        $mod = $GLOBALS['module_handler']->getByDirname($this->dirname);
57
        if (!$mod || !$mod->getVar('isactive')) {
58
            return null;
59
        }
60
61
        if (!$mod->getVar('isactive')) {
62
            return null;
63
        }
64
        $this->modname = $mod->getVar('name');
65
        $this->module  = $mod;   // optional, remove this line if there is nothing to do with module info when grabbing entries
66
67
        return $mod;
68
    }
69
70
    public function grabEntries(\XoopsMySQLDatabase $xoopsDB): ?array
71
    {
72
        $myts   = \MyTextSanitizer::getInstance();
73
        $ret    = null;
74
        $i      = 0;
75
        $sql    = 'SELECT id, uid, summary, location, description, categories, start, end, UNIX_TIMESTAMP(dtstamp) as dtstamp FROM ' . $xoopsDB->prefix('pical_event') . ' WHERE admission>0 AND (rrule_pid=0 OR rrule_pid=id) ORDER BY dtstamp DESC';
76
        $result = $xoopsDB->query($sql, $this->grab, 0);
77
        if ($result instanceof \mysqli_result) {
78
            $ret = [];
79
            while (false !== ($row = $xoopsDB->fetchArray($result))) {
80
                $ret[$i]['title']       = $row['summary'];
81
                $link                   = XOOPS_URL . '/modules/' . $this->dirname . '/index.php?event_id=' . $row['id'];
82
                $ret[$i]['link']        = $ret[$i]['guid'] = $link;
83
                $ret[$i]['timestamp']   = $row['dtstamp'];
84
                $ret[$i]['description'] = $myts->displayTarea($row['description']);
85
                $ret[$i]['category']    = $this->modname;
86
                $ret[$i]['domain']      = XOOPS_URL . '/modules/' . $this->dirname . '/';
87
                $i++;
88
            }
89
        }
90
        return $ret;
91
    }
92
}
93