Passed
Push — master ( 508375...b109af )
by Michael
57s queued 15s
created

index.php (2 issues)

1
<?php declare(strict_types=1);
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
 * @author         XOOPS Development Team
16
 */
17
18
/**
19
 * Module's index
20
 *
21
 * This page displays a list of the published articles and can also display the
22
 * stories of a particular topic.
23
 *
24
 * @author                Xoops Modules Dev Team
25
 * @copyright (c)         XOOPS Project (https://xoops.org)
26
 *
27
 * Parameters received by this page :
28
 * @page_param            int        storytopic                    Topic's ID
29
 * @page_param            int        topic_id                    Topic's ID
30
 * @page_param            int        storynum                    Number of news per page
31
 * @page_param            int        start                        First news to display
32
 *
33
 * @page_title            Topic's title - Story's title - Module's name
34
 *
35
 * @template_name         news_index.html or news_by_topic.html
36
 *
37
 * Template's variables :
38
 * For each article
39
 * @template_var          int        id            story's ID
40
 * @template_var          string    poster        Complete link to the author's profile
41
 * @template_var          string    author_name    Author's name according to the module's option called displayname
42
 * @template_var          int        author_uid    Author's ID
43
 * @template_var          float    rating        New's rating
44
 * @template_var          int        votes        number of votes
45
 * @template_var          int        posttimestamp Timestamp representing the published date
46
 * @template_var          string    posttime        Formated published date
47
 * @template_var          string    text        The introduction's text
48
 * @template_var          string    morelink    The link to read the full article (points to article.php)
49
 * @template_var          string    adminlink    Link reserved to the admin to edit and delete the news
50
 * @template_var          string    mail_link    Link used to send the story's url by email
51
 * @template_var          string    title        Story's title presented on the form of a link
52
 * @template_var          string    news_title    Just the news title
53
 * @template_var          string    topic_title    Just the topic's title
54
 * @template_var          int        hits        Number of times the article was read
55
 * @template_var          int        files_attached    Number of files attached to this news
56
 * @template_var          string    attached_link    An URL pointing to the attached files
57
 * @template_var          string    topic_color    The topic's color
58
 * @template_var          int        columnwidth    column's width
59
 * @template_var          int        displaynav    To know if we must display the navigation's box
60
 * @template_var          string    lang_go        fixed text : Go!
61
 * @template_var          string    lang_morereleases    fixed text : More releases in
62
 * @template_var          string    lang_on        fixed text : on
63
 * @template_var          string    lang_postedby    fixed text : Posted by
64
 * @template_var          string    lang_printerpage    fixed text : Printer Friendly Page
65
 * @template_var          string    lang_ratethisnews    fixed text : Rate this News
66
 * @template_var          string    lang_ratingc    fixed text : Rating:
67
 * @template_var          string    lang_reads        fixed text : reads
68
 * @template_var          string    lang_sendstory    fixed text : Send this Story to a Friend
69
 * @template_var          string     topic_select    contains the topics selector
70
 */
71
72
use Xmf\Module\Admin;
73
use Xmf\Request;
74
use XoopsModules\News;
75
use XoopsModules\News\Files;
76
use XoopsModules\News\NewsStory;
77
use XoopsModules\News\NewsTopic;
78
79
require_once \dirname(__DIR__, 2) . '/mainfile.php';
80
81
/** @var News\Helper $helper */
82
$helper = News\Helper::getInstance();
83
84
//$XOOPS_URL = XOOPS_URL;
85
//$u=$XOOPS_URL.'/uploads/news_xml.php';
86
//  $x = file_get_contents($u);
87
88
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
89
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php';
90
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
91
//;
92
//require_once XOOPS_ROOT_PATH . '/modules/news/class/tree.php';
93
94
$moduleDirName = basename(__DIR__);
95
xoops_load('utility', $moduleDirName);
96
$module = \XoopsModule::getByDirname($moduleDirName);
97
98
$storytopic = 0;
99
if (Request::hasVar('storytopic', 'GET')) {
100
    $storytopic = Request::getInt('storytopic', 0, 'GET');
101
} elseif (Request::hasVar('topic_id', 'GET')) {
102
    $storytopic = Request::getInt('topic_id', 0, 'GET');
103
}
104
105
if ($storytopic) {
106
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
107
    /** @var \XoopsGroupPermHandler $grouppermHandler */
108
    $grouppermHandler = xoops_getHandler('groupperm');
109
    if (!$grouppermHandler->checkRight('news_view', $storytopic, $groups, $xoopsModule->getVar('mid'))) {
110
        redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
111
    }
112
    $xoopsOption['storytopic'] = $storytopic;
113
} else {
114
    $xoopsOption['storytopic'] = 0;
115
}
116
if (Request::hasVar('storynum', 'GET')) {
117
    $xoopsOption['storynum'] = Request::getInt('storynum', 0, 'GET');
118
    if ($xoopsOption['storynum'] > 30) {
119
        $xoopsOption['storynum'] = $helper->getConfig('storyhome');
120
    }
121
} else {
122
    $xoopsOption['storynum'] = $helper->getConfig('storyhome');
123
}
124
125
if (Request::hasVar('start', 'GET')) {
126
    $start = Request::getInt('start', 0, 'GET');
127
} else {
128
    $start = 0;
129
}
130
131
if (empty($helper->getConfig('newsdisplay')) || 'Classic' === $helper->getConfig('newsdisplay')
132
    || $xoopsOption['storytopic'] > 0) {
133
    $showclassic = 1;
134
} else {
135
    $showclassic = 0;
136
}
137
$firsttitle = '';
138
$topictitle = '';
139
$myts       = \MyTextSanitizer::getInstance();
140
$sfiles     = new Files();
141
142
$column_count = $helper->getConfig('columnmode');
143
144
if ($showclassic) {
145
    $GLOBALS['xoopsOption']['template_main'] = 'news_index.tpl';
146
    require_once XOOPS_ROOT_PATH . '/header.php';
147
    $xt = new NewsTopic();
148
149
    $xoopsTpl->assign('columnwidth', (int)(1 / $column_count * 100));
150
    if ($helper->getConfig('ratenews')) {
151
        $xoopsTpl->assign('rates', true);
152
        $xoopsTpl->assign('lang_ratingc', _NW_RATINGC);
153
        $xoopsTpl->assign('lang_ratethisnews', _NW_RATETHISNEWS);
154
    } else {
155
        $xoopsTpl->assign('rates', false);
156
    }
157
158
    if ($xoopsOption['storytopic']) {
159
        $xt->getTopic($xoopsOption['storytopic']);
160
        $xoopsTpl->assign('topic_description', $xt->topic_description('S'));
161
        $xoopsTpl->assign('topic_color', '#' . $xt->topic_color('S'));
162
        $topictitle = $xt->topic_title();
163
    }
164
165
    if (1 == $helper->getConfig('displaynav')) {
166
        $xoopsTpl->assign('displaynav', true);
167
168
        $allTopics  = $xt->getAllTopics($helper->getConfig('restrictindex'));
169
        $topic_tree = new \XoopsModules\News\ObjectTree($allTopics, 'topic_id', 'topic_pid');
170
171
        if (News\Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) {
172
            $topic_select = $topic_tree->makeSelectElement('storytopic', 'topic_title', '--', $xoopsOption['storytopic'], true, 0, '', '');
173
            $xoopsTpl->assign('topic_select', $topic_select->render());
174
        } else {
175
            $topic_select = $topic_tree->makeSelBox('storytopic', 'topic_title', '-- ', $xoopsOption['storytopic'], true);
0 ignored issues
show
Deprecated Code introduced by
The function XoopsModules\News\ObjectTree::makeSelBox() has been deprecated: since 2.5.9, please use makeSelectElement() ( Ignorable by Annotation )

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

175
            $topic_select = /** @scrutinizer ignore-deprecated */ $topic_tree->makeSelBox('storytopic', 'topic_title', '-- ', $xoopsOption['storytopic'], true);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
176
            $xoopsTpl->assign('topic_select', $topic_select);
177
        }
178
179
        $storynum_options = '';
180
        for ($i = 5; $i <= 30; $i += 5) {
181
            $sel = '';
182
            if ($i == $xoopsOption['storynum']) {
183
                $sel = ' selected';
184
            }
185
            $storynum_options .= '<option value="' . $i . '"' . $sel . '>' . $i . '</option>';
186
        }
187
        $xoopsTpl->assign('storynum_options', $storynum_options);
188
    } else {
189
        $xoopsTpl->assign('displaynav', false);
190
    }
191
    if (0 == $xoopsOption['storytopic']) {
192
        $topic_frontpage = true;
193
    } else {
194
        $topic_frontpage = false;
195
    }
196
    $sarray = NewsStory::getAllPublished($xoopsOption['storynum'], $start, $helper->getConfig('restrictindex'), $xoopsOption['storytopic'], 0, true, 'published', $topic_frontpage);
197
198
    $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

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