\r
$CFG->admin = 'admin';\r
\r
+//=========================================================================\r
+// 7. TEXT FILTERS (most people can just ignore this setting)\r
+//=========================================================================\r
+// This is a new and experimental feature that allows text filters to \r
+// be used on all printed texts in Moodle. To add text filters, you\r
+// need to specify the path to a file that contains a standard textfilter.\r
+// The numbers need to start at one and increment up to ten.\r
+// \r
+// eg $CFG->textfilter1 = "mod/glossary/dynalink.php";\r
+// $CFG->textfilter2 = "library/librarylib.php";\r
+\r
\r
//=========================================================================\r
// ALL DONE! To continue installation, visit your main page with a browser\r
/// $text is raw text (originally from a user)
/// $format is one of the format constants, defined above
- global $CFG;
+ global $CFG, $course;
switch ($format) {
case FORMAT_HTML:
replace_smilies($text);
- return $text;
+ return filter_text($text);
break;
case FORMAT_PLAIN:
break;
case FORMAT_WIKI:
- return wiki_to_html($text);
+ $text = wiki_to_html($text);
+ return filter_text($text);
break;
default: // FORMAT_MOODLE or anything else
if (!isset($options->para)) {
$options->para=true;
}
- return text_to_html($text, $options->smiley, $options->para);
+ $text = text_to_html($text, $options->smiley, $options->para);
+ return filter_text($text);
+
break;
}
}
}
}
+
+function filter_text($text) {
+/// Given some text in HTML format, this function will pass it
+/// through any filters that have been defined in $CFG->textfilterx
+/// 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 $course->id and $text parameters
+
+ global $CFG, $course; // A dirty hack right now ... should not be assumed global
+
+ if (empty($course->id)) {
+ return $text;
+ }
+
+ for ($i=1; $i<=10; $i++) {
+ $variable = "textfilter$i";
+ if (empty($CFG->$variable)) { /// No more filters
+ return $text;
+ }
+ if (is_readable("$CFG->dirroot/".$CFG->$variable)) {
+ include("$CFG->dirroot/".$CFG->$variable);
+ $text = $textfilter_function($course->id, $text);
+ }
+ }
+ return $text;
+}
+
+
function clean_text($text, $format) {
/// Given raw text (eg typed in by a user), this function cleans it up
/// and removes any nasty tags that could mess up Moodle pages.
/// Make returns into HTML newlines.
$text = nl2br($text);
-/// Insert links to library pages if Library is being used
- if (!empty($CFG->librarypath)) {
- if (file_exists("$CFG->dirroot/$CFG->librarypath/librarylib.php")) {
- include_once("$CFG->dirroot/$CFG->librarypath/librarylib.php");
- $text = librarytexttohtml($text);
- }
- }
-
/// Turn smileys into images.
if ($smiley) {
replace_smilies($text);