|
|
@@ -1,4 +1,4 @@
|
|
|
-<?php
|
|
|
+<?php
|
|
|
require_once("user.php");
|
|
|
$USER = new User("registration_callback");
|
|
|
$userpic = md5( strtolower( trim( $USER->email ) ) );
|
|
|
@@ -24,9 +24,8 @@ function formatAMPM(date) {
|
|
|
var isMobile = false; //initiate as false
|
|
|
var d = new Date();
|
|
|
var timezone = d.getTimezoneOffset();
|
|
|
-console.log(timezone)
|
|
|
// 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)
|
|
|
+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
|
|
|
@@ -313,74 +312,74 @@ if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine
|
|
|
$(document).ready(function()
|
|
|
{
|
|
|
// init
|
|
|
-
|
|
|
+
|
|
|
$(window).focus();
|
|
|
var tabinfocus = true;
|
|
|
$("#chat").hide();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
// 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 = "<?php echo $USER->username; ?>";
|
|
|
-
|
|
|
+
|
|
|
// choose avatar, check username, start chat
|
|
|
-
|
|
|
+
|
|
|
var avatar = "";
|
|
|
avatar = "https://www.gravatar.com/avatar/" + md5('<?php echo $USER->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 + ")");
|
|
|
+ //$("#chat").css("-moz-transform", "scale(" + ratio + ")");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// update favicon to user avatar
|
|
|
-
|
|
|
+
|
|
|
//$("#favicon").remove();
|
|
|
- //var userfavicon = "<link id=\"favicon\" type=\"image/x-icon\"" +
|
|
|
+ //var userfavicon = "<link id=\"favicon\" type=\"image/x-icon\"" +
|
|
|
" rel=\"shortcut icon\" href=\"img/" + avatar + ".ico\">";
|
|
|
//$(userfavicon).appendTo("head");
|
|
|
-
|
|
|
+
|
|
|
// start chat
|
|
|
$("#chat").show();
|
|
|
$("#message").focus();
|
|
|
-
|
|
|
+
|
|
|
refresh();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// allowed characters in message
|
|
|
-
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
// log message
|
|
|
-
|
|
|
+
|
|
|
$("#message").focus().keypress(function(event)
|
|
|
{
|
|
|
if( event.keyCode === 13 )
|
|
|
{
|
|
|
event.preventDefault();
|
|
|
-
|
|
|
+
|
|
|
if( $("#content").is(":visible") )
|
|
|
{
|
|
|
var message = $("#message").val();
|
|
|
@@ -394,20 +393,20 @@ $(document).ready(function()
|
|
|
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",
|
|
|
@@ -420,9 +419,9 @@ $(document).ready(function()
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// show upload form
|
|
|
-
|
|
|
+
|
|
|
$("#showuploadform").click(function()
|
|
|
{
|
|
|
$("#showuploadform").hide();
|
|
|
@@ -430,30 +429,30 @@ $(document).ready(function()
|
|
|
$("#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();
|
|
|
+ var formdata = new FormData();
|
|
|
formdata.append("image", filedata);
|
|
|
var datavars = user + "###" + avatar;
|
|
|
formdata.append("datavars", datavars);
|
|
|
-
|
|
|
+
|
|
|
$.ajax
|
|
|
({
|
|
|
type: "POST",
|
|
|
@@ -472,11 +471,11 @@ $(document).ready(function()
|
|
|
$("#content").show();
|
|
|
$("#emoticons").show();
|
|
|
}
|
|
|
- });
|
|
|
+ });
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// show emoticons
|
|
|
-
|
|
|
+
|
|
|
$("#showemoticons").click(function()
|
|
|
{
|
|
|
$("#showuploadform").show();
|
|
|
@@ -486,18 +485,18 @@ $(document).ready(function()
|
|
|
$("#content").show();
|
|
|
$("#emoticons").show();
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// refresh content
|
|
|
-
|
|
|
+
|
|
|
var content = $("#messages");
|
|
|
var newcontent = content.html();
|
|
|
-
|
|
|
+
|
|
|
function refresh()
|
|
|
- {
|
|
|
+ {
|
|
|
setTimeout(function()
|
|
|
{
|
|
|
var data = "user=" + user;
|
|
|
-
|
|
|
+
|
|
|
$.ajax
|
|
|
({
|
|
|
type: "POST",
|
|
|
@@ -505,11 +504,11 @@ $(document).ready(function()
|
|
|
data: data,
|
|
|
cache: false,
|
|
|
success: function(result)
|
|
|
- {
|
|
|
+ {
|
|
|
// check who is still online
|
|
|
-
|
|
|
+
|
|
|
var datetoday = new Date();
|
|
|
- var timenow = datetoday.getTime() / 1000;
|
|
|
+ var timenow = datetoday.getTime() / 1000;
|
|
|
|
|
|
$.ajax
|
|
|
({
|
|
|
@@ -521,7 +520,7 @@ $(document).ready(function()
|
|
|
var oldonlineusers = $("#onlineusers").html();
|
|
|
var newonlineusers = '';
|
|
|
var onlinecount = 0;
|
|
|
-
|
|
|
+
|
|
|
if( onlineusers.length <= 0 ) // no user typing
|
|
|
{
|
|
|
newonlineusers += "No Users Online";
|
|
|
@@ -529,7 +528,7 @@ $(document).ready(function()
|
|
|
|
|
|
}
|
|
|
else
|
|
|
- {
|
|
|
+ {
|
|
|
if( onlineusers.length >= 1 ) // one user typing
|
|
|
{
|
|
|
jQuery.each( onlineusers, function( i, val ) {
|
|
|
@@ -541,18 +540,18 @@ $(document).ready(function()
|
|
|
status = '<span style="min-height: 14px;margin-top: 10px;" class="pull-right badge badge-danger"> </span>';
|
|
|
color = "red";
|
|
|
}else{
|
|
|
- status = '<span style="min-height: 14px;margin-top: 10px;" class="pull-right badge badge-success"> </span>';
|
|
|
- color = "blue";
|
|
|
+ status = '<span style="min-height: 14px;margin-top: 10px;" class="pull-right badge badge-success"> </span>';
|
|
|
+ color = "blue";
|
|
|
}
|
|
|
if( timecheck < timenow - 3600 )
|
|
|
{
|
|
|
- newonlineusers += '';
|
|
|
+ newonlineusers += '';
|
|
|
}else{
|
|
|
- newonlineusers += '<div class="member-info"><img style="height:40px" src="'+val[2]+'" alt="admin" class="img-circle"><span class="member-name" style="position: absolute;margin-top: 10px;">'+val[0]+'</span>'+status+'</div>';
|
|
|
+ newonlineusers += '<div class="member-info"><img style="height:40px" src="'+val[2]+'" alt="admin" class="img-circle"><span class="member-name" style="position: absolute;margin-top: 10px;">'+val[0]+'</span>'+status+'</div>';
|
|
|
i++;
|
|
|
onlinecount++;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$("img[alt^='"+val[0]+"']").each(function()
|
|
|
{
|
|
|
var timestamp = val[1];
|
|
|
@@ -573,7 +572,7 @@ $(document).ready(function()
|
|
|
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
@@ -587,24 +586,24 @@ $(document).ready(function()
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
// new messages
|
|
|
-
|
|
|
+
|
|
|
var newmessages = result.split("###endofmessage###");
|
|
|
|
|
|
for( var i=0; i<newmessages.length; i++ )
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
var message = newmessages[i];
|
|
|
-
|
|
|
+
|
|
|
if( message != "" )
|
|
|
{
|
|
|
var messagekeypos = message.indexOf("avatarandtext");
|
|
|
var messagekey = message.substr(messagekeypos + 19, 32);
|
|
|
var contentdom = document.getElementById("messages");
|
|
|
var messagedom = document.getElementById(messagekey);
|
|
|
-
|
|
|
+
|
|
|
if( $.contains(contentdom, messagedom) == false )
|
|
|
{
|
|
|
// append new message
|
|
|
@@ -627,11 +626,11 @@ $(document).ready(function()
|
|
|
}else {
|
|
|
newdate = moment(new Date($this+'Z')).format('lll');
|
|
|
}
|
|
|
- $(this).text(newdate);
|
|
|
+ $(this).text(newdate);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// new message tab alert
|
|
|
|
|
|
var userwriting = user + "writing";
|
|
|
@@ -644,9 +643,9 @@ $(document).ready(function()
|
|
|
newmessagealert(message);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// refresh eventlisteners of messages to set likes
|
|
|
-
|
|
|
+
|
|
|
$(".messagelike").unbind().click(function()
|
|
|
{
|
|
|
if( this.innerHTML.indexOf("target=") == -1 &&
|
|
|
@@ -659,9 +658,9 @@ $(document).ready(function()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// get and show likes
|
|
|
-
|
|
|
+
|
|
|
$.ajax
|
|
|
({
|
|
|
url: "chat/getlikes.php",
|
|
|
@@ -673,13 +672,13 @@ $(document).ready(function()
|
|
|
var unlikedmessages = likesandunlikes[1];
|
|
|
var likes = JSON.parse(likedmessages);
|
|
|
var unlikes = JSON.parse(unlikedmessages);
|
|
|
-
|
|
|
+
|
|
|
for( var i=0; i<likes.length; i++ )
|
|
|
{
|
|
|
var likeid = "#like" + likes[i];
|
|
|
$(likeid).show();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
for( var i=0; i<unlikes.length; i++ )
|
|
|
{
|
|
|
var unlikeid = "#like" + unlikes[i];
|
|
|
@@ -687,34 +686,34 @@ $(document).ready(function()
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// hide intro
|
|
|
-
|
|
|
+
|
|
|
if( result != "" )
|
|
|
{
|
|
|
- $("#intro").hide();
|
|
|
+ $("#intro").hide();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// loop
|
|
|
-
|
|
|
+
|
|
|
refresh();
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// update if current user is typing
|
|
|
-
|
|
|
+
|
|
|
if( $("#message").val() != "" )
|
|
|
{
|
|
|
- istyping(user, 1);
|
|
|
+ istyping(user, 1);
|
|
|
}
|
|
|
else if( $("#message").val() == "" )
|
|
|
{
|
|
|
- istyping(user, 0);
|
|
|
+ istyping(user, 0);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}, 1250);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// tab focus
|
|
|
window.onload = function()
|
|
|
{
|
|
|
@@ -748,9 +747,9 @@ $(document).ready(function()
|
|
|
console.log("not in focus");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
window.onblur = function()
|
|
|
{
|
|
|
if(window.chatLoaded === true){
|
|
|
@@ -758,11 +757,11 @@ $(document).ready(function()
|
|
|
console.log("not in focus");
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
// new message tab alert
|
|
|
-
|
|
|
+
|
|
|
function newmessagealert(message)
|
|
|
- {
|
|
|
+ {
|
|
|
|
|
|
|
|
|
if( !tabinfocus )
|
|
|
@@ -791,20 +790,20 @@ $(document).ready(function()
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// sound
|
|
|
-
|
|
|
+
|
|
|
var audio = $("#tabalert")[0];
|
|
|
audio.play();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// like message
|
|
|
-
|
|
|
+
|
|
|
function likemessage(messageid)
|
|
|
{
|
|
|
var data = "messageid=" + messageid;
|
|
|
-
|
|
|
+
|
|
|
$.ajax
|
|
|
({
|
|
|
type: "POST",
|
|
|
@@ -813,15 +812,15 @@ $(document).ready(function()
|
|
|
cache: false
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// update which users are typing
|
|
|
-
|
|
|
+
|
|
|
function istyping(u, t)
|
|
|
{
|
|
|
// set typing user
|
|
|
-
|
|
|
+
|
|
|
var data = "datavars=" + u + "###" + t;
|
|
|
-
|
|
|
+
|
|
|
$.ajax
|
|
|
({
|
|
|
type: "POST",
|
|
|
@@ -831,7 +830,7 @@ $(document).ready(function()
|
|
|
success: function(result)
|
|
|
{
|
|
|
// get typing users
|
|
|
-
|
|
|
+
|
|
|
$.ajax
|
|
|
({
|
|
|
url: "chat/gettyping.php",
|
|
|
@@ -839,7 +838,7 @@ $(document).ready(function()
|
|
|
success: function(result)
|
|
|
{
|
|
|
var typingusers = JSON.parse(result);
|
|
|
-
|
|
|
+
|
|
|
if( typingusers.length == 0 ) // no user typing
|
|
|
{
|
|
|
$("#istyping").html("");
|
|
|
@@ -873,4 +872,4 @@ $(document).ready(function()
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-});
|
|
|
+});
|