Skip to content

Commit f054713

Browse files
Merge pull request #44 from catalyst/45-fixes
45 fixes
2 parents 13cdd0f + 5566fc6 commit f054713

File tree

9 files changed

+149
-142
lines changed

9 files changed

+149
-142
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ 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
12-
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
@@ -22,19 +22,24 @@
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
2424

25+
use core\url;
26+
use local_smartmedia\aws_api;
27+
use local_smartmedia\aws_elastic_transcoder;
28+
use local_smartmedia\conversion;
29+
2530
require_once(__DIR__ . '/../../config.php');
2631
require_admin();
2732
confirm_sesskey();
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: 38 additions & 42 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

@@ -130,16 +124,17 @@ class filter_smartmedia extends moodle_text_filter {
130124
*
131125
* @param context $context The current context.
132126
* @param array $localconfig Any context-specific configuration for this filter.
127+
* @param conversion|null $conversion
133128
*/
134-
public function __construct($context, array $localconfig, \local_smartmedia\conversion $conversion = null) {
129+
public function __construct($context, array $localconfig, conversion $conversion = null) {
135130
parent::__construct($context, $localconfig);
136131

137132
if (!empty($conversion)) {
138133
$this->conversion = $conversion;
139134
} else {
140135
$api = new aws_api();
141136
$transcoder = new aws_elastic_transcoder($api->create_elastic_transcoder_client());
142-
$this->conversion = new \local_smartmedia\conversion($transcoder);
137+
$this->conversion = new conversion($transcoder);
143138
}
144139
}
145140

@@ -176,7 +171,7 @@ private function videojs_enabled() {
176171
if ($this->videojsenabled == self::VIDEOJS_ENABLED_NOT_SET) {
177172
// If we haven't already determined Videjos plugin enabled status
178173
// do so now.
179-
$enabledplayes = \core\plugininfo\media::get_enabled_plugins();
174+
$enabledplayes = media::get_enabled_plugins();
180175
if (in_array('videojs', $enabledplayes) && class_exists('media_videojs_plugin')) {
181176
$this->videojsenabled = self::VIDEOJS_ENABLED;
182177
} else {
@@ -193,7 +188,7 @@ private function videojs_enabled() {
193188
*
194189
* @return string $typestring String of supported types.
195190
*/
196-
private function get_browser_native_types() : string {
191+
private function get_browser_native_types(): string {
197192
$typestring = '\\'. implode('|\\', $this->browsernative);
198193

199194
return $typestring;
@@ -206,11 +201,11 @@ private function get_browser_native_types() : string {
206201
* @param string $linkhref The href to the source file.
207202
* @return array $elements The smart media elements to embed.
208203
*/
209-
private function get_smart_elements(string $linkhref) : array {
204+
private function get_smart_elements(string $linkhref): array {
210205
$urls = [];
211206
$options = [];
212207
$elements = [];
213-
$moodleurl = new \moodle_url($linkhref);
208+
$moodleurl = new url($linkhref);
214209

215210
$smartmedia = $this->conversion->get_smart_media($moodleurl);
216211

@@ -241,7 +236,7 @@ private function get_smart_elements(string $linkhref) : array {
241236
* @param string $needle The string to search for.
242237
* @return bool Result of string check.
243238
*/
244-
private function string_ends_with(string $haystack, string $needle) : bool {
239+
private function string_ends_with(string $haystack, string $needle): bool {
245240
$length = strlen($needle);
246241
if ($length == 0) {
247242
return true;
@@ -261,7 +256,7 @@ private function string_ends_with(string $haystack, string $needle) : bool {
261256
* @param bool $hasdata Whether there is metadata associated with this smartmedia.
262257
* @return string $newtext Rendered VideoJS markup.
263258
*/
264-
private function get_embed_markup(string $linkhref, array $urls, array $options, array $download, bool $hasdata) : string {
259+
private function get_embed_markup(string $linkhref, array $urls, array $options, array $download, bool $hasdata): string {
265260
global $OUTPUT;
266261

267262
$name = $options['name'];
@@ -270,7 +265,7 @@ private function get_embed_markup(string $linkhref, array $urls, array $options,
270265
$embedoptions = [];
271266
$downloaddata = '<video ';
272267

273-
$videojs = new \media_videojs_plugin();
268+
$videojs = new media_videojs_plugin();
274269
$newtext = $videojs->embed($urls, $name, $width, $height, $embedoptions);
275270
// TODO: Deal with fallback link.
276271

@@ -315,7 +310,7 @@ private function get_embed_markup(string $linkhref, array $urls, array $options,
315310
// Explode the url to get the filename component for naming.
316311
$components = explode('/', $linkhref);
317312
$newtext .= $OUTPUT->single_button(
318-
new moodle_url('/filter/smartmedia/download_metadata.php', [
313+
new url('/filter/smartmedia/download_metadata.php', [
319314
'sesskey' => sesskey(),
320315
'conv' => base64_encode($linkhref),
321316
'title' => base64_encode(end($components)),
@@ -335,9 +330,9 @@ private function get_embed_markup(string $linkhref, array $urls, array $options,
335330
* @param string $fulltext The full text of the element.
336331
* @return string $markup The placeholder markup.
337332
*/
338-
private function get_placeholder_markup(string $linkhref, string $fulltext) : string {
333+
private function get_placeholder_markup(string $linkhref, string $fulltext): string {
339334
global $OUTPUT;
340-
$moodleurl = new \moodle_url($linkhref);
335+
$moodleurl = new url($linkhref);
341336
$path = $moodleurl->get_path();
342337
$args = explode('/', $path);
343338
$filename = array_pop($args);
@@ -349,7 +344,7 @@ private function get_placeholder_markup(string $linkhref, string $fulltext) : st
349344
}
350345

351346
$markup = $fulltext;
352-
$context = new \stdClass();
347+
$context = new stdClass();
353348

354349
// If file is of type that is browser native,
355350
// don't show placeholder.
@@ -376,10 +371,11 @@ private function get_placeholder_markup(string $linkhref, string $fulltext) : st
376371
* Given a matched link check if there is smartmedia available,
377372
* and return updated link if there is.
378373
*
379-
* @param array $matches An array of link matches.
374+
* @param string $target
375+
* @param string $fulltext
380376
* @return array Array of newtext and whether the text was replaced
381377
*/
382-
private function replace($target, $fulltext) : array {
378+
private function replace($target, $fulltext): array {
383379
global $OUTPUT, $SESSION;
384380

385381
list($context, $elements) = $this->get_smart_elements($target); // Get the smartmedia elements if they exist.
@@ -390,7 +386,7 @@ private function replace($target, $fulltext) : array {
390386
// The placeholder should only be displayed if this file will actually be converted.
391387
// We need to verify that the file will be queued for conversion.
392388
// Timecreated check.
393-
$file = $this->conversion->get_file_from_url(new \moodle_url($target));
389+
$file = $this->conversion->get_file_from_url(new url($target));
394390
if (!empty($file) && $file->get_timecreated() < time() - $lookback) {
395391
$placeholder = false;
396392
}
@@ -421,12 +417,12 @@ private function replace($target, $fulltext) : array {
421417
if ($usesource && has_capability('filter/smartmedia:viewsource', $context)) {
422418
// Return the original markup, along with a button to swap back to smartmedia.
423419
$url->param('sm', $current);
424-
$button = new \single_button(
420+
$button = new single_button(
425421
$url,
426422
get_string('viewoptimised', 'filter_smartmedia'),
427423
'get'
428424
);
429-
$button = \html_writer::div($OUTPUT->render($button), 'local-smartmedia-view-optimised');
425+
$button = html_writer::div($OUTPUT->render($button), 'local-smartmedia-view-optimised');
430426

431427
// Output the original source media and return.
432428
if (!array_key_exists($current, $viewsource)) {
@@ -439,7 +435,7 @@ private function replace($target, $fulltext) : array {
439435
$fulltext = str_replace('&nbsp;', '', $fulltext);
440436

441437
// Put in the smartmedia wrapper to keep styling consistent.
442-
$html = \html_writer::div($fulltext . $button, 'local-smartmedia-wrapper');
438+
$html = html_writer::div($fulltext . $button, 'local-smartmedia-wrapper');
443439
return [$html, false];
444440
}
445441
// Now store the state back into the session.
@@ -459,20 +455,20 @@ private function replace($target, $fulltext) : array {
459455
if (has_capability('filter/smartmedia:viewsource', $context)) {
460456
// Add a button to view source.
461457
$url->param('source', $current);
462-
$button = new \single_button(
458+
$button = new single_button(
463459
$url,
464460
get_string('viewsource', 'filter_smartmedia'),
465461
'get'
466462
);
467463
// Wrap just smartmedia content inside a wrapper div for styling targeting.
468-
$replacedlink = \html_writer::div($replacedlink . $OUTPUT->render($button), 'local-smartmedia-wrapper');
464+
$replacedlink = html_writer::div($replacedlink . $OUTPUT->render($button), 'local-smartmedia-wrapper');
469465
} else {
470-
$replacedlink = \html_writer::div($replacedlink, 'local-smartmedia-wrapper');
466+
$replacedlink = html_writer::div($replacedlink, 'local-smartmedia-wrapper');
471467
}
472468
$replaced = true;
473469
} else if ($placeholder) {
474470
// If no smartmedia found add the correct placeholder markup.
475-
$replacedlink = \html_writer::div($this->get_placeholder_markup($target, $fulltext), 'local-smartmedia-wrapper');
471+
$replacedlink = html_writer::div($this->get_placeholder_markup($target, $fulltext), 'local-smartmedia-wrapper');
476472
$replaced = true;
477473
} else {
478474
// Do nothing, no replacement candidate.
@@ -487,7 +483,7 @@ private function replace($target, $fulltext) : array {
487483
* Gets the course/page url from the context.
488484
*
489485
* @param context $context
490-
* @return moodle_url $url
486+
* @return \core\url $url
491487
*/
492488
private function url_from_context($context) {
493489
global $PAGE;
@@ -499,11 +495,11 @@ private function url_from_context($context) {
499495
$course = null;
500496
$cm = null;
501497

502-
if ($context instanceof \context_module) {
498+
if ($context instanceof module) {
503499
list($course, $cm) = get_course_and_cm_from_cmid($context->instanceid);
504500
}
505501

506-
if ($context instanceof \context_course) {
502+
if ($context instanceof course) {
507503
$course = get_course($context->instanceid);
508504
}
509505

@@ -512,7 +508,7 @@ private function url_from_context($context) {
512508

513509
// Start with course, as its the most likely to exist.
514510
if ($isajax && !empty($course)) {
515-
$url = new moodle_url('/course/view.php', ['id' => $course->id]);
511+
$url = new url('/course/view.php', ['id' => $course->id]);
516512
}
517513

518514
// Then check the course module has a URL, if so then use that instead.
@@ -521,7 +517,7 @@ private function url_from_context($context) {
521517
}
522518

523519
// 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)) {
520+
if ($context instanceof module && strpos($url, '/course/view.php') !== false && !empty($cm)) {
525521
$url->set_anchor('section-' . $cm->sectionnum);
526522
}
527523

@@ -657,7 +653,7 @@ public function filter($text, array $options = []) {
657653
if ($link->isSameNode($newlink)) {
658654
$exists = true;
659655
}
660-
} catch (\Throwable $e) {
656+
} catch (Throwable $e) {
661657
// Some error, likely when the $link is no longer a valid DOMElement.
662658
continue;
663659
}

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)