22
22
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
23
*/
24
24
25
+ use block_rss_client \output \channel_image ;
26
+ use block_rss_client \output \feed ;
25
27
use block_rss_thumbnails \output \block ;
28
+ use block_rss_thumbnails \output \item ;
26
29
27
30
defined ('MOODLE_INTERNAL ' ) || die ();
28
31
global $ CFG ;
37
40
*/
38
41
class block_rss_thumbnails extends block_rss_client {
39
42
43
+ /** @var int The default caroussel speed */
40
44
const DEFAULT_CAROUSSEL_SPEED = 4000 ;
41
45
42
46
/** @var bool track whether any of the output feeds have recorded failures */
@@ -54,7 +58,7 @@ public function init() {
54
58
/**
55
59
* Content for the block
56
60
*
57
- * @return \ stdClass|string|null
61
+ * @return stdClass|string|null
58
62
* @throws coding_exception
59
63
*/
60
64
public function get_content () {
@@ -67,7 +71,7 @@ public function get_content() {
67
71
return $ this ->content ;
68
72
}
69
73
70
- // initalise block content object
74
+ // Initialise block content object.
71
75
$ this ->content = new stdClass ;
72
76
$ this ->content ->text = '' ;
73
77
$ this ->content ->footer = '' ;
@@ -78,7 +82,7 @@ public function get_content() {
78
82
79
83
if (!isset ($ this ->config )) {
80
84
// The block has yet to be configured - just display configure message in
81
- // the block if user has permission to configure it
85
+ // the block if user has permission to configure it.
82
86
83
87
if (has_capability ('block/rss_client:manageanyfeeds ' , $ this ->context )) {
84
88
$ this ->content ->text = get_string ('feedsconfigurenewinstance2 ' , 'block_rss_client ' );
@@ -138,7 +142,7 @@ public function get_content() {
138
142
* @param array $feedrecords The feed records from the database.
139
143
* @return block_rss_client\output\footer|null The renderable footer or null if none should be displayed.
140
144
*/
141
- protected function get_footer ($ feedrecords ) {
145
+ protected function get_footer ($ feedrecords ) : ? block_rss_client \ output \ footer {
142
146
$ footer = null ;
143
147
144
148
if (!empty ($ this ->config ->show_channel_link )) {
@@ -171,12 +175,12 @@ protected function get_footer($feedrecords) {
171
175
/**
172
176
* Returns the html of a feed to be displaed in the block
173
177
*
174
- * @param mixed feedrecord The feed record from the database
175
- * @param int maxentries The maximum number of entries to be displayed
176
- * @param boolean showtitle Should the feed title be displayed in html
178
+ * @param mixed $ feedrecord The feed record from the database
179
+ * @param int $ maxentries The maximum number of entries to be displayed
180
+ * @param boolean $ showtitle Should the feed title be displayed in html
177
181
* @return block_rss_client\output\feed|null The renderable feed or null of there is an error
178
182
*/
179
- public function get_feed ($ feedrecord , $ maxentries , $ showtitle ) {
183
+ public function get_feed ($ feedrecord , $ maxentries , $ showtitle ) : ? feed {
180
184
global $ CFG ;
181
185
require_once ($ CFG ->libdir . '/simplepie/moodle_simplepie.php ' );
182
186
@@ -186,7 +190,15 @@ public function get_feed($feedrecord, $maxentries, $showtitle) {
186
190
return null ;
187
191
}
188
192
189
- $ simplepiefeed = new moodle_simplepie ($ feedrecord ->url );
193
+ if (!empty ($ feedrecord ->url )) {
194
+ $ simplepiefeed = new moodle_simplepie ($ feedrecord ->url );
195
+ } else {
196
+ $ simplepiefeed = new moodle_simplepie ();
197
+ $ simplepiefeed ->set_file ($ feedrecord ->fileurl );
198
+ $ simplepiefeed ->enable_cache (false );
199
+ $ simplepiefeed ->init ();
200
+
201
+ }
190
202
191
203
if (isset ($ CFG ->block_rss_client_timeout )) {
192
204
$ simplepiefeed ->set_cache_duration ($ CFG ->block_rss_client_timeout * 60 );
@@ -209,12 +221,12 @@ public function get_feed($feedrecord, $maxentries, $showtitle) {
209
221
}
210
222
211
223
if (empty ($ this ->config ->title )) {
212
- //NOTE: this means the 'last feed' displayed wins the block title - but
213
- //this is exiting behaviour..
224
+ // NOTE: this means the 'last feed' displayed wins the block title - but
225
+ // this is exiting behaviour..
214
226
$ this ->title = strip_tags ($ feedtitle );
215
227
}
216
228
217
- $ feed = new \ block_rss_client \ output \ feed ($ feedtitle , $ showtitle , false );
229
+ $ feed = new feed ($ feedtitle , $ showtitle , false );
218
230
219
231
if ($ simplepieitems = $ simplepiefeed ->get_items (0 , $ maxentries )) {
220
232
foreach ($ simplepieitems as $ simplepieitem ) {
@@ -231,7 +243,7 @@ public function get_feed($feedrecord, $maxentries, $showtitle) {
231
243
return $ cat ->term ;
232
244
}, $ simplepieitem ->get_categories ());
233
245
234
- $ item = new \ block_rss_thumbnails \ output \ item (
246
+ $ item = new item (
235
247
$ simplepieitem ->get_id (),
236
248
new moodle_url ($ simplepieitem ->get_link ()),
237
249
$ simplepieitem ->get_title (),
@@ -247,7 +259,7 @@ public function get_feed($feedrecord, $maxentries, $showtitle) {
247
259
} catch (moodle_exception $ e ) {
248
260
// If there is an error with the RSS item, we don't
249
261
// want to crash the page. Specifically, moodle_url can
250
- // throw an exception of the param is an extremely
262
+ // throw an exception if the param is an extremely
251
263
// malformed url.
252
264
debugging ($ e ->getMessage ());
253
265
}
@@ -257,15 +269,15 @@ public function get_feed($feedrecord, $maxentries, $showtitle) {
257
269
// Feed image.
258
270
if ($ imageurl = $ simplepiefeed ->get_image_url ()) {
259
271
try {
260
- $ image = new \ block_rss_client \ output \ channel_image (
272
+ $ image = new channel_image (
261
273
new moodle_url ($ imageurl ),
262
274
$ simplepiefeed ->get_image_title (),
263
275
new moodle_url ($ simplepiefeed ->get_image_link ())
264
276
);
265
277
266
278
$ feed ->set_image ($ image );
267
279
} catch (moodle_exception $ e ) {
268
- // If there is an error with the RSS image, we don'twant to
280
+ // If there is an error with the RSS image, we don't want to
269
281
// crash the page. Specifically, moodle_url can throw an
270
282
// exception if the param is an extremely malformed url.
271
283
debugging ($ e ->getMessage ());
0 commit comments