Merge branch 'master' into hendrik-testing

This commit is contained in:
Hendrik
2017-01-26 15:33:08 +01:00
32 changed files with 472 additions and 391 deletions

View File

@@ -1,31 +0,0 @@
<?php
session_start();
require("../../queries/friendship.php");
require("../../queries/user.php");
if(empty($_POST["userID"]) OR empty($_POST["delete"]) AND empty($_POST["accept"]) AND empty($_POST["request"])) {
echo "Not enough arguments.";
return;
}
$friendship_status = getFriendshipStatus($_POST["userID"]);
echo "\nfriendshipstatus: $friendship_status";
echo "You: " . $_SESSION["userID"];
echo "other user: " . $_POST["userID"];
if(!empty($_POST["request"]) AND $friendship_status == 0) {
echo "request";
requestFriendship($_POST["userID"]);
} else if(!empty($_POST["delete"]) AND in_array($friendship_status, array(1, 2, 3))) {
echo "delete";
removeFriendship($_POST["userID"]);
} else if (!empty($_POST["accept"]) AND $friendship_status == 3) {
echo "accept";
acceptFriendship($_POST["userID"]);
}
$username = getUsername($_POST["userID"]);
header("Location: ../profile.php?username=$username");

View File

@@ -0,0 +1,24 @@
<?php
if(empty($_POST["usr"])) {
header('HTTP/1.1 500 Non enough arguments');
}
require_once ("../../queries/user.php");
require_once ("../../queries/nicetime.php");
$posts = selectAllUserPosts($_POST["usr"]);
if(!$posts) {
header('HTTP/1.1 500 Query failed');
}
$results = $posts->fetchAll(PDO::FETCH_ASSOC);
for($i = 0; $i < sizeof($results); $i++) {
$results[$i]["nicetime"] = nicetime($results[$i]["creationdate"]);
}
//$results[0]["niceTime"] = nicetime($results[0]["creationdate"]);
echo json_encode($results);

View File

@@ -0,0 +1,18 @@
<?php
session_start();
require("../../queries/post.php");
require("../../queries/connect.php");
require("../../queries/checkInput.php");
if (empty($_POST['newcomment-content'])) {
echo 0;
} else {
if(makeComment($_POST['postID'],
$_SESSION['userID'],
test_input($_POST['newcomment-content']))) {
echo 1;
} else {
echo 0;
}
}

View File

@@ -0,0 +1,17 @@
<?php
session_start();
require("../../queries/post.php");
require("../../queries/connect.php");
require("../../queries/checkInput.php");
if (empty($_POST['newpost-title'])) {
} else {
makePost($_SESSION['userID'],
null,
test_input($_POST['newpost-title']),
test_input($_POST['newpost-content']));
}
header("Location: ../profile.php");

View File

@@ -0,0 +1,28 @@
<?php
session_start();
require_once ("../../queries/connect.php");
require_once ("../../queries/checkInput.php");
require_once ("../../queries/group_member.php");
require_once ("../../queries/group_page.php");
$n = 0;
if (isset($_POST["n"])) {
$n = (int) test_input($_POST["n"]);
}
$m = 20;
if (isset($_POST["m"])) {
$m = (int) test_input($_POST["m"]);
}
$search = "";
if (isset($_POST["search"])) {
$search = test_input($_POST["search"]);
}
if (isset($_POST["filter"]) && $_POST["filter"] == "personal") {
echo searchSomeOwnGroups($n, $m, $search);
} else {
echo searchSomeGroups($n, $m, $search);
}

View File

@@ -0,0 +1,27 @@
<?php
session_start();
require_once ("../../queries/connect.php");
require_once ("../../queries/checkInput.php");
require_once ("../../queries/friendship.php");
require_once ("../../queries/user.php");
$n = 0;
if (isset($_POST["n"])) {
$n = (int) test_input($_POST["n"]);
}
$m = 20;
if (isset($_POST["m"])) {
$m = (int) test_input($_POST["m"]);
}
$search = "";
if (isset($_POST["search"])) {
$search = test_input($_POST["search"]);
}
if (isset($_POST["filter"]) && $_POST["filter"] == "personal") {
echo searchSomeFriends($n, $m, $search);
} else {
echo searchSomeUsers($n, $m, $search);
}

View File

