koblog/bl-kernel/archives.class.php
Kazhnuz a5805a1f3f 🗃️ add an archive database for pages
Show pages by dates (monthly or yearly)
2025-01-19 11:38:07 +01:00

49 lines
No EOL
1.2 KiB
PHP

<?php defined('KOBLOG') or die('Koblog CMS.');
class Archives extends dbList {
function __construct()
{
parent::__construct(DB_ARCHIVES);
}
function numberOfPages($key)
{
return $this->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();
}
}