Wgdiaries   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 25
c 1
b 0
f 1
dl 0
loc 52
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A grabEntries() 0 43 3
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
use XoopsModules\Rssfit\{
24
    AbstractPlugin
25
};
26
use XoopsModules\Wgdiaries\Helper as PluginHelper;
27
28
if (!\defined('RSSFIT_ROOT_PATH')) {
29
    exit();
30
}
31
32
/**
33
 * Class Sample
34
 * @package XoopsModules\Rssfit\Plugins
35
 */
36
final class Wgdiaries extends AbstractPlugin
37
{
38
    public function __construct() {
39
        if (\class_exists(PluginHelper::class)) {
40
            $this->helper = PluginHelper::getInstance();
41
            $this->dirname = $this->helper->dirname();
42
        }
43
    }
44
45
    public function grabEntries(\XoopsMySQLDatabase $xoopsDB): ?array
46
    {
47
        $ret  = null;
48
        $i    = 0;
49
        //  The following example code grabs the latest entries from the module
50
        $sql  = 'SELECT i.item_id, i.item_datecreated, i.item_name, i.item_remarks, c.cat_name ';
51
        $sql .= 'FROM ' . $xoopsDB->prefix('wgdiaries_items') . ' i INNER JOIN ' . $xoopsDB->prefix('wgdiaries_categories') . ' c ON i.item_catid = c.cat_id ';
52
        $sql .= 'ORDER BY i.item_datecreated DESC, i.item_id DESC';
53
54
        $result = $xoopsDB->query($sql, $this->grab, 0);
55
        if ($result instanceof \mysqli_result) {
56
            $ret = [];
57
            while (false !== ($row = $xoopsDB->fetchArray($result))) {
58
                $link = XOOPS_URL . '/modules/' . $this->dirname . '/items.php?op=show&amp;item_id=' . $row['item_id'];
59
                /*
60
                * Required elements of an RSS item
61
                */
62
                //  1. Title of an item
63
                $ret[$i]['title'] = $row['item_name'];
64
                //  2. URL of an item
65
                $ret[$i]['link'] = $link;
66
                //  3. Item modification date, must be in Unix time format
67
                $ret[$i]['timestamp'] = $row['item_datecreated'];
68
                //  4. The item synopsis, or description, whatever
69
                $ret[$i]['description'] = $row['item_remarks'];
70
                /*
71
                * Optional elements of an RSS item
72
                */
73
                //  5. The item synopsis, or description, whatever
74
                $ret[$i]['guid'] = $link;
75
                //  6. A string + domain that identifies a categorization taxonomy
76
                $ret[$i]['category'] = $this->modname;
77
                $ret[$i]['domain']   = XOOPS_URL . '/modules/' . $this->dirname . '/';
78
                //  7. extra tags examples
79
                $ret[$i]['extras'] = [];
80
                //  7a. without attribute
81
                $ret[$i]['extras']['state'] = ['content' => $row['cat_name']];
82
                //  7b. with attributes
83
                //$ret[$i]['extras']['enclosure']['attributes'] = ['url' => 'url-to-any-file', 'length' => 1024000, 'type' => 'audio/mpeg'];
84
                $i++;
85
            }
86
        }
87
        return $ret;
88
    }
89
}
90