Skip to content

Commit

Permalink
Merge pull request #387 from causefx/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
causefx authored Jun 15, 2017
2 parents 832bf89 + 2c032d9 commit d7643b0
Show file tree
Hide file tree
Showing 15 changed files with 811 additions and 58 deletions.
52 changes: 42 additions & 10 deletions chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@

$dbcreated = false;

if (!extension_loaded("SQLITE3")){

echo '<div class="row" style="margin: 0"><div class="panel panel-danger" style="margin: 10px";>';
echo '<div class="panel-heading">';
echo '<h3 class="panel-title">SQLITE3</h3>';
echo '</div>';
echo '<div style="color: gray" class="panel-body">';
echo 'SQLITE3 is NOT loaded! Please install it before proceeding';

echo '</div></div></div>';
die();

}

if( $db = new SQLite3("chatpack.db") )
{
if( $db->busyTimeout(5000) )
Expand All @@ -156,8 +170,14 @@
(id INTEGER PRIMARY KEY,
timestamp INTEGER NOT NULL,
user TEXT NOT NULL)";

$onlinetable = "CREATE TABLE IF NOT EXISTS chatpack_last_message
(
user TEXT PRIMARY KEY NOT NULL,
timestamp INTEGER NOT NULL,
avatar TEXT NOT NULL)";

if( $db->exec($usertable) )
if( $db->exec($usertable) && $db->exec($onlinetable) )
{
$dbcreated = true;
}
Expand Down Expand Up @@ -200,28 +220,35 @@
<div id="content" class="container-fluid">
<br>
<div class="row">
<div class="col-lg-12">
<div class="content-box big-box chat">
<div class="content-title i-block">
<h4 class="zero-m">Welcome To The Chat <?php echo $USER->username;?></h4>
</div>
<div class="box" style="overflow: hidden; width: auto; height: calc(100vh - 130px);">
<div class="col-lg-10">
<div class="content-box big-box chat gray-bg">
<div class="box" style="overflow: hidden; width: auto; height: 550px;">
<div id="intro">
<center><img class="logo" alt="logo" src="images/organizr-logo-h-d.png">
<center><img class="logo" alt="logo" src="images/organizr-logo-h.png">
<br><br>start chatting...</center>
</div>
<ul id="messages" class="chat-double chat-container"></ul>
<ul class="chat-double chat-container" style="padding: 0px;"><li id="istyping"></li></ul>
</div>

<input id="message" autofocus type="text" class="form-control" placeholder="Enter your text" autocomplete="off"/>
<br/>
<input id="message" autofocus type="text" class="form-control gray-bg" placeholder="Enter your text" autocomplete="off"/>
<audio id="tabalert" preload="auto">
<source src="chat/audio/newmessage.mp3" type="audio/mpeg">
</audio>

</div>
</div>
<div class="col-lg-2">
<div class="content-box">
<div class="content-title big-box i-block gray-bg">
<h4 class="zero-m">Online</h4>
</div>
<div class="clearfix"></div>
<div id="onlineusers" class="big-box"></div>
</div>
</div>
</div>

</div>
</div>

Expand All @@ -246,6 +273,11 @@ function errormessage($msg)
scrollspeed: 30,
mousescrollstep: 60
});
$("#onlineusers").niceScroll({
railpadding: {top:0,right:0,left:0,bottom:0},
scrollspeed: 30,
mousescrollstep: 60
});
</script>

</html>
26 changes: 26 additions & 0 deletions chat/getonline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

include("connect.php");

$onlineusers = array();

if( $result = $db->query("SELECT user, timestamp, avatar FROM chatpack_last_message ORDER BY user ASC") )
{
while( $row = $result->fetchArray() )
{
$user = $row["user"];
$timestamp = $row["timestamp"];
$avatar = $row["avatar"];
$push = array($user, $timestamp, $avatar);

array_push($onlineusers, $push);
}
}

$db->close();

// pass online users as JSON back to chat.js

echo json_encode($onlineusers);

?>
2 changes: 2 additions & 0 deletions chat/logmessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

