Skip to content

Commit f03d35a

Browse files
committed
fix: Move filter to /classes for 4.5 compat
1 parent f054713 commit f03d35a

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

filter.php renamed to classes/text_filter.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
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+
namespace filter_smartmedia;
18+
1719
use local_smartmedia\conversion;
1820
use core\plugininfo\media;
1921
use core\url;
@@ -22,6 +24,13 @@
2224
use core\context\course;
2325
use local_smartmedia\aws_api;
2426
use local_smartmedia\aws_elastic_transcoder;
27+
use core_media_manager;
28+
use core_media_player_native;
29+
use media_videojs_plugin;
30+
use DOMDocument;
31+
use DOMXPath;
32+
use stdClass;
33+
use core\output\single_button;
2534

2635
/**
2736
* Automatic smart media embedding filter class.
@@ -30,7 +39,7 @@
3039
* @copyright 2019 Matt Porritt <mattp@catalyst-au.net>
3140
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3241
*/
33-
class filter_smartmedia extends moodle_text_filter {
42+
class text_filter extends \core_filters\text_filter {
3443

3544
/**
3645
* Video.js plugin enabled status not set.
@@ -126,7 +135,7 @@ class filter_smartmedia extends moodle_text_filter {
126135
* @param array $localconfig Any context-specific configuration for this filter.
127136
* @param conversion|null $conversion
128137
*/
129-
public function __construct($context, array $localconfig, conversion $conversion = null) {
138+
public function __construct($context, array $localconfig, ?conversion $conversion = null) {
130139
parent::__construct($context, $localconfig);
131140

132141
if (!empty($conversion)) {
@@ -576,7 +585,7 @@ public function filter($text, array $options = []) {
576585
// Add a wrapping div so DOMDocument doesnt mangle the structure.
577586
$loadtext = '<div>' . $text . '</div>';
578587
// Ensure the encoding can be loaded by the domdoc.
579-
$loadtext = mb_convert_encoding($loadtext, 'HTML-ENTITIES', 'UTF-8');
588+
$loadtext = htmlspecialchars($loadtext);
580589

581590
// Supress warnings. HTML5 nodes currently throw warnings.
582591
// Use flags to prevent html and body tags from being included.
@@ -653,7 +662,7 @@ public function filter($text, array $options = []) {
653662
if ($link->isSameNode($newlink)) {
654663
$exists = true;
655664
}
656-
} catch (Throwable $e) {
665+
} catch (\Throwable $e) {
657666
// Some error, likely when the $link is no longer a valid DOMElement.
658667
continue;
659668
}

tests/filter_test.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
use core\context\course;
2222
use core\context\module;
2323
use local_smartmedia\conversion;
24+
use text_filter\text_filter;
2425

2526
defined('MOODLE_INTERNAL') || die();
2627

2728
global $CFG;
28-
require_once($CFG->dirroot . '/filter/smartmedia/filter.php'); // Include the code to test.
2929

3030
/**
31-
* Unit test for the filter_smartmedia
31+
* Unit test for the text_filter
3232
*
33-
* @package filter_smartmedia
33+
* @package text_filter
3434
* @copyright 2019 Matt Porritt <mattp@catalyst-au.net>
3535
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3636
*/
@@ -63,10 +63,10 @@ public function setUp(): void {
6363
public function test_videojs_enabled_true(): void {
6464
$this->resetAfterTest(true);
6565

66-
$filterplugin = new filter_smartmedia(null, []);
66+
$filterplugin = new text_filter(null, []);
6767

6868
// We're testing a private method, so we need to setup reflector magic.
69-
$method = new ReflectionMethod('filter_smartmedia', 'videojs_enabled');
69+
$method = new ReflectionMethod('text_filter', 'videojs_enabled');
7070
$method->setAccessible(true); // Allow accessing of private method.
7171
$proxy = $method->invoke($filterplugin); // Get result of invoked method.
7272

@@ -82,10 +82,10 @@ public function test_videojs_enabled_false(): void {
8282
// Only enable the HTML5 video player not video.js.
8383
media::set_enabled_plugins('html5video');
8484

85-
$filterplugin = new filter_smartmedia(null, []);
85+
$filterplugin = new text_filter(null, []);
8686

8787
// We're testing a private method, so we need to setup reflector magic.
88-
$method = new ReflectionMethod('filter_smartmedia', 'videojs_enabled');
88+
$method = new ReflectionMethod('text_filter', 'videojs_enabled');
8989
$method->setAccessible(true); // Allow accessing of private method.
9090
$proxy = $method->invoke($filterplugin); // Get result of invoked method.
9191

@@ -98,12 +98,12 @@ public function test_videojs_enabled_false(): void {
9898
*/
9999
public function test_get_smart_elements_no_smart(): void {
100100
$this->resetAfterTest(true);
101-
$filterplugin = new filter_smartmedia(null, []);
101+
$filterplugin = new text_filter(null, []);
102102

103103
$linkhref = 'http://moodle.local/pluginfile.php/1461/mod_label/intro/SampleVideo1mb.mp4';
104104

105105
// We're testing a private method, so we need to setup reflector magic.
106-
$method = new ReflectionMethod('filter_smartmedia', 'get_smart_elements');
106+
$method = new ReflectionMethod('text_filter', 'get_smart_elements');
107107
$method->setAccessible(true); // Allow accessing of private method.
108108
list($context, $proxy) = $method->invoke($filterplugin, $linkhref); // Get result of invoked method.
109109

@@ -113,7 +113,7 @@ public function test_get_smart_elements_no_smart(): void {
113113

114114
public function test_get_embed_markup_simple(): void {
115115
$this->resetAfterTest(true);
116-
$filterplugin = new filter_smartmedia(null, []);
116+
$filterplugin = new text_filter(null, []);
117117

118118
$linkhref = 'http://moodle.local/pluginfile.php/1461/mod_label/intro/OriginalVideo.mp4';
119119
$urls = [new url('http://moodle.local/pluginfile.php/1461/mod_label/intro/SampleVideo1mb.m3u8')];
@@ -128,7 +128,7 @@ public function test_get_embed_markup_simple(): void {
128128
];
129129

130130
// We're testing a private method, so we need to setup reflector magic.
131-
$method = new ReflectionMethod('filter_smartmedia', 'get_embed_markup');
131+
$method = new ReflectionMethod('text_filter', 'get_embed_markup');
132132
$method->setAccessible(true); // Allow accessing of private method.
133133
$proxy = $method->invoke($filterplugin, $linkhref, $urls, $options, $download, false); // Get result of invoked method.
134134

@@ -142,9 +142,9 @@ public function test_get_embed_markup_simple(): void {
142142
* There is no valid tags to replace.
143143
* Output next should be the same as input text.
144144
*/
145-
public function test_filter_smartmedia_filter_no_replace(): void {
145+
public function test_text_filter_filter_no_replace(): void {
146146
$this->resetAfterTest(true);
147-
$filterplugin = new filter_smartmedia(null, []);
147+
$filterplugin = new text_filter(null, []);
148148

149149
$inputtext = '<div class="no-overflow">'
150150
.'<a href="#">Some test data</a>'
@@ -162,7 +162,7 @@ public function test_get_placeholder_markkup(): void {
162162
$this->resetAfterTest(true);
163163

164164
global $DB;
165-
$filterplugin = new filter_smartmedia(null, []);
165+
$filterplugin = new text_filter(null, []);
166166

167167
$linkhref = 'http://moodle.local/pluginfile.php/1461/mod_label/intro/SampleVideo1mb.avi';
168168
$fulltext = '<div class="no-overflow">'
@@ -239,7 +239,7 @@ public function test_get_placeholder_markkup(): void {
239239
$initialfilerecord2['itemid'], $initialfilerecord2['filepath'], $initialfilerecord2['filename']);
240240

241241
// We're testing a private method, so we need to setup reflector magic.
242-
$method = new ReflectionMethod('filter_smartmedia', 'get_placeholder_markup');
242+
$method = new ReflectionMethod('text_filter', 'get_placeholder_markup');
243243
$method->setAccessible(true); // Allow accessing of private method.
244244

245245
$proxy = $method->invoke($filterplugin, $linkhref, $fulltext); // Get result of invoked method.
@@ -514,7 +514,7 @@ public function test_filter_replace($text, $regex, $matchcount, $mediaplugincoun
514514
]);
515515
$PAGE->set_url(new url($pageurl));
516516

517-
$filterplugin = new filter_smartmedia(null, [], $conversion);
517+
$filterplugin = new text_filter(null, [], $conversion);
518518
$result = $filterplugin->filter($text);
519519
$this->assertEquals($matchcount, preg_match_all($regex, $result));
520520

@@ -545,7 +545,7 @@ public function test_view_source(): void {
545545
]);
546546
$PAGE->set_url(new url("/my/"));
547547

548-
$filterplugin = new filter_smartmedia(null, [], $conversion);
548+
$filterplugin = new text_filter(null, [], $conversion);
549549
$text = '<div><div><video><source src="url.com/pluginfile.php/fake.mp4"/></video></div></div>';
550550
$result = $filterplugin->filter($text);
551551
$this->assertMatchesRegularExpression('/<button.*View source media.*<\/button>/', $result);
@@ -570,7 +570,7 @@ public function test_view_optimised(): void {
570570
$text = '<div><div><video><source src="url.com/pluginfile.php/fake.mp4"/></video></div></div>';
571571
$SESSION->local_smartmedia_viewsource = [sha1('url.com/pluginfile.php/fake.mp4') => true];
572572

573-
$filterplugin = new filter_smartmedia(null, [], $conversion);
573+
$filterplugin = new text_filter(null, [], $conversion);
574574
$result = $filterplugin->filter($text);
575575
$this->assertMatchesRegularExpression('/<button.*View optimised media.*<\/button>/', $result);
576576
}

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
defined('MOODLE_INTERNAL') || die();
2626

2727
$plugin->component = 'filter_smartmedia';
28-
$plugin->release = 2025061300;
29-
$plugin->version = 2025061300;
28+
$plugin->release = 2025061301;
29+
$plugin->version = 2025061301;
3030
$plugin->supported = [405, 405];
3131
$plugin->requires = 2024100700; // 4.5
3232
$plugin->maturity = MATURITY_STABLE;

0 commit comments

Comments
 (0)