[Phpfreechat-svn] SF.net SVN: phpfreechat: [767] trunk/src
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-09-17 20:51:45
|
Revision: 767 http://svn.sourceforge.net/phpfreechat/?rev=767&view=rev Author: kerphi Date: 2006-09-17 13:51:29 -0700 (Sun, 17 Sep 2006) Log Message: ----------- Work in progress: the disconnect by timeout process is buggy (don't checkout this revision) Modified Paths: -------------- trunk/src/commands/connect.class.php trunk/src/commands/getnewmsg.class.php trunk/src/commands/getonlinenick.class.php trunk/src/commands/join.class.php trunk/src/commands/privmsg.class.php trunk/src/commands/send.class.php trunk/src/containers/file.class.php trunk/src/pfcuserconfig.class.php Removed Paths: ------------- trunk/src/containers/memory.class.php Modified: trunk/src/commands/connect.class.php =================================================================== --- trunk/src/commands/connect.class.php 2006-09-17 09:51:46 UTC (rev 766) +++ trunk/src/commands/connect.class.php 2006-09-17 20:51:29 UTC (rev 767) @@ -30,11 +30,11 @@ $chanrecip = pfcCommand_join::GetRecipient($channame); $chanid = pfcCommand_join::GetRecipientId($channame); // reset the fromid flag - $from_id_sid = $c->prefix."from_id_".$c->getId()."_".$clientid."_".$chanid; + $from_id_sid = "pfc_from_id_".$c->getId()."_".$clientid."_".$chanid; $from_id = $container->getLastId($chanrecip)-$c->max_msg; $_SESSION[$from_id_sid] = ($from_id<0) ? 0 : $from_id; // reset the oldmsg flag - $oldmsg_sid = $c->prefix."oldmsg_".$c->getId()."_".$clientid."_".$chanid; + $oldmsg_sid = "pfc_oldmsg_".$c->getId()."_".$clientid."_".$chanid; $_SESSION[$oldmsg_sid] = true; } Modified: trunk/src/commands/getnewmsg.class.php =================================================================== --- trunk/src/commands/getnewmsg.class.php 2006-09-17 09:51:46 UTC (rev 766) +++ trunk/src/commands/getnewmsg.class.php 2006-09-17 20:51:29 UTC (rev 767) @@ -19,21 +19,21 @@ //$xml_reponse->addScript("alert('getnewmsg: sender=".addslashes($sender)." param=".addslashes($param)." recipient=".addslashes($recipient)." recipientid=".addslashes($recipientid)."');"); // check this methode is not being called - if( isset($_SESSION[$c->prefix."lock_readnewmsg_".$c->getId()."_".$clientid]) ) + if( isset($_SESSION["pfc_lock_readnewmsg_".$c->getId()."_".$clientid]) ) { // kill the lock if it has been created more than 10 seconds ago $last_10sec = time()-10; - $last_lock = $_SESSION[$c->prefix."lock_readnewmsg_".$c->getId()."_".$clientid]; - if ($last_lock < $last_10sec) $_SESSION[$c->prefix."lock_".$c->getId()."_".$clientid] = 0; - if ( $_SESSION[$c->prefix."lock_readnewmsg_".$c->getId()."_".$clientid] != 0 ) exit; + $last_lock = $_SESSION["pfc_lock_readnewmsg_".$c->getId()."_".$clientid]; + if ($last_lock < $last_10sec) $_SESSION["pfc_lock_".$c->getId()."_".$clientid] = 0; + if ( $_SESSION["pfc_lock_readnewmsg_".$c->getId()."_".$clientid] != 0 ) exit; } // create a new lock - $_SESSION[$c->prefix."lock_readnewmsg_".$c->getId()."_".$clientid] = time(); + $_SESSION["pfc_lock_readnewmsg_".$c->getId()."_".$clientid] = time(); // read the last from_id value $container =& $c->getContainerInstance(); - $from_id_sid = $c->prefix."from_id_".$c->getId()."_".$clientid."_".$recipientid; + $from_id_sid = "pfc_from_id_".$c->getId()."_".$clientid."_".$recipientid; $from_id = 0; if (isset($_SESSION[$from_id_sid])) $from_id = $_SESSION[$from_id_sid]; @@ -43,7 +43,7 @@ if ($from_id < 0) $from_id = 0; } // check if this is the first time you get messages - $oldmsg_sid = $c->prefix."oldmsg_".$c->getId()."_".$clientid."_".$recipientid; + $oldmsg_sid = "pfc_oldmsg_".$c->getId()."_".$clientid."_".$recipientid; $oldmsg = false; if (isset($_SESSION[$oldmsg_sid])) { @@ -91,7 +91,7 @@ } // remove the lock - $_SESSION[$c->prefix."lock_readnewmsg_".$c->getId()."_".$clientid] = 0; + $_SESSION["pfc_lock_readnewmsg_".$c->getId()."_".$clientid] = 0; } } Modified: trunk/src/commands/getonlinenick.class.php =================================================================== --- trunk/src/commands/getonlinenick.class.php 2006-09-17 09:51:46 UTC (rev 766) +++ trunk/src/commands/getonlinenick.class.php 2006-09-17 20:51:29 UTC (rev 767) @@ -16,7 +16,7 @@ $container =& $c->getContainerInstance(); // get the cached nickname list - $nicklist_sid = $c->prefix."nicklist_".$c->getId()."_".$clientid."_".$recipientid; + $nicklist_sid = "pfc_nicklist_".$c->getId()."_".$clientid."_".$recipientid; $oldnicklist = isset($_SESSION[$nicklist_sid]) ? $_SESSION[$nicklist_sid] : array(); // get the real nickname list Modified: trunk/src/commands/join.class.php =================================================================== --- trunk/src/commands/join.class.php 2006-09-17 09:51:46 UTC (rev 766) +++ trunk/src/commands/join.class.php 2006-09-17 20:51:29 UTC (rev 767) @@ -38,7 +38,7 @@ $u->saveInCache(); // clear the cached nicknames list for the given channel - $nicklist_sid = $c->prefix."nicklist_".$c->getId()."_".$clientid."_".$chanid; + $nicklist_sid = "pfc_nicklist_".$c->getId()."_".$clientid."_".$chanid; $_SESSION[$nicklist_sid] = NULL; } Modified: trunk/src/commands/privmsg.class.php =================================================================== --- trunk/src/commands/privmsg.class.php 2006-09-17 09:51:46 UTC (rev 766) +++ trunk/src/commands/privmsg.class.php 2006-09-17 20:51:29 UTC (rev 767) @@ -67,12 +67,12 @@ $u->saveInCache(); // clear the cached nicknames list for the given channel - $nicklist_sid = $c->prefix."nicklist_".$c->getId()."_".$clientid."_".$pvrecipientid; + $nicklist_sid = "pfc_nicklist_".$c->getId()."_".$clientid."_".$pvrecipientid; $_SESSION[$nicklist_sid] = NULL; // reset the message id indicator // i.e. be ready to re-get all last posted messages - $from_id_sid = $c->prefix."from_id_".$c->getId()."_".$clientid."_".$pvrecipientid; + $from_id_sid = "pfc_from_id_".$c->getId()."_".$clientid."_".$pvrecipientid; $from_id = $container->getLastId($pvrecipient)-$c->max_msg; $_SESSION[$from_id_sid] = ($from_id<0) ? 0 : $from_id; } Modified: trunk/src/commands/send.class.php =================================================================== --- trunk/src/commands/send.class.php 2006-09-17 09:51:46 UTC (rev 766) +++ trunk/src/commands/send.class.php 2006-09-17 20:51:29 UTC (rev 767) @@ -57,8 +57,8 @@ // check the sent text is not empty and the user has a none empty nickname $errors = array(); - if ($text == "") $errors[$c->prefix."words"] = _pfc("Text cannot be empty"); - if ($nick == "") $errors[$c->prefix."handle"] = _pfc("Please enter your nickname"); + if ($text == "") $errors["pfc_words"] = _pfc("Text cannot be empty"); + if ($nick == "") $errors["pfc_handle"] = _pfc("Please enter your nickname"); if (count($errors) > 0) { // an error occured, just ignore the message and display errors @@ -68,8 +68,8 @@ $cmdp["param"] = $errors; $cmd =& pfcCommand::Factory("error"); $cmd->run($xml_reponse, $cmdp); - if (isset($errors[$c->prefix."handle"])) // the nick is empty so give it focus - $xml_reponse->addScript("$('".$c->prefix."handle').focus();"); + if (isset($errors["pfc_handle"])) // the nick is empty so give it focus + $xml_reponse->addScript("$('pfc_handle').focus();"); $can_send = false; } @@ -92,8 +92,8 @@ // a message has been posted so : // - clear errors // - give focus to "words" field - $xml_reponse->addScript("pfc.clearError(Array('".$c->prefix."words"."','".$c->prefix."handle"."'));"); - $xml_reponse->addScript("$('".$c->prefix."words').focus();"); + $xml_reponse->addScript("pfc.clearError(Array('pfc_words"."','pfc_handle"."'));"); + $xml_reponse->addScript("$('pfc_words').focus();"); } } } Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2006-09-17 09:51:46 UTC (rev 766) +++ trunk/src/containers/file.class.php 2006-09-17 20:51:29 UTC (rev 767) @@ -90,17 +90,25 @@ */ function createNick($chan, $nick, $nickid) { + $c =& $this->c; + // store nickid -> nickname and nickname -> nickid correspondance $this->setMeta($nick, "nickname", "fromnickid", $nickid); $this->setMeta($nickid, "nickid", "fromnickname", $nick); + $this->_registerUserMeta($nickid, $chan); + + if ($c->debug) pxlog("createNick - nickname metadata created: chan=".($chan==NULL?"SERVER":$chan)." nickid=".$nickid, "chat", $c->getId()); + + /* // increment the nick references (used to know when the nick is really disconnected) $nick_ref = $this->getMeta("references", $nickid); if ($nick_ref == NULL || !is_numeric($nick_ref)) $nick_ref = 0; $nick_ref++; $this->setMeta($nick_ref, "references", $nickid); + */ - + $c =& $this->c; $nick_dir = ($chan != NULL) ? $c->container_cfg_channel_dir."/".$this->_encode($chan)."/nicknames" : @@ -119,19 +127,16 @@ // check the if the file exists only in debug mode! if ($c->debug) { + /* if (file_exists($nickid_filename)) - pxlog("createNick(".$nick.", ".$nickid.") - Error: another nickname data file exists, we are overwriting it (nickname takeover)!", "chat", $c->getId()); + pxlog("createNick(".$nick.", ".$nickid.") - Error: another nickname data file exists, we are overwriting it (nickname takeover)!: ".$nickid_filename, "chat", $c->getId()); + else + pxlog("createNick - nickname file created: chan=".($chan==NULL?"SERVER":$chan)." nickid=".$nickid, "chat", $c->getId()); + */ } // trust the caller : this nick is not used touch($nickid_filename); - /* - $fp = fopen($nickid_filename, "w"); - flock ($fp, LOCK_EX); // lock - fwrite($fp, $nickid); - flock ($fp, LOCK_UN); // unlock - fclose($fp); - */ // append the nickname to the cached nickname list $id = $this->isNickOnline($chan, $nick); @@ -141,7 +146,7 @@ $this->_users[$_chan]["nickid"][] = $nickid; $this->_users[$_chan]["timestamp"][] = filemtime($nickid_filename); } - + return true; } @@ -170,13 +175,18 @@ // check the nickname file really exists if (!file_exists($nickid_filename)) - pxlog("removeNick(".$nick.") - Error: the nickname data file to remove doesn't exists", "chat", $c->getId()); + pxlog("removeNick(".$nick.") - Error: the nickname data file to remove doesn't exists: ".$nickid_filename, "chat", $c->getId()); + else + pxlog("removeNick - nickname file removed: chan=".($chan==NULL?"SERVER":$chan)." nickid=".$nickid, "chat", $c->getId()); } $ok = @unlink($nickid_filename); // remove the user metadata if he is disconnected from the server + $this->_unregisterUserMeta($nickid, $chan); + + /* // decrement the nick references and kill the metadata if not more references is found // (used to know when the nick is really disconnected) $nick_ref = $this->getMeta("references", $nickid); @@ -190,7 +200,7 @@ } else $this->setMeta($nick_ref, "references", $nickid); - + */ if ($c->debug) { @@ -222,6 +232,9 @@ // retrive the nickid to update $nickid = $this->getNickId($nick); if ($nickid == "undefined") return false; + + // update the user metadata + $this->_registerUserMeta($nickid, $chan); $c =& $this->c; $there = false; @@ -237,6 +250,8 @@ @touch($nickid_filename); @chmod($nickid_filename, 0700); + if ($c->debug) pxlog("updateNick - nickname file updated: chan=".($chan==NULL?"SERVER":$chan)." nickid=".$nickid, "chat", $c->getId()); + // append the nickname to the cache list $_chan = ($chan == NULL) ? "SERVER" : $chan; $id = $this->isNickOnline($chan, $nick); @@ -373,6 +388,9 @@ $du_nickid = $du_nid; $du_nickname = $this->getNickname($du_nid); + $this->_unregisterUserMeta($du_nickid, $chan); + + /* // decrement the nick references and kill the metadata if not more references is found // (used to know when the nick is really disconnected) $nick_ref = $this->getMeta("references", $du_nickid); @@ -386,7 +404,7 @@ } else $this->setMeta($nick_ref, "references", $du_nickid); - + */ } } @@ -725,6 +743,52 @@ $this->_users = array("nickid" => array(), "timestamp" => array()); } + + function _registerUserMeta($nickid, $chan) + { + $c =& $this->c; + // create or update the nickname references (used to know when the nick is really disconnected) + if ($chan == NULL) $chan = "SERVER"; + $ref = $this->getMeta("references", $nickid); + if ($ref == NULL) + $ref = array(); + else + $ref = explode(';',$ref); + if ($c->debug) pxlog("registerUserMeta -> ref=".implode(';',$ref), "chat", $c->getId()); + if (in_array($chan,$ref)) + return; + else + $ref[] = $chan; + $ref = implode(';',$ref); + $this->setMeta($ref, "references", $nickid); + } + + function _unregisterUserMeta($nickid, $chan) + { + $c =& $this->c; + // decrement the nick references and kill the metadata if not more references is found + // (used to know when the nick is really disconnected) + if ($chan == NULL) $chan = "SERVER"; + $nickname = $this->getNickname($nickid); + $ref = $this->getMeta("references", $nickid); + if ($ref == NULL) $ref = ''; + $ref = explode(';',$ref); + $ref = array_diff($ref, array($chan)); + if (count($ref) == 0) + { + $this->rmMeta("nickid", "fromnickname", $nickname); + $this->rmMeta("nickname", "fromnickid", $nickid); + $this->rmMeta("references", $nickid); // destroy also the reference counter + if ($c->debug) pxlog("_unregisterUserMeta -> destroy!", "chat", $c->getId()); + } + else + { + $ref = implode(';',$ref); + $this->setMeta($ref, "references", $nickid); + if ($c->debug) pxlog("_unregisterUserMeta -> ref=".$ref, "chat", $c->getId()); + } + } + /** * Return a unique id. Each time this function is called, the last id is incremented. Deleted: trunk/src/containers/memory.class.php =================================================================== --- trunk/src/containers/memory.class.php 2006-09-17 09:51:46 UTC (rev 766) +++ trunk/src/containers/memory.class.php 2006-09-17 20:51:29 UTC (rev 767) @@ -1,344 +0,0 @@ -<?php -/** - * pfccontainer_memory.class.php - * - * Copyright \xA9 2006 Bernhard J. M. Gr\xFCn <Ber...@go...> - * - * 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__)."/../pfccontainer.class.php"; -require_once dirname(__FILE__)."/../../lib/pear/System/SharedMemory.php"; - -/** - * pfcContainer_Memory is a concrete container which stores data into - * shared memory using a PEAR class. - * Version: 2006-02-28#01 - * - * @author Bernhard J. M. Gr\xFCn <Ber...@go...> - */ -class pfcContainer_Memory extends pfcContainer -{ - var $_users = NULL; - var $_cache_nickid = array(); - var $_memory = NULL; - - function _connect() - { - $c =& $this->c; - if ($c->container_cfg_sm_type=="auto") - $this->_memory =& System_SharedMemory::factory(); - else - $this->_memory =& System_SharedMemory::factory($c->container_cfg_sm_type, $c->container_cfg_sm_options); - } - - function getDefaultConfig() - { - $c =& $this->c; - - $cfg = array(); - $cfg['sm_type'] = ""; - $cfg['sm_options'] = array(); - $cfg['sm_messages'] = ""; - $cfg['sm_message_index'] = ""; - $cfg['sm_nicknames'] = ""; - $cfg['sm_nicknames_time'] = ""; - return $cfg; - } - - function init() - { - $c =& $this->c; - if ($c->container_cfg_sm_type=="") - $c->container_cfg_sm_type = "auto"; - if ($c->container_cfg_sm_options=="" || !is_array($c->container_cfg_sm_options)) - $c->container_cfg_sm_options = array(); - if ($c->container_cfg_sm_messages=="") - $c->container_cfg_sm_messages = $c->prefix.$c->serverid.'messages'; - if ($c->container_cfg_sm_message_index=="") - $c->container_cfg_sm_message_index = $c->prefix.$c->serverid.'message_index'; - if ($c->container_cfg_sm_nicknames=="") - $c->container_cfg_sm_nicknames = $c->prefix.$c->serverid.'nicknames'; - if ($c->container_cfg_sm_nicknames_time=="") - $c->container_cfg_sm_nicknames_time = $c->prefix.$c->serverid.'nicknames_time'; - - $this->_connect(); - $messages=$this->_memory->get - ($c->container_cfg_sm_messages); - $message_index=$this->_memory->get - ($c->container_cfg_sm_message_index); - $nick_array=$this->_memory->get - ($c->container_cfg_sm_nicknames); - $nicktime_array=$this->_memory->get - ($c->container_cfg_sm_nicknames_time); - if (!isset($messages) || $messages==NULL || !is_array($messages)) - { - $this->_memory->rm($c->container_cfg_sm_messages); - $this->_memory->set - ($c->container_cfg_sm_messages, array()); - } - if (!isset($message_index) || $message_index==NULL || !is_numeric($message_index)) - $this->_memory->set - ($c->container_cfg_sm_message_index, 0); - if (!isset($nick_array) || $nick_array==NULL || !is_array($nick_array)) - { - $this->_memory->rm($c->container_cfg_sm_nicknames); - $this->_memory->set - ($c->container_cfg_sm_nicknames, array()); - } - if (!isset($nicktime_array) || $nicktime_array==NULL || !is_array($nicktime_array)) - { - $this->_memory->rm($c->container_cfg_sm_nicknames_time); - $this->_memory->set - ($c->container_cfg_sm_nicknames_time, array()); - } - return array(); - } - - function updateNick($nickname) - { - $c =& $this->c; - $this->_connect(); - $nick_array=$this->_memory->get - ($c->container_cfg_sm_nicknames_time); - $nick_array[$c->nick]=time(); - $this->_memory->set - ($c->container_cfg_sm_nicknames_time, $nick_array); - return true; - } - - /** - * returns the id identifying the nickname's owner session - */ - function getNickId($nickname) - { - if (!isset($this->_cache_nickid[$nickname])) - { - $c =& $this->c; - $nickid = "undefined"; - $this->_connect(); - $nick_array=$this->_memory->get - ($c->container_cfg_sm_nicknames); - if (isset($nick_array[$nickname])) - { - // write the nickid into the new nickname place - $nickid=$nick_array[$nickname]; - if ($nickid == "") - $nickid = "undefined"; - } - $this->_cache_nickid[$nickname] = $nickid; - } - return $this->_cache_nickid[$nickname]; - } - - /** - * create an array element containing the new nickname id - * and delete oldnickname array element if the nickname id match - */ - function changeNick($newnick) - { - $c =& $this->c; - $nickid = $c->sessionid; - $oldnickid = $this->getNickId($c->nick); - $this->_connect(); - $nick_array=$this->_memory->get - ($c->container_cfg_sm_nicknames); - $nicktime_array=$this->_memory->get - ($c->container_cfg_sm_nicknames_time); - // delete the old nickname element only if the nickid match - if ($nickid == $oldnickid) - { - unset($nick_array[$c->nick]); - unset($nicktime_array[$c->nick]); - } - // write the nickid into the new nicknames element - $nick_array[$newnick]=$nickid; - $nicktime_array[$newnick]=time(); - $this->_memory->set - ($c->container_cfg_sm_nicknames, $nick_array); - $this->_memory->set - ($c->container_cfg_sm_nicknames_time, $nicktime_array); - return $newnick; - } - - function removeNick($nick) - { - $c =& $this->c; - $this->_connect(); - $nick_array=$this->_memory->get - ($c->container_cfg_sm_nicknames); - $nicktime_array=$this->_memory->get - ($c->container_cfg_sm_nicknames_time); - $nickid = $this->getNickId($nick); - // don't allow to remove foreign nicknames - if ($c->sessionid == $nickid && isset($nick_array[$nick])) - { - unset($nick_array[$nick]); - unset($nicktime_array[$nick]); - $this->_memory->set - ($c->container_cfg_sm_nicknames, $nick_array); - $this->_memory->set - ($c->container_cfg_sm_nicknames_time, $nicktime_array); - return true; - } - else - return false; - } - - function removeObsoleteNick() - { - $c =& $this->c; - - $deleted_user = array(); - $users = array(); - $this->_connect(); - $nicktime_array=$this->_memory->get - ($c->container_cfg_sm_nicknames_time); - $nick_array=$this->_memory->get - ($c->container_cfg_sm_nicknames); - if (!isset($nicktime_array)) - return $deleted_user; - $deleted=false; - foreach ($nicktime_array as $key => $nick_time) - { - if (time() > ($nick_time+2+($c->refresh_delay/1000)*4) ) - { - $deleted_user[]=$key; - unset($nicktime_array[$key]); - unset($nick_array[$key]); - $deleted=true; - } - else - { - $users[]=$key; - } - } - $this->_users =& $users; // _users will be used by getOnlineUserList - if ($deleted) - { - $this->_memory->set - ($c->container_cfg_sm_nicknames_time, $nicktime_array); - $this->_memory->set - ($c->container_cfg_sm_nicknames, $nick_array); - } - return $deleted_user; - } - - function getOnlineNick() - { - if (is_array($this->_users) && count($this->_users)>0) - return $this->_users; - - $c =& $this->c; - $users = array(); - $this->_connect(); - $nicktime_array=$this->_memory->get - ($c->container_cfg_sm_nicknames_time); - if (!isset($nicktime_array)) - return $users; - foreach ($nicktime_array as $key => $nick_time) - { - $users[]=$key; - } - return $users; - } - - /** - * Returns the last posted message id - */ - function getLastMsgId() - { - // read last message id - $c =& $this->c; - $this->_connect(); - $msg_id=$this->_memory->get - ($c->container_cfg_sm_message_index); - return isset($msg_id) ? $msg_id : 0; - } - - function readNewMsg($from_id) - { - - $c =& $this->c; - $this->_connect(); - $content=$this->_memory->get - ($c->container_cfg_sm_messages); - - // remove old messages - $content = array_slice($content, -$c->max_msg); - $this->_memory->set - ($c->container_cfg_sm_messages, $content); - - // format content in order to extract only necessary information - $formated_content = array(); - $new_from_id = $from_id; - foreach ( $content as $line ) - { - if ($line != "" && $line != "\n") - { - $formated_line = explode( "\t", $line ); - if ($from_id < $formated_line[0]) - $formated_content[] = $formated_line; - if ($new_from_id < $formated_line[0]) - $new_from_id = $formated_line[0]; - } - } - return array("messages" => $formated_content, "new_from_id" => $new_from_id); - } - - function writeMsg($nickname, $message) - { - // format message - $msg_id = $this->_requestMsgId(); - $line = $msg_id."\t"; - $line .= date("d/m/Y")."\t"; - $line .= date("H:i:s")."\t"; - $line .= $nickname."\t"; - $line .= $message; - - // write it to message array - $c =& $this->c; - $this->_connect(); - $content=$this->_memory->get - ($c->container_cfg_sm_messages); - $count=count($content)+1; - $content[$count]=$line; - $this->_memory->set - ($c->container_cfg_sm_messages, $content); - return true; - } - - /** - * used internaly - */ - function _requestMsgId() - { - // read last message id - $c =& $this->c; - $this->_connect(); - $msg_id=$this->_memory->get - ($c->container_cfg_sm_message_index); - if (!is_numeric($msg_id)) - $msg_id = 0; - // increment message id and save it - $msg_id++; - $this->_memory->set - ($c->container_cfg_sm_message_index, $msg_id); - return $msg_id; - } -} - -?> Modified: trunk/src/pfcuserconfig.class.php =================================================================== --- trunk/src/pfcuserconfig.class.php 2006-09-17 09:51:46 UTC (rev 766) +++ trunk/src/pfcuserconfig.class.php 2006-09-17 20:51:29 UTC (rev 767) @@ -41,6 +41,17 @@ if (!isset($this->privmsg)) $this->_setParam("serverid",$c->serverid); } + function &Instance() + { + static $i; + + if (!isset($i)) + { + $i = new pfcUserConfig(); + } + return $i; + } + function &_getParam($p) { if (!isset($this->$p)) @@ -70,95 +81,7 @@ unset($this->$p); } - function &Instance() - { - static $i; - - if (!isset($i)) - { - $i = new pfcUserConfig(); - } - return $i; - } - /* - function init() - { - // echo "init()<br>"; - $ok = true; - - $c =& pfcGlobalConfig::Instance(); - if ($c) - { - $this->nick = $c->nick; - $this->timeout = $c->timeout; - } - else - { - $this->errors[] = "pfcGlobalConfig must be instanciated first"; - $ok = false; - } - - $this->is_init = $ok; - } - function isInit() - { - return $this->is_init; - } - - function &getErrors() - { - return $this->errors; - } - */ - - /* - function getCacheFile() - { - $c =& pfcGlobalConfig::Instance(); - $cachefile = ""; - if ($this->nick != "") - $cachefile = $c->data_private_path."/cache/".$c->prefix."userconfig_".$c->getId()."_".md5($this->nick); - // echo "getCacheFile() = '$cachefile'<br>"; - return $cachefile; - } - */ - /** - * save the pfcUserConfig object into cache if it doesn't exists yet - * else restore the old pfcConfig object - */ - /* - function synchronizeWithCache() - { - // echo "synchronizeWithCache()<br>"; - $c =& pfcGlobalConfig::Instance(); - $cachefile = $this->getCacheFile(); - if ($c->debug) pxlog("pfcUserConfig::synchronizeWithCache: cachefile=".$cachefile, "chatconfig", $c->getId()); - if (file_exists($cachefile)) - { - echo "synchronizeWithCache():exists<br>"; - $pfc_configvar = unserialize(file_get_contents($cachefile)); - foreach($pfc_configvar as $key => $val) - $this->$key = $val; - if ($c->debug) pxlog("pfcUserConfig::synchronizeWithCache: restore pfcUserConfig from cache", "chatconfig", $c->getId()); - } - else - { - // echo "synchronizeWithCache():!exists<br>"; - if (!$this->isInit()) - $this->init(); - $errors =& $this->getErrors(); - if (count($errors) > 0) - { - echo "<ul>"; foreach( $errors as $e ) echo "<li>".$e."</li>"; echo "</ul>"; - exit; - } - // save the validated config in cache - $this->saveInCache(); - } - } - */ - function destroy() { $this->_rmParam("nick"); @@ -181,27 +104,6 @@ $this->_setParam("channels",$this->channels); $this->_setParam("privmsg",$this->privmsg); $this->_setParam("serverid",$this->serverid); - - /* - - // save nickname and active status into sessions - $nickid = $c->prefix."pfcuserconfig_".$c->getId(); - $nickid_nick = $nickid."_nick"; - $nickid_active = $nickid."_active"; - $_SESSION[$nickid_nick] = $this->nick; - $_SESSION[$nickid_active] = $this->active; - */ - - - // @todo - // save the whole object into cache - /* - $cachefile = $this->getCacheFile(); - if ($cachefile == "") - die("Error: cachefile should not be null!"); - file_put_contents($cachefile, serialize(get_object_vars($this))); - if ($c->debug) pxlog("pfcUserConfig::saveInCache: nick=".$this->nick, "chatconfig", $c->getId()); - */ } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |