Passed
Push — master ( 6d0bec...700d12 )
by Michael
05:09 queued 02:42
created
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);
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

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