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

article.php (11 issues)

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 228 and the first side effect is on line 114.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
 * Article's page
22
 *
23
 * This page is used to see an article (or story) and is mainly called from
24
 * the module's index page.
25
 *
26
 * If no story Id has been placed on the URL or if the story is not yet published
27
 * then the page will redirect user to the module's index.
28
 * If the user does not have the permissions to see the article, he is also redirected
29
 * to the module's index page but with a error message saying :
30
 *     "Sorry, you don't have the permission to access this area"
31
 *
32
 * Each time a page is seen, and only if we are on the first page, its counter of hits is
33
 * updated
34
 *
35
 * Each file(s) attached to the article is visible at the bottom of the article and can
36
 * be downloaded
37
 *
38
 * Notes :
39
 * - To create more than one page in your story, use the tag [pagebreak]
40
 * - If you are a module's admin, you have the possibility to see two links at the bottom
41
 *   of the article, "Edit & Delete"
42
 *
43
 * @package                         News
44
 * @author                          Xoops Modules Dev Team
45
 * @copyright (c)                   XOOPS Project (https://xoops.org)
46
 *
47
 * Parameters received by this page :
48
 *
49
 * @param int storyid    Id of the story we want to see
50
 * @param int page        page's number (in the case where there are more than one page)
51
 *
52
 * @page_title                      Article's title - Topic's title - Module's name
53
 *
54
 * @template_name                   news_article.html wich will call news_item.html
55
 *
56
 * Template's variables :
57
 * @template_var                    string    pagenav    some links to navigate thru pages
58
 * @template_var                    array    story    Contains all the information about the story
59
 *                                    Structure :
60
 * @template_var                    int        id            Story's ID
61
 * @template_var                    string    posttime    Story's date of publication
62
 * @template_var                    string    title        A link to go and see all the articles in the same topic and the story's title
63
 * @template_var                    string    news_title    Just the news title
64
 * @template_var                    string    topic_title    Just the topic's title
65
 * @template_var                    string    text        Defined as "The scoop"
66
 * @template_var                    string    poster        A link to see the author's profil and his name or "Anonymous"
67
 * @template_var                    int        posterid    Author's uid (or 0 if it's an anonymous or a user wich does not exist any more)
68
 * @template_var                    string    morelink    Never used ???? May be it could be deleted
69
 * @template_var                    string    adminlink    A link to Edit or Delete the story or a blank string if you are not the module's admin
70
 * @template_var                    string    topicid        News topic's Id
71
 * @template_var                    string    topic_color    Topic's color
72
 * @template_var                    string    imglink        A link to go and see the topic of the story with the topic's picture (if it exists)
73
 * @template_var                    string    align        Topic's image alignement
74
 * @template_var                    int        hits        Story's counter of visits
75
 * @template_var                    string    mail_link    A link (with a mailto) to email the story's URL to someone
76
 * @template_var                    string    lang_printerpage    Used in the link and picture to have a "printable version" (fixed text)
77
 * @template_var                    string    lang_on        Fixed text "On" ("published on")
78
 * @template_var                    string    lang_postedby    Fixed text "Posted by"
79
 * @template_var                    string    lang_reads    Fixed text "Reads"
80
 * @template_var                    string    news_by_the_same_author_link    According the the module's option named "newsbythisauthor", it contains a link to see all the article's stories
81
 * @template_var                    int        summary_count    Number of stories really visibles in the summary table
82
 * @template_var                    boolean    showsummary    According to the module's option named "showsummarytable", this contains "True" of "False"
83
 * @template_var                    array    summary    Contains the required information to create a summary table at the bottom of the article. Note, we use the module's option "storyhome" to determine the maximum number of stories visibles in this summary table
84
 *                                    Structure :
85
 * @template_var                    int        story_id        Story's ID
86
 * @template_var                    string    story_title        Story's title
87
 * @template_var                    int        story_hits        Counter of hits
88
 * @template_var                    string    story_published    Story's date of creation
89
 * @template_var                    string    lang_attached_files    Fixed text "Attached Files:"
90
 * @template_var                    int        attached_files_count    Number of files attached to the story
91
 * @template_var                    array    attached_files    Contains the list of all the files attached to the story
92
 *                                    Structure :
93
 * @template_var                    int        file_id                File's ID
94
 * @template_var                    string    visitlink            Link to download the file
95
 * @template_var                    string    file_realname        Original filename (not the real one use to store the file but the one it have when it was on the user hard disk)
96
 * @template_var                    string    file_attacheddate    Date to wich the file was attached to the story (in general that's equal to the article's creation date)
97
 * @template_var                    string    file_mimetype        File's mime type
98
 * @template_var                    string    file_downloadname    Real name of the file on the webserver's disk (changed by the module)
99
 * @template_var                    boolean    nav_links    According to the module's option named "showprevnextlink" it contains "True" or "False" to know if we have to show two links to go to the previous and next article
100
 * @template_var                    int        previous_story_id    Id of the previous story (according to the published date and to the perms)
101
 * @template_var                    int        next_story_id        Id of the next story (according to the published date and to the perms)
102
 * @template_var                    string    previous_story_title    Title of the previous story
103
 * @template_var                    string    next_story_title        Title of the next story
104
 * @template_var                    string    lang_previous_story        Fixed text "Previous article"
105
 * @template_var                    string    lang_next_story            Fixed text "Next article"
106
 * @template_var                    string    lang_other_story        Fixed text "Other articles"
107
 * @template_var                    boolean    rates    To know if rating is enable or not
108
 * @template_var                    string    lang_ratingc    Fixed text "Rating: "
109
 * @template_var                    string    lang_ratethisnews    Fixed text "Rate this News"
110
 * @template_var                    float    rating    Article's rating
111
 * @template_var                    string    votes    "1 vote" or "X votes"
112
 * @template_var                    string    topic_path    A path from the root to the current topic (of the current news)
113
 */
114
include __DIR__ . '/../../mainfile.php';
115
require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
116
require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php';
117
require_once XOOPS_ROOT_PATH . '/modules/news/class/tree.php';
118
require_once XOOPS_ROOT_PATH . '/modules/news/class/utility.php';
119
require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
120
require_once XOOPS_ROOT_PATH . '/modules/news/class/keyhighlighter.class.php';
121
require_once XOOPS_ROOT_PATH . '/modules/news/config.php';
122
123
$storyid = isset($_GET['storyid']) ? (int)$_GET['storyid'] : 0;
124
125
if (empty($storyid)) {
126
    redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY);
127
}
128
129
$myts = MyTextSanitizer::getInstance();
130
131
// Not yet published
132
$article = new NewsStory($storyid);
133 View Code Duplication
if (0 == $article->published() || $article->published() > time()) {
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...
134
    redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOTYETSTORY);
135
}
136
// Expired
137
if (0 != $article->expired() && $article->expired() < time()) {
138
    redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY);
139
}
140
141
$gpermHandler = xoops_getHandler('groupperm');
142
if (is_object($xoopsUser)) {
143
    $groups = $xoopsUser->getGroups();
144
} else {
145
    $groups = XOOPS_GROUP_ANONYMOUS;
146
}
147
if (!$gpermHandler->checkRight('news_view', $article->topicid(), $groups, $xoopsModule->getVar('mid'))) {
148
    redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
149
}
150
151
$storypage  = isset($_GET['page']) ? (int)$_GET['page'] : 0;
152
$dateformat = NewsUtility::getModuleOption('dateformat');
153
$hcontent   = '';
154
155
/**
156
 * update counter only when viewing top page and when you are not the author or an admin
157
 */
158
if (empty($_GET['com_id']) && 0 == $storypage) {
159
    if (is_object($xoopsUser)) {
160
        if (($xoopsUser->getVar('uid') == $article->uid()) || NewsUtility::isAdminGroup()) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
161
            // nothing ! ;-)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
162
        } else {
163
            $article->updateCounter();
164
        }
165
    } else {
166
        $article->updateCounter();
167
    }
168
}
169
$GLOBALS['xoopsOption']['template_main'] = 'news_article.tpl';
170
require_once XOOPS_ROOT_PATH . '/header.php';
171
172
$story['id']          = $storyid;
173
$story['posttime']    = formatTimestamp($article->published(), $dateformat);
174
$story['news_title']  = $article->title();
175
$story['title']       = $article->textlink() . '&nbsp;:&nbsp;' . $article->title();
176
$story['subtitle']    = $article->subtitle();
177
$story['topic_title'] = $article->textlink();
178
179
$story['text'] = $article->hometext();
180
$bodytext      = $article->bodytext();
181
182
if ('' !== xoops_trim($bodytext)) {
183
    $articletext = [];
184
    if (NewsUtility::getModuleOption('enhanced_pagenav')) {
185
        $articletext             = preg_split('/(\[pagebreak:|\[pagebreak)(.*)(\])/iU', $bodytext);
186
        $arr_titles              = [];
187
        $auto_summary            = $article->auto_summary($bodytext, $arr_titles);
188
        $bodytext                = str_replace('[summary]', $auto_summary, $bodytext);
189
        $articletext[$storypage] = str_replace('[summary]', $auto_summary, $articletext[$storypage]);
190
        $story['text']           = str_replace('[summary]', $auto_summary, $story['text']);
191
    } else {
192
        $articletext = explode('[pagebreak]', $bodytext);
193
    }
194
195
    $story_pages = count($articletext);
196
197
    if ($story_pages > 1) {
198
        require_once XOOPS_ROOT_PATH . '/modules/news/include/pagenav.php';
199
        $pagenav = new XoopsPageNav($story_pages, 1, $storypage, 'page', 'storyid=' . $storyid);
200
        if (NewsUtility::isBot()) { // A bot is reading the articles, we are going to show him all the links to the pages
201
            $xoopsTpl->assign('pagenav', $pagenav->renderNav($story_pages));
202
        } else {
203
            if (NewsUtility::getModuleOption('enhanced_pagenav')) {
204
                $xoopsTpl->assign('pagenav', $pagenav->renderEnhancedSelect(true, $arr_titles));
205
            } else {
206
                $xoopsTpl->assign('pagenav', $pagenav->renderNav());
207
            }
208
        }
209
210
        if (0 == $storypage) {
211
            $story['text'] = $story['text'] . '<br>' . NewsUtility::getModuleOption('advertisement') . '<br>' . $articletext[$storypage];
212
        } else {
213
            $story['text'] = $articletext[$storypage];
214
        }
215
    } else {
216
        $story['text'] = $story['text'] . '<br>' . NewsUtility::getModuleOption('advertisement') . '<br>' . $bodytext;
217
    }
218
}
219
// Publicit�
220
$xoopsTpl->assign('advertisement', NewsUtility::getModuleOption('advertisement'));
221
222
// ****************************************************************************************************************
223
/**
224
 * @param $matches
225
 *
226
 * @return string
227
 */
