categories description and bug fix

This commit is contained in:
Diego Najar 2018-08-02 17:06:53 +02:00
parent 5cdef56023
commit b04587813e
16 changed files with 116 additions and 61 deletions

View File

@ -7,11 +7,13 @@ Database structure
"videos": { "videos": {
"name": "Videos", "name": "Videos",
"template: "", "template: "",
"description: "",
"list": [ "my-page", "second-page" ] "list": [ "my-page", "second-page" ]
}, },
"pets": { "pets": {
"name": "Pets", "name": "Pets",
"template: "", "template: "",
"description: "",
"list": [ "cats-and-dogs" ] "list": [ "cats-and-dogs" ]
} }
} }
@ -65,13 +67,14 @@ class dbList extends dbJSON
} }
// Add a new item to the dblist // Add a new item to the dblist
// $args => 'name', 'template', 'list' // $args => 'name', 'template', 'description', list'
public function add($args) public function add($args)
{ {
$key = $this->generateKey($args['name']); $key = $this->generateKey($args['name']);
$this->db[$key]['name'] = $args['name']; $this->db[$key]['name'] = $args['name'];
$this->db[$key]['template'] = isset($args['template'])?$args['template']:''; $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->db[$key]['list'] = isset($args['list'])?$args['list']:array();
$this->sortAlphanumeric(); $this->sortAlphanumeric();
@ -91,7 +94,7 @@ class dbList extends dbJSON
} }
// Edit an item to the dblist // Edit an item to the dblist
// $args => 'name', 'oldkey', 'newKey', 'template' // $args => 'name', 'oldkey', 'newKey', 'template', 'description'
public function edit($args) public function edit($args)
{ {
if ( isset($this->db[$args['newKey']]) && ($args['newKey']!==$args['oldKey']) ) { 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']]['name'] = $args['name'];
$this->db[$args['newKey']]['template'] = isset($args['template'])?$args['template']:''; $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']; $this->db[$args['newKey']]['list'] = $this->db[$args['oldKey']]['list'];
// Remove the old category // 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 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) public function getMap($key)
{ {
if (isset($this->db[$key])) { if (isset($this->db[$key])) {

View File

@ -7,7 +7,7 @@
if (!checkRole(array('admin','editor'), false)) { if (!checkRole(array('admin','editor'), false)) {
try { try {
$pageKey = isset($_POST['key']) ? $_POST['key'] : $layout['parameters']; $pageKey = isset($_POST['key']) ? $_POST['key'] : $layout['parameters'];
$page = new PageX($pageKey); $page = new Page($pageKey);
} catch (Exception $e) { } catch (Exception $e) {
Alert::set($Language->g('You do not have sufficient permissions')); Alert::set($Language->g('You do not have sufficient permissions'));
Redirect::page('dashboard'); Redirect::page('dashboard');
@ -63,7 +63,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// ============================================================================ // ============================================================================
try { try {
$pageKey = $layout['parameters']; $pageKey = $layout['parameters'];
$page = new PageX($pageKey); $page = new Page($pageKey);
} catch (Exception $e) { } catch (Exception $e) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the page: '.$pageKey, LOG_TYPE_ERROR); Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the page: '.$pageKey, LOG_TYPE_ERROR);
Redirect::page('content'); Redirect::page('content');

View File

@ -189,7 +189,7 @@ EOF;
$class = $class.' '.$args['class']; $class = $class.' '.$args['class'];
} }
$html = '<div class="form-group m-0">'; $html = '<div class="form-group">';
if (!empty($args['label'])) { if (!empty($args['label'])) {
$html .= '<label for="'.$id.'">'.$args['label'].'</label>'; $html .= '<label for="'.$id.'">'.$args['label'].'</label>';
} }

View File

@ -68,7 +68,7 @@ function table($type) {
if (ORDER_BY=='position') { if (ORDER_BY=='position') {
foreach ($list as $pageKey) { foreach ($list as $pageKey) {
try { try {
$page = new PageX($pageKey); $page = new Page($pageKey);
if (!$page->isChild() || $type!='published') { if (!$page->isChild() || $type!='published') {
echo '<tr> echo '<tr>
<td> <td>
@ -109,7 +109,7 @@ function table($type) {
} else { } else {
foreach ($list as $pageKey) { foreach ($list as $pageKey) {
try { try {
$page = new PageX($pageKey); $page = new Page($pageKey);
echo '<tr>'; echo '<tr>';
echo '<td class="pt-3"> echo '<td class="pt-3">
<div> <div>

View File

@ -38,6 +38,16 @@ echo Bootstrap::formOpen(array('id'=>'jsform'));
'tip'=>'' '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( echo Bootstrap::formInputTextBlock(array(
'name'=>'template', 'name'=>'template',
'label'=>$L->g('Category template'), 'label'=>$L->g('Category template'),

View File

@ -177,7 +177,7 @@
// Parent // Parent
try { try {
$parentKey = $page->parent(); $parentKey = $page->parent();
$parent = new PageX($parentKey); $parent = new Page($parentKey);
$parentOption = $parent->title(); $parentOption = $parent->title();
} catch (Exception $e) { } catch (Exception $e) {
$parentOption = ''; $parentOption = '';

View File

@ -7,23 +7,18 @@ class Category {
function __construct($key) function __construct($key)
{ {
global $dbCategories; global $dbCategories;
if (isset($dbCategories->db[$key])) { if (isset($dbCategories->db[$key])) {
$this->vars['name'] = $dbCategories->db[$key]['name']; $this->vars['name'] = $dbCategories->db[$key]['name'];
$this->vars['template'] = $dbCategories->db[$key]['template']; $this->vars['template'] = $dbCategories->db[$key]['template'];
$this->vars['description'] = $dbCategories->db[$key]['description'];
$this->vars['key'] = $key; $this->vars['key'] = $key;
$this->vars['permalink'] = DOMAIN_CATEGORIES . $key; $this->vars['permalink'] = DOMAIN_CATEGORIES . $key;
$this->vars['list'] = $dbCategories->db[$key]['list']; $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) public function getValue($field)
@ -54,6 +49,11 @@ class Category {
return $this->getValue('template'); return $this->getValue('template');
} }
public function description()
{
return $this->getValue('description');
}
// Returns an array with the keys of pages linked to the category // Returns an array with the keys of pages linked to the category
public function pages() public function pages()
{ {

View File

@ -23,7 +23,6 @@ class dbCategories extends dbList
// Get a database with published pages // Get a database with published pages
$db = $dbPages->getPublishedDB(false); $db = $dbPages->getPublishedDB(false);
foreach ($db as $pageKey=>$pageFields) { foreach ($db as $pageKey=>$pageFields) {
if (!empty($pageFields['category'])) { if (!empty($pageFields['category'])) {
$categoryKey = $pageFields['category']; $categoryKey = $pageFields['category'];

View File

@ -22,9 +22,9 @@ function buildErrorPage() {
try { try {
$pageNotFoundKey = $site->pageNotFound(); $pageNotFoundKey = $site->pageNotFound();
$pageNotFound = New PageX($pageNotFoundKey); $pageNotFound = New Page($pageNotFoundKey);
} catch (Exception $e) { } catch (Exception $e) {
$pageNotFound = New PageX(false); $pageNotFound = New Page(false);
$pageNotFound->setField('title', $language->get('page-not-found')); $pageNotFound->setField('title', $language->get('page-not-found'));
$pageNotFound->setField('content', $language->get('page-not-found-content')); $pageNotFound->setField('content', $language->get('page-not-found-content'));
$pageNotFound->setField('username', 'admin'); $pageNotFound->setField('username', 'admin');
@ -41,7 +41,7 @@ function buildThePage() {
try { try {
$pageKey = $url->slug(); $pageKey = $url->slug();
$page = New PageX($pageKey); $page = New Page($pageKey);
} catch (Exception $e) { } catch (Exception $e) {
$url->setNotFound(); $url->setNotFound();
return false; return false;
@ -118,7 +118,7 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
$content = array(); $content = array();
foreach ($list as $pageKey) { foreach ($list as $pageKey) {
try { try {
$page = new PageX($pageKey); $page = new Page($pageKey);
array_push($content, $page); array_push($content, $page);
} catch (Exception $e) { } catch (Exception $e) {
// continue // continue
@ -136,7 +136,7 @@ function buildStaticPages() {
$pagesKey = $dbPages->getStaticDB(); $pagesKey = $dbPages->getStaticDB();
foreach ($pagesKey as $pageKey) { foreach ($pagesKey as $pageKey) {
try { try {
$page = new PageX($pageKey); $page = new Page($pageKey);
array_push($list, $page); array_push($list, $page);
} catch (Exception $e) { } catch (Exception $e) {
// continue // continue
@ -146,6 +146,16 @@ function buildStaticPages() {
return $list; 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 // Returns an array with all the parent pages as Page-Object
// The pages are order by the settings on the system // The pages are order by the settings on the system
function buildParentPages() { function buildParentPages() {
@ -155,7 +165,7 @@ function buildParentPages() {
$pagesKey = $dbPages->getPublishedDB(); $pagesKey = $dbPages->getPublishedDB();
foreach ($pagesKey as $pageKey) { foreach ($pagesKey as $pageKey) {
try { try {
$page = new PageX($pageKey); $page = new Page($pageKey);
array_push($list, $page); array_push($list, $page);
} catch (Exception $e) { } catch (Exception $e) {
// continue // continue
@ -335,7 +345,7 @@ function editPage($args) {
// Title and content need to be here because from inside the dbPages is not visible // Title and content need to be here because from inside the dbPages is not visible
if (empty($args['title']) || empty($args['content'])) { if (empty($args['title']) || empty($args['content'])) {
try { try {
$page = new PageX($args['key']); $page = new Page($args['key']);
if (empty($args['title'])) { if (empty($args['title'])) {
$args['title'] = $page->title(); $args['title'] = $page->title();
} }
@ -750,11 +760,12 @@ function getCategories() {
// Returns the object category if the category exists, FALSE otherwise // Returns the object category if the category exists, FALSE otherwise
function getCategory($key) { function getCategory($key) {
try {
$category = new Category($key); $category = new Category($key);
if (!$category->isValid()) { return $category;
} catch (Exception $e) {
return false; return false;
} }
return $category;
} }
// Returns an array with all the tags // Returns an array with all the tags
@ -770,6 +781,16 @@ function getTags() {
return $list; 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) { function activateTheme($themeDirectory) {
global $site; global $site;
global $syslog; global $syslog;

View File

@ -75,18 +75,25 @@ class Theme {
$format = $site->titleFormatPages(); $format = $site->titleFormatPages();
$format = Text::replace('{{page-title}}', $page->title(), $format); $format = Text::replace('{{page-title}}', $page->title(), $format);
$format = Text::replace('{{page-description}}', $page->description(), $format); $format = Text::replace('{{page-description}}', $page->description(), $format);
} } elseif ($WHERE_AM_I=='tag') {
elseif ($WHERE_AM_I=='tag') { try {
$tagKey = $url->slug(); $tagKey = $url->slug();
$tagName = $dbTags->getName($tagKey); $tag = new Tag($tagKey);
$format = $site->titleFormatTag(); $format = $site->titleFormatTag();
$format = Text::replace('{{tag-name}}', $tagName, $format); $format = Text::replace('{{tag-name}}', $tag->name(), $format);
} catch (Exception $e) {
// Tag doesn't exist
} }
elseif ($WHERE_AM_I=='category') {
} elseif ($WHERE_AM_I=='category') {
try {
$categoryKey = $url->slug(); $categoryKey = $url->slug();
$categoryName = $dbCategories->getName($categoryKey); $category = new Category($categoryKey);
$format = $site->titleFormatCategory(); $format = $site->titleFormatCategory();
$format = Text::replace('{{category-name}}', $categoryName, $format); $format = Text::replace('{{category-name}}', $category->name(), $format);
} catch (Exception $e) {
// Category doesn't exist
}
} else { } else {
$format = $site->titleFormatHomepage(); $format = $site->titleFormatHomepage();
} }
@ -106,8 +113,16 @@ class Theme {
$description = $site->description(); $description = $site->description();
if( $WHERE_AM_I=='page' ) { if ($WHERE_AM_I=='page') {
$description = $page->description(); $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 '<meta name="description" content="'.$description.'">'.PHP_EOL; return '<meta name="description" content="'.$description.'">'.PHP_EOL;

View File

@ -1,6 +1,6 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); <?php defined('BLUDIT') or die('Bludit CMS.');
class PageX { class Page {
private $vars; private $vars;
@ -433,7 +433,7 @@ class PageX {
$parentKey = $this->parentKey(); $parentKey = $this->parentKey();
if ($parentKey) { if ($parentKey) {
try { try {
$page = new PageX($parentKey); $page = new Page($parentKey);
return $page->{$method}(); return $page->{$method}();
} catch (Exception $e) { } catch (Exception $e) {
// Continoue // Continoue
@ -472,7 +472,7 @@ class PageX {
$childrenKeys = $dbPages->getChildren($this->key()); $childrenKeys = $dbPages->getChildren($this->key());
foreach ($childrenKeys as $childKey) { foreach ($childrenKeys as $childKey) {
try { try {
$child = new PageX($childKey); $child = new Page($childKey);
array_push($list, $child); array_push($list, $child);
} catch (Exception $e) { } catch (Exception $e) {
// Continue // Continue

View File

@ -7,22 +7,18 @@ class Tag {
function __construct($key) function __construct($key)
{ {
global $dbTags; global $dbTags;
if (isset($dbTags->db[$key])) { if (isset($dbTags->db[$key])) {
$this->vars['name'] = $dbTags->db[$key]['name']; $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['key'] = $key;
$this->vars['permalink'] = DOMAIN_TAGS . $key; $this->vars['permalink'] = DOMAIN_TAGS . $key;
$this->vars['list'] = $dbTags->db[$key]['list']; $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) public function getValue($field)
@ -48,6 +44,16 @@ class Tag {
return $this->getValue('permalink'); 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 // Returns an array with the keys of pages linked to the tag
public function pages() public function pages()
{ {

View File

@ -252,7 +252,7 @@ class pluginAPI extends Plugin {
foreach ($list as $pageKey) { foreach ($list as $pageKey) {
try { try {
// Create the page object from the page key // Create the page object from the page key
$page = new PageX($pageKey); $page = new Page($pageKey);
array_push($tmp['data'], $page->json( $returnsArray=true )); array_push($tmp['data'], $page->json( $returnsArray=true ));
} catch (Exception $e) { } catch (Exception $e) {
// Continue // Continue
@ -265,7 +265,7 @@ class pluginAPI extends Plugin {
private function getPage($key) private function getPage($key)
{ {
try { try {
$page = new PageX($key); $page = new Page($key);
return array( return array(
'status'=>'0', 'status'=>'0',
'message'=>'Page filtered by key: '.$key, 'message'=>'Page filtered by key: '.$key,

View File

@ -105,7 +105,7 @@ class pluginNavigation extends Plugin {
foreach ($publishedPages as $pageKey) { foreach ($publishedPages as $pageKey) {
try { try {
$page = new PageX($pageKey); $page = new Page($pageKey);
$html .= '<li>'; $html .= '<li>';
$html .= '<a href="' . $page->permalink() . '">' . $page->title() . '</a>'; $html .= '<a href="' . $page->permalink() . '">' . $page->title() . '</a>';
$html .= '</li>'; $html .= '</li>';

View File

@ -62,7 +62,7 @@ class pluginRSS extends Plugin {
foreach($list as $pageKey) { foreach($list as $pageKey) {
try { try {
// Create the page object from the page key // Create the page object from the page key
$page = new PageX($pageKey); $page = new Page($pageKey);
$xml .= '<item>'; $xml .= '<item>';
$xml .= '<title>'.$page->title().'</title>'; $xml .= '<title>'.$page->title().'</title>';
$xml .= '<link>'.$page->permalink().'</link>'; $xml .= '<link>'.$page->permalink().'</link>';

View File

@ -41,7 +41,7 @@ class pluginSitemap extends Plugin {
foreach($list as $pageKey) { foreach($list as $pageKey) {
try { try {
// Create the page object from the page key // Create the page object from the page key
$page = new PageX($pageKey); $page = new Page($pageKey);
$xml .= '<url>'; $xml .= '<url>';
$xml .= '<loc>'.$page->permalink().'</loc>'; $xml .= '<loc>'.$page->permalink().'</loc>';
$xml .= '<lastmod>'.$page->dateRaw(SITEMAP_DATE_FORMAT).'</lastmod>'; $xml .= '<lastmod>'.$page->dateRaw(SITEMAP_DATE_FORMAT).'</lastmod>';