From a5805a1f3f815c73648acd04991db277e598911c Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 19 Jan 2025 11:38:07 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20add=20an=20archive=20da?= =?UTF-8?q?tabase=20for=20pages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Show pages by dates (monthly or yearly) --- bl-kernel/archives.class.php | 49 ++++++++++++++++++++++++++++ bl-kernel/boot/init.php | 3 ++ bl-kernel/functions.php | 11 +++++++ bl-plugins/remote-content/plugin.php | 1 + 4 files changed, 64 insertions(+) create mode 100644 bl-kernel/archives.class.php diff --git a/bl-kernel/archives.class.php b/bl-kernel/archives.class.php new file mode 100644 index 00000000..314ab678 --- /dev/null +++ b/bl-kernel/archives.class.php @@ -0,0 +1,49 @@ +countItems($key); + } + + public function reindex() + { + global $pages; + $db = $pages->getDB($onlyKeys=false); + $archiveIndex = array(); + foreach ($db as $pageKey=>$pageFields) { + if (in_array($pageFields['type'], $GLOBALS['DB_TAGS_TYPES'])) { + $date = $pageFields['date']; + $year = mb_substr($date, 0, 4); + $month = mb_substr($date, 0, 7); + + // Index by years + if (isset($archiveIndex[$year])) { + array_push($archiveIndex[$year]['list'], $pageKey); + } else { + $archiveIndex[$year]['name'] = $year; + $archiveIndex[$year]['list'] = array($pageKey); + } + + // Index by month + if (isset($archiveIndex[$month])) { + array_push($archiveIndex[$month]['list'], $pageKey); + } else { + $archiveIndex[$month]['name'] = $month; + $archiveIndex[$month]['list'] = array($pageKey); + } + } + } + + $this->db = $archiveIndex; + $this->sortAlphanumeric(); + return $this->save(); + } + +} \ No newline at end of file diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index 4177f3e3..ee779727 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -67,6 +67,7 @@ define('DB_SITE', PATH_DATABASES . 'site.php'); define('DB_CATEGORIES', PATH_DATABASES . 'categories.php'); define('DB_TAGS', PATH_DATABASES . 'tags.php'); define('DB_AUTHORS', PATH_DATABASES . 'authors.php'); +define('DB_ARCHIVES', PATH_DATABASES . 'archives.php'); define('DB_SYSLOG', PATH_DATABASES . 'syslog.php'); define('DB_USERS', PATH_DATABASES . 'users.php'); define('DB_SECURITY', PATH_DATABASES . 'security.php'); @@ -90,6 +91,7 @@ include(PATH_KERNEL . 'pages.class.php'); include(PATH_KERNEL . 'users.class.php'); include(PATH_KERNEL . 'tags.class.php'); include(PATH_KERNEL . 'authors.class.php'); +include(PATH_KERNEL . 'archives.class.php'); include(PATH_KERNEL . 'language.class.php'); include(PATH_KERNEL . 'site.class.php'); include(PATH_KERNEL . 'categories.class.php'); @@ -129,6 +131,7 @@ $pages = new Pages(); $users = new Users(); $tags = new Tags(); $authors = new Authors(); +$archives = new Archives(); $categories = new Categories(); $site = new Site(); $url = new Url(); diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index bf07b9cc..c6cee4db 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -24,6 +24,14 @@ function reindexAuthors() return $authors->reindex(); } +// Re-index database of archives +// If you create/edit/remove a page is necessary regenerate the database of archives +function reindexArchives() +{ + global $archives; + return $archives->reindex(); +} + // Generate the page 404 Not found function buildErrorPage() { @@ -363,6 +371,7 @@ function createPage($args) reindexCategories(); reindexTags(); reindexAuthors(); + reindexArchives(); // Add to syslog $syslog->add(array( @@ -415,6 +424,7 @@ function editPage($args) reindexCategories(); reindexTags(); reindexAuthors(); + reindexArchives(); // Add to syslog $syslog->add(array( @@ -441,6 +451,7 @@ function deletePage($key) reindexCategories(); reindexTags(); reindexAuthors(); + reindexArchives(); // Add to syslog $syslog->add(array( diff --git a/bl-plugins/remote-content/plugin.php b/bl-plugins/remote-content/plugin.php index 2f301493..4c05aa7d 100644 --- a/bl-plugins/remote-content/plugin.php +++ b/bl-plugins/remote-content/plugin.php @@ -155,6 +155,7 @@ EOF; reindexCategories(); reindexTags(); reindexAuthors(); + reindexArchives(); } return true;