diff --git a/endpoints/account.php b/endpoints/account.php index ad4075a..e1b5de2 100644 --- a/endpoints/account.php +++ b/endpoints/account.php @@ -1,4 +1,5 @@ " : '', $meme_out); $meme_votes = calculateNetVotes($id); @@ -48,10 +51,10 @@ function renderMeme(int $id, int $authorId, string $title, string $textContent, $meme_upvote = isLoggedIn() ? "" : ''; $meme_downvote = isLoggedIn() ? "" : ''; - $meme_out = str_replace('__TEMPLATE_MEME_VOTES_NUMBER__', $meme_net_votes, $meme_out); + $meme_out = str_replace('__TEMPLATE_MEME_VOTES_NUMBER__', strval($meme_net_votes), $meme_out); $meme_out = str_replace('__TEMPLATE_MEME_UPVOTE__', $meme_upvote, $meme_out); $meme_out = str_replace('__TEMPLATE_MEME_DOWNVOTE__', $meme_downvote, $meme_out); - $meme_out = str_replace('__TEMPLATE_MEME_ID__', $id, $meme_out); + $meme_out = str_replace('__TEMPLATE_MEME_ID__', strval($id), $meme_out); $meme_out = str_replace('__TEMPLATE_MEME_VOTE_COUNTER_CLASS__', $meme_vote_counter_class, $meme_out); return str_replace('__TEMPLATE_MEME_TEXT__', htmlspecialchars($textContent), $meme_out); @@ -61,7 +64,7 @@ function renderMemeGallery(): string { global $mysqli; global $routerConfig; - $stmtlist = $mysqli->prepare('SELECT Memes.ID, Memes.Title, Memes.TextContent, Memes.CreatedAt, Memes.AuthorID, Files.Path, Files.Type, Users.Nickname FROM Memes INNER JOIN Users ON Memes.AuthorID = Users.ID INNER JOIN Files ON Memes.FileID = Files.ID'); + $stmtlist = $mysqli->prepare('SELECT Memes.ID, Memes.Title, Memes.TextContent, Memes.CreatedAt, Memes.AuthorID, Files.Path, Files.Width, Files.Height, Files.Type, Users.Nickname FROM Memes INNER JOIN Users ON Memes.AuthorID = Users.ID INNER JOIN Files ON Memes.FileID = Files.ID'); // Execute the prepared statement $memeID = 0; @@ -72,8 +75,10 @@ function renderMemeGallery(): string $fileType = ""; $userNickname = ""; $createdAt = ""; + $imageWidth = 0; + $imageHeight = 0; // Bind the result variables - $stmtlist->bind_result($memeID, $title, $textContent, $createdAt, $authorID, $filePath, $fileType, $userNickname); + $stmtlist->bind_result($memeID, $title, $textContent, $createdAt, $authorID, $filePath, $imageWidth, $imageHeight, $fileType, $userNickname); $stmtlist->execute(); $meme_gallery_template = file_get_contents($routerConfig['template_dir'] . 'meme_gallery.html'); @@ -84,7 +89,7 @@ function renderMemeGallery(): string $stmtlist->store_result(); while ($stmtlist->fetch()) { if (str_starts_with($fileType, 'image')) { - $memes_out .= renderMeme($memeID, $authorID, $title, $textContent, $createdAt, $filePath, $userNickname, $meme_template); + $memes_out .= renderMeme($memeID, $authorID, $title, $textContent, $createdAt, $filePath, $imageWidth, $imageHeight, $userNickname, $meme_template); } } $meme_add = isLoggedIn() ? file_get_contents($routerConfig['template_dir'] . 'meme_add.html') : ''; diff --git a/lib/navigation.php b/lib/navigation.php index df9fe06..cf0a2b4 100644 --- a/lib/navigation.php +++ b/lib/navigation.php @@ -1,4 +1,5 @@ 0 && count(array_filter(array_keys($phpArray), 'is_string')) === count($phpArray)) { diff --git a/lib/sitemap.php b/lib/sitemap.php index 967be22..f10414a 100644 --- a/lib/sitemap.php +++ b/lib/sitemap.php @@ -1,4 +1,5 @@ prepare("INSERT INTO Files (Path, Type, UploadedBy, UploadedAt) VALUES (?, ?, ?, NOW())"); - $stmt->bind_param("ssi", $filePath, $fileType, $_SESSION["ID"]); + $stmt = $mysqli->prepare("INSERT INTO Files (Path, Type, UploadedBy, UploadedAt, Width, Height) VALUES (?, ?, ?, NOW(), ?, ?)"); + $stmt->bind_param("ssiii", $filePath, $fileType, $_SESSION["ID"], $width, $height); $stmt->execute(); $stat = $stmt->affected_rows > 0; $stmt->close(); @@ -82,19 +83,23 @@ function saveUploadedFileInDatabase($filePath, $fileType): bool function doImageUpload($inFile, $outFile): bool { // Create Imagick object + $width = 0; + $height = 0; try { $imagick = new Imagick($inFile); $imagick->setImageFormat('webp'); autoRotateImage($imagick); $imagick->stripImage(); $imagick->writeImage($outFile); + $width = $imagick->getImageWidth(); + $height = $imagick->getImageHeight(); $imagick->destroy(); } catch (ImagickException) { } // Check if the reencoding was successful if (file_exists($outFile)) { - return saveUploadedFileInDatabase($outFile, 'image/webp'); + return saveUploadedFileInDatabase($outFile, 'image/webp', $width, $height); } else { return false; } diff --git a/pages/account/index.php b/pages/account/index.php index 8cb3995..8c7e196 100644 --- a/pages/account/index.php +++ b/pages/account/index.php @@ -1,4 +1,5 @@
__TEMPLATE_MEME_TEXT__