Completed
Push — master ( 53db9c...d00923 )
by Michael
03:42 queued 01:42
created

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 http://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
include __DIR__ . '/../../mainfile.php';
75
76
//$XOOPS_URL = XOOPS_URL;
77
//$u=$XOOPS_URL.'/uploads/news_xml.php';
78
//  $x = file_get_contents($u);
79
80
require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
81
require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php';
82
require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
83
require_once XOOPS_ROOT_PATH . '/modules/news/class/utility.php';
84
require_once XOOPS_ROOT_PATH . '/modules/news/class/tree.php';
85
86
$moduleDirName = basename(__DIR__);
87
xoops_load('utility', $moduleDirName);
88
$module = XoopsModule::getByDirname($moduleDirName);
89
90
$storytopic = 0;
91
if (isset($_GET['storytopic'])) {
92
    $storytopic = (int)$_GET['storytopic'];
93
} else {
94
    if (isset($_GET['topic_id'])) {
95
        $storytopic = (int)$_GET['topic_id'];
96
    }
97
}
98
99
if ($storytopic) {
100
    $groups       = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
101
    $gpermHandler = xoops_getHandler('groupperm');
102 View Code Duplication
    if (!$gpermHandler->checkRight('news_view', $storytopic, $groups, $xoopsModule->getVar('mid'))) {
103
        redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
104
    }
105
    $xoopsOption['storytopic'] = $storytopic;
106
} else {
107
    $xoopsOption['storytopic'] = 0;
108
}
109
if (isset($_GET['storynum'])) {
110
    $xoopsOption['storynum'] = (int)$_GET['storynum'];
111
    if ($xoopsOption['storynum'] > 30) {
112
        $xoopsOption['storynum'] = $xoopsModuleConfig['storyhome'];
113
    }
114
} else {
115
    $xoopsOption['storynum'] = $xoopsModuleConfig['storyhome'];
116
}
117
118
if (isset($_GET['start'])) {
119
    $start = (int)$_GET['start'];
120
} else {
121
    $start = 0;
122
}
123
124
if (empty($xoopsModuleConfig['newsdisplay']) || 'Classic' === $xoopsModuleConfig['newsdisplay']
125
    || $xoopsOption['storytopic'] > 0) {
126
    $showclassic = 1;
127
} else {
128
    $showclassic = 0;
129
}
130
$firsttitle = '';
131
$topictitle = '';
132
$myts       = MyTextSanitizer::getInstance();
133
$sfiles     = new sFiles();
134
135
$column_count = $xoopsModuleConfig['columnmode'];
136
137
if ($showclassic) {
138
    $GLOBALS['xoopsOption']['template_main'] = 'news_index.tpl';
139
    require_once XOOPS_ROOT_PATH . '/header.php';
140
    $xt = new NewsTopic();
141
142
    $xoopsTpl->assign('columnwidth', (int)(1 / $column_count * 100));
143 View Code Duplication
    if ($xoopsModuleConfig['ratenews']) {
144
        $xoopsTpl->assign('rates', true);
145
        $xoopsTpl->assign('lang_ratingc', _NW_RATINGC);
146
        $xoopsTpl->assign('lang_ratethisnews', _NW_RATETHISNEWS);
147
    } else {
148
        $xoopsTpl->assign('rates', false);
149
    }
150
151
    if ($xoopsOption['storytopic']) {
152
        $xt->getTopic($xoopsOption['storytopic']);
153
        $xoopsTpl->assign('topic_description', $xt->topic_description('S'));
154
        $xoopsTpl->assign('topic_color', '#' . $xt->topic_color('S'));
155
        $topictitle = $xt->topic_title();
156
    }
157
158
    if (1 == $xoopsModuleConfig['displaynav']) {
159
        $xoopsTpl->assign('displaynav', true);
160
161
        $allTopics  = $xt->getAllTopics($xoopsModuleConfig['restrictindex']);
162
        $topic_tree = new MyXoopsObjectTree($allTopics, 'topic_id', 'topic_pid');
163
164
        if (NewsUtility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) {
165
            $topic_select = $topic_tree->makeSelectElement('storytopic', 'topic_title', '--', $xoopsOption['storytopic'], true, 0, '', '');
166
            $xoopsTpl->assign('topic_select', $topic_select->render());
167
        } else {
168
            $topic_select = $topic_tree->makeSelBox('storytopic', 'topic_title', '-- ', $xoopsOption['storytopic'], true);
169
            $xoopsTpl->assign('topic_select', $topic_select);
170
        }
171
172
        $storynum_options = '';
173
        for ($i = 5; $i <= 30; $i += 5) {
174
            $sel = '';
175
            if ($i == $xoopsOption['storynum']) {
176
                $sel = ' selected';
177
            }
178
            $storynum_options .= '<option value="' . $i . '"' . $sel . '>' . $i . '</option>';
179
        }
180
        $xoopsTpl->assign('storynum_options', $storynum_options);
181
    } else {
182
        $xoopsTpl->assign('displaynav', false);
183
    }
184
    if (0 == $xoopsOption['storytopic']) {
185
        $topic_frontpage = true;
186
    } else {
187
        $topic_frontpage = false;
188
    }
189
    $sarray = NewsStory::getAllPublished($xoopsOption['storynum'], $start, $xoopsModuleConfig['restrictindex'], $xoopsOption['storytopic'], 0, true, 'published', $topic_frontpage);
190
191
    $scount = count($sarray);
192
    $xoopsTpl->assign('story_count', $scount);
193
    $k       = 0;
194
    $columns = [];
195
    if ($scount > 0) {
196
        $storieslist = [];
197
        foreach ($sarray as $storyid => $thisstory) {
198
            $storieslist[] = $thisstory->storyid();
199
        }
200
        $filesperstory = $sfiles->getCountbyStories($storieslist);
201
202
        if (!empty($sarray)) {
203
            foreach ($sarray as $storyid => $thisstory) {
204
                $filescount = array_key_exists($thisstory->storyid(), $filesperstory) ? $filesperstory[$thisstory->storyid()] : 0;
205
                $story      = $thisstory->prepare2show($filescount);
206
                // The line below can be used to display a Permanent Link image
207
                // $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>";
208
                $story['news_title']  = $story['title'];
209
                $story['title']       = $thisstory->textlink() . '&nbsp;:&nbsp;' . $story['title'];
210
                $story['topic_title'] = $thisstory->textlink();
211
                $story['topic_color'] = '#' . $myts->displayTarea($thisstory->topic_color);
212
                if ('' === $firsttitle) {
213
                    $firsttitle = $thisstory->topic_title() . ' - ' . $thisstory->title();
214
                }
215
                $columns[$k][] = $story;
216
                ++$k;
217
                if ($k == $column_count) {
218
                    $k = 0;
219
                }
220
            }
221
        }
222
    }
223
    $xoopsTpl->assign('columns', $columns);
224
    unset($story);
225
    
226
    // orwah show topictitle in news_item.tpl
227 View Code Duplication
	if (NewsUtility::getModuleOption('displaytopictitle') == 1) {
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
228
          $xoopsTpl->assign('displaytopictitle',true);
229
    } else {
230
          $xoopsTpl->assign('displaytopictitle',false);
231
    }
232
233
    $totalcount = NewsStory::countPublishedByTopic($xoopsOption['storytopic'], $xoopsModuleConfig['restrictindex']);
234
    if ($totalcount > $scount) {
235
        require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
236
        $pagenav = new XoopsPageNav($totalcount, $xoopsOption['storynum'], $start, 'start', 'storytopic=' . $xoopsOption['storytopic']);
237
        if (NewsUtility::isBot()) { // A bot is reading the news, we are going to show it all the links so that he can read everything
238
            $xoopsTpl->assign('pagenav', $pagenav->renderNav($totalcount));
239
        } else {
240
            $xoopsTpl->assign('pagenav', $pagenav->renderNav());
241
        }
242
    } else {
243
        $xoopsTpl->assign('pagenav', '');
244
    }
245
} else { // Affichage par sujets
246
    $GLOBALS['xoopsOption']['template_main'] = 'news_by_topic.tpl';
247
    require_once XOOPS_ROOT_PATH . '/header.php';
248
    $xoopsTpl->assign('columnwidth', (int)(1 / $column_count * 100));
249 View Code Duplication
    if ($xoopsModuleConfig['ratenews']) {
250
        $xoopsTpl->assign('rates', true);
251
        $xoopsTpl->assign('lang_ratingc', _NW_RATINGC);
252
        $xoopsTpl->assign('lang_ratethisnews', _NW_RATETHISNEWS);
253
    } else {
254
        $xoopsTpl->assign('rates', false);
255
    }
256
257
    $xt            = new NewsTopic();
258
    $alltopics     = $xt->getTopicsList(true, $xoopsModuleConfig['restrictindex']);
259
    $smarty_topics = [];
260
    $topicstories  = [];
261
262
    foreach ($alltopics as $topicid => $topic) {
263
        $allstories  = NewsStory::getAllPublished($xoopsModuleConfig['storyhome'], 0, $xoopsModuleConfig['restrictindex'], $topicid);
264
        $storieslist = [];
265
        foreach ($allstories as $thisstory) {
266
            $storieslist[] = $thisstory->storyid();
267
        }
268
        $filesperstory = $sfiles->getCountbyStories($storieslist);
269
        foreach ($allstories as $thisstory) {
270
            $filescount               = array_key_exists($thisstory->storyid(), $filesperstory) ? $filesperstory[$thisstory->storyid()] : 0;
271
            $story                    = $thisstory->prepare2show($filescount);
272
            $story['topic_title']     = $thisstory->textlink();
273
            $story['news_title']      = $story['title'];
274
            $topicstories[$topicid][] = $story;
275
        }
276
        if (isset($topicstories[$topicid])) {
277
            $smarty_topics[$topicstories[$topicid][0]['posttimestamp']] = [
278
                'title'       => $topic['title'],
279
                'stories'     => $topicstories[$topicid],
280
                'id'          => $topicid,
281
                'topic_color' => $topic['color']
282
            ];
283
        }
284
    }
285
286
    krsort($smarty_topics);
287
    $columns = [];
288
    $i       = 0;
289
    foreach ($smarty_topics as $thistopictimestamp => $thistopic) {
290
        $columns[$i][] = $thistopic;
291
        ++$i;
292
        if ($i == $column_count) {
293
            $i = 0;
294
        }
295
    }
296
    //$xoopsTpl->assign('topics', $smarty_topics);
297
    $xoopsTpl->assign('columns', $columns);
298
}
299
300
$xoopsTpl->assign('advertisement', NewsUtility::getModuleOption('advertisement'));
301
302
/**
303
 * Create the Meta Datas
304
 */
