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

Wggallery::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 4
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
use XoopsModules\Rssfit\{
24
    AbstractPlugin
25
};
26
use XoopsModules\Wggallery\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 Wggallery 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.img_date, i.img_id, i.img_title, i.img_desc, i.img_albid, a.alb_name, a.alb_state, i.img_state ';
51
        $sql .= 'FROM ' . $xoopsDB->prefix('wggallery_images') . ' i  INNER JOIN ' . $xoopsDB->prefix('wggallery_albums') . ' a ';
52
        $sql .= 'ON i.img_albid = a.alb_id ORDER BY i.img_date DESC';
53
        $result = $xoopsDB->query($sql, $this->grab, 0);
54
        if ($result instanceof \mysqli_result) {
55
            $ret = [];
56
            while (false !== ($row = $xoopsDB->fetchArray($result))) {
57
                $link = XOOPS_URL . '/modules/' . $this->dirname . '/images.php?op=show&amp;img_id=' . $row['img_id'];
58
                /*
59
                * Required elements of an RSS item
60
                */
61
                //  1. Title of an item
62
                $ret[$i]['title'] = $row['img_title'];
63
                //  2. URL of an item
64
                $ret[$i]['link'] = $link;
65
                //  3. Item modification date, must be in Unix time format
66
                $ret[$i]['timestamp'] = $row['img_date'];
67
                //  4. The item synopsis, or description, whatever
68
                $ret[$i]['description'] = $row['img_desc'];
69
                /*
70
                * Optional elements of an RSS item
71
                */
72
                //  5. The item synopsis, or description, whatever
73
                $ret[$i]['guid'] = $link;
74
                //  6. A string + domain that identifies a categorization taxonomy
75
                $ret[$i]['category'] = $this->modname;
76
                $ret[$i]['domain']   = XOOPS_URL . '/modules/' . $this->dirname . '/';
77
                //  7. extra tags examples
78
                $ret[$i]['extras'] = [];
79
                //  7a. without attribute
80
                //$ret[$i]['extras']['author'] = ['content' => '[email protected]'];
81
                //  7b. with attributes
82
                //$ret[$i]['extras']['enclosure']['attributes'] = ['url' => 'url-to-any-file', 'length' => 1024000, 'type' => 'audio/mpeg'];
83
                $i++;
84
            }
85
        }
86
        return $ret;
87
    }
88
}
89