[Phpfreechat-svn] SF.net SVN: phpfreechat: [490] trunk/src/commands
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-05-11 16:48:03
|
Revision: 490 Author: kerphi Date: 2006-05-11 09:47:54 -0700 (Thu, 11 May 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=490&view=rev Log Message: ----------- improve the getOnlineNick function: now it returns the nicknames timestamps Modified Paths: -------------- trunk/src/commands/getonlinenick.class.php trunk/src/commands/nick.class.php trunk/src/commands/send.class.php trunk/src/containers/file.class.php Modified: trunk/src/commands/getonlinenick.class.php =================================================================== --- trunk/src/commands/getonlinenick.class.php 2006-05-11 16:11:14 UTC (rev 489) +++ trunk/src/commands/getonlinenick.class.php 2006-05-11 16:47:54 UTC (rev 490) @@ -34,7 +34,7 @@ $js = ""; foreach ($users as $u) { - $nickname = addslashes($u); // must escape ' charactere for javascript string + $nickname = addslashes($u["nick"]); // must escape ' charactere for javascript string $js .= "'".$nickname."',"; } $js = substr($js, 0, strlen($js)-1); // remove last ',' Modified: trunk/src/commands/nick.class.php =================================================================== --- trunk/src/commands/nick.class.php 2006-05-11 16:11:14 UTC (rev 489) +++ trunk/src/commands/nick.class.php 2006-05-11 16:47:54 UTC (rev 490) @@ -34,11 +34,11 @@ $online_users = $container->getOnlineNick(NULL); foreach($online_users as $ou) { - if (preg_match("/^".preg_quote($ou)."$/i",$newnick)) + if (preg_match("/^".preg_quote($ou["nick"])."$/i",$newnick)) { // the nick match // just allow the owner to change his capitalised letters - if ($container->getNickId($ou) != $oldnickid) + if ($container->getNickId($ou["nick"]) != $oldnickid) $nick_in_use = true; } } Modified: trunk/src/commands/send.class.php =================================================================== --- trunk/src/commands/send.class.php 2006-05-11 16:11:14 UTC (rev 489) +++ trunk/src/commands/send.class.php 2006-05-11 16:47:54 UTC (rev 490) @@ -22,8 +22,14 @@ // now check if this user is currently online $container =& $c->getContainerInstance(); $onlineusers = $container->getOnlineNick(NULL); - if (!in_array($pvnick,$onlineusers)) + $uid = 0; $isonline = false; + while($uid < count($onlineusers) && !$isonline) { + if ($onlineusers[$uid]["nick"] == $pvnick) $isonline = true; + $uid++; + } + if (!$isonline) + { $cmd =& pfcCommand::Factory("error"); $cmd->run($xml_reponse, $clientid, _pfc("Can't send the message, %s is offline", $pvnick)); $can_send = false; Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2006-05-11 16:11:14 UTC (rev 489) +++ trunk/src/containers/file.class.php 2006-05-11 16:47:54 UTC (rev 490) @@ -147,11 +147,21 @@ @unlink($nick_filename); // remove the nickname from the cache list - if (isset($this->_users[$chan]) && - in_array($nick, $this->_users[$chan])) + if (isset($this->_users[$chan])) { - $key = array_search($nick, $this->_users[$chan]); - unset($this->_users[$chan][$key]); + $uid = 0; $isonline = false; + while($uid < count($this->_users[$chan]) && !$isonline) + { + if ($this->_users[$chan][$uid]["nick"] == $nick) + $isonline = true; + else + $uid++; + } + if ($isonline) + { + $key = $uid; + unset($this->_users[$chan][$key]); + } } return true; @@ -179,10 +189,21 @@ @chmod($nick_filename, 0777); // append the nickname to the cache list - if (isset($this->_users[$chan]) && - !in_array($nick, $this->_users[$chan])) + if (isset($this->_users[$chan])) { - $this->_users[$chan][] = $nick; + $uid = 0; $isonline = false; + while($uid < count($this->_users[$chan]) && !$isonline) + { + if ($this->_users[$chan][$uid]["nick"] == $nick) + $isonline = true; + else + $uid++; + } + if (!$isonline) + { + $this->_users[$chan][] = array("nick" => $nick, + "timestamp" => filemtime($nick_filename)); + } } return $there; @@ -210,14 +231,22 @@ // update the nick cache list if($ok) { - if (isset($this->_users[$chan]) && - in_array($oldnick, $this->_users[$chan])) + if (isset($this->_users[$chan])) { - // remove the oldnick from the cache - $key = array_search($oldnick, $this->_users[$chan]); - unset($this->_users[$chan][$key]); - // append the new nick to the cache - $this->_users[$chan][] = $newnick; + $uid = 0; $isonline = false; + while($uid < count($this->_users[$chan]) && !$isonline) + { + if ($this->_users[$chan][$uid]["nick"] == $oldnick) + $isonline = true; + else + $uid++; + } + if ($isonline) + { + $key = $uid; + $this->_users[$chan][$key]["nick"] = $newnick; + $this->_users[$chan][$key]["timestamp"] = filemtime($newnick_filename); + } } } @@ -287,8 +316,9 @@ } else { - // optimisation: cache user list for next getOnlineUserList call - $users[] = $this->_decode($file); + // optimisation: cache user list for next getOnlineNick call + $users[] = array("nick" => $this->_decode($file), + "timestamp" => filemtime($nick_dir."/".$file)); } } @@ -321,7 +351,8 @@ while (false !== ($file = readdir($dir_handle))) { if ($file == "." || $file == "..") continue; // skip . and .. generic files - $users[] = $this->_decode($file); + $users[] = array("nick" => $this->_decode($file), + "timestamp" => filemtime($nick_dir."/".$file)); } // cache the user list This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |