64 lines
No EOL
1.6 KiB
PHP
64 lines
No EOL
1.6 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'] = Date::prettyArchiveDate($month);
|
|
$archiveIndex[$month]['list'] = array($pageKey);
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->db = $archiveIndex;
|
|
$this->sortAlphanumeric();
|
|
return $this->save();
|
|
}
|
|
|
|
public function getLinkList($month, $class = "", $classActive = "active")
|
|
{
|
|
$listLink = array();
|
|
foreach ($this->db as $pageKey=>$pageFields) {
|
|
if (
|
|
($month && strlen($pageKey) != 4)
|
|
|| (!$month && strlen($pageKey) == 4)
|
|
) {
|
|
$link = DOMAIN_ARCHIVES . $pageKey;
|
|
$listLink[] = new Link($pageFields['name'], $link, $class, $classActive);
|
|
}
|
|
}
|
|
return $listLink;
|
|
}
|
|
|
|
} |