From cbdfb9291bdccaf7f6f4ef1802863fc84e46d2f1 Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 15 Mar 2007 06:08:46 +0000 Subject: [PATCH] Merged filter_string fix from MDL-8713 (Also includes some reverting of a revert that Nicolas accidentally did ;-P ) --- lib/weblib.php | 70 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index 20b26aa512..df920de9ed 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1446,9 +1446,7 @@ function format_string ($string, $striplinks = false, $courseid=NULL ) { $strcache[$md5] = $string; if (!empty($CFG->filterall)) { - $CFG->formatstring = true; // new - $string = filter_text($string, $courseid); - unset($CFG->formatstring); + $string = filter_string($string, $courseid); } return $string; @@ -1517,8 +1515,8 @@ function filter_text($text, $courseid=NULL) { $courseid = $COURSE->id; // (copied from format_text) } - require_once($CFG->libdir.'/filterlib.php'); if (!empty($CFG->textfilters)) { + require_once($CFG->libdir.'/filterlib.php'); $textfilters = explode(',', $CFG->textfilters); foreach ($textfilters as $textfilter) { if (is_readable($CFG->dirroot .'/'. $textfilter .'/filter.php')) { @@ -1538,6 +1536,62 @@ function filter_text($text, $courseid=NULL) { return $text; } + +/** + * Given a string (short text) in HTML format, this function will pass it + * through any filters that have been defined in $CFG->stringfilters + * The variable defines a filepath to a file containing the + * filter function. The file must contain a variable called + * $textfilter_function which contains the name of the function + * with $courseid and $text parameters + * + * @param string $string The text to be passed through format filters + * @param int $courseid The id of a course + * @return string + */ +function filter_string($string, $courseid=NULL) { + global $CFG, $COURSE; + + if (empty($CFG->textfilters)) { // All filters are disabled anyway so quit + return $string; + } + + if (empty($courseid)) { + $courseid = $COURSE->id; + } + + require_once($CFG->libdir.'/filterlib.php'); + + if (isset($CFG->stringfilters)) { // We have a predefined list to use, great! + if (empty($CFG->stringfilters)) { // but it's blank, so finish now + return $string; + } + $stringfilters = explode(',', $CFG->stringfilters); // ..use the list we have + + } else { // Otherwise try to derive a list from textfilters + if (strpos($CFG->textfilters, 'filter/multilang')) { // Multilang is here + $stringfilters = array('filter/multilang'); // Let's use just that + $CFG->stringfilters = 'filter/multilang'; // Save it for next time through + } + } + + foreach ($stringfilters as $stringfilter) { + if (is_readable($CFG->dirroot .'/'. $stringfilter .'/filter.php')) { + include_once($CFG->dirroot .'/'. $stringfilter .'/filter.php'); + $functionname = basename($stringfilter).'_filter'; + if (function_exists($functionname)) { + $string = $functionname($courseid, $string); + } + } + } + + /// tags removed for XHTML compatibility + $string = str_replace('', '', $string); + $string = str_replace('', '', $string); + + return $string; +} + /** * Is the text marked as trusted? * @@ -4334,17 +4388,17 @@ function navmenu($course, $cm=NULL, $targetwindow='self') { } if ($backmod) { $backtext= get_string('activityprev', 'access'); - $backmod = '
  • frametarget.'>
    '. + $backmod = '
  • frametarget.'>
    '. ''. '
  • '; + ''.$backtext.''; } if ($nextmod) { $nexttext= get_string('activitynext', 'access'); - $nextmod = '
  • frametarget.'>
    '. + $nextmod = '
  • frametarget.'>
    '. ''. '
  • '; + ''.$nexttext.''; } return '