" . $post['content'] . "
+=$post['content']?>
diff --git a/website/public/API/getPosts.php b/website/public/API/getPosts.php index 3f07c7d..4d2d452 100644 --- a/website/public/API/getPosts.php +++ b/website/public/API/getPosts.php @@ -1,7 +1,10 @@ fetchAll(PDO::FETCH_ASSOC); + + for($i = 0; $i < sizeof($results); $i++) { + $results[$i]["nicetime"] = nicetime($results[$i]["creationdate"]); + } + + echo json_encode($results); } - - $results = $posts->fetchAll(PDO::FETCH_ASSOC); - - for ($i = 0; $i < sizeof($results); $i++) { - $results[$i]["nicetime"] = nicetime($results[$i]["creationdate"]); - } - - echo json_encode($results); } else { header('HTTP/1.0 403 Forbidden'); -} \ No newline at end of file +} diff --git a/website/public/img/nietslecht_small.png b/website/public/img/nietslecht_small.png new file mode 100644 index 0000000..bb44b90 Binary files /dev/null and b/website/public/img/nietslecht_small.png differ diff --git a/website/public/js/masonry.js b/website/public/js/masonry.js index b4370b7..4c40aad 100644 --- a/website/public/js/masonry.js +++ b/website/public/js/masonry.js @@ -45,6 +45,21 @@ function postPost() { } +var masonryMode = 0; +var windowWidth; +var columnCount; +var columns; +var postLimit; +var postAmount = 0; +var noposts = false; + +$(document).ready(function () { + windowWidth = $(window).width(); + columnCount = Math.floor($(".posts").width() / 250); + columns = new Array(columnCount); + postLimit = columnCount * 7; +}); + $(window).on("load", function() { $(".modal-close").click(function () { $(".modal").hide(); @@ -52,17 +67,30 @@ $(window).on("load", function() { $('#modal-response').hide(); $('.modal-default').show(); }); -}); -var masonryMode = 0; -var windowWidth = $(window).width(); + // http://stackoverflow.com/questions/9439725/javascript-how-to-detect-if-browser-window-is-scrolled-to-bottom + // $(window).on("scroll", function () { + // if ((window.innerHeight + window.pageYOffset) >= document.body.offsetHeight) { + // loadMorePosts(userID, groupID, postAmount, postLimit); + // } + // }); + window.onscroll = function(ev) { + if($(window).scrollTop() + $(window).height() == $(document).height() ) { + loadMorePosts(userID, groupID, postAmount, postLimit); + } + }; +}); $(window).resize(function() { clearTimeout(window.resizedFinished); window.resizeFinished = setTimeout(function() { if ($(window).width() != windowWidth) { windowWidth = $(window).width(); - masonry(masonryMode); + + if (columnCount != Math.floor($(".posts").width() / 250)) { + columnCount = Math.floor($(".posts").width() / 250); + masonry(masonryMode); + } } }, 250); }); @@ -72,12 +100,10 @@ var $container = $(".posts"); function masonry(mode) { masonryMode = mode; $container.children().remove(); - columnCount = Math.floor($(".posts").width() / 250); /* * Initialise columns. */ - var columns = new Array(columnCount); for (i = 0; i < columnCount; i++) { $column = $("
").html(fancyText(this["content"]))); - $post.append($("
").text(this["nicetime"])); - $post.append($("
").text("comments: " + this["comments"] + ", niet slechts: " + this["niet_slechts"])); - - shortestColumn = getShortestColumn(columns); - shortestColumn[1].append($post); - shortestColumn[0] = shortestColumn[0] + $post.height() + margin; - }); - }); + loadMorePosts(userID, groupID, 0, postLimit); } +function getShortestColumn(columns) { + column = columns[0]; + + for (i = 1; i < columnCount; i++) { + if (column[0] > columns[i][0]) { + column = columns[i]; + } + } + return column; +} + +function loadMorePosts(uID, gID, offset, limit) { + if (noposts) { + return; + } + + console.log(uID, gID, offset, limit); + + + $.post("API/getPosts.php", { usr : uID, + grp : gID, + offset : offset, + limit : limit}) + .done(function(data) { + if (!data) { + $('.noposts').show(); + noposts = true; + return; + } + + posts = JSON.parse(data); + + /* + * Rearange the objects. + */ + $.each(posts, function() { + $post = $("
").html(fancyText(this["content"]))); + $post.append($("
").text(this["nicetime"])); + $post.append($("
").text("comments: " + this["comments"] + ", niet slechts: " + this["niet_slechts"]));
+
+ shortestColumn = getShortestColumn(columns);
+ shortestColumn[1].append($post);
+ shortestColumn[0] = shortestColumn[0] + $post.height() + margin;
+ });
+ });
+
+ postAmount += limit;
+}
\ No newline at end of file
diff --git a/website/public/styles/post-popup.css b/website/public/styles/post-popup.css
index 7bbeb48..67d7880 100644
--- a/website/public/styles/post-popup.css
+++ b/website/public/styles/post-popup.css
@@ -14,7 +14,7 @@
/* Modal Content/Box */
.modal-content {
- margin: 5% auto;
+ margin: 50px auto;
width: 70%; /* Could be more or less, depending on screen size */
overflow-y: auto;
}
diff --git a/website/public/styles/profile.css b/website/public/styles/profile.css
index d2bdab4..1bacafa 100644
--- a/website/public/styles/profile.css
+++ b/website/public/styles/profile.css
@@ -123,6 +123,11 @@ div.posts .post form textarea.newpost {
font-size: 0.8em;
}
+.noposts {
+ display: none;
+ text-align: center;
+}
+
@media only screen and (max-width: 1500px) {
.post-box {
width: calc(50% - 68px);
diff --git a/website/queries/login.php b/website/queries/login.php
index f3c5d9a..4dad5c5 100644
--- a/website/queries/login.php
+++ b/website/queries/login.php
@@ -19,7 +19,7 @@ function getUser() {
}
function getUserID() {
- $stmt = $GLOBALS["db"]->prepare("
+ $stmt = prepareQuery("
SELECT
`userID`
FROM
@@ -73,7 +73,7 @@ function validateLogin($username, $password){
}
function fbLogin($fbID) {
- $stmt = $GLOBALS["db"]->prepare("
+ $stmt = prepareQuery("
SELECT
`email`,
`userID`,
@@ -91,7 +91,7 @@ function fbLogin($fbID) {
}
function getfbUserID($fbID) {
- $stmt = $GLOBALS["db"]->prepare("
+ $stmt = prepareQuery("
SELECT
`userID`,
`role`
diff --git a/website/queries/post.php b/website/queries/post.php
index a175cda..db81892 100644
--- a/website/queries/post.php
+++ b/website/queries/post.php
@@ -46,6 +46,57 @@ function selectAllPosts($userID, $groupID) {
}
+function selectSomePosts($userID, $groupID, $offset, $limit) {
+ $stmt = prepareQuery("
+ SELECT
+ `post`.`postID`,
+ `post`.`author`,
+ `title`,
+ CASE LENGTH(`post`.`content`) >= 150 AND `post`.`content` NOT LIKE 'bindParam(':userID', $userID, PDO::PARAM_INT);
+ $stmt->bindParam(':groupID', $groupID , PDO::PARAM_INT);
+ $stmt->bindParam(':offset', intval($offset), PDO::PARAM_INT);
+ $stmt->bindParam(':limit', intval($limit), PDO::PARAM_INT);
+ if(!$stmt->execute()) {
+ return False;
+ }
+ if($stmt->rowCount() == 0) {
+ return False;
+ }
+ return $stmt;
+
+}
+
function selectPostById($postID) {
$stmt = prepareQuery("
SELECT
diff --git a/website/queries/register.php b/website/queries/register.php
index 6ed4d50..3dcbed4 100644
--- a/website/queries/register.php
+++ b/website/queries/register.php
@@ -17,7 +17,7 @@ function getExistingUsername() {
}
function getExistingFBUsername() {
- $stmt = $GLOBALS["db"]->prepare("
+ $stmt = prepareQuery("
SELECT
`username`
FROM
@@ -49,7 +49,7 @@ function getExistingEmail() {
}
function getExistingFBEmail() {
- $stmt = $GLOBALS["db"]->prepare("
+ $stmt = prepareQuery("
SELECT
`email`,
`userID`
@@ -120,7 +120,7 @@ function registerAccount() {
}
function fbRegisterAccount() {
- $stmt = $GLOBALS["db"]->prepare("
+ $stmt = prepareQuery("
INSERT INTO
`user`(fname,
lname,
diff --git a/website/views/facebookRegisterModal.php b/website/views/facebookRegisterModal.php
index d36b08e..7db44b0 100644
--- a/website/views/facebookRegisterModal.php
+++ b/website/views/facebookRegisterModal.php
@@ -81,18 +81,14 @@
-
-
-
-
" . $post['content'] . "
+=$post['content']?>
Geen posts meer!
+