[Phpfreechat-svn] SF.net SVN: phpfreechat: [635] trunk/src
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-06-30 16:28:13
|
Revision: 635 Author: kerphi Date: 2006-06-30 09:28:03 -0700 (Fri, 30 Jun 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=635&view=rev Log Message: ----------- New proxy: a censor proxy used to filter bad words in posted messages Modified Paths: -------------- trunk/src/pfcglobalconfig.class.php Added Paths: ----------- trunk/src/proxys/censor.class.php Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2006-06-28 19:59:12 UTC (rev 634) +++ trunk/src/pfcglobalconfig.class.php 2006-06-30 16:28:03 UTC (rev 635) @@ -38,9 +38,10 @@ var $admins = array("admin" => ""); // nicknames is the key, password is the value // these parameters are static (cached) - var $proxys = array("auth", "noflood"); + var $proxys = array("auth", "noflood", "censor"); var $proxys_cfg = array("auth" => array(), - "noflood" => array("limit"=>10,"delay"=>5)); + "noflood" => array("limit"=>10,"delay"=>5), + "censor" => array("words"=>array("fuck","sex","bitch"),"replaceby"=>"*")); var $title = ""; // default is _pfc("My Chat") var $channels = array(); // the default joined channels when opening the chat var $frozen_channels = array(); // by default allow users to create there own channels Added: trunk/src/proxys/censor.class.php =================================================================== --- trunk/src/proxys/censor.class.php (rev 0) +++ trunk/src/proxys/censor.class.php 2006-06-30 16:28:03 UTC (rev 635) @@ -0,0 +1,59 @@ +<?php +/** + * censor.class.php + * + * Copyright © 2006 Stephane Gully <ste...@gm...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ +require_once dirname(__FILE__)."/../pfci18n.class.php"; +require_once dirname(__FILE__)."/../pfcuserconfig.class.php"; +require_once dirname(__FILE__)."/../pfcproxycommand.class.php"; + +/** + * pfcProxyCommand_censor + * this proxy will filter bad words from messages + * @author Stephane Gully <ste...@gm...> + */ +class pfcProxyCommand_censor extends pfcProxyCommand +{ + function run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid) + { + $c =& $this->c; + $u =& $this->u; + + $cmdtocheck = array("send", "nick", "me"); + if ( in_array($this->name, $cmdtocheck) ) + { + $words = $c->proxys_cfg[$this->proxyname]["words"]; + $replaceby = $c->proxys_cfg[$this->proxyname]["replaceby"]; + + $patterns = array(); + $replacements = array(); + foreach($words as $w) + { + $patterns[] = "/".preg_quote($w)."/i"; + $replacements[] = str_repeat($replaceby,strlen($w)); + } + $param = preg_replace($patterns, $replacements, $param); + } + + // forward the command to the next proxy or to the final command + $this->next->run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid); + } +} + +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |