[Phpfreechat-svn] SF.net SVN: phpfreechat: [865] trunk/src
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-11-05 11:09:27
|
Revision: 865 http://svn.sourceforge.net/phpfreechat/?rev=865&view=rev Author: kerphi Date: 2006-11-05 03:09:12 -0800 (Sun, 05 Nov 2006) Log Message: ----------- [en] Makes possible to use regular expressions for the words in the censor proxy. [45min] [fr] Rend possible l'utilisation d'expressions r?\195?\169guli?\195?\168res pour les mots ?\195?\160 censurer. [45min] Modified Paths: -------------- trunk/src/pfcglobalconfig.class.php trunk/src/proxies/censor.class.php Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2006-11-02 20:12:51 UTC (rev 864) +++ trunk/src/pfcglobalconfig.class.php 2006-11-05 11:09:12 UTC (rev 865) @@ -49,9 +49,13 @@ var $post_proxies = array(); // these proxies will be handled just before to process commands and just after system proxies var $pre_proxies = array(); // these proxies will be handled before system proxies (at begining) var $proxies_cfg = array("auth" => array(), - "noflood" => array("charlimit"=>450,"msglimit"=>10,"delay"=>5), - "censor" => array("words"=>array("fuck","sex","bitch"),"replaceby"=>"*"), - "log" => array("path"=>"")); + "noflood" => array("charlimit" => 450, + "msglimit" => 10, + "delay" => 5), + "censor" => array("words" => array("fuck","sex","bitch"), + "replaceby" => "*", + "regex" => false), + "log" => array("path" => "")); var $proxies_path = ""; // a custom proxies path var $proxies_path_default = ""; // dirname(__FILE__).'/proxies' var $cmd_path = ""; // a custom commands path Modified: trunk/src/proxies/censor.class.php =================================================================== --- trunk/src/proxies/censor.class.php 2006-11-02 20:12:51 UTC (rev 864) +++ trunk/src/proxies/censor.class.php 2006-11-05 11:09:12 UTC (rev 865) @@ -46,13 +46,24 @@ { $words = $c->proxies_cfg[$this->proxyname]["words"]; $replaceby = $c->proxies_cfg[$this->proxyname]["replaceby"]; - + $regex = $c->proxies_cfg[$this->proxyname]["regex"]; + $patterns = array(); $replacements = array(); foreach($words as $w) { - $patterns[] = "/".preg_quote($w)."/i"; - $replacements[] = str_repeat($replaceby,strlen($w)); + if ($regex) + { + // the words are regular expressions + $patterns[] = "/".$w."/ie"; + $replacements[] = "'\\1'.str_repeat('$replaceby',strlen('\\2')).'\\3'"; + } + else + { + // the words are simple words + $patterns[] = "/".preg_quote($w)."/i"; + $replacements[] = str_repeat($replaceby,strlen($w)); + } } $param = preg_replace($patterns, $replacements, $param); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |