diff options
author | Thomas Lange <code@nerdmind.de> | 2017-05-30 21:03:03 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2017-05-30 21:03:03 +0200 |
commit | fd6af01e313f441189c4cd69668766d2ded7ced3 (patch) | |
tree | 0a0ae7cb2dd19c2a52b0799c37bb53b0e5e9e892 | |
parent | 1f1de386b09e48a02fccd62aa82ff319533969cc (diff) | |
download | blog-fd6af01e313f441189c4cd69668766d2ded7ced3.tar.gz blog-fd6af01e313f441189c4cd69668766d2ded7ced3.tar.xz blog-fd6af01e313f441189c4cd69668766d2ded7ced3.zip |
Several changes have been made in this commit, which together with the previous commits result in version 2.2 [changed template parameters]:v2.2
+ Implemented [core]: A new method called "getAll" has been added to the "Attribute" class which now returns all attributes as key->value array. The first parameter can be an array with attribute names which shall be excluded from returning.
+ Optimization [core]: The function "generateItemData" has been renamed to "generateItemTemplateData" and has been restructured to use the new implemented method "getAll" from the "Attribute" class.
+ Optimization [core]: The function "generateNaviTemplate" has been added and the functions "generatePageNaviTemplate", "generatePostNaviTemplate" and "generateUserNaviTemplate" have been restructured to make use of the new "generateNaviTemplate" function to reduce duplicate code.
+ Optimization [core]: Several files within the admin directory has been optimized to use the new "getAll" method of the "Attribute" class.
+ Optimization [core]: Several code optimizations have been made to the "HTTP" class.
+ Optimization [admin template]: All occurences of $PAGE['ID'], $POST['ID'] and $USER['ID'] have been replaced with $PAGE['ATTR']['ID'], $POST['ATTR']['ID'] and $USER['ATTR']['ID'] to make it more consistent. You now have to use ['ATTR']['ID'] instead of ['ID'] in your templates to get the ID of an item!
Template upgrade to version 2.2 (only for customized templates):
SEARCH: ['ID']
REPLACE: ['ATTR']['ID']
-rw-r--r-- | admin/page/delete.php | 7 | ||||
-rw-r--r-- | admin/page/insert.php | 11 | ||||
-rw-r--r-- | admin/page/update.php | 11 | ||||
-rw-r--r-- | admin/post/delete.php | 7 | ||||
-rw-r--r-- | admin/post/insert.php | 11 | ||||
-rw-r--r-- | admin/post/update.php | 11 | ||||
-rw-r--r-- | admin/user/delete.php | 7 | ||||
-rw-r--r-- | admin/user/insert.php | 13 | ||||
-rw-r--r-- | admin/user/update.php | 13 | ||||
-rw-r--r-- | core/functions.php | 132 | ||||
-rw-r--r-- | core/include/feed/main.php | 8 | ||||
-rw-r--r-- | core/include/page/main.php | 8 | ||||
-rw-r--r-- | core/include/post/main.php | 8 | ||||
-rw-r--r-- | core/include/user/main.php | 6 | ||||
-rw-r--r-- | core/namespace/Attribute.php | 11 | ||||
-rw-r--r-- | core/namespace/HTTP.php | 67 | ||||
-rw-r--r-- | template/admin/html/page/item.php | 8 | ||||
-rw-r--r-- | template/admin/html/post/item.php | 8 | ||||
-rw-r--r-- | template/admin/html/user/item.php | 6 |
19 files changed, 102 insertions, 251 deletions
diff --git a/admin/page/delete.php b/admin/page/delete.php index de9ac21..890188e 100644 --- a/admin/page/delete.php +++ b/admin/page/delete.php @@ -36,12 +36,7 @@ try { $FormTemplate->set('FORM', [ 'TYPE' => 'DELETE', 'INFO' => $messages ?? [], - 'DATA' => [ - 'ID' => $Attribute->get('id'), - 'BODY' => $Attribute->get('body'), - 'TIME_INSERT' => $Attribute->get('time_insert'), - 'TIME_UPDATE' => $Attribute->get('time_update'), - ], + 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), 'TOKEN' => Application::getSecurityToken() ]); diff --git a/admin/page/insert.php b/admin/page/insert.php index 5731b6f..a360c1b 100644 --- a/admin/page/insert.php +++ b/admin/page/insert.php @@ -56,16 +56,7 @@ try { $FormTemplate->set('FORM', [ 'TYPE' => 'INSERT', 'INFO' => $messages ?? [], - 'DATA' => [ - 'ID' => $Attribute->get('id'), - 'USER' => $Attribute->get('user'), - 'SLUG' => $Attribute->get('slug'), - 'NAME' => $Attribute->get('name'), - 'BODY' => $Attribute->get('body'), - 'ARGV' => $Attribute->get('argv'), - 'TIME_INSERT' => $Attribute->get('time_insert'), - 'TIME_UPDATE' => $Attribute->get('time_update'), - ], + 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), 'USER_LIST' => $userAttributes ?? [], 'TOKEN' => Application::getSecurityToken() ]); diff --git a/admin/page/update.php b/admin/page/update.php index dc92073..18c9785 100644 --- a/admin/page/update.php +++ b/admin/page/update.php @@ -58,16 +58,7 @@ try { $FormTemplate->set('FORM', [ 'TYPE' => 'UPDATE', 'INFO' => $messages ?? [], - 'DATA' => [ - 'ID' => $Attribute->get('id'), - 'USER' => $Attribute->get('user'), - 'SLUG' => $Attribute->get('slug'), - 'NAME' => $Attribute->get('name'), - 'BODY' => $Attribute->get('body'), - 'ARGV' => $Attribute->get('argv'), - 'TIME_INSERT' => $Attribute->get('time_insert'), - 'TIME_UPDATE' => $Attribute->get('time_update'), - ], + 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), 'USER_LIST' => $userAttributes ?? [], 'TOKEN' => Application::getSecurityToken() ]); diff --git a/admin/post/delete.php b/admin/post/delete.php index a5151ff..80f3a70 100644 --- a/admin/post/delete.php +++ b/admin/post/delete.php @@ -36,12 +36,7 @@ try { $FormTemplate->set('FORM', [ 'TYPE' => 'DELETE', 'INFO' => $messages ?? [], - 'DATA' => [ - 'ID' => $Attribute->get('id'), - 'BODY' => $Attribute->get('body'), - 'TIME_INSERT' => $Attribute->get('time_insert'), - 'TIME_UPDATE' => $Attribute->get('time_update'), - ], + 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), 'TOKEN' => Application::getSecurityToken() ]); diff --git a/admin/post/insert.php b/admin/post/insert.php index 4587a87..8e08fb3 100644 --- a/admin/post/insert.php +++ b/admin/post/insert.php @@ -56,16 +56,7 @@ try { $FormTemplate->set('FORM', [ 'TYPE' => 'INSERT', 'INFO' => $messages ?? [], - 'DATA' => [ - 'ID' => $Attribute->get('id'), - 'USER' => $Attribute->get('user'), - 'SLUG' => $Attribute->get('slug'), - 'NAME' => $Attribute->get('name'), - 'BODY' => $Attribute->get('body'), - 'ARGV' => $Attribute->get('argv'), - 'TIME_INSERT' => $Attribute->get('time_insert'), - 'TIME_UPDATE' => $Attribute->get('time_update'), - ], + 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), 'USER_LIST' => $userAttributes ?? [], 'TOKEN' => Application::getSecurityToken() ]); diff --git a/admin/post/update.php b/admin/post/update.php index 7e3610f..af26835 100644 --- a/admin/post/update.php +++ b/admin/post/update.php @@ -58,16 +58,7 @@ try { $FormTemplate->set('FORM', [ 'TYPE' => 'UPDATE', 'INFO' => $messages ?? [], - 'DATA' => [ - 'ID' => $Attribute->get('id'), - 'USER' => $Attribute->get('user'), - 'SLUG' => $Attribute->get('slug'), - 'NAME' => $Attribute->get('name'), - 'BODY' => $Attribute->get('body'), - 'ARGV' => $Attribute->get('argv'), - 'TIME_INSERT' => $Attribute->get('time_insert'), - 'TIME_UPDATE' => $Attribute->get('time_update'), - ], + 'DATA' => array_change_key_case($Attribute->getAll(), CASE_UPPER), 'USER_LIST' => $userAttributes ?? [], 'TOKEN' => Application::getSecurityToken() ]); diff --git a/admin/user/delete.php b/admin/user/delete.php index 7023246..28d1b2a 100644 --- a/admin/user/delete.php +++ b/admin/user/delete.php @@ -36,12 +36,7 @@ try { $FormTemplate->set('FORM', [ 'TYPE' => 'DELETE', 'INFO' => $messages ?? [], - 'DATA' => [ - 'ID' => $Attribute->get('id'), - 'BODY' => $Attribute->get('body'), - 'TIME_INSERT' => $Attribute->get('time_insert'), - 'TIME_UPDATE' => $Attribute->get('time_update'), - ], + 'DATA' => array_change_key_case($Attribute->getAll(['password']), CASE_UPPER), 'TOKEN' => Application::getSecurityToken() ]); diff --git a/admin/user/insert.php b/admin/user/insert.php index 81daf98..2d49322 100644 --- a/admin/user/insert.php +++ b/admin/user/insert.php @@ -47,18 +47,7 @@ try { $FormTemplate->set('FORM', [ 'TYPE' => 'INSERT', 'INFO' => $messages ?? [], - 'DATA' => [ - 'ID' => $Attribute->get('id'), - 'SLUG' => $Attribute->get('slug'), - 'USERNAME' => $Attribute->get('username'), - 'PASSWORD' => NULL, - 'FULLNAME' => $Attribute->get('fullname'), - 'MAILADDR' => $Attribute->get('mailaddr'), - 'BODY' => $Attribute->get('body'), - 'ARGV' => $Attribute->get('argv'), - 'TIME_INSERT' => $Attribute->get('time_insert'), - 'TIME_UPDATE' => $Attribute->get('time_update'), - ], + 'DATA' => array_change_key_case($Attribute->getAll(['password']), CASE_UPPER), 'TOKEN' => Application::getSecurityToken() ]); diff --git a/admin/user/update.php b/admin/user/update.php index cdacfa0..3ba6df8 100644 --- a/admin/user/update.php +++ b/admin/user/update.php @@ -50,18 +50,7 @@ try { $FormTemplate->set('FORM', [ 'TYPE' => 'UPDATE', 'INFO' => $messages ?? [], - 'DATA' => [ - 'ID' => $Attribute->get('id'), - 'SLUG' => $Attribute->get('slug'), - 'USERNAME' => $Attribute->get('username'), - 'PASSWORD' => NULL, - 'FULLNAME' => $Attribute->get('fullname'), - 'MAILADDR' => $Attribute->get('mailaddr'), - 'BODY' => $Attribute->get('body'), - 'ARGV' => $Attribute->get('argv'), - 'TIME_INSERT' => $Attribute->get('time_insert'), - 'TIME_UPDATE' => $Attribute->get('time_update'), - ], + 'DATA' => array_change_key_case($Attribute->getAll(['password']), CASE_UPPER), 'TOKEN' => Application::getSecurityToken() ]); diff --git a/core/functions.php b/core/functions.php index ccaf008..35faed4 100644 --- a/core/functions.php +++ b/core/functions.php @@ -2,16 +2,18 @@ #=============================================================================== # Helper function to reduce duplicate code #=============================================================================== -function generatePageNaviTemplate($currentSite): Template\Template { +function generateNaviTemplate(int $current, $location, $namespace): Template\Template { $Database = Application::getDatabase(); - $Statement = $Database->query(sprintf('SELECT COUNT(id) FROM %s', Page\Attribute::TABLE)); + $Attribute = "{$namespace}\\Attribute"; - $lastSite = ceil($Statement->fetchColumn() / Application::get('PAGE.LIST_SIZE')); + $Statement = $Database->query(sprintf('SELECT COUNT(id) FROM %s', $Attribute::TABLE)); + + $lastSite = ceil($Statement->fetchColumn() / Application::get(strtoupper($namespace).'.LIST_SIZE')); $PaginationTemplate = Template\Factory::build('pagination'); - $PaginationTemplate->set('THIS', $currentSite); + $PaginationTemplate->set('THIS', $current); $PaginationTemplate->set('LAST', $lastSite); - $PaginationTemplate->set('HREF', Application::getPageURL('?site=%d')); + $PaginationTemplate->set('HREF', "{$location}?site=%d"); return $PaginationTemplate; } @@ -19,35 +21,22 @@ function generatePageNaviTemplate($currentSite): Template\Template { #=============================================================================== # Helper function to reduce duplicate code #=============================================================================== -function generatePostNaviTemplate($currentSite): Template\Template { - $Database = Application::getDatabase(); - $Statement = $Database->query(sprintf('SELECT COUNT(id) FROM %s', Post\Attribute::TABLE)); - - $lastSite = ceil($Statement->fetchColumn() / Application::get('POST.LIST_SIZE')); - - $PaginationTemplate = Template\Factory::build('pagination'); - $PaginationTemplate->set('THIS', $currentSite); - $PaginationTemplate->set('LAST', $lastSite); - $PaginationTemplate->set('HREF', Application::getPostURL('?site=%d')); - - return $PaginationTemplate; +function generatePageNaviTemplate($current): Template\Template { + return generateNaviTemplate($current, Application::getPageURL(), 'Page'); } #=============================================================================== # Helper function to reduce duplicate code #=============================================================================== -function generateUserNaviTemplate($currentSite): Template\Template { - $Database = Application::getDatabase(); - $Statement = $Database->query(sprintf('SELECT COUNT(id) FROM %s', User\Attribute::TABLE)); - - $lastSite = ceil($Statement->fetchColumn() / Application::get('USER.LIST_SIZE')); - - $PaginationTemplate = Template\Factory::build('pagination'); - $PaginationTemplate->set('THIS', $currentSite); - $PaginationTemplate->set('LAST', $lastSite); - $PaginationTemplate->set('HREF', Application::getUserURL('?site=%d')); +function generatePostNaviTemplate($current): Template\Template { + return generateNaviTemplate($current, Application::getPostURL(), 'Post'); +} - return $PaginationTemplate; +#=============================================================================== +# Helper function to reduce duplicate code +#=============================================================================== +function generateUserNaviTemplate($current): Template\Template { + return generateNaviTemplate($current, Application::getUserURL(), 'User'); } #=============================================================================== @@ -55,8 +44,8 @@ function generateUserNaviTemplate($currentSite): Template\Template { #=============================================================================== function generatePageItemTemplate(Page\Item $Page, User\Item $User): Template\Template { $Template = Template\Factory::build('page/item'); - $Template->set('PAGE', generatePageItemData($Page)); - $Template->set('USER', generateUserItemData($User)); + $Template->set('PAGE', generateItemTemplateData($Page)); + $Template->set('USER', generateItemTemplateData($User)); return $Template; } @@ -66,8 +55,8 @@ function generatePageItemTemplate(Page\Item $Page, User\Item $User): Template\Te #=============================================================================== function generatePostItemTemplate(Post\Item $Post, User\Item $User): Template\Template { $Template = Template\Factory::build('post/item'); - $Template->set('POST', generatePostItemData($Post)); - $Template->set('USER', generateUserItemData($User)); + $Template->set('POST', generateItemTemplateData($Post)); + $Template->set('USER', generateItemTemplateData($User)); return $Template; } @@ -77,7 +66,7 @@ function generatePostItemTemplate(Post\Item $Post, User\Item $User): Template\Te #=============================================================================== function generateUserItemTemplate(User\Item $User): Template\Template { $Template = Template\Factory::build('user/item'); - $Template->set('USER', generateUserItemData($User)); + $Template->set('USER', generateItemTemplateData($User)); return $Template; } @@ -85,13 +74,17 @@ function generateUserItemTemplate(User\Item $User): Template\Template { #=============================================================================== # Helper function to reduce duplicate code #=============================================================================== -function generateItemData(Item $Item): array { +function generateItemTemplateData(Item $Item): array { + $ATTR = $Item->getAttribute()->getAll(['password']); + $ATTR = array_change_key_case($ATTR, CASE_UPPER); + return [ - 'ID' => $Item->getID(), 'URL' => $Item->getURL(), 'GUID' => $Item->getGUID(), 'ARGV' => $Item->getArguments(), + 'ATTR' => $ATTR, + 'PREV' => FALSE, 'NEXT' => FALSE, @@ -106,69 +99,6 @@ function generateItemData(Item $Item): array { 'HTML' => function() use($Item) { return $Item->getHTML(); } - ], - - 'ATTR' => [ - 'USER' => $Item->attr('user'), - 'SLUG' => $Item->attr('slug'), - 'NAME' => $Item->attr('name'), - 'BODY' => $Item->attr('body'), - 'ARGV' => $Item->attr('argv'), - 'TIME_INSERT' => $Item->attr('time_insert'), - 'TIME_UPDATE' => $Item->attr('time_update') - ] - ]; -} - -#=============================================================================== -# Helper function to reduce duplicate code -#=============================================================================== -function generatePageItemData(Page\Item $Page): array { - return generateItemData($Page); -} - -#=============================================================================== -# Helper function to reduce duplicate code -#=============================================================================== -function generatePostItemData(Post\Item $Post): array { - return generateItemData($Post); -} - -#=============================================================================== -# Helper function to reduce duplicate code -#=============================================================================== -function generateUserItemData(User\Item $User): array { - return [ - 'ID' => $User->getID(), - 'URL' => $User->getURL(), - 'GUID' => $User->getGUID(), - 'ARGV' => $User->getArguments(), - - 'PREV' => FALSE, - 'NEXT' => FALSE, - - 'FILE' => [ - 'LIST' => $User->getFiles() - ], - - 'BODY' => [ - 'TEXT' => function() use($User) { - return $User->getBody(); - }, - 'HTML' => function() use($User) { - return $User->getHTML(); - } - ], - - 'ATTR' => [ - 'SLUG' => $User->attr('slug'), - 'BODY' => $User->attr('body'), - 'ARGV' => $User->attr('argv'), - 'USERNAME' => $User->attr('username'), - 'FULLNAME' => $User->attr('fullname'), - 'MAILADDR' => $User->attr('mailaddr'), - 'TIME_INSERT' => $User->attr('time_insert'), - 'TIME_UPDATE' => $User->attr('time_update') ] ]; } @@ -354,7 +284,7 @@ function makeSlugURL($string, $separator = '-') { function PAGE(int $id): array { try { $Page = Page\Factory::build($id); - return generatePageItemData($Page); + return generateItemTemplateData($Page); } catch(Page\Exception $Exception) { return []; } @@ -366,7 +296,7 @@ function PAGE(int $id): array { function POST(int $id): array { try { $Post = Post\Factory::build($id); - return generatePostItemData($Post); + return generateItemTemplateData($Post); } catch(Post\Exception $Exception) { return []; } @@ -378,7 +308,7 @@ function POST(int $id): array { function USER(int $id): array { try { $User = User\Factory::build($id); - return generateUserItemData($User); + return generateItemTemplateData($User); } catch(User\Exception $Exception) { return []; } diff --git a/core/include/feed/main.php b/core/include/feed/main.php index 671f5c7..8879e72 100644 --- a/core/include/feed/main.php +++ b/core/include/feed/main.php @@ -24,8 +24,8 @@ try { $User = User\Factory::build($Post->attr('user')); $ItemTemplate = Template\Factory::build('feed/item_post'); - $ItemTemplate->set('POST', generatePostItemData($Post)); - $ItemTemplate->set('USER', generateUserItemData($User)); + $ItemTemplate->set('POST', generateItemTemplateData($Post)); + $ItemTemplate->set('USER', generateItemTemplateData($User)); $posts[] = $ItemTemplate; } @@ -45,8 +45,8 @@ try { $User = User\Factory::build($Page->attr('user')); $ItemTemplate = Template\Factory::build('feed/item_page'); - $ItemTemplate->set('PAGE', generatePageItemData($Page)); - $ItemTemplate->set('USER', generateUserItemData($User)); + $ItemTemplate->set('PAGE', generateItemTemplateData($Page)); + $ItemTemplate->set('USER', generateItemTemplateData($User)); $pages[] = $ItemTemplate; } diff --git a/core/include/page/main.php b/core/include/page/main.php index 01579fc..18ba4c8 100644 --- a/core/include/page/main.php +++ b/core/include/page/main.php @@ -19,20 +19,20 @@ try { $User = User\Factory::build($Page->attr('user')); - $page_data = generatePageItemData($Page); - $user_data = generateUserItemData($User); + $page_data = generateItemTemplateData($Page); + $user_data = generateItemTemplateData($User); #=============================================================================== # Add page data for previous and next page #=============================================================================== try { $PrevPage = Page\Factory::build($Page->getPrevID()); - $page_data['PREV'] = generatePageItemData($PrevPage); + $page_data['PREV'] = generateItemTemplateData($PrevPage); } catch(Page\Exception $Exception){} try { $NextPage = Page\Factory::build($Page->getNextID()); - $page_data['NEXT'] = generatePageItemData($NextPage); + $page_data['NEXT'] = generateItemTemplateData($NextPage); } catch(Page\Exception $Exception){} #=============================================================================== diff --git a/core/include/post/main.php b/core/include/post/main.php index 8cd0a49..f091a4c 100644 --- a/core/include/post/main.php +++ b/core/include/post/main.php @@ -19,20 +19,20 @@ try { $User = User\Factory::build($Post->attr('user')); - $post_data = generatePostItemData($Post); - $user_data = generateUserItemData($User); + $post_data = generateItemTemplateData($Post); + $user_data = generateItemTemplateData($User); #=============================================================================== # Add post data for previous and next post #=============================================================================== try { $PrevPost = Post\Factory::build($Post->getPrevID()); - $post_data['PREV'] = generatePostItemData($PrevPost); + $post_data['PREV'] = generateItemTemplateData($PrevPost); } catch(Post\Exception $Exception){} try { $NextPost = Post\Factory::build($Post->getNextID()); - $post_data['NEXT'] = generatePostItemData($NextPost); + $post_data['NEXT'] = generateItemTemplateData($NextPost); } catch(Post\Exception $Exception){} #=============================================================================== diff --git a/core/include/user/main.php b/core/include/user/main.php index ba0d07b..b2b054a 100644 --- a/core/include/user/main.php +++ b/core/include/user/main.php @@ -17,19 +17,19 @@ try { $User = User\Factory::build($param); } - $user_data = generateUserItemData($User); + $user_data = generateItemTemplateData($User); #=============================================================================== # Add user data for previous and next user #=============================================================================== try { $PrevUser = User\Factory::build($User->getPrevID()); - $user_data['PREV'] = generateUserItemData($PrevUser); + $user_data['PREV'] = generateItemTemplateData($PrevUser); } catch(User\Exception $Exception){} try { $NextUser = User\Factory::build($User->getNextID()); - $user_data['NEXT'] = generateUserItemData($NextUser); + $user_data['NEXT'] = generateItemTemplateData($NextUser); } catch(User\Exception $Exception){} #=============================================================================== diff --git a/core/namespace/Attribute.php b/core/namespace/Attribute.php index 69998e0..32cfa0a 100644 --- a/core/namespace/Attribute.php +++ b/core/namespace/Attribute.php @@ -16,6 +16,17 @@ abstract class Attribute implements AttributeInterface { } #=============================================================================== + # Get all attributes + #=============================================================================== + public function getAll($exclude = []): array { + $attributes = get_object_vars($this); + + return array_filter($attributes, function($attribute) use($exclude) { + return !in_array($attribute, $exclude); + }, ARRAY_FILTER_USE_KEY); + } + + #=============================================================================== # Get array with not FALSE attributes #=============================================================================== protected function getFilteredAttributes(): array { diff --git a/core/namespace/HTTP.php b/core/namespace/HTTP.php index bc2e062..d14b69b 100644 --- a/core/namespace/HTTP.php +++ b/core/namespace/HTTP.php @@ -81,23 +81,22 @@ class HTTP { self::$POST = $POST; self::$FILE = $FILE; - $removeArrays AND self::removeArrays(); + if($removeArrays) { + self::$GET = self::removeArrayValues(self::$GET); + self::$POST = self::removeArrayValues(self::$POST); + } self::$GET = ($trimValues === TRUE ? self::trim(self::$GET) : self::$GET ); self::$POST = ($trimValues === TRUE ? self::trim(self::$POST) : self::$POST); } #=============================================================================== - # Remove all arrays from $_GET and $_POST + # Remove all array values inside an array #=============================================================================== - private static function removeArrays() { - foreach(['GET', 'POST'] as $HTTP) { - foreach(self::$$HTTP as $name => $value) { - if(is_array(self::$$HTTP[$name])) { - unset(self::$$HTTP[$name]); - } - } - } + private static function removeArrayValues(array $array) { + return array_filter($array, function($value) { + return !is_array($value); + }); } #=============================================================================== @@ -114,7 +113,7 @@ class HTTP { #=============================================================================== # Checks if all elements of $arguments are set as key of $data #=============================================================================== - private static function issetData($data, $arguments) { + private static function issetData($data, $arguments): bool { foreach($arguments as $key) { if(is_array($key)) { if(!isset($data[key($key)]) OR $data[key($key)] !== $key[key($key)]) { @@ -131,61 +130,45 @@ class HTTP { } #=============================================================================== - # Return null or the value (if set) from one of the three requests attributes - #=============================================================================== - public static function returnKey($data, array $paths) { - $current = &$data; - - foreach($paths as $path) { - if(!isset($current[$path])) { - return NULL; - } - $current = &$current[$path]; - } - - return $current; - } - - #=============================================================================== # Return GET value #=============================================================================== - public static function GET() { - return self::returnKey(self::$GET, func_get_args()); + public static function GET($parameter) { + return self::$GET[$parameter] ?? NULL; } #=============================================================================== # Return POST value #=============================================================================== - public static function POST() { - return self::returnKey(self::$POST, func_get_args()); + public static function POST($parameter) { + return self::$POST[$parameter] ?? NULL; } #=============================================================================== # Return FILE value #=============================================================================== - public static function FILE() { - return self::returnKey(self::$FILE, func_get_args()); + public static function FILE($parameter) { + return self::$FILE[$parameter] ?? NULL; } #=============================================================================== - # Checks if all elements of func_get_args() are set key of self::$POST + # Checks if all elements of $parameters are set as key in self::$GET #=============================================================================== - public static function issetPOST() { - return self::issetData(self::$POST, func_get_args()); + public static function issetGET(... $parameters): bool { + return self::issetData(self::$GET, $parameters); } #=============================================================================== - # Checks if all elements of func_get_args() are set key of self::$GET + # Checks if all elements of $parameters are set as key in self::$POST #=============================================================================== - public static function issetGET() { - return self::issetData(self::$GET, func_get_args()); + public static function issetPOST(... $parameters): bool { + return self::issetData(self::$POST, $parameters); } #=============================================================================== - # Checks if all elements of func_get_args() are set key of self::$FILE + # Checks if all elements of $parameters are set as key in self::$FILE #=============================================================================== - public static function issetFILE() { - return self::issetData(self::$FILE, func_get_args()); + public static function issetFILE(... $parameters): bool { + return self::issetData(self::$FILE, $parameters); } #=============================================================================== diff --git a/template/admin/html/page/item.php b/template/admin/html/page/item.php index 599e942..8afeb15 100644 --- a/template/admin/html/page/item.php +++ b/template/admin/html/page/item.php @@ -1,8 +1,8 @@ <li class="item-list-li page"> <header> - <h2><i class="fa fa-file-text-o"></i><?=escapeHTML($PAGE['ATTR']['NAME'])?><span>#<?=$PAGE['ID']?></span></h2> + <h2><i class="fa fa-file-text-o"></i><?=escapeHTML($PAGE['ATTR']['NAME'])?><span>#<?=$PAGE['ATTR']['ID']?></span></h2> <div> - <a class="brackets" href="<?=Application::getAdminURL("user/update.php?id={$USER['ID']}")?>"><?=escapeHTML($USER['ATTR']['FULLNAME'])?></a> + <a class="brackets" href="<?=Application::getAdminURL("user/update.php?id={$USER['ATTR']['ID']}")?>"><?=escapeHTML($USER['ATTR']['FULLNAME'])?></a> <time class="brackets" datetime="<?=$PAGE['ATTR']['TIME_INSERT']?>"><?=parseDatetime($PAGE['ATTR']['TIME_INSERT'], $Language->template('date_format'))?></time> </div> </header> @@ -21,8 +21,8 @@ <footer> <ul> <li><a href="<?=$PAGE['URL']?>" target="_blank" title="<?=$Language->text('select_page')?>"><i class="fa fa-external-link"></i></a></li> - <li><a href="<?=Application::getAdminURL("page/update.php?id={$PAGE['ID']}")?>" title="<?=$Language->text('update_page')?>"><i class="fa fa-pencil-square-o"></i></a></li> - <li><a href="<?=Application::getAdminURL("page/delete.php?id={$PAGE['ID']}")?>" title="<?=$Language->text('delete_page')?>"><i class="fa fa-trash-o"></i></a></li> + <li><a href="<?=Application::getAdminURL("page/update.php?id={$PAGE['ATTR']['ID']}")?>" title="<?=$Language->text('update_page')?>"><i class="fa fa-pencil-square-o"></i></a></li> + <li><a href="<?=Application::getAdminURL("page/delete.php?id={$PAGE['ATTR']['ID']}")?>" title="<?=$Language->text('delete_page')?>"><i class="fa fa-trash-o"></i></a></li> </ul> </footer> </li>
\ No newline at end of file diff --git a/template/admin/html/post/item.php b/template/admin/html/post/item.php index abc2b0f..a49e2a5 100644 --- a/template/admin/html/post/item.php +++ b/template/admin/html/post/item.php @@ -1,8 +1,8 @@ <li class="item-list-li post"> <header> - <h2><i class="fa fa-newspaper-o"></i><?=escapeHTML($POST['ATTR']['NAME'])?><span>#<?=$POST['ID']?></span></h2> + <h2><i class="fa fa-newspaper-o"></i><?=escapeHTML($POST['ATTR']['NAME'])?><span>#<?=$POST['ATTR']['ID']?></span></h2> <div> - <a class="brackets" href="<?=Application::getAdminURL("user/update.php?id={$USER['ID']}")?>"><?=escapeHTML($USER['ATTR']['FULLNAME'])?></a> + <a class="brackets" href="<?=Application::getAdminURL("user/update.php?id={$USER['ATTR']['ID']}")?>"><?=escapeHTML($USER['ATTR']['FULLNAME'])?></a> <time class="brackets" datetime="<?=$POST['ATTR']['TIME_INSERT']?>"><?=parseDatetime($POST['ATTR']['TIME_INSERT'], $Language->template('date_format'))?></time> </div> </header> @@ -21,8 +21,8 @@ <footer> <ul> <li><a href="<?=$POST['URL']?>" target="_blank" title="<?=$Language->text('select_post')?>"><i class="fa fa-external-link"></i></a></li> - <li><a href="<?=Application::getAdminURL("post/update.php?id={$POST['ID']}")?>" title="<?=$Language->text('update_post')?>"><i class="fa fa-pencil-square-o"></i></a></li> - <li><a href="<?=Application::getAdminURL("post/delete.php?id={$POST['ID']}")?>" title="<?=$Language->text('delete_post')?>"><i class="fa fa-trash-o"></i></a></li> + <li><a href="<?=Application::getAdminURL("post/update.php?id={$POST['ATTR']['ID']}")?>" title="<?=$Language->text('update_post')?>"><i class="fa fa-pencil-square-o"></i></a></li> + <li><a href="<?=Application::getAdminURL("post/delete.php?id={$POST['ATTR']['ID']}")?>" title="<?=$Language->text('delete_post')?>"><i class="fa fa-trash-o"></i></a></li> </ul> </footer> </li>
\ No newline at end of file diff --git a/template/admin/html/user/item.php b/template/admin/html/user/item.php index 731f6b5..5efbae3 100644 --- a/template/admin/html/user/item.php +++ b/template/admin/html/user/item.php @@ -1,6 +1,6 @@ <li class="item-list-li user"> <header> - <h2><i class="fa fa-user"></i><?=escapeHTML($USER['ATTR']['FULLNAME'])?><span>#<?=$USER['ID']?></span></h2> + <h2><i class="fa fa-user"></i><?=escapeHTML($USER['ATTR']['FULLNAME'])?><span>#<?=$USER['ATTR']['ID']?></span></h2> <div> <time class="brackets" datetime="<?=$USER['ATTR']['TIME_INSERT']?>"><?=parseDatetime($USER['ATTR']['TIME_INSERT'], $Language->template('date_format'))?></time> </div> @@ -20,8 +20,8 @@ <footer> <ul> <li><a href="<?=$USER['URL']?>" target="_blank" title="<?=$Language->text('select_user')?>"><i class="fa fa-external-link"></i></a></li> - <li><a href="<?=Application::getAdminURL("user/update.php?id={$USER['ID']}")?>" title="<?=$Language->text('update_user')?>"><i class="fa fa-pencil-square-o"></i></a></li> - <li><a href="<?=Application::getAdminURL("user/delete.php?id={$USER['ID']}")?>" title="<?=$Language->text('delete_user')?>"><i class="fa fa-trash-o"></i></a></li> + <li><a href="<?=Application::getAdminURL("user/update.php?id={$USER['ATTR']['ID']}")?>" title="<?=$Language->text('update_user')?>"><i class="fa fa-pencil-square-o"></i></a></li> + <li><a href="<?=Application::getAdminURL("user/delete.php?id={$USER['ATTR']['ID']}")?>" title="<?=$Language->text('delete_user')?>"><i class="fa fa-trash-o"></i></a></li> </ul> </footer> </li>
\ No newline at end of file |