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". --- core/include/feed/main.php | 99 ++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 51 deletions(-) (limited to 'core/include/feed/main.php') 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; -- cgit v1.2.3