XoopsModules25x /
news
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | // |
||
| 3 | // ------------------------------------------------------------------------ // |
||
| 4 | // XOOPS - PHP Content Management System // |
||
| 5 | // Copyright (c) 2000-2016 XOOPS.org // |
||
| 6 | // <http://xoops.org/> // |
||
| 7 | // ------------------------------------------------------------------------- // |
||
| 8 | // This program is free software; you can redistribute it and/or modify // |
||
| 9 | // it under the terms of the GNU General Public License as published by // |
||
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
||
| 11 | // (at your option) any later version. // |
||
| 12 | // // |
||
| 13 | // You may not change or alter any portion of this comment or credits // |
||
| 14 | // of supporting developers from this source code or any supporting // |
||
| 15 | // source code which is considered copyrighted (c) material of the // |
||
| 16 | // original comment or credit authors. // |
||
| 17 | // // |
||
| 18 | // This program is distributed in the hope that it will be useful, // |
||
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
| 21 | // GNU General Public License for more details. // |
||
| 22 | // // |
||
| 23 | // You should have received a copy of the GNU General Public License // |
||
| 24 | // along with this program; if not, write to the Free Software // |
||
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
| 26 | // ------------------------------------------------------------------------ // |
||
| 27 | /** |
||
| 28 | * Module's index |
||
| 29 | * |
||
| 30 | * This page displays a list of the published articles and can also display the |
||
| 31 | * stories of a particular topic. |
||
| 32 | * |
||
| 33 | * @package News |
||
| 34 | * @author Xoops Modules Dev Team |
||
| 35 | * @copyright (c) XOOPS Project (http://xoops.org) |
||
| 36 | * |
||
| 37 | * Parameters received by this page : |
||
| 38 | * @page_param int storytopic Topic's ID |
||
| 39 | * @page_param int topic_id Topic's ID |
||
| 40 | * @page_param int storynum Number of news per page |
||
| 41 | * @page_param int start First news to display |
||
| 42 | * |
||
| 43 | * @page_title Topic's title - Story's title - Module's name |
||
| 44 | * |
||
| 45 | * @template_name news_index.html or news_by_topic.html |
||
| 46 | * |
||
| 47 | * Template's variables : |
||
| 48 | * For each article |
||
| 49 | * @template_var int id story's ID |
||
| 50 | * @template_var string poster Complete link to the author's profile |
||
| 51 | * @template_var string author_name Author's name according to the module's option called displayname |
||
| 52 | * @template_var int author_uid Author's ID |
||
| 53 | * @template_var float rating New's rating |
||
| 54 | * @template_var int votes number of votes |
||
| 55 | * @template_var int posttimestamp Timestamp representing the published date |
||
| 56 | * @template_var string posttime Formated published date |
||
| 57 | * @template_var string text The introduction's text |
||
| 58 | * @template_var string morelink The link to read the full article (points to article.php) |
||
| 59 | * @template_var string adminlink Link reserved to the admin to edit and delete the news |
||
| 60 | * @template_var string mail_link Link used to send the story's url by email |
||
| 61 | * @template_var string title Story's title presented on the form of a link |
||
| 62 | * @template_var string news_title Just the news title |
||
| 63 | * @template_var string topic_title Just the topic's title |
||
| 64 | * @template_var int hits Number of times the article was read |
||
| 65 | * @template_var int files_attached Number of files attached to this news |
||
| 66 | * @template_var string attached_link An URL pointing to the attached files |
||
| 67 | * @template_var string topic_color The topic's color |
||
| 68 | * @template_var int columnwidth column's width |
||
| 69 | * @template_var int displaynav To know if we must display the navigation's box |
||
| 70 | * @template_var string lang_go fixed text : Go! |
||
| 71 | * @template_var string lang_morereleases fixed text : More releases in |
||
| 72 | * @template_var string lang_on fixed text : on |
||
| 73 | * @template_var string lang_postedby fixed text : Posted by |
||
| 74 | * @template_var string lang_printerpage fixed text : Printer Friendly Page |
||
| 75 | * @template_var string lang_ratethisnews fixed text : Rate this News |
||
| 76 | * @template_var string lang_ratingc fixed text : Rating: |
||
| 77 | * @template_var string lang_reads fixed text : reads |
||
| 78 | * @template_var string lang_sendstory fixed text : Send this Story to a Friend |
||
| 79 | * @template_var string topic_select contains the topics selector |
||
| 80 | */ |
||
| 81 | include dirname(dirname(__DIR__)) . '/mainfile.php'; |
||
| 82 | |||
| 83 | //$XOOPS_URL = XOOPS_URL; |
||
|
0 ignored issues
–
show
|
|||
| 84 | //$u=$XOOPS_URL.'/uploads/news_xml.php'; |
||
| 85 | // $x = file_get_contents($u); |
||
| 86 | |||
| 87 | include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; |
||
| 88 | include_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php'; |
||
| 89 | include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php'; |
||
| 90 | include_once XOOPS_ROOT_PATH . '/modules/news/include/functions.php'; |
||
| 91 | include_once XOOPS_ROOT_PATH . '/modules/news/class/tree.php'; |
||
| 92 | |||
| 93 | $storytopic = 0; |
||
| 94 | if (isset($_GET['storytopic'])) { |
||
| 95 | $storytopic = (int)$_GET['storytopic']; |
||
| 96 | } else { |
||
| 97 | if (isset($_GET['topic_id'])) { |
||
| 98 | $storytopic = (int)$_GET['topic_id']; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | if ($storytopic) { |
||
| 103 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
| 104 | $gperm_handler = xoops_getHandler('groupperm'); |
||
| 105 | View Code Duplication | if (!$gperm_handler->checkRight('news_view', $storytopic, $groups, $xoopsModule->getVar('mid'))) { |
|
| 106 | redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM); |
||
| 107 | } |
||
| 108 | $xoopsOption['storytopic'] = $storytopic; |
||
| 109 | } else { |
||
| 110 | $xoopsOption['storytopic'] = 0; |
||
| 111 | } |
||
| 112 | if (isset($_GET['storynum'])) { |
||
| 113 | $xoopsOption['storynum'] = (int)$_GET['storynum']; |
||
| 114 | if ($xoopsOption['storynum'] > 30) { |
||
| 115 | $xoopsOption['storynum'] = $xoopsModuleConfig['storyhome']; |
||
| 116 | } |
||
| 117 | } else { |
||
| 118 | $xoopsOption['storynum'] = $xoopsModuleConfig['storyhome']; |
||
| 119 | } |
||
| 120 | |||
| 121 | if (isset($_GET['start'])) { |
||
| 122 | $start = (int)$_GET['start']; |
||
| 123 | } else { |
||
| 124 | $start = 0; |
||
| 125 | } |
||
| 126 | |||
| 127 | if (empty($xoopsModuleConfig['newsdisplay']) || $xoopsModuleConfig['newsdisplay'] === 'Classic' || $xoopsOption['storytopic'] > 0) { |
||
| 128 | $showclassic = 1; |
||
| 129 | } else { |
||
| 130 | $showclassic = 0; |
||
| 131 | } |
||
| 132 | $firsttitle = ''; |
||
| 133 | $topictitle = ''; |
||
| 134 | $myts = MyTextSanitizer::getInstance(); |
||
| 135 | $sfiles = new sFiles(); |
||
| 136 | |||
| 137 | $column_count = $xoopsModuleConfig['columnmode']; |
||
| 138 | |||
| 139 | if ($showclassic) { |
||
| 140 | $xoopsOption['template_main'] = 'news_index.tpl'; |
||
| 141 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 142 | $xt = new NewsTopic(); |
||
| 143 | |||
| 144 | $xoopsTpl->assign('columnwidth', (int)(1 / $column_count * 100)); |
||
| 145 | View Code Duplication | if ($xoopsModuleConfig['ratenews']) { |
|
| 146 | $xoopsTpl->assign('rates', true); |
||
| 147 | $xoopsTpl->assign('lang_ratingc', _NW_RATINGC); |
||
| 148 | $xoopsTpl->assign('lang_ratethisnews', _NW_RATETHISNEWS); |
||
| 149 | } else { |
||
| 150 | $xoopsTpl->assign('rates', false); |
||
| 151 | } |
||
| 152 | |||
| 153 | if ($xoopsOption['storytopic']) { |
||
| 154 | $xt->getTopic($xoopsOption['storytopic']); |
||
| 155 | $xoopsTpl->assign('topic_description', $xt->topic_description('S')); |
||
| 156 | $xoopsTpl->assign('topic_color', '#' . $xt->topic_color('S')); |
||
| 157 | $topictitle = $xt->topic_title(); |
||
| 158 | } |
||
| 159 | |||
| 160 | if ($xoopsModuleConfig['displaynav'] == 1) { |
||
| 161 | $xoopsTpl->assign('displaynav', true); |
||
| 162 | |||
| 163 | $allTopics = $xt->getAllTopics($xoopsModuleConfig['restrictindex']); |
||
| 164 | $topic_tree = new MyXoopsObjectTree($allTopics, 'topic_id', 'topic_pid'); |
||
| 165 | $topic_select = $topic_tree->makeSelBox('storytopic', 'topic_title', '-- ', $xoopsOption['storytopic'], true); |
||
| 166 | |||
| 167 | $xoopsTpl->assign('topic_select', $topic_select); |
||
| 168 | $storynum_options = ''; |
||
| 169 | for ($i = 5; $i <= 30; $i += 5) { |
||
| 170 | $sel = ''; |
||
| 171 | if ($i == $xoopsOption['storynum']) { |
||
| 172 | $sel = ' selected="selected"'; |
||
| 173 | } |
||
| 174 | $storynum_options .= '<option value="' . $i . '"' . $sel . '>' . $i . '</option>'; |
||
| 175 | } |
||
| 176 | $xoopsTpl->assign('storynum_options', $storynum_options); |
||
| 177 | } else { |
||
| 178 | $xoopsTpl->assign('displaynav', false); |
||
| 179 | } |
||
| 180 | if ($xoopsOption['storytopic'] == 0) { |
||
| 181 | $topic_frontpage = true; |
||
| 182 | } else { |
||
| 183 | $topic_frontpage = false; |
||
| 184 | } |
||
| 185 | $sarray = NewsStory::getAllPublished($xoopsOption['storynum'], $start, $xoopsModuleConfig['restrictindex'], $xoopsOption['storytopic'], 0, true, 'published', $topic_frontpage); |
||
| 186 | |||
| 187 | $scount = count($sarray); |
||
| 188 | $xoopsTpl->assign('story_count', $scount); |
||
| 189 | $k = 0; |
||
| 190 | $columns = array(); |
||
| 191 | if ($scount > 0) { |
||
| 192 | $storieslist = array(); |
||
| 193 | foreach ($sarray as $storyid => $thisstory) { |
||
| 194 | $storieslist[] = $thisstory->storyid(); |
||
| 195 | } |
||
| 196 | $filesperstory = $sfiles->getCountbyStories($storieslist); |
||
| 197 | |||
| 198 | foreach ($sarray as $storyid => $thisstory) { |
||
| 199 | $filescount = array_key_exists($thisstory->storyid(), $filesperstory) ? $filesperstory[$thisstory->storyid()] : 0; |
||
| 200 | $story = $thisstory->prepare2show($filescount); |
||
| 201 | // The line below can be used to display a Permanent Link image |
||
| 202 | // $story['title'] .= " <a href='".XOOPS_URL."/modules/news/article.php?storyid=".$sarray[$i]->storyid()."'><img src='".XOOPS_URL."/modules/news/assets/images/x.gif' alt='Permanent Link' /></a>"; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
54% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 203 | $story['news_title'] = $story['title']; |
||
| 204 | $story['title'] = $thisstory->textlink() . ' : ' . $story['title']; |
||
| 205 | $story['topic_title'] = $thisstory->textlink(); |
||
| 206 | $story['topic_color'] = '#' . $myts->displayTarea($thisstory->topic_color); |
||
| 207 | if ($firsttitle == '') { |
||
| 208 | $firsttitle = $thisstory->topic_title() . ' - ' . $thisstory->title(); |
||
| 209 | } |
||
| 210 | $columns[$k][] = $story; |
||
| 211 | ++$k; |
||
| 212 | if ($k == $column_count) { |
||
| 213 | $k = 0; |
||
| 214 | } |
||
| 215 | } |
||
| 216 | } |
||
| 217 | $xoopsTpl->assign('columns', $columns); |
||
| 218 | unset($story); |
||
| 219 | |||
| 220 | $totalcount = NewsStory::countPublishedByTopic($xoopsOption['storytopic'], $xoopsModuleConfig['restrictindex']); |
||
|
0 ignored issues
–
show
Are you sure the assignment to
$totalcount is correct as \NewsStory::countPublish...onfig['restrictindex']) (which targets NewsStory::countPublishedByTopic()) seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 221 | if ($totalcount > $scount) { |
||
| 222 | include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
| 223 | $pagenav = new XoopsPageNav($totalcount, $xoopsOption['storynum'], $start, 'start', 'storytopic=' . $xoopsOption['storytopic']); |
||
| 224 | if (news_isbot()) { // A bot is reading the news, we are going to show it all the links so that he can read everything |
||
| 225 | $xoopsTpl->assign('pagenav', $pagenav->renderNav($totalcount)); |
||
| 226 | } else { |
||
| 227 | $xoopsTpl->assign('pagenav', $pagenav->renderNav()); |
||
| 228 | } |
||
| 229 | } else { |
||
| 230 | $xoopsTpl->assign('pagenav', ''); |
||
| 231 | } |
||
| 232 | } else { // Affichage par sujets |
||
| 233 | $xoopsOption['template_main'] = 'news_by_topic.tpl'; |
||
| 234 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 235 | $xoopsTpl->assign('columnwidth', (int)(1 / $column_count * 100)); |
||
| 236 | View Code Duplication | if ($xoopsModuleConfig['ratenews']) { |
|
| 237 | $xoopsTpl->assign('rates', true); |
||
| 238 | $xoopsTpl->assign('lang_ratingc', _NW_RATINGC); |
||
| 239 | $xoopsTpl->assign('lang_ratethisnews', _NW_RATETHISNEWS); |
||
| 240 | } else { |
||
| 241 | $xoopsTpl->assign('rates', false); |
||
| 242 | } |
||
| 243 | |||
| 244 | $xt = new NewsTopic(); |
||
| 245 | $alltopics =& $xt->getTopicsList(true, $xoopsModuleConfig['restrictindex']); |
||
| 246 | $smarty_topics = array(); |
||
| 247 | $topicstories = array(); |
||
| 248 | |||
| 249 | foreach ($alltopics as $topicid => $topic) { |
||
| 250 | $allstories = NewsStory::getAllPublished($xoopsModuleConfig['storyhome'], 0, $xoopsModuleConfig['restrictindex'], $topicid); |
||
| 251 | $storieslist = array(); |
||
| 252 | foreach ($allstories as $thisstory) { |
||
| 253 | $storieslist[] = $thisstory->storyid(); |
||
| 254 | } |
||
| 255 | $filesperstory = $sfiles->getCountbyStories($storieslist); |
||
| 256 | foreach ($allstories as $thisstory) { |
||
| 257 | $filescount = array_key_exists($thisstory->storyid(), $filesperstory) ? $filesperstory[$thisstory->storyid()] : 0; |
||
| 258 | $story = $thisstory->prepare2show($filescount); |
||
| 259 | $story['topic_title'] = $thisstory->textlink(); |
||
| 260 | $story['news_title'] = $story['title']; |
||
| 261 | $topicstories[$topicid][] = $story; |
||
| 262 | } |
||
| 263 | if (isset($topicstories[$topicid])) { |
||
| 264 | $smarty_topics[$topicstories[$topicid][0]['posttimestamp']] = array('title' => $topic['title'], 'stories' => $topicstories[$topicid], 'id' => $topicid, 'topic_color' => $topic['color']); |
||
| 265 | } |
||
| 266 | } |
||
| 267 | |||
| 268 | krsort($smarty_topics); |
||
| 269 | $columns = array(); |
||
| 270 | $i = 0; |
||
| 271 | foreach ($smarty_topics as $thistopictimestamp => $thistopic) { |
||
| 272 | $columns[$i][] = $thistopic; |
||
| 273 | ++$i; |
||
| 274 | if ($i == $column_count) { |
||
| 275 | $i = 0; |
||
| 276 | } |
||
| 277 | } |
||
| 278 | //$xoopsTpl->assign('topics', $smarty_topics); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
80% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 279 | $xoopsTpl->assign('columns', $columns); |
||
| 280 | } |
||
| 281 | |||
| 282 | $xoopsTpl->assign('advertisement', news_getmoduleoption('advertisement')); |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Create the Meta Datas |
||
| 286 | */ |
||
| 287 | news_CreateMetaDatas(); |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Create a clickable path from the root to the current topic (if we are viewing a topic) |
||
| 291 | * Actually this is not used in the default templates but you can use it as you want |
||
| 292 | * You can comment the code to optimize the requests count |
||
| 293 | */ |
||
| 294 | if ($xoopsOption['storytopic']) { |
||
| 295 | include_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstree.php'; |
||
| 296 | $mytree = new MyXoopsTree($xoopsDB->prefix('news_topics'), 'topic_id', 'topic_pid'); |
||
| 297 | $topicpath = $mytree->getNicePathFromId($xoopsOption['storytopic'], 'topic_title', 'index.php?op=1'); |
||
| 298 | $xoopsTpl->assign('topic_path', $topicpath); |
||
| 299 | unset($mytree); |
||
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Create a link for the RSS feed (if the module's option is activated) |
||
| 304 | */ |
||
| 305 | $moduleInfo = $module_handler->get($xoopsModule->getVar('mid')); |
||
| 306 | if ($xoopsModuleConfig['topicsrss'] && $xoopsOption['storytopic']) { |
||
| 307 | $link = sprintf("<a href='%s' title='%s'><img src='%s' border='0' alt='%s'></a>", XOOPS_URL . '/modules/news/backendt.php?topicid=' . $xoopsOption['storytopic'], _NW_RSSFEED, XOOPS_URL . '/' . $moduleInfo->getInfo('icons16') . '/rss.gif', _NW_RSSFEED); |
||
| 308 | $xoopsTpl->assign('topic_rssfeed_link', $link); |
||
| 309 | } |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Assign page's title |
||
| 313 | */ |
||
| 314 | if ($firsttitle != '') { |
||
| 315 | $xoopsTpl->assign('xoops_pagetitle', $firsttitle . ' - ' . $xoopsModule->name('s')); |
||
| 316 | } else { |
||
| 317 | if ($topictitle != '') { |
||
| 318 | $xoopsTpl->assign('xoops_pagetitle', $topictitle); |
||
| 319 | } else { |
||
| 320 | $xoopsTpl->assign('xoops_pagetitle', $xoopsModule->name('s')); |
||
| 321 | } |
||
| 322 | } |
||
| 323 | |||
| 324 | $xoopsTpl->assign('lang_go', _GO); |
||
| 325 | $xoopsTpl->assign('lang_on', _ON); |
||
| 326 | $xoopsTpl->assign('lang_printerpage', _NW_PRINTERFRIENDLY); |
||
| 327 | $xoopsTpl->assign('lang_sendstory', _NW_SENDSTORY); |
||
| 328 | $xoopsTpl->assign('lang_postedby', _POSTEDBY); |
||
| 329 | $xoopsTpl->assign('lang_reads', _READS); |
||
| 330 | $xoopsTpl->assign('lang_morereleases', _NW_MORERELEASES); |
||
| 331 | include_once XOOPS_ROOT_PATH . '/footer.php'; |
||
| 332 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.