categories description and bug fix
This commit is contained in:
parent
5cdef56023
commit
b04587813e
@ -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])) {
|
||||
|
@ -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');
|
||||
|
@ -189,7 +189,7 @@ EOF;
|
||||
$class = $class.' '.$args['class'];
|
||||
}
|
||||
|
||||
$html = '<div class="form-group m-0">';
|
||||
$html = '<div class="form-group">';
|
||||
if (!empty($args['label'])) {
|
||||
$html .= '<label for="'.$id.'">'.$args['label'].'</label>';
|
||||
}
|
||||
|
@ -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 '<tr>
|
||||
<td>
|
||||
@ -109,7 +109,7 @@ function table($type) {
|
||||
} else {
|
||||
foreach ($list as $pageKey) {
|
||||
try {
|
||||
$page = new PageX($pageKey);
|
||||
$page = new Page($pageKey);
|
||||
echo '<tr>';
|
||||
echo '<td class="pt-3">
|
||||
<div>
|
||||
|
@ -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'),
|
||||
|
@ -177,7 +177,7 @@
|
||||
// Parent
|
||||
try {
|
||||
$parentKey = $page->parent();
|
||||
$parent = new PageX($parentKey);
|
||||
$parent = new Page($parentKey);
|
||||
$parentOption = $parent->title();
|
||||
} catch (Exception $e) {
|
||||
$parentOption = '';
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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'];
|
||||
|
@ -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;
|
||||
|
@ -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 '<meta name="description" content="'.$description.'">'.PHP_EOL;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class PageX {
|
||||
class Page {
|
||||
|
||||
private $vars;
|
||||
|
||||
@ -433,7 +433,7 @@ class PageX {
|
||||
$parentKey = $this->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
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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,
|
||||
|
@ -105,7 +105,7 @@ class pluginNavigation extends Plugin {
|
||||
|
||||
foreach ($publishedPages as $pageKey) {
|
||||
try {
|
||||
$page = new PageX($pageKey);
|
||||
$page = new Page($pageKey);
|
||||
$html .= '<li>';
|
||||
$html .= '<a href="' . $page->permalink() . '">' . $page->title() . '</a>';
|
||||
$html .= '</li>';
|
||||
|
@ -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 .= '<item>';
|
||||
$xml .= '<title>'.$page->title().'</title>';
|
||||
$xml .= '<link>'.$page->permalink().'</link>';
|
||||
|
@ -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 .= '<url>';
|
||||
$xml .= '<loc>'.$page->permalink().'</loc>';
|
||||
$xml .= '<lastmod>'.$page->dateRaw(SITEMAP_DATE_FORMAT).'</lastmod>';
|
||||
|
Loading…
Reference in New Issue
Block a user