aboutsummaryrefslogtreecommitdiffstats
path: root/admin/post
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2021-06-14 20:03:19 +0200
committerThomas Lange <code@nerdmind.de>2021-06-14 20:03:19 +0200
commit78fcc20190121d487a2e6cf1fca53b66df67dc3a (patch)
treeb9b0dc3da8afc923fbac80ade147305cb7079e3f /admin/post
parentd453ba414803832bb4e4f9ae5eddec7ae3f60205 (diff)
downloadblog-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/post')
-rw-r--r--admin/post/delete.php43
-rw-r--r--admin/post/index.php67
-rw-r--r--admin/post/insert.php59
-rw-r--r--admin/post/search.php25
-rw-r--r--admin/post/update.php59
5 files changed, 104 insertions, 149 deletions
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;
}
#===============================================================================