Passed
Push — master ( ae2d71...17f88f )
by Michael
43s queued 14s
created
Labels
Severity
1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright      {@link https://xoops.org/ XOOPS Project}
14
 * @license        {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package
16
 * @since
17
 * @author         XOOPS Development Team
18
 */
19
20
/**
21
 * Module's index
22
 *
23
 * This page displays a list of the published articles and can also display the
24
 * stories of a particular topic.
25
 *
26
 * @package               News
27
 * @author                Xoops Modules Dev Team
28
 * @copyright (c)         XOOPS Project (https://xoops.org)
29
 *
30
 * Parameters received by this page :
31
 * @page_param            int        storytopic                    Topic's ID
32
 * @page_param            int        topic_id                    Topic's ID
33
 * @page_param            int        storynum                    Number of news per page
34
 * @page_param            int        start                        First news to display
35
 *
36
 * @page_title            Topic's title - Story's title - Module's name
37
 *
38
 * @template_name         news_index.html or news_by_topic.html
39
 *
40
 * Template's variables :
41
 * For each article
42
 * @template_var          int        id            story's ID
43
 * @template_var          string    poster        Complete link to the author's profile
44
 * @template_var          string    author_name    Author's name according to the module's option called displayname
45
 * @template_var          int        author_uid    Author's ID
46
 * @template_var          float    rating        New's rating
47
 * @template_var          int        votes        number of votes
48
 * @template_var          int        posttimestamp Timestamp representing the published date
49
 * @template_var          string    posttime        Formated published date
50
 * @template_var          string    text        The introduction's text
51
 * @template_var          string    morelink    The link to read the full article (points to article.php)
52
 * @template_var          string    adminlink    Link reserved to the admin to edit and delete the news
53
 * @template_var          string    mail_link    Link used to send the story's url by email
54
 * @template_var          string    title        Story's title presented on the form of a link
55
 * @template_var          string    news_title    Just the news title
56
 * @template_var          string    topic_title    Just the topic's title
57
 * @template_var          int        hits        Number of times the article was read
58
 * @template_var          int        files_attached    Number of files attached to this news
59
 * @template_var          string    attached_link    An URL pointing to the attached files
60
 * @template_var          string    topic_color    The topic's color
61
 * @template_var          int        columnwidth    column's width
62
 * @template_var          int        displaynav    To know if we must display the navigation's box
63
 * @template_var          string    lang_go        fixed text : Go!
64
 * @template_var          string    lang_morereleases    fixed text : More releases in
65
 * @template_var          string    lang_on        fixed text : on
66
 * @template_var          string    lang_postedby    fixed text : Posted by
67
 * @template_var          string    lang_printerpage    fixed text : Printer Friendly Page
68
 * @template_var          string    lang_ratethisnews    fixed text : Rate this News
69
 * @template_var          string    lang_ratingc    fixed text : Rating:
70
 * @template_var          string    lang_reads        fixed text : reads
71
 * @template_var          string    lang_sendstory    fixed text : Send this Story to a Friend
72
 * @template_var          string     topic_select    contains the topics selector
73
 */
74
75
use Xmf\Module\Admin;
76
use Xmf\Request;
77
use XoopsModules\News;
78
use XoopsModules\News\Files;
79
use XoopsModules\News\NewsStory;
80
use XoopsModules\News\NewsTopic;
81
82
require_once dirname(__DIR__, 2) . '/mainfile.php';
83
84
/** @var News\Helper $helper */
85
$helper = News\Helper::getInstance();
86
87
//$XOOPS_URL = XOOPS_URL;
88
//$u=$XOOPS_URL.'/uploads/news_xml.php';
89
//  $x = file_get_contents($u);
90
91
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
92
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php';
93
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
94
//;
95
//require_once XOOPS_ROOT_PATH . '/modules/news/class/tree.php';
96
97
$moduleDirName = basename(__DIR__);
98
xoops_load('utility', $moduleDirName);
99
$module = \XoopsModule::getByDirname($moduleDirName);
100
101
$storytopic = 0;
102
if (Request::hasVar('storytopic', 'GET')) {
103
    $storytopic = Request::getInt('storytopic', 0, 'GET');
104
} elseif (Request::hasVar('topic_id', 'GET')) {
105
    $storytopic = Request::getInt('topic_id', 0, 'GET');
106
}
107
108
if ($storytopic) {
109
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
110
    /** @var \XoopsGroupPermHandler $grouppermHandler */
111
    $grouppermHandler = xoops_getHandler('groupperm');
112
    if (!$grouppermHandler->checkRight('news_view', $storytopic, $groups, $xoopsModule->getVar('mid'))) {
113
        redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
114
    }
115
    $xoopsOption['storytopic'] = $storytopic;
116
} else {
117
    $xoopsOption['storytopic'] = 0;
118
}
119
if (Request::hasVar('storynum', 'GET')) {
120
    $xoopsOption['storynum'] = Request::getInt('storynum', 0, 'GET');
121
    if ($xoopsOption['storynum'] > 30) {
122
        $xoopsOption['storynum'] = $helper->getConfig('storyhome');
123
    }
124
} else {
125
    $xoopsOption['storynum'] = $helper->getConfig('storyhome');
126
}
127
128
if (Request::hasVar('start', 'GET')) {
129
    $start = Request::getInt('start', 0, 'GET');
130
} else {
131
    $start = 0;
132
}
133
134
if (empty($helper->getConfig('newsdisplay')) || 'Classic' === $helper->getConfig('newsdisplay')
135
    || $xoopsOption['storytopic'] > 0) {
136
    $showclassic = 1;
137
} else {
138
    $showclassic = 0;
139
}
140
$firsttitle = '';
141
$topictitle = '';
142
$myts       = \MyTextSanitizer::getInstance();
143
$sfiles     = new Files();
144
145
$column_count = $helper->getConfig('columnmode');
146
147
if ($showclassic) {
148
    $GLOBALS['xoopsOption']['template_main'] = 'news_index.tpl';
149
    require_once XOOPS_ROOT_PATH . '/header.php';
150
    $xt = new NewsTopic();
151
152
    $xoopsTpl->assign('columnwidth', (int)(1 / $column_count * 100));
153
    if ($helper->getConfig('ratenews')) {
154
        $xoopsTpl->assign('rates', true);
155
        $xoopsTpl->assign('lang_ratingc', _NW_RATINGC);
156
        $xoopsTpl->assign('lang_ratethisnews', _NW_RATETHISNEWS);
157
    } else {
158
        $xoopsTpl->assign('rates', false);
159
    }
160
161
    if ($xoopsOption['storytopic']) {
162
        $xt->getTopic($xoopsOption['storytopic']);
163
        $xoopsTpl->assign('topic_description', $xt->topic_description('S'));
164
        $xoopsTpl->assign('topic_color', '#' . $xt->topic_color('S'));
165
        $topictitle = $xt->topic_title();
166
    }
167
168
    if (1 == $helper->getConfig('displaynav')) {
169
        $xoopsTpl->assign('displaynav', true);
170
171
        $allTopics  = $xt->getAllTopics($helper->getConfig('restrictindex'));
172
        $topic_tree = new \XoopsModules\News\ObjectTree($allTopics, 'topic_id', 'topic_pid');
173
174
        if (News\Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) {
175
            $topic_select = $topic_tree->makeSelectElement('storytopic', 'topic_title', '--', $xoopsOption['storytopic'], true, 0, '', '');
176
            $xoopsTpl->assign('topic_select', $topic_select->render());
177
        } else {
178
            $topic_select = $topic_tree->makeSelBox('storytopic', 'topic_title', '-- ', $xoopsOption['storytopic'], true);
179
            $xoopsTpl->assign('topic_select', $topic_select);
180
        }
181
182
        $storynum_options = '';
183
        for ($i = 5; $i <= 30; $i += 5) {
184
            $sel = '';
185
            if ($i == $xoopsOption['storynum']) {
186
                $sel = ' selected';
187
            }
188
            $storynum_options .= '<option value="' . $i . '"' . $sel . '>' . $i . '</option>';
189
        }
190
        $xoopsTpl->assign('storynum_options', $storynum_options);
191
    } else {
192
        $xoopsTpl->assign('displaynav', false);
193
    }
194
    if (0 == $xoopsOption['storytopic']) {
195
        $topic_frontpage = true;
196
    } else {
197
        $topic_frontpage = false;
198
    }
199
    $sarray = NewsStory::getAllPublished($xoopsOption['storynum'], $start, $helper->getConfig('restrictindex'), $xoopsOption['storytopic'], 0, true, 'published', $topic_frontpage);
200
201
    $scount = count($sarray);
0 ignored issues
show
It seems like $sarray can also be of type null; however, parameter $value of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

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

201
    $scount = count(/** @scrutinizer ignore-type */ $sarray);
Loading history...
202
    $xoopsTpl->assign('story_count', $scount);
203
    $k       = 0;
204
    $columns = [];
205
    if ($scount > 0) {
206
        $storieslist = [];
207
        foreach ($sarray as $storyid => $thisstory) {
208
            $storieslist[] = $thisstory->storyid();
209
        }
210
        $filesperstory = $sfiles->getCountbyStories($storieslist);
211
212
        if (!empty($sarray)) {
213
            foreach ($sarray as $storyid => $thisstory) {
214
                $filescount = array_key_exists($thisstory->storyid(), $filesperstory) ? $filesperstory[$thisstory->storyid()] : 0;
215
                $story      = $thisstory->prepare2show($filescount);
216
                // The line below can be used to display a Permanent Link image
217
                // $story['title'] .= "&nbsp;&nbsp;<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>";
218
                $story['news_title']  = $story['title'];
219
                $story['title']       = $thisstory->textlink() . '&nbsp;:&nbsp;' . $story['title'];
220
                $story['topic_title'] = $thisstory->textlink();
221
                $story['topic_img'] = $thisstory->imglink();
222
                $story['topic_color'] = '#' . $myts->displayTarea($thisstory->topic_color);
223
                if ('' === $firsttitle) {
224
                    $firsttitle = $thisstory->topic_title() . ' - ' . $thisstory->title();
225
                }
226
                $columns[$k][] = $story;
227
                ++$k;
228
                if ($k == $column_count) {
229
                    $k = 0;
230
                }
231
            }
232
        }
233
    }
234
    $xoopsTpl->assign('columns', $columns);
235
    unset($story);
236
237
    // orwah show topictitle in news_item.tpl
238
    if (1 == News\Utility::getModuleOption('displaytopictitle')) {
239
        $xoopsTpl->assign('displaytopictitle', true);
240
    } else {
241
        $xoopsTpl->assign('displaytopictitle', false);
242
    }
243
244
    $totalcount = NewsStory::countPublishedByTopic($xoopsOption['storytopic'], $helper->getConfig('restrictindex'));
245
    if ($totalcount > $scount) {
246
        require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
247
        $pagenav = new \XoopsPageNav($totalcount, $xoopsOption['storynum'], $start, 'start', 'storytopic=' . $xoopsOption['storytopic']);
248
        if (News\Utility::isBot()) { // A bot is reading the news, we are going to show it all the links so that he can read everything
249
            $xoopsTpl->assign('pagenav', $pagenav->renderNav($totalcount));
250
        } else {
251
            $xoopsTpl->assign('pagenav', $pagenav->renderNav());
252
        }
253
    } else {
254
        $xoopsTpl->assign('pagenav', '');
255
    }
256
} else { // Affichage par sujets
257
    $GLOBALS['xoopsOption']['template_main'] = 'news_by_topic.tpl';
258
    require_once XOOPS_ROOT_PATH . '/header.php';
259
    $xoopsTpl->assign('columnwidth', (int)(1 / $column_count * 100));
260
    if ($helper->getConfig('ratenews')) {
261
        $xoopsTpl->assign('rates', true);
262
        $xoopsTpl->assign('lang_ratingc', _NW_RATINGC);
263
        $xoopsTpl->assign('lang_ratethisnews', _NW_RATETHISNEWS);
264
    } else {
265
        $xoopsTpl->assign('rates', false);
266
    }
267
268
    $xt            = new NewsTopic();
269
    $alltopics     = $xt->getTopicsList(true, $helper->getConfig('restrictindex'));
270
    $smarty_topics = [];
271
    $topicstories  = [];
272
273
    foreach ($alltopics as $topicid => $topic) {
274
        $allstories  = NewsStory::getAllPublished($helper->getConfig('storyhome'), 0, $helper->getConfig('restrictindex'), $topicid);
275
        $storieslist = [];
276
        foreach ($allstories as $thisstory) {
277
            $storieslist[] = $thisstory->storyid();
278
        }
279
        $filesperstory = $sfiles->getCountbyStories($storieslist);
280
        foreach ($allstories as $thisstory) {
281
            $filescount               = array_key_exists($thisstory->storyid(), $filesperstory) ? $filesperstory[$thisstory->storyid()] : 0;
282
            $story                    = $thisstory->prepare2show($filescount);
283
            $story['topic_title']     = $thisstory->textlink();
284
            $story['news_title']      = $story['title'];
285
            $topicstories[$topicid][] = $story;
286
        }
287
        if (isset($topicstories[$topicid])) {
288
            $smarty_topics[$topicstories[$topicid][0]['posttimestamp']] = [
289
                'title'       => $topic['title'],
290
                'stories'     => $topicstories[$topicid],
291
                'id'          => $topicid,
292
                'topic_color' => $topic['color'],
293
            ];
294
        }
295
    }
296
297
    krsort($smarty_topics);
298
    $columns = [];
299
    $i       = 0;
300
    foreach ($smarty_topics as $thistopictimestamp => $thistopic) {
301
        $columns[$i][] = $thistopic;
302
        ++$i;
303
        if ($i == $column_count) {
304
            $i = 0;
305
        }
306
    }
307
    //$xoopsTpl->assign('topics', $smarty_topics);
308
    $xoopsTpl->assign('columns', $columns);
309
}
310
311
$xoopsTpl->assign('advertisement', News\Utility::getModuleOption('advertisement'));
312
313
/**
314
 * Create the Meta Datas
315
 */
316
News\Utility::createMetaDatas();
317
318
/**
319
 * Create a clickable path from the root to the current topic (if we are viewing a topic)
320
 * Actually this is not used in the default templates but you can use it as you want
321
 * You can comment the code to optimize the requests count
322
 */
323
if ($xoopsOption['storytopic']) {
324
    // require_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstree.php';
325
    $mytree    = new News\XoopsTree($xoopsDB->prefix('news_topics'), 'topic_id', 'topic_pid');
326
    $topicpath = $mytree->getNicePathFromId($xoopsOption['storytopic'], 'topic_title', 'index.php?op=1');
327
    $xoopsTpl->assign('topic_path', $topicpath);
328
    unset($mytree);
329
}
330
331
/**
332
 * Create a link for the RSS feed (if the module's option is activated)
333
 */
334
/** @var \XoopsModuleHandler $moduleHandler */
335
$moduleHandler = xoops_getHandler('module');
336
$moduleInfo    = $moduleHandler->get($GLOBALS['xoopsModule']->getVar('mid'));
337
if ($helper->getConfig('topicsrss') && $xoopsOption['storytopic']) {
338
    $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, Admin::iconUrl('', 16) . '/rss.gif', _NW_RSSFEED);
339
    $xoopsTpl->assign('topic_rssfeed_link', $link);
340
}
341
342
/**
343
 * Assign page's title
344
 */
345
if ('' !== $firsttitle) {
346
    $xoopsTpl->assign('xoops_pagetitle', $firsttitle . ' - ' . $xoopsModule->name('s'));
347
} elseif ('' !== $topictitle) {
348
    $xoopsTpl->assign('xoops_pagetitle', $topictitle);
349
} else {
350
    $xoopsTpl->assign('xoops_pagetitle', $xoopsModule->name('s'));
351
}
352
353
$xoopsTpl->assign('lang_go', _GO);
354
$xoopsTpl->assign('lang_on', _ON);
355
$xoopsTpl->assign('lang_printerpage', _NW_PRINTERFRIENDLY);
356
$xoopsTpl->assign('lang_sendstory', _NW_SENDSTORY);
357
$xoopsTpl->assign('lang_postedby', _POSTEDBY);
358
$xoopsTpl->assign('lang_reads', _READS);
359
$xoopsTpl->assign('lang_morereleases', _NW_MORERELEASES);
360
require_once XOOPS_ROOT_PATH . '/footer.php';
361