Compare commits
1 Commits
technischr
...
marijn-pos
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb094858b5 |
@@ -6,6 +6,7 @@ require_once("../../queries/post.php");
|
||||
require_once("../../queries/group_page.php");
|
||||
require_once("../../queries/connect.php");
|
||||
require_once("../../queries/checkInput.php");
|
||||
require_once("../../queries/picture.php");
|
||||
|
||||
if (empty($_POST["title"]) or
|
||||
empty($_POST["content"]) or
|
||||
@@ -17,7 +18,6 @@ if (empty($_POST["group"])) {
|
||||
// User Post
|
||||
makePost(
|
||||
$_SESSION["userID"],
|
||||
null,
|
||||
test_input($_POST["title"]),
|
||||
test_input($_POST["content"])
|
||||
);
|
||||
@@ -32,23 +32,8 @@ if (empty($_POST["group"])) {
|
||||
|
||||
makePost(
|
||||
$_SESSION["userID"],
|
||||
$_POST["group"],
|
||||
test_input($_POST["title"]),
|
||||
test_input($_POST["content"])
|
||||
test_input($_POST["content"]),
|
||||
$_POST["group"]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//if (empty($_POST['newpost-title'])) {
|
||||
//} else {
|
||||
// makePost($_SESSION['userID'],
|
||||
// null,
|
||||
// test_input($_POST['newpost-title']),
|
||||
// test_input($_POST['newpost-content']));
|
||||
//}
|
||||
//
|
||||
//header("Location: ../profile.php");
|
||||
@@ -31,14 +31,16 @@ function postPost() {
|
||||
$.post("API/postPost.php", { title: title,
|
||||
content : content,
|
||||
group : groupID })
|
||||
.done(function() {
|
||||
.done(function(data) {
|
||||
masonry(masonryMode);
|
||||
console.log(data);
|
||||
});
|
||||
} else {
|
||||
$.post("API/postPost.php", { title: title,
|
||||
content : content })
|
||||
.done(function() {
|
||||
.done(function(data) {
|
||||
masonry(masonryMode);
|
||||
console.log(data);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,24 +82,25 @@ function masonry(mode) {
|
||||
var columns = new Array(columnCount);
|
||||
var $columns = new Array(columnCount);
|
||||
for (i = 0; i < columnCount; i++) {
|
||||
$column = $("<div class=\"column\">");
|
||||
$column = $("<div class='column'>");
|
||||
$column.width(100/columnCount + "%");
|
||||
$container.append($column);
|
||||
columns[i] = [0, $column];
|
||||
}
|
||||
|
||||
if(mode > 0) {
|
||||
$postInput = $("<div class=\"post platform\">");
|
||||
$form = $("<form class=\"newpost\" action=\"API/postPost.php\" method=\"post\" onsubmit=\"postPost(); return false;\">");
|
||||
$postInput = $("<div class='post platform'>");
|
||||
$form = $("<form class='newpost' action='API/postPost.php' method='post' onsubmit='postPost(); return false;'>");
|
||||
$postInput.append($form);
|
||||
|
||||
if(mode == 2) {
|
||||
$form.append($("<input class=\"newpost\" type=\"hidden\" name=\"group\" value=\"" + groupID + "\">"));
|
||||
$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\">"));
|
||||
$form.append($("<input class='newpost' name='title' placeholder='Titel' type='text'>"));
|
||||
$form.append($("<textarea class='newpost' name='content' placeholder='Schrijf een berichtje...'>"));
|
||||
$form.append($("<label for='picture'>Voeg een foto toe</label><input class='newpost' name='picture' id='picture' type='file' accept='image/*' size='4000000'>"));
|
||||
$form.append($("<input value='Plaats!' type='submit'>"));
|
||||
columns[0][1].append($postInput);
|
||||
|
||||
columns[0][0] = $postInput.height() + margin;
|
||||
@@ -128,11 +131,11 @@ function masonry(mode) {
|
||||
* Rearange the objects.
|
||||
*/
|
||||
$.each(posts, function() {
|
||||
$post = $("<div class=\"post platform\" onclick=\"requestPost(\'"+this['postID']+"\')\">");
|
||||
$post = $("<div class='post platform' onclick='requestPost(\'"+this['postID']+"\')'>");
|
||||
$post.append($("<h2>").html(this["title"]));
|
||||
$post.append($("<p>").html(this["content"]));
|
||||
$post.append($("<p class=\"subscript\">").text(this["nicetime"]));
|
||||
$post.append($("<p class=\"subscript\">").text("comments: " + this["comments"] + ", niet slechts: " + this["niet_slechts"]));
|
||||
$post.append($("<p class='subscript'>").text(this["nicetime"]));
|
||||
$post.append($("<p class='subscript'>").text("comments: " + this["comments"] + ", niet slechts: " + this["niet_slechts"]));
|
||||
|
||||
shortestColumn = getShortestColumn(columns);
|
||||
shortestColumn[1].append($post);
|
||||
|
||||
@@ -21,7 +21,7 @@ function updateAvatar(bool $group = false) {
|
||||
move_uploaded_file($tmpImg, $publicDir . $relativePath);
|
||||
} else {
|
||||
$relativePath = $avatarDir . $_SESSION["userID"] . "_avatar.png";
|
||||
$scaledImg = scaleAvatar($tmpImg);
|
||||
$scaledImg = scalePicture($tmpImg);
|
||||
$group ? removeOldGroupAvatar($_POST["groupID"]) : removeOldUserAvatar();
|
||||
imagepng($scaledImg, $publicDir . $relativePath);
|
||||
}
|
||||
@@ -30,6 +30,24 @@ function updateAvatar(bool $group = false) {
|
||||
throw new HappyAlert("Profielfoto veranderd.");
|
||||
}
|
||||
|
||||
function uploadPostPicture($userID) {
|
||||
$publicDir = "/var/www/html/public/";
|
||||
$tmpImg = $_FILES["picture"]["tmp_name"];
|
||||
$photoDir = "uploads/post/";
|
||||
if (getimagesize($tmpImg)["mime"] == "image/gif") {
|
||||
if ($_FILES["picture"]["size"] > 4000000) {
|
||||
throw new AngryAlert("Bestand is te groot, maximaal 4MB toegestaan.");
|
||||
}
|
||||
$relativePath = $photoDir . date_format(new DateTime(), "YmdHis") . "_" . $userID . ".gif";
|
||||
move_uploaded_file($tmpImg, $publicDir . $relativePath);
|
||||
} else {
|
||||
$relativePath = $photoDir . date_format(new DateTime(), "YmdHis") . "_" . $userID . ".png";
|
||||
$scaledImg = scalePicture($tmpImg);
|
||||
imagepng($scaledImg, $publicDir . $relativePath);
|
||||
}
|
||||
return $relativePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the old avatar from the uploads folder, for a user.
|
||||
*/
|
||||
@@ -128,7 +146,7 @@ function checkAvatarSize(string $img) {
|
||||
* @return bool|resource Returns the image as an Resource.
|
||||
* @throws AngryAlert
|
||||
*/
|
||||
function scaleAvatar(string $imgLink, int $newWidth = 600) {
|
||||
function scalePicture(string $imgLink, int $newWidth = 600) {
|
||||
$img = imagecreatefromstring(file_get_contents($imgLink));
|
||||
if ($img) {
|
||||
return imagescale($img, $newWidth);
|
||||
|
||||
@@ -97,20 +97,28 @@ function selectCommentsByPostId($postID) {
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
function makePost($userID, $groupID, $title, $content) {
|
||||
function makePost($userID, $title, $content, $groupID = null) {
|
||||
$picturePath = null;
|
||||
print_r($_FILES);
|
||||
if (array_key_exists("picture", $_FILES)) {
|
||||
$picturePath = uploadPostPicture($userID);
|
||||
}
|
||||
echo "Hallo!";
|
||||
$stmt = prepareQuery("
|
||||
INSERT INTO
|
||||
`post` (
|
||||
`author`,
|
||||
`groupID`,
|
||||
`title`,
|
||||
`content`
|
||||
`content`,
|
||||
`image`
|
||||
)
|
||||
VALUES (
|
||||
:userID,
|
||||
:groupID,
|
||||
:title,
|
||||
:content
|
||||
:content,
|
||||
:image
|
||||
)
|
||||
");
|
||||
|
||||
@@ -118,6 +126,7 @@ function makePost($userID, $groupID, $title, $content) {
|
||||
$stmt->bindParam(':groupID', $groupID);
|
||||
$stmt->bindParam(':title', $title);
|
||||
$stmt->bindParam(':content', $content);
|
||||
$stmt->bindParam(':image', $picturePath);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user