Passed
Pull Request — master (#41)
by Michael
13:46
created

backendt.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
 * RSS per topics
20
 *
21
 * This script is used to generate RSS feeds for each topic.
22
 * You can enable and disable this feature with the module's option named "Enable RSS feeds per topics?"
23
 * The script uses the permissions to know what to display.
24
 *
25
 * @param type $nomvariable description
26
 * @author        Xoops Modules Dev Team
27
 * @copyright (c) XOOPS Project (https://xoops.org)
28
 */
29
30
use Xmf\Request;
31
use XoopsModules\News;
32
use XoopsModules\News\NewsStory;
33
use XoopsModules\News\NewsTopic;
34
35
require_once \dirname(__DIR__, 2) . '/mainfile.php';
36
require_once XOOPS_ROOT_PATH . '/class/template.php';
37
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
38
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
39
40
error_reporting(0);
41
$GLOBALS['xoopsLogger']->activated = false;
42
43
if (!News\Utility::getModuleOption('topicsrss')) {
44
    exit();
45
}
46
47
$topicid = Request::getInt('topicid', 0, 'GET');
48
if (0 == $topicid) {
49
    exit();
50
}
51
52
if (function_exists('mb_http_output')) {
53
    mb_http_output('pass');
54
}
55
56
$restricted = News\Utility::getModuleOption('restrictindex');
57
$newsnumber = News\Utility::getModuleOption('storyhome');
58
59
$charset = 'utf-8';
60
61
header('Content-Type:text/xml; charset=' . $charset);
62
$story        = new NewsStory();
63
$tpl          = new \XoopsTpl();
64
$tpl->caching = 2;
65
$tpl->xoops_setCacheTime(3600); // Change this to the value you want
0 ignored issues
show
Deprecated Code introduced by
The function XoopsTpl::xoops_setCacheTime() has been deprecated: DO NOT USE THESE METHODS, ACCESS THE CORRESPONDING PROPERTIES INSTEAD ( Ignorable by Annotation )

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

65
/** @scrutinizer ignore-deprecated */ $tpl->xoops_setCacheTime(3600); // Change this to the value you want

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...
66
if (!$tpl->is_cached('db:news_rss.tpl', $topicid)) {
67
    $xt     = new NewsTopic($topicid);
68
    $sarray = NewsStory::getAllPublished($newsnumber, 0, $restricted, $topicid);
0 ignored issues
show
It seems like $newsnumber can also be of type boolean; however, parameter $limit of XoopsModules\News\NewsStory::getAllPublished() does only seem to accept integer, 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

68
    $sarray = NewsStory::getAllPublished(/** @scrutinizer ignore-type */ $newsnumber, 0, $restricted, $topicid);
Loading history...
69
    if ($sarray && is_array($sarray)) {
70
        $sitename = htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES);
71
        $slogan   = htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES);
72
        $tpl->assign('channel_title', xoops_utf8_encode($sitename));
73
        $tpl->assign('channel_link', XOOPS_URL . '/');
74
        $tpl->assign('channel_desc', xoops_utf8_encode($slogan));
75
        $tpl->assign('channel_lastbuild', formatTimestamp(time(), 'rss'));
76
        $tpl->assign('channel_webmaster', checkEmail($xoopsConfig['adminmail'], true)); // Fed up with spam
77
        $tpl->assign('channel_editor', checkEmail($xoopsConfig['adminmail'], true)); // Fed up with spam
78
        $tpl->assign('channel_category', $xt->topic_title());
79
        $tpl->assign('channel_generator', 'XOOPS');
80
        $tpl->assign('channel_language', _LANGCODE);
81
        $tpl->assign('image_url', XOOPS_URL . '/images/logo.gif');
82
        $dimention = getimagesize(XOOPS_ROOT_PATH . '/images/logo.gif');
83
        if (empty($dimention[0])) {
84
            $width = 88;
85
        } else {
86
            $width = ($dimention[0] > 144) ? 144 : $dimention[0];
87
        }
88
        if (empty($dimention[1])) {
89
            $height = 31;
90
        } else {
91
            $height = ($dimention[1] > 400) ? 400 : $dimention[1];
92
        }
93
        $tpl->assign('image_width', $width);
94
        $tpl->assign('image_height', $height);
95
        $count = $sarray;
96
        foreach ($sarray as $story) {
97
            $storytitle = $story->title();
98
            //if we are allowing html, we need to use htmlspecialchars or any bug will break the output
99
            $description = htmlspecialchars($story->hometext(), ENT_QUOTES | ENT_HTML5);
100
            $tpl->append(
101
                'items',
102
                [
103
                    'title'       => xoops_utf8_encode($storytitle),
104
                    'link'        => XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(),
105
                    'guid'        => XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(),
106
                    'pubdate'     => formatTimestamp($story->published(), 'rss'),
107
                    'description' => xoops_utf8_encode($description),
108
                ]
109
            );
110
        }
111
    }
112
}
113
$tpl->display('db:news_rss.tpl', $topicid);
114