From d4d16661dffb7ecf3c64eea28aff40aa8e4a4c4a Mon Sep 17 00:00:00 2001 From: Hendrik Date: Thu, 2 Feb 2017 13:42:59 +0100 Subject: [PATCH 1/3] added alert box when emptpy posting --- website/public/API/postPost.php | 51 ++++++++++++++++--------------- website/public/js/masonry.js | 25 ++++++++++----- website/public/js/post.js | 2 ++ website/public/styles/profile.css | 5 +++ website/views/profile.php | 4 +++ 5 files changed, 56 insertions(+), 31 deletions(-) diff --git a/website/public/API/postPost.php b/website/public/API/postPost.php index b1c6649..241bda6 100644 --- a/website/public/API/postPost.php +++ b/website/public/API/postPost.php @@ -12,36 +12,39 @@ if (isset($_SESSION["userID"]) && getRoleByID($_SESSION["userID"]) != 'frozen' && getRoleByID($_SESSION["userID"]) != 'banned') { - if (empty($_POST["title"]) or - empty($_POST["content"]) or - empty($_SESSION["userID"]) - ) { + if (empty($_SESSION["userID"])) { header('HTTP/1.1 500 Non enough arguments'); } - if (empty($_POST["group"])) { - // User Post - makePost( - $_SESSION["userID"], - null, - test_input($_POST["title"]), - test_input($_POST["content"]) - ); + if (empty(test_input($_POST["title"])) or + empty(test_input($_POST["content"])) + ) { + echo "empty"; } else { - // Group Post + if (empty($_POST["group"])) { + // User Post + makePost( + $_SESSION["userID"], + null, + test_input($_POST["title"]), + test_input($_POST["content"]) + ); + } else { + // Group Post - // Check if the user is an admin or mod of the group. - if (!in_array(selectGroupRole($_POST["group"]), array('mod', 'admin'))) { - header('HTTP/1.1 500 Non enough rights'); - return; + // Check if the user is an admin or mod of the group. + if (!in_array(selectGroupRole($_POST["group"]), array('mod', 'admin'))) { + header('HTTP/1.1 500 Non enough rights'); + return; + } + + makePost( + $_SESSION["userID"], + $_POST["group"], + test_input($_POST["title"]), + test_input($_POST["content"]) + ); } - - makePost( - $_SESSION["userID"], - $_POST["group"], - test_input($_POST["title"]), - test_input($_POST["content"]) - ); } } else { echo "frozen"; diff --git a/website/public/js/masonry.js b/website/public/js/masonry.js index 4f638c2..d0d2074 100644 --- a/website/public/js/masonry.js +++ b/website/public/js/masonry.js @@ -31,14 +31,28 @@ function postPost() { $.post("API/postPost.php", { title: title, content : content, group : groupID }) - .done(function() { - masonry(masonryMode); + .done(function(data) { + if (data == "empty") { + $('#alertbox').show(); + $('#alerttext').html("Geen titel of inhoud; vul a.u.b. in."); + window.scrollTo(0,0); + } else { + $('#alertbox').hide(); + masonry(masonryMode); + } }); } else { $.post("API/postPost.php", { title: title, content : content }) - .done(function() { - masonry(masonryMode); + .done(function(data) { + if (data == "empty") { + $('#alertbox').show(); + $('#alerttext').html("Geen titel of inhoud; vul a.u.b. in."); + window.scrollTo(0,0); + } else { + $('#alertbox').hide(); + masonry(masonryMode); + } }); } @@ -153,9 +167,6 @@ function loadMorePosts(uID, gID, offset, limit) { return; } - console.log(uID, gID, offset, limit); - - $.post("API/getPosts.php", { usr : uID, grp : gID, offset : offset, diff --git a/website/public/js/post.js b/website/public/js/post.js index f176950..7c73793 100644 --- a/website/public/js/post.js +++ b/website/public/js/post.js @@ -32,6 +32,8 @@ function deletePost(postID) { alert("Je account is bevroren, dus je kan geen posts verwijderen. Contacteer een admin als je denkt dat dit onjuist is."); } }); + noposts = false; + postAmount = 0; closeModal(); masonry(masonryMode); diff --git a/website/public/styles/profile.css b/website/public/styles/profile.css index 1bacafa..27d2bdd 100644 --- a/website/public/styles/profile.css +++ b/website/public/styles/profile.css @@ -1,5 +1,10 @@ /* New */ +.alertbox { + display: none; + background-color: firebrick; +} + .user-box { text-align: center; } diff --git a/website/views/profile.php b/website/views/profile.php index 2bb117f..120dae4 100644 --- a/website/views/profile.php +++ b/website/views/profile.php @@ -1,4 +1,8 @@
+
+ +
+
" src="">
From feba1d978627948b73445a0016c1bd51e7d3bcd9 Mon Sep 17 00:00:00 2001 From: Hendrik Date: Thu, 2 Feb 2017 13:47:41 +0100 Subject: [PATCH 2/3] fix reload after posting post --- website/public/js/masonry.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/public/js/masonry.js b/website/public/js/masonry.js index 7128a8a..5a4ca4c 100644 --- a/website/public/js/masonry.js +++ b/website/public/js/masonry.js @@ -38,6 +38,8 @@ function postPost() { window.scrollTo(0,0); } else { $('#alertbox').hide(); + noposts = false; + postAmount = 0; masonry(masonryMode); } }); @@ -51,6 +53,8 @@ function postPost() { window.scrollTo(0,0); } else { $('#alertbox').hide(); + noposts = false; + postAmount = 0; masonry(masonryMode); } }); From 93e63111de4738629b0921cc5ca9882ef35a7581 Mon Sep 17 00:00:00 2001 From: Hendrik Date: Thu, 2 Feb 2017 13:54:52 +0100 Subject: [PATCH 3/3] cleaned fix --- website/public/js/masonry.js | 8 ++++---- website/public/js/post.js | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/website/public/js/masonry.js b/website/public/js/masonry.js index 5a4ca4c..a628e96 100644 --- a/website/public/js/masonry.js +++ b/website/public/js/masonry.js @@ -38,8 +38,6 @@ function postPost() { window.scrollTo(0,0); } else { $('#alertbox').hide(); - noposts = false; - postAmount = 0; masonry(masonryMode); } }); @@ -53,8 +51,6 @@ function postPost() { window.scrollTo(0,0); } else { $('#alertbox').hide(); - noposts = false; - postAmount = 0; masonry(masonryMode); } }); @@ -116,6 +112,10 @@ function masonry(mode) { masonryMode = mode; $container.children().remove(); + // reinit posts + noposts = false; + postAmount = 0; + /* * Initialise columns. */ diff --git a/website/public/js/post.js b/website/public/js/post.js index 20da034..4009023 100644 --- a/website/public/js/post.js +++ b/website/public/js/post.js @@ -32,8 +32,6 @@ function deletePost(postID) { alert("Je account is bevroren, dus je kan geen posts verwijderen. Contacteer een admin als je denkt dat dit onjuist is."); } }); - noposts = false; - postAmount = 0; closeModal(); masonry(masonryMode); } \ No newline at end of file