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

View file

@ -1,15 +1,24 @@
<?
use function Safe\preg_replace;
use function Safe\session_unset;
session_start();
/** @var string $identifier Passed from script this is included from. */
$ebook = null;
$isSaved = HttpInput::Bool(SESSION, 'is-ebook-placeholder-saved') ?? false;
try{
$ebook = Ebook::GetByIdentifier($identifier);
if($ebook->EbookPlaceholder === null){
throw new Exceptions\EbookNotFoundException();
}
if($isSaved){
session_unset();
}
}
catch(Exceptions\EbookNotFoundException){
Template::Emit404();
@ -53,6 +62,10 @@ catch(Exceptions\EbookNotFoundException){
</hgroup>
</header>
<? if($isSaved){ ?>
<p class="message success">Ebook Placeholder saved!</p>
<? } ?>
<aside id="reading-ease">
<? if($ebook->ContributorsHtml != ''){ ?>
<p><?= $ebook->ContributorsHtml ?></p>
@ -109,6 +122,11 @@ catch(Exceptions\EbookNotFoundException){
<? if(Session::$User?->Benefits->CanEditProjects || Session::$User?->Benefits->CanManageProjects || Session::$User?->Benefits->CanReviewProjects){ ?>
<?= Template::EbookProjects(['ebook' => $ebook, 'showAddButton' => Session::$User->Benefits->CanEditProjects && $ebook->ProjectInProgress === null]) ?>
<? } ?>
<? if(Session::$User?->Benefits->CanEditEbookPlaceholders){ ?>
<h2>Edit ebook placeholder</h2>
<p><a href="<?= $ebook->EditUrl ?>">Edit this ebook placeholder.</a></p>
<? } ?>
</article>
</main>
<?= Template::Footer() ?>