Skip to content

Commit

Permalink
MDL-47962 filter_glossary: only prepare_phrases_for_filtering once
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Sep 20, 2018
1 parent 2abf8fb commit c01503d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion filter/glossary/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ protected function get_all_concepts() {
// when you have two terms like 'Moodle' and 'Moodle 3.5'. You want the longest match.
usort($conceptlist, 'filter_glossary::sort_entries_by_length');

$conceptlist = filter_prepare_phrases_for_filtering($conceptlist);

$tocache = new stdClass();
$tocache->cacheuserid = $USER->id;
$tocache->cachecourseid = $courseid;
Expand All @@ -155,7 +157,7 @@ public function filter($text, array $options = array()) {

if (!empty($GLOSSARY_EXCLUDEENTRY)) {
foreach ($conceptlist as $key => $filterobj) {
if ($filterobj->conceptid == $GLOSSARY_EXCLUDEENTRY) {
if (is_object($filterobj) && $filterobj->conceptid == $GLOSSARY_EXCLUDEENTRY) {
unset($conceptlist[$key]);
}
}
Expand Down
16 changes: 10 additions & 6 deletions lib/filterlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,9 @@ function filter_phrases($text, $linkarray, $ignoretagsopen = null, $ignoretagscl
$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 (!isset($linkarray['__preparedmarker'])) {
$linkarray = filter_prepare_phrases_for_filtering($linkarray);
}

if (!$overridedefaultignore) {
// A list of open/close tags that we should not replace within.
Expand Down Expand Up @@ -1305,7 +1307,11 @@ function filter_phrases($text, $linkarray, $ignoretagsopen = null, $ignoretagscl
}

// Time to cycle through each phrase to be linked.
foreach ($linkarray as $linkobject) {
foreach ($linkarray as $key => $linkobject) {
if ($key === '__preparedmarker') {
continue;
}

if ($linkobject->workregexp === null) {
continue;
}
Expand Down Expand Up @@ -1427,11 +1433,9 @@ function filter_prepare_phrases_for_filtering(array $linkarray) {
}
}

return $linkarray;
}

function filter_prepare_phrases_for_replacement() {
$linkarray['__preparedmarker'] = 1;

return $linkarray;
}

/**
Expand Down

0 comments on commit c01503d

Please sign in to comment.