Add /edit endpoint to update placeholders

This commit is contained in:
Mike Colagrosso 2024-12-17 21:06:01 -07:00 committed by Alex Cabal
parent b125758138
commit f449c024ea
7 changed files with 297 additions and 73 deletions

35
www/ebooks/edit.php Normal file
View file

@ -0,0 +1,35 @@
<?
$ebook = null;
try{
if(Session::$User === null){
throw new Exceptions\LoginRequiredException();
}
if(!Session::$User->Benefits->CanEditEbookPlaceholders){
throw new Exceptions\InvalidPermissionsException();
}
$identifier = EBOOKS_IDENTIFIER_PREFIX . trim(str_replace('.', '', HttpInput::Str(GET, 'url-path') ?? ''), '/');
$ebook = Ebook::GetByIdentifier($identifier);
if($ebook->IsPlaceholder()){
require('/standardebooks.org/web/www/ebook-placeholders/edit.php');
exit();
}
// Editing published `Ebooks` is not supported.
Template::Emit404();
}
catch(Exceptions\EbookNotFoundException){
Template::Emit404();
}
catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin();
}
catch(Exceptions\InvalidPermissionsException){
Template::Emit403();
}