305
NewsUtility::createMetaDatas();
306
307
/**
308
 * Create a clickable path from the root to the current topic (if we are viewing a topic)
309
 * Actually this is not used in the default templates but you can use it as you want
310
 * You can comment the code to optimize the requests count
311
 */
312
if ($xoopsOption['storytopic']) {
313
    require_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstree.php';
314
    $mytree    = new MyXoopsTree($xoopsDB->prefix('news_topics'), 'topic_id', 'topic_pid');
315
    $topicpath = $mytree->getNicePathFromId($xoopsOption['storytopic'], 'topic_title', 'index.php?op=1');
316
    $xoopsTpl->assign('topic_path', $topicpath);
317
    unset($mytree);
318
}
319
320
/**
321
 * Create a link for the RSS feed (if the module's option is activated)
322
 */
323
/** @var XoopsModuleHandler $moduleHandler */
324
$moduleHandler = xoops_getHandler('module');
325
$moduleInfo    = $moduleHandler->get($GLOBALS['xoopsModule']->getVar('mid'));
326
if ($xoopsModuleConfig['topicsrss'] && $xoopsOption['storytopic']) {
327
    $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, \Xmf\Module\Admin::iconUrl('', 16) . '/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
require_once XOOPS_ROOT_PATH . '/footer.php';
352