Compare commits

...

4 commits

Author SHA1 Message Date
Kazhnuz
a5805a1f3f 🗃️ add an archive database for pages
Show pages by dates (monthly or yearly)
2025-01-19 11:38:07 +01:00
Kazhnuz
e1f77f2eac 🐛 (login): some visual fixes 2025-01-19 11:22:46 +01:00
Kazhnuz
79ff2bc74d (pages): allow to show pages by author 2025-01-19 11:22:30 +01:00
Kazhnuz
6b8420b10e 🗃️ add an author database for pages 2025-01-19 10:54:16 +01:00
8 changed files with 143 additions and 4 deletions

View file

@ -11,13 +11,13 @@ echo Bootstrap::formInputHidden(array(
echo '
<div class="form-group">
<input type="text" dir="auto" value="' . (isset($_POST['username']) ? Sanitize::html($_POST['username']) : '') . '" class="form-control form-control-lg" id="jsusername" name="username" placeholder="' . $L->g('Username') . '" autofocus>
<input type="text" dir="auto" value="' . (isset($_POST['username']) ? Sanitize::html($_POST['username']) : '') . '" class="form-control form-control-lg mb-2" id="jsusername" name="username" placeholder="' . $L->g('Username') . '" autofocus>
</div>
';
echo '
<div class="form-group">
<input type="password" class="form-control form-control-lg" id="jspassword" name="password" placeholder="' . $L->g('Password') . '">
<input type="password" class="form-control form-control-lg mb-2" id="jspassword" name="password" placeholder="' . $L->g('Password') . '">
</div>
';
@ -34,4 +34,4 @@ echo '
echo '</form>';
echo '<p class="mt-3 text-right">' . $L->g('Powered by Koblog') . '</p>';
echo '<p class="mt-3 text-end">' . $L->g('Powered by Koblog') . '</p>';

View file

@ -0,0 +1,49 @@
<?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();
}
}

View file

@ -0,0 +1,37 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
class Authors extends dbList {
function __construct()
{
parent::__construct(DB_AUTHORS);
}
function numberOfPages($key)
{
return $this->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();
}
}

View file

@ -66,6 +66,8 @@ define('DB_PAGES', PATH_DATABASES . 'pages.php');
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');
@ -88,6 +90,8 @@ include(PATH_ABSTRACT . 'plugin.class.php');
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');
@ -126,6 +130,8 @@ include(PATH_HELPERS . 'cookie.class.php');
$pages = new Pages();
$users = new Users();
$tags = new Tags();
$authors = new Authors();
$archives = new Archives();
$categories = new Categories();
$site = new Site();
$url = new Url();
@ -191,6 +197,9 @@ define('TAG_URI_FILTER', $url->filters('tag'));
// Category URI filter
define('CATEGORY_URI_FILTER', $url->filters('category'));
// Author URI filter
define('AUTHOR_URI_FILTER', $url->filters('author'));
// Page URI filter
define('PAGE_URI_FILTER', $url->filters('page'));
@ -247,6 +256,7 @@ define('DOMAIN_ADMIN', DOMAIN_BASE . ADMIN_URI_FILTER . '/');
define('DOMAIN_TAGS', Text::addSlashes(DOMAIN_BASE . TAG_URI_FILTER, false, true));
define('DOMAIN_CATEGORIES', Text::addSlashes(DOMAIN_BASE . CATEGORY_URI_FILTER, false, true));
define('DOMAIN_PAGES', Text::addSlashes(DOMAIN_BASE . PAGE_URI_FILTER, false, true));
define('DOMAIN_AUTHORS', Text::addSlashes(DOMAIN_BASE . AUTHOR_URI_FILTER, false, true));
$ADMIN_CONTROLLER = '';
$ADMIN_VIEW = '';

View file

@ -71,6 +71,10 @@ elseif ($url->whereAmI()==='tag') {
elseif ($url->whereAmI()==='category') {
$content = buildPagesByCategory();
}
// Build content by author
elseif ($url->whereAmI()==='author') {
$content = buildPagesByAuthor();
}
// Build content for the homepage
elseif ( ($url->whereAmI()==='home') || ($url->whereAmI()==='blog') ) {
$content = buildPagesForHome();

View file

@ -16,6 +16,22 @@ 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();
}
// 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()
{
@ -84,16 +100,26 @@ function buildPagesByTag()
return buildPagesFor('tag', false, $tagKey);
}
// This function is only used from the rule 69.pages.php, DO NOT use this function!
function buildPagesByAuthor()
{
global $url;
$authorKey = $url->slug();
return buildPagesFor('author', false, false, $authorKey);
}
// This function is only used from the rule 69.pages.php, DO NOT use this function!
// Generate the global variables $content / $content, defined on 69.pages.php
// This function is use for buildPagesForHome(), buildPagesByCategory(), buildPagesByTag()
function buildPagesFor($for, $categoryKey = false, $tagKey = false)
function buildPagesFor($for, $categoryKey = false, $tagKey = false, $authorKey = false)
{
global $pages;
global $categories;
global $tags;
global $site;
global $url;
global $authors;
// Get the page number from URL
$pageNumber = $url->pageNumber();
@ -114,6 +140,9 @@ function buildPagesFor($for, $categoryKey = false, $tagKey = false)
} elseif ($for == 'tag') {
$numberOfItems = $site->itemsPerPage();
$list = $tags->getList($tagKey, $pageNumber, $numberOfItems);
} elseif ($for == 'author') {
$numberOfItems = $site->itemsPerPage();
$list = $authors->getList($authorKey, $pageNumber, $numberOfItems);
}
// There are not items, invalid tag, invalid category, out of range, etc...
@ -341,6 +370,8 @@ function createPage($args)
reindexCategories();
reindexTags();
reindexAuthors();
reindexArchives();
// Add to syslog
$syslog->add(array(
@ -392,6 +423,8 @@ function editPage($args)
reindexCategories();
reindexTags();
reindexAuthors();
reindexArchives();
// Add to syslog
$syslog->add(array(
@ -417,6 +450,8 @@ function deletePage($key)
reindexCategories();
reindexTags();
reindexAuthors();
reindexArchives();
// Add to syslog
$syslog->add(array(

View file

@ -19,6 +19,7 @@ class Site extends dbJSON
'uriTag' => '/tag/',
'uriCategory' => '/category/',
'uriBlog' => '/blog/',
'uriAuthor' => '/author/',
'url' => '',
'emailFrom' => '',
'dateFormat' => 'F j, Y',
@ -99,6 +100,7 @@ class Site extends dbJSON
$filters['page'] = $this->getField('uriPage');
$filters['tag'] = $this->getField('uriTag');
$filters['category'] = $this->getField('uriCategory');
$filters['author'] = $this->getField('uriAuthor');
if ($this->getField('uriBlog')) {
$filters['blog'] = $this->getField('uriBlog');

View file

@ -154,6 +154,8 @@ EOF;
Theme::plugins('afterPageCreate');
reindexCategories();
reindexTags();
reindexAuthors();
reindexArchives();
}
return true;