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; |
||
0 ignored issues
–
show
|
|||
31 | use XoopsModules\News\{ |
||
32 | NewsStory, |
||
33 | NewsTopic, |
||
34 | Utility |
||
35 | }; |
||
36 | |||
37 | require_once \dirname(__DIR__, 2) . '/mainfile.php'; |
||
38 | require_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
39 | //require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; |
||
40 | //require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php'; |
||
41 | |||
42 | error_reporting(0); |
||
43 | $GLOBALS['xoopsLogger']->activated = false; |
||
44 | |||
45 | if (!Utility::getModuleOption('topicsrss')) { |
||
46 | exit(); |
||
47 | } |
||
48 | |||
49 | $topicid = Request::getInt('topicid', 0, 'GET'); |
||
50 | if (0 == $topicid) { |
||
51 | exit(); |
||
52 | } |
||
53 | |||
54 | if (function_exists('mb_http_output')) { |
||
55 | mb_http_output('pass'); |
||
56 | } |
||
57 | |||
58 | $restricted = Utility::getModuleOption('restrictindex'); |
||
59 | $newsnumber = Utility::getModuleOption('storyhome'); |
||
60 | |||
61 | $charset = 'utf-8'; |
||
62 | |||
63 | header('Content-Type:text/xml; charset=' . $charset); |
||
64 | $story = new NewsStory(); |
||
65 | $tpl = new \XoopsTpl(); |
||
66 | $tpl->caching = 2; |
||
67 | $tpl->cache_lifetime=3600; // Change this to the value you want |
||
68 | if (!$tpl->isCached('db:news_rss.tpl', $topicid)) { |
||
69 | $xt = new NewsTopic($topicid); |
||
70 | $sarray = NewsStory::getAllPublished($newsnumber, 0, $restricted, $topicid); |
||
71 | if ($sarray && \is_array($sarray)) { |
||
72 | $sitename = htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES | ENT_HTML5); |
||
73 | $slogan = htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES | ENT_HTML5); |
||
74 | $tpl->assign('channel_title', xoops_utf8_encode($sitename)); |
||
75 | $tpl->assign('channel_link', XOOPS_URL . '/'); |
||
76 | $tpl->assign('channel_desc', xoops_utf8_encode($slogan)); |
||
77 | $tpl->assign('channel_lastbuild', formatTimestamp(time(), 'rss')); |
||
78 | $tpl->assign('channel_webmaster', checkEmail($xoopsConfig['adminmail'], true)); // Fed up with spam |
||
79 | $tpl->assign('channel_editor', checkEmail($xoopsConfig['adminmail'], true)); // Fed up with spam |
||
80 | $tpl->assign('channel_category', $xt->topic_title()); |
||
81 | $tpl->assign('channel_generator', 'XOOPS'); |
||
82 | $tpl->assign('channel_language', _LANGCODE); |
||
83 | $tpl->assign('image_url', XOOPS_URL . '/images/logo.gif'); |
||
84 | $dimention = getimagesize(XOOPS_ROOT_PATH . '/images/logo.gif'); |
||
85 | if (empty($dimention[0])) { |
||
86 | $width = 88; |
||
87 | } else { |
||
88 | $width = ($dimention[0] > 144) ? 144 : $dimention[0]; |
||
89 | } |
||
90 | if (empty($dimention[1])) { |
||
91 | $height = 31; |
||
92 | } else { |
||
93 | $height = ($dimention[1] > 400) ? 400 : $dimention[1]; |
||
94 | } |
||
95 | $tpl->assign('image_width', $width); |
||
96 | $tpl->assign('image_height', $height); |
||
97 | $count = $sarray; |
||
98 | foreach ($sarray as $story) { |
||
99 | $storytitle = $story->title(); |
||
100 | //if we are allowing html, we need to use htmlspecialchars or any bug will break the output |
||
101 | $description = htmlspecialchars($story->hometext(), ENT_QUOTES | ENT_HTML5); |
||
102 | $tpl->append( |
||
103 | 'items', |
||
104 | [ |
||
105 | 'title' => xoops_utf8_encode($storytitle), |
||
106 | 'link' => XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), |
||
107 | 'guid' => XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), |
||
108 | 'pubdate' => formatTimestamp($story->published(), 'rss'), |
||
109 | 'description' => xoops_utf8_encode($description), |
||
110 | ] |
||
111 | ); |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | $tpl->display('db:news_rss.tpl', $topicid); |
||
116 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: