Merge branch 'master' into kevin-prototype
This commit is contained in:
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";
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,10 @@ function selectLimitedFriends($userID, $limit) {
|
||||
`profilepicture`,
|
||||
'../img/avatar-standard.png'
|
||||
) AS profilepicture,
|
||||
CASE `lastactivity` >= 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
|
||||
");
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ function getOldChatMessages($user2ID) {
|
||||
`destination` = :user1
|
||||
ORDER BY
|
||||
`creationdate` ASC
|
||||
LIMIT
|
||||
100
|
||||
");
|
||||
|
||||
$stmt->bindParam(":user1", $user1ID);
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -265,6 +278,25 @@ function changeMultipleUserStatusByID($ids, $status) {
|
||||
return $q;
|
||||
}
|
||||
|
||||
function changeMultipleUserStatusByIDAdmin($ids, $status) {
|
||||
$q = prepareQuery("
|
||||
UPDATE
|
||||
`user`
|
||||
SET
|
||||
`role` = :status
|
||||
WHERE
|
||||
FIND_IN_SET (`userID`, :ids)
|
||||
AND NOT `role` = 'admin'
|
||||
AND NOT `role` = 'owner'
|
||||
");
|
||||
|
||||
$ids = implode(',', $ids);
|
||||
$q->bindParam(':ids', $ids);
|
||||
$q->bindParam(':status', $status);
|
||||
$q->execute();
|
||||
return $q;
|
||||
}
|
||||
|
||||
function selectRandomNotFriendUser($userID) {
|
||||
$stmt = prepareQuery("
|
||||
SELECT
|
||||
@@ -335,9 +367,10 @@ function countSomeUsers($search) {
|
||||
FROM
|
||||
`user`
|
||||
WHERE
|
||||
`username` LIKE :keyword OR
|
||||
(`username` LIKE :keyword OR
|
||||
`fname` LIKE :keyword OR
|
||||
`lname` LIKE :keyword
|
||||
`lname` LIKE :keyword) AND
|
||||
`role` != 'banned'
|
||||
ORDER BY
|
||||
`fname`,
|
||||
`lname`,
|
||||
@@ -362,5 +395,20 @@ function getRoleByID($userID) {
|
||||
|
||||
$stmt->bindParam(':userID', $userID);
|
||||
$stmt->execute();
|
||||
return $stmt;
|
||||
return $stmt->fetch()["role"];
|
||||
}
|
||||
|
||||
function editBanCommentByID($userID, $comment) {
|
||||
$stmt = prepareQuery("
|
||||
UPDATE
|
||||
`user`
|
||||
SET
|
||||
`bancomment` = :comment
|
||||
WHERE
|
||||
`userID` = :userID
|
||||
");
|
||||
|
||||
$stmt->bindParam(':userID', $userID, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':comment', $comment);
|
||||
$stmt->execute();
|
||||
}
|
||||
Reference in New Issue
Block a user