From cd17efc82a5ed560a50b8a1619e4e724098eb209 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Tue, 29 Oct 2019 01:37:57 +0100 Subject: Remove PHP closing tags and add LF to text files Remove the unnecessary PHP closing tags and ensure that *all* text files ending with a LF character. --- admin/post/search.php | 1 - 1 file changed, 1 deletion(-) (limited to 'admin/post/search.php') diff --git a/admin/post/search.php b/admin/post/search.php index c2c83ca..cd28322 100644 --- a/admin/post/search.php +++ b/admin/post/search.php @@ -49,4 +49,3 @@ try { catch(Template\Exception $Exception) { Application::exit($Exception->getMessage()); } -?> \ No newline at end of file -- cgit v1.2.3 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". --- 403.php | 21 +++------ 404.php | 22 ++------- admin/auth.php | 37 ++++++--------- admin/database.php | 35 ++++++-------- admin/index.php | 108 ++++++++++++++++++------------------------- admin/page/delete.php | 43 +++++++---------- admin/page/index.php | 67 ++++++++++++--------------- admin/page/insert.php | 59 ++++++++++------------- admin/page/search.php | 25 ++++------ admin/page/update.php | 59 ++++++++++------------- admin/post/delete.php | 43 +++++++---------- admin/post/index.php | 67 ++++++++++++--------------- admin/post/insert.php | 59 ++++++++++------------- admin/post/search.php | 25 ++++------ admin/post/update.php | 59 ++++++++++------------- admin/user/delete.php | 43 +++++++---------- admin/user/index.php | 63 +++++++++++-------------- admin/user/insert.php | 43 +++++++---------- admin/user/update.php | 37 ++++++--------- core/include/feed/main.php | 99 +++++++++++++++++++-------------------- core/include/home.php | 67 ++++++++++++--------------- core/include/page/list.php | 65 +++++++++++--------------- core/include/page/main.php | 52 ++++++++------------- core/include/post/list.php | 65 +++++++++++--------------- core/include/post/main.php | 52 ++++++++------------- core/include/search/main.php | 77 ++++++++++++++---------------- core/include/user/list.php | 61 +++++++++++------------- core/include/user/main.php | 65 +++++++++----------------- 28 files changed, 616 insertions(+), 902 deletions(-) (limited to 'admin/post/search.php') diff --git a/403.php b/403.php index 4fbe789..82f6836 100644 --- a/403.php +++ b/403.php @@ -10,20 +10,11 @@ require_once 'core/application.php'; http_response_code(403); #=============================================================================== -# TRY: Template\Exception +# Build document #=============================================================================== -try { - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', '403 Forbidden'); - $MainTemplate->set('HEAD', ['NAME' => $MainTemplate->get('NAME')]); - $MainTemplate->set('HTML', Template\Factory::build('403')); +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', '403 Forbidden'); +$MainTemplate->set('HEAD', ['NAME' => $MainTemplate->get('NAME')]); +$MainTemplate->set('HTML', Template\Factory::build('403')); - echo $MainTemplate; -} - -#=============================================================================== -# CATCH: Template\Exception -#=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +echo $MainTemplate; diff --git a/404.php b/404.php index 544246d..0fdf419 100644 --- a/404.php +++ b/404.php @@ -9,21 +9,9 @@ require_once 'core/application.php'; #=============================================================================== http_response_code(404); -#=============================================================================== -# TRY: Template\Exception -#=============================================================================== -try { - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', '404 Not Found'); - $MainTemplate->set('HEAD', ['NAME' => $MainTemplate->get('NAME')]); - $MainTemplate->set('HTML', Template\Factory::build('404')); - - echo $MainTemplate; -} +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', '404 Not Found'); +$MainTemplate->set('HEAD', ['NAME' => $MainTemplate->get('NAME')]); +$MainTemplate->set('HTML', Template\Factory::build('404')); -#=============================================================================== -# CATCH: Template\Exception -#=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +echo $MainTemplate; diff --git a/admin/auth.php b/admin/auth.php index cec8867..8c6d5a6 100644 --- a/admin/auth.php +++ b/admin/auth.php @@ -50,28 +50,19 @@ if(HTTP::issetPOST(['token' => Application::getSecurityToken()], 'username', 'pa } #=============================================================================== -# TRY: Template\Exception +# Build document #=============================================================================== -try { - $AuthTemplate = Template\Factory::build('auth'); - $AuthTemplate->set('FORM', [ - 'INFO' => $messages ?? [], - 'DATA' => [ - 'USERNAME' => HTTP::POST('username'), - 'PASSWORD' => HTTP::POST('password'), - ], - 'TOKEN' => Application::getSecurityToken() - ]); +$AuthTemplate = Template\Factory::build('auth'); +$AuthTemplate->set('FORM', [ + 'INFO' => $messages ?? [], + 'DATA' => [ + 'USERNAME' => HTTP::POST('username'), + 'PASSWORD' => HTTP::POST('password'), + ], + 'TOKEN' => Application::getSecurityToken() +]); - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', 'Authentication'); - $MainTemplate->set('HTML', $AuthTemplate); - echo $MainTemplate; -} - -#=============================================================================== -# CATCH: Template\Exception -#=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', 'Authentication'); +$MainTemplate->set('HTML', $AuthTemplate); +echo $MainTemplate; diff --git a/admin/database.php b/admin/database.php index 14f34e1..78d47c1 100644 --- a/admin/database.php +++ b/admin/database.php @@ -26,26 +26,17 @@ if(HTTP::issetPOST(['token' => Application::getSecurityToken()], 'command')) { } #=============================================================================== -# TRY: Template\Exception -#=============================================================================== -try { - $DatabaseTemplate = Template\Factory::build('database'); - $DatabaseTemplate->set('FORM', [ - 'INFO' => $messages ?? [], - 'TOKEN' => Application::getSecurityToken(), - 'RESULT' => implode(NULL, $result ?? []), - 'COMMAND' => HTTP::POST('command'), - ]); +# Build document +#=============================================================================== +$DatabaseTemplate = Template\Factory::build('database'); +$DatabaseTemplate->set('FORM', [ + 'INFO' => $messages ?? [], + 'TOKEN' => Application::getSecurityToken(), + 'RESULT' => implode(NULL, $result ?? []), + 'COMMAND' => HTTP::POST('command'), +]); - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', 'SQL'); - $MainTemplate->set('HTML', $DatabaseTemplate); - echo $MainTemplate; -} - -#=============================================================================== -# CATCH: Template\Exception -#=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', 'SQL'); +$MainTemplate->set('HTML', $DatabaseTemplate); +echo $MainTemplate; diff --git a/admin/index.php b/admin/index.php index 6170021..788cee4 100644 --- a/admin/index.php +++ b/admin/index.php @@ -11,81 +11,61 @@ define('AUTHENTICATION', TRUE); require '../core/application.php'; #=============================================================================== -# TRY: PDOException +# Fetch last items and item count #=============================================================================== -try { - $execute = 'SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1'; +$execute = 'SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1'; +$LastPageStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE)); +$LastPostStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE)); +$LastUserStatement = $Database->query(sprintf($execute, User\Attribute::TABLE)); - $LastPageStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE)); - $LastPostStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE)); - $LastUserStatement = $Database->query(sprintf($execute, User\Attribute::TABLE)); +$execute = 'SELECT COUNT(*) FROM %s'; +$PageCountStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE)); +$PostCountStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE)); +$UserCountStatement = $Database->query(sprintf($execute, User\Attribute::TABLE)); - $execute = 'SELECT COUNT(*) FROM %s'; +try { + $LastPage = Page\Factory::build($LastPageStatement->fetchColumn()); + $LastPageUser = User\Factory::build($LastPage->attr('user')); - $PageCountStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE)); - $PostCountStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE)); - $UserCountStatement = $Database->query(sprintf($execute, User\Attribute::TABLE)); + $PageItemTemplate = generatePageItemTemplate($LastPage, $LastPageUser); } -#=============================================================================== -# CATCH: PDOException -#=============================================================================== -catch(PDOException $Exception) { - exit($Exception->getMessage()); -} +catch(Page\Exception $Exception){} +catch(User\Exception $Exception){} -#=============================================================================== -# TRY: Template\Exception -#=============================================================================== try { - try { - $LastPage = Page\Factory::build($LastPageStatement->fetchColumn()); - $LastPageUser = User\Factory::build($LastPage->attr('user')); - - $PageItemTemplate = generatePageItemTemplate($LastPage, $LastPageUser); - } - - catch(Page\Exception $Exception){} - catch(User\Exception $Exception){} + $LastPost = Post\Factory::build($LastPostStatement->fetchColumn()); + $LastPostUser = User\Factory::build($LastPost->attr('user')); - try { - $LastPost = Post\Factory::build($LastPostStatement->fetchColumn()); - $LastPostUser = User\Factory::build($LastPost->attr('user')); - - $PostItemTemplate = generatePostItemTemplate($LastPost, $LastPostUser); - } - - catch(Post\Exception $Exception){} - catch(User\Exception $Exception){} - - try { - $LastUser = User\Factory::build($LastUserStatement->fetchColumn()); - $UserItemTemplate = generateUserItemTemplate($LastUser); - } catch(User\Exception $Exception){} - - $HomeTemplate = Template\Factory::build('home'); - $HomeTemplate->set('LAST', [ - 'PAGE' => $PageItemTemplate ?? FALSE, - 'POST' => $PostItemTemplate ?? FALSE, - 'USER' => $UserItemTemplate ?? FALSE, - - ]); + $PostItemTemplate = generatePostItemTemplate($LastPost, $LastPostUser); +} - $HomeTemplate->set('COUNT', [ - 'PAGE' => $PageCountStatement->fetchColumn(), - 'POST' => $PostCountStatement->fetchColumn(), - 'USER' => $UserCountStatement->fetchColumn(), - ]); +catch(Post\Exception $Exception){} +catch(User\Exception $Exception){} - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', 'Dashboard'); - $MainTemplate->set('HTML', $HomeTemplate); - echo $MainTemplate; -} +try { + $LastUser = User\Factory::build($LastUserStatement->fetchColumn()); + $UserItemTemplate = generateUserItemTemplate($LastUser); +} catch(User\Exception $Exception){} #=============================================================================== -# CATCH: Template\Exception +# Build document #=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +$HomeTemplate = Template\Factory::build('home'); +$HomeTemplate->set('LAST', [ + 'PAGE' => $PageItemTemplate ?? FALSE, + 'POST' => $PostItemTemplate ?? FALSE, + 'USER' => $UserItemTemplate ?? FALSE, + +]); + +$HomeTemplate->set('COUNT', [ + 'PAGE' => $PageCountStatement->fetchColumn(), + 'POST' => $PostCountStatement->fetchColumn(), + 'USER' => $UserCountStatement->fetchColumn(), +]); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', 'Dashboard'); +$MainTemplate->set('HTML', $HomeTemplate); +echo $MainTemplate; diff --git a/admin/page/delete.php b/admin/page/delete.php index 111910b..1406ece 100644 --- a/admin/page/delete.php +++ b/admin/page/delete.php @@ -28,33 +28,24 @@ try { } #=============================================================================== - # TRY: Template\Exception + # Build document #=============================================================================== - try { - $FormTemplate = Template\Factory::build('page/form'); - $FormTemplate->set('HTML', $Page->getHTML()); - $FormTemplate->set('FORM', [ - 'TYPE' => 'DELETE', - 'INFO' => $messages ?? [], - 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), - 'TOKEN' => Application::getSecurityToken() - ]); - - $DeleteTemplate = Template\Factory::build('page/delete'); - $DeleteTemplate->set('HTML', $FormTemplate); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_page_delete')); - $MainTemplate->set('HTML', $DeleteTemplate); - echo $MainTemplate; - } - - #=============================================================================== - # CATCH: Template\Exception - #=============================================================================== - catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); - } + $FormTemplate = Template\Factory::build('page/form'); + $FormTemplate->set('HTML', $Page->getHTML()); + $FormTemplate->set('FORM', [ + 'TYPE' => 'DELETE', + 'INFO' => $messages ?? [], + 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), + 'TOKEN' => Application::getSecurityToken() + ]); + + $DeleteTemplate = Template\Factory::build('page/delete'); + $DeleteTemplate->set('HTML', $FormTemplate); + + $MainTemplate = Template\Factory::build('main'); + $MainTemplate->set('NAME', $Language->text('title_page_delete')); + $MainTemplate->set('HTML', $DeleteTemplate); + echo $MainTemplate; } #=============================================================================== diff --git a/admin/page/index.php b/admin/page/index.php index 584ba48..7c8b1a6 100644 --- a/admin/page/index.php +++ b/admin/page/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}"; $pageIDs = $Database->query(sprintf($execSQL, Page\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN); -#=============================================================================== -# TRY: Template\Exception -#=============================================================================== -try { - 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; } - - $PaginationTemplate = Template\Factory::build('pagination'); - $PaginationTemplate->set('THIS', $currentSite); - $PaginationTemplate->set('LAST', $lastSite); - $PaginationTemplate->set('HREF', Application::getAdminURL('page/?site=%d')); - - $ListTemplate = Template\Factory::build('page/index'); - $ListTemplate->set('LIST', [ - 'PAGES' => $pages ?? [] - ]); - - $ListTemplate->set('PAGINATION', [ - 'THIS' => $currentSite, - 'LAST' => $lastSite, - 'HTML' => $PaginationTemplate - ]); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_page_overview', $currentSite)); - $MainTemplate->set('HTML', $ListTemplate); - echo $MainTemplate; + catch(Page\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('page/?site=%d')); + +$ListTemplate = Template\Factory::build('page/index'); +$ListTemplate->set('LIST', [ + 'PAGES' => $pages ?? [] +]); + +$ListTemplate->set('PAGINATION', [ + 'THIS' => $currentSite, + 'LAST' => $lastSite, + 'HTML' => $PaginationTemplate +]); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', $Language->text('title_page_overview', $currentSite)); +$MainTemplate->set('HTML', $ListTemplate); +echo $MainTemplate; diff --git a/admin/page/insert.php b/admin/page/insert.php index 4fc4d8b..ec903e7 100644 --- a/admin/page/insert.php +++ b/admin/page/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('page/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('page/insert'); - $InsertTemplate->set('HTML', $FormTemplate); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_page_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('page/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('page/insert'); +$InsertTemplate->set('HTML', $FormTemplate); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', $Language->text('title_page_insert')); +$MainTemplate->set('HTML', $InsertTemplate); +echo $MainTemplate; diff --git a/admin/page/search.php b/admin/page/search.php index e71a8b8..eb57a7c 100644 --- a/admin/page/search.php +++ b/admin/page/search.php @@ -29,23 +29,14 @@ if($search = HTTP::GET('q')) { } #=============================================================================== -# TRY: Template\Exception +# Build document #=============================================================================== -try { - $SearchTemplate = Template\Factory::build('page/search'); - $SearchTemplate->set('QUERY', $search); - $SearchTemplate->set('PAGES', $pages ?? []); +$SearchTemplate = Template\Factory::build('page/search'); +$SearchTemplate->set('QUERY', $search); +$SearchTemplate->set('PAGES', $pages ?? []); - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_page_search')); - $MainTemplate->set('HTML', $SearchTemplate); +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', $Language->text('title_page_search')); +$MainTemplate->set('HTML', $SearchTemplate); - echo $MainTemplate; -} - -#=============================================================================== -# CATCH: Template\Exception -#=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} +echo $MainTemplate; diff --git a/admin/page/update.php b/admin/page/update.php index a7c9cd0..ba34a86 100644 --- a/admin/page/update.php +++ b/admin/page/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('page/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)); - $PageUpdateTemplate = Template\Factory::build('page/update'); - $PageUpdateTemplate->set('HTML', $FormTemplate); - - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', $Language->text('title_page_update')); - $MainTemplate->set('HTML', $PageUpdateTemplate); - 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('page/form'); + $FormTemplate->set('FORM', [ + 'TYPE' => 'UPDATE', + 'INFO' => $messages ?? [], + 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), + 'USER_LIST' => $userAttributes ?? [], + 'TOKEN' => Application::getSecurityToken() + ]); + + $PageUpdateTemplate = Template\Factory::build('page/update'); + $PageUpdateTemplate->set('HTML', $FormTemplate); + + $MainTemplate = Template\Factory::build('main'); + $MainTemplate->set('NAME', $Language->text('title_page_update')); + $MainTemplate->set('HTML', $PageUpdateTemplate); + echo $MainTemplate; } #=============================================================================== 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; } #=============================================================================== 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; } #=============================================================================== 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; } #=============================================================================== -- cgit v1.2.3