diff --git a/filter/activitynames/filter.php b/filter/activitynames/filter.php index e4bf1f1..a235092 100644 --- a/filter/activitynames/filter.php +++ b/filter/activitynames/filter.php @@ -35,7 +35,7 @@ class filter_activitynames extends moodle_text_filter { static $activitylist = null; static $cachedcourseid; - function filter($text) { + function filter($text, array $options = array()) { global $CFG, $COURSE, $DB; if (!$courseid = get_courseid_from_context($this->context)) { diff --git a/filter/algebra/filter.php b/filter/algebra/filter.php index c913b24..b196f2d 100644 --- a/filter/algebra/filter.php +++ b/filter/algebra/filter.php @@ -92,7 +92,7 @@ function filter_algebra_image($imagefile, $tex= "", $height="", $width="", $alig } class filter_algebra extends moodle_text_filter { - function filter($text){ + function filter($text, array $options = array()){ global $CFG, $DB; /// Do a quick check using stripos to avoid unnecessary wor diff --git a/filter/censor/filter.php b/filter/censor/filter.php index 92c9053..67d695e 100644 --- a/filter/censor/filter.php +++ b/filter/censor/filter.php @@ -52,7 +52,7 @@ class filter_censor extends moodle_text_filter { return $cap; } - function filter($text){ + function filter($text, array $options = array()){ static $words; global $CFG; diff --git a/filter/emailprotect/filter.php b/filter/emailprotect/filter.php index a8d266f..2d0dbc4 100644 --- a/filter/emailprotect/filter.php +++ b/filter/emailprotect/filter.php @@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die(); * hides them using the Moodle obfuscate_text function. */ class filter_emailprotect extends moodle_text_filter { - function filter($text) { + function filter($text, array $options = array()) { /// Do a quick check using stripos to avoid unnecessary work if (strpos($text, '@') === false) { return $text; diff --git a/filter/mediaplugin/filter.php b/filter/mediaplugin/filter.php index 266d8a9..838f4cb 100644 --- a/filter/mediaplugin/filter.php +++ b/filter/mediaplugin/filter.php @@ -33,7 +33,7 @@ require_once($CFG->libdir.'/filelib.php'); class filter_mediaplugin extends moodle_text_filter { private $eolas_fix_applied = false; - function filter($text) { + function filter($text, array $options = array()) { global $CFG, $PAGE; // You should never modify parameters passed to a method or function, it's BAD practice. Create a copy instead. // The reason is that you must always be able to refer to the original parameter that was passed. diff --git a/filter/multilang/filter.php b/filter/multilang/filter.php index d2a2372..efb618f 100644 --- a/filter/multilang/filter.php +++ b/filter/multilang/filter.php @@ -40,7 +40,7 @@ defined('MOODLE_INTERNAL') || die(); // one langanother language class filter_multilang extends moodle_text_filter { - function filter($text) { + function filter($text, array $options = array()) { global $CFG; // [pj] I don't know about you but I find this new implementation funny :P diff --git a/filter/tex/filter.php b/filter/tex/filter.php index 5287b4b..78a831e 100644 --- a/filter/tex/filter.php +++ b/filter/tex/filter.php @@ -105,7 +105,7 @@ function filter_text_image($imagefile, $tex= "", $height="", $width="", $align=" } class filter_tex extends moodle_text_filter { - function filter ($text) { + function filter ($text, array $options = array()) { global $CFG, $DB; diff --git a/filter/tidy/filter.php b/filter/tidy/filter.php index f38d3a1..567f9b6 100644 --- a/filter/tidy/filter.php +++ b/filter/tidy/filter.php @@ -38,7 +38,7 @@ defined('MOODLE_INTERNAL') || die(); // values are, see http://php.net/manual/en/function.tidy-get-config.php. class filter_tidy extends moodle_text_filter { - function filter($text) { + function filter($text, array $options = array()) { /// Configuration for tidy. Feel free to tune for your needs, e.g. to allow /// proprietary markup. diff --git a/lib/filterlib.php b/lib/filterlib.php index addb2dd..e99d558 100644 --- a/lib/filterlib.php +++ b/lib/filterlib.php @@ -148,11 +148,12 @@ class filter_manager { * @todo Document this function * @param string $text * @param array $filterchain + * @param array $options options passed to the filters * @return string $text */ - protected function apply_filter_chain($text, $filterchain) { + protected function apply_filter_chain($text, $filterchain, array $options = array()) { foreach ($filterchain as $filter) { - $text = $filter->filter($text); + $text = $filter->filter($text, $options); } return $text; } @@ -186,10 +187,11 @@ class filter_manager { * * @param string $text The text to filter * @param object $context + * @param array $options options passed to the filters * @return string resulting text */ - public function filter_text($text, $context) { - $text = $this->apply_filter_chain($text, $this->get_text_filters($context)); + public function filter_text($text, $context, array $options = array()) { + $text = $this->apply_filter_chain($text, $this->get_text_filters($context), $options); /// tags removed for XHTML compatibility $text = str_replace(array('', ''), '', $text); return $text; @@ -236,7 +238,7 @@ class null_filter_manager { /** * @return string */ - public function filter_text($text, $context) { + public function filter_text($text, $context, $options) { return $text; } @@ -285,11 +287,12 @@ class performance_measuring_filter_manager extends filter_manager { /** * @param string $text * @param object $context + * @param array $options options passed to the filters * @return mixed */ - public function filter_text($text, $context) { + public function filter_text($text, $context, array $options = array()) { $this->textsfiltered++; - return parent::filter_text($text, $context); + return parent::filter_text($text, $context, $options); } /** @@ -332,7 +335,7 @@ class performance_measuring_filter_manager extends filter_manager { abstract class moodle_text_filter { /** @var object The context we are in. */ protected $context; - /** @var object Any local configuration for this filter in this context. */ + /** @var array Any local configuration for this filter in this context. */ protected $localconfig; /** @@ -357,9 +360,10 @@ abstract class moodle_text_filter { * Override this function to actually implement the filtering. * * @param $text some HTML content. + * @param array $options options passed to the filters * @return the HTML content after the filtering has been applied. */ - public abstract function filter($text); + public abstract function filter($text, array $options = array()); } /** @@ -391,9 +395,10 @@ class legacy_filter extends moodle_text_filter { /** * @param string $text + * @param array $options options - not supported for legacy filters * @return mixed */ - public function filter($text) { + public function filter($text, array $options = array()) { if ($this->courseid) { // old filters are called only when inside courses return call_user_func($this->filterfunction, $this->courseid, $text); diff --git a/lib/weblib.php b/lib/weblib.php index 762d4a9..a30f8b8 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1036,7 +1036,7 @@ function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_ if (!$options['noclean']) { $text = clean_text($text, FORMAT_HTML); } - $text = $filtermanager->filter_text($text, $context); + $text = $filtermanager->filter_text($text, $context, array('originalformat' => FORMAT_HTML)); break; case FORMAT_PLAIN: @@ -1062,7 +1062,7 @@ function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_ if (!$options['noclean']) { $text = clean_text($text, FORMAT_HTML); } - $text = $filtermanager->filter_text($text, $context); + $text = $filtermanager->filter_text($text, $context, array('originalformat' => FORMAT_MARKDOWN)); break; default: // FORMAT_MOODLE or anything else @@ -1070,7 +1070,7 @@ function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_ if (!$options['noclean']) { $text = clean_text($text, FORMAT_HTML); } - $text = $filtermanager->filter_text($text, $context); + $text = $filtermanager->filter_text($text, $context, array('originalformat' => $format)); break; }