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