class category and tag

This commit is contained in:
Diego Najar 2017-12-18 23:49:53 +01:00
parent 3b4b1c2f79
commit 7a3cb64a0f
4 changed files with 149 additions and 0 deletions

View File

@ -87,6 +87,8 @@ include(PATH_KERNEL.'dbsite.class.php');
include(PATH_KERNEL.'dbcategories.class.php'); include(PATH_KERNEL.'dbcategories.class.php');
include(PATH_KERNEL.'dbsyslog.class.php'); include(PATH_KERNEL.'dbsyslog.class.php');
include(PATH_KERNEL.'page.class.php'); include(PATH_KERNEL.'page.class.php');
include(PATH_KERNEL.'category.class.php');
include(PATH_KERNEL.'tag.class.php');
include(PATH_KERNEL.'user.class.php'); include(PATH_KERNEL.'user.class.php');
include(PATH_KERNEL.'url.class.php'); include(PATH_KERNEL.'url.class.php');
include(PATH_KERNEL.'login.class.php'); include(PATH_KERNEL.'login.class.php');

View File

@ -0,0 +1,56 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
class Category {
private $vars;
function __construct($key)
{
global $dbCategories;
if (isset($dbCategories->db[$key])) {
$this->vars['name'] = $dbCategories->db[$key]['name'];
$this->vars['key'] = $key;
$this->vars['permalink'] = DOMAIN_CATEGORIES . $key;
$this->vars['list'] = $dbCategories->db[$key]['list'];
}
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)
{
if (isset($this->vars[$field])) {
return $this->vars[$field];
}
return false;
}
public function key()
{
return $this->getValue('key');
}
public function name()
{
return $this->getValue('name');
}
public function permalink()
{
return $this->getValue('permalink');
}
// Returns an array with the keys of pages linked to the category
public function pages()
{
return $this->getValue('list');
}
}

View File

@ -705,6 +705,41 @@ function deleteCategory($categoryKey) {
return true; return true;
} }
// Returns an array with all the categories
// By default, the database of categories is alphanumeric sorted
function getCategories() {
global $dbCategories;
$list = array();
foreach ($dbCategories->db as $key=>$fields) {
$category = new Category($key);
array_push($list, $category);
}
return $list;
}
// Returns the object category if the category exists, FALSE otherwise
function getCategory($key) {
$category = new Category($key);
if (!$category->isValid()) {
return false;
}
return $category;
}
// Returns an array with all the tags
// By default, the database of tags is alphanumeric sorted
function getTags() {
global $dbTags;
$list = array();
foreach ($dbTags->db as $key=>$fields) {
$tag = new Tag($key);
array_push($list, $tag);
}
return $list;
}
function activateTheme($themeDirectory) { function activateTheme($themeDirectory) {
global $Site; global $Site;
global $Syslog; global $Syslog;

56
bl-kernel/tag.class.php Normal file
View File

@ -0,0 +1,56 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
class Tag {
private $vars;
function __construct($key)
{
global $dbTags;
if (isset($dbTags->db[$key])) {
$this->vars['name'] = $dbTags->db[$key]['name'];
$this->vars['key'] = $key;
$this->vars['permalink'] = DOMAIN_TAGS . $key;
$this->vars['list'] = $dbTags->db[$key]['list'];
}
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)
{
if (isset($this->vars[$field])) {
return $this->vars[$field];
}
return false;
}
public function key()
{
return $this->getValue('key');
}
public function name()
{
return $this->getValue('name');
}
public function permalink()
{
return $this->getValue('permalink');
}
// Returns an array with the keys of pages linked to the tag
public function pages()
{
return $this->getValue('list');
}
}