UserRss   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 188
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 68
dl 0
loc 188
rs 10
c 0
b 0
f 0
wmc 12

5 Methods

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

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...
51
        $this->phpcode = 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 $phpcode.

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...
52
        $this->usercode = UserXoopsCode::getInstance();
53
    }
54
55
    /**
56
     *  @static function getInstance
57
     *  @param null
58
     * @return UserRss
59
     */
60
    public static function getInstance()
61
    {
62
        static $instance = false;
63
        if (!$instance) {
64
            $instance = new self();
65
        }
66
67
        return $instance;
68
    }
69
70
    /**
71
     *  @public function write
72
     *  @param string $module
73
     *  @param mixed $table
74
     *  @param string $filename
75
     */
76
    public function write($module, $table, $filename)
77
    {
78
        $this->setModule($module);
79
        $this->setTable($table);
80
        $this->setFileName($filename);
81
    }
82
83
    /**
84
     *  @public function getUserRss
85
     *  @param string $moduleDirname
86
     *  @param string $language
87
     *
88
     * @return string
89
     */
90
    public function getUserRss($moduleDirname, $language)
0 ignored issues
show
Unused Code introduced by
The parameter $language is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

90
    public function getUserRss($moduleDirname, /** @scrutinizer ignore-unused */ $language)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
91
    {
92
        $table = $this->getTable();
93
        $tableName = $table->getVar('table_name');
94
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
95
        foreach (array_keys($fields) as $f) {
96
            $fieldName = $fields[$f]->getVar('field_name');
97
            $fieldMain[] = $fields[$f]->getVar('field_main');
98
            $fieldParent[] = $fields[$f]->getVar('field_parent');
99
            $rpFieldName = $fieldName;
0 ignored issues
show
Unused Code introduced by
The assignment to $rpFieldName is dead and can be removed.
Loading history...
100
            if (mb_strpos($fieldName, '_')) {
101
                $str = mb_strpos($fieldName, '_');
102
                if (false !== $str) {
103
                    $rpFieldName = mb_substr($fieldName, $str + 1, mb_strlen($fieldName));
104
                }
105
            }
106
            $lpFieldName = mb_substr($fieldName, 0, mb_strpos($fieldName, '_'));
0 ignored issues
show
Unused Code introduced by
The assignment to $lpFieldName is dead and can be removed.
Loading history...
107
            if (0 == $f) {
108
                $fieldId = $fieldName;
109
            }
110
            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 97. Are you sure it is defined here?
Loading history...
111
                $fpmf = $fieldName;
112
            }
113
            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 98. Are you sure it is defined here?
Loading history...
114
                $fppf = $fieldName;
115
            } else {
116
                $fppf = 'cid';
117
            }
118
        }
119
        $ret = $this->getInclude();
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
120
121
        $ret = <<<EOT
122
123
\${$fppf} = {$moduleDirname}_CleanVars(\$_GET, '{$fppf}', 0);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fppf seems to be defined by a foreach iteration on line 95. 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
\${$moduleDirname}->geConfig('utf8') = false;
130
131
\$tpl = new \XoopsTpl();
132
\$tpl->xoops_setCaching(2); //1 = Cache global, 2 = Cache individual (for template)
133
\$tpl->xoops_setCacheTime(\${$moduleDirname}->geConfig('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(\${$moduleDirname}->geConfig('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');
214
        $content = $this->getHeaderFilesComments($module, $filename);
215
        $content .= $this->getUserRss($moduleDirname, $language);
216
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
217
218
        return $this->renderFile();
219
    }
220
}
221