Merge pull request 'Add Post Kinds' (#65) from koblog-redo into koblog2

Reviewed-on: #65
This commit is contained in:
Lake Kazhnuz 2025-06-26 20:57:32 +02:00
commit a099fa8ab0
16 changed files with 217 additions and 5 deletions

View file

@ -13,6 +13,10 @@ First forked version from bludit
- Admin: Added a sidebar panel that show all sidebar widget to be activated/deactivated
- Admin: Show some pages only if the theme support their features
- Site: Add support for archive view (à la Wordpress)
- Site: Add support for author view
- Site: Add support for IndieWeb post kinds
- Site: Add a source URL (usefull for some post kinds)
### Changed

View file

@ -1,7 +1,18 @@
<?php
echo "<div class='d-flex justify-content-between align-content-center'>";
echo Bootstrap::pageTitle(array('title'=>$L->g('Articles and pages'), 'icon'=>'archive'));
echo "<div>";
echo Bootstrap::link(array(
'title'=>$L->g('New'),
'href'=>HTML_PATH_ADMIN_ROOT.'new-content/',
'icon'=>'plus',
'class'=>'btn btn-outline-success'
));
echo "</div></div>";
function table($type) {
global $url;
global $L;

View file

@ -146,6 +146,18 @@ echo Bootstrap::formInputHidden(array(
'value' => $page->tags()
));
// Post Kinds
echo Bootstrap::formSelectBlock(array(
'name' => 'kind',
'label' => $L->g('Post Kinds'),
'selected' => $page->kind(),
'class' => '',
'emptyOption' => '- ' . $L->g('None') . ' -',
'options' => $kinds->getKeyNameArray(),
'mt' => 'mt-0',
'type'=> 'Post kinds allow themes to use different formating and microformat for this kind of posts'
));
// Description
echo Bootstrap::formTextareaBlock(array(
'name' => 'description',
@ -156,6 +168,15 @@ echo Bootstrap::formInputHidden(array(
'rows' => 5,
'placeholder' => $L->get('this-field-can-help-describe-the-content')
));
// Source Link
echo Bootstrap::formInputTextBlock(array(
'name' => 'sourceLink',
'label' => $L->g('Source Link'),
'placeholder' => '',
'tip' => $L->g('The external link you refer to in the post'),
'value' => $page->sourceLink()
));
?>
<!-- Cover Image -->

View file

@ -135,6 +135,18 @@ echo Bootstrap::formInputHidden(array(
'tip' => $L->g('Write the tags separated by comma')
));
// Post Kinds
echo Bootstrap::formSelectBlock(array(
'name' => 'kind',
'label' => $L->g('Post Kinds'),
'selected' => 'article',
'class' => '',
'emptyOption' => '- ' . $L->g('None') . ' -',
'options' => $kinds->getKeyNameArray(),
'mt' => 'mt-0',
'type'=> 'Post kinds allow themes to use different formating and microformat for this kind of posts'
));
// Description
echo Bootstrap::formTextareaBlock(array(
'name' => 'description',
@ -145,6 +157,15 @@ echo Bootstrap::formInputHidden(array(
'rows' => 5,
'placeholder' => $L->get('this-field-can-help-describe-the-content')
));
// Source Link
echo Bootstrap::formInputTextBlock(array(
'name' => 'sourceLink',
'label' => $L->g('Source Link'),
'placeholder' => '',
'tip' => $L->g('The external link you refer to in the post'),
'value' => ''
));
?>
<!-- Cover Image -->

View file

@ -306,6 +306,15 @@ echo Bootstrap::formInputHidden(array(
'tip' => DOMAIN_ARCHIVES
));
echo Bootstrap::formInputText(array(
'name' => 'uriKind',
'label' => $L->g('Post Kind'),
'value' => $site->uriFilters('kind'),
'class' => '',
'placeholder' => '',
'tip' => DOMAIN_KINDS
));
echo Bootstrap::formInputText(array(
'name' => 'uriAuthor',
'label' => $L->g('Authors'),

View file

@ -68,6 +68,7 @@ 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_KINDS', PATH_DATABASES . 'kinds.php');
define('DB_SYSLOG', PATH_DATABASES . 'syslog.php');
define('DB_USERS', PATH_DATABASES . 'users.php');
define('DB_SECURITY', PATH_DATABASES . 'security.php');
@ -92,6 +93,7 @@ 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 . 'kinds.class.php');
include(PATH_KERNEL . 'language.class.php');
include(PATH_KERNEL . 'site.class.php');
include(PATH_KERNEL . 'categories.class.php');
@ -132,6 +134,7 @@ $users = new Users();
$tags = new Tags();
$authors = new Authors();
$archives = new Archives();
$kinds = new Kinds();
$categories = new Categories();
$site = new Site();
$url = new Url();
@ -203,6 +206,9 @@ define('AUTHOR_URI_FILTER', $url->filters('author'));
// Archive URI filter
define('ARCHIVE_URI_FILTER', $url->filters('archive'));
// Post kind URI filter
define('KIND_URI_FILTER', $url->filters('kind'));
// Page URI filter
define('PAGE_URI_FILTER', $url->filters('page'));
@ -261,6 +267,7 @@ define('DOMAIN_CATEGORIES', Text::addSlashes(DOMAIN_BASE . CATEGORY_URI_FILTER,
define('DOMAIN_PAGES', Text::addSlashes(DOMAIN_BASE . PAGE_URI_FILTER, false, true));
define('DOMAIN_AUTHORS', Text::addSlashes(DOMAIN_BASE . AUTHOR_URI_FILTER, false, true));
define('DOMAIN_ARCHIVES', Text::addSlashes(DOMAIN_BASE . ARCHIVE_URI_FILTER, false, true));
define('DOMAIN_KINDS', Text::addSlashes(DOMAIN_BASE . KIND_URI_FILTER, false, true));
$ADMIN_CONTROLLER = '';
$ADMIN_VIEW = '';

View file

@ -75,10 +75,14 @@ elseif ($url->whereAmI()==='category') {
elseif ($url->whereAmI()==='author') {
$content = buildPagesByAuthor();
}
// Build content by author
// Build content by archive
elseif ($url->whereAmI()==='archive') {
$content = buildPagesByArchive();
}
// Build content by archive
elseif ($url->whereAmI()==='kind') {
$content = buildPagesByKind();
}
// Build content for the homepage
elseif ( ($url->whereAmI()==='home') || ($url->whereAmI()==='blog') ) {
$content = buildPagesForHome();

View file

@ -111,3 +111,22 @@ $GLOBALS['ALLOWED_IMG_EXTENSION'] = array('gif', 'png', 'jpg', 'jpeg', 'svg', 'w
// Allowed image mime types
$GLOBALS['ALLOWED_IMG_MIMETYPES'] = array('image/gif', 'image/png', 'image/jpeg', 'image/svg+xml', 'image/webp');
// Supported post kinds
$GLOBALS['POST_KINDS'] = array('article', 'note', 'photo', 'video', 'audio', 'reply', 'bookmark', 'like', 'art', 'literature', 'review', 'event', 'chicken');
$GLOBALS['POST_KINDS_EMOJI'] = array(
"article"=>'📄',
'note'=>'📔',
'photo'=>'📷',
'art'=>'🎨',
'event'=>'📅',
'video'=>'🎥',
'audio'=>'🎤',
'reply'=>'💬',
'bookmark'=>'🔖',
'like'=>'👍',
'review'=>'⭐️',
'chicken'=>'🐔',
'literature'=>'📕'
);

View file

@ -32,6 +32,14 @@ function reindexArchives()
return $archives->reindex();
}
// Re-index database of post kinds
// If you create/edit/remove a page is necessary regenerate the database of archives
function reindexKinds()
{
global $kinds;
return $kinds->reindex();
}
// Generate the page 404 Not found
function buildErrorPage()
{
@ -118,10 +126,20 @@ function buildPagesByArchive()
return buildPagesFor('archive', false, false, false, $archiveKey);
}
// This function is only used from the rule 69.pages.php, DO NOT use this function!
function buildPagesByKind()
{
global $url;
$kindKey = $url->slug();
return buildPagesFor('kind', false, false, false, false, $kindKey);
}
// 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, $authorKey = false, $archiveKey = false)
function buildPagesFor($for, $categoryKey = false, $tagKey = false, $authorKey = false, $archiveKey = false, $kindKey = false)
{
global $pages;
global $categories;
@ -130,6 +148,7 @@ function buildPagesFor($for, $categoryKey = false, $tagKey = false, $authorKey =
global $url;
global $authors;
global $archives;
global $kinds;
// Get the page number from URL
$pageNumber = $url->pageNumber();
@ -156,6 +175,9 @@ function buildPagesFor($for, $categoryKey = false, $tagKey = false, $authorKey =
} elseif ($for == 'archive') {
$numberOfItems = $site->itemsPerPage();
$list = $archives->getList($archiveKey, $pageNumber, $numberOfItems);
} elseif ($for == 'kind') {
$numberOfItems = $site->itemsPerPage();
$list = $kinds->getList($kindKey, $pageNumber, $numberOfItems);
}
// There are not items, invalid tag, invalid category, out of range, etc...
@ -385,6 +407,7 @@ function createPage($args)
reindexTags();
reindexAuthors();
reindexArchives();
reindexKinds();
// Add to syslog
$syslog->add(array(
@ -438,6 +461,7 @@ function editPage($args)
reindexTags();
reindexAuthors();
reindexArchives();
reindexKinds();
// Add to syslog
$syslog->add(array(
@ -465,6 +489,7 @@ function deletePage($key)
reindexTags();
reindexAuthors();
reindexArchives();
reindexKinds();
// Add to syslog
$syslog->add(array(

45
bl-kernel/kinds.class.php Normal file
View file

@ -0,0 +1,45 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
class Kinds extends dbList {
function __construct()
{
parent::__construct(DB_KINDS);
}
function numberOfPages($key)
{
return $this->countItems($key);
}
public function reindex()
{
global $pages;
global $L;
$kindArray = array();
foreach ($GLOBALS['POST_KINDS'] as $kind) {
$kindArray[$kind]['name'] = $GLOBALS['POST_KINDS_EMOJI'][$kind]." ".$L->g($kind);
$kindArray[$kind]['list'] = array();
}
$db = $pages->getDB($onlyKeys=false);
foreach ($db as $pageKey=>$pageFields) {
if ($pageFields['type'] == "published" && isset($pageFields['kind']) && $pageFields !== '') {
$kind = $pageFields['kind'];
// Index by years
if (isset($kindArray[$kind])) {
array_push($kindArray[$kind]['list'], $pageKey);
}
}
}
$this->db = $kindArray;
return $this->save();
}
}

View file

@ -10,6 +10,7 @@ class Pages extends dbJSON
'username' => '',
'tags' => array(),
'type' => 'published', // published, static, draft, sticky, scheduled, autosave
'kind'=>'',
'date' => '',
'dateModified' => '',
'position' => 0,
@ -22,6 +23,7 @@ class Pages extends dbJSON
'noindex' => false,
'nofollow' => false,
'noarchive' => false,
'sourceLink'=>'',
'custom' => array()
);

View file

@ -435,6 +435,17 @@ class Page
return $this->getValue('noarchive');
}
// retour the source link
public function sourceLink()
{
return $this->getValue('sourceLink');
}
public function kind()
{
return $this->getValue('kind');
}
// Returns the page slug
public function slug()
{

View file

@ -21,6 +21,7 @@ class Site extends dbJSON
'uriBlog' => '/blog/',
'uriAuthor' => '/author/',
'uriArchive' => '/archive/',
'uriKind' => '/kind/',
'url' => '',
'emailFrom' => '',
'dateFormat' => 'F j, Y',
@ -104,7 +105,8 @@ class Site extends dbJSON
$filters['tag'] = $this->getField('uriTag');
$filters['category'] = $this->getField('uriCategory');
$filters['author'] = $this->getField('uriAuthor');
$filters['archive'] = $this->getField(field: 'uriArchive');
$filters['archive'] = $this->getField('uriArchive');
$filters['kind'] = $this->getField('uriKind');
if ($this->getField('uriBlog')) {
$filters['blog'] = $this->getField('uriBlog');

View file

@ -258,6 +258,19 @@
"type": "Type",
"draft-content": "Draft content",
"post": "Post",
"article": "Article",
"note": "Note",
"photo": "Photo",
"video": "Video",
"audio": "Audio",
"reply": "Reply",
"bookmark": "Bookmark",
"like": "Like",
"art": "Art",
"literature": "Literature",
"review": "Review",
"event": "Event",
"chicken": "Chicken",
"default": "Default",
"latest-content": "Latest content",
"default-message": "Default message",

View file

@ -8,7 +8,7 @@
"Frédéric K. http:\/\/flatboard.free.fr",
"Clickwork https:\/\/clickwork.ch",
"Nicolas B.",
""
"Lake \"Kazhnuz\" M. https\/\/kazhnuz.space"
]
},
"dates": {
@ -263,6 +263,21 @@
"type": "Type",
"draft-content": "Contenu brouillon",
"post": "Article",
"article": "Article",
"note": "Note",
"photo": "Photo",
"video": "Vidéo",
"audio": "Audio",
"reply": "Réponse",
"bookmark": "Marque-Page",
"like": "Favori",
"art": "Art",
"literature": "Littérature",
"review": "Review",
"event": "Évenement",
"chicken": "Poulet",
"post-kind": "Type de contenu",
"post-kinds": "Types de contenu",
"default": "Défaut",
"latest-content": "Dernier contenu",
"default-message": "Message par défaut",
@ -407,5 +422,7 @@
"insert-thumbnail": "Insérer une miniature",
"insert-linked-thumbnail": "Insérer une miniature liée",
"more-infos": "Infos supplémentaires",
"base-infos": "Infos de bases"
"base-infos": "Infos de bases",
"source-link": "Lien source",
"the-external-link-you-refer-to-in-the-post":"Le lien externe auquel vous vous referrez dans le contenu"
}

View file

@ -156,6 +156,7 @@ EOF;
reindexTags();
reindexAuthors();
reindexArchives();
reindexKinds();
}
return true;