Skip to content

Commit

Permalink
Chat Beta Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
causefx committed Jun 7, 2017
1 parent cf756f7 commit a8ef12b
Show file tree
Hide file tree
Showing 19 changed files with 1,179 additions and 110 deletions.
121 changes: 107 additions & 14 deletions chat.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php


$data = false;

ini_set("display_errors", 1);
Expand Down Expand Up @@ -113,6 +114,10 @@
<script src="bower_components/respondJs/dest/respond.min.js"></script>
<![endif]-->
<style>
.offline{
-webkit-filter: grayscale; /*sepia, hue-rotate, invert....*/
-webkit-filter: brightness(25%);
}
<?php if(CUSTOMCSS == "true") :
$template_file = "custom.css";
$file_handle = fopen($template_file, "rb");
Expand All @@ -123,7 +128,74 @@
</style>
</head>

<body class="scroller-body" style="padding: 0px;">
<body id="chat" class="scroller-body" style="padding: 0px;">

<!-- D A T A B A S E -->

<?php

$dbcreated = false;

if( $db = new SQLite3("chatpack.db") )
{
if( $db->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 )
{

?>

<div class="main-wrapper" style="position: initial;">
<div id="content" class="container-fluid">
<br>
Expand All @@ -133,26 +205,47 @@
<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: 500px;">
<div class="box" style="overflow: hidden; width: auto; height: calc(100vh - 130px);">
<div id="intro">
<center><img class="logo" alt="logo" src="images/organizr-logo-h-d.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>
<form id="message_form">
<input id="writehere" type="text" class="form-control" placeholder="Enter your text">
</form>

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

</div>
</div>
</div>
</div>
</div>

<?php

}

function errormessage($msg)
{
echo "<div style=\"margin-top: 50px;\">";
echo "<span style=\"color:#d89334;\">error </span>";
echo $msg;
echo "</div>";
}

?>
</body>

<script>

$(".box").niceScroll({
railpadding: {top:0,right:0,left:0,bottom:0},
scrollspeed: 30,
mousescrollstep: 60
});
</script>
<script>
$(".box").niceScroll({
railpadding: {top:0,right:0,left:0,bottom:0},
scrollspeed: 30,
mousescrollstep: 60
});
</script>

</html>
</html>
Binary file added chat/audio/newmessage.mp3
Binary file not shown.
66 changes: 66 additions & 0 deletions chat/checkuser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

$user = $_POST["user"];

if( $db = new SQLite3("../chatpack.db") )
{
if( $db->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 "<div style=\"margin-top: 50px;\">";
echo "<span style=\"color:#d89334;\">error </span>";
echo $msg;
echo "</div>";
}

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

$db = new SQLite3("../chatpack.db");
$db->busyTimeout(5000);
$db->exec("PRAGMA journal_mode = wal;");

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

include("connect.php");

$likedmessages = array();
$unlikedmessages = array();

if( $result = $db->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;

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

include("connect.php");

$typingusers = array();

if( $result = $db->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);

?>
Binary file added chat/img/favicon.ico
Binary file not shown.
Binary file added chat/img/like.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions chat/logmessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

$data = $_POST["messagedata"];
$dataarray = explode("###", $data);
$message = $dataarray[0];
$user = $dataarray[1];
$avatar = $dataarray[2];

include("connect.php");

if( strlen($message) > 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();

?>
2 changes: 2 additions & 0 deletions chat/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
post_max_size = 15M
upload_max_filesize = 10M
Loading

0 comments on commit a8ef12b

Please sign in to comment.