UserRss   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 187
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 62
dl 0
loc 187
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 11 1
A __construct() 0 6 1
A getInstance() 0 8 2
B getUserRss() 0 107 5
A write() 0 5 1
1
<?php
2
3
namespace XoopsModules\Tdmcreate\Files\User;
4
5
use XoopsModules\Tdmcreate;
6
use XoopsModules\Tdmcreate\Files;
7
8
/**
9
 * You may not change or alter any portion of this comment or credits
10
 * of supporting developers from this source code or any supporting source code
11
 * which is considered copyrighted (c) material of the original comment or credit authors.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
/**
18
 * tdmcreate module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.0
24
 *
25
 * @author          Txmod Xoops http://www.txmodxoops.org
26
 *
27
 */
28
29
/**
30
 * Class UserRss.
31
 */
32
class UserRss extends Files\CreateFile
33
{
34
    /**
35
     * @var mixed
36
     */
37
    private $uxc = null;
38
39
    /**
40
     * @var string
41
     */
42
    private $xc = null;
43
44
    /**
45
     * @var string
46
     */
47
    private $pc = null;
48
49
    /**
50
     * @public function constructor
51
     * @param null
52
     */
53
    public function __construct()
54
    {
55
        parent::__construct();
56
        $this->xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like XoopsModules\Tdmcreate\F...oopsCode::getInstance() of type XoopsModules\Tdmcreate\Files\CreateXoopsCode is incompatible with the declared type string of property $xc.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
57
        $this->pc   = Tdmcreate\Files\CreatePhpCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like XoopsModules\Tdmcreate\F...ePhpCode::getInstance() of type XoopsModules\Tdmcreate\Files\CreatePhpCode is incompatible with the declared type string of property $pc.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
58
        $this->uxc  = UserXoopsCode::getInstance();
59
    }
60
61
    /**
62
     * @static function getInstance
63
     * @param null
64
     * @return UserRss
65
     */
66
    public static function getInstance()
67
    {
68
        static $instance = false;
69
        if (!$instance) {
70
            $instance = new self();
71
        }
72
73
        return $instance;
74
    }
75
76
    /**
77
     * @public function write
78
     * @param string $module
79
     * @param mixed  $table
80
     * @param string $filename
81
     */
82
    public function write($module, $table, $filename)
83
    {
84
        $this->setModule($module);
85
        $this->setTable($table);
86
        $this->setFileName($filename);
87
    }
88
89
    /**
90
     * @public function getUserRss
91
     * @param string $moduleDirname
92
     * @return string
93
     */
94
    public function getUserRss($moduleDirname)
95
    {
96
        $pc        = Tdmcreate\Files\CreatePhpCode::getInstance();
97
        $table     = $this->getTable();
98
        $tableName = $table->getVar('table_name');
99
        $fields    = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
100
        foreach (array_keys($fields) as $f) {
101
            $fieldName     = $fields[$f]->getVar('field_name');
102
            $fieldMain[]   = $fields[$f]->getVar('field_main');
103
            $fieldParent[] = $fields[$f]->getVar('field_parent');
104
105
            if (0 == $f) {
106
                $fieldId = $fieldName;
107
            }
108
            if (in_array(1, $fieldMain)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldMain seems to be defined later in this foreach loop on line 102. Are you sure it is defined here?
Loading history...
109
                $fpmf = $fieldName;
110
            }
111
            if (in_array(1, $fieldParent)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldParent seems to be defined later in this foreach loop on line 103. Are you sure it is defined here?
Loading history...
112
                $fppf = $fieldName;
113
            } else {
114
                $fppf = 'cid';
115
            }
116
        }
117
118
        $ret = $pc->getPhpCodeUseNamespace(['Xmf', 'Request']);
119
        $ret .= $this->getInclude();
120
121
        $ret .= <<<EOT
122
123
\${$fppf} = Request::getInt('{$fppf}', 0, 'GET');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fppf seems to be defined by a foreach iteration on line 100. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
124
include_once XOOPS_ROOT_PATH.'/class/template.php';
125
if (function_exists('mb_http_output')) {
126
    mb_http_output('pass');
127
}
128
//header ('Content-Type:text/xml; charset=UTF-8');
129
\$xoopsModuleConfig['utf8'] = false;
130
131
\$tpl = new \XoopsTpl();
132
\$tpl->xoops_setCaching(2); //1 = Cache global, 2 = Cache individual (for template)
133
\$tpl->xoops_setCacheTime(\$helper->getConfig('timecacherss')*60); // Time of the cache on seconds
134
\$categories = {$moduleDirname}MyGetItemIds('{$moduleDirname}_view', '{$moduleDirname}');
135
\$criteria = new \CriteriaCompo();
136
137
\$criteria->add(new \Criteria('cat_status', 0, '!='));
138
\$criteria->add(new \Criteria('{$fppf}', '(' . implode(',', \$categories) . ')','IN'));
139
if (\${$fppf} != 0){
140
    \$criteria->add(new \Criteria('{$fppf}', \${$fppf}));
141
    \${$tableName} = \${$tableName}Handler->get(\${$fppf});
142
    \$title = \$xoopsConfig['sitename'] . ' - ' . \$xoopsModule->getVar('name') . ' - ' . \${$tableName}->getVar('{$fpmf}');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fpmf does not seem to be defined for all execution paths leading up to this point.
Loading history...
143
} else {
144
    \$title = \$xoopsConfig['sitename'] . ' - ' . \$xoopsModule->getVar('name');
145
}
146
\$criteria->setLimit(\$helper->getConfig('perpagerss'));
147
\$criteria->setSort('date');
148
\$criteria->setOrder('DESC');
149
\${$tableName}Arr = \${$tableName}Handler->getAll(\$criteria);
150
unset(\$criteria);
151
152
if (!\$tpl->is_cached('db:{$moduleDirname}_rss.tpl', \${$fppf})) {
153
    \$tpl->assign('channel_title', htmlspecialchars(\$title, ENT_QUOTES));
154
    \$tpl->assign('channel_link', XOOPS_URL.'/');
155
    \$tpl->assign('channel_desc', htmlspecialchars(\$xoopsConfig['slogan'], ENT_QUOTES));
156
    \$tpl->assign('channel_lastbuild', formatTimestamp(time(), 'rss'));
157
    \$tpl->assign('channel_webmaster', \$xoopsConfig['adminmail']);
158
    \$tpl->assign('channel_editor', \$xoopsConfig['adminmail']);
159
    \$tpl->assign('channel_category', 'Event');
160
    \$tpl->assign('channel_generator', 'XOOPS - ' . htmlspecialchars(\$xoopsModule->getVar('{$fpmf}'), ENT_QUOTES));
161
    \$tpl->assign('channel_language', _LANGCODE);
162
    if ( _LANGCODE == 'fr' ) {
163
        \$tpl->assign('docs', 'http://www.scriptol.fr/rss/RSS-2.0.html');
164
    } else {
165
        \$tpl->assign('docs', 'http://cyber.law.harvard.edu/rss/rss.html');
166
    }
167
    \$tpl->assign('image_url', XOOPS_URL . \$xoopsModuleConfig['logorss']);
168
    \$dimention = getimagesize(XOOPS_ROOT_PATH . \$xoopsModuleConfig['logorss']);
169
    if (empty(\$dimention[0])) {
170
        \$width = 88;
171
    } else {
172
       \$width = (\$dimention[0] > 144) ? 144 : \$dimention[0];
173
    }
174
    if (empty(\$dimention[1])) {
175
        \$height = 31;
176
    } else {
177
        \$height = (\$dimention[1] > 400) ? 400 : \$dimention[1];
178
    }
179
    \$tpl->assign('image_width', \$width);
180
    \$tpl->assign('image_height', \$height);
181
    foreach (array_keys(\${$tableName}Arr) as \$i) {
182
        \$description = \${$tableName}Arr[\$i]->getVar('description');
183
        //permet d'afficher uniquement la description courte
184
        if (strpos(\$description,'[pagebreak]')==false){
185
            \$description_short = \$description;
186
        } else {
187
            \$description_short = substr(\$description,0,strpos(\$description,'[pagebreak]'));
188
        }
189
        \$tpl->append('items', array('title' => htmlspecialchars(\${$tableName}Arr[\$i]->getVar('{$fpmf}'), ENT_QUOTES),
190
                                    'link' => XOOPS_URL . '/modules/{$moduleDirname}/single.php?{$fppf}=' . \${$tableName}Arr[\$i]->getVar('{$fppf}') . '&amp;{$fieldId}=' . \${$tableName}Arr[\$i]->getVar('{$fieldId}'),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldId does not seem to be defined for all execution paths leading up to this point.
Loading history...
191
                                    'guid' => XOOPS_URL . '/modules/{$moduleDirname}/single.php?{$fppf}=' . \${$tableName}Arr[\$i]->getVar('{$fppf}') . '&amp;{$fieldId}=' . \${$tableName}Arr[\$i]->getVar('{$fieldId}'),
192
                                    'pubdate' => formatTimestamp(\${$tableName}Arr[\$i]->getVar('date'), 'rss'),
193
                                    'description' => htmlspecialchars(\$description_short, ENT_QUOTES)));
194
    }
195
}
196
header('Content-Type:text/xml; charset=' . _CHARSET);
197
\$tpl->display('db:{$moduleDirname}_rss.tpl', \${$fppf});
198
EOT;
199
200
        return $ret;
201
    }
202
203
    /**
204
     * @public function render
205
     * @param null
206
     * @return bool|string
207
     */
208
    public function render()
209
    {
210
        $module        = $this->getModule();
211
        $filename      = $this->getFileName();
212
        $moduleDirname = $module->getVar('mod_dirname');
213
        $language      = $this->getLanguage($moduleDirname, 'MA');
0 ignored issues
show
Unused Code introduced by
The assignment to $language is dead and can be removed.
Loading history...
214
        $content       = $this->getHeaderFilesComments($module);
215
        $content       .= $this->getUserRss($moduleDirname);
216
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
217
218
        return $this->renderFile();
219
    }
220
}
221