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 /core | |
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 'core')
-rw-r--r-- | core/include/feed/main.php | 99 | ||||
-rw-r--r-- | core/include/home.php | 67 | ||||
-rw-r--r-- | core/include/page/list.php | 65 | ||||
-rw-r--r-- | core/include/page/main.php | 52 | ||||
-rw-r--r-- | core/include/post/list.php | 65 | ||||
-rw-r--r-- | core/include/post/main.php | 52 | ||||
-rw-r--r-- | core/include/search/main.php | 77 | ||||
-rw-r--r-- | core/include/user/list.php | 61 | ||||
-rw-r--r-- | core/include/user/main.php | 65 |
9 files changed, 251 insertions, 352 deletions
diff --git a/core/include/feed/main.php b/core/include/feed/main.php index cd53fa0..765f296 100644 --- a/core/include/feed/main.php +++ b/core/include/feed/main.php @@ -11,72 +11,69 @@ $Language = Application::getLanguage(); HTTP::responseHeader(HTTP::HEADER_CONTENT_TYPE, HTTP::CONTENT_TYPE_XML); #=============================================================================== -# TRY: Template\Exception +# Post feed #=============================================================================== -try { - if(!isset($param) OR $param !== 'page') { - $POST['FEED_SORT'] = Application::get('POST.FEED_SORT'); - $POST['FEED_SIZE'] = Application::get('POST.FEED_SIZE'); +if(!isset($param) OR $param !== 'page') { + $POST['FEED_SORT'] = Application::get('POST.FEED_SORT'); + $POST['FEED_SIZE'] = Application::get('POST.FEED_SIZE'); - $execSQL = "SELECT id FROM %s ORDER BY {$POST['FEED_SORT']} LIMIT {$POST['FEED_SIZE']}"; - $postIDs = $Database->query(sprintf($execSQL, Post\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN); + $execSQL = "SELECT id FROM %s ORDER BY {$POST['FEED_SORT']} LIMIT {$POST['FEED_SIZE']}"; + $postIDs = $Database->query(sprintf($execSQL, Post\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN); - 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 = Template\Factory::build('feed/item_post'); - $ItemTemplate->set('POST', generateItemTemplateData($Post)); - $ItemTemplate->set('USER', generateItemTemplateData($User)); + $ItemTemplate = Template\Factory::build('feed/item_post'); + $ItemTemplate->set('POST', generateItemTemplateData($Post)); + $ItemTemplate->set('USER', generateItemTemplateData($User)); - $posts[] = $ItemTemplate; - } - - catch(Post\Exception $Exception){} - catch(User\Exception $Exception){} + $posts[] = $ItemTemplate; } - } - if(!isset($param) OR $param !== 'post') { - $PAGE['FEED_SORT'] = Application::get('PAGE.FEED_SORT'); - $PAGE['FEED_SIZE'] = Application::get('PAGE.FEED_SIZE'); + catch(Post\Exception $Exception){} + catch(User\Exception $Exception){} + } +} - $execSQL = "SELECT id FROM %s ORDER BY {$PAGE['FEED_SORT']} LIMIT {$PAGE['FEED_SIZE']}"; - $pageIDs = $Database->query(sprintf($execSQL, Page\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN); +#=============================================================================== +# Page feed +#=============================================================================== +if(!isset($param) OR $param !== 'post') { + $PAGE['FEED_SORT'] = Application::get('PAGE.FEED_SORT'); + $PAGE['FEED_SIZE'] = Application::get('PAGE.FEED_SIZE'); - foreach($pageIDs as $pageID) { - try { - $Page = Page\Factory::build($pageID); - $User = User\Factory::build($Page->attr('user')); + $execSQL = "SELECT id FROM %s ORDER BY {$PAGE['FEED_SORT']} LIMIT {$PAGE['FEED_SIZE']}"; + $pageIDs = $Database->query(sprintf($execSQL, Page\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN); - $ItemTemplate = Template\Factory::build('feed/item_page'); - $ItemTemplate->set('PAGE', generateItemTemplateData($Page)); - $ItemTemplate->set('USER', generateItemTemplateData($User)); + foreach($pageIDs as $pageID) { + try { + $Page = Page\Factory::build($pageID); + $User = User\Factory::build($Page->attr('user')); - $pages[] = $ItemTemplate; - } + $ItemTemplate = Template\Factory::build('feed/item_page'); + $ItemTemplate->set('PAGE', generateItemTemplateData($Page)); + $ItemTemplate->set('USER', generateItemTemplateData($User)); - catch(Page\Exception $Exception){} - catch(User\Exception $Exception){} + $pages[] = $ItemTemplate; } - } - - $FeedTemplate = Template\Factory::build('feed/main'); - $FeedTemplate->set('FEED', [ - 'TYPE' => $param ?? NULL, - 'LIST' => [ - 'POSTS' => $posts ?? [], - 'PAGES' => $pages ?? [], - ] - ]); - echo $FeedTemplate; + catch(Page\Exception $Exception){} + catch(User\Exception $Exception){} + } } #=============================================================================== -# CATCH: Template\Exception +# Build document #=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +$FeedTemplate = Template\Factory::build('feed/main'); +$FeedTemplate->set('FEED', [ + 'TYPE' => $param ?? NULL, + 'LIST' => [ + 'POSTS' => $posts ?? [], + 'PAGES' => $pages ?? [], + ] +]); + +echo $FeedTemplate; diff --git a/core/include/home.php b/core/include/home.php index bb96837..dfa2a36 100644 --- a/core/include/home.php +++ b/core/include/home.php @@ -5,50 +5,41 @@ $Database = Application::getDatabase(); $Language = Application::getLanguage(); -#=============================================================================== -# TRY: Template\Exception -#=============================================================================== -try { - $execSQL = 'SELECT id FROM %s ORDER BY '.Application::get('POST.LIST_SORT').' LIMIT '.Application::get('POST.LIST_SIZE'); - $Statement = $Database->query(sprintf($execSQL, Post\Attribute::TABLE)); +$execSQL = 'SELECT id FROM %s ORDER BY '.Application::get('POST.LIST_SORT').' LIMIT '.Application::get('POST.LIST_SIZE'); +$Statement = $Database->query(sprintf($execSQL, Post\Attribute::TABLE)); - $postIDs = $Statement->fetchAll($Database::FETCH_COLUMN); +$postIDs = $Statement->fetchAll($Database::FETCH_COLUMN); - 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; } - - $HomeTemplate = Template\Factory::build('home'); - $HomeTemplate->set('PAGINATION', [ - 'HTML' => generatePostNaviTemplate(1) - ]); - $HomeTemplate->set('LIST', [ - 'POSTS' => $posts ?? [] - ]); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('HTML', $HomeTemplate); - $MainTemplate->set('HEAD', [ - 'NAME' => Application::get('BLOGMETA.HOME'), - 'DESC' => Application::get('BLOGMETA.NAME').' – '.Application::get('BLOGMETA.DESC'), - 'PERM' => Application::getURL() - ]); - - echo $MainTemplate; + catch(Post\Exception $Exception){} + catch(User\Exception $Exception){} } #=============================================================================== -# CATCH: Template\Exception +# Build document #=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +$HomeTemplate = Template\Factory::build('home'); +$HomeTemplate->set('PAGINATION', [ + 'HTML' => generatePostNaviTemplate(1) +]); +$HomeTemplate->set('LIST', [ + 'POSTS' => $posts ?? [] +]); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('HTML', $HomeTemplate); +$MainTemplate->set('HEAD', [ + 'NAME' => Application::get('BLOGMETA.HOME'), + 'DESC' => Application::get('BLOGMETA.NAME').' – '.Application::get('BLOGMETA.DESC'), + 'PERM' => Application::getURL() +]); + +echo $MainTemplate; diff --git a/core/include/page/list.php b/core/include/page/list.php index 6bda9cf..0165116 100644 --- a/core/include/page/list.php +++ b/core/include/page/list.php @@ -30,48 +30,39 @@ if(Application::get('PAGE.SINGLE_REDIRECT') === TRUE AND $count === '1') { HTTP::redirect($Page->getURL()); } -#=============================================================================== -# TRY: Template\Exception -#=============================================================================== -try { - $execSQL = "SELECT id FROM %s ORDER BY {$site_sort} LIMIT ".(($currentSite-1) * $site_size).", {$site_size}"; - $pageIDs = $Database->query(sprintf($execSQL, Page\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN); +$execSQL = "SELECT id FROM %s ORDER BY {$site_sort} LIMIT ".(($currentSite-1) * $site_size).", {$site_size}"; +$pageIDs = $Database->query(sprintf($execSQL, Page\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN); - foreach($pageIDs as $pageID) { - try { - $Page = Page\Factory::build($pageID); - $User = User\Factory::build($Page->attr('user')); +foreach($pageIDs as $pageID) { + try { + $Page = Page\Factory::build($pageID); + $User = User\Factory::build($Page->attr('user')); - $ItemTemplate = generatePageItemTemplate($Page, $User); + $ItemTemplate = generatePageItemTemplate($Page, $User); - $pages[] = $ItemTemplate; - } - catch(Page\Exception $Exception){} - catch(User\Exception $Exception){} + $pages[] = $ItemTemplate; } - - $ListTemplate = Template\Factory::build('page/list'); - $ListTemplate->set('PAGINATION', [ - 'THIS' => $currentSite, - 'LAST' => $lastSite, - 'HTML' => generatePageNaviTemplate($currentSite) - ]); - $ListTemplate->set('LIST', [ - 'PAGES' => $pages ?? [] - ]); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('HTML', $ListTemplate); - $MainTemplate->set('HEAD', [ - 'NAME' => $Language->text('title_page_overview', $currentSite) - ]); - - echo $MainTemplate; + catch(Page\Exception $Exception){} + catch(User\Exception $Exception){} } #=============================================================================== -# CATCH: Template\Exception +# Build document #=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +$ListTemplate = Template\Factory::build('page/list'); +$ListTemplate->set('PAGINATION', [ + 'THIS' => $currentSite, + 'LAST' => $lastSite, + 'HTML' => generatePageNaviTemplate($currentSite) +]); +$ListTemplate->set('LIST', [ + 'PAGES' => $pages ?? [] +]); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('HTML', $ListTemplate); +$MainTemplate->set('HEAD', [ + 'NAME' => $Language->text('title_page_overview', $currentSite) +]); + +echo $MainTemplate; diff --git a/core/include/page/main.php b/core/include/page/main.php index 6086345..955bb35 100644 --- a/core/include/page/main.php +++ b/core/include/page/main.php @@ -6,7 +6,7 @@ $Database = Application::getDatabase(); $Language = Application::getLanguage(); #=============================================================================== -# TRY: Page\Exception, User\Exception +# TRY: Page\Exception #=============================================================================== try { if(Application::get('PAGE.SLUG_URLS')) { @@ -36,36 +36,27 @@ try { } catch(Page\Exception $Exception){} #=============================================================================== - # TRY: Template\Exception + # Build document #=============================================================================== - try { - $PageTemplate = Template\Factory::build('page/main'); - $PageTemplate->set('PAGE', $page_data); - $PageTemplate->set('USER', $user_data); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('HTML', $PageTemplate); - $MainTemplate->set('HEAD', [ - 'NAME' => $page_data['ATTR']['NAME'], - 'DESC' => description($page_data['BODY']['HTML'](), Application::get('PAGE.DESCRIPTION_SIZE')), - 'PERM' => $page_data['URL'], - 'OG_IMAGES' => $page_data['FILE']['LIST'] - ]); + $PageTemplate = Template\Factory::build('page/main'); + $PageTemplate->set('PAGE', $page_data); + $PageTemplate->set('USER', $user_data); - # Get access to the current item data from main template - $MainTemplate->set('TYPE', 'PAGE'); - $MainTemplate->set('PAGE', $page_data); - $MainTemplate->set('USER', $user_data); + $MainTemplate = Template\Factory::build('main'); + $MainTemplate->set('HTML', $PageTemplate); + $MainTemplate->set('HEAD', [ + 'NAME' => $page_data['ATTR']['NAME'], + 'DESC' => description($page_data['BODY']['HTML'](), Application::get('PAGE.DESCRIPTION_SIZE')), + 'PERM' => $page_data['URL'], + 'OG_IMAGES' => $page_data['FILE']['LIST'] + ]); - echo $MainTemplate; - } + # Get access to the current item data from main template + $MainTemplate->set('TYPE', 'PAGE'); + $MainTemplate->set('PAGE', $page_data); + $MainTemplate->set('USER', $user_data); - #=============================================================================== - # CATCH: Template\Exception - #=============================================================================== - catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); - } + echo $MainTemplate; } #=============================================================================== @@ -86,10 +77,3 @@ catch(Page\Exception $Exception) { Application::error404(); } } - -#=============================================================================== -# CATCH: User\Exception -#=============================================================================== -catch(User\Exception $Exception) { - Application::exit($Exception->getMessage()); -} diff --git a/core/include/post/list.php b/core/include/post/list.php index e3b37c3..0f5ef1f 100644 --- a/core/include/post/list.php +++ b/core/include/post/list.php @@ -30,48 +30,39 @@ if(Application::get('POST.SINGLE_REDIRECT') === TRUE AND $count === '1') { HTTP::redirect($Post->getURL()); } -#=============================================================================== -# TRY: Template\Exception -#=============================================================================== -try { - $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); +$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); - 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; } - - $ListTemplate = Template\Factory::build('post/list'); - $ListTemplate->set('PAGINATION', [ - 'THIS' => $currentSite, - 'LAST' => $lastSite, - 'HTML' => generatePostNaviTemplate($currentSite) - ]); - $ListTemplate->set('LIST', [ - 'POSTS' => $posts ?? [] - ]); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('HTML', $ListTemplate); - $MainTemplate->set('HEAD', [ - 'NAME' => $Language->text('title_post_overview', $currentSite) - ]); - - echo $MainTemplate; + catch(Post\Exception $Exception){} + catch(User\Exception $Exception){} } #=============================================================================== -# CATCH: Template\Exception +# Build document #=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +$ListTemplate = Template\Factory::build('post/list'); +$ListTemplate->set('PAGINATION', [ + 'THIS' => $currentSite, + 'LAST' => $lastSite, + 'HTML' => generatePostNaviTemplate($currentSite) +]); +$ListTemplate->set('LIST', [ + 'POSTS' => $posts ?? [] +]); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('HTML', $ListTemplate); +$MainTemplate->set('HEAD', [ + 'NAME' => $Language->text('title_post_overview', $currentSite) +]); + +echo $MainTemplate; diff --git a/core/include/post/main.php b/core/include/post/main.php index d891416..8c65740 100644 --- a/core/include/post/main.php +++ b/core/include/post/main.php @@ -6,7 +6,7 @@ $Database = Application::getDatabase(); $Language = Application::getLanguage(); #=============================================================================== -# TRY: Post\Exception, User\Exception +# TRY: Post\Exception #=============================================================================== try { if(Application::get('POST.SLUG_URLS')) { @@ -36,36 +36,27 @@ try { } catch(Post\Exception $Exception){} #=============================================================================== - # TRY: Template\Exception + # Build document #=============================================================================== - try { - $PostTemplate = Template\Factory::build('post/main'); - $PostTemplate->set('POST', $post_data); - $PostTemplate->set('USER', $user_data); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('HTML', $PostTemplate); - $MainTemplate->set('HEAD', [ - 'NAME' => $post_data['ATTR']['NAME'], - 'DESC' => description($post_data['BODY']['HTML'](), Application::get('POST.DESCRIPTION_SIZE')), - 'PERM' => $post_data['URL'], - 'OG_IMAGES' => $post_data['FILE']['LIST'] - ]); + $PostTemplate = Template\Factory::build('post/main'); + $PostTemplate->set('POST', $post_data); + $PostTemplate->set('USER', $user_data); - # Get access to the current item data from main template - $MainTemplate->set('TYPE', 'POST'); - $MainTemplate->set('POST', $post_data); - $MainTemplate->set('USER', $user_data); + $MainTemplate = Template\Factory::build('main'); + $MainTemplate->set('HTML', $PostTemplate); + $MainTemplate->set('HEAD', [ + 'NAME' => $post_data['ATTR']['NAME'], + 'DESC' => description($post_data['BODY']['HTML'](), Application::get('POST.DESCRIPTION_SIZE')), + 'PERM' => $post_data['URL'], + 'OG_IMAGES' => $post_data['FILE']['LIST'] + ]); - echo $MainTemplate; - } + # Get access to the current item data from main template + $MainTemplate->set('TYPE', 'POST'); + $MainTemplate->set('POST', $post_data); + $MainTemplate->set('USER', $user_data); - #=============================================================================== - # CATCH: Template\Exception - #=============================================================================== - catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); - } + echo $MainTemplate; } #=============================================================================== @@ -86,10 +77,3 @@ catch(Post\Exception $Exception) { Application::error404(); } } - -#=============================================================================== -# CATCH: User\Exception -#=============================================================================== -catch(User\Exception $Exception) { - Application::exit($Exception->getMessage()); -} diff --git a/core/include/search/main.php b/core/include/search/main.php index db9a77a..f1b0693 100644 --- a/core/include/search/main.php +++ b/core/include/search/main.php @@ -35,55 +35,46 @@ $search_data = [ ]; #=============================================================================== -# TRY: Template\Exception +# Build document #=============================================================================== -try { - if(isset($postIDs) AND !empty($postIDs)) { - foreach($postIDs as $postID) { - try { - $Post = Post\Factory::build($postID); - $User = User\Factory::build($Post->attr('user')); +if(isset($postIDs) AND !empty($postIDs)) { + foreach($postIDs as $postID) { + try { + $Post = Post\Factory::build($postID); + $User = User\Factory::build($Post->attr('user')); - $posts[] = generatePostItemTemplate($Post, $User); - } - catch(Post\Exception $Exception){} - catch(User\Exception $Exception){} + $posts[] = generatePostItemTemplate($Post, $User); } - - $ResultTemplate = Template\Factory::build('search/result'); - $ResultTemplate->set('FORM', $form_data); - $ResultTemplate->set('SEARCH', $search_data); - $ResultTemplate->set('RESULT', [ - 'LIST' => $posts ?? [] - ]); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('HTML', $ResultTemplate); - $MainTemplate->set('HEAD', [ - 'NAME' => $Language->text('title_search_results', escapeHTML($search)), - 'PERM' => Application::getURL('search/') - ]); + catch(Post\Exception $Exception){} + catch(User\Exception $Exception){} } - else { - $SearchTemplate = Template\Factory::build('search/main'); - $SearchTemplate->set('FORM', $form_data); - $SearchTemplate->set('SEARCH', $search_data); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('HTML', $SearchTemplate); - $MainTemplate->set('HEAD', [ - 'NAME' => $Language->text('title_search_request'), - 'PERM' => Application::getURL('search/') - ]); - } + $ResultTemplate = Template\Factory::build('search/result'); + $ResultTemplate->set('FORM', $form_data); + $ResultTemplate->set('SEARCH', $search_data); + $ResultTemplate->set('RESULT', [ + 'LIST' => $posts ?? [] + ]); - echo $MainTemplate; + $MainTemplate = Template\Factory::build('main'); + $MainTemplate->set('HTML', $ResultTemplate); + $MainTemplate->set('HEAD', [ + 'NAME' => $Language->text('title_search_results', escapeHTML($search)), + 'PERM' => Application::getURL('search/') + ]); } -#=============================================================================== -# CATCH: Template\Exception -#=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); +else { + $SearchTemplate = Template\Factory::build('search/main'); + $SearchTemplate->set('FORM', $form_data); + $SearchTemplate->set('SEARCH', $search_data); + + $MainTemplate = Template\Factory::build('main'); + $MainTemplate->set('HTML', $SearchTemplate); + $MainTemplate->set('HEAD', [ + 'NAME' => $Language->text('title_search_request'), + 'PERM' => Application::getURL('search/') + ]); } + +echo $MainTemplate; diff --git a/core/include/user/list.php b/core/include/user/list.php index f715a55..afc8179 100644 --- a/core/include/user/list.php +++ b/core/include/user/list.php @@ -30,44 +30,35 @@ if(Application::get('USER.SINGLE_REDIRECT') === TRUE AND $count === '1') { HTTP::redirect($User->getURL()); } -#=============================================================================== -# TRY: Template\Exception -#=============================================================================== -try { - $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); - - foreach($userIDs as $userID) { - try { - $User = User\Factory::build($userID); - $ItemTemplate = generateUserItemTemplate($User); - - $users[] = $ItemTemplate; - } catch(User\Exception $Exception){} - } +$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); - $ListTemplate = Template\Factory::build('user/list'); - $ListTemplate->set('PAGINATION', [ - 'THIS' => $currentSite, - 'LAST' => $lastSite, - 'HTML' => generateUserNaviTemplate($currentSite) - ]); - $ListTemplate->set('LIST', [ - 'USERS' => $users ?? [] - ]); +foreach($userIDs as $userID) { + try { + $User = User\Factory::build($userID); + $ItemTemplate = generateUserItemTemplate($User); - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('HTML', $ListTemplate); - $MainTemplate->set('HEAD', [ - 'NAME' => $Language->text('title_user_overview', $currentSite) - ]); - - echo $MainTemplate; + $users[] = $ItemTemplate; + } catch(User\Exception $Exception){} } #=============================================================================== -# CATCH: Template\Exception +# Build document #=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +$ListTemplate = Template\Factory::build('user/list'); +$ListTemplate->set('PAGINATION', [ + 'THIS' => $currentSite, + 'LAST' => $lastSite, + 'HTML' => generateUserNaviTemplate($currentSite) +]); +$ListTemplate->set('LIST', [ + 'USERS' => $users ?? [] +]); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('HTML', $ListTemplate); +$MainTemplate->set('HEAD', [ + 'NAME' => $Language->text('title_user_overview', $currentSite) +]); + +echo $MainTemplate; diff --git a/core/include/user/main.php b/core/include/user/main.php index ee1fa76..80969da 100644 --- a/core/include/user/main.php +++ b/core/include/user/main.php @@ -32,54 +32,33 @@ try { $user_data['NEXT'] = generateItemTemplateData($NextUser); } catch(User\Exception $Exception){} + $PostCountStatement = $Database->query(sprintf('SELECT COUNT(*) FROM %s WHERE user = %d', Post\Attribute::TABLE, $User->getID())); + $PageCountStatement = $Database->query(sprintf('SELECT COUNT(*) FROM %s WHERE user = %d', Page\Attribute::TABLE, $User->getID())); + #=============================================================================== - # TRY: Template\Exception + # Build document #=============================================================================== - try { - #=============================================================================== - # TRY: PDOException - #=============================================================================== - try { - $PostCountStatement = $Database->query(sprintf('SELECT COUNT(*) FROM %s WHERE user = %d', Post\Attribute::TABLE, $User->getID())); - $PageCountStatement = $Database->query(sprintf('SELECT COUNT(*) FROM %s WHERE user = %d', Page\Attribute::TABLE, $User->getID())); - } - - #=============================================================================== - # CATCH: PDOException - #=============================================================================== - catch(PDOException $Exception) { - exit($Exception->getMessage()); - } - - $UserTemplate = Template\Factory::build('user/main'); - $UserTemplate->set('USER', $user_data); - $UserTemplate->set('COUNT', [ - 'POST' => $PostCountStatement->fetchColumn(), - 'PAGE' => $PageCountStatement->fetchColumn() - ]); + $UserTemplate = Template\Factory::build('user/main'); + $UserTemplate->set('USER', $user_data); + $UserTemplate->set('COUNT', [ + 'POST' => $PostCountStatement->fetchColumn(), + 'PAGE' => $PageCountStatement->fetchColumn() + ]); - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('HTML', $UserTemplate); - $MainTemplate->set('HEAD', [ - 'NAME' => $user_data['ATTR']['FULLNAME'], - 'DESC' => description($user_data['BODY']['HTML'](), Application::get('USER.DESCRIPTION_SIZE')), - 'PERM' => $User->getURL(), - 'OG_IMAGES' => $User->getFiles() - ]); + $MainTemplate = Template\Factory::build('main'); + $MainTemplate->set('HTML', $UserTemplate); + $MainTemplate->set('HEAD', [ + 'NAME' => $user_data['ATTR']['FULLNAME'], + 'DESC' => description($user_data['BODY']['HTML'](), Application::get('USER.DESCRIPTION_SIZE')), + 'PERM' => $User->getURL(), + 'OG_IMAGES' => $User->getFiles() + ]); - # Get access to the current item data from main template - $MainTemplate->set('TYPE', 'USER'); - $MainTemplate->set('USER', $user_data); + # Get access to the current item data from main template + $MainTemplate->set('TYPE', 'USER'); + $MainTemplate->set('USER', $user_data); - echo $MainTemplate; - } - - #=============================================================================== - # CATCH: Template\Exception - #=============================================================================== - catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); - } + echo $MainTemplate; } #=============================================================================== |