function trusttext_prepare_edit(&$text, &$format, $usehtmleditor, $context) { global $CFG; $options = new object(); $options->smiley = false; $options->filter = false; if (!empty($CFG->enabletrusttext) and has_capability('moodle/site:trustcontent', $context) and trusttext_present($text)) { $options->noclean = true; } else { $options->noclean = false; } $text = trusttext_strip($text); if ($usehtmleditor) { $text = format_text($text, $format, $options); $format = FORMAT_HTML; } else { if (!$options->noclean) { $text = clean_text($text, $format); } } }
//Use highlight() with nonsense tags to spot search terms in the //actual text content first. fiedorow - 9/2/2005 $missing_terms = ""; // Hack for posts of format FORMAT_PLAIN. Otherwise html tags added by // the highlight() call bellow get stripped out by forum_print_post(). if ($post->format == FORMAT_PLAIN) { $post->message = stripslashes_safe($post->message); $post->message = rebuildnolinktag($post->message); $post->message = str_replace(' ', ' ', $post->message); $post->message = nl2br($post->message); $post->format = FORMAT_HTML; } $options = new object(); $options->trusttext = true; // detect TRUSTTEXT marker before first call to format_text if (trusttext_present($post->message)) { $ttpresent = true; } else { $ttpresent = false; } $message = highlight($strippedsearch, format_text($post->message, $post->format, $options, $course->id), 0, '<fgw9sdpq4>', '</fgw9sdpq4>'); foreach ($searchterms as $searchterm) { if (preg_match("/{$searchterm}/i", $message) && !preg_match('/<fgw9sdpq4>' . $searchterm . '<\\/fgw9sdpq4>/i', $message)) { $missing_terms .= " {$searchterm}"; } } // now is the right time to strip the TRUSTTEXT marker, we will add it later if needed $post->message = trusttext_strip($post->message); $message = str_replace('<fgw9sdpq4>', '<span class="highlight">', $message); $message = str_replace('</fgw9sdpq4>', '</span>', $message); if ($missing_terms) {
function glossary_print_entry_definition($entry) { $definition = $entry->definition; // always detect and strip TRUSTTEXT marker before processing and add+strip it afterwards! if (trusttext_present($definition)) { $ttpresent = true; $definition = trusttext_strip($definition); } else { $ttpresent = false; } global $GLOSSARY_EXCLUDECONCEPTS; //Calculate all the strings to be no-linked //First, the concept $GLOSSARY_EXCLUDECONCEPTS = array($entry->concept); //Now the aliases if ($aliases = get_records('glossary_alias', 'entryid', $entry->id)) { foreach ($aliases as $alias) { $GLOSSARY_EXCLUDECONCEPTS[] = trim($alias->alias); } } $options = new object(); $options->para = false; $options->trusttext = true; // reconstruct the TRUSTTEXT properly after processing if ($ttpresent) { $definition = trusttext_mark($definition); } else { $definition = trusttext_strip($definition); //make 100% sure TRUSTTEXT marker was not created } $text = format_text($definition, $entry->format, $options); // Stop excluding concepts from autolinking unset($GLOSSARY_EXCLUDECONCEPTS); if (!empty($entry->highlight)) { $text = highlight($entry->highlight, $text); } if (isset($entry->footer)) { // Unparsed footer info $text .= $entry->footer; } echo $text; }
function glossary_print_entry_definition($entry) { $definition = $entry->definition; // always detect and strip TRUSTTEXT marker before processing and add+strip it afterwards! if (trusttext_present($definition)) { $ttpresent = true; $definition = trusttext_strip($definition); } else { $ttpresent = false; } $links = array(); $tags = array(); $urls = array(); $addrs = array(); //Calculate all the strings to be no-linked //First, the concept $term = preg_quote(trim($entry->concept), '/'); $pat = '/(' . $term . ')/is'; $doNolinks[] = $pat; //Now the aliases if ($aliases = get_records('glossary_alias', 'entryid', $entry->id)) { foreach ($aliases as $alias) { $term = preg_quote(trim($alias->alias), '/'); $pat = '/(' . $term . ')/is'; $doNolinks[] = $pat; } } //Extract <a>..><a> tags from definition preg_match_all('/<a[^>]+?>(.*?)<\\/a>/is', $definition, $list_of_a); //Save them into links array to use them later foreach (array_unique($list_of_a[0]) as $key => $value) { $links['<#' . $key . '#>'] = $value; } //Take off every link from definition if ($links) { $definition = str_replace($links, array_keys($links), $definition); } //Extract all tags from definition preg_match_all('/(<.*?>)/is', $definition, $list_of_tags); //Save them into tags array to use them later foreach (array_unique($list_of_tags[0]) as $key => $value) { $tags['<@' . $key . '@>'] = $value; } //Take off every tag from definition if ($tags) { $definition = str_replace($tags, array_keys($tags), $definition); } //Extract all URLS with protocol (http://domain.com) from definition preg_match_all('/([[:space:]]|^|\\(|\\[)([[:alnum:]]+):\\/\\/([^[:space:]]*)([[:alnum:]#?\\/&=])/is', $definition, $list_of_urls); //Save them into urls array to use them later foreach (array_unique($list_of_urls[0]) as $key => $value) { $urls['<*' . $key . '*>'] = $value; } //Take off every url from definition if ($urls) { $definition = str_replace($urls, array_keys($urls), $definition); } //Extract all WEB ADDRESSES (www.domain.com) from definition preg_match_all('/([[:space:]]|^|\\(|\\[)www\\.([^[:space:]]*)([[:alnum:]#?\\/&=])/is', $definition, $list_of_addresses); //Save them into addrs array to use them later foreach (array_unique($list_of_addresses[0]) as $key => $value) { $addrs['<+' . $key . '+>'] = $value; } //Take off every addr from definition if ($addrs) { $definition = str_replace($addrs, array_keys($addrs), $definition); } //Put doNolinks (concept + aliases) enclosed by <nolink> tag $definition = preg_replace($doNolinks, '<span class="nolink">$1</span>', $definition); //Restore addrs if ($addrs) { $definition = str_replace(array_keys($addrs), $addrs, $definition); } //Restore urls if ($urls) { $definition = str_replace(array_keys($urls), $urls, $definition); } //Restore tags if ($tags) { $definition = str_replace(array_keys($tags), $tags, $definition); } //Restore links if ($links) { $definition = str_replace(array_keys($links), $links, $definition); } $options = new object(); $options->para = false; $options->trusttext = true; // reconstruct the TRUSTTEXT properly after processing if ($ttpresent) { $definition = trusttext_mark($definition); } else { $definition = trusttext_strip($definition); //make 100% sure TRUSTTEXT marker was not created } $text = format_text($definition, $entry->format, $options); if (!empty($entry->highlight)) { $text = highlight($entry->highlight, $text); } if (isset($entry->footer)) { // Unparsed footer info $text .= $entry->footer; } echo $text; }