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/include/feed | |
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/include/feed')
-rw-r--r-- | core/include/feed/main.php | 99 |
1 files changed, 48 insertions, 51 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; |