$db->exec("INSERT INTO chatpack_log (timestamp, user, avatar, message)
VALUES ('$timestamp', '$user', '$avatar', '$message')");
$db->exec("REPLACE INTO chatpack_last_message (timestamp, user, avatar)
VALUES ('$timestamp', '$user', '$avatar')");
}

function encryptmessage($msg)
Expand Down
4 changes: 2 additions & 2 deletions chat/refreshmessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

if( $result = $db->query("SELECT * FROM
(SELECT id, timestamp, user, avatar, message
FROM chatpack_log ORDER BY id DESC LIMIT 250)
FROM chatpack_log ORDER BY id DESC LIMIT 125)
ORDER BY id ASC") )
{
$newmessages = array();
Expand All @@ -22,7 +22,7 @@
$message = $row["message"];

$timenow = time();
$messagetime = date("h:i", intval($timestamp));
$messagetime = date("h:iA", intval($timestamp));
$messagedate = date("m-d", intval($timestamp));
$message = utf8_encode($message);

Expand Down
113 changes: 86 additions & 27 deletions chatjs.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,7 @@ function startchat()

// allowed characters in message

$("#message").keyup(function()
{
var text = $(this).val();
$(this).val(text.replace("'", "`")
.replace("###", "#"));
});


// log message

Expand Down Expand Up @@ -497,30 +492,79 @@ function refresh()
// check who is still online

var datetoday = new Date();
var timenow = datetoday.getTime() / 1000;
var timenow = datetoday.getTime() / 1000;

$(".img-circle").each(function()
$.ajax
({
url: "chat/getonline.php",
cache: false,
success: function(result)
{
var timestamp = this.id;
var avauser = $(this).attr("alt");
var avatarsrc = $(this).attr("src");
var onlineusers = JSON.parse(result);
var oldonlineusers = $("#onlineusers").html();
var newonlineusers = '';

// set user offline avatar

if( timestamp < timenow - 2700 )
if( onlineusers.length <= 0 ) // no user typing
{
$(this).addClass("offline");
$(this).removeClass("online");

newonlineusers += "No Users Online";
}
else // set user online avatar
{
else
{
if( onlineusers.length >= 1 ) // one user typing
{
jQuery.each( onlineusers, function( i, val ) {
var timecheck = val[1];
var status = "";
var color = "";
if( timecheck < timenow - 1800 )
{
status = '<span style="min-height: 14px;margin-top: 10px;" class="pull-right badge badge-danger animated pulse"> </span>';
color = "red";
}else{
status = '<span style="min-height: 14px;margin-top: 10px;" class="pull-right badge badge-success animated flash"> </span>';
color = "blue";
}
if( timecheck < timenow - 3600 )
{
newonlineusers += '';
}else{
newonlineusers += '<div class="member-info"><img style="height:40px" src="'+val[2]+'" alt="admin" class="img-circle"><span class="member-name">'+val[0]+'</span>'+status+'</div>';
i++;
}

$("img[alt^='"+val[0]+"']").each(function()
{
var timestamp = val[1];

$(this).addClass("online");
$(this).removeClass("offline");

// set user offline avatar

if( timestamp < timenow - 1800 )
{
$(this).addClass("offline");
$(this).removeClass("online");

}
else // set user online avatar
{

$(this).addClass("online");
$(this).removeClass("offline");

}
});

});
}
}
});
if(newonlineusers === ''){ newonlineusers = "No Users Online";}
if( newonlineusers != oldonlineusers )
{
$("#onlineusers").html(newonlineusers);
}
}
});



// new messages

Expand Down Expand Up @@ -559,7 +603,7 @@ function refresh()

if( message.lastIndexOf(userwriting) == -1 )
{
newmessagealert();
newmessagealert(message);
}

// refresh eventlisteners of messages to set likes
Expand Down Expand Up @@ -637,7 +681,7 @@ function refresh()
window.onfocus = function()
{
tabinfocus = true;
parent.document.title = "Organzir Chat";
parent.document.title = "Chat";
window.parent.$("span[id^='chat.phps']").html("");
};

Expand All @@ -648,7 +692,7 @@ function refresh()

// new message tab alert

function newmessagealert()
function newmessagealert(message)
{
if( !tabinfocus )
{
Expand All @@ -660,9 +704,24 @@ function newmessagealert()
i++
}

parent.document.title = i + " Organzir Chat";
parent.document.title = i + " Chat";
//window.parent.$("#chat.phpx").addClass("gottem");
window.parent.$("span[id^='chat.phps']").html(i);
var $jQueryObject = $($.parseHTML(message));
var alertMessage = $jQueryObject.find(".chat-body").html();
var alertUsername = $jQueryObject.find("h4[class^='pull-left zero-m']").html();
var alertIcon = $jQueryObject.find("img").attr("src");;
if(isMobile === false){
parent.Push.create(alertUsername, {
body: alertMessage,
icon: alertIcon,
timeout: 4000,
onClick: function () {
window.parent.focus();
this.close();
}
});
}

// sound

Expand Down
1 change: 1 addition & 0 deletions check.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function getFilePermission($file) {

check("PDO_SQLITE");
check("PDO");
check("SQLITE3");
check("Zip");
check("openssl");
check("session");
Expand Down
1 change: 1 addition & 0 deletions config/configDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@
"git_branch" => "master",
"git_check" => true,
"speedTest" => false,
"smtpHostType" => "tls",
);
2 changes: 1 addition & 1 deletion css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d7643b0

Please sign in to comment.