From a8ef12bc460487db36727e62d7c0c2598bfa5a3c Mon Sep 17 00:00:00 2001 From: causefx Date: Tue, 6 Jun 2017 22:30:49 -0700 Subject: [PATCH] Chat Beta Fixes --- chat.php | 121 ++++++++- chat/audio/newmessage.mp3 | Bin 0 -> 4597 bytes chat/checkuser.php | 66 +++++ chat/connect.php | 7 + chat/getlikes.php | 36 +++ chat/gettyping.php | 23 ++ chat/img/favicon.ico | Bin 0 -> 4286 bytes chat/img/like.png | Bin 0 -> 11862 bytes chat/logmessage.php | 46 ++++ chat/php.ini | 2 + chat/refreshmessages.php | 149 +++++++++++ chat/setlike.php | 41 +++ chat/settyping.php | 58 ++++ chat/uploadimage.php | 177 +++++++++++++ chatjs.php | 540 +++++++++++++++++++++++++++++++------- functions.php | 2 +- homepage.php | 6 +- index.php | 5 +- user.php | 10 +- 19 files changed, 1179 insertions(+), 110 deletions(-) create mode 100644 chat/audio/newmessage.mp3 create mode 100644 chat/checkuser.php create mode 100644 chat/connect.php create mode 100644 chat/getlikes.php create mode 100644 chat/gettyping.php create mode 100644 chat/img/favicon.ico create mode 100644 chat/img/like.png create mode 100644 chat/logmessage.php create mode 100644 chat/php.ini create mode 100644 chat/refreshmessages.php create mode 100644 chat/setlike.php create mode 100644 chat/settyping.php create mode 100644 chat/uploadimage.php 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 0000000000000000000000000000000000000000..dac28fee65aeeadf2c1cec74ae55de74015628c2 GIT binary patch literal 4597 zcmezWd%_V0<^v3jOBfg!6c`vx8W|p;aA07tf4=ZA*B=#TxfMI~|L$5= zzTxMwo(X>Y-^~4E`qT5Q$tJ!HCyfgD`1Kwb{?V>Fzktoj*+c5K^n$dV%+|9Xztwi#`5rGxVl7~5X>=+LiZZK>(n$YlV*(pf%L@qwriKTM|H0s&+ztsD zM#n~n1m=bU3C03GW(FI(1qm!{4F`m|+1Qv4WC$@lNHAe*Y`DNDQz0SFq#(j_QnevK zLxhW!X`(}efdEG{dyjrIX9~0QQ3pnc1&lKofjCw@V!m8+qlCbLxieG~t0Wj7FiS8W z5S&@^GD~u%W6zBLzb73z28lOH`^yLv@EzgLzY27LflbkhW-JG8S{3{ z`)JPCut0z#VMR6H423A^^*mBqmzx}n5^6WyP-KiLaOC3BKk0awmHo@bH1E4ta-W== zy)5Cylmv^Yqy@_oA~+H@1bx1BeyeQf`6+HZP67@Jm90*iZ4H)92Q}Lm@Bdv_w_N{{ zmvW6;qeIF;1=&Rs0z5Nx7+MedtpB^m==$yD+xtphE;{Lwz~r>4QG%6klZt9_?C<%% z-)#P#bWG~dQERRGMZQ)1B{Q%19xC1ce@ET__;3Hd+SR_T`EdKvTh}?_x56G=c8{5J zKm1wHlc&G#*Z;M17?672!;jj_5 ze*g@d-+Irbc*`QPmL_Qh@hYx8_Jy6(+~=Zo&dKMEz07R_}2oYmzT#)$+NMuM(1Ck-8 zrVpe1q-+J59WLH=1jW#E2F=?2);s?-2u1QgOWxSP5U6<%Xo%ly*2qr> zE|?x%eE*LZ*D4=JUsq#2OG`b|RU;VCKNLVQWQktLjo=s{>rIGLLoHJ@}n^{&@n*B{?QmB6hZ?nKN>>=9Rq~yAB`bGAvE&j0l77$82|tP literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..677cfd53b2f3f9623d5c2c0f77412a734fc138ad GIT binary patch literal 4286 zcmZQzU<5)11qKkwutI==L5zWcK?8_^LJST-3=*dVJpK9-u6@OwZQ*{qa(0<*jQAnG z)b_8)66?Q)>x2Jz?npl|;mYFd|NsB9fE0iG{R6ItT*jLFJHcAFKRN6#wanog^IV;O z40E*p2{o^Y^o74uwOyne-JH%yLkj`n|pbwTGrhQj=X%RP5LJqAmeZ;ZIcFk6FS zyJ2o%n4|e$X1OCc5#e$JOx$)$>^bV%4NEVY|D~5ZzQW~qka*OA(jJD{>QwYM%x)O1 z`CoT!z$J7y7;Xq+s5(8t5ENI4FoWsALC;eCPi{E1oS%`i`O$t9XXvjBd`7h0)8zhd zd35l9#*s#{+`u{C@DI##-X#_c*+-i_8D;|gLm+R1T`Sb|G z4RR}-u$m1mf7n3vfZ4|Iy?D)r*+GEjTV#e|zt_$TtoF0c(}OoqbB?#Vl9F%nxi#@% zHP{W$zrDs=FVvlxTo0=QLA1$+(7X7|C0Y(x{ zK=Z%iO4oNFOMnRkW-SU0tZ%@4_Z_KQs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=jyb0gyrzpj}qnxCxo=Qi!V}(8Zm%E{&7KUf#t1h=$lJaHt=i>ms#Z zH#6n`vRSj->d>r}Kn^V3$4RI`fcmVX8sB<{!tr&lHG2*NB>^?z^y{Lb*G0}mnx_jr z7jY|d?%0gPFq(#%U`cSi(%$=Rvk+Ix#~=A|rc-kCZD?D<;1ItTEx}{MXm6xX=>~fl zrd`{9+&*Z~d)MJmDhlO!&*ooMxzWA(R)h9SShX~l$uD*3&>&(= zQX(=^sl@f|I+2XfhgL1maL`||GGaK}4b-^!>BUkQIWlo59bZSH8hXmt6PhV-uy@j(BGagQ>%K-O%)qisN*hLOc$!;kf$kcnvrZj;aDs_ z-Js|15EUrMgOOGYSz>pK-FqTBjz!H5!GAXjq<-v|*EA)?*n?sQ}h#2Fhc}oMj(}U_VWM>Z8<98lrRPt2!pta~H(^d%i#Y{Z2RU z&EJJe_$f>LO|V8M()&40)9^4-$?jY9}l3o`R}Tt*bvcN{KQEl62t1);XZ m5Qhe4O#Mz4Oq5^GsFZ`R-iLgH^aEw#NGb}N@>Q}HVgCcr{?@Yq literal 0 HcmV?d00001 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 @@ +