diff --git a/endpoints/meme.php b/endpoints/meme.php index 3684fc7..8b4b1c1 100644 --- a/endpoints/meme.php +++ b/endpoints/meme.php @@ -7,6 +7,7 @@ function endpoint($endpoint_data): array return match ($endpoint_data["action"]) { "addMeme" => addMeme($endpoint_data['memetext'], $endpoint_data['imageid']), + "renderGallery" => renderMemeGallery(), default => ["Status" => "Fail", "message" => "Invalid action"], }; } \ No newline at end of file diff --git a/lib/meme.php b/lib/meme.php index 25af11c..656a58a 100644 --- a/lib/meme.php +++ b/lib/meme.php @@ -13,10 +13,24 @@ function addMeme(string $memeText, int $imageID): bool return false; } +function renderMeme(string $title, string $textContent, string $createdAt, string $filePath, string $userNickname): string +{ + global $routerConfig; + $meme_template = file_get_contents($routerConfig->template_dir . "meme.html"); + + $meme_out = str_replace('__TEMPLATE_MEME_TITLE__', htmlspecialchars($title), $meme_template); + $meme_out = str_replace('__TEMPLATE_MEME_AUTHOR__', htmlspecialchars($userNickname), $meme_out); + $meme_out = str_replace('__TEMPLATE_MEME_DATE__', htmlspecialchars($createdAt), $meme_out); + $meme_out = str_replace('__TEMPLATE_MEME_IMAGE__', htmlspecialchars($filePath), $meme_out); + + return str_replace('__TEMPLATE_MEME_TEXT__', htmlspecialchars($textContent), $meme_out); +} + function renderMemeGallery(): string { global $mysqli; - $stmtlist = $mysqli->prepare('SELECT Memes.ID, Memes.Title Memes.TextContent, Memes.CreatedAt, Files.Path, Files.Type, Users.Nickname FROM Memes INNER JOIN Users ON Memes.AuthorID = Users.ID INNER JOIN Files ON Memes.FileID = Files.ID'); + global $routerConfig; + $stmtlist = $mysqli->prepare('SELECT Memes.ID, Memes.Title, Memes.TextContent, Memes.CreatedAt, Files.Path, 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 $stmtlist->execute(); @@ -30,12 +44,18 @@ function renderMemeGallery(): string // Bind the result variables $stmtlist->bind_result($memeID, $title, $textContent, $createdAt, $filePath, $fileType, $userNickname); -// Fetch the results - while ($stmtlist->fetch()) { + $meme_gallery_template = file_get_contents($routerConfig->template_dir . "meme_gallery.html"); + // Fetch the results + $memes_out = ''; + while ($stmtlist->fetch()) { + if ($fileType == 'image') { + $memes_out .= renderMeme($title, $textContent, $createdAt, $filePath, $userNickname); + } } + $meme_gallery_out = str_replace('__TEMPLATE_MEMES_HERE__', $memes_out, $meme_gallery_template); // Close the statement $stmtlist->close(); - return ""; + return $meme_gallery_out; } \ No newline at end of file diff --git a/pages/memes/index.php b/pages/memes/index.php new file mode 100644 index 0000000..8645a64 --- /dev/null +++ b/pages/memes/index.php @@ -0,0 +1,18 @@ + $output, + "parameters" => + [ + "minimal_permission_level" => 1, + "secret" => "no", + "page_title" => "Účet" + ] +]; \ No newline at end of file diff --git a/templates/meme.html b/templates/meme.html index 6ee4fce..3269e97 100644 --- a/templates/meme.html +++ b/templates/meme.html @@ -1,8 +1,9 @@ -
-

__TEMPLATE_ARTICLE_TITLE__

-
-

__TEMPLATE_MEME_AUTHOR__

-

__TEMPLATE_MEME_DATE__

- +

__TEMPLATE_MEME_TITLE__

+
+

__TEMPLATE_MEME_AUTHOR__

+

__TEMPLATE_MEME_DATE__

+ +

__TEMPLATE_MEME_TEXT__

\ No newline at end of file diff --git a/pages/memes/index.html b/templates/meme_gallery.html similarity index 71% rename from pages/memes/index.html rename to templates/meme_gallery.html index 0a6bd69..d1e9e51 100644 --- a/pages/memes/index.html +++ b/templates/meme_gallery.html @@ -1,7 +1,11 @@ -

Adlerka Memes

Skoro, ako r/adlerka, ale lepšie.


-
\ No newline at end of file + +
+ +
\ No newline at end of file