global $CFG, $course;
+ if (!empty($CFG->cachetext)) {
+ $time = time() - $CFG->cachetext;
+ $md5key = md5($text);
+ if ($cacheitem = get_record_select('text_cache', "md5key = '$md5key' AND timemodified > '$time'")) {
+ return $cacheitem->formattedtext;
+ }
+ }
+
if (empty($courseid)) {
if (!empty($course->id)) { // An ugly hack for better compatibility
$courseid = $course->id;
switch ($format) {
case FORMAT_HTML:
replace_smilies($text);
- return filter_text($text, $courseid);
+ $text = filter_text($text, $courseid);
break;
case FORMAT_PLAIN:
$text = str_replace(" ", " ", $text);
replace_smilies($text);
$text = nl2br($text);
- return $text;
break;
case FORMAT_WIKI:
$text = wiki_to_html($text);
- return filter_text($text, $courseid);
+ $text = filter_text($text, $courseid);
break;
default: // FORMAT_MOODLE or anything else
$options->para=true;
}
$text = text_to_html($text, $options->smiley, $options->para);
- return filter_text($text, $courseid);
-
+ $text = filter_text($text, $courseid);
break;
}
+
+ if (!empty($CFG->cachetext)) {
+ $newrecord->md5key = $md5key;
+ $newrecord->formattedtext = addslashes($text);
+ $newrecord->timemodified = time();
+ insert_record('text_cache', $newrecord);
+ }
+
+ return $text;
}
function format_text_email($text, $format) {