228
function my_highlighter($matches)
229
{
230
    $color = NewsUtility::getModuleOption('highlightcolor');
231
    if ('#' !== substr($color, 0, 1)) {
232
        $color = '#' . $color;
233
    }
234
235
    return '<span style="font-weight: bolder; background-color: ' . $color . ';">' . $matches[0] . '</span>';
236
}
237
238
$highlight = false;
239
$highlight = NewsUtility::getModuleOption('keywordshighlight');
240
241
if ($highlight && isset($_GET['keywords'])) {
242
    $keywords      = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords'])));
243
    $h             = new keyhighlighter($keywords, true, 'my_highlighter');
244
    $story['text'] = $h->highlight($story['text']);
245
}
246
// ****************************************************************************************************************
247
248
$story['poster'] = $article->uname();
249
if ($story['poster']) {
250
    $story['posterid']         = $article->uid();
251
    $story['poster']           = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $story['posterid'] . '">' . $story['poster'] . '</a>';
252
    $tmp_user                  = new XoopsUser($article->uid());
253
    $story['poster_avatar']    = XOOPS_UPLOAD_URL . '/' . $tmp_user->getVar('user_avatar');
254
    $story['poster_signature'] = $tmp_user->getVar('user_sig');
255
    $story['poster_email']     = $tmp_user->getVar('email');
256
    $story['poster_url']       = $tmp_user->getVar('url');
257
    $story['poster_from']      = $tmp_user->getVar('user_from');
258
    unset($tmp_user);
259
} else {
260
    $story['poster']           = '';
261
    $story['posterid']         = 0;
262
    $story['poster_avatar']    = '';
263
    $story['poster_signature'] = '';
264
    $story['poster_email']     = '';
265
    $story['poster_url']       = '';
266
    $story['poster_from']      = '';
267
    if (3 != NewsUtility::getModuleOption('displayname')) {
268
        $story['poster'] = $xoopsConfig['anonymous'];
269
    }
270
}
271
$story['morelink']  = '';
272
$story['adminlink'] = '';
273
unset($isadmin);
274
275
if (is_object($xoopsUser)) {
276
    if ($xoopsUser->isAdmin($xoopsModule->getVar('mid'))
277
        || (NewsUtility::getModuleOption('authoredit')
278
            && $article->uid() == $xoopsUser->getVar('uid'))) {
279
        $isadmin = true;
280
        //      $story['adminlink'] = $article->adminlink();
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
281
    }
282
}
283
$story['topicid']     = $article->topicid();
284
$story['topic_color'] = '#' . $myts->displayTarea($article->topic_color);
0 ignored issues
show
The property topic_color does not seem to exist in NewsStory.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
285
286
$story['imglink'] = '';
287
$story['align']   = '';
288
if ($article->topicdisplay()) {
289
    $story['imglink'] = $article->imglink();
290
    $story['align']   = $article->topicalign();
291
}
292
$story['hits']      = $article->counter();
293
$story['mail_link'] = 'mailto:?subject=' . sprintf(_NW_INTARTICLE, $xoopsConfig['sitename']) . '&amp;body=' . sprintf(_NW_INTARTFOUND, $xoopsConfig['sitename']) . ':  ' . XOOPS_URL . '/modules/news/article.php?storyid=' . $article->storyid();
294
$xoopsTpl->assign('lang_printerpage', _NW_PRINTERFRIENDLY);
295
$xoopsTpl->assign('lang_sendstory', _NW_SENDSTORY);
296
$xoopsTpl->assign('lang_pdfstory', _NW_MAKEPDF);
297
$xoopsTpl->assign('lang_on', _ON);
298
$xoopsTpl->assign('lang_postedby', _POSTEDBY);
299
$xoopsTpl->assign('lang_reads', _READS);
300
$xoopsTpl->assign('mail_link', 'mailto:?subject=' . sprintf(_NW_INTARTICLE, $xoopsConfig['sitename']) . '&amp;body=' . sprintf(_NW_INTARTFOUND, $xoopsConfig['sitename']) . ':  ' . XOOPS_URL . '/modules/news/article.php?storyid=' . $article->storyid());
301
302
if ('' !== xoops_trim($article->picture())) {
303
    $story['picture']     = XOOPS_URL . '/uploads/news/image/' . $article->picture();
304
    $story['pictureinfo'] = $article->pictureinfo();
305
} else {
306
    $story['picture']     = '';
307
    $story['pictureinfo'] = '';
308
}
309
310
$xoopsTpl->assign('lang_attached_files', _NW_ATTACHEDFILES);
311
$sfiles     = new sFiles();
312
$filesarr   = $newsfiles = [];
313
$filesarr   = $sfiles->getAllbyStory($storyid);
314
$filescount = count($filesarr);
315
$xoopsTpl->assign('attached_files_count', $filescount);
316
if ($filescount > 0) {
317
    foreach ($filesarr as $onefile) {
318
        $newsfiles[] = [
319
            'file_id'           => $onefile->getFileid(),
320
            'visitlink'         => XOOPS_URL . '/modules/news/visit.php?fileid=' . $onefile->getFileid(),
321
            'file_realname'     => $onefile->getFileRealName(),
322
            'file_attacheddate' => formatTimestamp($onefile->getDate(), $dateformat),
323
            'file_mimetype'     => $onefile->getMimetype(),
324
            'file_downloadname' => XOOPS_UPLOAD_URL . '/' . $onefile->getDownloadname()
325
        ];
326
    }
327
    $xoopsTpl->assign('attached_files', $newsfiles);
328
}
329
330
/**
331
 * Create page's title
332
 */
333
$complement = '';
334
if (NewsUtility::getModuleOption('enhanced_pagenav')
335
    && (isset($arr_titles) && is_array($arr_titles)
336
        && isset($arr_titles, $storypage)
337
        && $storypage > 0)) {
338
    $complement = ' - ' . $arr_titles[$storypage];
339
}
340
$xoopsTpl->assign('xoops_pagetitle', $article->title() . $complement . ' - ' . $article->topic_title() . ' - ' . $xoopsModule->name('s'));
341
342
if (NewsUtility::getModuleOption('newsbythisauthor')) {
343
    $xoopsTpl->assign('news_by_the_same_author_link', sprintf("<a href='%s?uid=%d'>%s</a>", XOOPS_URL . '/modules/news/newsbythisauthor.php', $article->uid(), _NW_NEWSSAMEAUTHORLINK));
344
}
345
346
/**
347
 * Create a clickable path from the root to the current topic (if we are viewing a topic)
348
 * Actually this is not used in the default's templates but you can use it as you want
349
 * Uncomment the code to be able to use it
350
 */
