From 6b8420b10e6b2009f9eae52b9871b6f0b65190bb Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 19 Jan 2025 10:54:16 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20add=20an=20author=20dat?= =?UTF-8?q?abase=20for=20pages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bl-kernel/authors.class.php | 37 ++++++++++++++++++++++++++++ bl-kernel/functions.php | 11 +++++++++ bl-plugins/remote-content/plugin.php | 1 + 3 files changed, 49 insertions(+) create mode 100644 bl-kernel/authors.class.php diff --git a/bl-kernel/authors.class.php b/bl-kernel/authors.class.php new file mode 100644 index 00000000..1a384c3e --- /dev/null +++ b/bl-kernel/authors.class.php @@ -0,0 +1,37 @@ +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(); + } + +} \ No newline at end of file diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 77711d40..e57337d5 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -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( diff --git a/bl-plugins/remote-content/plugin.php b/bl-plugins/remote-content/plugin.php index 98d9259b..2f301493 100644 --- a/bl-plugins/remote-content/plugin.php +++ b/bl-plugins/remote-content/plugin.php @@ -154,6 +154,7 @@ EOF; Theme::plugins('afterPageCreate'); reindexCategories(); reindexTags(); + reindexAuthors(); } return true;