| Conditions | 5 |
| Paths | 9 |
| Total Lines | 111 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 93 | public function getUserRss($moduleDirname) |
||
| 94 | { |
||
| 95 | $table = $this->getTable(); |
||
| 96 | $tableName = $table->getVar('table_name'); |
||
| 97 | $fppf = ''; |
||
| 98 | $fpmf = ''; |
||
| 99 | $fieldId = ''; |
||
| 100 | $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
||
| 101 | foreach (\array_keys($fields) as $f) { |
||
| 102 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 103 | $fieldMain[] = $fields[$f]->getVar('field_main'); |
||
| 104 | $fieldParent[] = $fields[$f]->getVar('field_parent'); |
||
| 105 | |||
| 106 | if (0 == $f) { |
||
| 107 | $fieldId = $fieldName; |
||
| 108 | } |
||
| 109 | if (\in_array(1, $fieldMain)) { |
||
|
|
|||
| 110 | $fpmf = $fieldName; |
||
| 111 | } |
||
| 112 | if (\in_array(1, $fieldParent)) { |
||
| 113 | $fppf = $fieldName; |
||
| 114 | } else { |
||
| 115 | $fppf = 'cid'; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | $ret = $this->pc->getPhpCodeUseNamespace(['Xmf', 'Request']); |
||
| 120 | $ret .= $this->getRequire(); |
||
| 121 | |||
| 122 | $ret .= <<<EOT |
||
| 123 | |||
| 124 | \${$fppf} = Request::getInt('{$fppf}', 0, 'GET'); |
||
| 125 | require_once \XOOPS_ROOT_PATH.'/class/template.php'; |
||
| 126 | if (\\function_exists('mb_http_output')) { |
||
| 127 | mb_http_output('pass'); |
||
| 128 | } |
||
| 129 | //header ('Content-Type:text/xml; charset=UTF-8'); |
||
| 130 | \$xoopsModuleConfig['utf8'] = false; |
||
| 131 | |||
| 132 | \$tpl = new \XoopsTpl(); |
||
| 133 | \$tpl->xoops_setCaching(2); //1 = Cache global, 2 = Cache individual (for template) |
||
| 134 | \$tpl->xoops_setCacheTime(\$helper->getConfig('timecacherss')*60); // Time of the cache on seconds |
||
| 135 | \$categories = {$moduleDirname}MyGetItemIds('{$moduleDirname}_view', '{$moduleDirname}'); |
||
| 136 | \$criteria = new \CriteriaCompo(); |
||
| 137 | |||
| 138 | \$criteria->add(new \Criteria('cat_status', 0, '!=')); |
||
| 139 | \$criteria->add(new \Criteria('{$fppf}', '(' . \implode(',', \$categories) . ')','IN')); |
||
| 140 | if (0 != \${$fppf}){ |
||
| 141 | \$criteria->add(new \Criteria('{$fppf}', \${$fppf})); |
||
| 142 | \${$tableName} = \${$tableName}Handler->get(\${$fppf}); |
||
| 143 | \$title = \$xoopsConfig['sitename'] . ' - ' . \$xoopsModule->getVar('name') . ' - ' . \${$tableName}->getVar('{$fpmf}'); |
||
| 144 | } else { |
||
| 145 | \$title = \$xoopsConfig['sitename'] . ' - ' . \$xoopsModule->getVar('name'); |
||
| 146 | } |
||
| 147 | \$criteria->setLimit(\$helper->getConfig('perpagerss')); |
||
| 148 | \$criteria->setSort('date'); |
||
| 149 | \$criteria->setOrder('DESC'); |
||
| 150 | \${$tableName}Arr = \${$tableName}Handler->getAll(\$criteria); |
||
| 151 | unset(\$criteria); |
||
| 152 | |||
| 153 | if (!\$tpl->is_cached('db:{$moduleDirname}_rss.tpl', \${$fppf})) { |
||
| 154 | \$tpl->assign('channel_title', \htmlspecialchars(\$title, ENT_QUOTES)); |
||
| 155 | \$tpl->assign('channel_link', \XOOPS_URL.'/'); |
||
| 156 | \$tpl->assign('channel_desc', \htmlspecialchars(\$xoopsConfig['slogan'], ENT_QUOTES)); |
||
| 157 | \$tpl->assign('channel_lastbuild', \\formatTimestamp(\time(), 'rss')); |
||
| 158 | \$tpl->assign('channel_webmaster', \$xoopsConfig['adminmail']); |
||
| 159 | \$tpl->assign('channel_editor', \$xoopsConfig['adminmail']); |
||
| 160 | \$tpl->assign('channel_category', 'Event'); |
||
| 161 | \$tpl->assign('channel_generator', 'XOOPS - ' . \htmlspecialchars(\$xoopsModule->getVar('{$fpmf}'), ENT_QUOTES)); |
||
| 162 | \$tpl->assign('channel_language', _LANGCODE); |
||
| 163 | if ( 'fr' == _LANGCODE ) { |
||
| 164 | \$tpl->assign('docs', 'http://www.scriptol.fr/rss/RSS-2.0.html'); |
||
| 165 | } else { |
||
| 166 | \$tpl->assign('docs', 'http://cyber.law.harvard.edu/rss/rss.html'); |
||
| 167 | } |
||
| 168 | \$tpl->assign('image_url', \XOOPS_URL . \$xoopsModuleConfig['logorss']); |
||
| 169 | \$dimention = \getimagesize(\XOOPS_ROOT_PATH . \$xoopsModuleConfig['logorss']); |
||
| 170 | if (empty(\$dimention[0])) { |
||
| 171 | \$width = 88; |
||
| 172 | } else { |
||
| 173 | \$width = (\$dimention[0] > 144) ? 144 : \$dimention[0]; |
||
| 174 | } |
||
| 175 | if (empty(\$dimention[1])) { |
||
| 176 | \$height = 31; |
||
| 177 | } else { |
||
| 178 | \$height = (\$dimention[1] > 400) ? 400 : \$dimention[1]; |
||
| 179 | } |
||
| 180 | \$tpl->assign('image_width', \$width); |
||
| 181 | \$tpl->assign('image_height', \$height); |
||
| 182 | foreach (\array_keys(\${$tableName}Arr) as \$i) { |
||
| 183 | \$description = \${$tableName}Arr[\$i]->getVar('description'); |
||
| 184 | //permet d'afficher uniquement la description courte |
||
| 185 | if (false == \strpos(\$description,'[pagebreak]')){ |
||
| 186 | \$description_short = \$description; |
||
| 187 | } else { |
||
| 188 | \$description_short = \substr(\$description,0,\strpos(\$description,'[pagebreak]')); |
||
| 189 | } |
||
| 190 | \$tpl->append('items', ['title' => \htmlspecialchars(\${$tableName}Arr[\$i]->getVar('{$fpmf}'), ENT_QUOTES), |
||
| 191 | 'link' => \XOOPS_URL . '/modules/{$moduleDirname}/single.php?{$fppf}=' . \${$tableName}Arr[\$i]->getVar('{$fppf}') . '&{$fieldId}=' . \${$tableName}Arr[\$i]->getVar('{$fieldId}'), |
||
| 192 | 'guid' => \XOOPS_URL . '/modules/{$moduleDirname}/single.php?{$fppf}=' . \${$tableName}Arr[\$i]->getVar('{$fppf}') . '&{$fieldId}=' . \${$tableName}Arr[\$i]->getVar('{$fieldId}'), |
||
| 193 | 'pubdate' => \\formatTimestamp(\${$tableName}Arr[\$i]->getVar('date'), 'rss'), |
||
| 194 | 'description' => \htmlspecialchars(\$description_short, ENT_QUOTES) |
||
| 195 | ]); |
||
| 196 | } |
||
| 197 | } |
||
| 198 | header('Content-Type:text/xml; charset=' . _CHARSET); |
||
| 199 | \$tpl->display('db:{$moduleDirname}_rss.tpl', \${$fppf}); |
||
| 200 | |||
| 201 | EOT; |
||
| 202 | |||
| 203 | return $ret; |
||
| 204 | } |
||
| 223 |