diff options
author | Thomas Lange <code@nerdmind.de> | 2021-06-14 20:03:19 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2021-06-14 20:03:19 +0200 |
commit | 78fcc20190121d487a2e6cf1fca53b66df67dc3a (patch) | |
tree | b9b0dc3da8afc923fbac80ade147305cb7079e3f /admin/user | |
parent | d453ba414803832bb4e4f9ae5eddec7ae3f60205 (diff) | |
download | blog-78fcc20190121d487a2e6cf1fca53b66df67dc3a.tar.gz blog-78fcc20190121d487a2e6cf1fca53b66df67dc3a.tar.xz blog-78fcc20190121d487a2e6cf1fca53b66df67dc3a.zip |
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".
Diffstat (limited to 'admin/user')
-rw-r--r-- | admin/user/delete.php | 43 | ||||
-rw-r--r-- | admin/user/index.php | 63 | ||||
-rw-r--r-- | admin/user/insert.php | 43 | ||||
-rw-r--r-- | admin/user/update.php | 37 |
4 files changed, 75 insertions, 111 deletions
diff --git a/admin/user/delete.php b/admin/user/delete.php index 92aed0d..18a57cf 100644 --- a/admin/user/delete.php +++ b/admin/user/delete.php @@ -28,33 +28,24 @@ try { } #=============================================================================== - # TRY: Template\Exception + # Build document #=============================================================================== - try { - $FormTemplate = Template\Factory::build('user/form'); - $FormTemplate->set('HTML', $User->getHTML()); - $FormTemplate->set('FORM', [ - 'TYPE' => 'DELETE', - 'INFO' => $messages ?? [], - 'DATA' => array_change_key_case($Attribute->getAll(['password']), CASE_UPPER), - 'TOKEN' => Application::getSecurityToken() - ]); - - $DeleteTemplate = Template\Factory::build('user/delete'); - $DeleteTemplate->set('HTML', $FormTemplate); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_user_delete')); - $MainTemplate->set('HTML', $DeleteTemplate); - echo $MainTemplate; - } - - #=============================================================================== - # CATCH: Template\Exception - #=============================================================================== - catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); - } + $FormTemplate = Template\Factory::build('user/form'); + $FormTemplate->set('HTML', $User->getHTML()); + $FormTemplate->set('FORM', [ + 'TYPE' => 'DELETE', + 'INFO' => $messages ?? [], + 'DATA' => array_change_key_case($Attribute->getAll(['password']), CASE_UPPER), + 'TOKEN' => Application::getSecurityToken() + ]); + + $DeleteTemplate = Template\Factory::build('user/delete'); + $DeleteTemplate->set('HTML', $FormTemplate); + + $MainTemplate = Template\Factory::build('main'); + $MainTemplate->set('NAME', $Language->text('title_user_delete')); + $MainTemplate->set('HTML', $DeleteTemplate); + echo $MainTemplate; } #=============================================================================== diff --git a/admin/user/index.php b/admin/user/index.php index 223e83e..7d0cfa8 100644 --- a/admin/user/index.php +++ b/admin/user/index.php @@ -31,44 +31,35 @@ 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}"; $userIDs = $Database->query(sprintf($execSQL, User\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN); -#=============================================================================== -# TRY: Template\Exception -#=============================================================================== -try { - foreach($userIDs as $userID) { - try { - $User = User\Factory::build($userID); - $ItemTemplate = generateUserItemTemplate($User); - - $users[] = $ItemTemplate; - } catch(User\Exception $Exception){} - } - - $PaginationTemplate = Template\Factory::build('pagination'); - $PaginationTemplate->set('THIS', $currentSite); - $PaginationTemplate->set('LAST', $lastSite); - $PaginationTemplate->set('HREF', Application::getAdminURL('user/?site=%d')); - - $ListTemplate = Template\Factory::build('user/index'); - $ListTemplate->set('LIST', [ - 'USERS' => $users ?? [] - ]); +foreach($userIDs as $userID) { + try { + $User = User\Factory::build($userID); + $ItemTemplate = generateUserItemTemplate($User); - $ListTemplate->set('PAGINATION', [ - 'THIS' => $currentSite, - 'LAST' => $lastSite, - 'HTML' => $PaginationTemplate - ]); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_user_overview', $currentSite)); - $MainTemplate->set('HTML', $ListTemplate); - echo $MainTemplate; + $users[] = $ItemTemplate; + } 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('user/?site=%d')); + +$ListTemplate = Template\Factory::build('user/index'); +$ListTemplate->set('LIST', [ + 'USERS' => $users ?? [] +]); + +$ListTemplate->set('PAGINATION', [ + 'THIS' => $currentSite, + 'LAST' => $lastSite, + 'HTML' => $PaginationTemplate +]); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', $Language->text('title_user_overview', $currentSite)); +$MainTemplate->set('HTML', $ListTemplate); +echo $MainTemplate; diff --git a/admin/user/insert.php b/admin/user/insert.php index 0a50927..59b9444 100644 --- a/admin/user/insert.php +++ b/admin/user/insert.php @@ -40,29 +40,20 @@ if(HTTP::issetPOST('id', 'slug', 'username', 'password', 'fullname', 'mailaddr', } #=============================================================================== -# TRY: Template\Exception -#=============================================================================== -try { - $FormTemplate = Template\Factory::build('user/form'); - $FormTemplate->set('FORM', [ - 'TYPE' => 'INSERT', - 'INFO' => $messages ?? [], - 'DATA' => array_change_key_case($Attribute->getAll(['password']), CASE_UPPER), - 'TOKEN' => Application::getSecurityToken() - ]); - - $InsertTemplate = Template\Factory::build('user/insert'); - $InsertTemplate->set('HTML', $FormTemplate); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_user_insert')); - $MainTemplate->set('HTML', $InsertTemplate); - echo $MainTemplate; -} - -#=============================================================================== -# CATCH: Template\Exception -#=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +# Build document +#=============================================================================== +$FormTemplate = Template\Factory::build('user/form'); +$FormTemplate->set('FORM', [ + 'TYPE' => 'INSERT', + 'INFO' => $messages ?? [], + 'DATA' => array_change_key_case($Attribute->getAll(['password']), CASE_UPPER), + 'TOKEN' => Application::getSecurityToken() +]); + +$InsertTemplate = Template\Factory::build('user/insert'); +$InsertTemplate->set('HTML', $FormTemplate); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', $Language->text('title_user_insert')); +$MainTemplate->set('HTML', $InsertTemplate); +echo $MainTemplate; diff --git a/admin/user/update.php b/admin/user/update.php index 49ec335..b9b5f08 100644 --- a/admin/user/update.php +++ b/admin/user/update.php @@ -42,32 +42,23 @@ try { } #=============================================================================== - # TRY: Template\Exception + # Build document #=============================================================================== - try { - $FormTemplate = Template\Factory::build('user/form'); - $FormTemplate->set('FORM', [ - 'TYPE' => 'UPDATE', - 'INFO' => $messages ?? [], - 'DATA' => array_change_key_case($Attribute->getAll(['password']), CASE_UPPER), - 'TOKEN' => Application::getSecurityToken() - ]); + $FormTemplate = Template\Factory::build('user/form'); + $FormTemplate->set('FORM', [ + 'TYPE' => 'UPDATE', + 'INFO' => $messages ?? [], + 'DATA' => array_change_key_case($Attribute->getAll(['password']), CASE_UPPER), + 'TOKEN' => Application::getSecurityToken() + ]); - $InsertTemplate = Template\Factory::build('user/update'); - $InsertTemplate->set('HTML', $FormTemplate); + $InsertTemplate = Template\Factory::build('user/update'); + $InsertTemplate->set('HTML', $FormTemplate); - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_user_update')); - $MainTemplate->set('HTML', $InsertTemplate); - echo $MainTemplate; - } - - #=============================================================================== - # CATCH: Template\Exception - #=============================================================================== - catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); - } + $MainTemplate = Template\Factory::build('main'); + $MainTemplate->set('NAME', $Language->text('title_user_update')); + $MainTemplate->set('HTML', $InsertTemplate); + echo $MainTemplate; } #=============================================================================== |