2 //////////////////////////////////////////////////////////////
3 // Censorship filtering
5 // This very simple example of a Text Filter will parse
6 // printed text, blacking out words perceived to be bad
8 // The list of words is in the lang/xx/moodle.php
10 //////////////////////////////////////////////////////////////
12 /// This is the filtering function itself. It accepts the
13 /// courseid and the text to be filtered (in HTML form).
15 function censor_filter($courseid, $text) {
20 if (!isset($CFG->filter_censor_badwords
)) {
21 set_config( 'filter_censor_badwords','' );
26 // if no user-specified words, use default list from language pack
27 if (empty($CFG->filter_censor_badwords
)) {
28 $badwords = explode(',',get_string('badwords','censor') );
31 $badwords = explode(',', $CFG->filter_censor_badwords
);
33 foreach ($badwords as $badword) {
34 $badword = trim($badword);
35 $words[] = new filterobject($badword, '<span class="censoredtext" title="'.$badword.'">', '</span>',
36 false, false, str_pad('',strlen($badword),'*'));
40 return filter_phrases($text, $words); // Look for all these words in the text