@@ -71,7 +71,7 @@ class filter_smartmedia extends moodle_text_filter {
71
71
*
72
72
* @var array
73
73
*/
74
- private $ mediatypes = array (
74
+ private $ mediatypes = [
75
75
'aac ' , // Type: audio/aac.
76
76
'au ' , // Type: audio/au.
77
77
'mp3 ' , // Type: audio/mp3.
@@ -104,19 +104,19 @@ class filter_smartmedia extends moodle_text_filter {
104
104
'asf ' , // Type: video/x-ms-asf.
105
105
'avi ' , // Type: video/x-ms-wm.
106
106
'wmv ' , // Type: video/x-ms-wmv.
107
- ) ;
107
+ ] ;
108
108
109
109
/**
110
110
* Types of media that most browsers will play natively.
111
111
*
112
112
* @var array
113
113
*/
114
- private $ browsernative = array (
114
+ private $ browsernative = [
115
115
'.mp3 ' , // Type: audio/mp3.
116
116
'.ogg ' , // Type: audio/ogg.
117
117
'.mp4 ' , // Type: video/mp4.
118
118
'.webm ' , // Type: video/webm.
119
- ) ;
119
+ ] ;
120
120
121
121
/**
122
122
* Conversion controller used for filtering.
@@ -207,9 +207,9 @@ private function get_browser_native_types() : string {
207
207
* @return array $elements The smart media elements to embed.
208
208
*/
209
209
private function get_smart_elements (string $ linkhref ) : array {
210
- $ urls = array () ;
211
- $ options = array () ;
212
- $ elements = array () ;
210
+ $ urls = [] ;
211
+ $ options = [] ;
212
+ $ elements = [] ;
213
213
$ moodleurl = new \moodle_url ($ linkhref );
214
214
215
215
$ smartmedia = $ this ->conversion ->get_smart_media ($ moodleurl );
@@ -223,12 +223,12 @@ private function get_smart_elements(string $linkhref) : array {
223
223
$ options ['height ' ] = core_media_player_native::get_attribute ($ linkhref , 'height ' , PARAM_INT );
224
224
$ options ['name ' ] = core_media_player_native::get_attribute ($ linkhref , 'title ' );
225
225
226
- $ elements = array (
226
+ $ elements = [
227
227
'urls ' => $ urls ,
228
228
'options ' => $ options ,
229
229
'download ' => $ smartmedia ['download ' ],
230
- 'metadata ' => $ smartmedia ['data ' ]
231
- ) ;
230
+ 'metadata ' => $ smartmedia ['data ' ],
231
+ ] ;
232
232
}
233
233
234
234
return [$ smartmedia ['context ' ], $ elements ];
@@ -267,7 +267,7 @@ private function get_embed_markup(string $linkhref, array $urls, array $options,
267
267
$ name = $ options ['name ' ];
268
268
$ width = $ options ['width ' ];
269
269
$ height = $ options ['height ' ];
270
- $ embedoptions = array () ;
270
+ $ embedoptions = [] ;
271
271
$ downloaddata = '<video ' ;
272
272
273
273
$ videojs = new \media_videojs_plugin ();
@@ -290,8 +290,8 @@ private function get_embed_markup(string $linkhref, array $urls, array $options,
290
290
$ decoded = json_decode (htmlspecialchars_decode ($ originalvalue ));
291
291
$ decoded ->html5 = [
292
292
'hls ' => [
293
- 'enableLowInitialPlaylist ' => true
294
- ]
293
+ 'enableLowInitialPlaylist ' => true ,
294
+ ],
295
295
];
296
296
297
297
$ newvalue = htmlspecialchars (json_encode ($ decoded ));
@@ -302,9 +302,9 @@ private function get_embed_markup(string $linkhref, array $urls, array $options,
302
302
if (!empty ($ download )) {
303
303
foreach ($ download as $ url ) {
304
304
if ($ this ->string_ends_with ($ url ->out (), '.mp4 ' )) {
305
- $ downloaddata .= 'data-download-video=" ' . $ url ->out (true , array ( 'forcedownload ' => true ) ). '" ' ;
305
+ $ downloaddata .= 'data-download-video=" ' . $ url ->out (true , [ 'forcedownload ' => true ] ). '" ' ;
306
306
} else if ($ this ->string_ends_with ($ url ->out (), '.mp3 ' )) {
307
- $ downloaddata .= 'data-download-audio=" ' . $ url ->out (true , array ( 'forcedownload ' => true ) ). '" ' ;
307
+ $ downloaddata .= 'data-download-audio=" ' . $ url ->out (true , [ 'forcedownload ' => true ] ). '" ' ;
308
308
}
309
309
}
310
310
$ newtext = preg_replace ('/\<video / ' , $ downloaddata , $ newtext );
@@ -318,7 +318,7 @@ private function get_embed_markup(string $linkhref, array $urls, array $options,
318
318
new moodle_url ('/filter/smartmedia/download_metadata.php ' , [
319
319
'sesskey ' => sesskey (),
320
320
'conv ' => base64_encode ($ linkhref ),
321
- 'title ' => base64_encode (end ($ components ))
321
+ 'title ' => base64_encode (end ($ components )),
322
322
]),
323
323
get_string ('downloadmetadata ' , 'filter_smartmedia ' )
324
324
) . '' ;
@@ -475,7 +475,7 @@ private function replace($target, $fulltext) : array {
475
475
$ replacedlink = \html_writer::div ($ this ->get_placeholder_markup ($ target , $ fulltext ), 'local-smartmedia-wrapper ' );
476
476
$ replaced = true ;
477
477
} else {
478
- // Do nothing, no replacement candidate
478
+ // Do nothing, no replacement candidate.
479
479
$ replacedlink = $ fulltext ;
480
480
$ replaced = false ;
481
481
}
@@ -535,7 +535,7 @@ private function url_from_context($context) {
535
535
* @param array $options Extra options.
536
536
* @return string $newtext The filtered Text.
537
537
*/
538
- public function filter ($ text , array $ options = array () ) {
538
+ public function filter ($ text , array $ options = [] ) {
539
539
global $ SESSION ;
540
540
541
541
// First check the page URL's for flags. Prevents Ajax load missing them.
@@ -565,7 +565,7 @@ public function filter($text, array $options = array()) {
565
565
return $ text ;
566
566
}
567
567
568
- if (!is_string ($ text ) or empty ($ text )) {
568
+ if (!is_string ($ text ) || empty ($ text )) {
569
569
// Non string data can not be filtered anyway.
570
570
return $ text ;
571
571
}
@@ -653,8 +653,13 @@ public function filter($text, array $options = array()) {
653
653
// Check if this link node still exists. That's the ones we want.
654
654
$ exists = false ;
655
655
foreach ($ newlinks as $ newlink ) {
656
- if ($ link ->isSameNode ($ newlink )) {
657
- $ exists = true ;
656
+ try {
657
+ if ($ link ->isSameNode ($ newlink )) {
658
+ $ exists = true ;
659
+ }
660
+ } catch (\Throwable $ e ) {
661
+ // Some error, likely when the $link is no longer a valid DOMElement.
662
+ continue ;
658
663
}
659
664
}
660
665
if (!$ exists ) {
0 commit comments