Thread: [Phpfreechat-svn] SF.net SVN: phpfreechat: [955] trunk/src (Page 4)
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2007-02-15 11:29:18
|
Revision: 955 http://svn.sourceforge.net/phpfreechat/?rev=955&view=rev Author: kerphi Date: 2007-02-15 03:29:18 -0800 (Thu, 15 Feb 2007) Log Message: ----------- Optimizations : - pfcI18N::GetAcceptedLanguage function was very slow - pfcGlobaConfig::pfcGlobalConfig has some useless code which was repeted at each call Modified Paths: -------------- trunk/src/pfcglobalconfig.class.php trunk/src/pfci18n.class.php Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-02-15 11:14:53 UTC (rev 954) +++ trunk/src/pfcglobalconfig.class.php 2007-02-15 11:29:18 UTC (rev 955) @@ -129,47 +129,43 @@ var $debugurl = ""; var $debug = false; var $debugxajax = false; - + // private parameters - var $_sys_proxies = array("lock", "checktimeout", "checknickchange", "auth", "noflood", "censor", "log"); - var $_proxies = array(); // will contains proxies to execute on each command (filled in the init step) + var $_sys_proxies = array("lock", "checktimeout", "checknickchange", "auth", "noflood", "censor", "log"); + var $_proxies = array(); // will contains proxies to execute on each command (filled in the init step) var $_dyn_params = array("nick","isadmin","islocked","admins","frozen_channels", "channels", "privmsg", "nickmeta","baseurl"); var $_params_type = array(); function pfcGlobalConfig( $params = array() ) - { - // first of all, save our current state in order to be able to check for variable types later - $this->_saveParamsTypes(); - + { // setup the local for translated messages pfcI18N::Init(isset($params["language"]) ? $params["language"] : ""); - + // check the serverid is really defined if (!isset($params["serverid"])) $this->errors[] = _pfc("'%s' parameter is mandatory by default use '%s' value", "serverid", "md5(__FILE__)"); $this->serverid = $params["serverid"]; - // _getCacheFile needs data_private_path + // setup data_private_path because _getCacheFile needs it if (!isset($params["data_private_path"])) $this->data_private_path = dirname(__FILE__)."/../data/private"; else $this->data_private_path = $params["data_private_path"]; - if (!isset($params["data_public_path"])) - $this->data_public_path = dirname(__FILE__)."/../data/public"; - else - $this->data_public_path = $params["data_public_path"]; - /* - // delete the cache if no proxy.php file is found - if (!file_exists($this->_getProxyFile())) - @unlink($this->_getCacheFile()); - */ - + // check if a cached configuration allready exists // don't load parameters if the cache exists $cachefile = $this->_getCacheFile(); if (!file_exists($cachefile)) { + // first of all, save our current state in order to be able to check for variable types later + $this->_saveParamsTypes(); + + if (!isset($params["data_public_path"])) + $this->data_public_path = dirname(__FILE__)."/../data/public"; + else + $this->data_public_path = $params["data_public_path"]; + // load users container or keep default one if (isset($params["container_type"])) $this->container_type = $params["container_type"]; @@ -212,7 +208,7 @@ // load dynamic parameter even if the config exists in the cache foreach ( $this->_dyn_params as $dp ) if (isset($params[$dp])) - $this->$dp = $params[$dp]; + $this->$dp = $params[$dp]; // 'channels' is now a dynamic parameter, just check if I need to initialize it or not if (is_array($this->channels) && @@ -498,7 +494,7 @@ // load version number from file $this->version = trim(file_get_contents(dirname(__FILE__)."/../version")); - + $this->is_init = (count($this->errors) == 0); } @@ -586,7 +582,7 @@ foreach($pfc_configvar as $key => $val) { // the dynamics parameters must not be cached - if (!in_array($key,$this->_dyn_params)) + if (!isset($this->_dyn_params[$key])) $this->$key = $val; } Modified: trunk/src/pfci18n.class.php =================================================================== --- trunk/src/pfci18n.class.php 2007-02-15 11:14:53 UTC (rev 954) +++ trunk/src/pfci18n.class.php 2007-02-15 11:29:18 UTC (rev 955) @@ -97,37 +97,7 @@ */ function GetAcceptedLanguage($type="main") { - if ($type=="admin"){ - if (isset($GLOBALS["accepted_admin_languages"])) - return $GLOBALS["accepted_admin_languages"]; // restore the cached languages list - $GLOBALS["accepted_admin_languages"] = array(); - $dir_handle = opendir(dirname(__FILE__)."/../i18n"); - while (false !== ($file = readdir($dir_handle))) - { - // skip . and .. generic files - // skip also .svn directory - if ($file == "." || $file == ".." || strpos($file,".")===0) continue; - if (file_exists(dirname(__FILE__)."/../i18n/".$file."/admin.php")) - $GLOBALS["accepted_admin_languages"][] = $file; - } - closedir($dir_handle); - return $GLOBALS["accepted_admin_languages"]; - } - else{ - if (isset($GLOBALS["accepted_languages"])) - return $GLOBALS["accepted_languages"]; // restore the cached languages list - $GLOBALS["accepted_languages"] = array(); - $dir_handle = opendir(dirname(__FILE__)."/../i18n"); - while (false !== ($file = readdir($dir_handle))) - { - // skip . and .. generic files - // skip also .svn directory - if ($file == "." || $file == ".." || strpos($file,".")===0) continue; - $GLOBALS["accepted_languages"][] = $file; - } - closedir($dir_handle); - return $GLOBALS["accepted_languages"]; - } + return /*<GetAcceptedLanguage>*/array('ar_LB','bg_BG','de_DE-formal','el_GR','eo','fr_FR','hy_AM','it_IT','ko_KR','nl_NL', 'pt_BR','ru_RU','sv_SE','uk_RO','zh_CN','ba_BA','bn_BD','de_DE-informal','en_US','es_ES','hu_HU','id_ID','ja_JP','nb_NO','pl_PL','pt_PT','sr_CS','tr_TR','uk_UA','zh_TW');/*</GetAcceptedLanguage>*/ } /** @@ -135,6 +105,24 @@ */ function UpdateMessageRessources() { + // first of all, update the GetAcceptedLanguage list + $i18n_basepath = dirname(__FILE__).'/../i18n'; + $i18n_accepted_lang = array(); + $dh = opendir($i18n_basepath); + while (false !== ($file = readdir($dh))) + { + // skip . and .. generic files, skip also .svn directory + if ($file == "." || $file == ".." || strpos($file,".")===0) continue; + if (file_exists($i18n_basepath.'/'.$file.'/main.php')) $i18n_accepted_lang[] = $file; + } + closedir($dh); + $i18n_accepted_lang_str = "array('" . implode("','", $i18n_accepted_lang) . "');"; + $data = file_get_contents(__FILE__); + $data = preg_replace("/\/\*<GetAcceptedLanguage>\*\/(.*)\/\*<\/GetAcceptedLanguage>\*\//", + "/*<GetAcceptedLanguage>*/$i18n_accepted_lang_str/*</GetAcceptedLanguage>*/", + $data); + + // Now scan the source code in order to find "_pfc" patterns $files = array(); $files = array_merge($files, glob(dirname(__FILE__)."/*.php")); $files = array_merge($files, glob(dirname(__FILE__)."/commands/*.php")); @@ -142,7 +130,6 @@ $files = array_merge($files, glob(dirname(__FILE__)."/proxies/*.php")); $files = array_merge($files, glob(dirname(__FILE__)."/client/*.php")); $files = array_merge($files, glob(dirname(__FILE__)."/../themes/default/*.php")); - $res = array(); foreach ( $files as $src_filename ) { @@ -170,7 +157,7 @@ } $dst_filenames = array(); - foreach(pfcI18N::GetAcceptedLanguage() as $lg) + foreach($i18n_accepted_lang as $lg) $dst_filenames[] = dirname(__FILE__)."/../i18n/".$lg."/main.php"; foreach( $dst_filenames as $dst_filename ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-02-15 17:38:42
|
Revision: 959 http://svn.sourceforge.net/phpfreechat/?rev=959&view=rev Author: kerphi Date: 2007-02-15 09:38:23 -0800 (Thu, 15 Feb 2007) Log Message: ----------- revert my changes about in_array replacments Modified Paths: -------------- trunk/src/pfcglobalconfig.class.php trunk/src/proxies/log.class.php Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-02-15 17:27:13 UTC (rev 958) +++ trunk/src/pfcglobalconfig.class.php 2007-02-15 17:38:23 UTC (rev 959) @@ -537,7 +537,7 @@ foreach($pfc_configvar as $key => $val) { // the dynamics parameters must not be cached - if (!isset($this->_dyn_params[$key])) + if (!in_array($key,$this->_dyn_params)) $this->$key = $val; } Modified: trunk/src/proxies/log.class.php =================================================================== --- trunk/src/proxies/log.class.php 2007-02-15 17:27:13 UTC (rev 958) +++ trunk/src/proxies/log.class.php 2007-02-15 17:38:23 UTC (rev 959) @@ -33,7 +33,7 @@ function run(&$xml_reponse, $p) { $cmdtocheck = array("send", "me", "notice"); - if ( isset($cmdtocheck[$this->name]) ) + if ( in_array($this->name, $cmdtocheck) ) { $clientid = $p["clientid"]; $param = $p["param"]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-03-08 13:59:54
|
Revision: 985 http://svn.sourceforge.net/phpfreechat/?rev=985&view=rev Author: kerphi Date: 2007-03-08 05:59:52 -0800 (Thu, 08 Mar 2007) Log Message: ----------- should fix the "You must be connected" problem Modified Paths: -------------- trunk/src/pfccontainer.class.php trunk/src/proxies/checktimeout.class.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-03-07 19:14:11 UTC (rev 984) +++ trunk/src/pfccontainer.class.php 2007-03-08 13:59:52 UTC (rev 985) @@ -147,13 +147,15 @@ function removeNick($chan, $nickid) { $c =& pfcGlobalConfig::Instance(); - + if ($chan == NULL) $chan = 'SERVER'; $deleted_user = array(); $deleted_user["nick"] = array(); $deleted_user["nickid"] = array(); $deleted_user["timestamp"] = array(); + + if (!$nickid) return $deleted_user; $timestamp = $this->getMeta("channelid-to-nickid", $this->encode('SERVER'), $nickid); if (count($timestamp["timestamp"]) == 0) return $deleted_user; @@ -162,7 +164,7 @@ $deleted_user["nick"][] = $this->getNickname($nickid); $deleted_user["nickid"][] = $nickid; $deleted_user["timestamp"][] = $timestamp; - + // remove the nickid from the channel list $this->rmMeta('channelid-to-nickid', $this->encode($chan), $nickid); $this->rmMeta('nickid-to-channelid', $nickid, $this->encode($chan)); @@ -284,7 +286,7 @@ { $timestamp = $ret['timestamp'][$i]; $nickid = $ret['value'][$i]; - if (time() > ($timestamp+$timeout/1000) ) // user will be disconnected after 'timeout' secondes of inactivity + if (time() > ($timestamp+$timeout/1000) && $nickid) // user will be disconnected after 'timeout' secondes of inactivity { // get the current user's channels list $channels = array(); @@ -733,4 +735,4 @@ } } -?> \ No newline at end of file +?> Modified: trunk/src/proxies/checktimeout.class.php =================================================================== --- trunk/src/proxies/checktimeout.class.php 2007-03-07 19:14:11 UTC (rev 984) +++ trunk/src/proxies/checktimeout.class.php 2007-03-08 13:59:52 UTC (rev 985) @@ -39,6 +39,8 @@ $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; + if ($this->name == 'update') + { $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); $ct =& pfcContainer::Instance(); @@ -50,6 +52,7 @@ $nick = $disconnected_users["nick"][$i]; for($j=0; $j<count($disconnected_users["channels"][$i]); $j++) { + file_put_contents('/tmp/disco',var_export($disconnected_users,true), FILE_APPEND); $chan = $disconnected_users["channels"][$i][$j]; $online_users = $ct->getOnlineNick($chan); if ($chan != 'SERVER' && @@ -65,10 +68,11 @@ } } } + } // 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. |
From: <ke...@us...> - 2007-03-20 19:28:14
|
Revision: 1005 http://svn.sourceforge.net/phpfreechat/?rev=1005&view=rev Author: kerphi Date: 2007-03-20 10:28:34 -0700 (Tue, 20 Mar 2007) Log Message: ----------- Work in progresse : fix the "You must be connected to send a message" [3h00] Modified Paths: -------------- trunk/src/commands/connect.class.php trunk/src/commands/nick.class.php trunk/src/commands/update.class.php trunk/src/proxies/auth.class.php trunk/src/proxies/checktimeout.class.php Modified: trunk/src/commands/connect.class.php =================================================================== --- trunk/src/commands/connect.class.php 2007-03-20 08:51:29 UTC (rev 1004) +++ trunk/src/commands/connect.class.php 2007-03-20 17:28:34 UTC (rev 1005) @@ -13,6 +13,7 @@ $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; $getoldmsg = isset($p["getoldmsg"]) ? $p["getoldmsg"] : true; + $joinoldchan = isset($p["joinoldchan"]) ? $p["joinoldchan"] : true; // nickname must be given to be able to connect to the chat $nick = $params[0]; @@ -24,43 +25,7 @@ // reset the message id indicator (see getnewmsg.class.php) // i.e. be ready to re-get all last posted messages if ($getoldmsg) - { - // reset the channel identifiers - require_once(dirname(__FILE__)."/join.class.php"); - $channels = array(); - if (count($u->channels) == 0) - $channels = $c->channels; - else - foreach($u->channels as $chan) - $channels[] = $chan["name"]; - foreach($channels as $channame) - { - $chanrecip = pfcCommand_join::GetRecipient($channame); - $chanid = pfcCommand_join::GetRecipientId($channame); - // reset the fromid flag - $from_id_sid = "pfc_from_id_".$c->getId()."_".$clientid."_".$chanid; - $from_id = $ct->getLastId($chanrecip)-$c->max_msg; - $_SESSION[$from_id_sid] = ($from_id<0) ? 0 : $from_id; - // reset the oldmsg flag - $oldmsg_sid = "pfc_oldmsg_".$c->getId()."_".$clientid."_".$chanid; - $_SESSION[$oldmsg_sid] = true; - } - // reset the private messages identifiers - if (count($u->privmsg) > 0) - { - foreach($u->privmsg as $recipientid2 => $pv) - { - $recipient2 = $pv['recipient']; - // reset the fromid flag - $from_id_sid = "pfc_from_id_".$c->getId()."_".$clientid."_".$recipientid2; - $from_id = $ct->getLastId($recipient2)-$c->max_msg; - $_SESSION[$from_id_sid] = ($from_id<0) ? 0 : $from_id; - // reset the oldmsg flag - $oldmsg_sid = "pfc_oldmsg_".$c->getId()."_".$clientid."_".$recipientid2; - $_SESSION[$oldmsg_sid] = true; - } - } - } + $this->_resetChannelIdentifier($clientid); // check if the user is alone on the server, and give it the admin status if yes $isadmin = $ct->getUserMeta($u->nickid, 'isadmin'); @@ -102,6 +67,10 @@ if ($ret) { + // @todo join the channels if $joinoldchan is true (see /update command code) + // @todo remove the /join client side in pfcclient.js.php + + $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ok', Array('".addslashes($nick)."'));"); } else @@ -109,6 +78,53 @@ $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ko', Array('".addslashes($nick)."'));"); } } + + /** + * reset the channel identifiers + */ + function _resetChannelIdentifier($clientid) + { + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); + $ct =& pfcContainer::Instance(); + + // reset the channel identifiers + require_once(dirname(__FILE__)."/join.class.php"); + $channels = array(); + if (count($u->channels) == 0) + $channels = $c->channels; + else + foreach($u->channels as $chan) + $channels[] = $chan["name"]; + foreach($channels as $channame) + { + $chanrecip = pfcCommand_join::GetRecipient($channame); + $chanid = pfcCommand_join::GetRecipientId($channame); + // reset the fromid flag + $from_id_sid = "pfc_from_id_".$c->getId()."_".$clientid."_".$chanid; + $from_id = $ct->getLastId($chanrecip)-$c->max_msg; + $_SESSION[$from_id_sid] = ($from_id<0) ? 0 : $from_id; + // reset the oldmsg flag + $oldmsg_sid = "pfc_oldmsg_".$c->getId()."_".$clientid."_".$chanid; + $_SESSION[$oldmsg_sid] = true; + } + // reset the private messages identifiers + if (count($u->privmsg) > 0) + { + foreach($u->privmsg as $recipientid2 => $pv) + { + $recipient2 = $pv['recipient']; + // reset the fromid flag + $from_id_sid = "pfc_from_id_".$c->getId()."_".$clientid."_".$recipientid2; + $from_id = $ct->getLastId($recipient2)-$c->max_msg; + $_SESSION[$from_id_sid] = ($from_id<0) ? 0 : $from_id; + // reset the oldmsg flag + $oldmsg_sid = "pfc_oldmsg_".$c->getId()."_".$clientid."_".$recipientid2; + $_SESSION[$oldmsg_sid] = true; + } + } + } + } ?> \ No newline at end of file Modified: trunk/src/commands/nick.class.php =================================================================== --- trunk/src/commands/nick.class.php 2007-03-20 08:51:29 UTC (rev 1004) +++ trunk/src/commands/nick.class.php 2007-03-20 17:28:34 UTC (rev 1005) @@ -77,7 +77,7 @@ { // this is a first connection : create the nickname on the server $ct->createNick($u->nickid, $newnick); - $u->nick = $nick; + $u->nick = $newnick; $u->saveInCache(); $this->forceWhoisReload($u->nickid); Modified: trunk/src/commands/update.class.php =================================================================== --- trunk/src/commands/update.class.php 2007-03-20 08:51:29 UTC (rev 1004) +++ trunk/src/commands/update.class.php 2007-03-20 17:28:34 UTC (rev 1005) @@ -14,21 +14,22 @@ $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); + + // check the user has not been disconnected from the server by timeout + // if he has been disconnected, then I reconnect him with /connect command + if ($u->nick != '' && !$u->isOnline()) + { + $cmd =& pfcCommand::Factory("connect"); + $cmdp = $p; + $cmdp['params'] = array($u->nick); + $cmdp['getoldmsg'] = false; + $cmdp['joinoldchan'] = false; + $cmd->run($xml_reponse, $cmdp); + } // do not update if user isn't active (didn't connect) if ($u->isOnline()) { - // check the user has not been disconnected from the server by timeout - // if I found he has been disconnected, then I reconnect him with /connect command - $ct =& pfcContainer::Instance(); - if ($ct->isNickOnline(NULL, $u->nickid) < 0) - { - $cmd =& pfcCommand::Factory("connect"); - $cmdp = $p; - $cmdp["getoldmsg"] = false; - $cmd->run($xml_reponse, $cmdp); - } - $cmdp = $p; // update the user nickname timestamp on the server @@ -72,7 +73,9 @@ $xml_reponse->script("pfc.handleResponse('update', 'ok', '');"); } else + { $xml_reponse->script("pfc.handleResponse('update', 'ko', '');"); + } } } Modified: trunk/src/proxies/auth.class.php =================================================================== --- trunk/src/proxies/auth.class.php 2007-03-20 08:51:29 UTC (rev 1004) +++ trunk/src/proxies/auth.class.php 2007-03-20 17:28:34 UTC (rev 1005) @@ -45,6 +45,7 @@ // do not allow someone to run a command if he is not online if ($this->name != 'error' && $this->name != 'connect' && + $this->name != 'update' && !$u->isOnline()) { $cmdp = $p; Modified: trunk/src/proxies/checktimeout.class.php =================================================================== --- trunk/src/proxies/checktimeout.class.php 2007-03-20 08:51:29 UTC (rev 1004) +++ trunk/src/proxies/checktimeout.class.php 2007-03-20 17:28:34 UTC (rev 1005) @@ -39,7 +39,7 @@ $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; - if ($this->name == 'update') + if ($this->name == 'update' || $this->name == 'connect') { $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); @@ -53,17 +53,19 @@ for($j=0; $j<count($disconnected_users["channels"][$i]); $j++) { $chan = $disconnected_users["channels"][$i][$j]; - $online_users = $ct->getOnlineNick($chan); - if ($chan != 'SERVER' && - count($online_users['nickid'])) + if ($chan != 'SERVER') { - $cmdp = $p; - $cmdp["param"] = _pfc("%s quit (timeout)", $nick); - $cmdp["flag"] = 2; - $cmdp["recipient"] = $chan; - $cmdp["recipientid"] = md5($chan); // @todo: clean the recipient/recipientid notion - $cmd =& pfcCommand::Factory("notice"); - $cmd->run($xml_reponse, $cmdp); + $online_users = $ct->getOnlineNick($chan); + if (count($online_users['nickid']) > 0) + { + $cmdp = $p; + $cmdp["param"] = _pfc("%s quit (timeout)", $nick); + $cmdp["flag"] = 2; + $cmdp["recipient"] = $chan; + $cmdp["recipientid"] = md5($chan); // @todo: clean the recipient/recipientid notion + $cmd =& pfcCommand::Factory("notice"); + $cmd->run($xml_reponse, $cmdp); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-03-25 17:42:32
|
Revision: 1009 http://svn.sourceforge.net/phpfreechat/?rev=1009&view=rev Author: kerphi Date: 2007-03-25 10:42:32 -0700 (Sun, 25 Mar 2007) Log Message: ----------- Bug fix: users were not considered online when they connected first time Modified Paths: -------------- trunk/src/commands/connect.class.php trunk/src/commands/invite.class.php trunk/src/commands/updatemynick.class.php trunk/src/pfccontainer.class.php trunk/src/pfcuserconfig.class.php trunk/src/proxies/auth.class.php Modified: trunk/src/commands/connect.class.php =================================================================== --- trunk/src/commands/connect.class.php 2007-03-25 16:55:12 UTC (rev 1008) +++ trunk/src/commands/connect.class.php 2007-03-25 17:42:32 UTC (rev 1009) @@ -39,16 +39,9 @@ $isadmin = true; } - // setup some user meta + // create the nickid and setup some user meta $nickid = $u->nickid; - - // create the nickid $ct->joinChan($nickid, NULL); // join the server - - // setup the active flag in user session - // $u->active = true; - // $u->saveInCache(); - // store the user ip $ip = isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"]; if ($ip == "::1") $ip = "127.0.0.1"; // fix for konqueror & localhost Modified: trunk/src/commands/invite.class.php =================================================================== --- trunk/src/commands/invite.class.php 2007-03-25 16:55:12 UTC (rev 1008) +++ trunk/src/commands/invite.class.php 2007-03-25 17:42:32 UTC (rev 1009) @@ -66,7 +66,7 @@ } // check that the inviter is already in the channeltarget - if ($ct->isNickOnline(pfcCommand_join::GetRecipient($channeltarget),$u->nickid) == -1) + if (!$ct->isNickOnline(pfcCommand_join::GetRecipient($channeltarget),$u->nickid)) { $cmdp = $p; $cmdp["params"] = array(); Modified: trunk/src/commands/updatemynick.class.php =================================================================== --- trunk/src/commands/updatemynick.class.php 2007-03-25 16:55:12 UTC (rev 1008) +++ trunk/src/commands/updatemynick.class.php 2007-03-25 17:42:32 UTC (rev 1009) @@ -14,9 +14,9 @@ $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); - - $container =& pfcContainer::Instance(); - $container->updateNick($u->nickid); + $ct =& pfcContainer::Instance(); + + $ct->updateNick($u->nickid); } } Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-03-25 16:55:12 UTC (rev 1008) +++ trunk/src/pfccontainer.class.php 2007-03-25 17:42:32 UTC (rev 1009) @@ -129,7 +129,7 @@ $this->setMeta("channelid-to-nickid", $this->encode($chan), $nickid); // update the SERVER channel - if ($chan != 'SERVER') $this->updateNick($nickid); + if ($chan == 'SERVER') $this->updateNick($nickid); return true; } @@ -348,18 +348,17 @@ /** * Returns returns a positive number if the nick is online in the given channel * @param $chan if NULL then check if the user is online on the server, otherwise check if the user has joined the channel - * @return -1 if the user is off line, a positive (>=0) if the user is online + * @return false if the user is off line, true if the user is online */ function isNickOnline($chan, $nickid) { if ($chan == NULL) $chan = 'SERVER'; - $ret = $this->getMeta("channelid-to-nickid", $this->encode($chan)); - for($i = 0; $i<count($ret['timestamp']); $i++) - { - if ($ret['value'][$i] == $nickid) return $i; - } - return -1; + $ret = $this->getMeta("channelid-to-nickid", + $this->encode($chan), + $nickid); + + return (count($ret['timestamp']) > 0); } /** Modified: trunk/src/pfcuserconfig.class.php =================================================================== --- trunk/src/pfcuserconfig.class.php 2007-03-25 16:55:12 UTC (rev 1008) +++ trunk/src/pfcuserconfig.class.php 2007-03-25 17:42:32 UTC (rev 1009) @@ -111,7 +111,7 @@ function isOnline() { $ct =& pfcContainer::Instance(); - $online = ($ct->isNickOnline(NULL, $this->nickid) >= 0); + $online = $ct->isNickOnline(NULL, $this->nickid); return $online; } Modified: trunk/src/proxies/auth.class.php =================================================================== --- trunk/src/proxies/auth.class.php 2007-03-25 16:55:12 UTC (rev 1008) +++ trunk/src/proxies/auth.class.php 2007-03-25 17:42:32 UTC (rev 1009) @@ -43,10 +43,10 @@ // do not allow someone to run a command if he is not online - if ($this->name != 'error' && - $this->name != 'connect' && - $this->name != 'update' && - !$u->isOnline()) + if ( !$u->isOnline() && + $this->name != 'error' && + $this->name != 'connect' && + $this->name != 'update' ) { $cmdp = $p; $cmdp["param"] = _pfc("Your must be connected to send a message"); @@ -113,4 +113,4 @@ } } -?> \ No newline at end of file +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-04-01 11:01:51
|
Revision: 1012 http://svn.sourceforge.net/phpfreechat/?rev=1012&view=rev Author: kerphi Date: 2007-04-01 04:01:46 -0700 (Sun, 01 Apr 2007) Log Message: ----------- [en] Bug fix: add get_ip_from_xforwardedfor parameter which can be used to get ip from HTTP_X_FORWARDED_FOR when the chat is behind a reverse proxy (thanks to datacompboy) [0h15] [fr] Bug fix : ajout du parametre get_ip_from_xforwardedfor qui peut ?\195?\170tre utilis?\195?\169 pour r?\195?\169cup?\195?\169rer l'ip des client depuis l'ent?\195?\170te http HTTP_X_FORWARDED_FOR lorsque le chat est derri?\195?\168re un reverse proxy (merci ?\195?\160 datacompboy) [0h15] Modified Paths: -------------- trunk/src/commands/connect.class.php trunk/src/pfcglobalconfig.class.php Modified: trunk/src/commands/connect.class.php =================================================================== --- trunk/src/commands/connect.class.php 2007-03-29 08:29:05 UTC (rev 1011) +++ trunk/src/commands/connect.class.php 2007-04-01 11:01:46 UTC (rev 1012) @@ -43,7 +43,9 @@ $nickid = $u->nickid; $ct->joinChan($nickid, NULL); // join the server // store the user ip - $ip = isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"]; + $ip = ( $c->get_ip_from_xforwardedfor && isset($_SERVER["HTTP_X_FORWARDED_FOR"])) ? + $_SERVER["HTTP_X_FORWARDED_FOR"] : + $_SERVER["REMOTE_ADDR"]; if ($ip == "::1") $ip = "127.0.0.1"; // fix for konqueror & localhost $ct->setUserMeta($nickid, 'ip', $ip); // store the admin flag Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-03-29 08:29:05 UTC (rev 1011) +++ trunk/src/pfcglobalconfig.class.php 2007-04-01 11:01:46 UTC (rev 1012) @@ -131,6 +131,14 @@ var $debugurl = ""; var $debug = false; var $debugxajax = false; + + /** + * This parameter is useful when your chat server is behind a reverse proxy that + * forward client ip address in HTTP_X_FORWARDED_FOR http header. + * see : http://www.phpfreechat.net/forum/viewtopic.php?id=1344 + */ + var $get_ip_from_xforwardedfor = false; + // private parameters var $_sys_proxies = array("lock", "checktimeout", "checknickchange", "auth", "noflood", "censor", "log"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-04-01 13:06:42
|
Revision: 1013 http://svn.sourceforge.net/phpfreechat/?rev=1013&view=rev Author: kerphi Date: 2007-04-01 06:06:42 -0700 (Sun, 01 Apr 2007) Log Message: ----------- [en] Bug fix: use flock() to lock the read and write access in the file container [1h10] [fr] Bug fix : utilise la fonction flock() pour les acc?\195?\168s en lecture et ?\195?\169criture du conteneur "file" [1h10] Modified Paths: -------------- trunk/src/containers/file.class.php trunk/src/pfctools.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2007-04-01 11:01:46 UTC (rev 1012) +++ trunk/src/containers/file.class.php 2007-04-01 13:06:42 UTC (rev 1013) @@ -91,7 +91,7 @@ } else { - file_put_contents($leaffilename, $leafvalue); + flock_put_contents($leaffilename, $leafvalue); } // store the value in the memory cache @@ -157,7 +157,7 @@ if (!file_exists($leaffilename)) return $ret; if ($withleafvalue) - $ret["value"][] = file_get_contents($leaffilename); + $ret["value"][] = flock_get_contents($leaffilename); else $ret["value"][] = NULL; $ret["timestamp"][] = filemtime($leaffilename); Modified: trunk/src/pfctools.php =================================================================== --- trunk/src/pfctools.php 2007-04-01 11:01:46 UTC (rev 1012) +++ trunk/src/pfctools.php 2007-04-01 13:06:42 UTC (rev 1013) @@ -403,4 +403,40 @@ } } +/** + * Almost the Same as file_get_contents except that it uses flock() to lock the file + */ +function flock_get_contents($filename, $mode = "rb") +{ + $data = ''; + if (!file_exists($filename)) return $data; + + $size = filesize($filename); + if ($size == 0) return $data; + + $fp = fopen( $filename, $mode ); + if( $fp && flock( $fp, LOCK_SH ) ) + { + $data = fread( $fp, $size ); + flock($fp, LOCK_UN); + } + fclose( $fp ); + return $data; +} + +/** + * Almost the Same as file_put_contents except that it uses flock() to lock the file + */ +function flock_put_contents($filename, $data, $mode = "wb") +{ + $fp = fopen( $filename, $mode ); + if( $fp && flock( $fp, LOCK_EX ) ) + { + fwrite( $fp, $data ); + flock($fp, LOCK_UN); + } + fclose( $fp ); +} + + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-04-18 15:25:30
|
Revision: 1020 http://svn.sourceforge.net/phpfreechat/?rev=1020&view=rev Author: kerphi Date: 2007-04-18 08:25:30 -0700 (Wed, 18 Apr 2007) Log Message: ----------- [en] Bug fix: $GLOBALS['i18n'] array could overlap with external codes, now pfc uses $GLOBALS[$serverid]['i18n'], I think it's more secure. [1h30] [fr] Bug fix : le tableau $GLOBALS['i18n'] pouvait entrer en collision avec des programmes externes, maintenant pfc utilise le tableau $GLOBALS[$serverid]['i18n'] qui permettra d'?\195?\169viter ces situations. [1h30] Modified Paths: -------------- trunk/src/pfcglobalconfig.class.php trunk/src/pfci18n.class.php trunk/src/phpfreechat.class.php Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-04-18 13:59:38 UTC (rev 1019) +++ trunk/src/pfcglobalconfig.class.php 2007-04-18 15:25:30 UTC (rev 1020) @@ -147,10 +147,12 @@ var $_query_string = ''; function pfcGlobalConfig( $params = array() ) - { - // setup the local for translated messages - pfcI18N::Init(isset($params["language"]) ? $params["language"] : ""); - + { + // @todo find a cleaner way to forward serverid to i18n functions + $GLOBALS['serverid'] = isset($params['serverid']) ? $params['serverid'] : '_serverid_'; + // setup the locales for the translated messages + pfcI18N::Init(isset($params['language']) ? $params['language'] : ''); + // check the serverid is really defined if (!isset($params["serverid"])) $this->errors[] = _pfc("'%s' parameter is mandatory by default use '%s' value", "serverid", "md5(__FILE__)"); Modified: trunk/src/pfci18n.class.php =================================================================== --- trunk/src/pfci18n.class.php 2007-04-18 13:59:38 UTC (rev 1019) +++ trunk/src/pfci18n.class.php 2007-04-18 15:25:30 UTC (rev 1020) @@ -25,10 +25,11 @@ function _pfc() { $args = func_get_args(); - $args[0] = isset($GLOBALS["i18n"][$args[0]]) && $GLOBALS["i18n"][$args[0]] != "" ? + $serverid = $GLOBALS['serverid']; // serverid is used to avoid conflicts with external code using same 'i18n' key + $args[0] = isset($GLOBALS[$serverid]["i18n"][$args[0]]) && $GLOBALS[$serverid]["i18n"][$args[0]] != "" ? ($GLOBALS["output_encoding"] == "UTF-8" ? - $GLOBALS["i18n"][$args[0]] : - iconv("UTF-8", $GLOBALS["output_encoding"], $GLOBALS["i18n"][$args[0]])) : + $GLOBALS[$serverid]["i18n"][$args[0]] : + iconv("UTF-8", $GLOBALS["output_encoding"], $GLOBALS[$serverid]["i18n"][$args[0]])) : "_".$args[0]."_"; return call_user_func_array('sprintf', $args); } @@ -39,10 +40,11 @@ function _pfc2() { $args = func_get_args(); - $args[0] = isset($GLOBALS["i18n"][$args[0]]) && $GLOBALS["i18n"][$args[0]] != "" ? + $serverid = $GLOBALS['serverid']; // serverid is used to avoid conflicts with external code using same 'i18n' key + $args[0] = isset($GLOBALS[$serverid]["i18n"][$args[0]]) && $GLOBALS[$serverid]["i18n"][$args[0]] != "" ? ($GLOBALS["output_encoding"] == "UTF-8" ? - $GLOBALS["i18n"][$args[0]] : - iconv("UTF-8", $GLOBALS["output_encoding"], $GLOBALS["i18n"][$args[0]])) : + $GLOBALS[$serverid]["i18n"][$args[0]] : + iconv("UTF-8", $GLOBALS["output_encoding"], $GLOBALS[$serverid]["i18n"][$args[0]])) : "_".$args[0]."_"; return $args[0]; } @@ -61,6 +63,10 @@ require_once(dirname(__FILE__)."/../i18n/".$language."/admin.php"); else require_once(dirname(__FILE__)."/../i18n/".$language."/main.php"); + + $serverid = $GLOBALS['serverid']; // serverid is used to avoid conflicts with external code using same 'i18n' key + $GLOBALS[$serverid]['i18n'] = $GLOBALS['i18n']; // do not pass by reference because $GLOBALS['i18n'] is maybe used by unknown external code + $GLOBALS["output_encoding"] = "UTF-8"; // by default client/server communication is utf8 encoded } Modified: trunk/src/phpfreechat.class.php =================================================================== --- trunk/src/phpfreechat.class.php 2007-04-18 13:59:38 UTC (rev 1019) +++ trunk/src/phpfreechat.class.php 2007-04-18 15:25:30 UTC (rev 1020) @@ -38,19 +38,14 @@ function phpFreeChat( &$params ) { - if (!is_object($params) && - isset($params["debug"]) && - $params["debug"]) + if (!is_array($params)) + die('phpFreeChat parameters must be an array'); + + if ( isset($params["debug"]) && $params["debug"] ) require_once dirname(__FILE__)."/../debug/log.php"; - // check if the given parameters is a simple array - // or a allready created phpfreechat object - $c = NULL; - if (is_object($params) && - get_class($params) == "pfcglobalconfig") - $c =& $params; - else - $c =& pfcGlobalConfig::Instance( $params ); + // initialize the global config object + $c =& pfcGlobalConfig::Instance( $params ); // need to initiate the user config object here because it uses sessions $u =& pfcUserConfig::Instance(); @@ -76,19 +71,11 @@ } /** - * printJavaScript must be called into html header - * usage: - * <code> - * <?php $chat->printJavascript(); ?> - * </code> + * depreciated */ function printJavaScript( $return = false ) { $output = ''; - $c =& pfcGlobalConfig::Instance(); - $u =& pfcUserConfig::Instance(); - - // display output if ($return) return $output; else @@ -96,19 +83,11 @@ } /** - * printStyle must be called in the header - * it inserts CSS in order to style the chat - * usage: - * <code> - * <?php $chat->printStyle(); ?> - * </code> + * depreciated */ function printStyle( $return = false ) { - $c =& pfcGlobalConfig::Instance(); - $output = ''; - if($return) return $output; else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-05-11 09:40:49
|
Revision: 1025 http://svn.sourceforge.net/phpfreechat/?rev=1025&view=rev Author: kerphi Date: 2007-05-11 02:40:49 -0700 (Fri, 11 May 2007) Log Message: ----------- [en] Integrate the user time zone contribution http://www.phpfreechat.net/forum/viewtopic.php?id=1508 (thanks to Peter's great work) [1h] [fr] Int?\195?\169gration de la contribution sur le param?\195?\169trage des fuseaux horaires utilisateurs http://www.phpfreechat.net/forum/viewtopic.php?id=1508 (merci ?\195?\160 Peter pour son tr?\195?\168s bon travail) [1h] Modified Paths: -------------- trunk/src/commands/getnewmsg.class.php trunk/src/pfccontainer.class.php trunk/src/pfcglobalconfig.class.php Modified: trunk/src/commands/getnewmsg.class.php =================================================================== --- trunk/src/commands/getnewmsg.class.php 2007-05-11 09:34:07 UTC (rev 1024) +++ trunk/src/commands/getnewmsg.class.php 2007-05-11 09:40:49 UTC (rev 1025) @@ -79,8 +79,8 @@ foreach ($data as $d) { $m_id = $d["id"]; - $m_date = $d["date"]; - $m_time = $d["time"]; + $m_date = gmdate($c->date_format, $d["timestamp"] + $c->time_offset); + $m_time = gmdate($c->time_format, $d["timestamp"] + $c->time_offset); $m_sender = $d["sender"]; $m_recipientid = $recipientid; $m_cmd = $d["cmd"]; @@ -92,8 +92,8 @@ $m_recipientid, $m_cmd, $m_param, - date("d/m/Y") == $m_date ? 1 : 0, - $oldmsg ? 1 : 0); + gmdate($c->date_format, time() + $c->time_offset) == $m_date ? 1 : 0, // posted today ? + $oldmsg ? 1 : 0); // is it a new message in the current session or is it a part of the history $data_sent = true; } if (count($js) != 0) Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-05-11 09:34:07 UTC (rev 1024) +++ trunk/src/pfccontainer.class.php 2007-05-11 09:40:49 UTC (rev 1025) @@ -352,6 +352,7 @@ */ function isNickOnline($chan, $nickid) { + if (!$nickid) return false; if ($chan == NULL) $chan = 'SERVER'; $ret = $this->getMeta("channelid-to-nickid", @@ -380,8 +381,7 @@ // format message $data = "\n"; $data .= $msgid."\t"; - $data .= date("d/m/Y")."\t"; - $data .= date("H:i:s")."\t"; + $data .= time()."\t"; $data .= $nick."\t"; $data .= $cmd."\t"; $data .= $param; @@ -434,12 +434,11 @@ { $formated_line = explode( "\t", $line ); $data = array(); - $data["id"] = trim($formated_line[0]); - $data["date"] = $formated_line[1]; - $data["time"] = $formated_line[2]; - $data["sender"]= $formated_line[3]; - $data["cmd"] = $formated_line[4]; - $data["param"] = $formated_line[5]; + $data["id"] = trim($formated_line[0]); + $data["timestamp"] = $formated_line[1]; + $data["sender"] = $formated_line[2]; + $data["cmd"] = $formated_line[3]; + $data["param"] = $formated_line[4]; $datalist[$data["id"]] = $data; } } Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-05-11 09:34:07 UTC (rev 1024) +++ trunk/src/pfcglobalconfig.class.php 2007-05-11 09:40:49 UTC (rev 1025) @@ -133,6 +133,20 @@ var $debugxajax = false; /** + * This is the user time zone + * it is the difference in seconds between user clock and server clock + */ + var $time_offset = 0; + /** + * How to display the dates in the chat + */ + var $date_format = "d/m/Y"; + /** + * How to display the time in the chat + */ + var $time_format = "H:i:s"; + + /** * This parameter is useful when your chat server is behind a reverse proxy that * forward client ip address in HTTP_X_FORWARDED_FOR http header. * see : http://www.phpfreechat.net/forum/viewtopic.php?id=1344 @@ -142,7 +156,7 @@ // private parameters var $_sys_proxies = array("lock", "checktimeout", "checknickchange", "auth", "noflood", "censor", "log"); - var $_dyn_params = array("nick","isadmin","islocked","admins","frozen_channels", "channels", "privmsg", "nickmeta","baseurl"); + var $_dyn_params = array("nick","isadmin","islocked","admins","frozen_channels", "channels", "privmsg", "nickmeta","baseurl","time_offset","date_format","time_format"); var $_params_type = array(); var $_query_string = ''; @@ -266,7 +280,7 @@ if (is_string($v)) $this->_params_type["string"][] = $k; else if (is_bool($v)) $this->_params_type["bool"][] = $k; else if (is_array($v)) $this->_params_type["array"][] = $k; - else if (is_int($v) && $v>=0) $this->_params_type["positivenumeric"][] = $k; + else if (is_int($v) && $v>0) $this->_params_type["positivenumeric"][] = $k; else $this->_params_type["misc"][] = $k; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-07-01 10:00:24
|
Revision: 1048 http://svn.sourceforge.net/phpfreechat/?rev=1048&view=rev Author: kerphi Date: 2007-07-01 03:00:25 -0700 (Sun, 01 Jul 2007) Log Message: ----------- Bug fix : the theme was broken (sourceforge bug 1745898) Modified Paths: -------------- trunk/src/pfcglobalconfig.class.php trunk/src/phpfreechat.class.php Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-07-01 09:55:19 UTC (rev 1047) +++ trunk/src/pfcglobalconfig.class.php 2007-07-01 10:00:25 UTC (rev 1048) @@ -421,6 +421,12 @@ $this->server_script_url = relativePath($this->client_script_path, $this->server_script_path).'/'.basename($filetotest).$this->_query_string; } + // check if the theme_path parameter are correctly setup + if ($this->theme_default_path == '' || !is_dir($this->theme_default_path)) + $this->theme_default_path = dirname(__FILE__).'/../themes'; + if ($this->theme_path == '' || !is_dir($this->theme_path)) + $this->theme_path = $this->theme_default_path; + // If the user didn't give any theme_default_url value, // copy the default theme resources in a public directory if ($this->theme_default_url == '') @@ -437,19 +443,25 @@ dirname(__FILE__).'/../themes/default', $this->data_public_path.'/themes/default'); } + $this->theme_default_url = $this->data_public_url.'/themes'; } - - // check if the theme_path parameter are correctly setup - if ($this->theme_default_path == '' || !is_dir($this->theme_default_path)) - $this->theme_default_path = dirname(__FILE__).'/../themes'; - if ($this->theme_path == '' || !is_dir($this->theme_path)) - $this->theme_path = $this->theme_default_path; - // calculate theme url - if ($this->theme_default_url == '') - $this->theme_default_url = $this->data_public_url.'/themes'; if ($this->theme_url == '') + { + mkdir_r($this->data_public_path.'/themes/'.$this->theme); + if (!is_dir($this->data_public_path.'/themes/'.$this->theme)) + $this->errors[] = _pfc("cannot create %s", $this->data_public_path.'/themes/'.$this->theme); + else + { + $ret = copy_r( $this->theme_path.'/'.$this->theme, + $this->data_public_path.'/themes/'.$this->theme ); + if (!$ret) + $this->errors[] = _pfc("cannot copy %s in %s", + $this->theme_path.'/'.$this->theme, + $this->data_public_path.'/themes/'.$this->theme); + } $this->theme_url = $this->theme_default_url; - + } + // if the user do not have an existing prototype.js library, we use the embeded one if ($this->prototypejs_url == '') $this->prototypejs_url = $this->data_public_url.'/js/prototype.js'; @@ -526,12 +538,13 @@ $result = array(); foreach($theme as $line) { + $line = trim($line); if (preg_match("/^#.*/",$line)) continue; - else if (preg_match("/^([a-z_\-0-9]*(\.gif|\.png))(.*)$/i",$line,$res)) + else if (preg_match("/([a-z_\-0-9\.]+)(.*)$/i",$line,$res)) { $smiley_file = 'smileys/'.$res[1]; - $smiley_str = trim($res[3])."\n"; + $smiley_str = trim($res[2])."\n"; $smiley_str = str_replace("\n", "", $smiley_str); $smiley_str = str_replace("\t", " ", $smiley_str); $smiley_str_tab = explode(" ", $smiley_str); Modified: trunk/src/phpfreechat.class.php =================================================================== --- trunk/src/phpfreechat.class.php 2007-07-01 09:55:19 UTC (rev 1047) +++ trunk/src/phpfreechat.class.php 2007-07-01 10:00:25 UTC (rev 1048) @@ -349,7 +349,11 @@ if ($xml_reponse == null) $xml_reponse =& new pfcResponse(); $c =& pfcGlobalConfig::Instance(); - $c->theme = $theme; + + // do not overload the theme parameter as long as + // the ajax request do not give the correct one + // $c->theme = $theme; + $u =& pfcUserConfig::Instance(); $js = '';//file_get_contents(dirname(__FILE__).'/client/createstylerule.js'); @@ -396,7 +400,7 @@ if ($xml_reponse == null) $xml_reponse =& new pfcResponse(); $c =& pfcGlobalConfig::Instance(); - + $js = ''; // load customize.js.php @@ -524,7 +528,11 @@ if ($xml_reponse == null) $xml_reponse =& new pfcResponse(); $c =& pfcGlobalConfig::Instance(); - $c->theme = $theme; + + // do not overload the theme parameter as long as + // the ajax request do not give the correct one + // $c->theme = $theme; + $u =& pfcUserConfig::Instance(); $html = ''; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-07-23 10:21:36
|
Revision: 1056 http://svn.sourceforge.net/phpfreechat/?rev=1056&view=rev Author: kerphi Date: 2007-07-23 03:21:38 -0700 (Mon, 23 Jul 2007) Log Message: ----------- Make possible to free the global config when using the pfcInfo API Modified Paths: -------------- trunk/src/pfcglobalconfig.class.php trunk/src/pfcinfo.class.php Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-07-20 18:40:26 UTC (rev 1055) +++ trunk/src/pfcglobalconfig.class.php 2007-07-23 10:21:38 UTC (rev 1056) @@ -275,14 +275,16 @@ $this->nick = $this->filterNickname($this->nick); } - function &Instance( $params = array() ) + function &Instance( $params = array(), $destroy_instance = false ) { static $i; - if (!isset($i)) - $i = new pfcGlobalConfig( $params ); + if ($destroy_instance) + $i = NULL; + else + if (!isset($i)) + $i = new pfcGlobalConfig( $params ); return $i; } - /** * This function saves all the parameters types in order to check later if the types are ok Modified: trunk/src/pfcinfo.class.php =================================================================== --- trunk/src/pfcinfo.class.php 2007-07-20 18:40:26 UTC (rev 1055) +++ trunk/src/pfcinfo.class.php 2007-07-23 10:21:38 UTC (rev 1056) @@ -28,6 +28,12 @@ $this->c =& pfcGlobalConfig::Instance($params); } + function free() + { + // free the pfcglobalconfig instance + pfcGlobalConfig::Instance(array(), true); + } + /** * @return array(string) a list of errors */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-07-30 14:43:38
|
Revision: 1063 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1063&view=rev Author: kerphi Date: 2007-07-30 07:43:40 -0700 (Mon, 30 Jul 2007) Log Message: ----------- Add the 'sender', 'recipient' and 'recipientid' parameters in the cmdtoplay commands Modified Paths: -------------- trunk/src/pfccommand.class.php trunk/src/phpfreechat.class.php Modified: trunk/src/pfccommand.class.php =================================================================== --- trunk/src/pfccommand.class.php 2007-07-30 13:16:33 UTC (rev 1062) +++ trunk/src/pfccommand.class.php 2007-07-30 14:43:40 UTC (rev 1063) @@ -194,7 +194,7 @@ return false; } - function RunPendingCmdToPlay($nickid,$clientid,&$xml_reponse) + function RunPendingCmdToPlay($nickid,$context,&$xml_reponse) { $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); @@ -217,10 +217,10 @@ $cmd =& pfcCommand::Factory($cmdtmp['cmdstr']); $cmdp = $cmdtmp['params']; if (!isset($cmdp['param'])) $cmdp['param'] = ''; - if (!isset($cmdp['sender'])) $cmdp['sender'] = null; - if (!isset($cmdp['recipient'])) $cmdp['recipient'] = null; - if (!isset($cmdp['recipientid'])) $cmdp['recipientid'] = null; - $cmdp['clientid'] = $clientid; // the clientid must be the current user one + if (!isset($cmdp['sender'])) $cmdp['sender'] = $context['sender']; + if (!isset($cmdp['recipient'])) $cmdp['recipient'] = $context['recipient']; + if (!isset($cmdp['recipientid'])) $cmdp['recipientid'] = $context['recipientid']; + $cmdp['clientid'] = $context['clientid']; // the clientid must be the current user one $cmdp['cmdtoplay'] = true; // used to run some specials actions in the command (ex: if the cmdtoplay is a 'leave' command, then show an alert to the kicked or banished user) if ($c->debug) $cmd->run($xml_reponse, $cmdp); Modified: trunk/src/phpfreechat.class.php =================================================================== --- trunk/src/phpfreechat.class.php 2007-07-30 13:16:33 UTC (rev 1062) +++ trunk/src/phpfreechat.class.php 2007-07-30 14:43:40 UTC (rev 1063) @@ -271,18 +271,19 @@ } + + $cmdp = array(); + $cmdp["clientid"] = $clientid; + $cmdp["sender"] = $sender; + $cmdp["recipient"] = $recipient; + $cmdp["recipientid"] = $recipientid; // before playing the wanted command // play the found commands into the meta 'cmdtoplay' - pfcCommand::RunPendingCmdToPlay($u->nickid, $clientid, $xml_reponse); - + pfcCommand::RunPendingCmdToPlay($u->nickid, $cmdp, $xml_reponse); + // play the wanted command $cmd =& pfcCommand::Factory($cmdname); - $cmdp = array(); - $cmdp["clientid"] = $clientid; $cmdp["param"] = $param; $cmdp["params"] = $params; - $cmdp["sender"] = $sender; - $cmdp["recipient"] = $recipient; - $cmdp["recipientid"] = $recipientid; if ($cmd != NULL) { // call the command This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-07-31 20:02:52
|
Revision: 1064 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1064&view=rev Author: gpinzone Date: 2007-07-31 13:02:55 -0700 (Tue, 31 Jul 2007) Log Message: ----------- Eliminated flock_get_contents and flock_put_contents. Created patched version of file_get_contents that include file locking: file_get_contents_flock. Modified setMeta and getMeta to use file_get_contents_flock and file_put_contents. Rewrote setMeta's null $leafvalue handling to use file_put_contents. Modified Paths: -------------- trunk/src/containers/file.class.php trunk/src/pfctools.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2007-07-30 14:43:40 UTC (rev 1063) +++ trunk/src/containers/file.class.php 2007-07-31 20:02:55 UTC (rev 1064) @@ -85,13 +85,11 @@ $leafexists = file_exists($leaffilename); if ($leafvalue == NULL) { - if (file_exists($leaffilename) && - filesize($leaffilename)>0) unlink($leaffilename); - touch($leaffilename); + file_put_contents($leaffilename, '', LOCK_EX); } else { - flock_put_contents($leaffilename, $leafvalue); + file_put_contents($leaffilename, $leafvalue, LOCK_EX); } // store the value in the memory cache @@ -157,7 +155,7 @@ if (!file_exists($leaffilename)) return $ret; if ($withleafvalue) - $ret["value"][] = flock_get_contents($leaffilename); + $ret["value"][] = file_get_contents_flock($leaffilename); else $ret["value"][] = NULL; $ret["timestamp"][] = filemtime($leaffilename); Modified: trunk/src/pfctools.php =================================================================== --- trunk/src/pfctools.php 2007-07-30 14:43:40 UTC (rev 1063) +++ trunk/src/pfctools.php 2007-07-31 20:02:55 UTC (rev 1064) @@ -255,8 +255,42 @@ return $errors; } +/** + * file_get_contents_flock + * define an alternative file_get_contents when this function doesn't exists on the used php version (<4.3.0) + */ +if (!defined('LOCK_SH')) { + define('LOCK_SH', 1); +} +function file_get_contents_flock($filename, $incpath = false, $resource_context = null) +{ + if (false === $fh = fopen($filename, 'rb', $incpath)) { + user_error('file_get_contents() failed to open stream: No such file or directory ['.$filename.']', + E_USER_WARNING); + return false; + } + + // Attempt to get a shared (read) lock + if (!flock($fh, LOCK_SH)) { + return false; + } + + clearstatcache(); + if ($fsize = @filesize($filename)) { + $data = fread($fh, $fsize); + } else { + $data = ''; + while (!feof($fh)) { + $data .= fread($fh, 8192); + } + } + + fclose($fh); + return $data; +} + /** * file_get_contents * define an alternative file_get_contents when this function doesn't exists on the used php version (<4.3.0) @@ -267,7 +301,7 @@ { if (false === $fh = fopen($filename, 'rb', $incpath)) { - trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING); + trigger_error('file_get_contents() failed to open stream: No such file or directory ['.$filename.']', E_USER_WARNING); return false; } clearstatcache(); @@ -403,40 +437,4 @@ } } -/** - * Almost the Same as file_get_contents except that it uses flock() to lock the file - */ -function flock_get_contents($filename, $mode = "rb") -{ - $data = ''; - $fp = fopen( $filename, $mode ); - if( $fp && flock( $fp, LOCK_SH ) ) - { - clearstatcache(); - $size = filesize($filename); - if ($size > 0) - $data = fread( $fp, $size ); - // flock($fp, LOCK_UN); // will be done by fclose - } - fclose( $fp ); - return $data; -} - -/** - * Almost the Same as file_put_contents except that it uses flock() to lock the file - */ -function flock_put_contents($filename, $data, $mode = "wb") -{ - $fp = fopen( $filename, $mode ); - if( $fp ) - { - if ( flock( $fp, LOCK_EX ) ) - { - fwrite( $fp, $data ); - // flock($fp, LOCK_UN); // will be done by fclose - } - fclose( $fp ); - } -} - -?> +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-02 16:28:35
|
Revision: 1075 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1075&view=rev Author: gpinzone Date: 2007-08-02 09:27:50 -0700 (Thu, 02 Aug 2007) Log Message: ----------- Updated debug logging to honor file locking on appends. Modified Paths: -------------- trunk/src/containers/file.class.php trunk/src/containers/mysql.class.php trunk/src/proxies/log.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2007-08-01 20:14:09 UTC (rev 1074) +++ trunk/src/containers/file.class.php 2007-08-02 16:27:50 UTC (rev 1075) @@ -73,7 +73,7 @@ $c =& pfcGlobalConfig::Instance(); if ($c->debug) - file_put_contents("/tmp/debug", "\nsetMeta(".$group.",".$subgroup.",".$leaf.",".$leafvalue.")", FILE_APPEND); + file_put_contents("/tmp/debug", "\nsetMeta(".$group.",".$subgroup.",".$leaf.",".$leafvalue.")", FILE_APPEND | LOCK_EX); // create directories $dir_base = $c->container_cfg_server_dir; @@ -107,7 +107,7 @@ { $c =& pfcGlobalConfig::Instance(); if ($c->debug) - file_put_contents("/tmp/debug", "\ngetMeta(".$group.",".$subgroup.",".$leaf.",".$withleafvalue.")", FILE_APPEND); + file_put_contents("/tmp/debug", "\ngetMeta(".$group.",".$subgroup.",".$leaf.",".$withleafvalue.")", FILE_APPEND | LOCK_EX); // read data from metadata file $ret = array(); @@ -167,7 +167,7 @@ { $c =& pfcGlobalConfig::Instance(); if ($c->debug) - file_put_contents("/tmp/debug", "\nrmMeta(".$group.",".$subgroup.",".$leaf.")", FILE_APPEND); + file_put_contents("/tmp/debug", "\nrmMeta(".$group.",".$subgroup.",".$leaf.")", FILE_APPEND | LOCK_EX); $dir = $c->container_cfg_server_dir; Modified: trunk/src/containers/mysql.class.php =================================================================== --- trunk/src/containers/mysql.class.php 2007-08-01 20:14:09 UTC (rev 1074) +++ trunk/src/containers/mysql.class.php 2007-08-02 16:27:50 UTC (rev 1075) @@ -158,7 +158,7 @@ $c =& pfcGlobalConfig::Instance(); if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nsetMeta(".$group.",".$subgroup.",".$leaf.",".$leafvalue.")", FILE_APPEND); + file_put_contents("/tmp/debug.txt", "\nsetMeta(".$group.",".$subgroup.",".$leaf.",".$leafvalue.")", FILE_APPEND | LOCK_EX); $server = $c->serverid; $db = $this->_connect(); @@ -173,7 +173,7 @@ if( !(mysql_num_rows($res)>0) ) { if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_insert.")", FILE_APPEND); + file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_insert.")", FILE_APPEND | LOCK_EX); mysql_query($sql_insert, $db); return 0; // value created @@ -183,7 +183,7 @@ if ($sql_update != "") { if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_update.")", FILE_APPEND); + file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_update.")", FILE_APPEND | LOCK_EX); mysql_query($sql_update, $db); } @@ -197,7 +197,7 @@ $c =& pfcGlobalConfig::Instance(); if ($c->debug) - file_put_contents("/tmp/debug.txt", "\ngetMeta(".$group.",".$subgroup.",".$leaf.",".$withleafvalue.")", FILE_APPEND); + file_put_contents("/tmp/debug.txt", "\ngetMeta(".$group.",".$subgroup.",".$leaf.",".$withleafvalue.")", FILE_APPEND | LOCK_EX); $ret = array(); $ret["timestamp"] = array(); @@ -234,7 +234,7 @@ $sql_select="SELECT `$value`, `timestamp` FROM ".$c->container_cfg_mysql_table." WHERE `server`='$server' $sql_where $sql_group_by ORDER BY timestamp"; if ($c->debug) - file_put_contents("/tmp/debug.txt", "\ngetSQL(".$sql_select.")", FILE_APPEND); + file_put_contents("/tmp/debug.txt", "\ngetSQL(".$sql_select.")", FILE_APPEND | LOCK_EX); if ($sql_select != "") { @@ -266,7 +266,7 @@ { $c =& pfcGlobalConfig::Instance(); if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nrmMeta(".$group.",".$subgroup.",".$leaf.")", FILE_APPEND); + file_put_contents("/tmp/debug.txt", "\nrmMeta(".$group.",".$subgroup.",".$leaf.")", FILE_APPEND | LOCK_EX); $server = $c->serverid; $db = $this->_connect(); @@ -283,7 +283,7 @@ $sql_delete .= " AND `leaf`='$leaf'"; if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nrmSQL(".$sql_delete.")", FILE_APPEND); + file_put_contents("/tmp/debug.txt", "\nrmSQL(".$sql_delete.")", FILE_APPEND | LOCK_EX); mysql_query($sql_delete, $db); return true; Modified: trunk/src/proxies/log.class.php =================================================================== --- trunk/src/proxies/log.class.php 2007-08-01 20:14:09 UTC (rev 1074) +++ trunk/src/proxies/log.class.php 2007-08-02 16:27:50 UTC (rev 1075) @@ -59,7 +59,7 @@ $log .= date("H:i:s")."\t"; $log .= $sender."\t"; $log .= $param."\n"; - file_put_contents($logfile, $log, FILE_APPEND); + file_put_contents($logfile, $log, FILE_APPEND | LOCK_EX); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-06 13:47:12
|
Revision: 1086 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1086&view=rev Author: gpinzone Date: 2007-08-06 06:47:13 -0700 (Mon, 06 Aug 2007) Log Message: ----------- Introduction of incMeta function to resolve issue of data corruption. The mysql changes need to be tested. Modified Paths: -------------- trunk/src/containers/file.class.php trunk/src/containers/mysql.class.php trunk/src/pfccontainer.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2007-08-06 13:12:26 UTC (rev 1085) +++ trunk/src/containers/file.class.php 2007-08-06 13:47:13 UTC (rev 1086) @@ -102,7 +102,6 @@ return 0; // value created } - function getMeta($group, $subgroup = null, $leaf = null, $withleafvalue = false) { $c =& pfcGlobalConfig::Instance(); @@ -161,6 +160,63 @@ $ret["timestamp"][] = filemtime($leaffilename); return $ret; + } + + function incMeta($group, $subgroup, $leaf) + { + $c =& pfcGlobalConfig::Instance(); + if ($c->debug) + file_put_contents("/tmp/debug", "\nincMeta(".$group.",".$subgroup.",".$leaf.")", FILE_APPEND | LOCK_EX); + + // create directories + $dir_base = $c->container_cfg_server_dir; + $dir = $dir_base.'/'.$group.'/'.$subgroup; + + if (!is_dir($dir)) mkdir_r($dir); + + // create or replace metadata file + $leaffilename = $dir."/".$leaf; + + // create return array + $ret = array(); + $ret["timestamp"] = array(); + $ret["value"] = array(); + + // read and increment data from metadata file + clearstatcache(); + if (file_exists($leaffilename)) + { + $fh = fopen($leaffilename, 'r+'); + for($i = 0; $i < 10; $i++) // Try 10 times until an exclusive lock can be obtained + { + if (flock($fh, LOCK_EX)) + { + $leafvalue = chop(fread($fh, filesize($leaffilename))); + $leafvalue++; + rewind($fh); + fwrite($fh, $leafvalue); + fflush($fh); + ftruncate($fh, ftell($fh)); + flock($fh, LOCK_UN); + break; + } + // If flock is working properly, this will never be reached + $delay = rand(0, pow(2, ($i+1)) - 1) * 5000; // Exponential backoff + echo "try=".$i." ".$delay."\n"; + usleep($delay); + } + fclose($fh); + } + else + { + $leafvalue="1"; + file_put_contents($leaffilename, $leafvalue, LOCK_EX); + } + + $ret["value"][] = $leafvalue; + $ret["timestamp"][] = filemtime($leaffilename); + + return $ret; } function rmMeta($group, $subgroup = null, $leaf = null) Modified: trunk/src/containers/mysql.class.php =================================================================== --- trunk/src/containers/mysql.class.php 2007-08-06 13:12:26 UTC (rev 1085) +++ trunk/src/containers/mysql.class.php 2007-08-06 13:47:13 UTC (rev 1086) @@ -263,6 +263,82 @@ return $ret; } + + function incMeta($group, $subgroup, $leaf) + { + $c =& pfcGlobalConfig::Instance(); + + if ($c->debug) + file_put_contents("/tmp/debug.txt", "\ngetMeta(".$group.",".$subgroup.",".$leaf.")", FILE_APPEND | LOCK_EX); + + $ret = array(); + $ret["timestamp"] = array(); + $ret["value"] = array(); + + $server = $c->serverid; + $db = $this->_connect(); + + $sql_where .= " AND `leaf`='$leaf'"; + $value = "leafvalue"; + $sql_group_by = ""; + + $sql_select="SELECT `$value`, `timestamp` FROM ".$c->container_cfg_mysql_table." WHERE `server`='$server' $sql_where $sql_group_by ORDER BY timestamp FOR UPDATE"; + + if ($c->debug) + file_put_contents("/tmp/debug.txt", "\ngetSQL(".$sql_select.")", FILE_APPEND | LOCK_EX); + + if ($sql_select != "") + { + $thisresult = mysql_query($sql_select, $db); + if (mysql_num_rows($thisresult)) + { + while ($regel = mysql_fetch_array($thisresult)) + { + $ret["timestamp"][] = $regel["timestamp"]; + $ret["value"][] = $regel[$value]; + } + } + } + + $leafvalue = $ret["value"][]; + + if ($leafvalue == NULL) + $leafvalue = 0; + else + $leafvalue++; + + $timestamp = time(); + + $sql_count = "SELECT COUNT(*) AS C FROM ".$c->container_cfg_mysql_table." WHERE `server`='$server' AND `group`='$group' AND `subgroup`='$subgroup' AND `leaf`='$leaf' LIMIT 1"; + $sql_insert="REPLACE INTO ".$c->container_cfg_mysql_table." (`server`, `group`, `subgroup`, `leaf`, `leafvalue`, `timestamp`) VALUES('$server', '$group', '$subgroup', '$leaf', '".addslashes($leafvalue)."', '".$timestamp."')"; + $sql_update="UPDATE ".$c->container_cfg_mysql_table." SET `leafvalue`='".addslashes($leafvalue)."', `timestamp`='".$timestamp."' WHERE `server`='$server' AND `group`='$group' AND `subgroup`='$subgroup' AND `leaf`='$leaf'"; + + $res = mysql_query($sql_count, $db); + $row = mysql_fetch_array($res, MYSQL_ASSOC); + if( $row['C'] == 0 ) + { + if ($c->debug) + file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_insert.")", FILE_APPEND | LOCK_EX); + + mysql_query($sql_insert, $db); + } + else + { + if ($sql_update != "") + { + if ($c->debug) + file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_update.")", FILE_APPEND | LOCK_EX); + + mysql_query($sql_update, $db); + } + } + $ret["value"][] = $leafvalue; + $ret["timestamp"][] = $timestamp; + + return $ret; + } + + function rmMeta($group, $subgroup = null, $leaf = null) { $c =& pfcGlobalConfig::Instance(); Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-08-06 13:12:26 UTC (rev 1085) +++ trunk/src/pfccontainer.class.php 2007-08-06 13:47:13 UTC (rev 1086) @@ -476,10 +476,12 @@ { if ($chan == NULL) $chan = 'SERVER'; - $lastmsgid = $this->getLastId($chan); - $lastmsgid++; - $this->setMeta("channelid-to-msgid", $this->encode($chan), 'lastmsgid', $lastmsgid); + $lastmsgid = $this->incMeta("channelid-to-msgid", $this->encode($chan), 'lastmsgid'); + if (count($lastmsgid["value"]) == 0) + $lastmsgid = 0; + else + $lastmsgid = $lastmsgid["value"][0]; return $lastmsgid; } @@ -665,8 +667,34 @@ return $ret; } - + + function incMeta($group, $subgroup, $leaf) + { + $ret = $this->_container->incMeta($group, $subgroup, $leaf); + + if ($this->_usememorycache) + { + // store the modifications in the cache + if (isset($this->_cache[$group]['value']) && + !in_array($subgroup, $this->_cache[$group]['value'])) + { + $this->_cache[$group]['value'][] = $subgroup; + $this->_cache[$group]['timestamp'][] = time(); + } + if (isset($this->_cache[$group]['childs'][$subgroup]['value']) && + !in_array($leaf, $this->_cache[$group]['childs'][$subgroup]['value'])) + { + $this->_cache[$group]['childs'][$subgroup]['value'][] = $leaf; + $this->_cache[$group]['childs'][$subgroup]['timestamp'][] = time(); + } + $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value'] = array($leafvalue); + $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['timestamp'] = array(time()); + } + + return $ret; + } + /** * Remove a meta data or a group of metadata * @param $group if null then it will remove all the possible groups (all the created metadata) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-08-06 14:44:56
|
Revision: 1087 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1087&view=rev Author: kerphi Date: 2007-08-06 07:44:57 -0700 (Mon, 06 Aug 2007) Log Message: ----------- Now msgid are requested in an atomic process. It prevents corruption problems with multithreaded access. (thanks to Gerard Pinzone) Modified Paths: -------------- trunk/src/containers/file.class.php trunk/src/containers/mysql.class.php trunk/src/pfccontainer.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2007-08-06 13:47:13 UTC (rev 1086) +++ trunk/src/containers/file.class.php 2007-08-06 14:44:57 UTC (rev 1087) @@ -171,7 +171,6 @@ // create directories $dir_base = $c->container_cfg_server_dir; $dir = $dir_base.'/'.$group.'/'.$subgroup; - if (!is_dir($dir)) mkdir_r($dir); // create or replace metadata file @@ -202,22 +201,21 @@ } // If flock is working properly, this will never be reached $delay = rand(0, pow(2, ($i+1)) - 1) * 5000; // Exponential backoff - echo "try=".$i." ".$delay."\n"; - usleep($delay); + usleep($delay); } fclose($fh); } else { $leafvalue="1"; - file_put_contents($leaffilename, $leafvalue, LOCK_EX); + file_put_contents($leaffilename, $leafvalue, LOCK_EX); } $ret["value"][] = $leafvalue; $ret["timestamp"][] = filemtime($leaffilename); return $ret; - } + } function rmMeta($group, $subgroup = null, $leaf = null) { @@ -283,4 +281,4 @@ } -?> \ No newline at end of file +?> Modified: trunk/src/containers/mysql.class.php =================================================================== --- trunk/src/containers/mysql.class.php 2007-08-06 13:47:13 UTC (rev 1086) +++ trunk/src/containers/mysql.class.php 2007-08-06 14:44:57 UTC (rev 1087) @@ -267,75 +267,41 @@ function incMeta($group, $subgroup, $leaf) { $c =& pfcGlobalConfig::Instance(); - + if ($c->debug) - file_put_contents("/tmp/debug.txt", "\ngetMeta(".$group.",".$subgroup.",".$leaf.")", FILE_APPEND | LOCK_EX); + file_put_contents("/tmp/debug.txt", "\nsetMeta(".$group.",".$subgroup.",".$leaf.",".$leafvalue.")", FILE_APPEND | LOCK_EX); - $ret = array(); - $ret["timestamp"] = array(); - $ret["value"] = array(); - $server = $c->serverid; $db = $this->_connect(); - - $sql_where .= " AND `leaf`='$leaf'"; - $value = "leafvalue"; - $sql_group_by = ""; - - $sql_select="SELECT `$value`, `timestamp` FROM ".$c->container_cfg_mysql_table." WHERE `server`='$server' $sql_where $sql_group_by ORDER BY timestamp FOR UPDATE"; + $time = time(); - if ($c->debug) - file_put_contents("/tmp/debug.txt", "\ngetSQL(".$sql_select.")", FILE_APPEND | LOCK_EX); - - if ($sql_select != "") - { - $thisresult = mysql_query($sql_select, $db); - if (mysql_num_rows($thisresult)) - { - while ($regel = mysql_fetch_array($thisresult)) - { - $ret["timestamp"][] = $regel["timestamp"]; - $ret["value"][] = $regel[$value]; - } - } - } - - $leafvalue = $ret["value"][]; - - if ($leafvalue == NULL) - $leafvalue = 0; - else - $leafvalue++; - - $timestamp = time(); - - $sql_count = "SELECT COUNT(*) AS C FROM ".$c->container_cfg_mysql_table." WHERE `server`='$server' AND `group`='$group' AND `subgroup`='$subgroup' AND `leaf`='$leaf' LIMIT 1"; - $sql_insert="REPLACE INTO ".$c->container_cfg_mysql_table." (`server`, `group`, `subgroup`, `leaf`, `leafvalue`, `timestamp`) VALUES('$server', '$group', '$subgroup', '$leaf', '".addslashes($leafvalue)."', '".$timestamp."')"; - $sql_update="UPDATE ".$c->container_cfg_mysql_table." SET `leafvalue`='".addslashes($leafvalue)."', `timestamp`='".$timestamp."' WHERE `server`='$server' AND `group`='$group' AND `subgroup`='$subgroup' AND `leaf`='$leaf'"; - - $res = mysql_query($sql_count, $db); + // search for the existing leafvalue + mysql_query('LOCK TABLES phpfreechat WRITE;', $db); + $sql_select = "SELECT leafvalue FROM ".$c->container_cfg_mysql_table." WHERE `server`='$server' AND `group`='$group' AND `subgroup`='$subgroup' AND `leaf`='$leaf' LIMIT 1"; + $res = mysql_query($sql_select, $db); $row = mysql_fetch_array($res, MYSQL_ASSOC); - if( $row['C'] == 0 ) + if( !isset($row['leafvalue']) ) { if ($c->debug) file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_insert.")", FILE_APPEND | LOCK_EX); - + $leafvalue = 1; + $sql_insert="REPLACE INTO ".$c->container_cfg_mysql_table." (`server`, `group`, `subgroup`, `leaf`, `leafvalue`, `timestamp`) VALUES('$server', '$group', '$subgroup', '$leaf', '".$leafvalue."', '".$time."')"; mysql_query($sql_insert, $db); } else { - if ($sql_update != "") - { - if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_update.")", FILE_APPEND | LOCK_EX); - - mysql_query($sql_update, $db); - } + if ($c->debug) + file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_update.")", FILE_APPEND | LOCK_EX); + $leafvalue = $row['leafvalue'] + 1; + $sql_update="UPDATE ".$c->container_cfg_mysql_table." SET `leafvalue`='".$leafvalue."', `timestamp`='".$time."' WHERE `server`='$server' AND `group`='$group' AND `subgroup`='$subgroup' AND `leaf`='$leaf'"; + mysql_query($sql_update, $db); } - $ret["value"][] = $leafvalue; - $ret["timestamp"][] = $timestamp; - - return $ret; + mysql_query('UNLOCK TABLES;', $db); + + $ret["value"][] = $leafvalue; + $ret["timestamp"][] = $time; + + return $ret; } @@ -378,4 +344,4 @@ } -?> \ No newline at end of file +?> Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-08-06 13:47:13 UTC (rev 1086) +++ trunk/src/pfccontainer.class.php 2007-08-06 14:44:57 UTC (rev 1087) @@ -696,6 +696,40 @@ } /** + * Increment a counter identified by the following path : group / subgroup / leaf + * Notice: this step must be atomic in order to avoid multithread problem (don't forget to use locking features) + * @param $group is mandatory + * @param $subgroup is mandatory + * @param $leaf is mandatory, it's the counter name + * @return array which contains two subarray 'timestamp' and 'value' (value contains the incremented numeric value) + */ + function incMeta($group, $subgroup, $leaf) + { + $ret = $this->_container->incMeta($group, $subgroup, $leaf); + + if ($this->_usememorycache) + { + // store the modifications in the cache + if (isset($this->_cache[$group]['value']) && + !in_array($subgroup, $this->_cache[$group]['value'])) + { + $this->_cache[$group]['value'][] = $subgroup; + $this->_cache[$group]['timestamp'][] = time(); + } + if (isset($this->_cache[$group]['childs'][$subgroup]['value']) && + !in_array($leaf, $this->_cache[$group]['childs'][$subgroup]['value'])) + { + $this->_cache[$group]['childs'][$subgroup]['value'][] = $leaf; + $this->_cache[$group]['childs'][$subgroup]['timestamp'][] = time(); + } + $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['value'] = $ret['value']; + $this->_cache[$group]['childs'][$subgroup]['childs'][$leaf]['timestamp'] = array(time()); + } + + return $ret; + } + + /** * Remove a meta data or a group of metadata * @param $group if null then it will remove all the possible groups (all the created metadata) * @param $subgroup if null then it will remove the $group's childs (all the subgroup contained by $group) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-08 02:11:54
|
Revision: 1097 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1097&view=rev Author: gpinzone Date: 2007-08-07 19:11:56 -0700 (Tue, 07 Aug 2007) Log Message: ----------- Rewrite of "command to play" stack. Uses similar algorithm as messages. Modified Paths: -------------- trunk/src/pfccommand.class.php trunk/src/pfccontainer.class.php Modified: trunk/src/pfccommand.class.php =================================================================== --- trunk/src/pfccommand.class.php 2007-08-07 07:47:36 UTC (rev 1096) +++ trunk/src/pfccommand.class.php 2007-08-08 02:11:56 UTC (rev 1097) @@ -173,49 +173,68 @@ } } + /** + * Add command to be played onto command stack + * @param $nickid is the user that entered the command + * @param $cmdstr is the command + * @param $cmdp is the command's parameters + * @return false if $nickid is blank, true for all other values of $nickid + */ function AppendCmdToPlay($nickid, $cmdstr, $cmdp) { $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); $ct =& pfcContainer::Instance(); - if ($nickid != "") - { - $cmdtoplay = $ct->getUserMeta($nickid, 'cmdtoplay'); - $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - $cmdtmp = array(); - $cmdtmp['cmdstr'] = $cmdstr; - $cmdtmp['params'] = $cmdp; - $cmdtoplay[] = $cmdtmp; - $ct->setUserMeta($nickid, 'cmdtoplay', serialize($cmdtoplay)); - return true; - } + + // check for empty nickid + if ($nickid == "") return false; + + // get new command id + $cmdtoplay_id = $ct->incMeta("nickid-to-cmdtoplayid", $nickid, 'cmdtoplayid'); + if (count($cmdtoplay_id["value"]) == 0) + $cmdtoplay_id = 0; else - return false; + $cmdtoplay_id = $cmdtoplay_id["value"][0]; + + // create command array + $cmdtoplay = array(); + $cmdtoplay['cmdstr'] = $cmdstr; + $cmdtoplay['params'] = $cmdp; + + // store command to play + $ct->setCmdMeta($nickid, $cmdtoplay_id, serialize($cmdtoplay)); + + return true; } - function RunPendingCmdToPlay($nickid,$context,&$xml_reponse) + + /** + * Run all commands to be played for a user + * @param $nickid is the user that entered the command + * @param $context + * @param $xml_reponse + */ + function RunPendingCmdToPlay($nickid, $context, &$xml_reponse) { $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); $ct =& pfcContainer::Instance(); - $morecmd = true; - while($morecmd) + // Get all queued commands to be played + $cmdtoplay_ids = $ct->getCmdMeta($nickid); + + // process each command and parse content + foreach ( $cmdtoplay_ids as $cid ) { // take a command from the list - $cmdtoplay = $ct->getUserMeta($nickid, 'cmdtoplay'); + $cmdtoplay = $ct->getCmdMeta($nickid, $cid); $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - if (count($cmdtoplay) == 0) { $morecmd = false; break; } - // take the last posted command - $cmdtmp = array_pop($cmdtoplay); - // store the new cmdtoplay list (-1 item) - $ct->setUserMeta($nickid, 'cmdtoplay', serialize($cmdtoplay)); // play the command - // print_r($cmdtmp); - $cmd =& pfcCommand::Factory($cmdtmp['cmdstr']); - $cmdp = $cmdtmp['params']; + // print_r($cmdtoplay); + $cmd =& pfcCommand::Factory($cmdtoplay['cmdstr']); + $cmdp = $cmdtoplay['params']; if (!isset($cmdp['param'])) $cmdp['param'] = ''; if (!isset($cmdp['sender'])) $cmdp['sender'] = $context['sender']; if (!isset($cmdp['recipient'])) $cmdp['recipient'] = $context['recipient']; @@ -226,6 +245,9 @@ $cmd->run($xml_reponse, $cmdp); else @$cmd->run($xml_reponse, $cmdp); + + // delete command when complete + $ct->rmMeta("nickid-to-cmdtoplay", $nickid, $cid); } } Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-08-07 07:47:36 UTC (rev 1096) +++ trunk/src/pfccontainer.class.php 2007-08-08 02:11:56 UTC (rev 1097) @@ -517,6 +517,18 @@ return $ret; } + function getCmdMeta($nickid, $key = NULL) + { + $ret = $this->getMeta("nickid-to-cmdtoplay", $nickid, $key, true); + return isset($ret['value'][0]) ? $ret['value'][0] : NULL; + } + + function setCmdMeta($nickid, $key, $value) + { + $ret = $this->setMeta("nickid-to-cmdtoplay", $nickid, $key, $value); + return $ret; + } + function getAllChanMeta($chan) { $result = array(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-08-08 07:28:27
|
Revision: 1100 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1100&view=rev Author: kerphi Date: 2007-08-08 00:17:57 -0700 (Wed, 08 Aug 2007) Log Message: ----------- Fix the new cmdtoplay queue Modified Paths: -------------- trunk/src/pfccommand.class.php trunk/src/pfccontainer.class.php Modified: trunk/src/pfccommand.class.php =================================================================== --- trunk/src/pfccommand.class.php 2007-08-08 07:08:23 UTC (rev 1099) +++ trunk/src/pfccommand.class.php 2007-08-08 07:17:57 UTC (rev 1100) @@ -223,16 +223,14 @@ // Get all queued commands to be played $cmdtoplay_ids = $ct->getCmdMeta($nickid); - // process each command and parse content foreach ( $cmdtoplay_ids as $cid ) { // take a command from the list $cmdtoplay = $ct->getCmdMeta($nickid, $cid); - $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - + $cmdtoplay = ($cmdtoplay == NULL || count($cmdtoplay) == 0) ? array() : unserialize($cmdtoplay[0]); + // play the command - // print_r($cmdtoplay); $cmd =& pfcCommand::Factory($cmdtoplay['cmdstr']); $cmdp = $cmdtoplay['params']; if (!isset($cmdp['param'])) $cmdp['param'] = ''; Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-08-08 07:08:23 UTC (rev 1099) +++ trunk/src/pfccontainer.class.php 2007-08-08 07:17:57 UTC (rev 1100) @@ -523,7 +523,7 @@ function getCmdMeta($nickid, $key = NULL) { $ret = $this->getMeta("nickid-to-cmdtoplay", $nickid, $key, true); - return isset($ret['value'][0]) ? $ret['value'][0] : NULL; + return $ret['value']; } function setCmdMeta($nickid, $key, $value) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-20 19:36:11
|
Revision: 1134 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1134&view=rev Author: gpinzone Date: 2007-08-20 12:36:14 -0700 (Mon, 20 Aug 2007) Log Message: ----------- Needed to change function name to resolve conflict with phpBB. Modified Paths: -------------- trunk/src/pfccontainer.class.php trunk/src/urlprocessing.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-08-20 17:41:46 UTC (rev 1133) +++ trunk/src/pfccontainer.class.php 2007-08-20 19:36:14 UTC (rev 1134) @@ -383,7 +383,7 @@ $msgid = $this->_requestMsgId($chan); // convert URLs to html - $param = make_clickable($param); + $param = make_hyperlink($param); // format message $data = "\n"; Modified: trunk/src/urlprocessing.php =================================================================== --- trunk/src/urlprocessing.php 2007-08-20 17:41:46 UTC (rev 1133) +++ trunk/src/urlprocessing.php 2007-08-20 19:36:14 UTC (rev 1134) @@ -13,7 +13,7 @@ * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe * have it require something like xxxx@yyyy.zzzz or such. We'll see. */ -function make_clickable($text) +function make_hyperlink($text) { $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); @@ -50,7 +50,7 @@ * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs. * */ -function undo_make_clickable($text) +function undo_make_hyperlink($text) { $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text); $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-08-22 06:38:31
|
Revision: 1140 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1140&view=rev Author: kerphi Date: 2007-08-21 23:38:33 -0700 (Tue, 21 Aug 2007) Log Message: ----------- To avoid functions name conflicts : prefix the function and file name with "pfc" or "pfc_" So that you can be almost sure that the functions pfc uses will not interact with other users libraries. Modified Paths: -------------- trunk/src/pfccontainer.class.php Added Paths: ----------- trunk/src/pfcurlprocessing.php Removed Paths: ------------- trunk/src/urlprocessing.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-08-21 16:59:45 UTC (rev 1139) +++ trunk/src/pfccontainer.class.php 2007-08-22 06:38:33 UTC (rev 1140) @@ -21,7 +21,7 @@ */ require_once dirname(__FILE__)."/pfccontainerinterface.class.php"; - require_once dirname(__FILE__)."/urlprocessing.php"; + require_once dirname(__FILE__)."/pfcurlprocessing.php"; /** * pfcContainer is an abstract class which define interface @@ -383,7 +383,7 @@ $msgid = $this->_requestMsgId($chan); // convert URLs to html - $param = make_hyperlink($param); + $param = pfc_make_hyperlink($param); // format message $data = "\n"; Copied: trunk/src/pfcurlprocessing.php (from rev 1139, trunk/src/urlprocessing.php) =================================================================== --- trunk/src/pfcurlprocessing.php (rev 0) +++ trunk/src/pfcurlprocessing.php 2007-08-22 06:38:33 UTC (rev 1140) @@ -0,0 +1,70 @@ +<?php + +/** + * Rewritten by Nathan Codding - Feb 6, 2001. + * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking + * to that URL + * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking + * to http://www.xxxx.yyyy[/zzzz] + * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking + * to that email address + * - Only matches these 2 patterns either after a space, or at the beginning of a line + * + * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe + * have it require something like xxxx@yyyy.zzzz or such. We'll see. + */ +function pfc_make_hyperlink($text) +{ + $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); + + // pad it with a space so we can match things at the start of the 1st line. + $ret = ' ' . $text; + + // matches an "xxxx://yyyy" URL at the start of a line, or after a space. + // xxxx can only be alpha characters. + // yyyy is anything up to the first space, newline, comma, double quote or < + //$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret); + $ret = preg_replace("#(^|[\n \]])([\w]+?://[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"\\2\" target=\"_blank\">' . pfc_shorten_url('\\2') . '</a>'", $ret); + + // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing + // Must contain at least 2 dots. xxxx contains either alphanum, or "-" + // zzzz is optional.. will contain everything up to the first space, newline, + // comma, double quote or <. + //$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); + $ret = preg_replace("#(^|[\n \]])((www|ftp)\.[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"http://\\2\" target=\"_blank\">' . pfc_shorten_url('\\2') . '</a>'", $ret); + + // matches an email@domain type address at the start of a line, or after a space. + // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". + //$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); + $ret = preg_replace("#(^|[\n \]])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#ie", "'\\1<a href=\"mailto:\\2@\\3\">' . pfc_shorten_url('\\2@\\3') . '</a>'", $ret); + + // Remove our padding.. + $ret = substr($ret, 1); + + return($ret); +} + +/** + * Nathan Codding - Feb 6, 2001 + * Reverses the effects of make_clickable(), for use in editpost. + * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs. + * + */ +function pfc_undo_make_hyperlink($text) +{ + $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text); + $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text); + + return $text; + +} + +function pfc_shorten_url($url) +{ + $len = strlen($url); + $short_url = ($len > 40) ? substr($url, 0, 30) . "..." . substr($url, -7) : $url; + + return $short_url; +} + +?> Deleted: trunk/src/urlprocessing.php =================================================================== --- trunk/src/urlprocessing.php 2007-08-21 16:59:45 UTC (rev 1139) +++ trunk/src/urlprocessing.php 2007-08-22 06:38:33 UTC (rev 1140) @@ -1,70 +0,0 @@ -<?php - -/** - * Rewritten by Nathan Codding - Feb 6, 2001. - * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking - * to that URL - * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking - * to http://www.xxxx.yyyy[/zzzz] - * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking - * to that email address - * - Only matches these 2 patterns either after a space, or at the beginning of a line - * - * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe - * have it require something like xxxx@yyyy.zzzz or such. We'll see. - */ -function make_hyperlink($text) -{ - $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); - - // pad it with a space so we can match things at the start of the 1st line. - $ret = ' ' . $text; - - // matches an "xxxx://yyyy" URL at the start of a line, or after a space. - // xxxx can only be alpha characters. - // yyyy is anything up to the first space, newline, comma, double quote or < - //$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret); - $ret = preg_replace("#(^|[\n \]])([\w]+?://[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"\\2\" target=\"_blank\">' . shorten_url('\\2') . '</a>'", $ret); - - // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing - // Must contain at least 2 dots. xxxx contains either alphanum, or "-" - // zzzz is optional.. will contain everything up to the first space, newline, - // comma, double quote or <. - //$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); - $ret = preg_replace("#(^|[\n \]])((www|ftp)\.[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"http://\\2\" target=\"_blank\">' . shorten_url('\\2') . '</a>'", $ret); - - // matches an email@domain type address at the start of a line, or after a space. - // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". - //$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); - $ret = preg_replace("#(^|[\n \]])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#ie", "'\\1<a href=\"mailto:\\2@\\3\">' . shorten_url('\\2@\\3') . '</a>'", $ret); - - // Remove our padding.. - $ret = substr($ret, 1); - - return($ret); -} - -/** - * Nathan Codding - Feb 6, 2001 - * Reverses the effects of make_clickable(), for use in editpost. - * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs. - * - */ -function undo_make_hyperlink($text) -{ - $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text); - $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text); - - return $text; - -} - -function shorten_url($url) -{ - $len = strlen($url); - $short_url = ($len > 40) ? substr($url, 0, 30) . "..." . substr($url, -7) : $url; - - return $short_url; -} - -?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-23 21:02:54
|
Revision: 1142 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1142&view=rev Author: gpinzone Date: 2007-08-23 14:02:56 -0700 (Thu, 23 Aug 2007) Log Message: ----------- Fixed issue with shortening URL when escaped HTML characters were being split improperly. Modified Paths: -------------- trunk/src/pfctools.php trunk/src/pfcurlprocessing.php Modified: trunk/src/pfctools.php =================================================================== --- trunk/src/pfctools.php 2007-08-23 19:40:15 UTC (rev 1141) +++ trunk/src/pfctools.php 2007-08-23 21:02:56 UTC (rev 1142) @@ -437,4 +437,22 @@ } } +/** + * html_entity_decode + * For users prior to PHP 4.3.0 + */ +if (!function_exists('html_entity_decode')) +{ + function html_entity_decode($string) + { + // replace numeric entities + $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string); + $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string); + // replace literal entities + $trans_tbl = get_html_translation_table(HTML_ENTITIES); + $trans_tbl = array_flip($trans_tbl); + return strtr($string, $trans_tbl); + } +} + ?> \ No newline at end of file Modified: trunk/src/pfcurlprocessing.php =================================================================== --- trunk/src/pfcurlprocessing.php 2007-08-23 19:40:15 UTC (rev 1141) +++ trunk/src/pfcurlprocessing.php 2007-08-23 21:02:56 UTC (rev 1142) @@ -61,10 +61,12 @@ function pfc_shorten_url($url) { - $len = strlen($url); - $short_url = ($len > 40) ? substr($url, 0, 30) . "..." . substr($url, -7) : $url; + $decodedurl = html_entity_decode($url, ENT_QUOTES); - return $short_url; + $len = strlen($decodedurl); + $short_url = ($len > 40) ? substr($decodedurl, 0, 30) . "..." . substr($decodedurl, -7) : $decodedurl; + + return htmlentities($short_url, ENT_QUOTES); } ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-24 15:25:12
|
Revision: 1145 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1145&view=rev Author: gpinzone Date: 2007-08-24 08:13:24 -0700 (Fri, 24 Aug 2007) Log Message: ----------- Added two new parameters to the globalconfigclass: $short_url and $short_url_width. Rewrote short URL algorithm to use these values and to deal with ridiculously small widths. Moved URL proceesing to read instead of write. Fixed issue with honoring target global setting from the last commit. Modified Paths: -------------- trunk/src/pfccontainer.class.php trunk/src/pfcglobalconfig.class.php trunk/src/pfcurlprocessing.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-08-24 02:39:27 UTC (rev 1144) +++ trunk/src/pfccontainer.class.php 2007-08-24 15:13:24 UTC (rev 1145) @@ -382,9 +382,6 @@ $msgid = $this->_requestMsgId($chan); - // convert URLs to html - $param = pfc_make_hyperlink($param); - // format message $data = "\n"; $data .= $msgid."\t"; @@ -445,7 +442,8 @@ $data["timestamp"] = $formated_line[1]; $data["sender"] = $formated_line[2]; $data["cmd"] = $formated_line[3]; - $data["param"] = $formated_line[4]; + // convert URLs to html + $data["param"] = pfc_make_hyperlink($formated_line[4]); $datalist[$data["id"]] = $data; } } Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-08-24 02:39:27 UTC (rev 1144) +++ trunk/src/pfcglobalconfig.class.php 2007-08-24 15:13:24 UTC (rev 1145) @@ -100,6 +100,8 @@ var $startwithsound = true; // start with sound enabled var $openlinknewwindow = true; // used to open the links in a new window var $notify_window = true; // true : appends a prefix to the window title with the number of new posted messages + var $short_url = true; // true : shortens long urls entered by users in the chat area + var $short_url_width = 40; // final width of the shortened url /** * Be sure that you are conform to the license page before setting this to false ! Modified: trunk/src/pfcurlprocessing.php =================================================================== --- trunk/src/pfcurlprocessing.php 2007-08-24 02:39:27 UTC (rev 1144) +++ trunk/src/pfcurlprocessing.php 2007-08-24 15:13:24 UTC (rev 1145) @@ -1,13 +1,15 @@ <?php +require_once dirname(__FILE__).'/pfcglobalconfig.class.php'; + /** * Rewritten by Nathan Codding - Feb 6, 2001. * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking - * to that URL + * to that URL * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking - * to http://www.xxxx.yyyy[/zzzz] + * to http://www.xxxx.yyyy[/zzzz] * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking - * to that email address + * to that email address * - Only matches these 2 patterns either after a space, or at the beginning of a line * * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe @@ -15,38 +17,41 @@ */ function pfc_make_hyperlink($text) { + $c =& pfcGlobalConfig::Instance(); + $openlinknewwindow = $c->openlinknewwindow; + if ($openlinknewwindow) $target = " onclick=\"window.open(this.href,\\'_blank\\');return false;\""; else - $target = ''; + $target = ""; $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); - // pad it with a space so we can match things at the start of the 1st line. - $ret = ' ' . $text; + // pad it with a space so we can match things at the start of the 1st line. + $ret = ' ' . $text; - // matches an "xxxx://yyyy" URL at the start of a line, or after a space. - // xxxx can only be alpha characters. - // yyyy is anything up to the first space, newline, comma, double quote or < - //$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret); - $ret = preg_replace("#(^|[\n \]])([\w]+?://[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"\\2\"" . $target . ">' . pfc_shorten_url('\\2') . '</a>'", $ret); + // matches an "xxxx://yyyy" URL at the start of a line, or after a space. + // xxxx can only be alpha characters. + // yyyy is anything up to the first space, newline, comma, double quote or < + //$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret); + $ret = preg_replace("#(^|[\n \]])([\w]+?://[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"\\2\"" . $target . ">' . pfc_shorten_url('\\2') . '</a>'", $ret); - // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing - // Must contain at least 2 dots. xxxx contains either alphanum, or "-" - // zzzz is optional.. will contain everything up to the first space, newline, - // comma, double quote or <. - //$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); - $ret = preg_replace("#(^|[\n \]])((www|ftp)\.[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"http://\\2\"" . $target . ">' . pfc_shorten_url('\\2') . '</a>'", $ret); + // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing + // Must contain at least 2 dots. xxxx contains either alphanum, or "-" + // zzzz is optional.. will contain everything up to the first space, newline, + // comma, double quote or <. + //$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); + $ret = preg_replace("#(^|[\n \]])((www|ftp)\.[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"http://\\2\"" . $target . ">' . pfc_shorten_url('\\2') . '</a>'", $ret); - // matches an email@domain type address at the start of a line, or after a space. - // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". - //$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); - $ret = preg_replace("#(^|[\n \]])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#ie", "'\\1<a href=\"mailto:\\2@\\3\">' . pfc_shorten_url('\\2@\\3') . '</a>'", $ret); + // matches an email@domain type address at the start of a line, or after a space. + // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". + //$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); + $ret = preg_replace("#(^|[\n \]])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#ie", "'\\1<a href=\"mailto:\\2@\\3\">' . pfc_shorten_url('\\2@\\3') . '</a>'", $ret); - // Remove our padding.. - $ret = substr($ret, 1); + // Remove our padding.. + $ret = substr($ret, 1); - return($ret); + return($ret); } /** @@ -57,19 +62,32 @@ */ function pfc_undo_make_hyperlink($text) { - $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text); - $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text); + $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text); + $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text); - return $text; + return $text; } function pfc_shorten_url($url) { + $c =& pfcGlobalConfig::Instance(); + + if (! $c->short_url) + return $url; + + // Short URL Width + $shurl_w = $c->short_url_width; + + $shurl_end_w = floor($shurl_w * .25) - 3; + if ($shurl_end_w < 3) $shurl_end_w = 3; + $shurl_begin_w = $shurl_w - $shurl_end_w - 3; + if ($shurl_begin_w < 3) $shurl_begin_w = 3; + $decodedurl = html_entity_decode($url, ENT_QUOTES); $len = strlen($decodedurl); - $short_url = ($len > 40) ? substr($decodedurl, 0, 30) . "..." . substr($decodedurl, -7) : $decodedurl; + $short_url = ($len > $shurl_w) ? substr($decodedurl, 0, $shurl_begin_w) . "..." . substr($decodedurl, -$shurl_end_w) : $decodedurl; return htmlentities($short_url, ENT_QUOTES); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-08-29 12:22:46
|
Revision: 1155 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1155&view=rev Author: kerphi Date: 2007-08-29 05:22:44 -0700 (Wed, 29 Aug 2007) Log Message: ----------- Rename functions to prevent naming conflicts Modified Paths: -------------- trunk/src/pfcglobalconfig.class.php trunk/src/pfctools.php Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-08-29 12:18:19 UTC (rev 1154) +++ trunk/src/pfcglobalconfig.class.php 2007-08-29 12:22:44 UTC (rev 1155) @@ -488,8 +488,6 @@ { $ok = true; - if ($this->debug) pxlog("pfcGlobalConfig::init()", "chatconfig", $this->getId()); - // check the parameters types $array_params = $this->_params_type["array"]; foreach( $array_params as $ap ) @@ -564,9 +562,8 @@ // test client script // try to find the path into server configuration if ($this->client_script_path == '') - $this->client_script_path = getScriptFilename(); + $this->client_script_path = pfc_GetScriptFilename(); - if ($this->server_script_url == '' && $this->server_script_path == '') { $filetotest = $this->client_script_path; @@ -578,12 +575,9 @@ $this->server_script_url = './'.basename($filetotest).$this->_query_string; } - //if ($this->client_script_url == "") - // $this->client_script_url = "./".basename($filetotest); - // calculate datapublic url if ($this->data_public_url == "") - $this->data_public_url = relativePath($this->client_script_path, $this->data_public_path); + $this->data_public_url = pfc_RelativePath($this->client_script_path, $this->data_public_path); if ($this->server_script_path == '') $this->server_script_path = $this->client_script_path; @@ -598,7 +592,7 @@ $filetotest = $res[1]; if ( !file_exists($filetotest) ) $this->errors[] = _pfc("%s doesn't exist", $filetotest); - $this->server_script_url = relativePath($this->client_script_path, $this->server_script_path).'/'.basename($filetotest).$this->_query_string; + $this->server_script_url = pfc_RelativePath($this->client_script_path, $this->server_script_path).'/'.basename($filetotest).$this->_query_string; } // check if the theme_path parameter are correctly setup @@ -648,14 +642,11 @@ // --- // run specific container initialisation $ct =& pfcContainer::Instance(); - /* $container_classname = "pfcContainer_".$this->container_type; - require_once dirname(__FILE__)."/containers/".strtolower($this->container_type).".class.php"; - $container = new $container_classname($this);*/ $ct_errors = $ct->init($this); $this->errors = array_merge($this->errors, $ct_errors); // load debug url - $this->debugurl = relativePath($this->client_script_path, dirname(__FILE__)."/../debug"); + $this->debugurl = pfc_RelativePath($this->client_script_path, dirname(__FILE__)."/../debug"); // check the language is known $lg_list = pfcI18N::GetAcceptedLanguage(); @@ -740,15 +731,6 @@ return $this->serverid; } - /* - function _getProxyFile($serverid = "", $data_public_path = "") - { - if ($serverid == "") $serverid = $this->getId(); - if ($data_public_path == "") $data_public_path = $this->data_public_path; - return $data_public_path."/".$serverid."/proxy.php"; - } - */ - function _GetCacheFile($serverid = "", $data_private_path = "") { if ($serverid == '') $serverid = $this->getId(); @@ -838,7 +820,6 @@ $data .= '?>'; file_put_contents($cachefile, $data/*serialize(get_object_vars($this))*/); - if ($this->debug) pxlog("pfcGlobalConfig::saveInCache()", "chatconfig", $this->getId()); } function isDefaultFile($file) @@ -848,19 +829,6 @@ return ($this->theme == "default" ? $fexists1 : !$fexists2); } - /* - function getFileUrlByProxy($file, $addprefix = true) - { - if (file_exists($this->theme_path."/".$this->theme."/".$file)) - return ($addprefix ? $this->data_public_url."/".$this->getId()."/proxy.php" : "")."?p=".$this->theme."/".$file; - else - if (file_exists($this->theme_default_path."/default/".$file)) - return ($addprefix ? $this->data_public_url."/".$this->getId()."/proxy.php" : "")."?p=default/".$file; - else - die(_pfc("Error: '%s' could not be found, please check your theme_path '%s' and your theme '%s' are correct", $file, $this->theme_path, $this->theme)); - } - */ - function getFilePathFromTheme($file) { if (file_exists($this->theme_path."/".$this->theme."/".$file)) @@ -896,4 +864,4 @@ } } -?> \ No newline at end of file +?> Modified: trunk/src/pfctools.php =================================================================== --- trunk/src/pfctools.php 2007-08-29 12:18:19 UTC (rev 1154) +++ trunk/src/pfctools.php 2007-08-29 12:22:44 UTC (rev 1155) @@ -36,25 +36,49 @@ * Returns the absolute script filename * takes care of php cgi configuration which do not support SCRIPT_FILENAME variable. */ -function getScriptFilename() +function pfc_GetScriptFilename() { - $sf = isset($_SERVER["PATH_TRANSLATED"]) ? $_SERVER["PATH_TRANSLATED"] : ""; // check for a cgi configurations - if ( $sf == "" || - !file_exists($sf)) - $sf = isset($_SERVER["SCRIPT_FILENAME"]) ? $_SERVER["SCRIPT_FILENAME"] : ""; // for 'normal' configurations - if ( $sf == "" || - !file_exists($sf)) + $sf = ''; + if(function_exists('debug_backtrace')) { + // browse the backtrace history and take the first unknown filename as the client script + foreach(debug_backtrace() as $db) + { + $f = $db['file']; + if (!preg_match('/phpfreechat.class.php/',$f) && + !preg_match('/pfcglobalconfig.class.php/',$f) && + !preg_match('/pfctools.class.php/',$f) && + !preg_match('/pfcinfo.class.php/',$f) + ) + { + $sf = $f; + break; + } + } + } + else if (isset($_SERVER['PATH_TRANSLATED']) && + file_exists($_SERVER['SCRIPT_FILENAME'])) // check for a cgi configurations + { + $sf = $_SERVER['PATH_TRANSLATED']; + } + else if (isset($_SERVER['SCRIPT_FILENAME'])&& + file_exists($_SERVER['SCRIPT_FILENAME'])) // for non-cgi configurations + { + $sf = $_SERVER['SCRIPT_FILENAME']; + } + else + { echo "<pre>"; - echo "<span style='color:red'>Error: GetScriptFilename function returns a wrong path. Please contact the pfc team (co...@ph...) and copy/paste this array to help debugging.</span>\n"; + echo "<span style='color:red'>Error: pfc_GetScriptFilename function returns a wrong path. Please contact the pfc team (co...@ph...) and copy/paste these data to help debugging:</span>\n"; print_r($_SERVER); + print_r(debug_backtrace()); echo "</pre>"; exit; } return $sf; } -function relativePath($p1, $p2) +function pfc_RelativePath($p1, $p2) { if (is_file($p1)) $p1 = dirname($p1); if (is_file($p2)) $p2 = dirname($p2); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-09-26 06:03:43
|
Revision: 1194 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1194&view=rev Author: kerphi Date: 2007-09-25 23:03:43 -0700 (Tue, 25 Sep 2007) Log Message: ----------- Code cleanup around 'debug' parameter (thanks to sappheiros) Modified Paths: -------------- trunk/src/commands/send.class.php trunk/src/containers/file.class.php trunk/src/containers/mysql.class.php trunk/src/phpfreechat.class.php Modified: trunk/src/commands/send.class.php =================================================================== --- trunk/src/commands/send.class.php 2007-09-22 17:32:00 UTC (rev 1193) +++ trunk/src/commands/send.class.php 2007-09-26 06:03:43 UTC (rev 1194) @@ -74,7 +74,6 @@ $cmd->run($xml_reponse, $cmdp); return; } - if ($c->debug) pxlog("/send ".$text." (a user just sent a message -> nick=".$nick.")", "chat", $c->getId()); // a message has been posted so : // - clear errors Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2007-09-22 17:32:00 UTC (rev 1193) +++ trunk/src/containers/file.class.php 2007-09-26 06:03:43 UTC (rev 1194) @@ -71,9 +71,6 @@ { $c =& pfcGlobalConfig::Instance(); - if ($c->debug) - file_put_contents("/tmp/debug", "\nsetMeta(".$group.",".$subgroup.",".$leaf.",".$leafvalue.")", FILE_APPEND | LOCK_EX); - // create directories $dir_base = $c->container_cfg_server_dir; $dir = $dir_base.'/'.$group.'/'.$subgroup; @@ -104,8 +101,6 @@ function getMeta($group, $subgroup = null, $leaf = null, $withleafvalue = false) { $c =& pfcGlobalConfig::Instance(); - if ($c->debug) - file_put_contents("/tmp/debug", "\ngetMeta(".$group.",".$subgroup.",".$leaf.",".$withleafvalue.")", FILE_APPEND | LOCK_EX); // read data from metadata file $ret = array(); @@ -164,8 +159,6 @@ function incMeta($group, $subgroup, $leaf) { $c =& pfcGlobalConfig::Instance(); - if ($c->debug) - file_put_contents("/tmp/debug", "\nincMeta(".$group.",".$subgroup.",".$leaf.")", FILE_APPEND | LOCK_EX); // create directories $dir_base = $c->container_cfg_server_dir; @@ -219,8 +212,6 @@ function rmMeta($group, $subgroup = null, $leaf = null) { $c =& pfcGlobalConfig::Instance(); - if ($c->debug) - file_put_contents("/tmp/debug", "\nrmMeta(".$group.",".$subgroup.",".$leaf.")", FILE_APPEND | LOCK_EX); $dir = $c->container_cfg_server_dir; Modified: trunk/src/containers/mysql.class.php =================================================================== --- trunk/src/containers/mysql.class.php 2007-09-22 17:32:00 UTC (rev 1193) +++ trunk/src/containers/mysql.class.php 2007-09-26 06:03:43 UTC (rev 1194) @@ -157,9 +157,6 @@ { $c =& pfcGlobalConfig::Instance(); - if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nsetMeta(".$group.",".$subgroup.",".$leaf.",".$leafvalue.")", FILE_APPEND | LOCK_EX); - $server = $c->serverid; $db = $this->_connect(); @@ -173,9 +170,6 @@ $row = mysql_fetch_array($res, MYSQL_ASSOC); if( $row['C'] == 0 ) { - if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_insert.")", FILE_APPEND | LOCK_EX); - mysql_query($sql_insert, $db); return 0; // value created } @@ -183,9 +177,6 @@ { if ($sql_update != "") { - if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_update.")", FILE_APPEND | LOCK_EX); - mysql_query($sql_update, $db); } return 1; // value overwritten @@ -197,9 +188,6 @@ { $c =& pfcGlobalConfig::Instance(); - if ($c->debug) - file_put_contents("/tmp/debug.txt", "\ngetMeta(".$group.",".$subgroup.",".$leaf.",".$withleafvalue.")", FILE_APPEND | LOCK_EX); - $ret = array(); $ret["timestamp"] = array(); $ret["value"] = array(); @@ -233,10 +221,6 @@ } $sql_select="SELECT `$value`, `timestamp` FROM ".$c->container_cfg_mysql_table." WHERE `server`='$server' $sql_where $sql_group_by ORDER BY timestamp"; - - if ($c->debug) - file_put_contents("/tmp/debug.txt", "\ngetSQL(".$sql_select.")", FILE_APPEND | LOCK_EX); - if ($sql_select != "") { $thisresult = mysql_query($sql_select, $db); @@ -268,9 +252,6 @@ { $c =& pfcGlobalConfig::Instance(); - if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nsetMeta(".$group.",".$subgroup.",".$leaf.",".$leafvalue.")", FILE_APPEND | LOCK_EX); - $server = $c->serverid; $db = $this->_connect(); $time = time(); @@ -281,16 +262,12 @@ $row = mysql_fetch_array($res, MYSQL_ASSOC); if( $row['C'] == 0 ) { - if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_insert.")", FILE_APPEND | LOCK_EX); $leafvalue = 1; $sql_insert="REPLACE INTO ".$c->container_cfg_mysql_table." (`server`, `group`, `subgroup`, `leaf`, `leafvalue`, `timestamp`) VALUES('$server', '$group', '$subgroup', '$leaf', '".$leafvalue."', '".$time."')"; mysql_query($sql_insert, $db); } else { - if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nsetSQL(".$sql_update.")", FILE_APPEND | LOCK_EX); $sql_update="UPDATE ".$c->container_cfg_mysql_table." SET `leafvalue`= LAST_INSERT_ID( leafvalue + 1 ), `timestamp`='".$time."' WHERE `server`='$server' AND `group`='$group' AND `subgroup`='$subgroup' AND `leaf`='$leaf'"; mysql_query($sql_update, $db); $res = mysql_query('SELECT LAST_INSERT_ID();', $db); @@ -308,8 +285,6 @@ function rmMeta($group, $subgroup = null, $leaf = null) { $c =& pfcGlobalConfig::Instance(); - if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nrmMeta(".$group.",".$subgroup.",".$leaf.")", FILE_APPEND | LOCK_EX); $server = $c->serverid; $db = $this->_connect(); @@ -325,9 +300,6 @@ if ($leaf != NULL) $sql_delete .= " AND `leaf`='$leaf'"; - if ($c->debug) - file_put_contents("/tmp/debug.txt", "\nrmSQL(".$sql_delete.")", FILE_APPEND | LOCK_EX); - mysql_query($sql_delete, $db); return true; } Modified: trunk/src/phpfreechat.class.php =================================================================== --- trunk/src/phpfreechat.class.php 2007-09-22 17:32:00 UTC (rev 1193) +++ trunk/src/phpfreechat.class.php 2007-09-26 06:03:43 UTC (rev 1194) @@ -40,9 +40,6 @@ if (!is_array($params)) die('phpFreeChat parameters must be an array'); - if ( isset($params["debug"]) && $params["debug"] ) - require_once dirname(__FILE__)."/../debug/log.php"; - // initialize the global config object $c =& pfcGlobalConfig::Instance( $params ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ke...@us...> - 2007-10-28 21:28:01
|
Revision: 1201 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1201&view=rev Author: kerphi Date: 2007-10-28 14:28:05 -0700 (Sun, 28 Oct 2007) Log Message: ----------- Add a test for filemtime behavior (could be problematic on special filesystems) in the file container init step Modified Paths: -------------- trunk/src/containers/file.class.php trunk/src/pfcglobalconfig.class.php trunk/src/phpfreechat.class.php Modified: trunk/src/containers/file.class.php =================================================================== --- trunk/src/containers/file.class.php 2007-10-28 19:22:11 UTC (rev 1200) +++ trunk/src/containers/file.class.php 2007-10-28 21:28:05 UTC (rev 1201) @@ -64,6 +64,24 @@ $errors = array_merge($errors, @test_writable_dir($c->container_cfg_chat_dir, "container_cfg_chat_dir")); $errors = array_merge($errors, @test_writable_dir($c->container_cfg_server_dir, "container_cfg_chat_dir/serverid")); + // test the filemtime php function because it doesn't work on special filesystem + // example : NFS, VZFS + $filename = $c->data_private_path.'/filemtime.test'; + $timetowait = 2; + if (is_writable(dirname($filename))) + { + file_put_contents($filename,'some-data1-'.time(), LOCK_EX); + clearstatcache(); + $time1 = filemtime($filename); + sleep($timetowait); + file_put_contents($filename,'some-data2-'.time(), LOCK_EX); + clearstatcache(); + $time2 = filemtime($filename); + unlink($filename); + if ($time2-$time1 != $timetowait) + $errors[] = "filemtime php fuction is not usable on your filesystem. Please do not use the 'file' container (try the 'mysql' container) or swith to another filesystem."; + } + return $errors; } Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-10-28 19:22:11 UTC (rev 1200) +++ trunk/src/pfcglobalconfig.class.php 2007-10-28 21:28:05 UTC (rev 1201) @@ -1045,14 +1045,13 @@ if (!$this->isInit()) $this->init(); $errors =& $this->getErrors(); - if (count($errors) > 0) + if (count($errors) == 0) { - @unlink($cachefile_lock); // destroy the lock file for the next attempt - echo "<p>"._pfc("Please correct these errors").":</p><ul>"; foreach( $errors as $e ) echo "<li>".$e."</li>"; echo "</ul>"; - exit; + // save the validated config in cache + $this->saveInCache(); } - // save the validated config in cache - $this->saveInCache(); + else + @unlink($cachefile_lock); // destroy the lock file for the next attempt return false; // new cache created } } Modified: trunk/src/phpfreechat.class.php =================================================================== --- trunk/src/phpfreechat.class.php 2007-10-28 19:22:11 UTC (rev 1200) +++ trunk/src/phpfreechat.class.php 2007-10-28 21:28:05 UTC (rev 1201) @@ -98,22 +98,27 @@ { $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); - + $output = ''; - pfcI18N::SwitchOutputEncoding($c->output_encoding); - - $path = $c->getFilePathFromTheme('chat.js.tpl.php'); - $t = new pfcTemplate($path); - $t->assignObject($u,"u"); - $t->assignObject($c,"c"); - $output .= $t->getOutput(); + if (count($c->getErrors()) > 0) + { + $output .= "<p>phpFreeChat cannot be initialized, please correct these errors:</p><ul>"; + foreach( $c->getErrors() as $e ) $output .= "<li>".$e."</li>"; $output .= "</ul>"; + } + else + { + pfcI18N::SwitchOutputEncoding($c->output_encoding); + + $path = $c->getFilePathFromTheme('chat.js.tpl.php'); + $t = new pfcTemplate($path); + $t->assignObject($u,"u"); + $t->assignObject($c,"c"); + $output .= $t->getOutput(); + + pfcI18N::SwitchOutputEncoding(); + } - pfcI18N::SwitchOutputEncoding(); - /* - $output .= " // ]]>\n"; - $output .= "</script>\n"; - */ if($return) return $output; else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |