🗃️ add an author database for pages

This commit is contained in:
Kazhnuz 2025-01-19 10:54:16 +01:00
parent 2326bdf770
commit 6b8420b10e
3 changed files with 49 additions and 0 deletions

View file

@ -0,0 +1,37 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
class Authors extends dbList {
function __construct()
{
parent::__construct(DB_AUTHORS);
}
function numberOfPages($key)
{
return $this->countItems($key);
}
public function reindex()
{
global $pages;
$db = $pages->getDB($onlyKeys=false);
$authorsIndex = array();
foreach ($db as $pageKey=>$pageFields) {
if (in_array($pageFields['type'], $GLOBALS['DB_TAGS_TYPES'])) {
$authorName = $pageFields['username'];
if (isset($authorsIndex[$authorName])) {
array_push($authorsIndex[$authorName]['list'], $pageKey);
} else {
$authorsIndex[$authorName]['name'] = $authorName;
$authorsIndex[$authorName]['list'] = array($pageKey);
}
}
}
$this->db = $authorsIndex;
$this->sortAlphanumeric();
return $this->save();
}
}

View file

@ -16,6 +16,14 @@ function reindexTags()
return $tags->reindex();
}
// Re-index database of authors
// If you create/edit/remove a page is necessary regenerate the database of authors
function reindexAuthors()
{
global $authors;
return $authors->reindex();
}
// Generate the page 404 Not found
function buildErrorPage()
{
@ -341,6 +349,7 @@ function createPage($args)
reindexCategories();
reindexTags();
reindexAuthors();
// Add to syslog
$syslog->add(array(
@ -392,6 +401,7 @@ function editPage($args)
reindexCategories();
reindexTags();
reindexAuthors();
// Add to syslog
$syslog->add(array(
@ -417,6 +427,7 @@ function deletePage($key)
reindexCategories();
reindexTags();
reindexAuthors();
// Add to syslog
$syslog->add(array(

View file

@ -154,6 +154,7 @@ EOF;
Theme::plugins('afterPageCreate');
reindexCategories();
reindexTags();
reindexAuthors();
}
return true;