I suggest the following changes:
In pfcglobalconfig.class.php add these 3 blue lines and add the blue values to var $_dyn_params:
class pfcGlobalConfig
{
var $serverid = ""; // this is the chat server id (comparable to the server host in IRC)
// these parameters are dynamic (not cached)
var $time_offset = 0;
var $date_format = "m-d-Y";
var $time_format = "h:i a";
...
var $_dyn_params = array("time_offset", "date_format","time_format","nick","isadmin","islocked","admins","frozen_channels", "channels", "privmsg", "nickmeta","baseurl");
...
Now we can pass time offsets and format strings thru initializing $params:
- Code: Select all
$params["time_offset"] = 8*3600;
$params["date_format"] = "d/m/Y";
$params["time_format"] = "H:i:s";
$chat = new phpFreeChat( $params );
In pfccontainer.class.php change function write($chan, $nick, $cmd, $param) like
function write($chan, $nick, $cmd, $param)
{
$c =& pfcGlobalConfig::Instance();
if ($chan == NULL) $chan = 'SERVER';
$msgid = $this->_requestMsgId($chan);
$time = time() + $c->time_offset;
// format message
$data = "n";
$data .= $msgid."t";
$data .= gmdate($c->date_format, $time)."t";
$data .= gmdate($c->time_format, $time)."t";
$data .= $nick."t";
$data .= $cmd."t";
$data .= $param;
// write message
$this->setMeta("channelid-to-msg", $this->encode($chan), $msgid, $data);
// delete the obsolete message
$old_msgid = $msgid - $c->max_msg - 20;
if ($old_msgid > 0)
$this->rmMeta("channelid-to-msg", $this->encode($chan), $old_msgid);
return $msgid;
}
gmdate is necessary in order to reset to GMT time.
This is the best method to control user timezones, because we can pass user data from sql via $params.
In flat file mode the log stores timestamps in formatted strings, therefore users may see different time formats. I would suggest to store the timestamps like "timestamp_xxxxxxxxxx" and with a new function in pfccontainer.class.php we can format those timestamps with a preg_replace:
- Code: Select all
function format_time($time) {
if (!$time) return "tt";
$c =& pfcGlobalConfig::Instance();
$time += $c->time_offset;
return gmdate($c->date_format, $time)."t".gmdate($c->time_format, $time)."t";
}
@kerphi:
I have noticed a small problem: time offsets can be positive and negative integers. The type test might reject negative offsets, because the default value is 0 (recognized as a positive type).