forked from Adleraci/adlerka.top
Do something
This commit is contained in:
parent
154fc4103f
commit
277232bdd1
@ -270,7 +270,7 @@ ul.navpage_list {
|
|||||||
display: flex !important;
|
display: flex !important;
|
||||||
max-height: 200px !important;
|
max-height: 200px !important;
|
||||||
width: inherit;
|
width: inherit;
|
||||||
box-sizing: border-box;
|
box-sizing: content-box;
|
||||||
transition-delay: .1s;
|
transition-delay: .1s;
|
||||||
}
|
}
|
||||||
.navsite_item:not(:hover) .navpage_list {
|
.navsite_item:not(:hover) .navpage_list {
|
||||||
|
@ -8,7 +8,10 @@ function endpoint($endpoint_data): array
|
|||||||
return match ($endpoint_data["action"]) {
|
return match ($endpoint_data["action"]) {
|
||||||
"getMyFiles" => listFiles(),
|
"getMyFiles" => listFiles(),
|
||||||
"getAllFiles" => listFiles(false),
|
"getAllFiles" => listFiles(false),
|
||||||
"UploadFiles" => parseIncomingFiles(),
|
"uploadFiles" => parseIncomingFiles(),
|
||||||
|
"addToGroup" => addToGroup($endpoint_data['group_id'], $endpoint_data['file_id']),
|
||||||
|
"myFileExists" => fileExists($endpoint_data['file_id'], ),
|
||||||
|
"FileExists" => fileExists($endpoint_data['file_id'], false),
|
||||||
default => ["Status" => "Fail", "message" => "Invalid action"],
|
default => ["Status" => "Fail", "message" => "Invalid action"],
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -24,11 +24,24 @@ function getEndpoint($endpoint_name): string
|
|||||||
$endpoint_file = $routerConfig["endpoint_dir"] . $endpoint_name . ".php";
|
$endpoint_file = $routerConfig["endpoint_dir"] . $endpoint_name . ".php";
|
||||||
|
|
||||||
if (file_exists($endpoint_file)){
|
if (file_exists($endpoint_file)){
|
||||||
$output = runEndpoint($endpoint_file);
|
$output_tmp = runEndpoint($endpoint_file);
|
||||||
|
$output["Endpoint"] = $endpoint_name;
|
||||||
|
switch (gettype($output)) {
|
||||||
|
case 'string':
|
||||||
|
$output = $output_tmp;
|
||||||
|
$output['Status'] = 'Success';
|
||||||
|
break;
|
||||||
|
case 'bool':
|
||||||
|
$output['Status'] = $output ? 'Success' : 'Fail';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$output['Status'] = 'Fail';
|
||||||
|
$output["Error"] = "Endpoint error";
|
||||||
|
http_response_code(500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$output["Error"] = "Not found";
|
$output["Error"] = "Not found";
|
||||||
$output["Endpoint"] = $endpoint_name;
|
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
lib/meme.php
Normal file
18
lib/meme.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function addMeme(string $memeText, int $imageID): bool
|
||||||
|
{
|
||||||
|
global $mysqli;
|
||||||
|
if(fileExists($imageID)){
|
||||||
|
$stmtMemeAdd = $mysqli->prepare('INSERT INTO Memes (AuthorID, TextContent, FileID) VALUES (?, ?, ?)');
|
||||||
|
$stmtMemeAdd->bind_param('isi', $_SESSION['ID'], htmlspecialchars($memeText), $imageID);
|
||||||
|
$stmtMemeAdd->execute();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderMemeGallery() :string
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
@ -43,7 +43,7 @@ function getIncomingFiles(): array
|
|||||||
return $files3;
|
return $files3;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveUploadedFileInDatabase($filePath, $fileType):bool
|
function saveUploadedFileInDatabase($filePath, $fileType): bool
|
||||||
{
|
{
|
||||||
global $mysqli;
|
global $mysqli;
|
||||||
$stmt = $mysqli->prepare("INSERT INTO Files (Path, Type, UploadedBy, UploadedAt) VALUES (?, ?, ?, NOW())");
|
$stmt = $mysqli->prepare("INSERT INTO Files (Path, Type, UploadedBy, UploadedAt) VALUES (?, ?, ?, NOW())");
|
||||||
@ -91,20 +91,20 @@ function doImageUpload($inFile, $outFile): bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function listFiles($onlyMine = true):array
|
function listFiles($onlyMine = true): array
|
||||||
{
|
{
|
||||||
$output = ["Status" => "Fail"];
|
$output = ["Status" => "Fail"];
|
||||||
require_once "lib/account.php";
|
require_once "lib/account.php";
|
||||||
if(($onlyMine && isLoggedIn()) || (!$onlyMine && isModerator())) {
|
if (($onlyMine && isLoggedIn()) || (!$onlyMine && isModerator())) {
|
||||||
global $mysqli;
|
global $mysqli;
|
||||||
$query = "SELECT ID, Path, Type, UploadedAt, UploadedBy FROM Files";
|
$query = "SELECT ID, Path, Type, UploadedAt, UploadedBy FROM Files";
|
||||||
|
|
||||||
if($onlyMine){
|
if ($onlyMine) {
|
||||||
$query .= " WHERE UploadedBy = ?";
|
$query .= " WHERE UploadedBy = ?";
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = $mysqli->prepare($query);
|
$stmt = $mysqli->prepare($query);
|
||||||
if($onlyMine) {
|
if ($onlyMine) {
|
||||||
$stmt->bind_param("i", $_SESSION["ID"]);
|
$stmt->bind_param("i", $_SESSION["ID"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ function parseIncomingFiles(): array
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$output = ["Status" => "Fail"];
|
$output = ["Status" => "Fail"];
|
||||||
if($success){
|
if ($success) {
|
||||||
$output["Status"] = "Success";
|
$output["Status"] = "Success";
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
@ -180,10 +180,52 @@ function getUploadPath($type = "unknown", $filename = "hehe"): string
|
|||||||
'image' => 'webp',
|
'image' => 'webp',
|
||||||
default => 'dummy',
|
default => 'dummy',
|
||||||
};
|
};
|
||||||
if($extension != "dummy") {
|
if ($extension != "dummy") {
|
||||||
return "uploads/$type/$id/$date/$filename.$extension";
|
return "uploads/$type/$id/$date/$filename.$extension";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fileExists(int $fileId, bool $onlyMine = true): bool
|
||||||
|
{
|
||||||
|
if(!$fileId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
global $mysqli;
|
||||||
|
if (!$onlyMine && !isAdmin()) {
|
||||||
|
$onlyMine = true;
|
||||||
|
}
|
||||||
|
$query = 'SELECT ID FROM Files WHERE ID = ?' . $onlyMine ? ' AND UploadedBy = ?' : '';
|
||||||
|
$stmtfileexists = $mysqli->prepare($query);
|
||||||
|
if ($onlyMine) {
|
||||||
|
$stmtfileexists->bind_param('ii', $fileId, $_SESSION['id']);
|
||||||
|
} else {
|
||||||
|
$stmtfileexists->bind_param('i', $fileId);
|
||||||
|
}
|
||||||
|
$stmtfileexists->execute();
|
||||||
|
return $stmtfileexists->affected_rows > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addToGroup(int $groupId, int $fileId): bool
|
||||||
|
{
|
||||||
|
$output = ["Status" => "Fail"];
|
||||||
|
if (!$groupId || !$fileId) {
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
global $mysqli;
|
||||||
|
$stmtcheck = $mysqli->prepare('SELECT ID FROM FileGroups WHERE CreatorID != ? AND ID = ?');
|
||||||
|
$stmtcheck->bind_param('ii', $_SESSION['id'], $groupId);
|
||||||
|
$stmtcheck->execute();
|
||||||
|
if ($stmtcheck->affected_rows == 0) {
|
||||||
|
if (fileExists($fileId, false)) {
|
||||||
|
$stmtadd = $mysqli->prepare('INSERT INTO FileGroups (FileID, CreatorID, ID) VALUES (?, ?, ?)');
|
||||||
|
$stmtadd->bind_param('iii', $fileId, $_SESSION['id'], $groupId);
|
||||||
|
$stmtadd->execute();
|
||||||
|
if ($stmtadd->affected_rows > 0) {
|
||||||
|
$output["Status"] = "Success";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user