From f26097f55fab9a19fa2fc59b087aa4c813f84b5f Mon Sep 17 00:00:00 2001 From: Lars van Hijfte Date: Tue, 31 Jan 2017 12:25:28 +0100 Subject: [PATCH 1/9] Fixed online status --- website/public/bits/friend-item.php | 2 +- website/public/group.php | 2 +- website/public/profile.php | 8 ++++---- website/public/styles/main.css | 10 +++++++++- website/public/styles/profile.css | 2 +- website/queries/friendship.php | 11 ++++++----- website/queries/user.php | 13 +++++++++++++ website/views/head.php | 5 ++++- website/views/profile.php | 4 ++-- 9 files changed, 41 insertions(+), 16 deletions(-) diff --git a/website/public/bits/friend-item.php b/website/public/bits/friend-item.php index a69d12a..40bc8a8 100644 --- a/website/public/bits/friend-item.php +++ b/website/public/bits/friend-item.php @@ -33,7 +33,7 @@ foreach($friends as $i => $friend) { } ?>'>
- PF + PF
fullname ?>
= DATE_SUB(NOW(),INTERVAL 15 MINUTE) + WHEN TRUE THEN 'online' + WHEN FALSE THEN 'offline' + END AS `onlinestatus`, `role` FROM `user` @@ -28,11 +32,8 @@ function selectLimitedFriends($userID, $limit) { `friendship`.`user1ID` = `user`.`userID`) AND `user`.`role` != 'banned' AND `friendship`.`status` = 'confirmed' - ORDER BY - CASE - WHEN `friendship`.`user2ID` = `user`.`userID` THEN `friendship`.`chatLastVisted1` - WHEN `friendship`.`user1ID` = `user`.`userID` THEN `friendship`.`chatLastVisted2` - END + ORDER BY + `user`.`lastactivity` DESC LIMIT :limitCount "); diff --git a/website/queries/user.php b/website/queries/user.php index 0900d9f..b1bb93c 100644 --- a/website/queries/user.php +++ b/website/queries/user.php @@ -2,6 +2,19 @@ require_once ("connect.php"); +function updateLastActivity() { + $stmt = prepareQuery(" + UPDATE + `user` + SET + `lastactivity` = NOW() + WHERE + `userID` = :userID + "); + $stmt->bindParam(":userID", $_SESSION["userID"]); + return $stmt->execute(); +} + function getUserID($username) { $stmt = prepareQuery(" SELECT diff --git a/website/views/head.php b/website/views/head.php index 6e8ca0a..284abb4 100644 --- a/website/views/head.php +++ b/website/views/head.php @@ -19,9 +19,12 @@ require_once ("../queries/checkInput.php"); require_once ("../queries/connect.php"); +require_once ("../queries/user.php"); session_start(); if(!isset($_SESSION["userID"])){ header("location:login.php"); -} \ No newline at end of file +} else { + updateLastActivity(); +} diff --git a/website/views/profile.php b/website/views/profile.php index 90a368d..8cf555f 100644 --- a/website/views/profile.php +++ b/website/views/profile.php @@ -1,10 +1,10 @@
- ">
+ " src="">
From f67dd019c46c67ca604423d00ac04b7c956a8ac7 Mon Sep 17 00:00:00 2001 From: Lars van Hijfte Date: Tue, 31 Jan 2017 12:47:24 +0100 Subject: [PATCH 2/9] Inputs are now mobile friendly --- website/public/styles/main.css | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/website/public/styles/main.css b/website/public/styles/main.css index 7909687..f2d7535 100644 --- a/website/public/styles/main.css +++ b/website/public/styles/main.css @@ -192,7 +192,7 @@ button.green { } button.gray{ - background-color: inherit; + background-color: #FFF; color: #333; } @@ -307,8 +307,9 @@ div[data-title]:hover:after { body { font-size: 28px!important; } - button { + button, input { font-size: 28px; + height: 42px; } } \ No newline at end of file From 794b5ab294b47d5343c630e288544df8dd5ea41e Mon Sep 17 00:00:00 2001 From: Lars van Hijfte Date: Tue, 31 Jan 2017 13:54:31 +0100 Subject: [PATCH 3/9] Added fancy text to posts and comments --- website/public/API/postComment.php | 6 +++--- website/public/API/postPost.php | 6 +++--- website/public/js/main.js | 2 +- website/public/js/masonry.js | 6 +++--- website/public/styles/adminpanel.css | 2 +- website/public/styles/main.css | 9 ++++++++- website/queries/private_message.php | 2 ++ 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/website/public/API/postComment.php b/website/public/API/postComment.php index e1d7617..3bb3c3f 100644 --- a/website/public/API/postComment.php +++ b/website/public/API/postComment.php @@ -2,10 +2,10 @@ session_start(); -require("../../queries/post.php"); +require_once("../../queries/post.php"); require_once("../../queries/connect.php"); -require("../../queries/checkInput.php"); -print_r($_POST); +require_once("../../queries/checkInput.php"); + if ($_POST['button'] == 'reaction') { if (empty($_POST['newcomment-content'])) { echo 0; diff --git a/website/public/API/postPost.php b/website/public/API/postPost.php index b52e96b..fdb86bc 100644 --- a/website/public/API/postPost.php +++ b/website/public/API/postPost.php @@ -2,9 +2,9 @@ session_start(); -require("../../queries/post.php"); -require("../../queries/connect.php"); -require("../../queries/checkInput.php"); +require_once("../../queries/post.php"); +require_once("../../queries/connect.php"); +require_once("../../queries/checkInput.php"); if (empty($_POST['newpost-title'])) { } else { diff --git a/website/public/js/main.js b/website/public/js/main.js index d23bbbf..7d37d05 100644 --- a/website/public/js/main.js +++ b/website/public/js/main.js @@ -3,7 +3,7 @@ var months = ["januari", "februari", "maart", "april", "mei", "juni", "juli", "a function fancyText(text) { // Add links, images, gifs and (youtube) video's. - var regex = /(https?:\/\/.[^ ]*)/ig; + var regex = /(https?:\/\/.[^ <>"]*)/ig; text = text.replace(regex, function(link) { // Add images if (link.match(/(https?:\/\/.[^ ]*\.(?:png|jpg|jpeg|gif))/ig)) { diff --git a/website/public/js/masonry.js b/website/public/js/masonry.js index 8d2080b..b07e3bc 100644 --- a/website/public/js/masonry.js +++ b/website/public/js/masonry.js @@ -19,7 +19,7 @@ function requestPost(postID) { var scrollBarWidth = window.innerWidth - document.body.offsetWidth; scrollbarMargin(scrollBarWidth, 'hidden'); $('#modal-response').show(); - $('#modal-response').html(data); + $('#modal-response').html(fancyText(data)); }); } @@ -52,7 +52,7 @@ function masonry(mode) { * Initialise columns. */ var columns = new Array(columnCount); - var $columns = new Array(columnCount); + for (i = 0; i < columnCount; i++) { $column = $("
"); $column.width(100/columnCount + "%"); @@ -100,7 +100,7 @@ function masonry(mode) { $.each(posts, function() { $post = $("
"); $post.append($("

").html(this["title"])); - $post.append($("

").html(this["content"])); + $post.append($("

").html(fancyText(this["content"]))); $post.append($("

").text(this["nicetime"])); $post.append($("

").text("comments: " + this["comments"] + ", niet slechts: " + this["niet_slechts"])); diff --git a/website/public/styles/adminpanel.css b/website/public/styles/adminpanel.css index f9410e1..1dc2eb6 100644 --- a/website/public/styles/adminpanel.css +++ b/website/public/styles/adminpanel.css @@ -4,7 +4,7 @@ .admin-panel input[type="radio"], input[type="checkbox"] { vertical-align: middle; - height: auto; + height: 28px; margin: 2px; } diff --git a/website/public/styles/main.css b/website/public/styles/main.css index f2d7535..7fc03e1 100644 --- a/website/public/styles/main.css +++ b/website/public/styles/main.css @@ -307,9 +307,16 @@ div[data-title]:hover:after { body { font-size: 28px!important; } - button, input { + button, input, select { font-size: 28px; height: 42px; } + textarea { + font-size: 28px; + } + input[type="checkbox"], input[type="radio"] { + width: 28px; + height: 28px; + } } \ No newline at end of file diff --git a/website/queries/private_message.php b/website/queries/private_message.php index 430fddb..4ac04a7 100644 --- a/website/queries/private_message.php +++ b/website/queries/private_message.php @@ -16,6 +16,8 @@ function getOldChatMessages($user2ID) { `destination` = :user1 ORDER BY `creationdate` ASC + LIMIT + 100 "); $stmt->bindParam(":user1", $user1ID); From 2dd7dd8140d6e96cdbb044c080f5f279dd8aa2ae Mon Sep 17 00:00:00 2001 From: Lars van Hijfte Date: Tue, 31 Jan 2017 13:56:34 +0100 Subject: [PATCH 4/9] Reload comments bug fix --- website/public/js/post.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/website/public/js/post.js b/website/public/js/post.js index 4a8ebc7..e88d3eb 100644 --- a/website/public/js/post.js +++ b/website/public/js/post.js @@ -4,9 +4,7 @@ function postComment(buttonValue) { $.post( "API/postComment.php", formData - ).done(function(data) { - console.log(data); - }); + ); $("#newcomment").val(""); @@ -15,6 +13,6 @@ function postComment(buttonValue) { "API/loadPost.php", $("#newcommentform").serialize() ).done(function (data) { - $('#modal-response').html(data); + $('#modal-response').html(fancyText(data)); }); } \ No newline at end of file From 164eb2dde6983b239287175c69ff39913bbabd08 Mon Sep 17 00:00:00 2001 From: Lars van Hijfte Date: Tue, 31 Jan 2017 14:26:34 +0100 Subject: [PATCH 5/9] Frozen users cant chat with other people --- website/public/API/loadFriendRequest.php | 9 ++++++++- website/public/API/loadFriends.php | 14 +++++++++----- website/public/API/sendMessage.php | 16 ++++++++++++---- website/public/admin.php | 4 ++-- website/public/js/chat.js | 6 +++++- website/queries/user.php | 4 ++-- website/views/notification-center.php | 4 ++-- 7 files changed, 40 insertions(+), 17 deletions(-) diff --git a/website/public/API/loadFriendRequest.php b/website/public/API/loadFriendRequest.php index b99d2c3..02dedb3 100644 --- a/website/public/API/loadFriendRequest.php +++ b/website/public/API/loadFriendRequest.php @@ -4,5 +4,12 @@ session_start(); require_once ("../../queries/connect.php"); require_once ("../../queries/friendship.php"); +require_once ("../../queries/user.php"); -echo selectAllFriendRequests(); \ No newline at end of file +if (isset($_SESSION["userID"]) && + getRoleByID($_SESSION["userID"]) != 'frozen' && + getRoleByID($_SESSION["userID"]) != 'banned') { + echo selectAllFriendRequests(); +} else { + echo "[]"; +} diff --git a/website/public/API/loadFriends.php b/website/public/API/loadFriends.php index 38158c9..c5c8797 100644 --- a/website/public/API/loadFriends.php +++ b/website/public/API/loadFriends.php @@ -6,11 +6,15 @@ require_once ("../../queries/connect.php"); require_once ("../../queries/checkInput.php"); require_once ("../../queries/friendship.php"); -if (isset($_POST["limit"])) { - echo selectLimitedFriends($_SESSION["userID"], (int) test_input($_POST["limit"])); -} else if (isset($_GET["limit"])) { - echo selectLimitedFriends($_SESSION["userID"], (int) test_input($_GET["limit"])); +if (isset($_SESSION["userID"])) { + if (isset($_POST["limit"])) { + echo selectLimitedFriends($_SESSION["userID"], (int)test_input($_POST["limit"])); + } else if (isset($_GET["limit"])) { + echo selectLimitedFriends($_SESSION["userID"], (int)test_input($_GET["limit"])); + } else { + echo selectFriends($_SESSION["userID"]); + } } else { - echo selectFriends($_SESSION["userID"]); + echo "[]"; } diff --git a/website/public/API/sendMessage.php b/website/public/API/sendMessage.php index c5d47d1..9864403 100644 --- a/website/public/API/sendMessage.php +++ b/website/public/API/sendMessage.php @@ -4,11 +4,19 @@ session_start(); require_once("../../queries/connect.php"); require_once("../../queries/private_message.php"); require_once("../../queries/checkInput.php"); +require_once("../../queries/user.php"); -if (!empty(test_input($_POST["destination"])) && - !empty(test_input($_POST["content"]))) { - if (sendMessage(test_input($_POST["destination"]), test_input($_POST["content"]))) { - echo 1; +if (isset($_SESSION["userID"]) && + getRoleByID($_SESSION["userID"]) != 'frozen' && + getRoleByID($_SESSION["userID"]) != 'banned') { + if (!empty(test_input($_POST["destination"])) && + !empty(test_input($_POST["content"])) + ) { + if (sendMessage(test_input($_POST["destination"]), test_input($_POST["content"]))) { + echo 1; + } else { + echo 0; + } } else { echo 0; } diff --git a/website/public/admin.php b/website/public/admin.php index 2785606..b264c25 100644 --- a/website/public/admin.php +++ b/website/public/admin.php @@ -19,9 +19,9 @@ include_once ("../queries/user.php"); // auth -$userinfo = getRoleByID($_SESSION['userID'])->fetch(PDO::FETCH_ASSOC); +$role = getRoleByID($_SESSION['userID']); -if ($userinfo['role'] != 'admin' AND $userinfo['role'] != 'owner') { +if ($role != 'admin' AND $role != 'owner') { header("location:profile.php"); } diff --git a/website/public/js/chat.js b/website/public/js/chat.js index e35f85c..0b63d65 100644 --- a/website/public/js/chat.js +++ b/website/public/js/chat.js @@ -33,7 +33,11 @@ function sendMessage() { $.post( "API/sendMessage.php", $("#sendMessageForm").serialize() - ); + ).done(function(data) { + if (data == "0") { + alert("Je account is bevroren, dus je kan niet chat berichten versturen. Contacteer een admin als je denk dat dit onjuist is."); + } + }); $("#newContent").val(""); loadMessages(); diff --git a/website/queries/user.php b/website/queries/user.php index b1bb93c..3c48e41 100644 --- a/website/queries/user.php +++ b/website/queries/user.php @@ -9,7 +9,7 @@ function updateLastActivity() { SET `lastactivity` = NOW() WHERE - `userID` = :userID + `userID` = :userID "); $stmt->bindParam(":userID", $_SESSION["userID"]); return $stmt->execute(); @@ -417,5 +417,5 @@ function getRoleByID($userID) { $stmt->bindParam(':userID', $userID); $stmt->execute(); - return $stmt; + return $stmt->fetch()["role"]; } \ No newline at end of file diff --git a/website/views/notification-center.php b/website/views/notification-center.php index 7630b75..7bd03ea 100644 --- a/website/views/notification-center.php +++ b/website/views/notification-center.php @@ -7,9 +7,9 @@ include_once ("../queries/user.php"); // auth - $userinfo = getRoleByID($_SESSION['userID'])->fetch(PDO::FETCH_ASSOC); + $role = getRoleByID($_SESSION['userID']); - if ($userinfo['role'] == 'admin' OR $userinfo['role'] == 'owner') { + if ($role == 'admin' OR $role == 'owner') { echo ""; echo ""; } From 44408ee429913c087a105d16a5a0a529e87b1583 Mon Sep 17 00:00:00 2001 From: Lars van Hijfte Date: Tue, 31 Jan 2017 14:34:51 +0100 Subject: [PATCH 6/9] Frozen user cant comment or niet slecht on postst --- website/public/API/postComment.php | 32 +++++++++++++++++++----------- website/public/API/sendMessage.php | 2 +- website/public/js/chat.js | 6 +++--- website/public/js/post.js | 6 +++++- website/views/profile.php | 2 +- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/website/public/API/postComment.php b/website/public/API/postComment.php index 3bb3c3f..3864cc8 100644 --- a/website/public/API/postComment.php +++ b/website/public/API/postComment.php @@ -5,25 +5,33 @@ session_start(); require_once("../../queries/post.php"); require_once("../../queries/connect.php"); require_once("../../queries/checkInput.php"); +require_once("../../queries/user.php"); -if ($_POST['button'] == 'reaction') { - if (empty($_POST['newcomment-content'])) { - echo 0; - } else { - if (makeComment($_POST['postID'], - $_SESSION['userID'], - test_input($_POST['newcomment-content']))) { + +if (isset($_SESSION["userID"]) && + getRoleByID($_SESSION["userID"]) != 'frozen' && + getRoleByID($_SESSION["userID"]) != 'banned') { + if ($_POST['button'] == 'reaction') { + if (empty($_POST['newcomment-content'])) { + echo 0; + } else { + if (makeComment($_POST['postID'], + $_SESSION['userID'], + test_input($_POST['newcomment-content']))) { + echo 1; + } else { + echo 0; + } + } + } else if ($_POST['button'] == 'nietslecht') { + if (makeNietSlecht($_POST["postID"], $_SESSION["userID"])) { echo 1; } else { echo 0; } - } -} else if ($_POST['button'] == 'nietslecht') { - if (makeNietSlecht($_POST["postID"], $_SESSION["userID"])) { - echo 1; } else { echo 0; } } else { - echo 0; + echo "frozen"; } \ No newline at end of file diff --git a/website/public/API/sendMessage.php b/website/public/API/sendMessage.php index 9864403..2d0b092 100644 --- a/website/public/API/sendMessage.php +++ b/website/public/API/sendMessage.php @@ -21,5 +21,5 @@ if (isset($_SESSION["userID"]) && echo 0; } } else { - echo 0; + echo "frozen"; } \ No newline at end of file diff --git a/website/public/js/chat.js b/website/public/js/chat.js index 0b63d65..1d70834 100644 --- a/website/public/js/chat.js +++ b/website/public/js/chat.js @@ -33,9 +33,9 @@ function sendMessage() { $.post( "API/sendMessage.php", $("#sendMessageForm").serialize() - ).done(function(data) { - if (data == "0") { - alert("Je account is bevroren, dus je kan niet chat berichten versturen. Contacteer een admin als je denk dat dit onjuist is."); + ).done(function(response) { + if (response == "frozen") { + alert("Je account is bevroren, dus je kan niet chat berichten versturen. Contacteer een admin als je denkt dat dit onjuist is."); } }); diff --git a/website/public/js/post.js b/website/public/js/post.js index e88d3eb..27bc34e 100644 --- a/website/public/js/post.js +++ b/website/public/js/post.js @@ -4,7 +4,11 @@ function postComment(buttonValue) { $.post( "API/postComment.php", formData - ); + ).done(function (response) { + if (response == "frozen") { + alert("Je account is bevroren, dus je kan geen comments plaatsen of \"niet slechten\". Contacteer een admin als je denkt dat dit onjuist is."); + } + }); $("#newcomment").val(""); diff --git a/website/views/profile.php b/website/views/profile.php index 8cf555f..4db1a1e 100644 --- a/website/views/profile.php +++ b/website/views/profile.php @@ -1,6 +1,6 @@

- " src="">
+ " src="">
- "/> - + "/>
From 4d40bb60421a6cbf3aab914a1f786855a6fc81d6 Mon Sep 17 00:00:00 2001 From: Lars van Hijfte Date: Tue, 31 Jan 2017 15:46:53 +0100 Subject: [PATCH 9/9] checkbox width fix --- website/public/styles/adminpanel.css | 1 - 1 file changed, 1 deletion(-) diff --git a/website/public/styles/adminpanel.css b/website/public/styles/adminpanel.css index 1dc2eb6..4d55945 100644 --- a/website/public/styles/adminpanel.css +++ b/website/public/styles/adminpanel.css @@ -34,7 +34,6 @@ width: 100%; } -.usertable .table-checkbox {width: 20px} .usertable .table-username {width: 150px} .usertable .table-status {width: 100px} .usertable .table-action {width: 200px}