351
if ($cfg['create_clickable_path']) {
352
    $mytree    = new MyXoopsObjectTree($xoopsDB->prefix('news_topics'), 'topic_id', 'topic_pid');
0 ignored issues
show
$xoopsDB->prefix('news_topics') cannot be passed to __construct() as the parameter $objectArr expects a reference.
Loading history...
353
    $topicpath = $mytree->getNicePathFromId($article->topicid(), 'topic_title', 'index.php?op=1');
0 ignored issues
show
The method getNicePathFromId() does not seem to exist on object<MyXoopsObjectTree>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
354
    $xoopsTpl->assign('topic_path', $topicpath);
355
    unset($mytree);
356
}
357
358
/**
359
 * Summary table
360
 *
361
 * When you are viewing an article, you can see a summary table containing
362
 * the first n links to the last published news.
363
 * This summary table is visible according to a module's option (showsummarytable)
364
 * The number of items is equal to the module's option "storyhome" ("Select the number
365
 * of news items to display on top page")
366
 * We also use the module's option "restrictindex" ("Restrict Topics on Index Page"), like
367
 * this you (the webmaster) select if users can see restricted stories or not.
368
 */
369
if (NewsUtility::getModuleOption('showsummarytable')) {
370
    $xoopsTpl->assign('showsummary', true);
371
    $xoopsTpl->assign('lang_other_story', _NW_OTHER_ARTICLES);
372
    $count      = 0;
373
    $tmparticle = new NewsStory();
374
    $infotips   = NewsUtility::getModuleOption('infotips');
375
    $sarray     = NewsStory::getAllPublished($cfg['article_summary_items_count'], 0, $xoopsModuleConfig['restrictindex']);
376
    if (count($sarray) > 0) {
377
        foreach ($sarray as $onearticle) {
0 ignored issues
show
The expression $sarray 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.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
378
            ++$count;
379
            $htmltitle = '';
380
            $tooltips  = '';
381
            $htmltitle = '';
382
            if ($infotips > 0) {
383
                $tooltips  = NewsUtility::makeInfotips($onearticle->hometext());
0 ignored issues
show
Are you sure the assignment to $tooltips is correct as \NewsUtility::makeInfoti...onearticle->hometext()) (which targets NewsUtility::makeInfotips()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
384
                $htmltitle = ' title="' . $tooltips . '"';
385
            }
386
            $xoopsTpl->append('summary', [
387
                'story_id'        => $onearticle->storyid(),
388
                'htmltitle'       => $htmltitle,
389
                'infotips'        => $tooltips,
390
                'story_title'     => $onearticle->title(),
391
                'story_hits'      => $onearticle->counter(),
392
                'story_published' => formatTimestamp($onearticle->published, $dateformat)
393
            ]);
394
        }
395
    }
396
    $xoopsTpl->assign('summary_count', $count);
397
    unset($tmparticle);
398
} else {
399
    $xoopsTpl->assign('showsummary', false);
400
}
401
402
/**
403
 * Show a link to go to the previous article and to the next article
404
 *
405
 * According to a module's option "showprevnextlink" ("Show Previous and Next link?")
406
 * you can display, at the bottom of each article, two links used to navigate thru stories.
407
 * This feature uses the module's option "restrictindex" so that we can, or can't see
408
 * restricted stories
409
 */
410
if (NewsUtility::getModuleOption('showprevnextlink')) {
411
    $xoopsTpl->assign('nav_links', true);
412
    $tmparticle    = new NewsStory();
413
    $nextId        = $previousId = -1;
414
    $next          = $previous = [];
415
    $previousTitle = $nextTitle = '';
416
417
    $next = $tmparticle->getNextArticle($storyid, $xoopsModuleConfig['restrictindex']);
418
    if (count($next) > 0) {
419
        $nextId    = $next['storyid'];
420
        $nextTitle = $next['title'];
421
    }
422
423
    $previous = $tmparticle->getPreviousArticle($storyid, $xoopsModuleConfig['restrictindex']);
424
    if (count($previous) > 0) {
425
        $previousId    = $previous['storyid'];
426
        $previousTitle = $previous['title'];
427
    }
428
429
    $xoopsTpl->assign('previous_story_id', $previousId);
430
    $xoopsTpl->assign('next_story_id', $nextId);
431
    if ($previousId > 0) {
432
        $xoopsTpl->assign('previous_story_title', $previousTitle);
433
        $hcontent .= sprintf("<link rel=\"Prev\" title=\"%s\" href=\"%s/\">\n", $previousTitle, XOOPS_URL . '/modules/news/article.php?storyid=' . $previousId);
434
    }
435
436
    if ($nextId > 0) {
437
        $xoopsTpl->assign('next_story_title', $nextTitle);
438
        $hcontent .= sprintf("<link rel=\"Next\" title=\"%s\" href=\"%s/\">\n", $nextTitle, XOOPS_URL . '/modules/news/article.php?storyid=' . $nextId);
439
    }
440
    $xoopsTpl->assign('lang_previous_story', _NW_PREVIOUS_ARTICLE);
441
    $xoopsTpl->assign('lang_next_story', _NW_NEXT_ARTICLE);
442
    unset($tmparticle);
443
} else {
444
    $xoopsTpl->assign('nav_links', false);
445
}
446
447
/**
448
 * Manage all the meta datas
449
 */
