diff --git a/app/Web/Routes/admin/addons.php b/app/Web/Routes/admin/addons.php index bf28aa7..3b1d18f 100755 --- a/app/Web/Routes/admin/addons.php +++ b/app/Web/Routes/admin/addons.php @@ -20,6 +20,55 @@ global $router; +$router->add('/admin/plugins/upload', function (): void { + global $router, $event, $renderer; + $template = 'admin/plugins/upload.twig'; + if (isset($_COOKIE['token']) === false) { + exit(header('location: /auth/login')); + } + + $user = new UserHelper($_COOKIE['token'], $renderer); + UserDataHandler::requireAuthorization($renderer, $_COOKIE['token']); + + if ( + !UserDataHandler::hasPermission($_COOKIE['token'], 'mythicalframework.admin.plugins.install') + ) { + exit(header('location: /errors/403')); + } + + $renderer->addGlobal('page_name', 'Upload Plugin'); + Engine::registerAlerts($renderer, $template); + + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_FILES['pluginFile']) && $_FILES['pluginFile']['error'] === UPLOAD_ERR_OK) { + $fileTmpPath = $_FILES['pluginFile']['tmp_name']; + $fileName = $_FILES['pluginFile']['name']; + $fileSize = $_FILES['pluginFile']['size']; + $fileType = $_FILES['pluginFile']['type']; + $fileNameCmps = explode(".", $fileName); + $fileExtension = strtolower(end($fileNameCmps)); + + if ($fileExtension === 'mfa') { + // Process the file upload (e.g., move to the desired directory) + $uploadFileDir = '/path/to/upload/directory/'; + $dest_path = $uploadFileDir . $fileName; + + if (move_uploaded_file($fileTmpPath, $dest_path)) { + exit(header('location: /admin/plugins?s=ok')); + } else { + exit(header('location: /admin/plugins?s=error')); + } + } else { + $renderer->addGlobal('error', 'Invalid file type. Only .mfa files are allowed.'); + } + } else { + $renderer->addGlobal('error', 'There was an error with the file upload.'); + } + } + + exit($renderer->render($template)); +}); + $router->add('/admin/plugins', function (): void { global $router, $event, $renderer; $template = 'admin/plugins/list.twig'; diff --git a/storage/lang/en_US.yml b/storage/lang/en_US.yml index 5cc4d15..4189890 100755 --- a/storage/lang/en_US.yml +++ b/storage/lang/en_US.yml @@ -499,6 +499,8 @@ Alerts: Message: "You have successfully verified two factor authentication." Error: + Plugins: + Social: CannotLikeYourSelf: Title: "Cannot Like Yourself" diff --git a/storage/themes/v2/admin/plugins/list.twig b/storage/themes/v2/admin/plugins/list.twig index 105c4b1..3d296fe 100755 --- a/storage/themes/v2/admin/plugins/list.twig +++ b/storage/themes/v2/admin/plugins/list.twig @@ -30,7 +30,7 @@