News   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A grabEntries() 0 25 4
A __construct() 0 4 2
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: tuff <http://www.brandycoke.com>
28
* Requirements (Tested with):
29
*  Module: News <https://xoops.org>
30
*  Version: 1.1 / 1.3 / 1.42 / 1.44
31
*  RSSFit verision: 1.2 / 1.5
32
*  XOOPS version: 2.0.13.2 / 2.2.3
33
*/
34
35
use XoopsModules\News\{
36
    Helper as PluginHelper,
37
    NewsStory,
38
    Utility as PluginUtility
39
};
40
use XoopsModules\Rssfit\{
41
    AbstractPlugin
42
};
43
44
if (!\defined('RSSFIT_ROOT_PATH')) {
45
    exit();
46
}
47
48
/**
49
 * Class News
50
 * @package XoopsModules\Rssfit\Plugins
51
 */
52
final class News extends AbstractPlugin
53
{
54
    public function __construct() {
55
        if (\class_exists(PluginHelper::class)) {
56
            $this->helper = PluginHelper::getInstance();
57
            $this->dirname = $this->helper->dirname();
58
        }
59
    }
60
61
    public function grabEntries(\XoopsMySQLDatabase $xoopsDB): ?array
62
    {
63
        $ret = null;
64
        //        @require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
65
        $myts = \MyTextSanitizer::getInstance();
66
        if ($this->module->getVar('version') >= 130) {
67
            //            @require_once XOOPS_ROOT_PATH . '/modules/news/include/functions.php';
68
            $news = NewsStory::getAllPublished($this->grab, 0, PluginUtility::getModuleOption('restrictindex'));
69
        } else {
70
            $news = NewsStory::getAllPublished($this->grab, 0);
71
        }
72
        if (\count($news) > 0) {
73
            $ret = [];
74
            for ($i = 0, $iMax = \count($news); $i < $iMax; ++$i) {
75
                $ret[$i]['title']       = $this->modname . ': ' . $myts->undoHtmlSpecialChars($news[$i]->title());
76
                $ret[$i]['link']        = XOOPS_URL . '/modules/news/article.php?storyid=' . $news[$i]->storyid();
77
                $ret[$i]['guid']        = XOOPS_URL . '/modules/news/article.php?storyid=' . $news[$i]->storyid();
78
                $ret[$i]['timestamp']   = $news[$i]->published();
79
                $ret[$i]['description'] = $news[$i]->hometext();
80
                $ret[$i]['category']    = $this->modname;
81
                $ret[$i]['domain']      = XOOPS_URL . '/modules/' . $this->dirname . '/';
82
            }
83
        }
84
85
        return $ret;
86
    }
87
}
88