diff --git a/chat.php b/chat.php index 9dd928395..c4659e125 100644 --- a/chat.php +++ b/chat.php @@ -1,5 +1,6 @@ - + + + + + busyTimeout(5000) ) + { + if( $db->exec("PRAGMA journal_mode = wal;") ) + { + $logtable = "CREATE TABLE IF NOT EXISTS chatpack_log + (id INTEGER PRIMARY KEY, + timestamp INTEGER NOT NULL, + user TEXT NOT NULL, + avatar TEXT NOT NULL, + message TEXT NOT NULL, + liked INTEGER DEFAULT 0)"; + + if( $db->exec($logtable) ) + { + $usertable = "CREATE TABLE IF NOT EXISTS chatpack_typing + (id INTEGER PRIMARY KEY, + timestamp INTEGER NOT NULL, + user TEXT NOT NULL)"; + + if( $db->exec($usertable) ) + { + $dbcreated = true; + } + else + { + errormessage("creating database table for typing"); + } + } + else + { + errormessage("creating database table for messages"); + } + + if( !$db->close() ) + { + errormessage("closing database connection"); + } + } + else + { + errormessage("setting journal mode"); + } + } + else + { + errormessage("setting busy timeout"); + } + } + else + { + errormessage("using SQLite"); + } + + if( $dbcreated ) + { + + ?> +

@@ -133,26 +205,47 @@

Welcome To The Chat username;?>

-
+
+
+
+

start chatting...
+
    +
    -
    - -
    + + + +
    + + "; + echo "error "; + echo $msg; + echo ""; + } + + ?> - - + - + \ No newline at end of file diff --git a/chat/audio/newmessage.mp3 b/chat/audio/newmessage.mp3 new file mode 100644 index 000000000..dac28fee6 Binary files /dev/null and b/chat/audio/newmessage.mp3 differ diff --git a/chat/checkuser.php b/chat/checkuser.php new file mode 100644 index 000000000..c69833b89 --- /dev/null +++ b/chat/checkuser.php @@ -0,0 +1,66 @@ +busyTimeout(5000) ) + { + if( $db->exec("PRAGMA journal_mode = wal;") ) + { + if( $result = @$db->query("SELECT timestamp, user FROM chatpack_log + WHERE LOWER(user)= LOWER('$user') ORDER BY id DESC") ) + { + if( $row = $result->fetchArray() ) + { + $timestamp = $row["timestamp"]; + $timenow = time(); + + if( $timestamp < $timenow - 2700 ) // user's last message too old means user offline + { + echo "success"; + } + else // user's last message young enough means user still online + { + echo "usernametaken"; + } + } + else // username available + { + echo "success"; + } + } + else + { + errormessage("querying database while checking user"); + } + + if( !@$db->close() ) + { + errormessage("closing database connection after checking user"); + } + } + else + { + errormessage("setting journal mode"); + } + } + else + { + errormessage("setting busy timeout"); + } +} +else +{ + errormessage("using SQLite"); +} + +function errormessage($msg) +{ + echo "
    "; + echo "error "; + echo $msg; + echo "
    "; +} + +?> \ No newline at end of file diff --git a/chat/connect.php b/chat/connect.php new file mode 100644 index 000000000..ae828fb25 --- /dev/null +++ b/chat/connect.php @@ -0,0 +1,7 @@ +busyTimeout(5000); +$db->exec("PRAGMA journal_mode = wal;"); + +?> \ No newline at end of file diff --git a/chat/getlikes.php b/chat/getlikes.php new file mode 100644 index 000000000..7376b1489 --- /dev/null +++ b/chat/getlikes.php @@ -0,0 +1,36 @@ +query("SELECT id, liked FROM chatpack_log") ) +{ + while( $row = $result->fetchArray() ) + { + $messageid = $row["id"]; + $liked = $row["liked"]; + + if( $liked == 1 ) + { + array_push($likedmessages, $messageid); + } + else if( $liked == 0 ) + { + array_push($unlikedmessages, $messageid); + } + } +} + +$db->close(); + +// pass likes and unlikes back to chat.js + +$likes = json_encode($likedmessages); +$unlikes = json_encode($unlikedmessages); +$likesandunlikes = $likes . "#" . $unlikes; + +echo $likesandunlikes; + +?> \ No newline at end of file diff --git a/chat/gettyping.php b/chat/gettyping.php new file mode 100644 index 000000000..2514f0d63 --- /dev/null +++ b/chat/gettyping.php @@ -0,0 +1,23 @@ +query("SELECT user FROM chatpack_typing") ) +{ + while( $row = $result->fetchArray() ) + { + $user = $row["user"]; + + array_push($typingusers, $user); + } +} + +$db->close(); + +// pass typing users as JSON back to chat.js + +echo json_encode($typingusers); + +?> \ No newline at end of file diff --git a/chat/img/favicon.ico b/chat/img/favicon.ico new file mode 100644 index 000000000..677cfd53b Binary files /dev/null and b/chat/img/favicon.ico differ diff --git a/chat/img/like.png b/chat/img/like.png new file mode 100644 index 000000000..ac8c16a41 Binary files /dev/null and b/chat/img/like.png differ diff --git a/chat/logmessage.php b/chat/logmessage.php new file mode 100644 index 000000000..3f61ea4e7 --- /dev/null +++ b/chat/logmessage.php @@ -0,0 +1,46 @@ + 0 ) +{ + $timestamp = time(); + $message = utf8_decode($message); + + if( !stristr($message, "specialcharemoticon") ) // only encrypt text message + { + $message = encryptmessage($message); + } + + // log message + + $db->exec("INSERT INTO chatpack_log (timestamp, user, avatar, message) + VALUES ('$timestamp', '$user', '$avatar', '$message')"); +} + +function encryptmessage($msg) +{ + $key = "OEFKSjczdG5JWkFITHZNUmFLT1I4aWRWaVVWY3l1SXdJZ285V2R3Ri90QjF4NUU1VG9mNnM + wcDRYWTQ1dEtRRXRYNlFWZE01QW1WS0hTNXZzaEtRbEdkcXY4cWpEOVRBYjBzSGJlRXVPWW + 9aWUtzNGZtK1BnRzRPeXk4ZWY0VUphUjc5VzRGQ2s0UXRrNENOWERJWmM3SWNFSEtpM0hpcT + l2UVRET2UrMkxQR29ONVpOVDRnSHArTGVwQU15NXg4YzdNSWZQTlBOd2FlWmY2aWRQOUdSZVh + 3VXQ4a1JlNDkwMWZIVE42cmpIMkRrUkg1VnF1NC9zMmhTZFROVnNleVlSTnVvcWtDYlB3TEJU + eDlRT3ZPZVQ2N0psT0NFNW5nekFCdG9xLzZ6K0Qva1V5UzNoVlAxWGt1ZittZnE5ek10Q2x4Q1 + QrdHVRdEVoYUIxc2V1UjgrZDZyK1Zzem9LOEtpSG9halczNEpmem5nRWllSDBaRzNERHBTbUxB + MGlodTZsclFEVzZLcjVBNEtYRUpxQXVNaEcycGN4U2VzT01NRlljM3pHL3Q1az0"; + $initvector = "aC92eG1PdGhuMXN6"; + $encryptedmessage = openssl_encrypt($msg, "AES-256-CBC", $key, 0, $initvector); + $encryptedmessage = utf8_decode($encryptedmessage); + + return $encryptedmessage; +} + +$db->close(); + +?> \ No newline at end of file diff --git a/chat/php.ini b/chat/php.ini new file mode 100644 index 000000000..6af19ff70 --- /dev/null +++ b/chat/php.ini @@ -0,0 +1,2 @@ +post_max_size = 15M +upload_max_filesize = 10M \ No newline at end of file diff --git a/chat/refreshmessages.php b/chat/refreshmessages.php new file mode 100644 index 000000000..70f929ffc --- /dev/null +++ b/chat/refreshmessages.php @@ -0,0 +1,149 @@ +query("SELECT * FROM + (SELECT id, timestamp, user, avatar, message + FROM chatpack_log ORDER BY id DESC LIMIT 250) + ORDER BY id ASC") ) +{ + $newmessages = array(); + + while( $row = $result->fetchArray() ) + { + $id = $row["id"]; + $timestamp = $row["timestamp"]; + $user = $row["user"]; + $avatar = $row["avatar"]; + $message = $row["message"]; + + $timenow = time(); + $messagetime = date("h:i", intval($timestamp)); + $messagedate = date("m-d", intval($timestamp)); + $message = utf8_encode($message); + + $msgstr = ""; // message components + + if( strlen($user) > 0 && strlen($message) > 0 ) + { + // catch emoticon + + $emoticon = false; + + if( stristr($message, "specialcharemoticon") ) + { + $emoticonid = substr($message, 11); + $message = ""; + $emoticon = true; + } + + // catch image + + $image = false; + + if( stristr($message, "specialcharimg") ) + { + $imagename = substr($message, 14); + $message = ""; + $image = true; + + $endingpos = strpos($imagename, "."); + $originalname = substr($imagename, 0, $endingpos-1); + $ending = substr($imagename, $endingpos+1); + $originalimg = $originalname . "." . $ending; + } + + if( !$emoticon && !$image ) + { + $message = decryptmessage($message); + } + + // catch URLs + + $message = str_replace("https://", "http://", $message); + + if( !stristr($message, "http://www.") ) + { + $message = str_replace("www.", "http://www.", $message); + } + + $message = preg_replace("!((http|ftp)(s)?:\/\/)(www\.)?[a-zA-Z0-9.?&_/=\-\%\:,\#\+]+!", + "$0", $message); + $message = str_replace("target=\"_blank\">http://", "target=\"_blank\">", $message); + + // catch highlightings + + $message = preg_replace("/\*{3}(.*?)\*{3}/", "$1", $message); + $message = preg_replace("/\*{2}(.*?)\*{2}/", + "$1", $message); + $message = preg_replace("/\*(.*?)\*/", + "$1", $message); + + // user online avatar + + //$avatar = ""; + + // unique message key + + $keystring = $timestamp . $user . $messagetime . $message . $id; + $messagekey = md5($keystring); + + // show user avatar and message + if($user == $currentuser){ + $msgstr = $msgstr . "

  • \"$user\"

    $user

    $messagedate $messagetime

    $message
    \"like\"
  • ";//class="chat-inverted" + }else{ + $msgstr = $msgstr . "

  • \"$user\"

    $user

    $messagedate $messagetime

    $message
    \"like\"
  • ";//class="chat-inverted" + } + + array_push($newmessages, $msgstr); + } + } +} + +$db->close(); + +function decryptmessage($msg) +{ + $key = "OEFKSjczdG5JWkFITHZNUmFLT1I4aWRWaVVWY3l1SXdJZ285V2R3Ri90QjF4NUU1VG9mNnM + wcDRYWTQ1dEtRRXRYNlFWZE01QW1WS0hTNXZzaEtRbEdkcXY4cWpEOVRBYjBzSGJlRXVPWW + 9aWUtzNGZtK1BnRzRPeXk4ZWY0VUphUjc5VzRGQ2s0UXRrNENOWERJWmM3SWNFSEtpM0hpcT + l2UVRET2UrMkxQR29ONVpOVDRnSHArTGVwQU15NXg4YzdNSWZQTlBOd2FlWmY2aWRQOUdSZVh + 3VXQ4a1JlNDkwMWZIVE42cmpIMkRrUkg1VnF1NC9zMmhTZFROVnNleVlSTnVvcWtDYlB3TEJU + eDlRT3ZPZVQ2N0psT0NFNW5nekFCdG9xLzZ6K0Qva1V5UzNoVlAxWGt1ZittZnE5ek10Q2x4Q1 + QrdHVRdEVoYUIxc2V1UjgrZDZyK1Zzem9LOEtpSG9halczNEpmem5nRWllSDBaRzNERHBTbUxB + MGlodTZsclFEVzZLcjVBNEtYRUpxQXVNaEcycGN4U2VzT01NRlljM3pHL3Q1az0"; + $initvector = "aC92eG1PdGhuMXN6"; + $decryptedmessage = openssl_decrypt($msg, "AES-256-CBC", $key, 0, $initvector); + $decryptedmessage = utf8_encode($decryptedmessage); + + return $decryptedmessage; +} + +// pass new messages back to chat.js + +if( count($newmessages) == 1 ) +{ + echo $newmessages[0]; +} +else +{ + for( $i=0; $i \ No newline at end of file diff --git a/chat/setlike.php b/chat/setlike.php new file mode 100644 index 000000000..63e2e38a5 --- /dev/null +++ b/chat/setlike.php @@ -0,0 +1,41 @@ +query("SELECT liked FROM chatpack_log WHERE id='$messageid'") ) +{ + if( $row = $result->fetchArray() ) + { + $liked = $row["liked"]; + + if( $liked == 0 ) + { + $likemessage = true; + } + else if( $liked == 1 ) + { + $likemessage = false; + } + } +} + +$db->close(); + +include("connect.php"); + +if( $likemessage ) // like message +{ + $db->exec("UPDATE chatpack_log SET liked='1' WHERE id='$messageid'"); +} +else // unlike message +{ + $db->exec("UPDATE chatpack_log SET liked='0' WHERE id='$messageid'"); +} + +$db->close(); + +?> \ No newline at end of file diff --git a/chat/settyping.php b/chat/settyping.php new file mode 100644 index 000000000..dbcfe722f --- /dev/null +++ b/chat/settyping.php @@ -0,0 +1,58 @@ +query("SELECT timestamp, user FROM chatpack_typing") ) +{ + while( $row = $result->fetchArray() ) + { + $typinguser = $row["user"]; + $timestamp = $row["timestamp"]; + + // check whether user is currently typing + + if( strcmp($typinguser, $user) == 0 ) + { + $useristyping = true; + } + + // catch users who are offline but still set as typing + + $timenow = time(); + + if( $timestamp < $timenow - 2700 ) + { + array_push($offlineusers, $typinguser); + } + } +} + +if( !$useristyping && $settyping == 1 ) // set user as typing +{ + $timestamp = time(); + + $db->exec("INSERT INTO chatpack_typing (timestamp, user) VALUES ('$timestamp', '$user')"); +} +else if( $settyping == 0 ) // set user as not typing +{ + $db->exec("DELETE FROM chatpack_typing WHERE user='$user'"); +} + +// set offline users as not typing + +for( $i=0; $iexec("DELETE FROM chatpack_typing WHERE user='$offlineusers[$i]'"); +} + +$db->close(); + +?> \ No newline at end of file diff --git a/chat/uploadimage.php b/chat/uploadimage.php new file mode 100644 index 000000000..d06f743cf --- /dev/null +++ b/chat/uploadimage.php @@ -0,0 +1,177 @@ + 0 && strlen($imagename) > 0 && $size > 0 && $uploaddirexists ) +{ + if( ($type == "image/gif") || ($type == "image/jpeg") || ($type == "image/jpg") || ($type == "image/png") ) + { + if( $size < 5000000 ) + { + if( $_FILES["image"]["error"] == 0 ) + { + if( !file_exists($path) ) + { + if( copy($tempname, $path) ) // upload image + { + // thumbnail + + $sizedata = getimagesize($tempname); + + if( $type == "image/gif" ) + { + $imagetoupload = @imagecreatefromgif($tempname); + } + elseif( $type == "image/jpeg" || $type == "image/jpg" ) + { + $imagetoupload = @imagecreatefromjpeg($tempname); + } + elseif( $type == "image/png" ) + { + $imagetoupload = @imagecreatefrompng($tempname); + } + + if( $imagetoupload ) // imagecreatefromX + { + $width = imagesx($imagetoupload); + $height = imagesy($imagetoupload); + $div = $width / $height; + $newwidth = 150; + $newheight = 150 / $div; + + $newimage = @imageCreateTrueColor($newwidth, $newheight); + + if( $newimage ) // imagecreatetruecolor + { + // upload thumbnail + + $imagecopy = @imagecopyresized($newimage, $imagetoupload, 0, 0, 0, 0, + $newwidth, $newheight, $sizedata[0], $sizedata[1]); + + if( $imagecopy ) // imagecopyresized + { + if( $type == "image/gif" ) + { + $img = @imagegif($newimage, $thumbpath); + } + elseif( $type == "image/jpeg" || $type1 == "image/jpg" ) + { + $img = @imagejpeg($newimage, $thumbpath); + } + elseif( $type == "image/png" ) + { + $img = @imagepng($newimage, $thumbpath); + } + + if( $img ) // imageX + { + @imagedestroy($newimage); + + // db entry + + include("connect.php"); + + $timestamp = time(); + $message = "specialcharimg" . $thumbname; + + if( !$db->exec("INSERT INTO chatpack_log (timestamp, user, avatar, message) + VALUES ('$timestamp', '$user', '$avatar', '$message')") ) + { + cleanup($path, $thumbpath, $filename); // clean up on error + } + + $db->close(); + } + } + } + } + } + else // error upload + { + cleanup($path, $thumbpath, $filename); + } + } + else // error exists + { + cleanup($path, $thumbpath, $filename); + } + } + } + else // error size + { + cleanup($path, $thumbpath, $filename); + } + } + else // error type + { + cleanup($path, $thumbpath, $filename); + } +} + +function cleanup($path, $thumbpath, $filename) +{ + // delete image + + if( file_exists($path) ) + { + unlink($path); + } + + // delete thumbnail + + if( file_exists($thumbpath) ) + { + unlink($thumbpath); + } + + // delete db entry + + include("connect.php"); + + $message = "specialcharimg" . $thumbname; + $db->exec("DELETE FROM chatpack_log WHERE message='$message'"); + + $db->close(); +} + +?> \ No newline at end of file diff --git a/chatjs.php b/chatjs.php index df64b556e..f94b715f0 100644 --- a/chatjs.php +++ b/chatjs.php @@ -4,6 +4,10 @@ $userpic = md5( strtolower( trim( $USER->email ) ) ); header("Content-type: application/javascript"); ?> +var isMobile = false; //initiate as false +// device detection +if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent) + || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4))) isMobile = true; /* * JavaScript MD5 * https://github.com/blueimp/JavaScript-MD5 @@ -286,101 +290,459 @@ function md5 (string, key, raw) { } }(this)); -var last_time=0; -function sendText(){ - $('#writehere')[0].onkeydown=function(e){ - if (e.keyCode==13){ - e.preventDefault(); - if (this.value){ - var datatosend={"text":this.value,"user":"username;?>","email":"email;?>"}; - $.ajax({ - type:"POST", - url:"chatAJAX.php", - data:datatosend, - datatype:"json", - success:function(data){} - }) - this.value=''; - $("#writehere").attr('placeholder', "Sending"); - $("#writehere").prop('disabled', true); - - } +$(document).ready(function() +{ + // init + + $(window).focus(); + var tabinfocus = true; + $("#chat").hide(); + $("#username").val(""); + $("#username").focus(); + + // allowed characters in username + + $("#username").keyup(function() + { + var text = $(this).val(); + $(this).val(text.replace(/[^a-zA-Z0-9 ]/g, "")); + }); + + // enter username + + var user = ""; + + user = "username; ?>"; + + // choose avatar, check username, start chat + + var avatar = ""; + avatar = "https://www.gravatar.com/avatar/" + md5('email; ?>') + "?d=mm"; + + startchat(); + + // start chat + + function startchat() + { + // zoom chat to fit viewport + + if( $(window).innerWidth() > 630 ) // if not mobile + { + var ratio = $(window).innerHeight() / 660; // browser viewport by chat height + + //$("#chat").css("zoom", ratio); + //$("#chat").css("-moz-transform-origin", "0 0"); + //$("#chat").css("-moz-transform", "scale(" + ratio + ")"); } + + // update favicon to user avatar + + //$("#favicon").remove(); + //var userfavicon = ""; + //$(userfavicon).appendTo("head"); + + // start chat + + $("#createuser").hide(); + $("#chat").show(); + $("#message").focus(); + + refresh(); } -} - -function checkText(){ - $.ajax({ - type:"POST", - url:"chatAJAX.php", - data:{time:last_time}, - datatype:"json", - success:function(data){ - if (data){ - data=JSON.parse(data); - for (var i=0; iusername;?>"){ - $('#messages').append( - '
  • user

    ' + data[i].USER + '

    '+ (setDateTime(data[i].TIME)) + '

    ' + data[i].MESSAGE + '
  • ' - ); - $(".box").animate({ scrollTop: $('.box').prop("scrollHeight")}, 0); - }else{ - $('#messages').append( - '
  • user

    ' + data[i].USER + '

    '+ (setDateTime(data[i].TIME)) + '

    ' + data[i].MESSAGE + '
  • ' - ); - $(".box").animate({ scrollTop: $('.box').prop("scrollHeight")}, 0); + + // allowed characters in message + + $("#message").keyup(function() + { + var text = $(this).val(); + $(this).val(text.replace("'", "`") + .replace("###", "#")); + }); + + // log message + + $("#message").focus().keypress(function(event) + { + if( event.keyCode === 13 ) + { + event.preventDefault(); + + if( $("#content").is(":visible") ) + { + var message = $("#message").val(); + message = encodeURIComponent(message); + var data = "messagedata=" + message + "###" + user + "###" + avatar; + $(this).val(""); + + $.ajax + ({ + type: "POST", + url: "chat/logmessage.php", + data: data, + cache: false + }); + } + } + }); + + // log emoticon + + $(".emoticonimg").click(function() + { + var emoticonselected = $(this); + emoticonselected.hide(); + var emoticonid = $(this).attr("id"); + var data = "messagedata=" + "specialchar" + emoticonid + "###" + user + "###" + avatar; + + $.ajax + ({ + type: "POST", + url: "chat/logmessage.php", + data: data, + cache: false, + success: function(result) + { + emoticonselected.show(); + } + }); + }); + + // show upload form + + $("#showuploadform").click(function() + { + $("#showuploadform").hide(); + $("#showemoticons").show(); + $("#uploadform").show(); + $("#emoticons").hide(); + $("#loadingwrapper").hide(); + + var r = Math.floor((Math.random() * 14) + 1); + var randomemoticon = "chat/img/emoticon" + r + ".png"; + $("#showemoticonsimg").attr("src", randomemoticon); + + refresh(); // also use as manual content refresh + }); + + // upload image + + $("#form").submit(function(event) + { + event.preventDefault(); + + $("#uploadform").hide(); + $("#showemoticons").hide(); + $("#loadingwrapper").show(); + + var filedata = $("#uploadimage").prop("files")[0]; + var formdata = new FormData(); + formdata.append("image", filedata); + var datavars = user + "###" + avatar; + formdata.append("datavars", datavars); + + $.ajax + ({ + type: "POST", + url: "chat/uploadimage.php", + cache: false, + contentType: false, + processData: false, + data: formdata, + success: function(result) + { + $("#uploadimage").val(""); + $("#showuploadform").show(); + $("#showemoticons").hide(); + $("#uploadform").hide(); + $("#loadingwrapper").hide(); + $("#content").show(); + $("#emoticons").show(); + } + }); + }); + + // show emoticons + + $("#showemoticons").click(function() + { + $("#showuploadform").show(); + $("#showemoticons").hide(); + $("#uploadform").hide(); + $("#loadingwrapper").hide(); + $("#content").show(); + $("#emoticons").show(); + }); + + // refresh content + + var content = $("#messages"); + var newcontent = content.html(); + + function refresh() + { + setTimeout(function() + { + var data = "user=" + user; + + $.ajax + ({ + type: "POST", + url: "chat/refreshmessages.php", + data: data, + cache: false, + success: function(result) + { + // check who is still online + + var datetoday = new Date(); + var timenow = datetoday.getTime() / 1000; + + $(".img-circle").each(function() + { + var timestamp = this.id; + var avauser = $(this).attr("alt"); + var avatarsrc = $(this).attr("src"); + + // set user offline avatar + + if( timestamp < timenow - 2700 ) + { + $(this).addClass("offline"); + $(this).removeClass("online"); + + } + else // set user online avatar + { + + $(this).addClass("online"); + $(this).removeClass("offline"); + + } + }); + + // new messages + + var newmessages = result.split("###endofmessage###"); + + for( var i=0; i') { - if (year1 > year2) return true; - else if (year1 === year2 && mon1 > mon2) return true; - else if (year1 === year2 && mon1 === mon2 && day1 > day2) return true; - else return false; - } -} - -function setDateTime(timedate){ - var tempdate=new Date(timedate*1000), - date=TwoDigits(tempdate.getDate()), - month=TwoDigits(tempdate.getMonth()+1), - year=tempdate.getFullYear(), - hours=TwoDigits(tempdate.getHours()), - mins=TwoDigits(tempdate.getMinutes()), - sec=TwoDigits(tempdate.getSeconds()); - var Today = new Date(); - if(datecompare(Today, ">", tempdate)){ - return (month+'-'+date+' '+hours+':'+mins ); + + // like message + + function likemessage(messageid) + { + var data = "messageid=" + messageid; + + $.ajax + ({ + type: "POST", + url: "chat/setlike.php", + data: data, + cache: false + }); } - if(datecompare(Today, "===", tempdate)){ - return (hours+':'+mins ); + + // update which users are typing + + function istyping(u, t) + { + // set typing user + + var data = "datavars=" + u + "###" + t; + + $.ajax + ({ + type: "POST", + url: "chat/settyping.php", + data: data, + cache: false, + success: function(result) + { + // get typing users + + $.ajax + ({ + url: "chat/gettyping.php", + cache: false, + success: function(result) + { + var typingusers = JSON.parse(result); + + if( typingusers.length == 0 ) // no user typing + { + $("#istyping").html(""); + } + else + { //$("#istyping").html("
  • \"user\"
    " + typingusers[0] + "...
  • "); + if( typingusers.length == 1 ) // one user typing + { + $("#istyping").html(typingusers[0] + " is typing..."); + //$(".box").animate({ scrollTop: $('.box').prop("scrollHeight")}, 0); + } + else if( typingusers.length == 2 ) // two users typing + { + var whoistyping = typingusers[0] + + " and " + typingusers[1] + + " are typing..."; + $("#istyping").html(whoistyping); + //$(".box").animate({ scrollTop: $('.box').prop("scrollHeight")}, 0); + } + else if( typingusers.length > 2 ) // more than two users typing + { + var whoistyping = typingusers[0] + + " and " + typingusers[1] + + " and others are typing..."; + $("#istyping").html(whoistyping); + //$(".box").animate({ scrollTop: $('.box').prop("scrollHeight")}, 0); + } + } + } + }); + } + }); } -} - -function TwoDigits(number){ - return (number<10 ? '0' : '') + number; -} - -sendText(); -checkText(); \ No newline at end of file +}); \ No newline at end of file diff --git a/functions.php b/functions.php index 9440a3818..3c6beef05 100755 --- a/functions.php +++ b/functions.php @@ -2,7 +2,7 @@ // =================================== // Define Version - define('INSTALLEDVERSION', '1.35'); + define('INSTALLEDVERSION', '1.36'); // =================================== // Debugging output functions diff --git a/homepage.php b/homepage.php index 5852b5446..20ea993dd 100755 --- a/homepage.php +++ b/homepage.php @@ -262,9 +262,9 @@ function runTest() { var ul = document.getElementById('upload') var ping = document.getElementById('ping') var jitter = document.getElementById('jitter') - dl.className = status === 1 ? 'flash' : '' - ping.className = status === 2 ? 'flash' : '' - jitter.className = ul.className = status === 3 ? 'flash' : '' + dl.className = status === 1 ? 'w-amount flash' : 'w-amount' + ping.className = status === 2 ? 'w-amount flash' : 'w-amount' + jitter.className = ul.className = status === 3 ? 'w-amount flash' : 'w-amount' if (status >= 4) { clearInterval(interval) document.getElementById('abortBtn').style.display = 'none' diff --git a/index.php b/index.php index cf72803cc..1d1781bdd 100755 --- a/index.php +++ b/index.php @@ -265,6 +265,7 @@ +