|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* You may not change or alter any portion of this comment or credits |
|
7
|
|
|
* of supporting developers from this source code or any supporting source code |
|
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
17
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
18
|
|
|
* @author XOOPS Development Team |
|
19
|
|
|
* @author Pascal Le Boustouller: original author ([email protected]) |
|
20
|
|
|
* @author Luc Bizet (www.frxoops.org) |
|
21
|
|
|
* @author jlm69 (www.jlmzone.com) |
|
22
|
|
|
* @author mamba (www.xoops.org) |
|
23
|
|
|
*/ |
|
24
|
|
|
$rssContent = []; |
|
25
|
|
|
/** |
|
26
|
|
|
* @param $item |
|
27
|
|
|
* @param $type |
|
28
|
|
|
* @return array |
|
29
|
|
|
*/ |
|
30
|
|
|
function rssTags($item, $type): array |
|
31
|
|
|
{ |
|
32
|
|
|
$y = []; |
|
33
|
|
|
$tnl = $item->getElementsByTagName('title'); |
|
34
|
|
|
$tnl = $tnl->item(0); |
|
35
|
|
|
$title = $tnl->firstChild->textContent; |
|
36
|
|
|
$tnl = $item->getElementsByTagName('link'); |
|
37
|
|
|
$tnl = $tnl->item(0); |
|
38
|
|
|
$link = $tnl->firstChild->textContent; |
|
39
|
|
|
$tnl = $item->getElementsByTagName('pubDate'); |
|
40
|
|
|
$tnl = $tnl->item(0); |
|
41
|
|
|
$date = $tnl->firstChild->textContent; |
|
42
|
|
|
$tnl = $item->getElementsByTagName('description'); |
|
43
|
|
|
$tnl = $tnl->item(0); |
|
44
|
|
|
$description = $tnl->firstChild->textContent; |
|
45
|
|
|
$y['title'] = $title; |
|
46
|
|
|
$y['link'] = $link; |
|
47
|
|
|
$y['date_created'] = $date; |
|
48
|
|
|
$y['description'] = $description; |
|
49
|
|
|
$y['type'] = $type; |
|
50
|
|
|
return $y; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param $channel |
|
55
|
|
|
*/ |
|
56
|
|
|
function rssChannel($channel): void |
|
57
|
|
|
{ |
|
58
|
|
|
global $rssContent; |
|
59
|
|
|
$items = $channel->getElementsByTagName('item'); |
|
60
|
|
|
// Processing channel |
|
61
|
|
|
$y = rssTags($channel, 0); // get description of channel, type 0 |
|
62
|
|
|
$rssContent[] = $y; |
|
63
|
|
|
// Processing articles |
|
64
|
|
|
foreach ($items as $item) { |
|
65
|
|
|
$y = rssTags($item, 1); // get description of article, type 1 |
|
66
|
|
|
$rssContent[] = $y; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param string $url |
|
72
|
|
|
*/ |
|
73
|
|
|
function rssRetrieve($url): void |
|
74
|
|
|
{ |
|
75
|
|
|
global $rssContent; |
|
76
|
|
|
$doc = new DOMDocument(); |
|
77
|
|
|
$doc->load($url); |
|
78
|
|
|
$channels = $doc->getElementsByTagName('channel'); |
|
79
|
|
|
$rssContent = []; |
|
80
|
|
|
foreach ($channels as $channel) { |
|
81
|
|
|
rssChannel($channel); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param string $url |
|
87
|
|
|
*/ |
|
88
|
|
|
function rssRetrieveLinks($url): void |
|
89
|
|
|
{ |
|
90
|
|
|
global $rssContent; |
|
91
|
|
|
$doc = new DOMDocument(); |
|
92
|
|
|
$doc->load($url); |
|
93
|
|
|
$channels = $doc->getElementsByTagName('channel'); |
|
94
|
|
|
$rssContent = []; |
|
95
|
|
|
foreach ($channels as $channel) { |
|
96
|
|
|
$items = $channel->getElementsByTagName('item'); |
|
97
|
|
|
foreach ($items as $item) { |
|
98
|
|
|
$y = rssTags($item, 1); // get description of article, type 1 |
|
99
|
|
|
$rssContent[] = $y; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param $url |
|
106
|
|
|
* @param int $size |
|
107
|
|
|
* @return string |
|
108
|
|
|
*/ |
|
109
|
|
|
function rssLinks($url, $size = 15): string |
|
110
|
|
|
{ |
|
111
|
|
|
global $rssContent; |
|
112
|
|
|
$recents = []; |
|
113
|
|
|
$page = '<ul>'; |
|
114
|
|
|
rssRetrieveLinks($url); |
|
115
|
|
|
if ($size > 0) { |
|
116
|
|
|
$recents = array_slice($rssContent, 0, $size + 1); |
|
117
|
|
|
} |
|
118
|
|
|
foreach ($recents as $article) { |
|
119
|
|
|
$type = $article['type']; |
|
120
|
|
|
if (0 === $type) { |
|
121
|
|
|
continue; |
|
122
|
|
|
} |
|
123
|
|
|
$title = $article['title']; |
|
124
|
|
|
$link = $article['link']; |
|
125
|
|
|
$page .= "<li><a href=\"{$link}\">{$title}</a></li>\n"; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $page . "</ul>\n"; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param $url |
|
133
|
|
|
* @param int $size |
|
134
|
|
|
* @param int $site |
|
135
|
|
|
* @return string |
|
136
|
|
|
*/ |
|
137
|
|
|
function rssDisplay( |
|
138
|
|
|
$url, |
|
139
|
|
|
$size = 15, |
|
140
|
|
|
$site = 0 |
|
141
|
|
|
): string { |
|
142
|
|
|
global $rssContent; |
|
143
|
|
|
$recents = []; |
|
144
|
|
|
$opened = false; |
|
145
|
|
|
$page = ''; |
|
146
|
|
|
$site = 0 === (int)$site ? 1 : 0; |
|
147
|
|
|
rssRetrieve($url); |
|
148
|
|
|
if ($size > 0) { |
|
149
|
|
|
$recents = array_slice($rssContent, $site, $size + 1 - $site); |
|
150
|
|
|
} |
|
151
|
|
|
foreach ($recents as $article) { |
|
152
|
|
|
$type = $article['type']; |
|
153
|
|
|
if (0 === $type) { |
|
154
|
|
|
if ($opened) { |
|
155
|
|
|
$page .= '</ul>'; |
|
156
|
|
|
$opened = false; |
|
157
|
|
|
} |
|
158
|
|
|
$page .= '<b>'; |
|
159
|
|
|
} elseif (!$opened) { |
|
160
|
|
|
$page .= '<ul>'; |
|
161
|
|
|
$opened = true; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
$title = $article['title']; |
|
165
|
|
|
$link = $article['link']; |
|
166
|
|
|
$page .= "<tr class=\"even\"><td width=\"300\"><img src=\"../assets/images/admin/info_button.png\" border=\"0\"> <a href=\"{$link}\">{$title}</a><br>"; |
|
167
|
|
|
$description = $article['description']; |
|
168
|
|
|
if (false !== $description) { |
|
169
|
|
|
$page .= "{$description}<br><br></td></tr>"; |
|
170
|
|
|
} |
|
171
|
|
|
$page .= ''; |
|
172
|
|
|
if (0 === $type) { |
|
173
|
|
|
$page .= '</b>'; |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
if ($opened) { |
|
177
|
|
|
$page .= '</ul>'; |
|
178
|
|
|
} |
|
179
|
|
|
return $page; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @param $url |
|
184
|
|
|
* @param int $size |
|
185
|
|
|
* @param int $site |
|
186
|
|
|
* @param int $withdate |
|
187
|
|
|
* @return string |
|
188
|
|
|
*/ |
|
189
|
|
|
function rssDisplayForum( |
|
190
|
|
|
$url, |
|
191
|
|
|
$size = 15, |
|
192
|
|
|
$site = 0, |
|
193
|
|
|
$withdate = 0 |
|
|
|
|
|
|
194
|
|
|
): string { |
|
195
|
|
|
global $rssContent; |
|
196
|
|
|
$recents = []; |
|
197
|
|
|
$opened = false; |
|
198
|
|
|
$page = ''; |
|
199
|
|
|
$site = 0 === (int)$site ? 1 : 0; |
|
200
|
|
|
rssRetrieve($url); |
|
201
|
|
|
if ($size > 0) { |
|
202
|
|
|
$recents = array_slice($rssContent, $site, $size + 1 - $site); |
|
203
|
|
|
} |
|
204
|
|
|
foreach ($recents as $article) { |
|
205
|
|
|
$type = $article['type']; |
|
206
|
|
|
if (0 === $type) { |
|
207
|
|
|
if ($opened) { |
|
208
|
|
|
$page .= '</ul>'; |
|
209
|
|
|
$opened = false; |
|
210
|
|
|
} |
|
211
|
|
|
$page .= '<b>'; |
|
212
|
|
|
} elseif (!$opened) { |
|
213
|
|
|
$page .= '<ul>'; |
|
214
|
|
|
$opened = true; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
$title = $article['title']; |
|
218
|
|
|
$link = $article['link']; |
|
219
|
|
|
|
|
220
|
|
|
$page .= "<img src=\"../assets/images/admin/comment.png\" border=0 > <a href=\"${link}\">${title}</a><br><br>"; |
|
221
|
|
|
|
|
222
|
|
|
if (0 === $type) { |
|
223
|
|
|
$page .= '</b>'; |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
if ($opened) { |
|
227
|
|
|
$page .= '</ul>'; |
|
228
|
|
|
} |
|
229
|
|
|
return $page; |
|
230
|
|
|
} |
|
231
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.