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

Comments::loadModule()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 14
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
use Criteria;
18
use CriteriaCompo;
19
20
/**
21
 * @copyright    XOOPS Project (https://xoops.org)
22
 * @license      GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
23
 * @package      RSSFit - Extendable XML news feed generator
24
 * @author       NS Tai (aka tuff) <http://www.brandycoke.com>
25
 * @author       XOOPS Development Team
26
 */
27
28
/*
29
* About this RSSFit plug-in
30
* Author: Graham Davies (gravies) <http://www.grahamdavies.net>
31
* Modified by: tuff <http://www.brandycoke.com>
32
* Requirements (Tested with):
33
*  Module: any module that support XOOPS system comments
34
*  RSSFit verision: 1.2 / 1.5
35
*  XOOPS version: 2.0.13.2 / 2.2.3
36
*/
37
38
use XoopsModules\Rssfit\{
39
    AbstractPlugin
40
};
41
42
//use XoopsModules\System\Helper as PluginHelper;
43
44
if (!\defined('RSSFIT_ROOT_PATH')) {
45
    exit();
46
}
47
48
/**
49
 * Class Comments
50
 * @package XoopsModules\Rssfit\Plugins
51
 */
52
final class Comments extends AbstractPlugin
53
{
54
    public function __construct() {
55
        $this->dirname = 'system';
56
    }
57
58
    public function loadModule(): ?\XoopsModule
59
    {
60
        $mod = $GLOBALS['module_handler']->getByDirname($this->dirname);
61
        if (!$mod || !$mod->getVar('isactive')) {
62
            return null;
63
        }
64
65
        if (!$mod->getVar('isactive')) {
66
            return null;
67
        }
68
        $this->modname = $mod->getVar('name');
69
        $this->module  = $mod;   // optional, remove this line if there is nothing to do with module info when grabbing entries
70
71
        return $mod;
72
    }
73
74
    public function grabEntries(\XoopsMySQLDatabase $xoopsDB): ?array
75
    {
76
        $myts = \MyTextSanitizer::getInstance();
77
        $ret  = null;
78
        require XOOPS_ROOT_PATH . '/include/comment_constants.php';
79
        /** @var \XoopsCommentHandler $commentHandler */
80
        $commentHandler = \xoops_getHandler('comment');
81
        $criteria       = new CriteriaCompo(new Criteria('com_status', \XOOPS_COMMENT_ACTIVE));
82
        $criteria->setLimit($this->grab);
83
        $criteria->setSort('com_created');
84
        $criteria->setOrder('DESC');
85
        $comments       = $commentHandler->getObjects($criteria, true);
86
        $commentConfig = [];
87
        if (\count($comments) > 0) {
88
            $modules = $GLOBALS['module_handler']->getObjects(new Criteria('hascomments', 1), true);
89
            $ret     = [];
90
            foreach (\array_keys($comments) as $i) {
91
                $mid = $comments[$i]->getVar('com_modid');
92
                if (!isset($commentConfig[$mid])) {
93
                    $commentConfig[$mid] = $modules[$mid]->getInfo('comments');
94
                }
95
                $ret[$i]['title']       = 'Comments: ' . $comments[$i]->getVar('com_title', 'n');
96
                $link                   = XOOPS_URL . '/modules/' . $modules[$mid]->getVar('dirname') . '/' . $commentConfig[$mid]['pageName'] . '?' . $commentConfig[$mid]['itemName'] . '=' . $comments[$i]->getVar('com_itemid') . '&amp;com_id=' . $i . '&amp;com_rootid=' . $comments[$i]->getVar(
97
                        'com_rootid'
98
                    ) . '&amp;' . $comments[$i]->getVar('com_exparams') . '#comment' . $i;
99
                $ret[$i]['link']        = $ret[$i]['guid'] = $link;
100
                $ret[$i]['timestamp']   = $comments[$i]->getVar('com_created');
101
                $ret[$i]['description'] = $comments[$i]->getVar('com_text');
102
                $ret[$i]['category']    = $modules[$mid]->getVar('name', 'n');
103
                $ret[$i]['domain']      = XOOPS_URL . '/modules/' . $modules[$mid]->getVar('dirname') . '/';
104
            }
105
        }
106
107
        return $ret;
108
    }
109
}
110