|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00030 defined('MOODLE_INTERNAL') || die(); 00031 00033 // Censorship filtering 00034 // 00035 // This very simple example of a Text Filter will parse 00036 // printed text, blacking out words perceived to be bad 00037 // 00038 // The list of words is in the lang/xx/moodle.php 00039 // 00041 00042 class filter_censor extends moodle_text_filter { 00043 private function _canseecensor() { 00044 return is_siteadmin(); //TODO: add proper access control 00045 } 00046 00047 function hash(){ 00048 $cap = "mod/filter:censor"; 00049 if (is_siteadmin()) { //TODO: add proper access control 00050 $cap = "mod/filter:seecensor"; 00051 } 00052 return $cap; 00053 } 00054 00055 function filter($text, array $options = array()){ 00056 static $words; 00057 global $CFG; 00058 00059 if (!isset($CFG->filter_censor_badwords)) { 00060 set_config( 'filter_censor_badwords','' ); 00061 } 00062 00063 if (empty($words)) { 00064 $words = array(); 00065 if (empty($CFG->filter_censor_badwords)) { 00066 $badwords = explode(',',get_string('badwords', 'filter_censor')); 00067 } 00068 else { 00069 $badwords = explode(',', $CFG->filter_censor_badwords); 00070 } 00071 foreach ($badwords as $badword) { 00072 $badword = trim($badword); 00073 if($this->_canseecensor()){ 00074 $words[] = new filterobject($badword, '<span class="censoredtexthighlight" title="'.$badword.'">', '</span>', 00075 false, false, $badword); 00076 } else { 00077 $words[] = new filterobject($badword, '<span class="censoredtext" title="'.$badword.'">', 00078 '</span>', false, false, str_pad('',strlen($badword),'*')); 00079 } 00080 } 00081 } 00082 return filter_phrases($text, $words); 00083 } 00084 } 00085 00086