Add PHPDocs generated by ChatGPT,
add additional clarification to some functions, add addNewsComment function and API, currently untested and not implemented in the client, fix a bunch of stuff that PHPStorm pointed out
This commit is contained in:
77
lib/meme.php
77
lib/meme.php
@@ -2,7 +2,15 @@
|
||||
|
||||
require_once "lib/upload.php";
|
||||
require_once "lib/account.php";
|
||||
|
||||
/**
|
||||
* Adds a meme to the database with associated image and text content.
|
||||
*
|
||||
* @param string $title The title of the meme.
|
||||
* @param string $memeText The text content of the meme.
|
||||
* @param int $imageID The ID of the image associated with the meme.
|
||||
* @global mysqli $mysqli The database connection object.
|
||||
* @return array Returns an associative array with the operation status and a message.
|
||||
*/
|
||||
function addMeme(string $title, string $memeText, int $imageID): array
|
||||
{
|
||||
global $mysqli;
|
||||
@@ -17,7 +25,21 @@ function addMeme(string $title, string $memeText, int $imageID): array
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a meme into HTML based on provided data and a template.
|
||||
*
|
||||
* @param int $id The ID of the meme.
|
||||
* @param int $authorId The author's user ID.
|
||||
* @param string $title The title of the meme.
|
||||
* @param string $textContent The text content of the meme.
|
||||
* @param string $createdAt The creation timestamp of the meme.
|
||||
* @param string $filePath The file path of the associated image.
|
||||
* @param int $imageWidth The width of the image.
|
||||
* @param int $imageHeight The height of the image.
|
||||
* @param string $userNickname The nickname of the meme's author.
|
||||
* @param string $meme_template The HTML template for a meme. (used to not read the template over and over when rendering more memes)
|
||||
* @return string Returns the rendered HTML of the meme.
|
||||
*/
|
||||
function renderMeme(int $id, int $authorId, string $title, string $textContent, string $createdAt, string $filePath, int $imageWidth, int $imageHeight, string $userNickname, string $meme_template): string
|
||||
{
|
||||
|
||||
@@ -64,7 +86,14 @@ function renderMeme(int $id, int $authorId, string $title, string $textContent,
|
||||
|
||||
return str_replace('__TEMPLATE_MEME_TEXT__', htmlspecialchars($textContent), $meme_out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an HTML representation of a gallery of memes from the database.
|
||||
* Renders the memes using renderMeme.
|
||||
*
|
||||
* @global mysqli $mysqli The database connection object.
|
||||
* @global array $routerConfig Configuration settings including paths to templates.
|
||||
* @return string Returns the complete HTML content of the meme gallery.
|
||||
*/
|
||||
function renderMemeGallery(): string
|
||||
{
|
||||
global $mysqli;
|
||||
@@ -105,7 +134,13 @@ function renderMemeGallery(): string
|
||||
$stmtlist->close();
|
||||
return $meme_gallery_out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a meme from the database if the current user has the right permissions.
|
||||
*
|
||||
* @param int $memeID The ID of the meme to delete.
|
||||
* @global mysqli $mysqli The database connection object.
|
||||
* @return array Returns an associative array with the status of the operation.
|
||||
*/
|
||||
function deleteMeme(int $memeID): array
|
||||
{
|
||||
global $mysqli;
|
||||
@@ -126,7 +161,14 @@ function deleteMeme(int $memeID): array
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Records or updates a vote on a meme by the current user.
|
||||
*
|
||||
* @param int $memeID The ID of the meme to be voted on.
|
||||
* @param int $isUpvote Indicates whether the vote is an upvote (1) or downvote (0).
|
||||
* @global mysqli $mysqli The database connection object.
|
||||
* @return array Returns an associative array with the status of the vote operation.
|
||||
*/
|
||||
function voteMeme(int $memeID, int $isUpvote): array
|
||||
{
|
||||
global $mysqli;
|
||||
@@ -143,7 +185,13 @@ function voteMeme(int $memeID, int $isUpvote): array
|
||||
$memeVoteConn->close();
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a vote previously made by the current user on a meme.
|
||||
*
|
||||
* @param int $memeID The ID of the meme whose vote is to be deleted.
|
||||
* @global mysqli $mysqli The database connection object.
|
||||
* @return array Returns an associative array with the status of the deletion.
|
||||
*/
|
||||
function deleteVoteMeme(int $memeID): array
|
||||
{
|
||||
global $mysqli;
|
||||
@@ -157,7 +205,14 @@ function deleteVoteMeme(int $memeID): array
|
||||
$memeVoteConn->close();
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the net votes for a meme and determines if the current user has voted on it.
|
||||
* The array has both the net votes and the user vote(0 when the user hasn't voted)
|
||||
*
|
||||
* @param int $memeID The ID of the meme for which votes are being calculated.
|
||||
* @global mysqli $mysqli The database connection object.
|
||||
* @return array Returns an array with net votes and the user's vote status.
|
||||
*/
|
||||
function calculateNetVotes(int $memeID): array
|
||||
{
|
||||
global $mysqli;
|
||||
@@ -193,7 +248,13 @@ function calculateNetVotes(int $memeID): array
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetches the net votes and user's vote status for a specific meme.
|
||||
* Essentially just a wrapper of getMemeVotes for an API call
|
||||
*
|
||||
* @param int $memeID The ID of the meme to fetch votes for.
|
||||
* @return array Returns an array with the net votes and the user's vote status, along with operation status.
|
||||
*/
|
||||
function getMemeVotes(int $memeID): array
|
||||
{
|
||||
$voteData = calculateNetVotes($memeID);
|
||||
|
Reference in New Issue
Block a user