Sample::__construct()   A
last analyzed

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
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
* This file is a dummy for making a RSSFit plug-in, follow the following steps
27
* if you really want to do so.
28
* Step 0:   Stop here if you are not sure what you are doing, it's no fun at all
29
* Step 1:   Clone this file and rename as something like rssfit.[mod_dir].php
30
* Step 2:   Replace the text "RssfitSample" with "Rssfit[mod_dir]" at line 59 and
31
*           line 65, i.e. "RssfitNews" for the module "News"
32
* Step 3:   Modify the word in line 60 from 'sample' to [mod_dir]
33
* Step 4:   Modify the function "grabEntries" to satisfy your needs
34
* Step 5:   Move your new plug-in file to the RSSFit plugins folder,
35
*           i.e. your-xoops-root/modules/rssfit/plugins
36
* Step 6:   Install your plug-in by pointing your browser to
37
*           your-xoops-url/modules/rssfit/admin/?do=plugins
38
* Step 7:   Finally, tell us about yourself and this file by modifying the
39
*           "About this RSSFit plug-in" section which is located... somewhere.
40
*
41
* [mod_dir]: Name of the driectory of your module, i.e. 'news'
42
*
43
* About this RSSFit plug-in
44
* Author: John Doe <http://www.your.site>
45
* Requirements (or Tested with):
46
*  Module: Blah <http://www.where.to.find.it>
47
*  Version: 1.0
48
*  RSSFit verision: 1.2 / 1.5
49
*  XOOPS version: 2.0.13.2 / 2.2.3
50
*/
51
52
use XoopsModules\Rssfit\{
53
    AbstractPlugin
54
};
55
56
use XoopsModules\Sample\Helper as PluginHelper;
0 ignored issues
show
Bug introduced by
The type XoopsModules\Sample\Helper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
57
58
if (!\defined('RSSFIT_ROOT_PATH')) {
59
    exit();
60
}
61
62
/**
63
 * Class Sample
64
 * @package XoopsModules\Rssfit\Plugins
65
 */
66
final class Sample extends AbstractPlugin
67
{
68
    public function __construct() {
69
        if (\class_exists(PluginHelper::class)) {
70
            $this->helper = PluginHelper::getInstance();
71
            $this->dirname = $this->helper->dirname();
72
        }
73
    }
74
75
    public function grabEntries(\XoopsMySQLDatabase $xoopsDB): ?array
76
    {
77
        $myts = \MyTextSanitizer::getInstance();
78
        $ret  = null;
79
        $i    = 0;
80
        //  The following example code grabs the latest entries from the module MyLinks
81
        $sql    = 'SELECT l.lid, l.cid, l.title, l.date, t.description FROM ' . $xoopsDB->prefix('mylinks_links') . ' l, ' . $xoopsDB->prefix('mylinks_text') . ' t WHERE l.status > 0 AND l.lid = t.lid ORDER BY date DESC';
82
        $result = $xoopsDB->query($sql, $this->grab, 0);
83
        if ($result instanceof \mysqli_result) {
84
            $ret = [];
85
            while (false !== ($row = $xoopsDB->fetchArray($result))) {
86
                $link = XOOPS_URL . '/modules/' . $this->dirname . '/singlelink.php?cid=' . $row['cid'] . '&amp;lid=' . $row['lid'];
87
                /*
88
                * Required elements of an RSS item
89
                */
90
                //  1. Title of an item
91
                $ret[$i]['title'] = $row['title'];
92
                //  2. URL of an item
93
                $ret[$i]['link'] = $link;
94
                //  3. Item modification date, must be in Unix time format
95
                $ret[$i]['timestamp'] = $row['date'];
96
                //  4. The item synopsis, or description, whatever
97
                $ret[$i]['description'] = $myts->displayTarea($row['description']);
98
                /*
99
                * Optional elements of an RSS item
100
                */
101
                //  5. The item synopsis, or description, whatever
102
                $ret[$i]['guid'] = $link;
103
                //  6. A string + domain that identifies a categorization taxonomy
104
                $ret[$i]['category'] = $this->modname;
105
                $ret[$i]['domain']   = XOOPS_URL . '/modules/' . $this->dirname . '/';
106
                //  7. extra tags examples
107
                $ret[$i]['extras'] = [];
108
                //  7a. without attribute
109
                $ret[$i]['extras']['author'] = ['content' => '[email protected]'];
110
                //  7b. with attributes
111
                $ret[$i]['extras']['enclosure']['attributes'] = ['url' => 'url-to-any-file', 'length' => 1024000, 'type' => 'audio/mpeg'];
112
                $i++;
113
            }
114
        }
115
        return $ret;
116
    }
117
}
118