From b04587813effa4ba3ebc450764008a59a213fb68 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Thu, 2 Aug 2018 17:06:53 +0200 Subject: [PATCH] categories description and bug fix --- bl-kernel/abstract/dblist.class.php | 10 +++-- bl-kernel/admin/controllers/edit-content.php | 4 +- bl-kernel/admin/themes/booty/init.php | 2 +- bl-kernel/admin/views/content.php | 4 +- bl-kernel/admin/views/edit-category.php | 10 +++++ bl-kernel/admin/views/edit-content.php | 2 +- bl-kernel/category.class.php | 20 +++++----- bl-kernel/dbcategories.class.php | 1 - bl-kernel/functions.php | 41 +++++++++++++++----- bl-kernel/helpers/theme.class.php | 41 +++++++++++++------- bl-kernel/pagex.class.php | 6 +-- bl-kernel/tag.class.php | 26 ++++++++----- bl-plugins/api/plugin.php | 4 +- bl-plugins/navigation/plugin.php | 2 +- bl-plugins/rss/plugin.php | 2 +- bl-plugins/sitemap/plugin.php | 2 +- 16 files changed, 116 insertions(+), 61 deletions(-) diff --git a/bl-kernel/abstract/dblist.class.php b/bl-kernel/abstract/dblist.class.php index 88d06ae2..1e45d5ce 100644 --- a/bl-kernel/abstract/dblist.class.php +++ b/bl-kernel/abstract/dblist.class.php @@ -7,11 +7,13 @@ Database structure "videos": { "name": "Videos", "template: "", + "description: "", "list": [ "my-page", "second-page" ] }, "pets": { "name": "Pets", "template: "", + "description: "", "list": [ "cats-and-dogs" ] } } @@ -65,13 +67,14 @@ class dbList extends dbJSON } // Add a new item to the dblist - // $args => 'name', 'template', 'list' + // $args => 'name', 'template', 'description', list' public function add($args) { $key = $this->generateKey($args['name']); $this->db[$key]['name'] = $args['name']; $this->db[$key]['template'] = isset($args['template'])?$args['template']:''; + $this->db[$key]['description'] = isset($args['description'])?$args['description']:''; $this->db[$key]['list'] = isset($args['list'])?$args['list']:array(); $this->sortAlphanumeric(); @@ -91,7 +94,7 @@ class dbList extends dbJSON } // Edit an item to the dblist - // $args => 'name', 'oldkey', 'newKey', 'template' + // $args => 'name', 'oldkey', 'newKey', 'template', 'description' public function edit($args) { if ( isset($this->db[$args['newKey']]) && ($args['newKey']!==$args['oldKey']) ) { @@ -101,6 +104,7 @@ class dbList extends dbJSON $this->db[$args['newKey']]['name'] = $args['name']; $this->db[$args['newKey']]['template'] = isset($args['template'])?$args['template']:''; + $this->db[$args['newKey']]['description'] = isset($args['description'])?$args['description']:''; $this->db[$args['newKey']]['list'] = $this->db[$args['oldKey']]['list']; // Remove the old category @@ -164,7 +168,7 @@ class dbList extends dbJSON } // Returns an array with a portion of the database filtered by key - // Returns array( 'key'=>'', 'name'=>'', 'template'=>'', 'list'=>array() ) + // Returns array( 'key'=>'', 'name'=>'', 'template'=>'', 'description'=>'', list'=>array() ) public function getMap($key) { if (isset($this->db[$key])) { diff --git a/bl-kernel/admin/controllers/edit-content.php b/bl-kernel/admin/controllers/edit-content.php index 1582baca..2de998f8 100644 --- a/bl-kernel/admin/controllers/edit-content.php +++ b/bl-kernel/admin/controllers/edit-content.php @@ -7,7 +7,7 @@ if (!checkRole(array('admin','editor'), false)) { try { $pageKey = isset($_POST['key']) ? $_POST['key'] : $layout['parameters']; - $page = new PageX($pageKey); + $page = new Page($pageKey); } catch (Exception $e) { Alert::set($Language->g('You do not have sufficient permissions')); Redirect::page('dashboard'); @@ -63,7 +63,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { // ============================================================================ try { $pageKey = $layout['parameters']; - $page = new PageX($pageKey); + $page = new Page($pageKey); } catch (Exception $e) { Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the page: '.$pageKey, LOG_TYPE_ERROR); Redirect::page('content'); diff --git a/bl-kernel/admin/themes/booty/init.php b/bl-kernel/admin/themes/booty/init.php index d481a670..1c981d98 100644 --- a/bl-kernel/admin/themes/booty/init.php +++ b/bl-kernel/admin/themes/booty/init.php @@ -189,7 +189,7 @@ EOF; $class = $class.' '.$args['class']; } - $html = '
'; + $html = '
'; if (!empty($args['label'])) { $html .= ''; } diff --git a/bl-kernel/admin/views/content.php b/bl-kernel/admin/views/content.php index 478c8d3d..df50249c 100644 --- a/bl-kernel/admin/views/content.php +++ b/bl-kernel/admin/views/content.php @@ -68,7 +68,7 @@ function table($type) { if (ORDER_BY=='position') { foreach ($list as $pageKey) { try { - $page = new PageX($pageKey); + $page = new Page($pageKey); if (!$page->isChild() || $type!='published') { echo ' @@ -109,7 +109,7 @@ function table($type) { } else { foreach ($list as $pageKey) { try { - $page = new PageX($pageKey); + $page = new Page($pageKey); echo ''; echo '
diff --git a/bl-kernel/admin/views/edit-category.php b/bl-kernel/admin/views/edit-category.php index 6a382ebf..7a5ea5b8 100644 --- a/bl-kernel/admin/views/edit-category.php +++ b/bl-kernel/admin/views/edit-category.php @@ -38,6 +38,16 @@ echo Bootstrap::formOpen(array('id'=>'jsform')); 'tip'=>'' )); + echo Bootstrap::formTextareaBlock(array( + 'name'=>'description', + 'label'=>$L->g('Category description'), + 'value'=>isset($categoryMap['description'])?$categoryMap['description']:'', + 'class'=>'', + 'placeholder'=>'', + 'tip'=>'', + 'rows'=>3 + )); + echo Bootstrap::formInputTextBlock(array( 'name'=>'template', 'label'=>$L->g('Category template'), diff --git a/bl-kernel/admin/views/edit-content.php b/bl-kernel/admin/views/edit-content.php index 71859665..2d943e05 100644 --- a/bl-kernel/admin/views/edit-content.php +++ b/bl-kernel/admin/views/edit-content.php @@ -177,7 +177,7 @@ // Parent try { $parentKey = $page->parent(); - $parent = new PageX($parentKey); + $parent = new Page($parentKey); $parentOption = $parent->title(); } catch (Exception $e) { $parentOption = ''; diff --git a/bl-kernel/category.class.php b/bl-kernel/category.class.php index 2a09d95b..f8c8246d 100644 --- a/bl-kernel/category.class.php +++ b/bl-kernel/category.class.php @@ -7,23 +7,18 @@ class Category { function __construct($key) { global $dbCategories; - if (isset($dbCategories->db[$key])) { $this->vars['name'] = $dbCategories->db[$key]['name']; $this->vars['template'] = $dbCategories->db[$key]['template']; + $this->vars['description'] = $dbCategories->db[$key]['description']; $this->vars['key'] = $key; $this->vars['permalink'] = DOMAIN_CATEGORIES . $key; $this->vars['list'] = $dbCategories->db[$key]['list']; + } else { + $errorMessage = 'Category not found in database by key ['.$key.']'; + Log::set(__METHOD__.LOG_SEP.$errorMessage); + throw new Exception($errorMessage); } - else { - $this->vars = false; - } - } - - // Returns TRUE if the category is valid/exists, FALSE otherwise - public function isValid() - { - return $this->vars!==false; } public function getValue($field) @@ -54,6 +49,11 @@ class Category { return $this->getValue('template'); } + public function description() + { + return $this->getValue('description'); + } + // Returns an array with the keys of pages linked to the category public function pages() { diff --git a/bl-kernel/dbcategories.class.php b/bl-kernel/dbcategories.class.php index dda63912..8cc9a41a 100644 --- a/bl-kernel/dbcategories.class.php +++ b/bl-kernel/dbcategories.class.php @@ -23,7 +23,6 @@ class dbCategories extends dbList // Get a database with published pages $db = $dbPages->getPublishedDB(false); - foreach ($db as $pageKey=>$pageFields) { if (!empty($pageFields['category'])) { $categoryKey = $pageFields['category']; diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 853ea88c..950d36c2 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -22,9 +22,9 @@ function buildErrorPage() { try { $pageNotFoundKey = $site->pageNotFound(); - $pageNotFound = New PageX($pageNotFoundKey); + $pageNotFound = New Page($pageNotFoundKey); } catch (Exception $e) { - $pageNotFound = New PageX(false); + $pageNotFound = New Page(false); $pageNotFound->setField('title', $language->get('page-not-found')); $pageNotFound->setField('content', $language->get('page-not-found-content')); $pageNotFound->setField('username', 'admin'); @@ -41,7 +41,7 @@ function buildThePage() { try { $pageKey = $url->slug(); - $page = New PageX($pageKey); + $page = New Page($pageKey); } catch (Exception $e) { $url->setNotFound(); return false; @@ -118,7 +118,7 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) { $content = array(); foreach ($list as $pageKey) { try { - $page = new PageX($pageKey); + $page = new Page($pageKey); array_push($content, $page); } catch (Exception $e) { // continue @@ -136,7 +136,7 @@ function buildStaticPages() { $pagesKey = $dbPages->getStaticDB(); foreach ($pagesKey as $pageKey) { try { - $page = new PageX($pageKey); + $page = new Page($pageKey); array_push($list, $page); } catch (Exception $e) { // continue @@ -146,6 +146,16 @@ function buildStaticPages() { return $list; } +// Returns the Page-Object if exists, FALSE otherwise +function buildPage($pageKey) { + try { + $page = new Page($pageKey); + return $page; + } catch (Exception $e) { + return false; + } +} + // Returns an array with all the parent pages as Page-Object // The pages are order by the settings on the system function buildParentPages() { @@ -155,7 +165,7 @@ function buildParentPages() { $pagesKey = $dbPages->getPublishedDB(); foreach ($pagesKey as $pageKey) { try { - $page = new PageX($pageKey); + $page = new Page($pageKey); array_push($list, $page); } catch (Exception $e) { // continue @@ -335,7 +345,7 @@ function editPage($args) { // Title and content need to be here because from inside the dbPages is not visible if (empty($args['title']) || empty($args['content'])) { try { - $page = new PageX($args['key']); + $page = new Page($args['key']); if (empty($args['title'])) { $args['title'] = $page->title(); } @@ -750,11 +760,12 @@ function getCategories() { // Returns the object category if the category exists, FALSE otherwise function getCategory($key) { - $category = new Category($key); - if (!$category->isValid()) { + try { + $category = new Category($key); + return $category; + } catch (Exception $e) { return false; } - return $category; } // Returns an array with all the tags @@ -770,6 +781,16 @@ function getTags() { return $list; } +// Returns the object tag if the tag exists, FALSE otherwise +function getTag($key) { + try { + $tag = new Tag($key); + return $tag; + } catch (Exception $e) { + return false; + } +} + function activateTheme($themeDirectory) { global $site; global $syslog; diff --git a/bl-kernel/helpers/theme.class.php b/bl-kernel/helpers/theme.class.php index 8fd7cbad..cc71ea77 100644 --- a/bl-kernel/helpers/theme.class.php +++ b/bl-kernel/helpers/theme.class.php @@ -75,18 +75,25 @@ class Theme { $format = $site->titleFormatPages(); $format = Text::replace('{{page-title}}', $page->title(), $format); $format = Text::replace('{{page-description}}', $page->description(), $format); - } - elseif ($WHERE_AM_I=='tag') { - $tagKey = $url->slug(); - $tagName = $dbTags->getName($tagKey); - $format = $site->titleFormatTag(); - $format = Text::replace('{{tag-name}}', $tagName, $format); - } - elseif ($WHERE_AM_I=='category') { - $categoryKey = $url->slug(); - $categoryName = $dbCategories->getName($categoryKey); - $format = $site->titleFormatCategory(); - $format = Text::replace('{{category-name}}', $categoryName, $format); + } elseif ($WHERE_AM_I=='tag') { + try { + $tagKey = $url->slug(); + $tag = new Tag($tagKey); + $format = $site->titleFormatTag(); + $format = Text::replace('{{tag-name}}', $tag->name(), $format); + } catch (Exception $e) { + // Tag doesn't exist + } + + } elseif ($WHERE_AM_I=='category') { + try { + $categoryKey = $url->slug(); + $category = new Category($categoryKey); + $format = $site->titleFormatCategory(); + $format = Text::replace('{{category-name}}', $category->name(), $format); + } catch (Exception $e) { + // Category doesn't exist + } } else { $format = $site->titleFormatHomepage(); } @@ -106,8 +113,16 @@ class Theme { $description = $site->description(); - if( $WHERE_AM_I=='page' ) { + if ($WHERE_AM_I=='page') { $description = $page->description(); + } elseif ($WHERE_AM_I=='category') { + try { + $categoryKey = $url->slug(); + $category = new Category($categoryKey); + $description = $category->description(); + } catch (Exception $e) { + // description from the site + } } return ''.PHP_EOL; diff --git a/bl-kernel/pagex.class.php b/bl-kernel/pagex.class.php index e77687e9..3ffee1fd 100644 --- a/bl-kernel/pagex.class.php +++ b/bl-kernel/pagex.class.php @@ -1,6 +1,6 @@ parentKey(); if ($parentKey) { try { - $page = new PageX($parentKey); + $page = new Page($parentKey); return $page->{$method}(); } catch (Exception $e) { // Continoue @@ -472,7 +472,7 @@ class PageX { $childrenKeys = $dbPages->getChildren($this->key()); foreach ($childrenKeys as $childKey) { try { - $child = new PageX($childKey); + $child = new Page($childKey); array_push($list, $child); } catch (Exception $e) { // Continue diff --git a/bl-kernel/tag.class.php b/bl-kernel/tag.class.php index 4a9a9526..5d9f148d 100644 --- a/bl-kernel/tag.class.php +++ b/bl-kernel/tag.class.php @@ -7,22 +7,18 @@ class Tag { function __construct($key) { global $dbTags; - if (isset($dbTags->db[$key])) { $this->vars['name'] = $dbTags->db[$key]['name']; + $this->vars['template'] = $dbTags->db[$key]['template']; + $this->vars['description'] = $dbTags->db[$key]['description']; $this->vars['key'] = $key; $this->vars['permalink'] = DOMAIN_TAGS . $key; $this->vars['list'] = $dbTags->db[$key]['list']; + } else { + $errorMessage = 'Category not found in database by key ['.$key.']'; + Log::set(__METHOD__.LOG_SEP.$errorMessage); + throw new Exception($errorMessage); } - else { - $this->vars = false; - } - } - - // Returns TRUE if the tag is valid/exists, FALSE otherwise - public function isValid() - { - return $this->vars!==false; } public function getValue($field) @@ -48,6 +44,16 @@ class Tag { return $this->getValue('permalink'); } + public function template() + { + return $this->getValue('template'); + } + + public function description() + { + return $this->getValue('description'); + } + // Returns an array with the keys of pages linked to the tag public function pages() { diff --git a/bl-plugins/api/plugin.php b/bl-plugins/api/plugin.php index 68f32b20..06f9ce96 100644 --- a/bl-plugins/api/plugin.php +++ b/bl-plugins/api/plugin.php @@ -252,7 +252,7 @@ class pluginAPI extends Plugin { foreach ($list as $pageKey) { try { // Create the page object from the page key - $page = new PageX($pageKey); + $page = new Page($pageKey); array_push($tmp['data'], $page->json( $returnsArray=true )); } catch (Exception $e) { // Continue @@ -265,7 +265,7 @@ class pluginAPI extends Plugin { private function getPage($key) { try { - $page = new PageX($key); + $page = new Page($key); return array( 'status'=>'0', 'message'=>'Page filtered by key: '.$key, diff --git a/bl-plugins/navigation/plugin.php b/bl-plugins/navigation/plugin.php index 0f73ea26..457687c7 100644 --- a/bl-plugins/navigation/plugin.php +++ b/bl-plugins/navigation/plugin.php @@ -105,7 +105,7 @@ class pluginNavigation extends Plugin { foreach ($publishedPages as $pageKey) { try { - $page = new PageX($pageKey); + $page = new Page($pageKey); $html .= '
  • '; $html .= '' . $page->title() . ''; $html .= '
  • '; diff --git a/bl-plugins/rss/plugin.php b/bl-plugins/rss/plugin.php index 2ba4bc95..864ca870 100644 --- a/bl-plugins/rss/plugin.php +++ b/bl-plugins/rss/plugin.php @@ -62,7 +62,7 @@ class pluginRSS extends Plugin { foreach($list as $pageKey) { try { // Create the page object from the page key - $page = new PageX($pageKey); + $page = new Page($pageKey); $xml .= ''; $xml .= ''.$page->title().''; $xml .= ''.$page->permalink().''; diff --git a/bl-plugins/sitemap/plugin.php b/bl-plugins/sitemap/plugin.php index 6bd5f828..7a3d42e0 100644 --- a/bl-plugins/sitemap/plugin.php +++ b/bl-plugins/sitemap/plugin.php @@ -41,7 +41,7 @@ class pluginSitemap extends Plugin { foreach($list as $pageKey) { try { // Create the page object from the page key - $page = new PageX($pageKey); + $page = new Page($pageKey); $xml .= ''; $xml .= ''.$page->permalink().''; $xml .= ''.$page->dateRaw(SITEMAP_DATE_FORMAT).'';