From 78fcc20190121d487a2e6cf1fca53b66df67dc3a Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Mon, 14 Jun 2021 20:03:19 +0200 Subject: Remove more redundant try/catch blocks Remove all try/catch blocks where the exception handling did not differ from the exception handler already defined by "set_exception_handler". --- admin/post/delete.php | 43 +++++++++++++-------------------- admin/post/index.php | 67 ++++++++++++++++++++++----------------------------- admin/post/insert.php | 59 +++++++++++++++++++-------------------------- admin/post/search.php | 25 ++++++------------- admin/post/update.php | 59 +++++++++++++++++++-------------------------- 5 files changed, 104 insertions(+), 149 deletions(-) (limited to 'admin/post') diff --git a/admin/post/delete.php b/admin/post/delete.php index 792b958..6da8a68 100644 --- a/admin/post/delete.php +++ b/admin/post/delete.php @@ -28,33 +28,24 @@ try { } #=============================================================================== - # TRY: Template\Exception + # Build document #=============================================================================== - try { - $FormTemplate = Template\Factory::build('post/form'); - $FormTemplate->set('HTML', $Post->getHTML()); - $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: Template\Exception - #=============================================================================== - catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); - } + $FormTemplate = Template\Factory::build('post/form'); + $FormTemplate->set('HTML', $Post->getHTML()); + $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; } #=============================================================================== diff --git a/admin/post/index.php b/admin/post/index.php index 7793c9b..e18a634 100644 --- a/admin/post/index.php +++ b/admin/post/index.php @@ -31,48 +31,39 @@ if($currentSite < 1 OR ($currentSite > $lastSite AND $lastSite > 0)) { $execSQL = "SELECT id FROM %s ORDER BY {$site_sort} LIMIT ".(($currentSite-1) * $site_size).", {$site_size}"; $postIDs = $Database->query(sprintf($execSQL, Post\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN); -#=============================================================================== -# TRY: Template\Exception -#=============================================================================== -try { - foreach($postIDs as $postID) { - try { - $Post = Post\Factory::build($postID); - $User = User\Factory::build($Post->attr('user')); +foreach($postIDs as $postID) { + try { + $Post = Post\Factory::build($postID); + $User = User\Factory::build($Post->attr('user')); - $ItemTemplate = generatePostItemTemplate($Post, $User); + $ItemTemplate = generatePostItemTemplate($Post, $User); - $posts[] = $ItemTemplate; - } - catch(Post\Exception $Exception){} - catch(User\Exception $Exception){} + $posts[] = $ItemTemplate; } - - $PaginationTemplate = Template\Factory::build('pagination'); - $PaginationTemplate->set('THIS', $currentSite); - $PaginationTemplate->set('LAST', $lastSite); - $PaginationTemplate->set('HREF', Application::getAdminURL('post/?site=%d')); - - $ListTemplate = Template\Factory::build('post/index'); - $ListTemplate->set('LIST', [ - 'POSTS' => $posts ?? [] - ]); - - $ListTemplate->set('PAGINATION', [ - 'THIS' => $currentSite, - 'LAST' => $lastSite, - 'HTML' => $PaginationTemplate - ]); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_post_overview', $currentSite)); - $MainTemplate->set('HTML', $ListTemplate); - echo $MainTemplate; + catch(Post\Exception $Exception){} + catch(User\Exception $Exception){} } #=============================================================================== -# CATCH: Template\Exception +# Build document #=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +$PaginationTemplate = Template\Factory::build('pagination'); +$PaginationTemplate->set('THIS', $currentSite); +$PaginationTemplate->set('LAST', $lastSite); +$PaginationTemplate->set('HREF', Application::getAdminURL('post/?site=%d')); + +$ListTemplate = Template\Factory::build('post/index'); +$ListTemplate->set('LIST', [ + 'POSTS' => $posts ?? [] +]); + +$ListTemplate->set('PAGINATION', [ + 'THIS' => $currentSite, + 'LAST' => $lastSite, + 'HTML' => $PaginationTemplate +]); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', $Language->text('title_post_overview', $currentSite)); +$MainTemplate->set('HTML', $ListTemplate); +echo $MainTemplate; diff --git a/admin/post/insert.php b/admin/post/insert.php index 6916a61..6065c95 100644 --- a/admin/post/insert.php +++ b/admin/post/insert.php @@ -37,42 +37,33 @@ if(HTTP::issetPOST('id', 'user', 'slug', 'name', 'body', 'argv', 'time_insert', } } -#=============================================================================== -# TRY: Template\Exception -#=============================================================================== -try { - $userIDs = $Database->query(sprintf('SELECT id FROM %s ORDER BY fullname ASC', User\Attribute::TABLE)); - - foreach($userIDs->fetchAll($Database::FETCH_COLUMN) as $userID) { - $User = User\Factory::build($userID); - $userAttributes[] = [ - 'ID' => $User->attr('id'), - 'FULLNAME' => $User->attr('fullname'), - 'USERNAME' => $User->attr('username'), - ]; - } - - $FormTemplate = Template\Factory::build('post/form'); - $FormTemplate->set('FORM', [ - 'TYPE' => 'INSERT', - 'INFO' => $messages ?? [], - 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), - 'USER_LIST' => $userAttributes ?? [], - 'TOKEN' => Application::getSecurityToken() - ]); +$userIDs = $Database->query(sprintf('SELECT id FROM %s ORDER BY fullname ASC', User\Attribute::TABLE)); - $InsertTemplate = Template\Factory::build('post/insert'); - $InsertTemplate->set('HTML', $FormTemplate); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_post_insert')); - $MainTemplate->set('HTML', $InsertTemplate); - echo $MainTemplate; +foreach($userIDs->fetchAll($Database::FETCH_COLUMN) as $userID) { + $User = User\Factory::build($userID); + $userAttributes[] = [ + 'ID' => $User->attr('id'), + 'FULLNAME' => $User->attr('fullname'), + 'USERNAME' => $User->attr('username'), + ]; } #=============================================================================== -# CATCH: Template\Exception +# Build document #=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +$FormTemplate = Template\Factory::build('post/form'); +$FormTemplate->set('FORM', [ + 'TYPE' => 'INSERT', + 'INFO' => $messages ?? [], + 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), + 'USER_LIST' => $userAttributes ?? [], + 'TOKEN' => Application::getSecurityToken() +]); + +$InsertTemplate = Template\Factory::build('post/insert'); +$InsertTemplate->set('HTML', $FormTemplate); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', $Language->text('title_post_insert')); +$MainTemplate->set('HTML', $InsertTemplate); +echo $MainTemplate; diff --git a/admin/post/search.php b/admin/post/search.php index cd28322..8fe6a51 100644 --- a/admin/post/search.php +++ b/admin/post/search.php @@ -29,23 +29,14 @@ if($search = HTTP::GET('q')) { } #=============================================================================== -# TRY: Template\Exception +# Build document #=============================================================================== -try { - $SearchTemplate = Template\Factory::build('post/search'); - $SearchTemplate->set('QUERY', $search); - $SearchTemplate->set('POSTS', $posts ?? []); +$SearchTemplate = Template\Factory::build('post/search'); +$SearchTemplate->set('QUERY', $search); +$SearchTemplate->set('POSTS', $posts ?? []); - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_post_search')); - $MainTemplate->set('HTML', $SearchTemplate); +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', $Language->text('title_post_search')); +$MainTemplate->set('HTML', $SearchTemplate); - echo $MainTemplate; -} - -#=============================================================================== -# CATCH: Template\Exception -#=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +echo $MainTemplate; diff --git a/admin/post/update.php b/admin/post/update.php index 7b82bf4..d7778f8 100644 --- a/admin/post/update.php +++ b/admin/post/update.php @@ -39,45 +39,36 @@ try { } } - #=============================================================================== - # TRY: Template\Exception - #=============================================================================== - try { - $userIDs = $Database->query(sprintf('SELECT id FROM %s ORDER BY fullname ASC', User\Attribute::TABLE)); - - foreach($userIDs->fetchAll($Database::FETCH_COLUMN) as $userID) { - $User = User\Factory::build($userID); - $userAttributes[] = [ - 'ID' => $User->attr('id'), - 'FULLNAME' => $User->attr('fullname'), - 'USERNAME' => $User->attr('username'), - ]; - } - - $FormTemplate = Template\Factory::build('post/form'); - $FormTemplate->set('FORM', [ - 'TYPE' => 'UPDATE', - 'INFO' => $messages ?? [], - 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), - 'USER_LIST' => $userAttributes ?? [], - 'TOKEN' => Application::getSecurityToken() - ]); + $userIDs = $Database->query(sprintf('SELECT id FROM %s ORDER BY fullname ASC', User\Attribute::TABLE)); - $PostUpdateTemplate = Template\Factory::build('post/update'); - $PostUpdateTemplate->set('HTML', $FormTemplate); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_post_update')); - $MainTemplate->set('HTML', $PostUpdateTemplate); - echo $MainTemplate; + foreach($userIDs->fetchAll($Database::FETCH_COLUMN) as $userID) { + $User = User\Factory::build($userID); + $userAttributes[] = [ + 'ID' => $User->attr('id'), + 'FULLNAME' => $User->attr('fullname'), + 'USERNAME' => $User->attr('username'), + ]; } #=============================================================================== - # CATCH: Template\Exception + # Build document #=============================================================================== - catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); - } + $FormTemplate = Template\Factory::build('post/form'); + $FormTemplate->set('FORM', [ + 'TYPE' => 'UPDATE', + 'INFO' => $messages ?? [], + 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), + 'USER_LIST' => $userAttributes ?? [], + 'TOKEN' => Application::getSecurityToken() + ]); + + $PostUpdateTemplate = Template\Factory::build('post/update'); + $PostUpdateTemplate->set('HTML', $FormTemplate); + + $MainTemplate = Template\Factory::build('main'); + $MainTemplate->set('NAME', $Language->text('title_post_update')); + $MainTemplate->set('HTML', $PostUpdateTemplate); + echo $MainTemplate; } #=============================================================================== -- cgit v1.2.3