@@ -4,12 +4,6 @@ session_start();
include_once ("../../queries/friendship.php");
if (isset($_POST["limit"])) {
$limit = $_POST["limit"];
} else {
$limit = 5;
}
if (isset($_POST["action"])) {
$action = $_POST["action"];
} else {
@@ -26,11 +20,6 @@ $friends = json_decode($_POST["friends"]);
foreach($friends as $i => $friend) {
$friendshipStatus = getFriendshipStatus($friend->userID);
if ($limit != 0 && $i >= $limit)
$extra = "extra-friend-item";
else
$extra = "";
?>
<li class='friend-item <?= $extra ?>'>
<form action='<?= $action ?>' method='<?= $actionType ?>'>
@@ -60,15 +49,13 @@ foreach($friends as $i => $friend) {
</form>
<?php
if ($friendshipStatus > 1) {
if ($friendshipStatus == 2) {
$denyName = "Annuleer";
} else {
$denyName = "Weiger";
}
?>
<div class='notification-options'>
<input type='hidden' name='userID' value='' />
<button name='delete'
onclick="editFriendship('<?= $friend->userID ?>', 'delete')"
class='deny-notification'
value='1'>
<i class='fa fa-times'></i>
</button>
<div class='notification-options'>
<?php
if ($friendshipStatus == 3) {
?>
@@ -76,11 +63,19 @@ foreach($friends as $i => $friend) {
onclick="editFriendship('<?= $friend->userID ?>', 'accept')"
class='accept-notification'
value='1'>
<i class='fa fa-check'></i>
<i class='fa fa-check'></i>Accepteer
</button>
<?php
}
?>
<input type='hidden' name='userID' value='' />
<button name='delete'
onclick="editFriendship('<?= $friend->userID ?>', 'delete')"
class='deny-notification'
value='1'>
<i class='fa fa-times'></i> <?= $denyName ?>
</button>
</div>
<?php
}
@@ -89,13 +84,6 @@ foreach($friends as $i => $friend) {
<?php
}
if (sizeof($friends) > $limit) {
?>
<li class='more-item'>
Meer vrienden...
</li>
<?php
}
?>

View File

@@ -22,17 +22,3 @@ foreach($groups as $i => $group) {
</li>
<?php
}
?>
<li>
<form action="search.php" method="get">
<input type="hidden"
name="search"
value="" />
<input type="hidden"
name="filter"
value="groups" />
<button type="submit">
Alle groepen...
</button>
</form>
</li>

View File

@@ -1,25 +1,19 @@
$(document).ready(function() {
$("#own-profile-picture").click(function() {
if($("#notification-center").css('right') == "-256px") {
$(".content").animate({
marginRight: "256px"
}, 500);
$(".chat-right").animate({
width: $(".chat-right").width() - 266
}, 500);
$("#notification-center").animate({
right: "0px"
}, 500);
// Toggle menu
$("#own-profile-picture, #open-notifications").click(function() {
if ($("#notification-center").css('right') == "-256px") {
// Make the menu visible and move the content to the left.
$("#chat-history").width("calc(100% - 587px)");
$(".modal").width("calc(100% - 512px)");
$(".content").css("margin-right", "256px");
$("#notification-center").css("right", "0px");
} else {
$(".chat-right").animate({
width: $(".chat-right").width() + 266
}, 500);
$(".content").animate({
marginRight: "0px"
}, 500);
$("#notification-center").animate({
right: "-256px"
}, 500);
// Make the menu invisible and move the content to the right.
$("#chat-history").width("calc(100% - 331px)");
$(".modal").width("calc(100% - 256px)");
$(".content").css("margin-right", "0px");
$("#notification-center").css("right", "-256px");
}
});
});

View File

@@ -11,12 +11,10 @@ function scrollbarMargin(width, overflow) {
});
}
function requestPost(post) {
function requestPost(postID) {
$(".modal").show();
$.get(
"API/loadPost.php",
$(post).children("form").serialize()
).done(function (data) {
$.get("API/loadPost.php", { postID : postID }).done(function(data) {
$('.modal-default').hide();
var scrollBarWidth = window.innerWidth - document.body.offsetWidth;
scrollbarMargin(scrollBarWidth, 'hidden');
@@ -26,37 +24,55 @@ function requestPost(post) {
}
$(window).on("load", function() {
console.log("LOADED");
container = $("div.posts");
posts = container.children();
posts.remove();
column = $('<div class="column"></div>').append(posts);
container.append(column);
mansonry();
mansonry();
$(".modal-close").click(function () {
$(".modal").hide();
scrollbarMargin(0, 'auto');
$('#modal-response').hide();
$('.modal-default').show();
});
});
var masonryMode = 0;
$(window).resize(function() {
clearTimeout(window.resizedFinished);
window.resizeFinished = setTimeout(function() {
mansonry();
masonry(masonryMode);
}, 250);
});
function mansonry() {
var $container = $(".posts");
function masonry(mode) {
masonryMode = mode;
$container.children().remove();
columnCount = Math.floor($(".posts").width() / 250);
console.log("columns: " + columnCount);
/*
* Initialise columns.
*/
var columns = new Array(columnCount);
var $columns = new Array(columnCount);
for (i = 0; i < columnCount; i++) {
columns[i] = [0, []];
console.log(columns[i]);
$column = $("<div class=\"column\">");
$column.width(100/columnCount + "%");
$container.append($column);
columns[i] = [0, $column];
}
if(mode == 1) {
$postInput = $("<div class=\"post platform\">");
$form = $("<form action=\"API/postPost.php\" method=\"post\">");
$postInput.append($form);
$form.append($("<input class=\"newpost\" name=\"newpost-title\" placeholder=\"Titel\" type=\"text\">"));
$form.append($("<textarea class=\"newpost\" name=\"newpost-content\" placeholder=\"Schrijf een berichtje...\">"));
$form.append($("<input value=\"Plaats!\" type=\"submit\">"));
columns[0][1].append($postInput);
$postInput.on("load", function() {
columns[0][0] = $postInput.height() + margin;
});
}
/*
@@ -70,38 +86,29 @@ function mansonry() {
column = columns[i];
}
}
return column;
}
/*
* Rearange the objects.
* Get the posts from the server.
*/
j = 0;
posts.each(function(i) {
post = posts[i];
shortestColumn = getShortestColumn(columns);
shortestColumn[0] = shortestColumn[0] + $(post).height() + margin;
shortestColumn[1].push(post);
$.post("API/getPosts.php", { usr : userID })
.done(function(data) {
posts = JSON.parse(data);
});
container.children().remove();
/*
* Display the objects again in the correct order.
*/
for (i = 0; i < columnCount; i++) {
column = $('<div class="column"></div>').append(columns[i][1]);
console.log(column);
container.append(column);
}
/*
* Rearange the objects.
*/
jQuery.each(posts, function() {
$post = $("<div class=\"post platform\" onclick=\"requestPost(\'"+this['postID']+"\')\">");
$post.append($("<h2>").text(this["title"]));
$post.append($("<p>").html(this["content"]));
$post.append($("<p class=\"subscript\">").text(this["nicetime"]));
$("div.posts div.column").width(100/columnCount + "%");
shortestColumn = getShortestColumn(columns);
shortestColumn[1].append($post);
shortestColumn[0] = shortestColumn[0] + $post.height() + margin;
});
});
}
$(".modal-close").click(function () {
$(".modal").hide();
scrollbarMargin(0, 'auto');
$('#modal-response').hide();
$('.modal-default').show();
});
}

View File

@@ -1,49 +1,28 @@
var menuFriendsData;
var menuGroupsData;
var notificationMessagesData;
var notificationRequestsData;
$(document).ready(function() {
// Show more friends/users
// Show more friends
// $("#more-friends-click").click(function() {
// // Show only friends
// $("#groups-menu-section").slideUp();
// $("#friends-menu-section li").show();
//
// // Change buttons
// $("#more-friends-click").hide();
// $("#menu-back").show();
// });
//
// // Show more groups
// $("#more-groups-click").click(function() {
// // Show only groups
// $("#friends-menu-section").slideUp();
// $("#groups-menu-section li").show();
//
// // Change buttons
// $("#more-groups-click").hide();
// $("#menu-back").show();
// });
// // Go back
// $("#menu-back").click(function() {
// // Show overview of friends and groups
// $("#friends-menu-section").slideDown();
// $("#groups-menu-section").slideDown();
// $(".extra-menu-items").hide();
//
// // Change buttons
// $("#menu-back").hide();
// $("#more-groups-click").show();
// $("#more-friends-click").show();
// });
loadMenuFriends(5);
loadNotificationFriends();
loadUnreadMessages();
loadMenuGroups();
setInterval(updateMenus, 3000);
});
// Update the menu and notification items.
function updateMenus() {
loadMenuFriends(5);
loadNotificationFriends();
loadUnreadMessages();
loadMenuGroups();
}
// Get, every 3 seconds, the friends and insert them in the menu.
function loadMenuFriends(limit) {
$.post(
"API/loadFriends.php",
@@ -51,16 +30,18 @@ function loadMenuFriends(limit) {
limit: 5
}
).done(function(data) {
if (showFriends(data, "#menu-friends-list", 5, "profile.php", "GET", limit)) {
$("#friends-menu-section").show();
} else {
$("#friends-menu-section").hide();
if (menuFriendsData != data) {
menuFriendsData = data;
if (showFriends(data, "#menu-friends-list", 5, "profile.php", "GET", limit)) {
$("#friends-menu-section").show();
} else {
$("#friends-menu-section").hide();
}
}
});
setTimeout(loadMenuFriends, 3000, limit);
}
// Get, every 3 seconds, the groups and insert them in the menu.
function loadMenuGroups() {
$.post(
"API/loadGroups.php",
@@ -68,41 +49,45 @@ function loadMenuGroups() {
limit: 5
}
).done(function(data) {
if (showGroups(data, "#menu-groups-list")) {
$("#groups-menu-section").show();
} else {
$("#groups-menu-section").hide();
if (menuGroupsData != data) {
menuGroupsData = data;
if (showGroups(data, "#menu-groups-list")) {
$("#groups-menu-section").show();
} else {
$("#groups-menu-section").hide();
}
}
});
setTimeout(loadMenuGroups, 3000);
}
// Get, every 3 seconds, the friends requests and insert them in the notification center.
function loadNotificationFriends() {
$.post(
"API/loadFriendRequest.php"
).done(function(data) {
if (showFriendsPlus(data, "#friend-requests-list", 5, "profile.php", "GET")) {
$("#friend-request-section").show();
} else {
$("#friend-request-section").hide();
if (notificationRequestsData != data) {
notificationRequestsData = data;
if (showFriendsPlus(data, "#friend-requests-list", 5, "profile.php", "GET")) {
$("#friend-request-section").show();
} else {
$("#friend-request-section").hide();
}
}
});
setTimeout(loadNotificationFriends, 3000);
}
// Get, every 3 seconds, the unread messages and insert them in the notification center.
function loadUnreadMessages() {
$.post(
"API/loadChatNotifications.php"
).done(function(data) {
if (showFriendsPlus(data, "#unread-chat-list", 5, "chat.php", "GET")) {
console.log(data);
$("#unread-messages-section").show();
} else {
$("#unread-messages-section").hide();
if (notificationMessagesData != data) {
notificationMessagesData = data;
if (showFriendsPlus(data, "#unread-chat-list", 5, "chat.php", "GET")) {
$("#unread-messages-section").show();
} else {
$("#unread-messages-section").hide();
}
}
});
setTimeout(loadUnreadMessages, 3000);
}

View File

@@ -1,43 +0,0 @@
// function showChatNotifications(notifications) {
// $("#unreadChatlist").html("");
// for (i in notifications) {
// $("#unreadChatlist").append(" \
// <li class='friend-item'> \
// <form action='chat.php' method='get'> \
// <button type='submit' \
// name='chatID' \
// value='"+ notifications[i].userID +"'> \
// <div class='friend'> \
// <img alt='PF' class='profile-picture' src='"+ notifications[i].profilepicture +"'/> \
// <div class='friend-name'> \
// "+ notifications[i].name +"<br/> \
// <span style='color: #666'>"+ notifications[i].content +"</span> \
// </div> \
// </div> \
// </button> \
// </form> \
// </li> \
// ");
// }
// }
//
// function loadNotifications() {
// $.post(
// "API/loadChatNotifications.php"
// ).done(function(data) {
// if (data && data != "[]") {
// $("#unread-messages-section").show();
// showChatNotifications(JSON.parse(data));
// } else {
// $("#unread-messages-section").hide();
// }
// });
//
// setTimeout(loadNotifications, 10000);
// }
// $(document).ready(function() {
// loadNotifications();
// });

18
website/public/js/post.js Normal file
View File

@@ -0,0 +1,18 @@
function postComment() {
$.post(
"API/postComment.php",
$("#newcommentform").serialize()
);
$("#newcomment").val("");
//reload post
$.get(
"API/loadPost.php",
$("#newcommentform").serialize()
).done(function (data) {
$('#modal-response').html(data);
});
}

View File

@@ -1,8 +0,0 @@
function loadPost(postID) {
$.get(
"API/loadPost.php",
$(postID).serialize()
).done(function (data) {
$('#modal-response').innerHTML= JSON.parse(data);
});
}

View File

@@ -0,0 +1,33 @@
function searchUsers(n, m) {
$.post(
"API/searchUsers.php",
{
n: n,
m: m,
search: $("#search-input").val(),
filter: $("#search-filter").val()
}
).done(function(data) {
console.log(data);
if (!showFriends(data, "#search-users-list", 0, "profile.php", "GET")) {
$("#search-users-list").text("Niemand gevonden");
}
});
}
function searchGroups(n, m) {
$.post(
"API/searchGroups.php",
{
n: n,
m: m,
search: $("#search-input").val(),
filter: $("#search-filter").val()
}
).done(function(data) {
console.log(data);
if (!showGroups(data, "#search-groups-list")) {
$("#search-groups-list").text("Geen groepen gevonden");
}
});
}

View File

@@ -2,8 +2,9 @@
<html>
<head>
<?php include("../views/head.php"); ?>
<script src="js/masonry.js"></script>
<!-- <script src="js/profile.js"></script>-->
<script src="js/post.js"></script>
<style>
@import url("styles/profile.css");
@import url("styles/post-popup.css");
@@ -30,8 +31,10 @@ $posts = selectAllUserPosts($userID);
if ($userID == $_SESSION["userID"]) {
$friendship_status = -1;
$masonry_mode = 1;
} else {
$friendship_status = $user["friend_status"];
$masonry_mode = 0;
}
/*
@@ -48,10 +51,25 @@ include("../views/footer.php");
?>
<script src="js/friendButtons.js"></script>
<script src="js/masonry.js"></script>
<script>
var posts;
$(document).ready(function() {
userID = <?= $userID ?>;
placeFriendButtons();
masonry(<?= $masonry_mode ?>);
// alert("blap");
// $.post("API/getPosts.php", { usr : userID }, "json")
// .done(function(data) {
// posts = JSON.parse(data);
// alert(posts[0]["content"]);
// }).fail(function() {
// alert("failure...");
// });
});
</script>
</body>

View File

@@ -9,6 +9,8 @@
<style>
@import url("styles/search.css");
</style>
<script src="js/search.js"></script>
</head>
<body>
<?php

View File

@@ -43,6 +43,10 @@ header div {
width: 64px;
}
#own-profile-picture {
#own-profile-picture, #open-notifications {
cursor: pointer;
}
#open-notifications {
padding: 5px 20px 5px 0px;
}

View File

@@ -252,16 +252,20 @@ div[data-title]:hover:after {
font-family: Arial, sans-serif;
}
.friend {
}
.friend-item, .group-item {
cursor: pointer;
transition-duration: 250ms;
}
.friend-item button, .group-item button {
background: none;
color: inherit;
width: 100%;
height: 100%;
padding: 0;
text-align: left;
}
.friend-item:hover, .group-item:hover {
background: #FBC02D;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);

View File

@@ -34,15 +34,6 @@
cursor: pointer;
}
.menu button {
background: none;
color: inherit;
width: 100%;
height: 100%;
padding: 0;
text-align: left;
}
#notification-center {
left: auto;
width: 236px;
@@ -66,13 +57,8 @@
}
.notification-options {
width: 100%;
display: none;
width: 100%;
}
.notification-options form {
width: 100%;
text-align: center;
}
.notification-options button {
@@ -91,4 +77,13 @@
.friend-item:hover .notification-options {
display: inline-block;
}
.menu button {
background: none;
color: inherit;
width: 100%;
height: 100%;
padding: 0;
text-align: left;
}