1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * Censorship filtering 20 * 21 * This very simple example of a Text Filter will parse 22 * printed text, blacking out words perceived to be bad 23 * 24 * @package filter 25 * @subpackage censor 26 * @copyright 2004 onwards Martin Dougiamas {@link http://moodle.com} 27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 28 */ 29 30 defined('MOODLE_INTERNAL') || die(); 31 32 ////////////////////////////////////////////////////////////// 33 // Censorship filtering 34 // 35 // This very simple example of a Text Filter will parse 36 // printed text, blacking out words perceived to be bad 37 // 38 // The list of words is in the lang/xx/moodle.php 39 // 40 ////////////////////////////////////////////////////////////// 41 42 class filter_censor extends moodle_text_filter { 43 private function _canseecensor() { 44 return is_siteadmin(); //TODO: add proper access control 45 } 46 47 function hash(){ 48 $cap = "mod/filter:censor"; 49 if (is_siteadmin()) { //TODO: add proper access control 50 $cap = "mod/filter:seecensor"; 51 } 52 return $cap; 53 } 54 55 function filter($text, array $options = array()){ 56 static $words; 57 global $CFG; 58 59 if (!isset($CFG->filter_censor_badwords)) { 60 set_config( 'filter_censor_badwords','' ); 61 } 62 63 if (empty($words)) { 64 $words = array(); 65 if (empty($CFG->filter_censor_badwords)) { 66 $badwords = explode(',',get_string('badwords', 'filter_censor')); 67 } 68 else { 69 $badwords = explode(',', $CFG->filter_censor_badwords); 70 } 71 foreach ($badwords as $badword) { 72 $badword = trim($badword); 73 if($this->_canseecensor()){ 74 $words[] = new filterobject($badword, '<span class="censoredtexthighlight" title="'.$badword.'">', '</span>', 75 false, false, $badword); 76 } else { 77 $words[] = new filterobject($badword, '<span class="censoredtext" title="'.$badword.'">', 78 '</span>', false, false, str_pad('',strlen($badword),'*')); 79 } 80 } 81 } 82 return filter_phrases($text, $words); 83 } 84 } 85 86
title
Description
Body
title
Description
Body
title
Description
Body
title
Body