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 __DIR__ . '/../../mainfile.php'; |
||
82 | |||
83 | //$XOOPS_URL = XOOPS_URL; |
||
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' |
||
128 | || $xoopsOption['storytopic'] > 0 |
||
129 | ) { |
||
130 | $showclassic = 1; |
||
131 | } else { |
||
132 | $showclassic = 0; |
||
133 | } |
||
134 | $firsttitle = ''; |
||
135 | $topictitle = ''; |
||
136 | $myts = MyTextSanitizer::getInstance(); |
||
137 | $sfiles = new sFiles(); |
||
138 | |||
139 | $column_count = $xoopsModuleConfig['columnmode']; |
||
140 | |||
141 | if ($showclassic) { |
||
142 | $GLOBALS['xoopsOption']['template_main'] = 'news_index.tpl'; |
||
143 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
144 | $xt = new NewsTopic(); |
||
145 | |||
146 | $xoopsTpl->assign('columnwidth', (int)(1 / $column_count * 100)); |
||
147 | View Code Duplication | if ($xoopsModuleConfig['ratenews']) { |
|
148 | $xoopsTpl->assign('rates', true); |
||
149 | $xoopsTpl->assign('lang_ratingc', _NW_RATINGC); |
||
150 | $xoopsTpl->assign('lang_ratethisnews', _NW_RATETHISNEWS); |
||
151 | } else { |
||
152 | $xoopsTpl->assign('rates', false); |
||
153 | } |
||
154 | |||
155 | if ($xoopsOption['storytopic']) { |
||
156 | $xt->getTopic($xoopsOption['storytopic']); |
||
157 | $xoopsTpl->assign('topic_description', $xt->topic_description('S')); |
||
158 | $xoopsTpl->assign('topic_color', '#' . $xt->topic_color('S')); |
||
159 | $topictitle = $xt->topic_title(); |
||
160 | } |
||
161 | |||
162 | if ($xoopsModuleConfig['displaynav'] == 1) { |
||
163 | $xoopsTpl->assign('displaynav', true); |
||
164 | |||
165 | $allTopics = $xt->getAllTopics($xoopsModuleConfig['restrictindex']); |
||
166 | $topic_tree = new MyXoopsObjectTree($allTopics, 'topic_id', 'topic_pid'); |
||
167 | $topic_select = $topic_tree->makeSelBox('storytopic', 'topic_title', '-- ', $xoopsOption['storytopic'], true); |
||
168 | |||
169 | $xoopsTpl->assign('topic_select', $topic_select); |
||
170 | $storynum_options = ''; |
||
171 | for ($i = 5; $i <= 30; $i += 5) { |
||
172 | $sel = ''; |
||
173 | if ($i == $xoopsOption['storynum']) { |
||
174 | $sel = ' selected'; |
||
175 | } |
||
176 | $storynum_options .= '<option value="' . $i . '"' . $sel . '>' . $i . '</option>'; |
||
177 | } |
||
178 | $xoopsTpl->assign('storynum_options', $storynum_options); |
||
179 | } else { |
||
180 | $xoopsTpl->assign('displaynav', false); |
||
181 | } |
||
182 | if ($xoopsOption['storytopic'] == 0) { |
||
183 | $topic_frontpage = true; |
||
184 | } else { |
||
185 | $topic_frontpage = false; |
||
186 | } |
||
187 | $sarray = NewsStory::getAllPublished($xoopsOption['storynum'], $start, $xoopsModuleConfig['restrictindex'], $xoopsOption['storytopic'], 0, true, |
||
188 | 'published', $topic_frontpage); |
||
189 | |||
190 | $scount = count($sarray); |
||
191 | $xoopsTpl->assign('story_count', $scount); |
||
192 | $k = 0; |
||
193 | $columns = array(); |
||
194 | if ($scount > 0) { |
||
195 | $storieslist = array(); |
||
196 | foreach ($sarray as $storyid => $thisstory) { |
||
197 | $storieslist[] = $thisstory->storyid(); |
||
198 | } |
||
199 | $filesperstory = $sfiles->getCountbyStories($storieslist); |
||
200 | |||
201 | foreach ($sarray as $storyid => $thisstory) { |
||
202 | $filescount = array_key_exists($thisstory->storyid(), $filesperstory) ? $filesperstory[$thisstory->storyid()] : 0; |
||
203 | $story = $thisstory->prepare2show($filescount); |
||
204 | // The line below can be used to display a Permanent Link image |
||
205 | // $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>"; |
||
206 | $story['news_title'] = $story['title']; |
||
207 | $story['title'] = $thisstory->textlink() . ' : ' . $story['title']; |
||
208 | $story['topic_title'] = $thisstory->textlink(); |
||
209 | $story['subtitle'] = $thisstory->subtitle(); |
||
210 | $story['topic_color'] = '#' . $myts->displayTarea($thisstory->topic_color); |
||
211 | if ($firsttitle === '') { |
||
212 | $firsttitle = $thisstory->topic_title() . ' - ' . $thisstory->title(); |
||
213 | } |
||
214 | $columns[$k][] = $story; |
||
215 | ++$k; |
||
216 | if ($k == $column_count) { |
||
217 | $k = 0; |
||
218 | } |
||
219 | } |
||
220 | } |
||
221 | $xoopsTpl->assign('columns', $columns); |
||
222 | unset($story); |
||
223 | |||
224 | $totalcount = NewsStory::countPublishedByTopic($xoopsOption['storytopic'], $xoopsModuleConfig['restrictindex']); |
||
225 | if ($totalcount > $scount) { |
||
226 | include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
227 | $pagenav = new XoopsPageNav($totalcount, $xoopsOption['storynum'], $start, 'start', 'storytopic=' . $xoopsOption['storytopic']); |
||
228 | if (news_isbot()) { // A bot is reading the news, we are going to show it all the links so that he can read everything |
||
229 | $xoopsTpl->assign('pagenav', $pagenav->renderNav($totalcount)); |
||
230 | } else { |
||
231 | $xoopsTpl->assign('pagenav', $pagenav->renderNav()); |
||
232 | } |
||
233 | } else { |
||
234 | $xoopsTpl->assign('pagenav', ''); |
||
235 | } |
||
236 | } else { // Affichage par sujets |
||
237 | $GLOBALS['xoopsOption']['template_main'] = 'news_by_topic.tpl'; |
||
238 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
239 | $xoopsTpl->assign('columnwidth', (int)(1 / $column_count * 100)); |
||
240 | View Code Duplication | if ($xoopsModuleConfig['ratenews']) { |
|
241 | $xoopsTpl->assign('rates', true); |
||
242 | $xoopsTpl->assign('lang_ratingc', _NW_RATINGC); |
||
243 | $xoopsTpl->assign('lang_ratethisnews', _NW_RATETHISNEWS); |
||
244 | } else { |
||
245 | $xoopsTpl->assign('rates', false); |
||
246 | } |
||
247 | |||
248 | $xt = new NewsTopic(); |
||
249 | $alltopics = $xt->getTopicsList(true, $xoopsModuleConfig['restrictindex']); |
||
250 | $smarty_topics = array(); |
||
251 | $topicstories = array(); |
||
252 | |||
253 | foreach ($alltopics as $topicid => $topic) { |
||
254 | $allstories = NewsStory::getAllPublished($xoopsModuleConfig['storyhome'], 0, $xoopsModuleConfig['restrictindex'], $topicid); |
||
255 | $storieslist = array(); |
||
256 | foreach ($allstories as $thisstory) { |
||
0 ignored issues
–
show
|
|||
257 | $storieslist[] = $thisstory->storyid(); |
||
258 | } |
||
259 | $filesperstory = $sfiles->getCountbyStories($storieslist); |
||
260 | foreach ($allstories as $thisstory) { |
||
261 | $filescount = array_key_exists($thisstory->storyid(), $filesperstory) ? $filesperstory[$thisstory->storyid()] : 0; |
||
262 | $story = $thisstory->prepare2show($filescount); |
||
263 | $story['topic_title'] = $thisstory->textlink(); |
||
264 | $story['news_title'] = $story['title']; |
||
265 | $topicstories[$topicid][] = $story; |
||
266 | } |
||
267 | if (isset($topicstories[$topicid])) { |
||
268 | $smarty_topics[$topicstories[$topicid][0]['posttimestamp']] = array( |
||
269 | 'title' => $topic['title'], |
||
270 | 'stories' => $topicstories[$topicid], |
||
271 | 'id' => $topicid, |
||
272 | 'topic_color' => $topic['color'] |
||
273 | ); |
||
274 | } |
||
275 | } |
||
276 | |||
277 | krsort($smarty_topics); |
||
278 | $columns = array(); |
||
279 | $i = 0; |
||
280 | foreach ($smarty_topics as $thistopictimestamp => $thistopic) { |
||
281 | $columns[$i][] = $thistopic; |
||
282 | ++$i; |
||
283 | if ($i == $column_count) { |
||
284 | $i = 0; |
||
285 | } |
||
286 | } |
||
287 | //$xoopsTpl->assign('topics', $smarty_topics); |
||
288 | $xoopsTpl->assign('columns', $columns); |
||
289 | } |
||
290 | |||
291 | $xoopsTpl->assign('advertisement', news_getmoduleoption('advertisement')); |
||
292 | |||
293 | /** |
||
294 | * Create the Meta Datas |
||
295 | */ |
||
296 | news_CreateMetaDatas(); |
||
297 | |||
298 | /** |
||
299 | * Create a clickable path from the root to the current topic (if we are viewing a topic) |
||
300 | * Actually this is not used in the default templates but you can use it as you want |
||
301 | * You can comment the code to optimize the requests count |
||
302 | */ |
||
303 | if ($xoopsOption['storytopic']) { |
||
304 | include_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstree.php'; |
||
305 | $mytree = new MyXoopsTree($xoopsDB->prefix('news_topics'), 'topic_id', 'topic_pid'); |
||
306 | $topicpath = $mytree->getNicePathFromId($xoopsOption['storytopic'], 'topic_title', 'index.php?op=1'); |
||
307 | $xoopsTpl->assign('topic_path', $topicpath); |
||
308 | unset($mytree); |
||
309 | } |
||
310 | |||
311 | /** |
||
312 | * Create a link for the RSS feed (if the module's option is activated) |
||
313 | */ |
||
314 | /** @var XoopsModuleHandler $moduleHandler */ |
||
315 | $moduleHandler = xoops_getHandler('module'); |
||
316 | $moduleInfo = $moduleHandler->get($GLOBALS['xoopsModule']->getVar('mid')); |
||
317 | if ($xoopsModuleConfig['topicsrss'] && $xoopsOption['storytopic']) { |
||
318 | $link = sprintf("<a href='%s' title='%s'><img src='%s' border='0' alt='%s'></a>", |
||
319 | XOOPS_URL . '/modules/news/backendt.php?topicid=' . $xoopsOption['storytopic'], _NW_RSSFEED, |
||
320 | XOOPS_URL . '/' . $moduleInfo->getInfo('icons16') . '/rss.gif', _NW_RSSFEED); |
||
321 | $xoopsTpl->assign('topic_rssfeed_link', $link); |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * Assign page's title |
||
326 | */ |
||
327 | if ($firsttitle !== '') { |
||
328 | $xoopsTpl->assign('xoops_pagetitle', $firsttitle . ' - ' . $xoopsModule->name('s')); |
||
329 | } else { |
||
330 | if ($topictitle !== '') { |
||
331 | $xoopsTpl->assign('xoops_pagetitle', $topictitle); |
||
332 | } else { |
||
333 | $xoopsTpl->assign('xoops_pagetitle', $xoopsModule->name('s')); |
||
334 | } |
||
335 | } |
||
336 | |||
337 | $xoopsTpl->assign('lang_go', _GO); |
||
338 | $xoopsTpl->assign('lang_on', _ON); |
||
339 | $xoopsTpl->assign('lang_printerpage', _NW_PRINTERFRIENDLY); |
||
340 | $xoopsTpl->assign('lang_sendstory', _NW_SENDSTORY); |
||
341 | $xoopsTpl->assign('lang_postedby', _POSTEDBY); |
||
342 | $xoopsTpl->assign('lang_reads', _READS); |
||
343 | $xoopsTpl->assign('lang_morereleases', _NW_MORERELEASES); |
||
344 | include_once XOOPS_ROOT_PATH . '/footer.php'; |
||
345 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.