Passed
Push — master ( b0fca4...7540c5 )
by Michael
06:08 queued 02:59
created

Wglinks::loadModule()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 6
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
namespace XoopsModules\Rssfit\Plugins;
4
5
/*
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * @copyright    XOOPS Project (https://xoops.org)
17
 * @license      GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
18
 * @package      RSSFit - Extendable XML news feed generator
19
 * @author       NS Tai (aka tuff) <http://www.brandycoke.com>
20
 * @author       XOOPS Development Team
21
 */
22
23
24
use XoopsModules\Rssfit\{
25
    AbstractPlugin
26
};
27
use XoopsModules\Wglinks\Helper as PluginHelper;
28
29
if (!\defined('RSSFIT_ROOT_PATH')) {
30
    exit();
31
}
32
33
/**
34
 * Class Sample
35
 * @package XoopsModules\Rssfit\Plugins
36
 */
37
final class Wglinks extends AbstractPlugin
38
{
39
    public function __construct() {
40
        if (\class_exists(PluginHelper::class)) {
41
            $this->helper = PluginHelper::getInstance();
42
            $this->dirname = $this->helper->dirname();
43
        }
44
    }
45
46
    public function grabEntries(\XoopsMySQLDatabase $xoopsDB): ?array
47
    {
48
        $ret  = null;
49
        $i    = 0;
50
        //  The following example code grabs the latest entries from the module
51
        $sql  = 'SELECT l.link_id, l.link_name, l.link_detail, l.link_date_created, l.link_state, c.cat_name ';
52
        $sql .= 'FROM ' . $xoopsDB->prefix('wglinks_links') . ' l  INNER JOIN ' . $xoopsDB->prefix('wglinks_categories') . ' c ';
53
        $sql .= 'ON l.link_catid = c.cat_id WHERE (((l.link_state)=1)) ORDER BY l.link_date_created DESC';
54
55
        $result = $xoopsDB->query($sql, $this->grab, 0);
56
        if ($result instanceof \mysqli_result) {
57
            $ret = [];
58
            while (false !== ($row = $xoopsDB->fetchArray($result))) {
59
                $link = XOOPS_URL . '/modules/' . $this->dirname . '/index.php?op=show&amp;link_id=' . $row['link_id'];
60
                /*
61
                * Required elements of an RSS item
62
                */
63
                //  1. Title of an item
64
                $ret[$i]['title'] = $row['link_name'];
65
                //  2. URL of an item
66
                $ret[$i]['link'] = $link;
67
                //  3. Item modification date, must be in Unix time format
68
                $ret[$i]['timestamp'] = $row['link_date_created'];
69
                //  4. The item synopsis, or description, whatever
70
                $ret[$i]['description'] = $row['link_detail'];
71
                /*
72
                * Optional elements of an RSS item
73
                */
74
                //  5. The item synopsis, or description, whatever
75
                $ret[$i]['guid'] = $link;
76
                //  6. A string + domain that identifies a categorization taxonomy
77
                $ret[$i]['category'] = $this->modname;
78
                $ret[$i]['domain']   = XOOPS_URL . '/modules/' . $this->dirname . '/';
79
                //  7. extra tags examples
80
                $ret[$i]['extras'] = [];
81
                //  7a. without attribute
82
                $ret[$i]['extras']['cat'] = ['content' => $row['cat_name']];
83
                //  7b. with attributes
84
                //$ret[$i]['extras']['enclosure']['attributes'] = ['url' => 'url-to-any-file', 'length' => 1024000, 'type' => 'audio/mpeg'];
85
                $i++;
86
            }
87
        }
88
        return $ret;
89
    }
90
}
91