[Phpfreechat-svn] SF.net SVN: phpfreechat: [897] trunk
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-12-09 21:07:55
|
Revision: 897 http://svn.sourceforge.net/phpfreechat/?rev=897&view=rev Author: kerphi Date: 2006-12-09 13:07:47 -0800 (Sat, 09 Dec 2006) Log Message: ----------- [en] Makes possible to have commands with multi parameters. Quotes (") are used to identify parameters with spaces. see: http://www.phpfreechat.net/forum/viewtopic.php?id=872 [5h15] [fr] Rend possible les commandes ayant plusieurs param?\195?\168tres. Les doubles guillemets (") sont utilis?\195?\169s pour s?\195?\169parer les param?\195?\168tres contenant des espaces. cf: http://www.phpfreechat.net/forum/viewtopic.php?id=872 [5h15] Modified Paths: -------------- trunk/demo/demo15_multiple_channel.php trunk/demo/demo34_add_a_link_on_nicknames/mytheme/customize.js trunk/demo/demo50_data/mytheme/customize.js trunk/src/client/pfcclient.js trunk/src/client/pfcgui.js trunk/src/commands/asknick.class.php trunk/src/commands/ban.class.php trunk/src/commands/banlist.class.php trunk/src/commands/kick.class.php trunk/src/commands/leave.class.php trunk/src/commands/unban.class.php trunk/src/phpfreechat.class.php Modified: trunk/demo/demo15_multiple_channel.php =================================================================== --- trunk/demo/demo15_multiple_channel.php 2006-12-09 17:31:03 UTC (rev 896) +++ trunk/demo/demo15_multiple_channel.php 2006-12-09 21:07:47 UTC (rev 897) @@ -24,8 +24,8 @@ <body> <p>Rooms list:</p> <ul> - <li><a href="#" onclick="pfc.sendRequest('/join', 'room1');">room1</a></li> - <li><a href="#" onclick="pfc.sendRequest('/join', 'room2');">room2</a></li> + <li><a href="#" onclick="pfc.sendRequest('/join room1');">room1</a></li> + <li><a href="#" onclick="pfc.sendRequest('/join room2');">room2</a></li> </ul> <?php $chat->printChat(); ?> Modified: trunk/demo/demo34_add_a_link_on_nicknames/mytheme/customize.js =================================================================== --- trunk/demo/demo34_add_a_link_on_nicknames/mytheme/customize.js 2006-12-09 17:31:03 UTC (rev 896) +++ trunk/demo/demo34_add_a_link_on_nicknames/mytheme/customize.js 2006-12-09 21:07:47 UTC (rev 897) @@ -18,7 +18,7 @@ var a = document.createElement('a'); a.setAttribute('href', ''); a.pfc_nick = nicks[i]; - a.onclick = function(){pfc.sendRequest('/privmsg', this.pfc_nick); return false;} + a.onclick = function(){pfc.sendRequest('/privmsg "'+this.pfc_nick+'"'); return false;} a.appendChild(img); li.appendChild(a); } @@ -58,4 +58,4 @@ else nickdiv.appendChild(ul,fc); this.colorizeNicks(nickdiv); -} \ No newline at end of file +} Modified: trunk/demo/demo50_data/mytheme/customize.js =================================================================== --- trunk/demo/demo50_data/mytheme/customize.js 2006-12-09 17:31:03 UTC (rev 896) +++ trunk/demo/demo50_data/mytheme/customize.js 2006-12-09 21:07:47 UTC (rev 897) @@ -38,7 +38,7 @@ a.pfc_parent = div; a.onclick = function(evt){ var nick = pfc.getUserMeta(this.pfc_nickid,'nick'); - pfc.sendRequest('/privmsg', nick); + pfc.sendRequest('/privmsg "'+nick+'"'); this.pfc_parent.style.display = 'none'; return false; } @@ -96,4 +96,4 @@ div.appendChild(img); this.nickwhoisbox[nickid] = div; - } \ No newline at end of file + } Modified: trunk/src/client/pfcclient.js =================================================================== --- trunk/src/client/pfcclient.js 2006-12-09 17:31:03 UTC (rev 896) +++ trunk/src/client/pfcclient.js 2006-12-09 21:07:47 UTC (rev 897) @@ -138,7 +138,7 @@ if (nickname == '') nickname = this.nickname; var newnick = prompt(this.res.getLabel('Please enter your nickname'), nickname); if (newnick) - this.sendRequest('/nick', newnick); + this.sendRequest('/nick "'+newnick+'"'); }, /** @@ -158,7 +158,7 @@ this.askNick(this.nickname); else { - this.sendRequest('/nick', this.nickname); + this.sendRequest('/nick "'+this.nickname+'"'); } // give focus the the input text box if wanted @@ -266,34 +266,37 @@ for (var i=0; i<pfc_defaultchan.length; i++) { if (i<pfc_defaultchan.length-1) - cmd = "/join2"; + cmd = '/join2'; else - cmd = "/join"; - this.sendRequest(cmd, pfc_defaultchan[i]); + cmd = '/join'; + cmd += ' "'+pfc_defaultchan[i]+'"'; + this.sendRequest(cmd); } // now join channels comming from sessions for (var i=0; i<pfc_userchan.length; i++) { if (i<pfc_userchan.length-1) - cmd = "/join2"; + cmd = '/join2'; else - cmd = "/join"; - this.sendRequest(cmd, pfc_userchan[i]); + cmd = '/join'; + cmd += ' "'+pfc_userchan[i]+'"'; + this.sendRequest(cmd); } // join the default privmsg comming from the parameter list for (var i=0; i<pfc_defaultprivmsg.length; i++) { if (i<pfc_defaultprivmsg.length-1) - cmd = "/privmsg2"; + cmd = '/privmsg2'; else - cmd = "/privmsg"; - this.sendRequest(cmd, pfc_defaultprivmsg[i]); + cmd = '/privmsg'; + cmd += ' "'+pfc_defaultprivmsg[i]+'"'; + this.sendRequest(cmd); } // now join privmsg comming from the sessions for (var i=0; i<pfc_userprivmsg.length; i++) { - this.sendRequest("/privmsg", pfc_userprivmsg[i]); + this.sendRequest('/privmsg "'+pfc_userprivmsg[i]+'"'); } } @@ -457,7 +460,7 @@ var nickid = meta['users']['nickid'][i]; var nick = meta['users']['nick'][i]; var um = this.getAllUserMeta(nickid); - if (!um) this.sendRequest('/whois2', nick); + if (!um) this.sendRequest('/whois2 "'+nick+'"'); } // update the nick list display on the current channel @@ -541,7 +544,7 @@ // a user command cmd = wval.replace(re, '$1'); param = wval.replace(re, '$3'); - this.sendRequest(cmd, param.substr(0, pfc_max_text_len + this.clientid.length)); + this.sendRequest(cmd +' '+ param.substr(0, pfc_max_text_len + 2*this.clientid.length)); } else { @@ -558,7 +561,7 @@ if (this.current_text_color != '' && wval.length != '') wval = '[color=#' + this.current_text_color + '] ' + wval + ' [/color]'; - this.sendRequest('/send', wval); + this.sendRequest('/send '+ wval); } w.value = ''; return false; @@ -885,28 +888,14 @@ * Call the ajax request function * Will query the server */ - sendRequest: function(cmd, param) + sendRequest: function(cmd) { - var recipientid = this.gui.getTabId(); - - - var req = cmd+" "+this.clientid+" "+(recipientid==''?'0':recipientid)+(param?" "+param : ""); if (pfc_debug) - if (cmd != "/update") trace('sendRequest: '+req); - return eval('pfc_handleRequest(req);'); - }, - - // @todo remplacer sendRequest par cette fonction (cf /leave dans pfcgui.js) - sendRequest2: function(cmd) - { + if (cmd != "/update") trace('sendRequest: '+cmd); var rx = new RegExp('(^\/[^ ]+) *(.*)','ig'); - var ttt = cmd.split(rx); - var recipientid = this.gui.getTabId(); - var req = ttt[1]+" "+this.clientid+" "+(recipientid==''?'0':recipientid)+' '+ttt[2]; - if (pfc_debug) - if (cmd != "/update") trace('sendRequest: '+req); - return eval('pfc_handleRequest(req);'); + cmd = cmd.replace(rx, '$1 '+this.clientid+' '+(recipientid==''?'0':recipientid)+' $2'); + return eval('pfc_handleRequest(cmd);'); }, /** @@ -1028,7 +1017,7 @@ a.pfc_parent = div; a.onclick = function(evt){ var nick = pfc.getUserMeta(this.pfc_nickid,'nick'); - pfc.sendRequest('/privmsg', nick); + pfc.sendRequest('/privmsg "'+nick+'"'); this.pfc_parent.style.display = 'none'; return false; } Modified: trunk/src/client/pfcgui.js =================================================================== --- trunk/src/client/pfcgui.js 2006-12-09 17:31:03 UTC (rev 896) +++ trunk/src/client/pfcgui.js 2006-12-09 21:07:47 UTC (rev 897) @@ -257,9 +257,12 @@ var a2 = document.createElement('a'); a2.pfc_tabid = tabid; a2.pfc_tabname = name; + a2.pfc_tabtype = type; a2.onclick = function(){ var res = confirm(pfc.res.getLabel('Do you really want to leave this room ?')); - if (res == true) pfc.sendRequest2('/leave "'+this.pfc_tabname+'"'); return false; + if (res == true) + pfc.sendRequest('/leave '+this.pfc_tabtype+' "'+this.pfc_tabname+'"'); + return false; } a2.alt = pfc.res.getLabel('Close this tab'); a2.title = a2.alt; Modified: trunk/src/commands/asknick.class.php =================================================================== --- trunk/src/commands/asknick.class.php 2006-12-09 17:31:03 UTC (rev 896) +++ trunk/src/commands/asknick.class.php 2006-12-09 21:07:47 UTC (rev 897) @@ -34,7 +34,7 @@ } else $msg = "'".$nicktochange."' is used, please choose another nickname."; - $xml_reponse->addScript("var newnick = prompt('".addslashes($msg)."', '".addslashes($nicktochange)."'); if (newnick) pfc.sendRequest('/nick', newnick);"); + $xml_reponse->addScript("var newnick = prompt('".addslashes($msg)."', '".addslashes($nicktochange)."'); if (newnick) pfc.sendRequest('/nick \"'+newnick+'\"');"); } } } Modified: trunk/src/commands/ban.class.php =================================================================== --- trunk/src/commands/ban.class.php 2006-12-09 17:31:03 UTC (rev 896) +++ trunk/src/commands/ban.class.php 2006-12-09 21:07:47 UTC (rev 897) @@ -18,7 +18,12 @@ $c =& $this->c; $u =& $this->u; - if (trim($params[0]) == '') + $nick = isset($params[0]) ? trim($params[0]) : ''; + $reason = isset($params[1]) ? $params[1] : ''; + if ($reason == '') $reason = _pfc("no reason"); + $channame = $u->channels[$recipientid]["name"]; + + if ($nick == '') { // error $cmdp = $p; @@ -30,11 +35,11 @@ } $ct =& $c->getContainerInstance(); - $nickidtoban = $ct->getNickId($params[0]); + $nickidtoban = $ct->getNickId($nick); // notify all the channel $cmdp = $p; - $cmdp["param"] = _pfc("banished from %s by %s", $recipient, $sender); + $cmdp["param"] = _pfc("banished from %s by %s", $channame, $sender); $cmdp["flag"] = 1; $cmd =& pfcCommand::Factory("notice"); $cmd->run($xml_reponse, $cmdp); @@ -42,8 +47,8 @@ // kick the user (maybe in the future, it will be dissociate in a /kickban command) $cmdp = $p; $cmdp["params"] = array(); - $cmdp["params"][] = $params[0]; // nickname to kick - $cmdp["params"][] = $params[1]; // reason + $cmdp["params"][] = $nick; // nickname to kick + $cmdp["params"][] = $reason; // reason $cmd =& pfcCommand::Factory("kick"); $cmd->run($xml_reponse, $cmdp); Modified: trunk/src/commands/banlist.class.php =================================================================== --- trunk/src/commands/banlist.class.php 2006-12-09 17:31:03 UTC (rev 896) +++ trunk/src/commands/banlist.class.php 2006-12-09 21:07:47 UTC (rev 897) @@ -21,14 +21,14 @@ if ($banlist == NULL) $banlist = array(); else $banlist = unserialize($banlist); $msg = ""; - $msg .= "<p>"._pfc("The banished user's id list is:")."</p>"; + $msg .= "<p>"._pfc("The banished user list is:")."</p>"; if (count($banlist)>0) { $msg .= "<ul>"; foreach($banlist as $b) { $n = $ct->getNickname($b); - $msg .= "<li style=\"margin-left:50px\">".$b." (".$n.")</li>"; + $msg .= "<li style=\"margin-left:50px\">".$n."</li>"; } $msg .= "</ul>"; } @@ -36,7 +36,7 @@ { $msg .= "<p>("._pfc("Empty").")</p>"; } - $msg .= "<p>"._pfc("'/unban {id}' will unban the user identified by {id}")."</p>"; + $msg .= "<p>"._pfc("'/unban {nickname}' will unban the user identified by {nickname}")."</p>"; $msg .= "<p>"._pfc("'/unban all' will unban all the users on this channel")."</p>"; $xml_reponse->addScript("pfc.handleResponse('".$this->name."', 'ok', '".addslashes($msg)."');"); Modified: trunk/src/commands/kick.class.php =================================================================== --- trunk/src/commands/kick.class.php 2006-12-09 17:31:03 UTC (rev 896) +++ trunk/src/commands/kick.class.php 2006-12-09 21:07:47 UTC (rev 897) @@ -18,7 +18,11 @@ $c =& $this->c; $u =& $this->u; - if (trim($params[0]) == '') + $nick = isset($params[0]) ? trim($params[0]) : ''; + $reason = isset($params[1]) ? $params[1] : ''; + if ($reason == '') $reason = _pfc("no reason"); + + if ($nick == '') { // error $cmdp = $p; @@ -31,12 +35,12 @@ // kicking a user just add a command to play to the aimed user metadata. $ct =& $c->getContainerInstance(); - $otherid = $ct->getNickId($params[0]); + $otherid = $ct->getNickId($nick); $channame = $u->channels[$recipientid]["name"]; $cmdstr = 'leave'; $cmdp = array(); $cmdp['params'][] = $channame; // channel name - $cmdp['params'][] = _pfc("kicked from %s by %s - reason: %s", $channame, $sender, $params[1]); // reason + $cmdp['params'][] = _pfc("kicked from %s by %s - reason: %s", $channame, $sender, $reason); // reason pfcCommand::AppendCmdToPlay($otherid, $cmdstr, $cmdp); } } Modified: trunk/src/commands/leave.class.php =================================================================== --- trunk/src/commands/leave.class.php 2006-12-09 17:31:03 UTC (rev 896) +++ trunk/src/commands/leave.class.php 2006-12-09 21:07:47 UTC (rev 897) @@ -5,7 +5,7 @@ class pfcCommand_leave extends pfcCommand { - var $usage = "/leave [{channel} {reason}]"; + var $usage = "/leave [ch|pv [[{channel|nickname}] {reason}]]"; function run(&$xml_reponse, $p) { @@ -17,24 +17,55 @@ $c =& $this->c; $u =& $this->u; + $ct =& $c->getContainerInstance(); - // tab to leave can be passed in the parameters - // a reason can also be present (used for kick and ban commands) - $id = ''; $reason = ''; - if (count($params)>0) + $type = isset($params[0]) ? $params[0] : ''; + $name = isset($params[1]) ? $params[1] : ''; + $reason = isset($params[2]) ? $params[2] : ''; + + if ($type != 'ch' && $type != 'pv' && $type != '') { - $id = pfcCommand_join::GetRecipientId($params[0]); - $reason = implode(" ",array_slice($params,1)); + // error + $cmdp = $p; + $cmdp["param"] = _pfc("Missing parameter"); + $cmdp["param"] .= " (".$this->usage.")"; + $cmd =& pfcCommand::Factory("error"); + $cmd->run($xml_reponse, $cmdp); + return; } - if ($id == '') $id = $recipientid; // be default this is the current tab to leave + - // $xml_reponse->addScript("alert('sender=".addslashes($sender)."');"); - // $xml_reponse->addScript("alert('recipientid=".addslashes($id)."');"); + // get the recipientid to close (a pv or a channel) + $id = ''; + if ($type == 'ch') + { + if ($name == '') + $id = $recipientid; + else + $id = pfcCommand_join::GetRecipientId($name); + } + else if ($type == 'pv') + { + // pv + $pvnickid = $ct->getNickId($name); + $nickid = $u->nickid; + if ($pvnickid != '') + { + // generate a pvid from the two nicknames ids + $a = array($pvnickid, $nickid); sort($a); + $pvrecipient = "pv_".$a[0]."_".$a[1]; + $id = md5($pvrecipient); + } + } + else + $id = $recipientid; + + $leavech = false; $leavepv = false; - $leave_recip = ""; - $leave_id = ""; + $leave_recip = ''; + $leave_id = ''; // check into channels if ( isset($u->channels[$id]) ) @@ -72,7 +103,6 @@ } // remove the nickname from the channel/pv - $ct =& $c->getContainerInstance(); $ct->removeNick($leave_recip, $u->nickid); // reset the sessions indicators Modified: trunk/src/commands/unban.class.php =================================================================== --- trunk/src/commands/unban.class.php 2006-12-09 17:31:03 UTC (rev 896) +++ trunk/src/commands/unban.class.php 2006-12-09 21:07:47 UTC (rev 897) @@ -4,12 +4,13 @@ class pfcCommand_unban extends pfcCommand { - var $usage = "/unban {id}"; + var $usage = "/unban {nickname}"; function run(&$xml_reponse, $p) { $clientid = $p["clientid"]; $param = $p["param"]; + $params = $p["params"]; $sender = $p["sender"]; $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; @@ -17,9 +18,12 @@ $c =& $this->c; $u =& $this->u; - $container =& $c->getContainerInstance(); + $ct =& $c->getContainerInstance(); - if (trim($param) == "") + $nick = isset($params[0]) ? $params[0] : ''; + $nickid = $ct->getNickId($nick); + + if ($nick == "") { // error $cmdp = $p; @@ -29,29 +33,30 @@ $cmd->run($xml_reponse, $cmdp); return; } + $updated = false; $msg = "<p>"._pfc("Nobody has been unbanished")."</p>"; // update the recipient banlist - $banlist = $container->getChanMeta($recipient, 'banlist_nickid'); + $banlist = $ct->getChanMeta($recipient, 'banlist_nickid'); if ($banlist == NULL) $banlist = array(); else $banlist = unserialize($banlist); $nb = count($banlist); - if (in_array($param, $banlist)) + if (in_array($nickid, $banlist)) { - $banlist = array_diff($banlist, array($param)); - $container->setChanMeta($recipient, 'banlist_nickid', serialize($banlist)); + $banlist = array_diff($banlist, array($nickid)); + $ct->setChanMeta($recipient, 'banlist_nickid', serialize($banlist)); $updated = true; - $msg = "<p>"._pfc("%s has been unbanished", $param)."</p>"; + $msg = "<p>"._pfc("%s has been unbanished", $nick)."</p>"; } - else if ($param == "all") + else if ($nick == "all") // @todo move the "/unban all" command in another command /unbanall { $banlist = array(); - $container->setChanMeta($recipient, 'banlist_nickid', serialize($banlist)); + $ct->setChanMeta($recipient, 'banlist_nickid', serialize($banlist)); $updated = true; $msg = "<p>"._pfc("%s users have been unbanished", $nb)."</p>"; } Modified: trunk/src/phpfreechat.class.php =================================================================== --- trunk/src/phpfreechat.class.php 2006-12-09 17:31:03 UTC (rev 896) +++ trunk/src/phpfreechat.class.php 2006-12-09 21:07:47 UTC (rev 897) @@ -339,7 +339,7 @@ $cmdname = strtolower(isset($res['cmdname']) ? $res['cmdname'] : ''); $clientid = isset($res['params'][0]) ? $res['params'][0] : ''; $recipientid = isset($res['params'][1]) ? $res['params'][1] : ""; - $params = array_slice($res['params'],2); + $params = array_slice(is_array($res['params']) ? $res['params'] : array() ,2); $param = implode(" ",$params); // to keep compatibility (will be removed) $sender = $u->nick; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |