diff options
Diffstat (limited to 'admin/page/delete.php')
-rw-r--r-- | admin/page/delete.php | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/admin/page/delete.php b/admin/page/delete.php index e1c95f0..2465f62 100644 --- a/admin/page/delete.php +++ b/admin/page/delete.php @@ -11,46 +11,46 @@ define('AUTHENTICATION', TRUE); require '../../core/application.php'; #=============================================================================== -# TRY: Page\Exception +# Get repositories #=============================================================================== -try { - $Page = Page\Factory::build(HTTP::GET('id')); - $Attribute = $Page->getAttribute(); +$PageRepository = Application::getRepository('Page'); - if(HTTP::issetPOST(['token' => Application::getSecurityToken()], 'delete')) { - try { - if($Attribute->delete($Database)) { - HTTP::redirect(Application::getAdminURL('page/')); - } - } catch(PDOException $Exception) { - $messages[] = $Exception->getMessage(); +#=============================================================================== +# Throw 404 error if page could not be found +#=============================================================================== +if(!$Page = $PageRepository->find(HTTP::GET('id'))) { + Application::error404(); +} + +#=============================================================================== +# Check for delete request +#=============================================================================== +if(HTTP::issetPOST(['token' => Application::getSecurityToken()], 'delete')) { + try { + if($PageRepository->delete($Page)) { + HTTP::redirect(Application::getAdminURL('page/')); } + } catch(PDOException $Exception) { + $messages[] = $Exception->getMessage(); } - - #=============================================================================== - # Build document - #=============================================================================== - $FormTemplate = Template\Factory::build('page/form'); - $FormTemplate->set('HTML', parseEntityContent($Page)); - $FormTemplate->set('FORM', [ - 'TYPE' => 'DELETE', - 'INFO' => $messages ?? [], - 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), - 'TOKEN' => Application::getSecurityToken() - ]); - - $DeleteTemplate = Template\Factory::build('page/delete'); - $DeleteTemplate->set('HTML', $FormTemplate); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_page_delete')); - $MainTemplate->set('HTML', $DeleteTemplate); - echo $MainTemplate; } #=============================================================================== -# CATCH: Page\Exception +# Build document #=============================================================================== -catch(Page\Exception $Exception) { - Application::error404(); -} +$FormTemplate = Template\Factory::build('page/form'); +$FormTemplate->set('HTML', parseEntityContent($Page)); +$FormTemplate->set('FORM', [ + 'TYPE' => 'DELETE', + 'INFO' => $messages ?? [], + 'DATA' => array_change_key_case($Page->getAll(), CASE_UPPER), + 'TOKEN' => Application::getSecurityToken() +]); + +$DeleteTemplate = Template\Factory::build('page/delete'); +$DeleteTemplate->set('HTML', $FormTemplate); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', $Language->text('title_page_delete')); +$MainTemplate->set('HTML', $DeleteTemplate); +echo $MainTemplate; |