diff --git a/lib/filterlib.php b/lib/filterlib.php index bd6f6d96cd8..ec4bd17a951 100644 --- a/lib/filterlib.php +++ b/lib/filterlib.php @@ -469,18 +469,21 @@ abstract class moodle_text_filter { class filterobject { /** @var string */ public $phrase; + /** @var bool whether to only recognise full word matches. */ + public $fullmatch; + public $hreftagbegin; public $hreftagend; /** @var bool */ public $casesensitive; - public $fullmatch; + + /** @var null|string once initialised, holds the regexp for matching this phrase. */ + public $workregexp = null; + /** @var mixed */ public $replacementphrase; - public $work_phrase; public $work_hreftagbegin; public $work_hreftagend; - public $work_casesensitive; - public $work_fullmatch; public $work_replacementphrase; /** @var bool */ public $work_calculated; @@ -504,8 +507,8 @@ class filterobject { $this->phrase = $phrase; $this->hreftagbegin = $hreftagbegin; $this->hreftagend = $hreftagend; - $this->casesensitive = $casesensitive; - $this->fullmatch = $fullmatch; + $this->casesensitive = !empty($casesensitive); + $this->fullmatch = !empty($fullmatch); $this->replacementphrase = $replacementphrase; $this->work_calculated = false; @@ -1240,7 +1243,7 @@ function filter_context_may_have_filter_settings($context) { * Process phrases intelligently found within a HTML text (such as adding links). * * @param string $text the text that we are filtering - * @param array $linkarray an array of filterobjects + * @param filterobject[] $linkarray an array of filterobjects * @param array $ignoretagsopen an array of opening tags that we should ignore while filtering * @param array $ignoretagsclose an array of corresponding closing tags * @param bool $overridedefaultignore True to only use tags provided by arguments @@ -1251,11 +1254,15 @@ function filter_phrases($text, $linkarray, $ignoretagsopen = null, $ignoretagscl global $CFG; - static $usedphrases; + // Used if $CFG->filtermatchoneperpage is on. Array with keys being the workregexp + // for things that have already been matched on this page. + static $usedphrases = []; $ignoretags = array(); // To store all the enclosig tags to be completely ignored. $tags = array(); // To store all the simple tags to be ignored. + $linkarray = filter_prepare_phrases_for_filtering($linkarray); + if (!$overridedefaultignore) { // A list of open/close tags that we should not replace within. // Extended to include