Created
May 19, 2011 14:48
-
-
Save mingtsay/980920 to your computer and use it in GitHub Desktop.
mt's Chatroom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $cls = true; | |
| $use_same_db = false; | |
| $old = true; | |
| define("MT_TIMEOUT", 10); | |
| function video_id($url) { | |
| $parse_url = parse_url($url); | |
| $query = array(); | |
| parse_str($parse_url["query"], $query); | |
| if(!empty($query["v"])) return $query["v"]; | |
| $t = explode("/", trim($parse_url["path"], "/")); | |
| foreach($t as $k => $v) if($v == "v") if(!empty($t[$k + 1])) return $t[$k+1]; | |
| return $url; | |
| } | |
| function bbs($str) | |
| { | |
| $bbs = array( | |
| '\\[b\\](.*?)\\[\\/b\\]', | |
| '\\[u\\](.*?)\\[\\/u\\]', | |
| '\\[i\\](.*?)\\[\\/i\\]', | |
| '\\[url\\=(.*?)\\](.*?)\\[\\/url\\]', | |
| '\\[url\\](.*?)\\[\\/url\\]', | |
| '\\[img\\](.*?)\\[\\/img\\]', | |
| '\\[youtube\\](.*?)\\[\\/youtube\\]', | |
| ); | |
| $html = array( | |
| '<span class="bbs_blod" style="font-weight: bold;">$1</span>', | |
| '<span class="bbs_underline" style="text-decoration: underline;">$1</span>', | |
| '<span class="bbs_italic" style="font-style: italic;">$1</span>', | |
| '<a href="$1" target="_blank" title="另開新視窗">$2</a>', | |
| '<a href="$1" target="_blank" title="另開新視窗">$1</a>', | |
| '<img alt="Picture" src="$1" />', | |
| '<div class="youtube"><a href="javascript:;" onclick="showBox(\'youtube\', \'$1\');"><img src="http://i3.ytimg.com/vi/$1/default.jpg" /></a></div>', | |
| ); | |
| $i = 0; | |
| while(isset($bbs[$i])) | |
| { | |
| $bbs[$i] = "/$bbs[$i]/is"; ++$i; | |
| } | |
| $str = preg_replace($bbs, $html, $str); | |
| return $str; | |
| } | |
| function getOnlineNo() | |
| { | |
| $c = 0; | |
| $d = dir("session"); | |
| while($file = $d -> read()) | |
| if((time() - filemtime("$d->path/$file")) <= MT_TIMEOUT) | |
| ++$c; | |
| return $c; | |
| } | |
| function getOnlineList() | |
| { | |
| $r = ""; | |
| $ts = time() - MT_TIMEOUT; | |
| $q = mysql_query("SELECT `color`, `nick`, `ip`, `ua` FROM `chatroom_sess` WHERE `ts` > $ts ORDER BY `nick` ASC"); | |
| if($q) | |
| while($data = mysql_fetch_array($q)) | |
| { | |
| $ip_r = explode(".", $data['ip']); | |
| $ip = sprintf("%3d.%3d.*.*", $ip_r[0], $ip_r[1]); | |
| $ip = str_replace(" ", "0", $ip); | |
| $ipc = (string)ip2nationcountries($data['ip']); | |
| $ipi = strtoupper((string)ip2nation($data['ip'])); | |
| $reviewers_info = analyse_user_agent($data['ua']); | |
| $r .= | |
| "<div class=\"online_list\">\n" . | |
| "\t<span class=\"ua\">\n" . | |
| "\t\t<img class=\"icon\" src=\"icons/{$reviewers_info['browser_icon']}.png\" title=\"{$reviewers_info['browser']}\" alt=\"{$reviewers_info['browser']}\" />\n" . | |
| "\t\t<img class=\"icon\" src=\"icons/{$reviewers_info['os_icon']}.png\" title=\"{$reviewers_info['os']}\" alt=\"{$reviewers_info['os']}\" />\n" . | |
| "\t</span>\n" . | |
| "\t<span class=\"ip\" title=\"$ipc\">\n" . | |
| "\t\t<img class=\"flag\" src=\"flags/$ipi.png\" alt=\"$ipi\" />\n" . | |
| "\t\t$ip\n" . | |
| "\t</span>\n" . | |
| "\t<span style=\"color: {$data['color']};\" class=\"nickname\" onclick=\"reply('" . strip_tags($data['nick']) . "');\" title=\"按此回覆\">" . strip_tags($data['nick']) . "</span>\n" . | |
| "</div>\n"; | |
| } | |
| $r .= | |
| "<div class=\"online_list online_list_hide\">\n" . | |
| "\t<a href=\"javascript:;\" onclick=\"$('.online_list_outer'). fadeOut('slow');\">按此隱藏聊天室名單</a>\n" . | |
| "</div>\n"; | |
| return $r; | |
| } | |
| function ip2nation($ip) | |
| { | |
| $q = mysql_query(" | |
| SELECT | |
| c.flag | |
| FROM | |
| ip2nationcountries c, | |
| ip2nation i | |
| WHERE | |
| i.ip < INET_ATON('$ip') | |
| AND | |
| c.code = i.country | |
| ORDER BY | |
| i.ip DESC | |
| LIMIT 0, 1 | |
| "); | |
| if(!$q) | |
| return "00"; | |
| list($r) = mysql_fetch_row($q); | |
| return $r; | |
| } | |
| function ip2nationcountries($ip) | |
| { | |
| $q = mysql_query(" | |
| SELECT | |
| c.country | |
| FROM | |
| ip2nationcountries c, | |
| ip2nation i | |
| WHERE | |
| i.ip < INET_ATON('$ip') | |
| AND | |
| c.code = i.country | |
| ORDER BY | |
| i.ip DESC | |
| LIMIT 0, 1 | |
| "); | |
| if(!$q) | |
| return "Unknown"; | |
| list($r) = mysql_fetch_row($q); | |
| return $r; | |
| } | |
| function analyse_user_agent($str) | |
| { | |
| #$str = strtolower($str); | |
| if(stripos($str,'msie') !== false) | |
| { | |
| //IE | |
| $pattern = '/msie ([0-9a-z\.]+);/i'; | |
| preg_match($pattern,$str,$versions); | |
| $version = $versions[1]; //IE VERSION | |
| //Based on IE | |
| $result['browser_base'] = 'ie'; | |
| if(stripos($str,'maxthon') !== false) | |
| { | |
| // MAXTHON | |
| $result['browser_icon'] = 'maxthon'; | |
| if(stripos($str,'maxthon 2.0') !== false) | |
| { | |
| // MAXTHON 2.0 | |
| $subversion = '2.0'; | |
| } | |
| else | |
| { | |
| //MAXTHON 1.0 | |
| $subversion = '1.0'; | |
| } | |
| $result['browser'] = "Maxthon $subversion based on IE $version"; | |
| } | |
| elseif(stripos($str,'theworld') !== false) | |
| { | |
| //The World | |
| $result['browser_icon'] = 'theworld'; | |
| $result['browser'] = "TheWorld based on IE $version"; | |
| } | |
| elseif(stripos($str,'greenbrowser') !== false) | |
| { | |
| // GreenBrowser | |
| $result['browser_icon'] = 'greenbrowser'; | |
| $result['browser'] = "GreenBrowser based on IE $version"; | |
| } | |
| elseif(stripos($str,'tencenttravel') !== false) | |
| { | |
| // TT | |
| $result['browser_icon'] = 'tencenttravel'; | |
| $result['browser'] = "TencentTravel based on IE $version"; | |
| } | |
| else | |
| { | |
| $result['browser_icon'] = 'ie'; | |
| $result['browser'] = "Internet Explorer $version"; | |
| } | |
| } | |
| elseif(stripos($str,'firefox') !== false) | |
| { | |
| //Firefox | |
| $pattern = '/firefox\/([A-Za-z0-9\.\-_]+)/i'; | |
| preg_match($pattern,$str,$versions); | |
| $version = $versions[1]; //Firefox VERSION | |
| //Based on Firefox | |
| $result['browser_base'] = 'firefox'; | |
| if(stripos($str,'navigator') !== false) | |
| { | |
| //Netscape 9 | |
| $pattern = '/navigator\/([A-Za-z0-9\.\-_]+)/i'; | |
| preg_match($pattern,$str,$versions); | |
| $v = $versions[1]; //Firefox VERSION | |
| $result['browser_icon'] = 'netscape'; | |
| $result['browser'] = "Netscape $v based on Firefox $version"; | |
| } | |
| else | |
| { | |
| $result['browser_icon'] = 'firefox'; | |
| $result['browser'] = "Firefox $version"; | |
| } | |
| } | |
| elseif(stripos($str,'opera') !== false) | |
| { | |
| //Opera | |
| $pattern = '/opera\/([A-Za-z0-9\.\-_]+)/i'; | |
| preg_match($pattern,$str,$versions); | |
| $version = $versions[1]; //OPERA VERSION | |
| $result['browser_base'] = 'opera'; | |
| $result['browser_icon'] = 'opera'; | |
| $result['browser'] = "Opera $version"; | |
| } | |
| elseif(stripos($str,'chrome') !== false) | |
| { | |
| //Chrome | |
| $pattern = '/chrome\/([A-Za-z0-9\.\-_]+)/i'; | |
| preg_match($pattern,$str,$versions); | |
| $version = $versions[1]; //Chrome VERSION | |
| $result['browser_base'] = 'chrome'; | |
| $result['browser_icon'] = 'chrome'; | |
| $result['browser'] = "Google Chrome $version"; | |
| } | |
| elseif(stripos($str,'webkit') !== false) | |
| { | |
| //Safari | |
| $pattern = '/version\/\\s?([\\d\\.]+)/i'; | |
| preg_match($pattern,$str,$versions); | |
| $version = $versions[1]; //SAFARI VERSION | |
| $result['browser_base'] = 'safari'; | |
| $result['browser_icon'] = 'safari'; | |
| $result['browser'] = "Safari $version"; | |
| } | |
| elseif(stripos($str,'netscape') !== false) | |
| { | |
| //Netscape | |
| $pattern = '/netscape\/([A-Za-z0-9\.\-_]+)/i'; | |
| preg_match($pattern,$str,$versions); | |
| $version = $versions[1]; //Netscape VERSION | |
| $result['browser_base'] = 'netscape'; | |
| $result['browser_icon'] = 'netscape'; | |
| $result['browser'] = "Netscape $version"; | |
| } | |
| else | |
| { | |
| $result['browser_base'] = 'other'; | |
| $result['browser_icon'] = 'other'; | |
| $result['browser'] = 'Unknown'; | |
| } | |
| if(stripos($str,'windows') !== false || stripos($str,'win') !== false) | |
| { | |
| $result['os_base'] = 'windows'; | |
| $result['os_icon'] = $result['os_base']; | |
| if(stripos($str,'win95') !== false) | |
| { | |
| $result['os'] = 'Windows 95'; | |
| $result['os_icon'] .= "_98"; | |
| } | |
| elseif(stripos($str,'win98') !== false) | |
| { | |
| $result['os'] = 'Windows 98'; | |
| $result['os_icon'] .= "_98"; | |
| } | |
| elseif(stripos($str,'windows 98') !== false) | |
| { | |
| $result['os'] = 'Windows 98'; | |
| $result['os_icon'] .= "_98"; | |
| } | |
| elseif(stripos($str,'windows me') !== false) | |
| { | |
| $result['os'] = 'Windows Me'; | |
| $result['os_icon'] .= "_98"; | |
| } | |
| elseif(stripos($str,'win 9x 4.90') !== false) | |
| { | |
| $result['os'] = 'Windows Me'; | |
| $result['os_icon'] .= "_98"; | |
| } | |
| elseif(stripos($str,'nt 5.0') !== false) | |
| { | |
| $result['os'] = 'Windows 2000'; | |
| $result['os_icon'] .= "_98"; | |
| } | |
| elseif(stripos($str,'windows nt 5.1') !== false) | |
| { | |
| $result['os'] = 'Windows XP'; | |
| $result['os_icon'] .= "_xp"; | |
| } | |
| elseif(stripos($str,'nt 5.2') !== false) | |
| { | |
| $result['os'] = 'Windows Server 2003'; | |
| $result['os_icon'] .= "_xp"; | |
| } | |
| elseif(stripos($str,'nt 6.0') !== false) | |
| { | |
| $result['os'] = 'Windows Vista'; | |
| $result['os_icon'] .= "_vista"; | |
| } | |
| elseif(stripos($str,'nt 6.1') !== false) | |
| { | |
| $result['os'] = 'Windows 7'; | |
| $result['os_icon'] .= "_7"; | |
| } | |
| else | |
| { | |
| $result['os'] = 'Windows other version'; | |
| } | |
| } | |
| elseif(stripos($str,'mac') !== false) | |
| { | |
| $result['os_base'] = 'mac'; | |
| $result['os_icon'] = $result['os_base']; | |
| $result['os'] = 'Mac OS X'; | |
| } | |
| elseif(stripos($str,'linux') !== false) | |
| { | |
| $result['os_base'] = 'linux'; | |
| if(stripos($str,'ubuntu') !== false) | |
| { | |
| $result['os'] = 'Ubuntu'; | |
| $result['os_icon'] = 'ubuntu'; | |
| } | |
| elseif(stripos($str,'debian') !== false) | |
| { | |
| $result['os'] = 'Debian'; | |
| $result['os_icon'] = 'debian'; | |
| } | |
| elseif(stripos($str,'red hat') !== false) | |
| { | |
| $result['os'] = 'Red Hat'; | |
| $result['os_icon'] = 'linux'; | |
| } | |
| else | |
| { | |
| $result['os'] = 'Linux'; | |
| $result['os_icon'] = 'linux'; | |
| } | |
| } | |
| elseif(stripos($str,'sonyericsson') !== false) | |
| { | |
| //SonyEricsson | |
| $pattern = '/sonyericsson(.*?)\//i'; | |
| preg_match($pattern,$str,$versions); | |
| $version = $versions[1]; //SonyEricsson MODULE | |
| $result['os_base'] = 'other'; | |
| $result['os_icon'] = 'sonyericsson'; | |
| $result['os'] = "SonyEricsson $version"; | |
| } | |
| else | |
| { | |
| $result['os_base'] = 'other'; | |
| $result['os_icon'] = $result['os_base']; | |
| $result['os'] = 'Unknown'; | |
| } | |
| return $result; | |
| } | |
| session_save_path("session"); | |
| session_start(); | |
| if(strtolower($_SERVER["HTTP_HOST"]) == "mtspc" && $use_same_db) | |
| mysql_connect("mt.aa.am", "mt", "504056"); | |
| else | |
| mysql_connect("localhost", "mt", "504056"); | |
| mysql_select_db("mt_web"); | |
| mysql_query("SET NAMES UTF8"); | |
| @include("xajax/xajax_core/xajax.inc.php"); | |
| $xajax = new xajax(); | |
| $xajax -> setFlag("waitCursor", false); | |
| $xajax -> registerFunction("initData"); | |
| $xajax -> registerFunction("getData"); | |
| $xajax -> registerFunction("sendData"); | |
| function initData($cls) | |
| { | |
| $return = new xajaxResponse(); | |
| if($cls) | |
| $return -> assign( | |
| "data", | |
| "innerHTML", | |
| "<div class=\"welcome\">歡迎使用 mt's Chatroom.</div>\n" | |
| ); | |
| $return -> script("$(\"#input\")[0].disabled = false;"); | |
| $return -> script("$(\"#submit\")[0].disabled = false;\n"); | |
| $return -> script("getData();"); | |
| return $return; | |
| } | |
| function getData($ts, $color, $nick) | |
| { | |
| $return = new xajaxResponse(); | |
| $notify = false; | |
| if($q = mysql_query("SELECT * FROM `chatroom` WHERE `ts` > $ts ORDER BY `ts` ASC")) | |
| while($data = mysql_fetch_array($q)) | |
| { | |
| $t1 = date("H:i:s", $data['ts']); | |
| $t2 = date("Y/m/d H:i:s", $data['ts']); | |
| $ip_r = explode(".", $data['ip']); | |
| $ip = sprintf("%3d.%3d.*.*", $ip_r[0], $ip_r[1]); | |
| $ip = str_replace(" ", "0", $ip); | |
| $ipc = (string)ip2nationcountries($data['ip']); | |
| $ipi = strtoupper((string)ip2nation($data['ip'])); | |
| $reviewers_info = analyse_user_agent($data['ua']); | |
| $return -> append( | |
| "data_msg", | |
| "innerHTML", | |
| "<div class=\"msg\" id=\"msg{$data['id']}\">\n" . | |
| "\t<span class=\"time\" title=\"$t2\">$t1</span>\n" . | |
| "\t<span class=\"ua\">\n" . | |
| "\t\t<img class=\"icon\" src=\"icons/{$reviewers_info['browser_icon']}.png\" title=\"{$reviewers_info['browser']}\" alt=\"{$reviewers_info['browser']}\" />\n" . | |
| "\t\t<img class=\"icon\" src=\"icons/{$reviewers_info['os_icon']}.png\" title=\"{$reviewers_info['os']}\" alt=\"{$reviewers_info['os']}\" />\n" . | |
| "\t</span>\n" . | |
| "\t<span class=\"ip\" title=\"$ipc\">\n" . | |
| "\t\t<img class=\"flag\" src=\"flags/$ipi.png\" alt=\"$ipi\" />\n" . | |
| "\t\t$ip\n" . | |
| "\t</span>\n" . | |
| "\t<span class=\"nickname\" onclick=\"reply('" . strip_tags($data['nick']) . "');\" title=\"按此回覆\">" . strip_tags($data['nick']) . ": </span>\n" . | |
| "\t<span class=\"message\" style=\"color: {$data['color']};\">" . bbs(str_replace("<", "<", $data['msg'])) . "</span>\n" . | |
| "</div>\n" | |
| ); | |
| $ts = $data['ts']; | |
| $notify = true; | |
| } | |
| if($notify) | |
| $return -> script("/*$.sound.play('message.wav');*/") | |
| -> script("showById(\"bottom_span\");"); | |
| $return -> script("gotData();"); | |
| $return -> script("setTimeout(function() { getData(); }, 1000);"); | |
| $return -> assign("ts", "innerHTML", $ts); | |
| $online = getOnlineNo(); | |
| $return -> assign("online_no", "innerHTML", $online); | |
| if($online == 1) | |
| $return -> assign("online_s", "innerHTML", ""); | |
| else | |
| $return -> assign("online_s", "innerHTML", ""); | |
| $_SESSION['ts'] = time(); | |
| if(!empty($_SERVER['HTTP_CLIENT_IP'])) | |
| $_SESSION['ip'] = $_SERVER['HTTP_CLIENT_IP']; | |
| else | |
| if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) | |
| $_SESSION['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
| else | |
| $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; | |
| $_SESSION['ua'] = $_SERVER["HTTP_USER_AGENT"]; | |
| $_SESSION['color'] = $color; | |
| $_SESSION['nick'] = $nick; | |
| $sid = $_COOKIE["PHPSESSID"]; | |
| if(mysql_fetch_array(mysql_query("SELECT `ts` FROM `chatroom_sess` WHERE `sid` = '" . mysql_real_escape_string($sid) . "' LIMIT 1"))) | |
| $q1 = mysql_query("UPDATE `chatroom_sess` SET " . | |
| "`color` = '" . mysql_real_escape_string($_SESSION['color']) . "', " . | |
| "`nick` = '" . mysql_real_escape_string($_SESSION['nick']) . "', " . | |
| "`ip` = '" . mysql_real_escape_string($_SESSION['ip']) . "', " . | |
| "`ua` = '" . mysql_real_escape_string($_SESSION['ua']) . "', " . | |
| "`ts` = {$_SESSION['ts']} WHERE `sid` = '" . mysql_real_escape_string($sid) . "' LIMIT 1"); | |
| else | |
| $q2 = mysql_query("INSERT INTO `chatroom_sess` (`sid`, `color`, `nick`, `ip`, `ua`, `ts`) VALUES (" . | |
| "'" . mysql_real_escape_string($sid) . "', " . | |
| "'" . mysql_real_escape_string($_SESSION['color']) . "', " . | |
| "'" . mysql_real_escape_string($_SESSION['nick']) . "', " . | |
| "'" . mysql_real_escape_string($_SESSION['ip']) . "', " . | |
| "'" . mysql_real_escape_string($_SESSION['ua']) . "', " . | |
| "{$_SESSION['ts']})"); | |
| $return -> assign("online_list", "innerHTML", getOnlineList()); | |
| return $return; | |
| } | |
| function sendData($color, $nick, $msg) | |
| { | |
| $return = new xajaxResponse(); | |
| if(!empty($_SERVER['HTTP_CLIENT_IP'])) | |
| $ip = $_SERVER['HTTP_CLIENT_IP']; | |
| else | |
| if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) | |
| $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
| else | |
| $ip = $_SERVER['REMOTE_ADDR']; | |
| $ip = mysql_real_escape_string($ip); | |
| $ua = mysql_real_escape_string($_SERVER["HTTP_USER_AGENT"]); | |
| $color = mysql_real_escape_string($color); | |
| $nick = mysql_real_escape_string($nick); | |
| $msg = mysql_real_escape_string($msg); | |
| mysql_query( | |
| "INSERT INTO `chatroom` " . | |
| "(`nick`, `color`, `msg`, `ip`, `ua`, `ts`) VALUES " . | |
| "('$nick', '$color', '$msg', '$ip', '$ua', " . (string)time() . ")" | |
| ); | |
| $return -> assign("input", "value", ""); | |
| $return -> script("sentData();"); | |
| return $return; | |
| } | |
| $xajax -> processRequest(); | |
| header("content-type: text/html; chatset=utf-8"); | |
| ?> | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>mt's Chatroom</title> | |
| <link rel="shortcut icon" href="/html5/favicon.ico" /> | |
| <meta http-equiv="content-type" content="text/html;charset=utf-8" /> | |
| <?php if(!(stripos($_SERVER['HTTP_USER_AGENT'], 'SonyEricssonU1i') !== false) && !(stripos($_SERVER['HTTP_USER_AGENT'], 'SymbOS') !== false)) { ?><link rel="stylesheet" href="style.css" /><?php } else { ?><link rel="stylesheet" href="style-mobile.css" /><?php } ?> | |
| <script type="text/javascript" charset="UTF-8"> | |
| /* <![CDATA[ */ | |
| try { if(undefined == xajax.config) xajax.config = {}; } catch (e) { xajax = {}; xajax.config = {}; }; | |
| xajax.config.requestURI = "http://<?php echo($_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]) ?>"; | |
| xajax.config.statusMessages = false; | |
| xajax.config.waitCursor = false; | |
| xajax.config.version = "xajax 0.5"; | |
| xajax.config.legacy = false; | |
| xajax.config.defaultMode = "asynchronous"; | |
| xajax.config.defaultMethod = "POST"; | |
| /* ]]> */ | |
| </script> | |
| <script type="text/javascript" src="xajax/xajax_js/xajax_core.js" charset="UTF-8"></script> | |
| <script type="text/javascript" charset="UTF-8"> | |
| /* <![CDATA[ */ | |
| window.setTimeout( | |
| function() { | |
| var scriptExists = false; | |
| try { if(xajax.isLoaded) scriptExists = true; } | |
| catch (e) {} | |
| if(!scriptExists) { | |
| document.getElementById("data").innerHTML = '<div class="error">xajax 發生錯誤!</div>'; | |
| } | |
| }, 2000); | |
| /* ]]> */ | |
| </script> | |
| <script type='text/javascript' charset='UTF-8'> | |
| /* <![CDATA[ */ | |
| xajax_initData = function() { return xajax.request( { xjxfun: 'initData' }, { parameters: arguments } ); }; | |
| xajax_getData = function() { return xajax.request( { xjxfun: 'getData' }, { parameters: arguments } ); }; | |
| xajax_sendData = function() { return xajax.request( { xjxfun: 'sendData' }, { parameters: arguments } ); }; | |
| /* ]]> */ | |
| </script> | |
| <script src="/file/script/jq.js"></script> | |
| <script src="jquery.sound.js"></script> | |
| <script> | |
| function initChatroom() | |
| { | |
| if(<?php echo(isset($old)? "false": "true"); ?>) | |
| { | |
| /*if(confirm("Do you want to load old messages?\n(It may takes more time!)")) | |
| { | |
| self.location = "./?old"; | |
| }*/ | |
| xajax_initData(true); | |
| $("#getting")[0].style.visibility = "visible"; | |
| } | |
| else | |
| xajax_initData(false); | |
| } | |
| function inputBox(q) | |
| { | |
| $("#input")[0].disabled = !q; | |
| $("#submit")[0].disabled = !q; | |
| } | |
| function getData() | |
| { | |
| $("#getting")[0].style.visibility = "visible"; | |
| (xajax_getData($("#ts")[0].innerHTML, $("#color")[0].value, $("#nick")[0].value)); | |
| } | |
| function gotData() | |
| { | |
| $("#getting")[0].style.visibility = "hidden"; | |
| } | |
| function gotDataError() | |
| { | |
| alert('從伺服器載入資料時發生錯誤!\n請按下粉紅色的圖片重新載入。'); | |
| } | |
| function sendData() | |
| { | |
| if($("#input")[0].value != "") | |
| { | |
| inputBox(false); | |
| $("#sending")[0].style.visibility = "visible"; | |
| xajax_sendData($("#color")[0].value, $("#nick")[0].value, $("#input")[0].value); | |
| } | |
| } | |
| function sentData() | |
| { | |
| inputBox(true); | |
| $("#sending")[0].style.visibility = "hidden"; | |
| } | |
| function sentData_error() | |
| { | |
| inputBox(true); | |
| $("#sending")[0].style.visibility = "hidden"; | |
| alert('送出資料至伺服器時發生錯誤!\n請按下淡黃色的圖片重新送出資料。'); | |
| } | |
| function reply(nick) | |
| { | |
| i = $('#input')[0]; | |
| i.value = "@" + nick + ": " + i.value; | |
| setCaretPosition(i, i.value.length); | |
| } | |
| function setCaretPosition(ctrl, pos) | |
| { | |
| if(ctrl.setSelectionRange) | |
| { | |
| ctrl.focus(); | |
| ctrl.setSelectionRange(pos, pos); | |
| } | |
| else | |
| if(ctrl.createTextRange) { | |
| var range = ctrl.createTextRange(); | |
| range.collapse(true); | |
| range.moveEnd('character', pos); | |
| range.moveStart('character', pos); | |
| range.select(); | |
| } | |
| } | |
| function addText(h,f) | |
| { | |
| i = $("#input")[0]; | |
| if(document.selection) | |
| { | |
| i.focus(); | |
| sel = document.selection.createRange(); | |
| sel.text = h + sel.text + f; | |
| i.focus(); | |
| } | |
| else | |
| if(i.selectionStart || i.selectionStart == '0') | |
| { | |
| var startPos = i.selectionStart; | |
| var endPos = i.selectionEnd; | |
| var cursorPos = endPos; | |
| i.value = i.value.substring(0, startPos) | |
| + h + i.value.substring(startPos, endPos) + f | |
| + i.value.substring(endPos, i.value.length); | |
| cursorPos += h.length + endPos - startPos; | |
| i.focus(); | |
| i.selectionStart = cursorPos; | |
| i.selectionEnd = cursorPos; | |
| } | |
| else | |
| { | |
| i.value += h + f; | |
| i.focus(); | |
| } | |
| } | |
| function setCookie(n, v) | |
| { | |
| now = new Date(); | |
| now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 365); | |
| document.cookie = n + "=" + v + "; expires=" + now.toGMTString(); | |
| } | |
| function showById(id) | |
| { | |
| $("#" + id)[0].scrollIntoView(); | |
| } | |
| function showByClass(className) | |
| { | |
| $("." + className)[0].scrollIntoView(); | |
| } | |
| $(document).ready(function() { | |
| inputBox(false); | |
| $(".online_list_outer").hide(); | |
| $("#out").hide(); | |
| $("#color").change(function() { | |
| this.style.background = this.value; | |
| this.style.color = this.value; | |
| $("#input")[0].style.color = this.value; | |
| }); | |
| $("#submit").click(function() { | |
| sendData(); | |
| }); | |
| $("#input").keypress(function(e) { | |
| if(e.which == 13) | |
| sendData(); | |
| }); | |
| $("#nick").change(function() { | |
| setCookie("nickname", escape($("#nick")[0].value)); | |
| }).keypress(function() { | |
| setCookie("nickname", escape($("#nick")[0].value)); | |
| });<?php | |
| if(isset($_COOKIE['nickname'])) | |
| { | |
| ?> | |
| $("#nick")[0].value = unescape("<?php echo($_COOKIE['nickname']); ?>"); | |
| setCookie("nickname", escape($("#nick")[0].value)); | |
| <?php | |
| } | |
| ?> | |
| $("#color").change(function() { | |
| setCookie("color", escape($("#color")[0].value)); | |
| }).keypress(function() { | |
| setCookie("color", escape($("#color")[0].value)); | |
| });<?php | |
| if(isset($_COOKIE['color'])) | |
| { | |
| ?> | |
| $("#color")[0].value = unescape("<?php echo($_COOKIE['color']); ?>"); | |
| setCookie("color", escape($("#color")[0].value)); | |
| $("#color")[0].style.background = $("#color")[0].value; | |
| $("#color")[0].style.color = $("#color")[0].value; | |
| $("#input")[0].style.color = $("#color")[0].value; | |
| <?php | |
| } | |
| ?> | |
| setTimeout(function() { | |
| $('.online_list_outer').fadeIn('slow'); | |
| showById("bottom_span"); | |
| }, 2000); | |
| setTimeout(function() { | |
| initChatroom(); | |
| }, 800); | |
| setTimeout(function() { | |
| $('#out').fadeIn('slow'); | |
| }, 500); | |
| setTimeout(function() { | |
| $(".background").fadeOut('slow'); | |
| }, 200); | |
| $("#setting").hide(); | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <div class="background"> </div> | |
| <span id="ts" style="display: none;"><?php echo($cls? time(): 0); ?></span> | |
| <div id="out"> | |
| <div id="data"> | |
| <span id="data_msg"> | |
| <span id="top_span"></span> | |
| <?php if(isset($old)) { ?><div class="welcome">歡迎使用 mt's Chatroom</div> | |
| <?php | |
| if($q = mysql_query("SELECT * FROM `chatroom` ORDER BY `ts` ASC")) | |
| while($data = mysql_fetch_array($q)) | |
| { | |
| $t1 = date("H:i:s", $data['ts']); | |
| $t2 = date("Y/m/d H:i:s", $data['ts']); | |
| $ip_r = explode(".", $data['ip']); | |
| $ip = sprintf("%3d.%3d.*.*", $ip_r[0], $ip_r[1]); | |
| $ip = str_replace(" ", "0", $ip); | |
| $ipc = (string)ip2nationcountries($data['ip']); | |
| $ipi = strtoupper((string)ip2nation($data['ip'])); | |
| $reviewers_info = analyse_user_agent($data['ua']); | |
| echo( | |
| "\t\t\t\t\t<div class=\"msg\" id=\"msg{$data['id']}\">\n" . | |
| "\t\t\t\t\t\t<span class=\"time\" title=\"$t2\">$t1</span>\n" . | |
| "\t\t\t\t\t\t<span class=\"ua\">\n" . | |
| "\t\t\t\t\t\t\t<img class=\"icon\" src=\"icons/{$reviewers_info['browser_icon']}.png\" title=\"{$reviewers_info['browser']}\" alt=\"{$reviewers_info['browser']}\" />\n" . | |
| "\t\t\t\t\t\t\t<img class=\"icon\" src=\"icons/{$reviewers_info['os_icon']}.png\" title=\"{$reviewers_info['os']}\" alt=\"{$reviewers_info['os']}\" />\n" . | |
| "\t\t\t\t\t\t</span>\n" . | |
| "\t\t\t\t\t\t<span class=\"ip\" title=\"$ipc\">\n" . | |
| "\t\t\t\t\t\t\t<img class=\"flag\" src=\"flags/$ipi.png\" alt=\"$ipi\" />\n" . | |
| "\t\t\t\t\t\t\t$ip\n" . | |
| "\t\t\t\t\t\t</span>\n" . | |
| "\t\t\t\t\t\t<span class=\"nickname\" onclick=\"reply('" . strip_tags($data['nick']) . "');\" title=\"按此回覆\">" . strip_tags($data['nick']) . ": </span>\n" . | |
| "\t\t\t\t\t\t<span class=\"message\" style=\"color: {$data['color']};\">" . bbs(str_replace("<", "<", $data['msg'])) . "</span>\n" . | |
| "\t\t\t\t\t</div>\n"); | |
| } | |
| if(isset($lastmsg)) | |
| echo("\t\t\t\t\t<script>$(function(){showById(\"bottom_span\");});</script>\n"); | |
| } else { ?><div class="init">聊天室正在初始化,請稍候…</div><?php } echo("\n"); ?> | |
| </span> | |
| <span id="bottom_span">目前有 <span id="online_no">0</span> 位使用者在聊天室中</span> | |
| </div> | |
| <div id="btn"> | |
| <label> | |
| 顏色: | |
| <select id="color" style="color: #CCC; background: #CCC"> | |
| <!--option style="color: #000; background: #000" value="#000000">#000000</option--> | |
| <option style="color: #CCC; background: #CCC" value="#CCCCCC">#CCCCCC</option> | |
| <option style="color: #C00; background: #C00" value="#CC0000">#CC0000</option> | |
| <option style="color: #0C0; background: #0C0" value="#00CC00">#00CC00</option> | |
| <option style="color: #00C; background: #00C" value="#0000CC">#0000CC</option> | |
| <option style="color: #CC0; background: #CC0" value="#CCCC00">#CCCC00</option> | |
| <option style="color: #C0C; background: #C0C" value="#CC00CC">#CC00CC</option> | |
| <option style="color: #0CC; background: #0CC" value="#00CCCC">#00CCCC</option> | |
| <option style="color: #F00; background: #F00" value="#FF0000">#FF0000</option> | |
| <option style="color: #0F0; background: #0F0" value="#00FF00">#00FF00</option> | |
| <option style="color: #00F; background: #00F" value="#0000FF">#0000FF</option> | |
| <option style="color: #FF0; background: #FF0" value="#FFFF00">#FFFF00</option> | |
| <option style="color: #F0F; background: #F0F" value="#FF00FF">#FF00FF</option> | |
| <option style="color: #0FF; background: #0FF" value="#00FFFF">#00FFFF</option> | |
| <option style="color: #FCC; background: #FCC" value="#FFCCCC">#FFCCCC</option> | |
| <option style="color: #CFC; background: #CFC" value="#CCFFCC">#CCFFCC</option> | |
| <option style="color: #CCF; background: #CCF" value="#CCCCFF">#CCCCFF</option> | |
| <option style="color: #FFC; background: #FFC" value="#FFFFCC">#FFFFCC</option> | |
| <option style="color: #FCF; background: #FCF" value="#FFCCFF">#FFCCFF</option> | |
| <option style="color: #CFF; background: #CFF" value="#CCFFFF">#CCFFFF</option> | |
| <option style="color: #FFF; background: #FFF" value="#FFFFFF">#FFFFFF</option> | |
| </select> | |
| </label> | |
| <label> | |
| 暱稱: | |
| <input id="nick" size="20" style="color: #CFC; background: #000;" /> | |
| </label> | |
| <label> | |
| 訊息: | |
| <input id="input" size="50" style="color: #CCC; background: #000;" /> | |
| </label> | |
| <input id="submit" type="button" value="Send" /> | |
| <span id="sending" style="visibility: hidden;"> | |
| <img src="sending.gif" alt="送出資料" onclick="sendData();" /> | |
| </span> | |
| <span id="getting" style="visibility: hidden;"> | |
| <img src="getting.gif" alt="載入資料" onclick="getData();" /> | |
| </span> | |
| </div> | |
| <div id="bbs"> | |
| <a href="javascript:addText('[b]', '[/b]');">粗體</a> | | |
| <a href="javascript:addText('[u]', '[/u]');">底線</a> | | |
| <a href="javascript:addText('[i]', '[/i]');">斜體</a> | | |
| <a href="javascript:addText('[url]', '[/url]');">網址</a> | | |
| <a href="javascript:addText('[img]', '[/img]');">圖片</a> | | |
| <a href="javascript:addText('[youtube]', '[/youtube]');">YouTube</a> | |
| <br /> | |
| <a href="javascript:showById('top_span');">Top</a> | | |
| <a href="javascript:showById('bottom_span');">Bottom</a> | |
| </div> | |
| <div id="copy"> | |
| Copyright © 2010-2011 Ming Tsay. All rights reserved.<br /> | |
| Hosted by <a href="http://dehit.aa.am" target="_blank" title="另開新視窗">DEHIT Group</a>. | |
| </div> | |
| </div> | |
| <div id="setting">[Setting] Load old messages: On; Timeout: <?php echo(MT_TIMEOUT); ?>;</div> | |
| <div id="online"> | |
| <div style="display: none;"> | |
| 目前有 | |
| <span> | |
| 0 | |
| </span> | |
| 位使用者<span id="online_s"></span>在聊天室中 | |
| </div> | |
| <div> | |
| <a href="javascript:;" onclick="$('.online_list_outer').fadeIn('slow');"> | |
| 按此顯示聊天室名單 | |
| </a> | |
| </div> | |
| </div> | |
| <div class="online_list_outer"> | |
| <div id="online_list"></div> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment