[Phpfreechat-svn] SF.net SVN: phpfreechat: [764] trunk
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-09-16 20:32:55
|
Revision: 764 http://svn.sourceforge.net/phpfreechat/?rev=764&view=rev Author: kerphi Date: 2006-09-16 13:32:44 -0700 (Sat, 16 Sep 2006) Log Message: ----------- [en] Proxies refactoring : I removed the 'proxy' parameter. I added 'skip_proxys' used to disable a system proxy (ex: censor). I added 'post_proxys' used to append your own proxy to the proxy chaine. I added 'pre_proxys' used to prepend your own proxy to the proxy chaine. I added 'proxys_path' used to define the location of your customized proxies. I also created demo48 to illustrate this powerfull proxy feature. [fr] Refonte des command proxies : J'ai retire les parametre 'proxy'. J'ai ajoute le parametre 'skip_proxys' utilise pour desactive un proxy systeme (ex: censor). J'ai ajoute le parametre 'post_proxys' utilise pour ajouter a la fin de la chaine son propre proxy. J'ai ajoute le parametre 'pre_proxys' utilise pour ajouter en debut de chaine son propre proxy. J'ai ajoute le parametre 'proxys_path' utilise pour indiquer le repertoire ou se trouve vos proxy. J'ai finalement ajoute la demo48 pour illustrer la puissance des proxy. Modified Paths: -------------- trunk/src/pfccommand.class.php trunk/src/pfcglobalconfig.class.php trunk/src/phpfreechat.class.php Added Paths: ----------- trunk/demo/demo48_custom_proxy/ trunk/demo/demo48_custom_proxy/myproxy.class.php trunk/demo/demo48_custom_proxy.php Added: trunk/demo/demo48_custom_proxy/myproxy.class.php =================================================================== --- trunk/demo/demo48_custom_proxy/myproxy.class.php (rev 0) +++ trunk/demo/demo48_custom_proxy/myproxy.class.php 2006-09-16 20:32:44 UTC (rev 764) @@ -0,0 +1,60 @@ +<?php +/** + * myproxy.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__)."/../../src/pfci18n.class.php"; +require_once dirname(__FILE__)."/../../src/pfcuserconfig.class.php"; +require_once dirname(__FILE__)."/../../src/pfcproxycommand.class.php"; + +/** + * pfcProxyCommand_myproxy + * this proxy will do nothing + * @author Stephane Gully <ste...@gm...> + */ +class pfcProxyCommand_myproxy extends pfcProxyCommand +{ + function run(&$xml_reponse, $p) + { + $clientid = $p["clientid"]; + $param = $p["param"]; + $sender = $p["sender"]; + $recipient = $p["recipient"]; + $recipientid = $p["recipientid"]; + $c =& $this->c; + $u =& $this->u; + + $cmdtocheck = array("send", "me"); + if ( in_array($this->name, $cmdtocheck) ) + { + // Modify the text + $param = "[this text is prepend by 'demo48_custom_proxy/myproxy.class.php'] ".$param; + } + + // forward the command to the next proxy or to the final command + $p["clientid"] = $clientid; + $p["param"] = $param; + $p["sender"] = $sender; + $p["recipient"] = $recipient; + $p["recipientid"] = $recipientid; + $this->next->run($xml_reponse, $p); + } +} + +?> \ No newline at end of file Added: trunk/demo/demo48_custom_proxy.php =================================================================== --- trunk/demo/demo48_custom_proxy.php (rev 0) +++ trunk/demo/demo48_custom_proxy.php 2006-09-16 20:32:44 UTC (rev 764) @@ -0,0 +1,39 @@ +<?php + +require_once dirname(__FILE__)."/../src/phpfreechat.class.php"; + +$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat +$params["skip_proxys"] = array("censor"); // shows how to disable a proxy (try to write fuck in the chat, it should be possible) +$params["post_proxys"] = array("myproxy"); +$params["proxys_path"] = dirname(__FILE__).'/demo48_custom_proxy'; +$chat = new phpFreeChat( $params ); + +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html> + <head> + <meta http-equiv="content-type" content="text/html; charset=utf-8" /> + <title>phpFreeChat demo</title> + + <?php $chat->printJavascript(); ?> + <?php $chat->printStyle(); ?> + + </head> + + <body> + <p>This demo shows how to create your own command proxy. Each chained proxies receive every transmitted commands. Your proxy can block the command, alterate the command, store some statistics. For example: to write a bot, just write a proxy.</p> + <?php $chat->printChat(); ?> + +<?php + // print the current file + echo "<h2>The source code</h2>"; + $filename = __FILE__; + echo "<p><code>".$filename."</code></p>"; + echo "<pre style=\"margin: 0 50px 0 50px; padding: 10px; background-color: #DDD;\">"; + $content = file_get_contents($filename); + echo htmlentities($content); + echo "</pre>"; +?> + + </body> +</html> Modified: trunk/src/pfccommand.class.php =================================================================== --- trunk/src/pfccommand.class.php 2006-09-15 18:13:17 UTC (rev 763) +++ trunk/src/pfccommand.class.php 2006-09-16 20:32:44 UTC (rev 764) @@ -81,15 +81,21 @@ // instanciate the proxys chaine $firstproxy =& $cmd; - for($i = count($c->proxys)-1; $i >= 0; $i--) + for($i = count($c->_proxys)-1; $i >= 0; $i--) { - $proxy_name = strtolower($c->proxys[$i]); + $proxy_name = strtolower($c->_proxys[$i]); $proxy_classname = "pfcProxyCommand_" . $proxy_name; if (!class_exists($proxy_classname)) { - // try to include the proxy class file - $proxy_filename = dirname(__FILE__)."/proxys/".$proxy_name.".class.php"; - if (file_exists($proxy_filename)) require_once($proxy_filename); + // try to include the proxy class file from the default path or from the customized path + $proxy_filename = $c->proxys_path_default.'/'.$proxy_name.".class.php"; + if (file_exists($proxy_filename)) + require_once($proxy_filename); + else + { + $proxy_filename = $c->proxys_path.'/'.$proxy_name.".class.php"; + if (file_exists($proxy_filename)) require_once($proxy_filename); + } } if (class_exists($proxy_classname)) { Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2006-09-15 18:13:17 UTC (rev 763) +++ trunk/src/pfcglobalconfig.class.php 2006-09-16 20:32:44 UTC (rev 764) @@ -41,14 +41,18 @@ var $lockurl = "http://www.phpfreechat.net"; // this is the url where the users must be redirected when the chat is locked // these parameters are static (cached) - var $proxys = array("lock", "checktimeout", "checknickchange", "auth", "noflood", "censor", "log"); + var $skip_proxys = array(); // these proxies will be skiped. ex: append "censor" to the list to disable words censoring + var $post_proxys = array(); // these proxies will be handled just before to process commands and just after system proxies + var $pre_proxys = array(); // these proxies will be handled before system proxies (at begining) var $proxys_cfg = array("auth" => array(), "noflood" => array("limit"=>10,"delay"=>5), "censor" => array("words"=>array("fuck","sex","bitch"),"replaceby"=>"*"), "log" => array("path"=>"")); + var $proxys_path = ""; // a custom proxies path + var $proxys_path_default = ""; // dirname(__FILE__).'/proxys' 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 + var $frozen_channels = array(); // if empty, allows users to create there own channels var $frozen_nick = false; var $max_nick_len = 15; var $max_text_len = 400; @@ -96,7 +100,6 @@ var $smileys = array(); var $errors = array(); - var $prefix = "pfc_"; var $is_init = false; // used internaly to know if the chat config is initialized var $version = ""; // the phpfreechat version: taken from the 'version' file content var $debugurl = ""; @@ -104,6 +107,8 @@ var $debugxajax = false; // private parameters + var $_sys_proxys = array("lock", "checktimeout", "checknickchange", "auth", "noflood", "censor", "log"); + var $_proxys = array(); // will contains proxies to execute on each command (filled in the init step) var $_dyn_params = array("nick","isadmin","islocked","admins","frozen_channels"); var $_params_type = array(); @@ -158,6 +163,9 @@ { if (!isset($this->$k)) $this->errors[] = _pfc("Error: undefined or obsolete parameter '%s', please correct or remove this parameter", $k); + if (preg_match('/^_/',$k)) + $this->errors[] = _pfc("Error: '%s' is a private parameter, you are not allowed to change it", $k); + if ($k == "proxys_cfg") { // don't replace all the proxy_cfg parameters, just replace the specified ones @@ -386,6 +394,33 @@ else @file_put_contents($proxyfile, $proxycontent); } + + + // calculate the proxies chaine + $this->_proxys = array(); + foreach($this->pre_proxys as $px) + { + if (!in_array($px,$this->skip_proxys) && !in_array($px,$this->_proxys)) + $this->_proxys[] = $px; + + } + foreach($this->_sys_proxys as $px) + { + if (!in_array($px,$this->skip_proxys) && !in_array($px,$this->_proxys)) + $this->_proxys[] = $px; + + } + foreach($this->post_proxys as $px) + { + if (!in_array($px,$this->skip_proxys) && !in_array($px,$this->_proxys)) + $this->_proxys[] = $px; + + } + // save the proxies path + $this->proxys_path_default = dirname(__FILE__).'/proxys'; + // check the customized proxies path + if ($this->proxys_path != '' && !is_dir($this->proxys_path)) + $this->errors[] = _pfc("'%s' directory doesn't exist", $this->proxys_path); // load smileys from file $this->loadSmileyTheme(); Modified: trunk/src/phpfreechat.class.php =================================================================== --- trunk/src/phpfreechat.class.php 2006-09-15 18:13:17 UTC (rev 763) +++ trunk/src/phpfreechat.class.php 2006-09-16 20:32:44 UTC (rev 764) @@ -64,7 +64,7 @@ if (file_exists($c->xajaxpath."/xajax.inc.php")) { require_once $c->xajaxpath."/xajax.inc.php"; - $this->xajax = new xajax($c->server_script_url.(isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "" ? "?".$_SERVER["QUERY_STRING"] : ""), $c->prefix); + $this->xajax = new xajax($c->server_script_url.(isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "" ? "?".$_SERVER["QUERY_STRING"] : ""), 'pfc_'); if ($c->debugxajax) $this->xajax->debugOn(); $this->xajax->waitCursorOff(); // do not show a wait cursor during chat updates $this->xajax->cleanBufferOff(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |