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 | // orwah show topictitle in news_item.tpl |
||
225 | View Code Duplication | if (news_getmoduleoption('displaytopictitle') == 1) { |
|
0 ignored issues
–
show
|
|||
226 | $xoopsTpl->assign('displaytopictitle',true); |
||
227 | } else { |
||
228 | $xoopsTpl->assign('displaytopictitle',false); |
||
229 | } |
||
230 | |||
231 | $totalcount = NewsStory::countPublishedByTopic($xoopsOption['storytopic'], $xoopsModuleConfig['restrictindex']); |
||
232 | if ($totalcount > $scount) { |
||
233 | include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
234 | $pagenav = new XoopsPageNav($totalcount, $xoopsOption['storynum'], $start, 'start', 'storytopic=' . $xoopsOption['storytopic']); |
||
235 | if (news_isbot()) { // A bot is reading the news, we are going to show it all the links so that he can read everything |
||
236 | $xoopsTpl->assign('pagenav', $pagenav->renderNav($totalcount)); |
||
237 | } else { |
||
238 | $xoopsTpl->assign('pagenav', $pagenav->renderNav()); |
||
239 | } |
||
240 | } else { |
||
241 | $xoopsTpl->assign('pagenav', ''); |
||
242 | } |
||
243 | } else { // Affichage par sujets |
||
244 | $GLOBALS['xoopsOption']['template_main'] = 'news_by_topic.tpl'; |
||
245 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
246 | $xoopsTpl->assign('columnwidth', (int)(1 / $column_count * 100)); |
||
247 | View Code Duplication | if ($xoopsModuleConfig['ratenews']) { |
|
248 | $xoopsTpl->assign('rates', true); |
||
249 | $xoopsTpl->assign('lang_ratingc', _NW_RATINGC); |
||
250 | $xoopsTpl->assign('lang_ratethisnews', _NW_RATETHISNEWS); |
||
251 | } else { |
||
252 | $xoopsTpl->assign('rates', false); |
||
253 | } |
||
254 | |||
255 | $xt = new NewsTopic(); |
||
256 | $alltopics = $xt->getTopicsList(true, $xoopsModuleConfig['restrictindex']); |
||
257 | $smarty_topics = array(); |
||
258 | $topicstories = array(); |
||
259 | |||
260 | foreach ($alltopics as $topicid => $topic) { |
||
261 | $allstories = NewsStory::getAllPublished($xoopsModuleConfig['storyhome'], 0, $xoopsModuleConfig['restrictindex'], $topicid); |
||
262 | $storieslist = array(); |
||
263 | foreach ($allstories as $thisstory) { |
||
0 ignored issues
–
show
The expression
$allstories of type null|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
264 | $storieslist[] = $thisstory->storyid(); |
||
265 | } |
||
266 | $filesperstory = $sfiles->getCountbyStories($storieslist); |
||
267 | foreach ($allstories as $thisstory) { |
||
268 | $filescount = array_key_exists($thisstory->storyid(), $filesperstory) ? $filesperstory[$thisstory->storyid()] : 0; |
||
269 | $story = $thisstory->prepare2show($filescount); |
||
270 | $story['topic_title'] = $thisstory->textlink(); |
||
271 | $story['news_title'] = $story['title']; |
||
272 | $topicstories[$topicid][] = $story; |
||
273 | } |
||
274 | if (isset($topicstories[$topicid])) { |
||
275 | $smarty_topics[$topicstories[$topicid][0]['posttimestamp']] = array( |
||
276 | 'title' => $topic['title'], |
||
277 | 'stories' => $topicstories[$topicid], |
||
278 | 'id' => $topicid, |
||
279 | 'topic_color' => $topic['color'] |
||
280 | ); |
||
281 | } |
||
282 | } |
||
283 | |||
284 | krsort($smarty_topics); |
||
285 | $columns = array(); |
||
286 | $i = 0; |
||
287 | foreach ($smarty_topics as $thistopictimestamp => $thistopic) { |
||
288 | $columns[$i][] = $thistopic; |
||
289 | ++$i; |
||
290 | if ($i == $column_count) { |
||
291 | $i = 0; |
||
292 | } |
||
293 | } |
||
294 | //$xoopsTpl->assign('topics', $smarty_topics); |
||
295 | $xoopsTpl->assign('columns', $columns); |
||
296 | } |
||
297 | |||
298 | $xoopsTpl->assign('advertisement', news_getmoduleoption('advertisement')); |
||
299 | |||
300 | /** |
||
301 | * Create the Meta Datas |
||
302 | */ |
||
303 | news_CreateMetaDatas(); |
||
304 | |||
305 | /** |
||
306 | * Create a clickable path from the root to the current topic (if we are viewing a topic) |
||
307 | * Actually this is not used in the default templates but you can use it as you want |
||
308 | * You can comment the code to optimize the requests count |
||
309 | */ |
||
310 | if ($xoopsOption['storytopic']) { |
||
311 | include_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstree.php'; |
||
312 | $mytree = new MyXoopsTree($xoopsDB->prefix('news_topics'), 'topic_id', 'topic_pid'); |
||
313 | $topicpath = $mytree->getNicePathFromId($xoopsOption['storytopic'], 'topic_title', 'index.php?op=1'); |
||
314 | $xoopsTpl->assign('topic_path', $topicpath); |
||
315 | unset($mytree); |
||
316 | } |
||
317 | |||
318 | /** |
||
319 | * Create a link for the RSS feed (if the module's option is activated) |
||
320 | */ |
||
321 | /** @var XoopsModuleHandler $moduleHandler */ |
||
322 | $moduleHandler = xoops_getHandler('module'); |
||
323 | $moduleInfo = $moduleHandler->get($GLOBALS['xoopsModule']->getVar('mid')); |
||
324 | if ($xoopsModuleConfig['topicsrss'] && $xoopsOption['storytopic']) { |
||
325 | $link = sprintf("<a href='%s' title='%s'><img src='%s' border='0' alt='%s'></a>", |
||
326 | XOOPS_URL . '/modules/news/backendt.php?topicid=' . $xoopsOption['storytopic'], _NW_RSSFEED, |
||
327 | XOOPS_URL . '/' . $moduleInfo->getInfo('icons16') . '/rss.gif', _NW_RSSFEED); |
||
328 | $xoopsTpl->assign('topic_rssfeed_link', $link); |
||
329 | } |
||
330 | |||
331 | /** |
||
332 | * Assign page's title |
||
333 | */ |
||
334 | if ($firsttitle !== '') { |
||
335 | $xoopsTpl->assign('xoops_pagetitle', $firsttitle . ' - ' . $xoopsModule->name('s')); |
||
336 | } else { |
||
337 | if ($topictitle !== '') { |
||
338 | $xoopsTpl->assign('xoops_pagetitle', $topictitle); |
||
339 | } else { |
||
340 | $xoopsTpl->assign('xoops_pagetitle', $xoopsModule->name('s')); |
||
341 | } |
||
342 | } |
||
343 | |||
344 | $xoopsTpl->assign('lang_go', _GO); |
||
345 | $xoopsTpl->assign('lang_on', _ON); |
||
346 | $xoopsTpl->assign('lang_printerpage', _NW_PRINTERFRIENDLY); |
||
347 | $xoopsTpl->assign('lang_sendstory', _NW_SENDSTORY); |
||
348 | $xoopsTpl->assign('lang_postedby', _POSTEDBY); |
||
349 | $xoopsTpl->assign('lang_reads', _READS); |
||
350 | $xoopsTpl->assign('lang_morereleases', _NW_MORERELEASES); |
||
351 | include_once XOOPS_ROOT_PATH . '/footer.php'; |
||
352 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.