Skip to content

Commit 907d14c

Browse files
committed
Moving classes for compatibility with Moodle 4.5
1 parent df62170 commit 907d14c

File tree

2 files changed

+89
-45
lines changed

2 files changed

+89
-45
lines changed

classes/text_filter.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Filter file.
19+
*
20+
* @package filter_shortcodes
21+
* @copyright 2024 Frédéric Massart
22+
* @author Frédéric Massart <fred@branchup.tech>
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
namespace filter_shortcodes;
27+
28+
defined('MOODLE_INTERNAL') || die();
29+
30+
use filter_shortcodes\local\processor\standard_processor;
31+
use filter_shortcodes\local\registry\plugin_registry;
32+
33+
require_once($CFG->dirroot . '/filter/shortcodes/lib/helpers.php');
34+
35+
if (class_exists(\core_filters\text_filter::class)) {
36+
/**
37+
* Parent class.
38+
*/
39+
abstract class core_text_filter extends \core_filters\text_filter {}
40+
} else {
41+
require_once($CFG->libdir . '/filterlib.php');
42+
43+
/**
44+
* Parent class.
45+
*/
46+
abstract class core_text_filter extends \moodle_text_filter {}
47+
}
48+
49+
/**
50+
* Filter class.
51+
*
52+
* @package filter_shortcodes
53+
* @copyright 2024 Frédéric Massart
54+
* @author Frédéric Massart <fred@branchup.tech>
55+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
56+
*/
57+
class text_filter extends core_text_filter {
58+
59+
/** @var processor The processor. */
60+
private $processor;
61+
62+
/**
63+
* The filtering occurs here.
64+
*
65+
* @param string $text HTML content.
66+
* @param array $options Options passed to the filter.
67+
* @return string The new content.
68+
*/
69+
public function filter($text, array $options = []) {
70+
$env = filter_shortcodes_make_env($this->context, $options);
71+
$processor = $this->get_processor();
72+
$processor->set_env($env);
73+
return $processor->process($text);
74+
}
75+
76+
/**
77+
* Get the processor.
78+
*
79+
* @return standard_processor
80+
*/
81+
private function get_processor() {
82+
if ($this->processor === null) {
83+
$this->processor = new standard_processor(new plugin_registry());
84+
}
85+
return $this->processor;
86+
}
87+
88+
}

filter.php

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,4 @@
2525

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

28-
use filter_shortcodes\local\processor\standard_processor;
29-
use filter_shortcodes\local\registry\plugin_registry;
30-
31-
require_once($CFG->dirroot . '/filter/shortcodes/lib/helpers.php');
32-
33-
/**
34-
* Filter class.
35-
*
36-
* @package filter_shortcodes
37-
* @copyright 2018 Frédéric Massart
38-
* @author Frédéric Massart <fred@branchup.tech>
39-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40-
*/
41-
class filter_shortcodes extends moodle_text_filter {
42-
43-
/** @var processor The processor. */
44-
private $processor;
45-
46-
/**
47-
* The filtering occurs here.
48-
*
49-
* @param string $text HTML content.
50-
* @param array $options Options passed to the filter.
51-
* @return string The new content.
52-
*/
53-
public function filter($text, array $options = []) {
54-
$env = filter_shortcodes_make_env($this->context, $options);
55-
$processor = $this->get_processor();
56-
$processor->set_env($env);
57-
return $processor->process($text);
58-
}
59-
60-
/**
61-
* Get the processor.
62-
*
63-
* @return standard_processor
64-
*/
65-
private function get_processor() {
66-
if ($this->processor === null) {
67-
$this->processor = new standard_processor(new plugin_registry());
68-
}
69-
return $this->processor;
70-
}
71-
72-
}
28+
class_alias(\filter_shortcodes\text_filter::class, 'filter_shortcodes');

0 commit comments

Comments
 (0)