NEW EXPERIMENTAL FEATURE: text filters.
This new feature allows arbitrary text filters to be added to any HTML that is printed (forum posts, resources etc) ... anything that uses the standard format_text function. The first one properly supported is the glossary dynamic linking feature.
This commit is contained in:
@@ -124,6 +124,17 @@ $CFG->directorypermissions = 0777;
|
||||
|
||||
$CFG->admin = 'admin';
|
||||
|
||||
//=========================================================================
|
||||
// 7. TEXT FILTERS (most people can just ignore this setting)
|
||||
//=========================================================================
|
||||
// This is a new and experimental feature that allows text filters to
|
||||
// be used on all printed texts in Moodle. To add text filters, you
|
||||
// need to specify the path to a file that contains a standard textfilter.
|
||||
// The numbers need to start at one and increment up to ten.
|
||||
//
|
||||
// eg $CFG->textfilter1 = "mod/glossary/dynalink.php";
|
||||
// $CFG->textfilter2 = "library/librarylib.php";
|
||||
|
||||
|
||||
//=========================================================================
|
||||
// ALL DONE! To continue installation, visit your main page with a browser
|
||||
|
||||
+36
-12
@@ -460,12 +460,12 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL) {
|
||||
/// $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:
|
||||
@@ -477,7 +477,8 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL) {
|
||||
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
|
||||
@@ -487,7 +488,9 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -520,6 +523,35 @@ function format_text_email($text, $format) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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.
|
||||
@@ -607,14 +639,6 @@ function text_to_html($text, $smiley=true, $para=true) {
|
||||
/// 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);
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
<?PHP
|
||||
|
||||
$textfilter_function = 'glossary_dynamic_link';
|
||||
|
||||
if (function_exists($textfilter_function)) {
|
||||
return;
|
||||
}
|
||||
|
||||
function glossary_dynamic_link($courseid, $text,$glossaryid = NULL) {
|
||||
global $CFG;
|
||||
static $entries; // to avoid repeated calls to database
|
||||
|
||||
Reference in New Issue
Block a user