GROUP BUTTONS AND GROUP STYLE #171
@@ -3,15 +3,52 @@
|
||||
session_start();
|
||||
|
||||
require_once("../../queries/post.php");
|
||||
require_once("../../queries/group_page.php");
|
||||
require_once("../../queries/connect.php");
|
||||
require_once("../../queries/checkInput.php");
|
||||
|
||||
if (empty($_POST['newpost-title'])) {
|
||||
} else {
|
||||
makePost($_SESSION['userID'],
|
||||
null,
|
||||
test_input($_POST['newpost-title']),
|
||||
test_input($_POST['newpost-content']));
|
||||
if (empty($_POST["title"]) or
|
||||
empty($_POST["content"]) or
|
||||
empty($_SESSION["userID"])) {
|
||||
header('HTTP/1.1 500 Non enough arguments');
|
||||
}
|
||||
|
||||
header("Location: ../profile.php");
|
||||
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;
|
||||
}
|
||||
|
||||
makePost(
|
||||
$_SESSION["userID"],
|
||||
$_POST["group"],
|
||||
test_input($_POST["title"]),
|
||||
test_input($_POST["content"])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//if (empty($_POST['newpost-title'])) {
|
||||
//} else {
|
||||
// makePost($_SESSION['userID'],
|
||||
// null,
|
||||
// test_input($_POST['newpost-title']),
|
||||
// test_input($_POST['newpost-content']));
|
||||
//}
|
||||
//
|
||||
//header("Location: ../profile.php");
|
||||
@@ -34,6 +34,9 @@ include("../views/group.php");
|
||||
include("../views/footer.php");
|
||||
|
||||
$masonry_mode = 0;
|
||||
if ($group["role"] == "mod" OR $group["role"] == "admin") {
|
||||
$masonry_mode = 2;
|
||||
}
|
||||
?>
|
||||
|
||||
<script src="js/masonry.js"></script>
|
||||
|
||||
@@ -23,6 +23,28 @@ function requestPost(postID) {
|
||||
});
|
||||
}
|
||||
|
||||
function postPost() {
|
||||
title = $("input.newpost[name='title']").val();
|
||||
content = $("textarea.newpost[name='content']").val();
|
||||
|
||||
if (masonryMode == 2) {
|
||||
$.post("API/postPost.php", { title: title,
|
||||
content : content,
|
||||
group : groupID })
|
||||
.done(function() {
|
||||
masonry(masonryMode);
|
||||
});
|
||||
} else {
|
||||
$.post("API/postPost.php", { title: title,
|
||||
content : content })
|
||||
.done(function() {
|
||||
masonry(masonryMode);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$(window).on("load", function() {
|
||||
$(".modal-close").click(function () {
|
||||
$(".modal").hide();
|
||||
@@ -33,11 +55,15 @@ $(window).on("load", function() {
|
||||
});
|
||||
|
||||
var masonryMode = 0;
|
||||
var windowWidth = $(window).width();
|
||||
|
||||
$(window).resize(function() {
|
||||
clearTimeout(window.resizedFinished);
|
||||
window.resizeFinished = setTimeout(function() {
|
||||
masonry(masonryMode);
|
||||
if ($(window).width() != windowWidth) {
|
||||
windowWidth = $(window).width();
|
||||
masonry(masonryMode);
|
||||
}
|
||||
}, 250);
|
||||
});
|
||||
|
||||
@@ -60,13 +86,17 @@ function masonry(mode) {
|
||||
columns[i] = [0, $column];
|
||||
}
|
||||
|
||||
if(mode == 1) {
|
||||
if(mode > 0) {
|
||||
$postInput = $("<div class=\"post platform\">");
|
||||
$form = $("<form action=\"API/postPost.php\" method=\"post\">");
|
||||
$form = $("<form class=\"newpost\" action=\"API/postPost.php\" method=\"post\" onsubmit=\"postPost(); return false;\">");
|
||||
$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...\">"));
|
||||
if(mode == 2) {
|
||||
$form.append($("<input class=\"newpost\" type=\"hidden\" name=\"group\" value=\"" + groupID + "\">"));
|
||||
}
|
||||
|
||||
$form.append($("<input class=\"newpost\" name=\"title\" placeholder=\"Titel\" type=\"text\">"));
|
||||
$form.append($("<textarea class=\"newpost\" name=\"content\" placeholder=\"Schrijf een berichtje...\">"));
|
||||
$form.append($("<input value=\"Plaats!\" type=\"submit\">"));
|
||||
columns[0][1].append($postInput);
|
||||
|
||||
|
||||
44
website/queries/alerts.php
Normal file
44
website/queries/alerts.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Class AlertMessage
|
||||
* abstract class for alertMessages used in
|
||||
*/
|
||||
abstract class AlertMessage extends Exception {
|
||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
abstract public function getClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class HappyAlert
|
||||
* class for a happy alert as an exception.
|
||||
*/
|
||||
class HappyAlert extends AlertMessage {
|
||||
|
||||
public function __construct($message = "Gelukt!", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
public function getClass() {
|
||||
return "settings-message-happy";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class AngryAlert
|
||||
* class for an angry alert as as exception.
|
||||
*/
|
||||
class AngryAlert extends AlertMessage {
|
||||
public function __construct($message = "Er is iets fout gegaan.", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
public function getClass() {
|
||||
return "settings-message-angry";
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,12 @@ function selectGroupByName($name) {
|
||||
`description`,
|
||||
`picture`,
|
||||
`status`,
|
||||
(
|
||||
SELECT `role`
|
||||
FROM `group_member`
|
||||
WHERE `group_member`.`groupID` = `group_page`.`groupID` AND
|
||||
`userID` = :userID
|
||||
) AS `role`,
|
||||
COUNT(`group_member`.`groupID`) as `members`
|
||||
FROM
|
||||
`group_page`
|
||||
@@ -22,13 +28,36 @@ function selectGroupByName($name) {
|
||||
name LIKE :name
|
||||
");
|
||||
|
||||
$stmt->bindParam(':name', $name);
|
||||
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
|
||||
$stmt->bindParam(':userID', $_SESSION["userID"], PDO::PARAM_INT);
|
||||
if (!$stmt->execute()) {
|
||||
return False;
|
||||
}
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
function selectGroupRole(int $groupID) {
|
||||
$stmt = prepareQuery("
|
||||
SELECT
|
||||
`role`
|
||||
FROM
|
||||
`group_member`
|
||||
WHERE
|
||||
`groupID` = :groupID AND
|
||||
`userID` = :userID
|
||||
");
|
||||
|
||||
$stmt->bindParam(':groupID', $groupID, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':userID', $_SESSION["userID"], PDO::PARAM_INT);
|
||||
if(!$stmt->execute()) {
|
||||
return False;
|
||||
}
|
||||
if($stmt->rowCount() == 0) {
|
||||
return "none";
|
||||
}
|
||||
return $stmt->fetch()["role"];
|
||||
}
|
||||
|
||||
function selectGroupMembers(int $groupID) {
|
||||
$stmt = prepareQuery("
|
||||
SELECT
|
||||
|
||||
138
website/queries/picture.php
Normal file
138
website/queries/picture.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Uploads Avatar, checks it, and removes the old one.
|
||||
* @param bool $group
|
||||
* @throws AngryAlert
|
||||
* @throws HappyAlert
|
||||
*/
|
||||
function updateAvatar(bool $group = false) {
|
||||
$publicDir = "/var/www/html/public/";
|
||||
$tmpImg = $_FILES["pp"]["tmp_name"];
|
||||
$avatarDir = $group ? "uploads/groupavatar/" : "uploads/profilepictures/";
|
||||
checkAvatarSize($tmpImg);
|
||||
|
||||
if (getimagesize($tmpImg)["mime"] == "image/gif") {
|
||||
if ($_FILES["pp"]["size"] > 4000000) {
|
||||
throw new AngryAlert("Bestand is te groot, maximaal 4MB toegestaan.");
|
||||
}
|
||||
$relativePath = $avatarDir . $_SESSION["userID"] . "_avatar.gif";
|
||||
$group ? removeOldGroupAvatar($_POST["groupID"]) : removeOldUserAvatar();
|
||||
move_uploaded_file($tmpImg, $publicDir . $relativePath);
|
||||
} else {
|
||||
$relativePath = $avatarDir . $_SESSION["userID"] . "_avatar.png";
|
||||
$scaledImg = scaleAvatar($tmpImg);
|
||||
$group ? removeOldGroupAvatar($_POST["groupID"]) : removeOldUserAvatar();
|
||||
imagepng($scaledImg, $publicDir . $relativePath);
|
||||
}
|
||||
|
||||
$group ? setGroupAvatarToDatabase("../" . $relativePath, $_POST["groupID"]) : setUserAvatarToDatabase("../" . $relativePath);
|
||||
throw new HappyAlert("Profielfoto veranderd.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the old avatar from the uploads folder, for a user.
|
||||
*/
|
||||
function removeOldUserAvatar() {
|
||||
$stmt = prepareQuery("
|
||||
SELECT
|
||||
`profilepicture`
|
||||
FROM
|
||||
`user`
|
||||
WHERE
|
||||
`userID` = :userID
|
||||
");
|
||||
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||
$stmt->execute();
|
||||
$old_avatar = $stmt->fetch()["profilepicture"];
|
||||
if ($old_avatar != NULL) {
|
||||
unlink("/var/www/html/public/uploads/" . $old_avatar);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Removes the old avatar from the uploads folder, for a group.
|
||||
* @param int $groupID
|
||||
*/
|
||||
function removeOldGroupAvatar(int $groupID) {
|
||||
$stmt = prepareQuery("
|
||||
SELECT
|
||||
`picture`
|
||||
FROM
|
||||
`group_page`
|
||||
WHERE
|
||||
groupID = :groupID
|
||||
");
|
||||
$stmt->bindParam(":groupID", $groupID);
|
||||
$stmt->execute();
|
||||
$old_avatar = $stmt->fetch()["picture"];
|
||||
if ($old_avatar != NULL) {
|
||||
unlink("/var/www/html/public/uploads/" . $old_avatar);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the the path to the avatar into the database, for Users.
|
||||
* @param string $url path to the avatar
|
||||
*/
|
||||
function setUserAvatarToDatabase(string $url) {
|
||||
$stmt = prepareQuery("
|
||||
UPDATE
|
||||
`user`
|
||||
SET
|
||||
`profilepicture` = :avatar
|
||||
WHERE
|
||||
`userID` = :userID
|
||||
");
|
||||
|
||||
$stmt->bindParam(":avatar", $url);
|
||||
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the the path to the avatar into the database, for Groups.
|
||||
* @param string $url path to the avatar
|
||||
* @param int $groupID
|
||||
*/
|
||||
function setGroupAvatarToDatabase(string $url, int $groupID) {
|
||||
$stmt = prepareQuery("
|
||||
UPDATE
|
||||
`group_page`
|
||||
SET
|
||||
`picture` = :avatar
|
||||
WHERE
|
||||
`groupID` = :groupID
|
||||
");
|
||||
$stmt->bindParam(":avatar", $url);
|
||||
$stmt->bindParam(":groupID", $groupID);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the resoluton of a picture.
|
||||
* @param string $img
|
||||
* @throws AngryAlert
|
||||
*/
|
||||
function checkAvatarSize(string $img) {
|
||||
$minResolution = 200;
|
||||
$imgSize = getimagesize($img);
|
||||
if ($imgSize[0] < $minResolution or $imgSize[1] < $minResolution) {
|
||||
throw new AngryAlert("Afbeelding te klein, minimaal 200x200 pixels.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales a picture, standard width is 600px.
|
||||
* @param string $imgLink Path to a image file
|
||||
* @param int $newWidth Custom image width.
|
||||
* @return bool|resource Returns the image as an Resource.
|
||||
* @throws AngryAlert
|
||||
*/
|
||||
function scaleAvatar(string $imgLink, int $newWidth = 600) {
|
||||
$img = imagecreatefromstring(file_get_contents($imgLink));
|
||||
if ($img) {
|
||||
return imagescale($img, $newWidth);
|
||||
} else {
|
||||
throw new AngryAlert("Afbeelding wordt niet ondersteund.");
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,7 @@
|
||||
<?php
|
||||
include_once "../queries/emailconfirm.php";
|
||||
|
||||
/**
|
||||
* Class AlertMessage
|
||||
* abstract class for alertMessages used in
|
||||
*/
|
||||
abstract class AlertMessage extends Exception {
|
||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
abstract public function getClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class HappyAlert
|
||||
* class for a happy alert as an exception.
|
||||
*/
|
||||
class HappyAlert extends AlertMessage {
|
||||
|
||||
public function __construct($message = "Gelukt!", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
public function getClass() {
|
||||
return "settings-message-happy";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class AngryAlert
|
||||
* class for an angry alert as as exception.
|
||||
*/
|
||||
class AngryAlert extends AlertMessage {
|
||||
public function __construct($message = "Er is iets fout gegaan.", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
public function getClass() {
|
||||
return "settings-message-angry";
|
||||
}
|
||||
}
|
||||
include_once "../queries/picture.php";
|
||||
include_once "../queries/alerts.php";
|
||||
|
||||
/**
|
||||
* Gets the settings form the database.
|
||||
@@ -232,74 +190,4 @@ function doChangeEmail($email) {
|
||||
} else {
|
||||
throw new AngryAlert();
|
||||
}
|
||||
}
|
||||
|
||||
function updateAvatar() {
|
||||
$profilePictureDir = "/var/www/html/public/";
|
||||
$tmpImg = $_FILES["pp"]["tmp_name"];
|
||||
|
||||
checkAvatarSize($tmpImg);
|
||||
if (getimagesize($tmpImg)["mime"] == "image/gif") {
|
||||
if ($_FILES["pp"]["size"] > 4000000) {
|
||||
throw new AngryAlert("Bestand is te groot, maximaal 4MB toegestaan.");
|
||||
}
|
||||
$relativePath = "uploads/profilepictures/" . $_SESSION["userID"] . "_avatar.gif";
|
||||
move_uploaded_file($tmpImg, $profilePictureDir . $relativePath);
|
||||
} else {
|
||||
$relativePath = "uploads/profilepictures/" . $_SESSION["userID"] . "_avatar.png";
|
||||
$scaledImg = scaleAvatar($tmpImg);
|
||||
imagepng($scaledImg, $profilePictureDir . $relativePath);
|
||||
}
|
||||
removeOldAvatar();
|
||||
setAvatarToDatabase("../" . $relativePath);
|
||||
throw new HappyAlert("Profielfoto veranderd.");
|
||||
}
|
||||
|
||||
function removeOldAvatar() {
|
||||
$stmt = prepareQuery("
|
||||
SELECT
|
||||
`profilepicture`
|
||||
FROM
|
||||
`user`
|
||||
WHERE
|
||||
`userID` = :userID
|
||||
");
|
||||
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||
$stmt->execute();
|
||||
$old_avatar = $stmt->fetch()["profilepicture"];
|
||||
if ($old_avatar != NULL) {
|
||||
unlink("/var/www/html/public/uploads/" . $old_avatar);
|
||||
}
|
||||
}
|
||||
|
||||
function setAvatarToDatabase(string $url) {
|
||||
$stmt = prepareQuery("
|
||||
UPDATE
|
||||
`user`
|
||||
SET
|
||||
`profilepicture` = :avatar
|
||||
WHERE
|
||||
`userID` = :userID
|
||||
");
|
||||
|
||||
$stmt->bindParam(":avatar", $url);
|
||||
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
function checkAvatarSize(string $img) {
|
||||
$minResolution = 200;
|
||||
$imgSize = getimagesize($img);
|
||||
if ($imgSize[0] < $minResolution or $imgSize[1] < $minResolution) {
|
||||
throw new AngryAlert("Afbeelding te klein, minimaal 200x200 pixels.");
|
||||
}
|
||||
}
|
||||
|
||||
function scaleAvatar(string $imgLink, int $newWidth = 600) {
|
||||
$img = imagecreatefromstring(file_get_contents($imgLink));
|
||||
if ($img) {
|
||||
return imagescale($img, $newWidth);
|
||||
} else {
|
||||
throw new AngryAlert("Afbeelding wordt niet ondersteund.");
|
||||
}
|
||||
}
|
||||
@@ -120,48 +120,6 @@ function selectAllUserGroups($userID) {
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
function selectAllUserPosts($userID) {
|
||||
$stmt = prepareQuery("
|
||||
SELECT
|
||||
`post`.`postID`,
|
||||
`post`.`author`,
|
||||
`title`,
|
||||
CASE LENGTH(`post`.`content`) >= 150 AND `post`.`content` NOT LIKE '<img%'
|
||||
WHEN TRUE THEN
|
||||
CONCAT(LEFT(`post`.`content`, 150), '...')
|
||||
WHEN FALSE THEN
|
||||
`post`.`content`
|
||||
END
|
||||
AS `content`,
|
||||
`post`.`creationdate`,
|
||||
COUNT(`commentID`) AS `comments`,
|
||||
COUNT(`niet_slecht`.`postID`) AS `niet_slechts`
|
||||
FROM
|
||||
`post`
|
||||
LEFT JOIN
|
||||
`niet_slecht`
|
||||
ON
|
||||
`post`.`postID` = `niet_slecht`.`postID`
|
||||
LEFT JOIN
|
||||
`comment`
|
||||
ON
|
||||
`post`.`postID` = `comment`.`postID`
|
||||
WHERE
|
||||
`post`.`author` = :userID AND
|
||||
`groupID` IS NULL
|
||||
GROUP BY
|
||||
`post`.`postID`
|
||||
ORDER BY
|
||||
`post`.`creationdate` DESC
|
||||
");
|
||||
|
||||
$stmt->bindParam(':userID', $userID, PDO::PARAM_INT);
|
||||
if(!$stmt->execute()) {
|
||||
return False;
|
||||
}
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
function select20UsersFromN($n) {
|
||||
$q = prepareQuery("
|
||||
SELECT
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="content">
|
||||
<div class="profile-box platform">
|
||||
<img class="left group-picture" src="<?= $group['picture'] ?>">
|
||||
<img class="left main-picture" src="<?= $group['picture'] ?>">
|
||||
<div class="profile-button">
|
||||
<p><img src="img/leave-group.png"> Groep verlaten</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user