bludit/bl-kernel/tags.class.php

40 lines
798 B
PHP
Raw Normal View History

2015-08-29 07:02:09 +02:00
<?php defined('BLUDIT') or die('Bludit CMS.');
2018-08-03 18:59:23 +02:00
class Tags extends dbList {
2015-08-29 07:02:09 +02:00
function __construct()
{
2017-05-12 20:18:44 +02:00
parent::__construct(DB_TAGS);
2015-08-29 07:02:09 +02:00
}
2018-08-04 12:44:37 +02:00
function numberOfPages($key)
2015-12-31 19:47:34 +01:00
{
2018-08-04 12:44:37 +02:00
return $this->countItems($key);
2015-12-31 19:47:34 +01:00
}
2017-05-12 20:18:44 +02:00
public function reindex()
2015-08-30 01:26:46 +02:00
{
2018-08-03 18:59:23 +02:00
global $pages;
2015-08-30 01:26:46 +02:00
2017-06-23 00:41:00 +02:00
// Get a database with published pages
2019-02-19 08:38:17 +01:00
$db = $pages->getDB(false);
2015-08-29 07:02:09 +02:00
$tagsIndex = array();
2019-02-19 08:38:17 +01:00
foreach ($db as $pageKey=>$pageFields) {
2017-05-12 20:18:44 +02:00
$tags = $pageFields['tags'];
2019-02-19 08:38:17 +01:00
foreach ($tags as $tagKey=>$tagName) {
if (isset($tagsIndex[$tagKey])) {
2017-05-12 20:18:44 +02:00
array_push($tagsIndex[$tagKey]['list'], $pageKey);
2019-02-19 08:38:17 +01:00
} else {
2015-09-18 05:24:10 +02:00
$tagsIndex[$tagKey]['name'] = $tagName;
2017-05-12 20:18:44 +02:00
$tagsIndex[$tagKey]['list'] = array($pageKey);
2015-08-29 07:02:09 +02:00
}
}
}
2019-02-19 08:38:17 +01:00
// Sort database by alphabet
ksort($tagsIndex);
2017-05-12 20:18:44 +02:00
$this->db = $tagsIndex;
return $this->save();
2015-08-29 07:02:09 +02:00
}
2016-02-26 15:42:28 +01:00
}