Xmlrss   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 51
dl 0
loc 98
rs 10
c 0
b 0
f 0
wmc 11

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A addItem() 0 24 4
A cleanup() 0 11 4
A setVarRss() 0 3 1
1
<?php
2
3
namespace XoopsModules\Newbb;
4
5
/**
6
 * NewBB 5.0x,  the forum module for XOOPS project
7
 *
8
 * @copyright      XOOPS Project (https://xoops.org)
9
 * @license        GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
10
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
11
 * @since          4.00
12
 * @package        module::newbb
13
 */
14
15
16
17
\defined('NEWBB_FUNCTIONS_INI') || require $GLOBALS['xoops']->path('modules/newbb/include/functions.ini.php');
18
//load_functions('locale');
19
20
/**
21
 * Description
22
 *
23
 * @param type $var description
24
 * @return type description
25
 * @link
26
 */
27
class Xmlrss
28
{
29
    public $xml_version;
30
    public $rss_version;
31
    public $xml_encoding;
32
33
    public $channel_title;
34
    public $channel_link;
35
    public $channel_desc;
36
    public $channel_lastbuild;
37
    public $channel_webmaster;
38
    public $channel_editor;
39
    public $channel_category;
40
    public $channel_generator;
41
    public $channel_language;
42
43
    public $image_title;
44
    public $image_url;
45
    public $image_link;
46
    public $image_description;
47
    public $image_height;
48
    public $image_width;
49
50
    public $max_items;
51
    public $max_item_description;
52
    public $items = [];
53
54
    public function __construct()
55
    {
56
        $this->xml_version          = '1.0';
57
        $this->xml_encoding         = empty($GLOBALS['xoopsModuleConfig']['rss_utf8']) ? _CHARSET : 'UTF-8';
58
        $this->rss_version          = '2.0';
59
        $this->image_height         = 31;
60
        $this->image_width          = 88;
61
        $this->max_items            = 10;
62
        $this->max_item_description = 0;
63
        $this->items                = [];
64
    }
65
66
    /**
67
     * @param $var
68
     * @param $val
69
     */
70
    public function setVarRss($var, $val)
71
    {
72
        $this->$var = $this->cleanup($val);
73
    }
74
75
    /**
76
     * @param             $title
77
     * @param             $link
78
     * @param string      $description
79
     * @param string      $label
80
     * @param int|string  $pubdate
81
     * @return bool
82
     */
83
    public function addItem($title, $link, $description = '', $label = '', $pubdate = 0)
84
    {
85
        if (\count($this->items) < $this->max_items) {
86
            if (!empty($label)) {
87
                $label = '[' . $this->cleanup($label) . ']';
88
            }
89
            if (!empty($description)) {
90
                $description = $this->cleanup($description, $this->max_item_description);
91
                //$description .= ' ' . $label;
92
            }
93
            //$description = $label;
94
95
            $title         = $this->cleanup($title) . ' ' . $label;
96
            $pubdate       = $this->cleanup($pubdate);
97
            $this->items[] = [
98
                'title'       => $title,
99
                'link'        => $link,
100
                'guid'        => $link,
101
                'description' => $description,
102
                'pubdate'     => $pubdate,
103
            ];
104
        }
105
106
        return true;
107
    }
108
109
    /**
110
     * @param               $text
111
     * @param int           $trim
112
     * @return mixed|string
113
     */
114
    public function cleanup($text, $trim = 0)
115
    {
116
        if ('utf-8' === mb_strtolower($this->xml_encoding) && \strncasecmp(_CHARSET, $this->xml_encoding, 5)) {
117
            $text = \XoopsLocal::convert_encoding($text, 'utf-8');
118
        }
119
        if (!empty($trim)) {
120
            $text = \xoops_substr($text, 0, (int)$trim);
121
        }
122
        $text = \htmlspecialchars($text, \ENT_QUOTES);
123
124
        return $text;
125
    }
126
}
127