mirror of
https://github.com/Mibew/i18n.git
synced 2025-01-22 21:40:28 +03:00
first message, user agent, userid
git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@150 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
parent
5d9c643725
commit
a3297ee3ea
@ -113,6 +113,11 @@ var HtmlGenerationUtils = {
|
||||
gen += '</td>';
|
||||
cellsCount++;
|
||||
}
|
||||
if( message != "" ) {
|
||||
gen += '</tr><tr><td class="firstmessage" align="right" colspan="'+cellsCount+'"><a href="javascript:void(0)" title="'+message+'" onclick="alert(this.title);return false;">';
|
||||
gen += message.length > 30 ? message.substring(0,30) + '...' : message;
|
||||
gen += '</a></td>';
|
||||
}
|
||||
return HtmlGenerationUtils.generateOneRowTable(gen);
|
||||
}
|
||||
};
|
||||
|
@ -32,9 +32,14 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
|
||||
|
||||
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
|
||||
$extAddr = $_SERVER['REMOTE_ADDR'];
|
||||
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {
|
||||
$extAddr = $_SERVER['REMOTE_ADDR'].' ('.$_SERVER['HTTP_X_FORWARDED_FOR'].')';
|
||||
}
|
||||
$userbrowser = $_SERVER['HTTP_USER_AGENT'];
|
||||
$remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
|
||||
$visitor = $remote_visitor();
|
||||
$thread = create_thread($visitor['name'], $remoteHost, $referer,$current_locale);
|
||||
$thread = create_thread($visitor['name'], $remoteHost, $referer,$current_locale,$visitor['id'], $userbrowser);
|
||||
$_SESSION['threadid'] = $thread['threadid'];
|
||||
if( $referer ) {
|
||||
post_message($thread['threadid'],$kind_for_agent,getstring2('chat.came.from',array($referer)));
|
||||
|
@ -16,6 +16,7 @@ $dbtables = array(
|
||||
"chatthread" => array(
|
||||
"threadid" => "int NOT NULL auto_increment PRIMARY KEY",
|
||||
"userName" => "varchar(64) NOT NULL",
|
||||
"userid" => "varchar(255)",
|
||||
"agentName" => "varchar(64)",
|
||||
"agentId" => "int NOT NULL DEFAULT 0",
|
||||
"dtmcreated" => "datetime DEFAULT 0",
|
||||
@ -31,6 +32,8 @@ $dbtables = array(
|
||||
"lastpingagent" => "datetime DEFAULT 0",
|
||||
"userTyping" => "int DEFAULT 0",
|
||||
"agentTyping" => "int DEFAULT 0",
|
||||
"shownmessageid" => "int NOT NULL DEFAULT 0",
|
||||
"userAgent" => "varchar(255)",
|
||||
"messageCount" => "varchar(16)"
|
||||
),
|
||||
|
||||
@ -67,7 +70,7 @@ $dbtables = array(
|
||||
$memtables = array();
|
||||
|
||||
$dbtables_can_update = array(
|
||||
"chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent"),
|
||||
"chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent", "shownmessageid", "userid", "userAgent"),
|
||||
"chatmessage" => array("agentId"),
|
||||
);
|
||||
|
||||
|
@ -98,6 +98,18 @@ if ($act == "silentcreateall") {
|
||||
runsql("ALTER TABLE chatthread ADD nextagent int NOT NULL DEFAULT 0", $link);
|
||||
}
|
||||
|
||||
if( in_array("chatthread.shownmessageid", $absent) ) {
|
||||
runsql("ALTER TABLE chatthread ADD shownmessageid int NOT NULL DEFAULT 0", $link);
|
||||
}
|
||||
|
||||
if( in_array("chatthread.userid", $absent) ) {
|
||||
runsql("ALTER TABLE chatthread ADD userid varchar(255) DEFAULT \"\"", $link);
|
||||
}
|
||||
|
||||
if( in_array("chatthread.userAgent", $absent) ) {
|
||||
runsql("ALTER TABLE chatthread ADD userAgent varchar(255)", $link);
|
||||
}
|
||||
|
||||
$res = runsql("select null from information_schema.statistics where table_name = 'chatmessage' and index_name = 'idx_agentid'", $link);
|
||||
if(mysql_num_rows($res) == 0) {
|
||||
runsql("ALTER TABLE chatmessage ADD INDEX idx_agentid (agentid)", $link);
|
||||
|
@ -1 +1 @@
|
||||
var myAgent="";var rk=0;var myRealAgent="";function sk(){var tk=["\u006f\u0070\145r\u0061","\u006d\163\151\u0065","\u0073af\u0061\u0072\151","\u0066i\162\u0065\u0066\u006fx","\u006eet\u0073\143a\160\145","\155\u006f\172i\u006cl\141"];var lj=navigator.userAgent.toLowerCase();for(var i=0;i<tk.length;i++){var uk=tk[i];if(lj.indexOf(uk)!=-1){myAgent=uk;if(!window.RegExp)break;var hk=new RegExp(uk+"\133\u0020\/]?(\1330-9]\u002b\u0028\.[0-9\u005d+\051\u003f\u0029");if(hk.exec(lj)!=null){rk=parseFloat(RegExp.$1);} break;} } myRealAgent=myAgent;if(navigator.product=="\u0047e\u0063k\u006f")myAgent="m\157\u007a";} sk();function getEl(name){return document.getElementById(name);}
|
||||
var myAgent="";var rk=0;var myRealAgent="";function sk(){var tk=["\u006f\u0070\145\162\141","\155\u0073ie","\u0073\141fari","\146ir\u0065f\157x","n\145\164\163ca\160\145","mo\u007a\u0069\u006cl\141"];var lj=navigator.userAgent.toLowerCase();for(var i=0;i<tk.length;i++){var uk=tk[i];if(lj.indexOf(uk)!=-1){myAgent=uk;if(!window.RegExp)break;var hk=new RegExp(uk+"\u005b \/\135\077\050\u005b\060-\071\135\053\050\.\133\u0030-\u0039\135\053)\077)");if(hk.exec(lj)!=null){rk=parseFloat(RegExp.$1);} break;} } myRealAgent=myAgent;if(navigator.product=="\107\u0065\143\153\u006f")myAgent="m\157\172";} sk();function getEl(name){return document.getElementById(name);}
|
File diff suppressed because one or more lines are too long
@ -17,6 +17,7 @@ $connection_timeout = 30; // sec
|
||||
|
||||
$simplenamecookie = "WEBIM_Name"; // 1.0.8 and earlier
|
||||
$namecookie = "WEBIM_Data"; // 1.0.9+
|
||||
$usercookie = "WEBIM_UserID";
|
||||
|
||||
$state_queue = 0;
|
||||
$state_waiting = 1;
|
||||
@ -34,6 +35,10 @@ $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 get_user_id() {
|
||||
return (time() + microtime()).rand(0,99999999);
|
||||
}
|
||||
|
||||
function next_token() {
|
||||
return rand(99999,99999999);
|
||||
}
|
||||
@ -165,10 +170,11 @@ function print_thread_messages($thread, $token, $lastid, $isuser, $format, $agen
|
||||
}
|
||||
}
|
||||
|
||||
function get_user_name($username, $addr) {
|
||||
function get_user_name($username, $addr, $id) {
|
||||
global $presentable_name_pattern;
|
||||
return str_replace("{addr}", $addr,
|
||||
str_replace("{name}", $username, $presentable_name_pattern));
|
||||
str_replace("{id}", $id,
|
||||
str_replace("{name}", $username, $presentable_name_pattern)));
|
||||
}
|
||||
|
||||
function is_ajax_browser($browserid,$ver,$useragent) {
|
||||
@ -273,7 +279,7 @@ function setup_chatview_for_operator($thread,$operator) {
|
||||
$page['canpost'] = $thread['agentId'] == $operator['operatorid'];
|
||||
$page['ct.chatThreadId'] = $thread['threadid'];
|
||||
$page['ct.token'] = $thread['ltoken'];
|
||||
$page['ct.user.name'] = topage(get_user_name($thread['userName'],$thread['remote']));
|
||||
$page['ct.user.name'] = topage(get_user_name($thread['userName'],$thread['remote'],$thread['userid']));
|
||||
|
||||
$page['ct.company.name'] = topage($settings['title']);
|
||||
$page['ct.company.chatLogoURL'] = topage($settings['logo']);
|
||||
@ -281,7 +287,7 @@ function setup_chatview_for_operator($thread,$operator) {
|
||||
$page['send_shortcut'] = "Ctrl-Enter";
|
||||
$page['isOpera95'] = is_agent_opera95();
|
||||
$page['neediframesrc'] = needsFramesrc();
|
||||
|
||||
$page['historyParams'] = array("userid" => "".$thread['userid']);
|
||||
$page['predefinedList'] = explode("\n", getlocal_('chat.predefined_answers', $thread['locale']));
|
||||
$params = "thread=".$thread['threadid']."&token=".$thread['ltoken'];
|
||||
$page['selfLink'] = "$webimroot/operator/agent.php?".$params;
|
||||
@ -378,7 +384,7 @@ function close_thread($thread,$isuser) {
|
||||
|
||||
function thread_by_id_($id,$link) {
|
||||
return select_one_row("select threadid,userName,agentName,agentId,lrevision,istate,ltoken,userTyping,agentTyping".
|
||||
",remote,referer,locale,unix_timestamp(lastpinguser) as lpuser,unix_timestamp(lastpingagent) as lpagent, unix_timestamp(CURRENT_TIMESTAMP) as current,nextagent".
|
||||
",remote,referer,locale,unix_timestamp(lastpinguser) as lpuser,unix_timestamp(lastpingagent) as lpagent, unix_timestamp(CURRENT_TIMESTAMP) as current,nextagent,shownmessageid,userid,userAgent".
|
||||
" from chatthread where threadid = ". $id, $link );
|
||||
}
|
||||
|
||||
@ -389,19 +395,21 @@ function thread_by_id($id) {
|
||||
return $thread;
|
||||
}
|
||||
|
||||
function create_thread($username,$remoteHost,$referer,$lang) {
|
||||
function create_thread($username,$remoteHost,$referer,$lang,$userid,$userbrowser) {
|
||||
global $state_loading;
|
||||
$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,userid,ltoken,remote,referer,lrevision,locale,userAgent,dtmcreated,dtmmodified,istate) values ".
|
||||
"('%s','%s',%s,'%s','%s',%s,'%s','%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,$state_loading)",
|
||||
mysql_real_escape_string($username),
|
||||
mysql_real_escape_string($userid),
|
||||
next_token(),
|
||||
mysql_real_escape_string($remoteHost),
|
||||
mysql_real_escape_string($referer),
|
||||
next_revision($link),
|
||||
mysql_real_escape_string($lang) );
|
||||
mysql_real_escape_string($lang),
|
||||
mysql_real_escape_string($userbrowser));
|
||||
|
||||
perform_query($query,$link);
|
||||
$id = mysql_insert_id($link);
|
||||
@ -496,7 +504,7 @@ function check_for_reassign($thread,$operator) {
|
||||
}
|
||||
|
||||
function visitor_from_request() {
|
||||
global $namecookie, $simplenamecookie, $compatibility_encoding, $webim_encoding;
|
||||
global $namecookie, $simplenamecookie, $compatibility_encoding, $webim_encoding, $usercookie;
|
||||
$userName = getstring("chat.default.username");
|
||||
if( isset($_COOKIE[$namecookie]) ) {
|
||||
$data = base64_decode(strtr($_COOKIE[$namecookie],'-_,', '+/='));
|
||||
@ -507,7 +515,14 @@ function visitor_from_request() {
|
||||
$userName = myiconv($compatibility_encoding,$webim_encoding,$_COOKIE[$simplenamecookie]);
|
||||
}
|
||||
|
||||
return array( 'name' => $userName );
|
||||
$userId = "";
|
||||
if (isset($_COOKIE[$usercookie])) {
|
||||
$userId = $_COOKIE[$usercookie];
|
||||
} else {
|
||||
$userId = get_user_id();
|
||||
setcookie($usercookie, $userId, time()+60*60*24*365);
|
||||
}
|
||||
return array( 'id' => $userId, 'name' => $userName );
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -39,6 +39,35 @@ $threadstate_key = array(
|
||||
$state_loading => "chat.thread.state_loading"
|
||||
);
|
||||
|
||||
function get_useragent_version($userAgent) {
|
||||
global $knownAgents;
|
||||
if (is_array($knownAgents)) {
|
||||
$userAgent = strtolower($userAgent);
|
||||
foreach( $knownAgents as $agent ) {
|
||||
if( strstr($userAgent,$agent) ) {
|
||||
if( preg_match( "/".$agent."[\\s\/]?(\\d+(\\.\\d+(\\.\\d+)?)?)/", $userAgent, $matches ) ) {
|
||||
$ver = $matches[1];
|
||||
if($agent=='safari') {
|
||||
if(preg_match( "/version\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $userAgent, $matches)) {
|
||||
$ver = $matches[1];
|
||||
} else {
|
||||
$ver = "1 or 2 (build ".$ver.")";
|
||||
}
|
||||
if(preg_match( "/mobile\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $userAgent, $matches)) {
|
||||
$userAgent = "iPhone ".$matches[1]." ($agent $ver)";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$userAgent = ucfirst($agent)." ".$ver;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $userAgent;
|
||||
}
|
||||
|
||||
function thread_to_xml($thread,$link) {
|
||||
global $threadstate_to_string, $threadstate_key, $webim_encoding, $operator;
|
||||
$state = $threadstate_to_string[$thread['istate']];
|
||||
@ -57,12 +86,22 @@ function thread_to_xml($thread,$link) {
|
||||
}
|
||||
|
||||
$result .= " state=\"$state\" typing=\"".$thread['userTyping']."\">";
|
||||
$result .= "<name>".htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'],$thread['remote'])))."</name>";
|
||||
$result .= "<name>".htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'],$thread['remote'], $thread['userid'])))."</name>";
|
||||
$result .= "<addr>".htmlspecialchars(htmlspecialchars($thread['remote']))."</addr>";
|
||||
$result .= "<agent>".htmlspecialchars(htmlspecialchars($threadoperator))."</agent>";
|
||||
$result .= "<time>".$thread['unix_timestamp(dtmcreated)']."000</time>";
|
||||
$result .= "<modified>".$thread['unix_timestamp(dtmmodified)']."000</modified>";
|
||||
|
||||
$userAgent = get_useragent_version($thread['userAgent']);
|
||||
$result .= "<useragent>".$userAgent."</useragent>";
|
||||
if( $thread["shownmessageid"] != 0 ) {
|
||||
$query = "select tmessage from chatmessage where messageid = ".$thread["shownmessageid"];
|
||||
$line = select_one_row($query, $link);
|
||||
if( $line ) {
|
||||
$message = preg_replace("/[\r\n\t]+/", " ", $line["tmessage"]);
|
||||
$result .= "<message>".htmlspecialchars(htmlspecialchars($message))."</message>";
|
||||
}
|
||||
}
|
||||
$result .= "</thread>";
|
||||
return $result;
|
||||
}
|
||||
@ -74,7 +113,7 @@ function print_pending_threads($since) {
|
||||
$revision = $since;
|
||||
$output = array();
|
||||
$query = "select threadid, userName, agentName, unix_timestamp(dtmcreated), userTyping, ".
|
||||
"unix_timestamp(dtmmodified), lrevision, istate, remote, nextagent, agentId ".
|
||||
"unix_timestamp(dtmmodified), lrevision, istate, remote, nextagent, agentId, userid, shownmessageid, userAgent ".
|
||||
"from chatthread where lrevision > $since ORDER BY threadid";
|
||||
$rows = select_multi_assoc($query, $link);
|
||||
foreach ($rows as $row) {
|
||||
|
@ -63,7 +63,12 @@ if( $act == "refresh" ) {
|
||||
show_error("cannot send");
|
||||
}
|
||||
|
||||
post_message($threadid,$kind,$message,$from, $isuser ? null : $operator['operatorid'] );
|
||||
$postedid = post_message($threadid,$kind,$message,$from, $isuser ? null : $operator['operatorid'] );
|
||||
if($isuser && $thread["shownmessageid"] == 0) {
|
||||
$link = connect();
|
||||
commit_thread( $thread['threadid'], array('shownmessageid' => $postedid), $link);
|
||||
mysql_close($link);
|
||||
}
|
||||
print_thread_messages($thread, $token, $lastid, $isuser, $outformat, $isuser ? null : $operator['operatorid']);
|
||||
exit;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user