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

Newbb::loadModule()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 12
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
* About this RSSFit plug-in
27
* Author: tuff <http://www.brandycoke.com>
28
* Requirements (Tested with):
29
*  Module: Newbb <https://xoops.org>
30
*  Version: 1.0
31
*  RSSFit verision: 1.2
32
*  XOOPS version: 2.0.13.2
33
*/
34
35
use XoopsModules\Newbb\Helper as PluginHelper;
36
use XoopsModules\Rssfit\{
37
    AbstractPlugin
38
};
39
40
if (!\defined('RSSFIT_ROOT_PATH')) {
41
    exit();
42
}
43
44
/**
45
 * Class Newbb
46
 * @package XoopsModules\Rssfit\Plugins
47
 */
48
final class Newbb extends AbstractPlugin
49
{
50
    public function __construct() {
51
        if (\class_exists(PluginHelper::class)) {
52
            $this->helper = PluginHelper::getInstance();
53
            $this->dirname = $this->helper->dirname();
54
        }
55
    }
56
57
58
    public function grabEntries(\XoopsMySQLDatabase $xoopsDB): ?array
59
    {
60
        require_once XOOPS_ROOT_PATH . '/modules/' . $this->dirname . '/class/class.forumposts.php';
61
        $myts   = \MyTextSanitizer::getInstance();
62
        $ret    = null;
63
        $i      = 0;
64
        $sql    = 'SELECT p.post_id, p.subject, p.post_time, p.forum_id, p.topic_id, p.nohtml, p.nosmiley, f.forum_name, t.post_text FROM '
65
                  . $xoopsDB->prefix('bb_posts')
66
                  . ' p, '
67
                  . $xoopsDB->prefix('bb_forums')
68
                  . ' f, '
69
                  . $xoopsDB->prefix('bb_posts_text')
70
                  . ' t WHERE f.forum_id = p.forum_id AND p.post_id = t.post_id AND f.forum_type != 1 ORDER BY p.post_time DESC';
71
        $result = $xoopsDB->query($sql, $this->grab, 0);
72
        if ($result instanceof \mysqli_result) {
73
            $ret = [];
74
            while (false !== ($row = $xoopsDB->fetchArray($result))) {
75
                $link                   = XOOPS_URL . '/modules/' . $this->dirname . '/viewtopic.php?topic_id=' . $row['topic_id'] . '&amp;forum=' . $row['forum_id'] . '&amp;post_id=' . $row['post_id'] . '#forumpost' . $row['post_id'];
76
                $ret[$i]['title']       = $row['subject'];
77
                $ret[$i]['link']        = $ret[$i]['guid'] = $link;
78
                $ret[$i]['timestamp']   = $row['post_time'];
79
                $ret[$i]['description'] = $myts->displayTarea($row['post_text'], $row['nohtml'] ? 0 : 1, $row['nosmiley'] ? 0 : 1);
80
                $ret[$i]['category']    = $row['forum_name'];
81
                $ret[$i]['domain']      = XOOPS_URL . '/modules/' . $this->dirname . '/viewforum.php?forum=' . $row['forum_id'];
82
                $i++;
83
            }
84
        }
85
        return $ret;
86
    }
87
}
88