450
NewsUtility::createMetaDatas($article);
451
452
/**
453
 * Show a "Bookmark this article at these sites" block ?
454
 */
455
if (NewsUtility::getModuleOption('bookmarkme')) {
456
    $xoopsTpl->assign('bookmarkme', true);
457
    $xoopsTpl->assign('encoded_title', rawurlencode($article->title()));
458
} else {
459
    $xoopsTpl->assign('bookmarkme', false);
460
}
461
462
/**
463
 * Use Facebook Comments Box?
464
 */
465
if (NewsUtility::getModuleOption('fbcomments')) {
466
    $xoopsTpl->assign('fbcomments', true);
467
} else {
468
    $xoopsTpl->assign('fbcomments', false);
469
}
470
471
/**
472
 * Enable users to vote
473
 *
474
 * According to a module's option, "ratenews", you can display a link to rate the current news
475
 * The actual rate in showed (and the number of votes)
476
 * Possible modification, restrict votes to registred users
477
 */
478
$other_test = true;
479
if ($cfg['config_rating_registred_only']) {
480
    if (isset($xoopsUser) && is_object($xoopsUser)) {
481
        $other_test = true;
482
    } else {
483
        $other_test = false;
484
    }
485
}
486
487
if (NewsUtility::getModuleOption('ratenews') && $other_test) {
488
    $xoopsTpl->assign('rates', true);
489
    $xoopsTpl->assign('lang_ratingc', _NW_RATINGC);
490
    $xoopsTpl->assign('lang_ratethisnews', _NW_RATETHISNEWS);
491
    $story['rating'] = number_format($article->rating(), 2);
492
    if (1 == $article->votes) {
493
        $story['votes'] = _NW_ONEVOTE;
494
    } else {
495
        $story['votes'] = sprintf(_NW_NUMVOTES, $article->votes);
496
    }
497
} else {
498
    $xoopsTpl->assign('rates', false);
499
}
500
501
$xoopsTpl->assign('story', $story);
502
503
// Added in version 1.63, TAGS
504
if (xoops_isActiveModule('tag') && NewsUtility::getModuleOption('tags')) {
505
    require_once XOOPS_ROOT_PATH . '/modules/tag/include/tagbar.php';
506
    $xoopsTpl->assign('tags', true);
507
    $xoopsTpl->assign('tagbar', tagBar($storyid, 0));
508
} else {
509
    $xoopsTpl->assign('tags', false);
510
}
511
512
$xoopsTpl->assign('share', $xoopsModuleConfig['share']);
513
$xoopsTpl->assign('showicons', $xoopsModuleConfig['showicons']);
514
515
$canPdf = 1;
516
if (!is_object($GLOBALS['xoopsUser']) && 0 == $xoopsModuleConfig['show_pdficon']) {
517
    $canPdf = 0;
518
}
519
$xoopsTpl->assign('showPdfIcon', $canPdf);
520
521
522 View Code Duplication
if (1 == NewsUtility::getModuleOption('displaytopictitle')) {
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...
523
    $xoopsTpl->assign('displaytopictitle', true);
524
} else {
525
    $xoopsTpl->assign('displaytopictitle', false);
526
}
527
528
//Add style css
529
$xoTheme->addStylesheet('modules/news/assets/css/style.css');
530
531
require_once XOOPS_ROOT_PATH . '/include/comment_view.php';
532
require_once XOOPS_ROOT_PATH . '/footer.php';
533