Skip to content

Commit 494250f

Browse files
committed
misc: 4.5 fixups
1 parent 13cdd0f commit 494250f

File tree

9 files changed

+139
-140
lines changed

9 files changed

+139
-140
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ jobs:
77
ci:
88
uses: catalyst/catalyst-moodle-workflows/.github/workflows/ci.yml@main
99
with:
10-
extra_plugin_runners: 'moodle-plugin-ci add-plugin catalyst/moodle-local_aws; moodle-plugin-ci add-plugin --branch MOODLE_401_STABLE catalyst/moodle-local_smartmedia'
10+
extra_plugin_runners: 'moodle-plugin-ci add-plugin --branch MOODLE_405_STABLE catalyst/moodle-local_smartmedia'
1111
disable_phpcpd: true
1212
disable_phpdoc: true

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
[![Build Status](https://travis-ci.org/catalyst/moodle-filter_smartmedia.svg?branch=master)](https://travis-ci.org/catalyst/moodle-filter_smartmedia)
2-
31
# Smart Media Filter #
42

53
Smart media aims to enhance Moodle's processing and delivery of multimedia while simplifying the process of managing multimedia for teachers and students.
@@ -11,7 +9,7 @@ The Smart Media Filter (this plugin) works to help display smart media content i
119
## Supported Moodle Versions
1210
This plugin currently supports Moodle:
1311

14-
* 3.9
12+
* 4.5
1513

1614
## Plugin Installation ##
1715

classes/privacy/provider.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,23 @@
2424

2525
namespace filter_smartmedia\privacy;
2626

27+
use core_privacy\local\metadata\null_provider;
28+
2729
/**
2830
* Privacy Subsystem for filter_smartmedia implementing null_provider.
2931
*
3032
* @copyright 2019 Matt Porritt <mattp@catalyst-au.net>
3133
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3234
*/
33-
class provider implements \core_privacy\local\metadata\null_provider {
35+
class provider implements null_provider {
3436

3537
/**
3638
* Get the language string identifier with the component's language
3739
* file to explain why this plugin stores no data.
3840
*
3941
* @return string
4042
*/
41-
public static function get_reason() : string {
43+
public static function get_reason(): string {
4244
return 'privacy:metadata';
4345
}
4446
}

db/access.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
'captype' => 'read',
3030
'contextlevel' => CONTEXT_COURSE,
3131
'archetypes' => [
32-
'user' => CAP_ALLOW
33-
]
32+
'user' => CAP_ALLOW,
33+
],
3434
],
3535
];

download_metadata.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use core\url;
18+
use local_smartmedia\aws_api;
19+
use local_smartmedia\aws_elastic_transcoder;
20+
use local_smartmedia\conversion;
21+
1722
/**
1823
* Smart media metadata download portal.
1924
*
@@ -28,13 +33,13 @@
2833

2934
$conv = required_param('conv', PARAM_TEXT);
3035
$titleraw = required_param('title', PARAM_TEXT);
31-
$convurl = new moodle_url(base64_decode($conv));
36+
$convurl = new url(base64_decode($conv));
3237
$title = base64_decode($titleraw);
3338

3439
// Get smartmedia elements.
35-
$api = new \local_smartmedia\aws_api();
36-
$transcoder = new \local_smartmedia\aws_elastic_transcoder($api->create_elastic_transcoder_client());
37-
$conversion = new \local_smartmedia\conversion($transcoder);
40+
$api = new aws_api();
41+
$transcoder = new aws_elastic_transcoder($api->create_elastic_transcoder_client());
42+
$conversion = new conversion($transcoder);
3843
// Get files instead of raw urls.
3944
$smartmedia = $conversion->get_smart_media($convurl, false, true);
4045

filter.php

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17-
/**
18-
* Smart media filtering
19-
*
20-
* This filter will replace any links to a compatible media file with
21-
* a smart media plugin that plays that media inline and uses AI/ML
22-
* techniques to improve user experience.
23-
*
24-
* @package filter_smartmedia
25-
* @copyright 2019 Matt Porritt <mattp@catalyst-au.net>V
26-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27-
*/
28-
17+
use local_smartmedia\conversion;
18+
use core\plugininfo\media;
19+
use core\url;
20+
use core\output\html_writer;
21+
use core\context\module;
22+
use core\context\course;
2923
use local_smartmedia\aws_api;
3024
use local_smartmedia\aws_elastic_transcoder;
3125

@@ -62,7 +56,7 @@ class filter_smartmedia extends moodle_text_filter {
6256
/**
6357
* Enabled status of the video JS player.
6458
*
65-
* @var integer
59+
* @var int
6660
*/
6761
private $videojsenabled = self::VIDEOJS_ENABLED_NOT_SET;
6862

@@ -131,15 +125,15 @@ class filter_smartmedia extends moodle_text_filter {
131125
* @param context $context The current context.
132126
* @param array $localconfig Any context-specific configuration for this filter.
133127
*/
134-
public function __construct($context, array $localconfig, \local_smartmedia\conversion $conversion = null) {
128+
public function __construct($context, array $localconfig, conversion $conversion = null) {
135129
parent::__construct($context, $localconfig);
136130

137131
if (!empty($conversion)) {
138132
$this->conversion = $conversion;
139133
} else {
140134
$api = new aws_api();
141135
$transcoder = new aws_elastic_transcoder($api->create_elastic_transcoder_client());
142-
$this->conversion = new \local_smartmedia\conversion($transcoder);
136+
$this->conversion = new conversion($transcoder);
143137
}
144138
}
145139

@@ -176,7 +170,7 @@ private function videojs_enabled() {
176170
if ($this->videojsenabled == self::VIDEOJS_ENABLED_NOT_SET) {
177171
// If we haven't already determined Videjos plugin enabled status
178172
// do so now.
179-
$enabledplayes = \core\plugininfo\media::get_enabled_plugins();
173+
$enabledplayes = media::get_enabled_plugins();
180174
if (in_array('videojs', $enabledplayes) && class_exists('media_videojs_plugin')) {
181175
$this->videojsenabled = self::VIDEOJS_ENABLED;
182176
} else {
@@ -193,7 +187,7 @@ private function videojs_enabled() {
193187
*
194188
* @return string $typestring String of supported types.
195189
*/
196-
private function get_browser_native_types() : string {
190+
private function get_browser_native_types(): string {
197191
$typestring = '\\'. implode('|\\', $this->browsernative);
198192

199193
return $typestring;
@@ -206,11 +200,11 @@ private function get_browser_native_types() : string {
206200
* @param string $linkhref The href to the source file.
207201
* @return array $elements The smart media elements to embed.
208202
*/
209-
private function get_smart_elements(string $linkhref) : array {
203+
private function get_smart_elements(string $linkhref): array {
210204
$urls = [];
211205
$options = [];
212206
$elements = [];
213-
$moodleurl = new \moodle_url($linkhref);
207+
$moodleurl = new url($linkhref);
214208

215209
$smartmedia = $this->conversion->get_smart_media($moodleurl);
216210

@@ -241,7 +235,7 @@ private function get_smart_elements(string $linkhref) : array {
241235
* @param string $needle The string to search for.
242236
* @return bool Result of string check.
243237
*/
244-
private function string_ends_with(string $haystack, string $needle) : bool {
238+
private function string_ends_with(string $haystack, string $needle): bool {
245239
$length = strlen($needle);
246240
if ($length == 0) {
247241
return true;
@@ -261,7 +255,7 @@ private function string_ends_with(string $haystack, string $needle) : bool {
261255
* @param bool $hasdata Whether there is metadata associated with this smartmedia.
262256
* @return string $newtext Rendered VideoJS markup.
263257
*/
264-
private function get_embed_markup(string $linkhref, array $urls, array $options, array $download, bool $hasdata) : string {
258+
private function get_embed_markup(string $linkhref, array $urls, array $options, array $download, bool $hasdata): string {
265259
global $OUTPUT;
266260

267261
$name = $options['name'];
@@ -270,7 +264,7 @@ private function get_embed_markup(string $linkhref, array $urls, array $options,
270264
$embedoptions = [];
271265
$downloaddata = '<video ';
272266

273-
$videojs = new \media_videojs_plugin();
267+
$videojs = new media_videojs_plugin();
274268
$newtext = $videojs->embed($urls, $name, $width, $height, $embedoptions);
275269
// TODO: Deal with fallback link.
276270

@@ -315,7 +309,7 @@ private function get_embed_markup(string $linkhref, array $urls, array $options,
315309
// Explode the url to get the filename component for naming.
316310
$components = explode('/', $linkhref);
317311
$newtext .= $OUTPUT->single_button(
318-
new moodle_url('/filter/smartmedia/download_metadata.php', [
312+
new url('/filter/smartmedia/download_metadata.php', [
319313
'sesskey' => sesskey(),
320314
'conv' => base64_encode($linkhref),
321315
'title' => base64_encode(end($components)),
@@ -335,9 +329,9 @@ private function get_embed_markup(string $linkhref, array $urls, array $options,
335329
* @param string $fulltext The full text of the element.
336330
* @return string $markup The placeholder markup.
337331
*/
338-
private function get_placeholder_markup(string $linkhref, string $fulltext) : string {
332+
private function get_placeholder_markup(string $linkhref, string $fulltext): string {
339333
global $OUTPUT;
340-
$moodleurl = new \moodle_url($linkhref);
334+
$moodleurl = new url($linkhref);
341335
$path = $moodleurl->get_path();
342336
$args = explode('/', $path);
343337
$filename = array_pop($args);
@@ -349,7 +343,7 @@ private function get_placeholder_markup(string $linkhref, string $fulltext) : st
349343
}
350344

351345
$markup = $fulltext;
352-
$context = new \stdClass();
346+
$context = new stdClass();
353347

354348
// If file is of type that is browser native,
355349
// don't show placeholder.
@@ -379,7 +373,7 @@ private function get_placeholder_markup(string $linkhref, string $fulltext) : st
379373
* @param array $matches An array of link matches.
380374
* @return array Array of newtext and whether the text was replaced
381375
*/
382-
private function replace($target, $fulltext) : array {
376+
private function replace($target, $fulltext): array {
383377
global $OUTPUT, $SESSION;
384378

385379
list($context, $elements) = $this->get_smart_elements($target); // Get the smartmedia elements if they exist.
@@ -390,7 +384,7 @@ private function replace($target, $fulltext) : array {
390384
// The placeholder should only be displayed if this file will actually be converted.
391385
// We need to verify that the file will be queued for conversion.
392386
// Timecreated check.
393-
$file = $this->conversion->get_file_from_url(new \moodle_url($target));
387+
$file = $this->conversion->get_file_from_url(new url($target));
394388
if (!empty($file) && $file->get_timecreated() < time() - $lookback) {
395389
$placeholder = false;
396390
}
@@ -421,12 +415,12 @@ private function replace($target, $fulltext) : array {
421415
if ($usesource && has_capability('filter/smartmedia:viewsource', $context)) {
422416
// Return the original markup, along with a button to swap back to smartmedia.
423417
$url->param('sm', $current);
424-
$button = new \single_button(
418+
$button = new single_button(
425419
$url,
426420
get_string('viewoptimised', 'filter_smartmedia'),
427421
'get'
428422
);
429-
$button = \html_writer::div($OUTPUT->render($button), 'local-smartmedia-view-optimised');
423+
$button = html_writer::div($OUTPUT->render($button), 'local-smartmedia-view-optimised');
430424

431425
// Output the original source media and return.
432426
if (!array_key_exists($current, $viewsource)) {
@@ -439,7 +433,7 @@ private function replace($target, $fulltext) : array {
439433
$fulltext = str_replace('&nbsp;', '', $fulltext);
440434

441435
// Put in the smartmedia wrapper to keep styling consistent.
442-
$html = \html_writer::div($fulltext . $button, 'local-smartmedia-wrapper');
436+
$html = html_writer::div($fulltext . $button, 'local-smartmedia-wrapper');
443437
return [$html, false];
444438
}
445439
// Now store the state back into the session.
@@ -459,20 +453,20 @@ private function replace($target, $fulltext) : array {
459453
if (has_capability('filter/smartmedia:viewsource', $context)) {
460454
// Add a button to view source.
461455
$url->param('source', $current);
462-
$button = new \single_button(
456+
$button = new single_button(
463457
$url,
464458
get_string('viewsource', 'filter_smartmedia'),
465459
'get'
466460
);
467461
// Wrap just smartmedia content inside a wrapper div for styling targeting.
468-
$replacedlink = \html_writer::div($replacedlink . $OUTPUT->render($button), 'local-smartmedia-wrapper');
462+
$replacedlink = html_writer::div($replacedlink . $OUTPUT->render($button), 'local-smartmedia-wrapper');
469463
} else {
470-
$replacedlink = \html_writer::div($replacedlink, 'local-smartmedia-wrapper');
464+
$replacedlink = html_writer::div($replacedlink, 'local-smartmedia-wrapper');
471465
}
472466
$replaced = true;
473467
} else if ($placeholder) {
474468
// If no smartmedia found add the correct placeholder markup.
475-
$replacedlink = \html_writer::div($this->get_placeholder_markup($target, $fulltext), 'local-smartmedia-wrapper');
469+
$replacedlink = html_writer::div($this->get_placeholder_markup($target, $fulltext), 'local-smartmedia-wrapper');
476470
$replaced = true;
477471
} else {
478472
// Do nothing, no replacement candidate.
@@ -487,7 +481,7 @@ private function replace($target, $fulltext) : array {
487481
* Gets the course/page url from the context.
488482
*
489483
* @param context $context
490-
* @return moodle_url $url
484+
* @return \core\url $url
491485
*/
492486
private function url_from_context($context) {
493487
global $PAGE;
@@ -499,11 +493,11 @@ private function url_from_context($context) {
499493
$course = null;
500494
$cm = null;
501495

502-
if ($context instanceof \context_module) {
496+
if ($context instanceof module) {
503497
list($course, $cm) = get_course_and_cm_from_cmid($context->instanceid);
504498
}
505499

506-
if ($context instanceof \context_course) {
500+
if ($context instanceof course) {
507501
$course = get_course($context->instanceid);
508502
}
509503

@@ -512,7 +506,7 @@ private function url_from_context($context) {
512506

513507
// Start with course, as its the most likely to exist.
514508
if ($isajax && !empty($course)) {
515-
$url = new moodle_url('/course/view.php', ['id' => $course->id]);
509+
$url = new url('/course/view.php', ['id' => $course->id]);
516510
}
517511

518512
// Then check the course module has a URL, if so then use that instead.
@@ -521,7 +515,7 @@ private function url_from_context($context) {
521515
}
522516

523517
// Setup a page anchor if on the course page and viewing a section.
524-
if ($context instanceof \context_module && strpos($url, '/course/view.php') !== false && !empty($cm)) {
518+
if ($context instanceof module && strpos($url, '/course/view.php') !== false && !empty($cm)) {
525519
$url->set_anchor('section-' . $cm->sectionnum);
526520
}
527521

@@ -657,7 +651,7 @@ public function filter($text, array $options = []) {
657651
if ($link->isSameNode($newlink)) {
658652
$exists = true;
659653
}
660-
} catch (\Throwable $e) {
654+
} catch (Throwable $e) {
661655
// Some error, likely when the $link is no longer a valid DOMElement.
662656
continue;
663657
}

lang/en/filter_smartmedia.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525

2626
defined('MOODLE_INTERNAL') || die();
2727

28-
$string['pluginname'] = 'Smart Media';
29-
30-
$string['filtername'] = 'Smart media';
31-
$string['privacy:metadata'] = 'The Smart media plugin does not store any personal data.';
32-
3328
$string['download'] = 'Download original file';
3429
$string['downloadmetadata'] = 'Download file metadata';
35-
$string['pending'] = 'Media conversion pending...';
3630
$string['enableplaceholder'] = 'Enable placeholder';
3731
$string['enableplaceholder_desc'] = 'When enabled a placeholder image will be displayed until smartmedia conversion completes';
32+
$string['filtername'] = 'Smart media';
33+
$string['pending'] = 'Media conversion pending...';
34+
$string['pluginname'] = 'Smart Media';
35+
36+
$string['privacy:metadata'] = 'The Smart media plugin does not store any personal data.';
37+
3838
$string['smartmedia:viewsource'] = 'View source media';
3939
$string['viewoptimised'] = 'View optimised media';
4040
$string['viewsource'] = 'View source media';

0 commit comments

Comments
 (0)