[Phpfreechat-svn] SF.net SVN: phpfreechat: [734] trunk/src
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-09-05 16:24:35
|
Revision: 734 http://svn.sourceforge.net/phpfreechat/?rev=734&view=rev Author: kerphi Date: 2006-09-05 09:24:23 -0700 (Tue, 05 Sep 2006) Log Message: ----------- [en] - Makes possible to use frozen_nick with a empty nick parameter. So it's possible to choose the nick at beginning of the session then it's impossible to change it. [fr] - Rend possible l'utilisation de frozen_nick avec un pseudonyme vide. Ainsi c'est possible de choisir son pseudo a la premi?\195?\168re connexion et ensuite c'est impossible de le changer. [en] - Make possible to change dynamicaly the user nickname using the parameter array (however, frozen_nick must be on) [fr] - On peut maintenant forcer un utilisateur ?\195?\160 changer de pseudo dynamiquement (ex: si l'utilisateur change de pseudo dans le syst?\195?\168me d'authentification hote). Pour cela il suffit d'assigner un nouveau nick dans les parametres en plein milieur de l'execution. Bien sur frozen_nick doit ?\195?\170tre activ?\195?\169! Modified Paths: -------------- trunk/src/client/chat.js.tpl.php trunk/src/client/pfcclient.js trunk/src/commands/nick.class.php trunk/src/pfcglobalconfig.class.php trunk/src/pfcuserconfig.class.php trunk/src/phpfreechat.class.php trunk/src/proxys/auth.class.php Added Paths: ----------- trunk/src/proxys/checknickchange.class.php Modified: trunk/src/client/chat.js.tpl.php =================================================================== --- trunk/src/client/chat.js.tpl.php 2006-09-04 20:41:46 UTC (rev 733) +++ trunk/src/client/chat.js.tpl.php 2006-09-05 16:24:23 UTC (rev 734) @@ -1,5 +1,6 @@ +<?php $nick = $u->nick != "" ? addslashes($u->nick) : addslashes($c->nick); ?> +var pfc_nickname = '<?php echo ($GLOBALS["output_encoding"]=="UTF-8" ? $nick : iconv("UTF-8", $GLOBALS["output_encoding"],$nick)); ?>'; var pfc_version = '<?php echo $version; ?>'; -var pfc_nickname = '<?php echo ($GLOBALS["output_encoding"]=="UTF-8" ? addslashes($u->nick) : iconv("UTF-8", $GLOBALS["output_encoding"],addslashes($u->nick))); ?>'; var pfc_clientid = '<?php echo md5(uniqid(rand(), true)); ?>'; var pfc_title = '<?php echo addslashes($title); ?>'; var pfc_refresh_delay = <?php echo $refresh_delay; ?>; @@ -78,6 +79,7 @@ "Enter the text to format", // _pfc "Configuration has been rehashed", // _pfc "A problem occurs during rehash", // _pfc + "Choosen nickname is allready used", //_pfc ); foreach($labels_to_load as $l) { Modified: trunk/src/client/pfcclient.js =================================================================== --- trunk/src/client/pfcclient.js 2006-09-04 20:41:46 UTC (rev 733) +++ trunk/src/client/pfcclient.js 2006-09-05 16:24:23 UTC (rev 734) @@ -306,7 +306,7 @@ } else if (resp == "isused") { - this.askNick(param); + this.displayMsg( cmd, this.res.getLabel('Choosen nickname is allready used') ); } else alert(cmd + "-"+resp+"-"+param); @@ -374,6 +374,10 @@ { this.displayMsg( cmd, param ); } + else if (cmd == "checknickchange") + { + this.displayMsg( cmd, param ); + } else alert(cmd + "-"+resp+"-"+param); }, Modified: trunk/src/commands/nick.class.php =================================================================== --- trunk/src/commands/nick.class.php 2006-09-04 20:41:46 UTC (rev 733) +++ trunk/src/commands/nick.class.php 2006-09-05 16:24:23 UTC (rev 734) @@ -31,111 +31,64 @@ $newnick = phpFreeChat::FilterNickname($param); $oldnick = $u->nick; - if ($c->debug) pxlog("/nick ".$newnick, "chat", $c->getId()); - $container =& $c->getContainerInstance(); $newnickid = $container->getNickId($newnick); - $oldnickid = $container->getNickId($u->nick); + $oldnickid = $container->getNickId($oldnick); - // now check unsensitive case - // 'BoB' and 'bob' must be considered same nicknames - $nick_in_use = false; - $online_users = $container->getOnlineNick(NULL); - if (isset($online_users["nickid"])) - foreach($online_users["nickid"] as $nid) - { - if (preg_match("/^".preg_quote($container->getNickname($nid))."$/i",$newnick)) - { - // the nick match - // just allow the owner to change his capitalised letters - if ($nid != $oldnickid) - $nick_in_use = true; - } - } + if ($c->debug) pxlog("/nick ".$newnick, "chat", $c->getId()); - if ( $newnickid == "undefined" && !$nick_in_use ) + // new nickname is undefined (not used) and + // current nickname (oldnick) is mine and + // oldnick is different from new nick + // -> this is a nickname change + if ($oldnickid == $u->nickid && + $oldnick != $newnick && $oldnick != "") { - // new nickname is undefined (not used) and - // current nickname (oldnick) is mine and - // oldnick is different from new nick - // -> this is a nickname change - if ($oldnickid == $u->nickid && - $oldnick != $newnick && $oldnick != "") - { - // really change the nick (rename it) - $container->changeNick($newnick, $oldnick); - $u->nick = $newnick; - $u->saveInCache(); + // really change the nick (rename it) + $container->changeNick($newnick, $oldnick); + $u->nick = $newnick; + $u->saveInCache(); - // notify all the joined channels/privmsg - $cmdp = $p; - $cmdp["param"] = _pfc("%s changes his nickname to %s",$oldnick,$newnick); - $cmdp["flag"] = 1; - $cmd =& pfcCommand::Factory("notice"); - foreach($u->channels as $id => $chan) - { - $cmdp["recipient"] = $chan["recipient"]; - $cmdp["recipientid"] = $id; - $cmd->run($xml_reponse, $cmdp); - } - foreach( $u->privmsg as $id => $pv ) - { - $cmdp["recipient"] = $pv["recipient"]; - $cmdp["recipientid"] = $id; - $cmd->run($xml_reponse, $cmdp); - } - $xml_reponse->addScript("pfc.handleResponse('nick', 'changed', '".addslashes($newnick)."');"); + // notify all the joined channels/privmsg + $cmdp = $p; + $cmdp["param"] = _pfc("%s changes his nickname to %s",$oldnick,$newnick); + $cmdp["flag"] = 1; + $cmd =& pfcCommand::Factory("notice"); + foreach($u->channels as $id => $chan) + { + $cmdp["recipient"] = $chan["recipient"]; + $cmdp["recipientid"] = $id; + $cmd->run($xml_reponse, $cmdp); } - - // new nickname is undefined (not used) and - // current nickname (oldnick) is not mine or is undefined - // -> this is a first connection - if ($oldnickid != $u->nickid) + foreach( $u->privmsg as $id => $pv ) { - // this is a first connection (create the nickname) - $container->createNick(NULL, $newnick, $u->nickid); - foreach($u->channels as $chan) - $container->createNick($chan["recipient"], $newnick, $u->nickid); - foreach($u->privmsg as $pv) - $container->createNick($pv["recipient"], $newnick, $u->nickid); - $u->nick = $newnick; - $u->active = true; - $u->saveInCache(); - - $xml_reponse->addScript("pfc.handleResponse('nick', 'connected', '".addslashes($newnick)."');"); - - if ($c->debug) - pxlog("/nick ".$newnick." (first connection, oldnick=".$oldnick.")", "chat", $c->getId()); + $cmdp["recipient"] = $pv["recipient"]; + $cmdp["recipientid"] = $id; + $cmd->run($xml_reponse, $cmdp); } - - // force the handle field to be uptodate - // $xml_reponse->addAssign($c->prefix."handle", "value", $newnick); - //$xml_reponse->addScript("$('".$c->prefix."words').focus();"); - + $xml_reponse->addScript("pfc.handleResponse('nick', 'changed', '".addslashes($newnick)."');"); } - else if ($newnickid == $u->nickid) + + // new nickname is undefined (not used) and + // current nickname (oldnick) is not mine or is undefined + // -> this is a first connection + if ($oldnickid != $u->nickid) { - // user didn't change his nickname - //$xml_reponse->addAssign($c->prefix."handle", "value", $newnick); - $xml_reponse->addScript("pfc.handleResponse('nick', 'notchanged', '".addslashes($newnick)."');"); + // this is a first connection (create the nickname) + $container->createNick(NULL, $newnick, $u->nickid); + foreach($u->channels as $chan) + $container->createNick($chan["recipient"], $newnick, $u->nickid); + foreach($u->privmsg as $pv) + $container->createNick($pv["recipient"], $newnick, $u->nickid); + $u->nick = $newnick; + $u->active = true; + $u->saveInCache(); + $xml_reponse->addScript("pfc.handleResponse('nick', 'connected', '".addslashes($newnick)."');"); + if ($c->debug) - pxlog("/nick ".$newnick." (user just reloded the page so let him keep his nickname without any warnings -> nickid=".$newnickid.")", "chat", $c->getId()); + pxlog("/nick ".$newnick." (first connection, oldnick=".$oldnick.")", "chat", $c->getId()); } - else - { - // the wanted nick is allready used, just ask again the user - //$cmd =& pfcCommand::Factory("asknick"); - //$cmd->run($xml_reponse, $clientid, $newnick, $sender, $recipient); - - $xml_reponse->addScript("pfc.handleResponse('nick', 'isused', '".addslashes($newnick)."');"); - - if ($c->debug) - pxlog("/nick ".$newnick." (wanted nick is allready in use -> wantednickid=".$newnickid.")", "chat", $c->getId()); - } - - // refresh users info on client side - //$xml_reponse->addScript("pfc.nickname = '".$u->nick."';"); } } Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2006-09-04 20:41:46 UTC (rev 733) +++ trunk/src/pfcglobalconfig.class.php 2006-09-05 16:24:23 UTC (rev 734) @@ -41,7 +41,7 @@ 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", "auth", "noflood", "censor", "log"); + var $proxys = array("lock", "auth", "checknickchange", "noflood", "censor", "log"); var $proxys_cfg = array("auth" => array(), "noflood" => array("limit"=>10,"delay"=>5), "censor" => array("words"=>array("fuck","sex","bitch"),"replaceby"=>"*"), @@ -398,11 +398,6 @@ // load debug url $this->debugurl = relativePath($this->client_script_path, dirname(__FILE__)."/../debug"); - - // check the frozen_nick parameter is used with a none empty nickname - if ($this->frozen_nick && $this->nick == "") - $this->errors[] = _pfc("frozen_nick can't be used with a empty nick"); - // check the language is known $lg_list = pfcI18N::GetAcceptedLanguage(); if ( $this->language != "" && !in_array($this->language, $lg_list) ) @@ -433,10 +428,6 @@ // load smileys from file $this->loadSmileyTheme(); - // do not froze nickname if it has not be specified - if ($this->nick == "" && $this->frozen_nick) - $this->frozen_nick = false; - // load version number from file $this->version = trim(file_get_contents(dirname(__FILE__)."/../version")); Modified: trunk/src/pfcuserconfig.class.php =================================================================== --- trunk/src/pfcuserconfig.class.php 2006-09-04 20:41:46 UTC (rev 733) +++ trunk/src/pfcuserconfig.class.php 2006-09-05 16:24:23 UTC (rev 734) @@ -30,7 +30,7 @@ // user parameters are cached in sessions $this->_getParam("nick"); - if (!isset($this->nick)) $this->_setParam("nick",$c->nick); + if (!isset($this->nick)) $this->_setParam("nick",""); // setup a blank nick if it is not yet in session $this->_getParam("active"); if (!isset($this->active)) $this->_setParam("active",false); $this->_getParam("channels"); @@ -57,8 +57,7 @@ function _setParam($p, $v) { $c =& pfcGlobalConfig::Instance(); - $nickid = "pfcuserconfig_".$c->getId(); - $nickid_param = $nickid."_".$p; + $nickid_param = "pfcuserconfig_".$c->getId()./*"_".$this->nickid.*/"_".$p; $_SESSION[$nickid_param] = $v; $this->$p = $v; } @@ -66,8 +65,7 @@ function _rmParam($p) { $c =& pfcGlobalConfig::Instance(); - $nickid = "pfcuserconfig_".$c->getId(); - $nickid_param = $nickid."_".$p; + $nickid_param = "pfcuserconfig_".$c->getId()./*"_".$this->nickid.*/"_".$p; unset($_SESSION[$nickid_param]); unset($this->$p); } Modified: trunk/src/phpfreechat.class.php =================================================================== --- trunk/src/phpfreechat.class.php 2006-09-04 20:41:46 UTC (rev 733) +++ trunk/src/phpfreechat.class.php 2006-09-05 16:24:23 UTC (rev 734) @@ -247,9 +247,9 @@ foreach ($s_strs as $s_str) { $s_str = stripslashes($s_str); /* the :'( smileys needs this filter */ - $query .= preg_quote($s_str,'/')."|"; - $search[] = "/".preg_quote($s_str,'/')."/"; - $replace[] = '<img src="'.$s_file.'" alt="'.$s_str.'" title="'.$s_str.'" />'; + $query .= preg_quote($s_str,'/')."|"; + $search[] = "/".preg_quote($s_str,'/')."/"; + $replace[] = '<img src="'.$s_file.'" alt="'.$s_str.'" title="'.$s_str.'" />'; } } $query = substr($query, 0, strlen($query)-1); @@ -425,9 +425,9 @@ { // call the command if ($c->debug) - $cmd->run($xml_reponse, $cmdp); + $cmd->run($xml_reponse, $cmdp); else - @$cmd->run($xml_reponse, $cmdp); + @$cmd->run($xml_reponse, $cmdp); } else { @@ -447,8 +447,8 @@ // do not update twice // do not update when the user just quit if ($rawcmd != "update" && - $rawcmd != "quit" && - $u->nick != "") + $rawcmd != "quit" && + $u->nick != "") { // force an update just after a command is sent // thus the message user just poster is really fastly displayed @@ -460,9 +460,9 @@ $cmdp["recipient"] = $recipient; $cmdp["recipientid"] = $recipientid; if ($c->debug) - $cmd->run($xml_reponse, $cmdp); + $cmd->run($xml_reponse, $cmdp); else - @$cmd->run($xml_reponse, $cmdp); + @$cmd->run($xml_reponse, $cmdp); } if ($c->debug) Modified: trunk/src/proxys/auth.class.php =================================================================== --- trunk/src/proxys/auth.class.php 2006-09-04 20:41:46 UTC (rev 733) +++ trunk/src/proxys/auth.class.php 2006-09-05 16:24:23 UTC (rev 734) @@ -85,18 +85,6 @@ } } } - - // disallow to change nickname if frozen_nick is true - if ($this->name == "nick") - { - if ($param != $c->nick && - $c->frozen_nick == true) - { - $msg = _pfc("You are not allowed to change your nickname", $param); - $xml_reponse->addScript("pfc.handleResponse('".$this->proxyname."', 'nick', '".addslashes($msg)."');"); - return; - } - } // forward the command to the next proxy or to the final command $p["clientid"] = $clientid; Added: trunk/src/proxys/checknickchange.class.php =================================================================== --- trunk/src/proxys/checknickchange.class.php (rev 0) +++ trunk/src/proxys/checknickchange.class.php 2006-09-05 16:24:23 UTC (rev 734) @@ -0,0 +1,128 @@ +<?php +/** + * checknickchange.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_checknickchange + * + * @author Stephane Gully <ste...@gm...> + */ +class pfcProxyCommand_checknickchange 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; + + if ( $this->name == "nick") + { + $newnick = phpFreeChat::FilterNickname($param); + $oldnick = $u->nick; + + if ($newnick == $oldnick) + { + $xml_reponse->addScript("pfc.handleResponse('nick', 'notchanged', '".addslashes($newnick)."');"); + if ($c->debug) + pxlog("/nick ".$newnick." (user just reloded the page so let him keep his nickname without any warnings -> nickid=".$newnickid.")", "chat", $c->getId()); + return; + } + + // if the user want to change his nickname but the frozen_nick is enable + // then send him a warning + if ( $this->name == "nick" && + $u->nick != "" && + $param != $u->nick && + $c->frozen_nick == true && + $p["owner"] != "checknickchange" ) + { + $msg = _pfc("You are not allowed to change your nickname"); + $xml_reponse->addScript("pfc.handleResponse('".$this->proxyname."', 'nick', '".addslashes($msg)."');"); + return; + } + + $container =& $c->getContainerInstance(); + $newnickid = $container->getNickId($newnick); + $oldnickid = $container->getNickId($oldnick); + + // now check the nickname is not yet used (unsensitive case) + // 'BoB' and 'bob' must be considered same nicknames + $nick_in_use = false; + $online_users = $container->getOnlineNick(NULL); + if (isset($online_users["nickid"])) + foreach($online_users["nickid"] as $nid) + { + if (preg_match("/^".preg_quote($container->getNickname($nid))."$/i",$newnick)) + { + // the nick match + // just allow the owner to change his capitalised letters + if ($nid != $oldnickid) + $nick_in_use = true; + } + } + if ($nick_in_use) + { + $xml_reponse->addScript("pfc.handleResponse('nick', 'isused', '".addslashes($newnick)."');"); + if ($c->debug) + pxlog("/nick ".$newnick." (wanted nick is allready in use -> wantednickid=".$newnickid.")", "chat", $c->getId()); + return; + } + + if ( $newnickid != "undefined" ) + { + // @todo notify the user ? + return; + } + + } + + // allow nick changes only from the parameters array (server side) + if ($c->frozen_nick == true && + $u->nick != $c->nick && + $c->nick != "" && // don't change the nickname to empty or the asknick popup will loop indefinatly + $p["owner"] != "checknickchange") + { + // change the user nickname + $cmdp = $p; + $cmdp["param"] = $c->nick; + $cmdp["owner"] = "checknickchange"; + $cmd =& pfcCommand::Factory("nick"); + $cmd->run($xml_reponse, $cmdp); + return; + } + + + + + // forward the command to the next proxy or to the final command + $this->next->run($xml_reponse, $p); + } +} + +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |