typing timeout, opera/safari fixes

git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@111 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
Evgeny Gryaznov 2008-09-29 22:35:08 +00:00
parent 835eaabf06
commit 7427fb4c68

View File

@ -34,8 +34,6 @@ $kind_events = 6;
$kind_to_string = array( $kind_user => "user", $kind_agent => "agent", $kind_for_agent => "hidden",
$kind_info => "inf", $kind_conn => "conn", $kind_events => "event" );
function next_token() {
return rand(99999,99999999);
}
@ -109,9 +107,8 @@ function get_messages($threadid,$meth,$isuser,&$lastid) {
$threadid, $lastid, $isuser ? "and ikind <> $kind_for_agent" : "" );
$messages = array();
$result = mysql_query($query,$link) or die(' Query failed: ' .mysql_error().": ".$query);
while ($msg = mysql_fetch_array($result, MYSQL_ASSOC)) {
$msgs = select_multi_assoc($query, $link);
foreach ($msgs as $msg) {
$message = "";
if ($meth == 'xml') {
$message = "<message>".myiconv($webim_encoding,"utf-8",escape_with_cdata(message_to_html($msg)))."</message>\n";
@ -125,20 +122,21 @@ function get_messages($threadid,$meth,$isuser,&$lastid) {
}
}
mysql_free_result($result);
mysql_close($link);
return $messages;
}
function print_thread_messages($thread, $token, $lastid, $isuser,$format) {
global $webim_encoding, $webimroot;
global $webim_encoding, $webimroot, $connection_timeout;
$threadid = $thread['threadid'];
$istyping = abs($thread['current']-$thread[$isuser ? "lpagent" : "lpuser"]) < $connection_timeout
&& $thread[$isuser?"agentTyping":"userTyping"] == "1" ? "1" : "0";
if( $format == "xml" ) {
$output = get_messages($threadid,"xml",$isuser,$lastid);
start_xml_output();
print("<thread lastid=\"$lastid\" typing=\"".$thread[$isuser?"agentTyping":"userTyping"]."\">");
print("<thread lastid=\"$lastid\" typing=\"".$istyping."\">");
foreach( $output as $msg ) {
print $msg;
}
@ -173,50 +171,6 @@ function get_user_name($username, $addr) {
str_replace("{name}", $username, $presentable_name_pattern));
}
function setup_chatview_for_user($thread,$level) {
global $page, $webimroot, $user_can_change_name, $company_logo_link, $company_name, $webim_host;
$page = array();
$page['agent'] = false;
$page['user'] = true;
$page['canpost'] = true;
$nameisset = getstring("chat.default.username") != $thread['userName'];
$page['displ1'] = $nameisset ? "none" : "inline";
$page['displ2'] = $nameisset ? "inline" : "none";
$page['level'] = $level;
$page['ct.chatThreadId'] = $thread['threadid'];
$page['ct.token'] = $thread['ltoken'];
$page['ct.user.name'] = topage($thread['userName']);
$page['canChangeName'] = $user_can_change_name;
$page['ct.company.name'] = topage($company_name);
$page['ct.company.chatLogoURL'] = topage($company_logo_link);
$page['send_shortcut'] = "Ctrl-Enter";
$params = "thread=".$thread['threadid']."&token=".$thread['ltoken'];
$page['selfLink'] = "$webimroot/client.php?".$params."&level=".$level;
$page['webimHost'] = $webim_host;
}
function setup_chatview_for_operator($thread,$operator) {
global $page, $webimroot, $company_logo_link, $company_name, $webim_host;
$page = array();
$page['agent'] = true;
$page['user'] = false;
$page['canpost'] = true;
$page['ct.chatThreadId'] = $thread['threadid'];
$page['ct.token'] = $thread['ltoken'];
$page['ct.user.name'] = topage(get_user_name($thread['userName'],$thread['remote']));
$page['ct.company.name'] = topage($company_name);
$page['ct.company.chatLogoURL'] = topage($company_logo_link);
$page['send_shortcut'] = "Ctrl-Enter";
$page['webimHost'] = $webim_host;
// TODO
$page['namePostfix'] = "";
}
function is_ajax_browser($browserid,$ver,$useragent) {
if( $browserid == "opera" )
return $ver >= 8.02;
@ -264,6 +218,73 @@ function get_remote_level($useragent) {
return "simple";
}
function is_agent_opera95() {
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
if( strstr($useragent,"opera") ) {
if( preg_match( "/opera[\\s\/]?(\\d+(\\.\\d+)?)/", $useragent, $matches ) ) {
$ver = $matches[1];
if ($ver >= "9.5")
return true;
}
}
return false;
}
function needsFramesrc() {
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
return strstr($useragent,"safari/");
}
function setup_chatview_for_user($thread,$level) {
global $page, $webimroot, $user_can_change_name, $settings;
loadsettings();
$page = array();
$page['agent'] = false;
$page['user'] = true;
$page['canpost'] = true;
$nameisset = getstring("chat.default.username") != $thread['userName'];
$page['displ1'] = $nameisset ? "none" : "inline";
$page['displ2'] = $nameisset ? "inline" : "none";
$page['level'] = $level;
$page['ct.chatThreadId'] = $thread['threadid'];
$page['ct.token'] = $thread['ltoken'];
$page['ct.user.name'] = topage($thread['userName']);
$page['canChangeName'] = $user_can_change_name;
$page['ct.company.name'] = topage($settings['title']);
$page['ct.company.chatLogoURL'] = topage($settings['logo']);
$page['webimHost'] = topage($settings['hosturl']);
$page['send_shortcut'] = "Ctrl-Enter";
$params = "thread=".$thread['threadid']."&token=".$thread['ltoken'];
$page['selfLink'] = "$webimroot/client.php?".$params."&level=".$level;
$page['isOpera95'] = is_agent_opera95();
$page['neediframesrc'] = needsFramesrc();
}
function setup_chatview_for_operator($thread,$operator) {
global $page, $webimroot, $company_logo_link, $company_name, $settings;
loadsettings();
$page = array();
$page['agent'] = true;
$page['user'] = false;
$page['canpost'] = true;
$page['ct.chatThreadId'] = $thread['threadid'];
$page['ct.token'] = $thread['ltoken'];
$page['ct.user.name'] = topage(get_user_name($thread['userName'],$thread['remote']));
$page['ct.company.name'] = topage($settings['title']);
$page['ct.company.chatLogoURL'] = topage($settings['logo']);
$page['webimHost'] = topage($settings['hosturl']);
$page['send_shortcut'] = "Ctrl-Enter";
$page['isOpera95'] = is_agent_opera95();
$page['neediframesrc'] = needsFramesrc();
$page['namePostfix'] = "";
}
function update_thread_access($threadid, $params, $link) {
$clause = "";
foreach( $params as $k => $v ) {
@ -335,7 +356,6 @@ function rename_user($thread, $newname) {
}
}
function close_thread($thread,$isuser) {
global $state_closed, $kind_events;
@ -369,8 +389,8 @@ function create_thread($username,$remoteHost,$referer,$lang) {
$link = connect();
$query = sprintf(
"insert into chatthread (userName,"."ltoken,remote,referer,lrevision,locale,dtmcreated,dtmmodified,istate) values ".
"('%s',"."%s,'%s','%s',%s,'%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,$state_loading)",
"insert into chatthread (userName,ltoken,remote,referer,lrevision,locale,dtmcreated,dtmmodified,istate) values ".
"('%s',%s,'%s','%s',%s,'%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,$state_loading)",
mysql_real_escape_string($username),
next_token(),
mysql_real_escape_string($remoteHost),