♻️ 💥 (pages): use the "article" type instead of published

It makes more sense to use the type of page you have for the type, and it prepare published to be a state instead of a type
This commit is contained in:
Kazhnuz 2025-01-23 22:41:26 +01:00
parent c2ed24a7c7
commit e8cebf6c10
17 changed files with 81 additions and 25 deletions

View file

@ -21,7 +21,7 @@ echo Bootstrap::formInputHidden(array(
'value' => $page->uuid()
));
// Type = published, draft, sticky, static
// Type = article, draft, sticky, static
echo Bootstrap::formInputHidden(array(
'name' => 'type',
'value' => $page->type()
@ -210,7 +210,7 @@ echo Bootstrap::formInputHidden(array(
'label' => $L->g('Type'),
'selected' => $page->type(),
'options' => array(
'published' => '- ' . $L->g('Default') . ' -',
'article' => '- ' . $L->g('Default') . ' -',
'sticky' => $L->g('Sticky'),
'static' => $L->g('Static')
),

View file

@ -21,10 +21,10 @@ echo Bootstrap::formInputHidden(array(
'value' => $uuid
));
// Type = published, draft, sticky, static
// Type = article, draft, sticky, static
echo Bootstrap::formInputHidden(array(
'name' => 'type',
'value' => 'published'
'value' => 'article'
));
// Cover image
@ -191,7 +191,7 @@ echo Bootstrap::formInputHidden(array(
'label' => $L->g('Type'),
'selected' => '',
'options' => array(
'published' => '- ' . $L->g('Default') . ' -',
'article' => '- ' . $L->g('Default') . ' -',
'sticky' => $L->g('Sticky'),
'static' => $L->g('Static')
),

View file

@ -28,7 +28,7 @@ foreach ($pagesKey as $pageKey) {
$page = new Page($pageKey);
if ($page->isParent() || !$checkIsParent) {
// Check page status
if ($page->published() || $page->sticky() || $page->isStatic()) {
if ($page->article() || $page->sticky() || $page->isStatic()) {
// Check if the query contains in the title
$lowerTitle = Text::lowercase($page->title());
if (Text::stringContains($lowerTitle, $query)) {

View file

@ -57,6 +57,7 @@ if ($layout['slug']==='ajax') {
else
{
// Boot rules
include(PATH_RULES.'50.updaters.php');
include(PATH_RULES.'69.pages.php');
include(PATH_RULES.'99.header.php');
include(PATH_RULES.'99.paginator.php');

View file

@ -126,6 +126,9 @@ include(PATH_HELPERS . 'tcp.class.php');
include(PATH_HELPERS . 'dom.class.php');
include(PATH_HELPERS . 'cookie.class.php');
// Updaters
include(PATH_HELPERS . 'updater.class.php');
// Objects
$pages = new Pages();
$users = new Users();

View file

@ -0,0 +1,15 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
// ============================================================================
// Variables
// ============================================================================
global $site;
// ============================================================================
// Main
// ============================================================================
if ($site->databaseVersion() < 2) {
KoblogUpdater::upgradeArticlesToPageTypes();
}

View file

@ -7,6 +7,7 @@ include(PATH_RULES.'60.plugins.php');
Theme::plugins('beforeAll');
// Load rules
include(PATH_RULES.'50.updaters.php');
include(PATH_RULES.'60.router.php');
include(PATH_RULES.'69.pages.php');
include(PATH_RULES.'99.header.php');

View file

@ -104,7 +104,7 @@ define('MEDIA_MANAGER_SORT_BY_DATE', true);
// Constant arrays using define are not allowed in PHP 5.6 or earlier
// Type of pages included in the tag database
$GLOBALS['DB_TAGS_TYPES'] = array('published','static','sticky');
$GLOBALS['DB_TAGS_TYPES'] = array('article','static','sticky');
// Allowed image extensions
$GLOBALS['ALLOWED_IMG_EXTENSION'] = array('gif', 'png', 'jpg', 'jpeg', 'svg', 'webp');

View file

@ -28,7 +28,7 @@ class Categories extends dbList {
$categoryKey = $pageFields['category'];
if (isset($this->db[$categoryKey]['list'])) {
if (
($db[$pageKey]['type']=='published') ||
($db[$pageKey]['type']=='article') ||
($db[$pageKey]['type']=='sticky') ||
($db[$pageKey]['type']=='static')
) {

View file

@ -168,7 +168,7 @@ function buildPagesFor($for, $categoryKey = false, $tagKey = false, $authorKey =
foreach ($list as $pageKey) {
try {
$page = new Page($pageKey);
if (($page->type() == 'published') ||
if (($page->type() == 'article') ||
($page->type() == 'sticky') ||
($page->type() == 'static')
) {

View file

@ -0,0 +1,20 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
class KoblogUpdater {
// Special function to upgrade
public static function upgradeArticlesToPageTypes()
{
global $pages;
foreach ($pages->db as $key => $fields) {
if ($fields['type'] === "published") {
$pages->db[$key]['type'] = "article";
} else {
//$pages->db[$key]['sticky'] = false; // Not really important for static
}
}
return $pages->save();
}
}

View file

@ -9,7 +9,7 @@ class Pages extends dbJSON
'description' => '',
'username' => '',
'tags' => array(),
'type' => 'published', // published, static, draft, sticky, scheduled, autosave
'type' => 'article', // article, static, draft, sticky, scheduled, autosave
'date' => '',
'dateModified' => '',
'position' => 0,
@ -129,7 +129,7 @@ class Pages extends dbJSON
}
// Schedule page
if (($row['date'] > Date::current(DB_DATE_FORMAT)) && ($row['type'] == 'published')) {
if (($row['date'] > Date::current(DB_DATE_FORMAT)) && ($row['type'] == 'article')) {
$row['type'] = 'scheduled';
}
@ -244,7 +244,8 @@ class Pages extends dbJSON
$row['dateModified'] = Date::current(DB_DATE_FORMAT);
// Schedule page
if (($row['date'] > Date::current(DB_DATE_FORMAT)) && ($row['type'] == 'published')) {
// TODO: will use the state then
if (($row['date'] > Date::current(DB_DATE_FORMAT)) && ($row['type'] == 'article')) {
$row['type'] = 'scheduled';
}
@ -395,14 +396,14 @@ class Pages extends dbJSON
return $tmp;
}
// Returns a database with published pages
// Returns a database with published articles
// $onlyKeys = true; Returns only the pages keys
// $onlyKeys = false; Returns part of the database, I do not recommend use this
public function getPublishedDB($onlyKeys = true)
{
$tmp = $this->db;
foreach ($tmp as $key => $fields) {
if ($fields['type'] != 'published') {
if ($fields['type'] != 'article') {
unset($tmp[$key]);
}
}
@ -504,12 +505,13 @@ class Pages extends dbJSON
// Returns the next page key of the current page key
public function nextPageKey($currentKey)
{
if ($this->db[$currentKey]['type'] == 'published') {
if ($this->db[$currentKey]['type'] == 'article') {
$keys = array_keys($this->db);
$position = array_search($currentKey, $keys) - 1;
if (isset($keys[$position])) {
$nextKey = $keys[$position];
if ($this->db[$nextKey]['type'] == 'published') {
// TODO: make it check pages from the same type instead
if ($this->db[$nextKey]['type'] == 'article') {
return $nextKey;
}
}
@ -520,12 +522,13 @@ class Pages extends dbJSON
// Returns the previous page key of the current page key
public function previousPageKey($currentKey)
{
if ($this->db[$currentKey]['type'] == 'published') {
if ($this->db[$currentKey]['type'] == 'article') {
$keys = array_keys($this->db);
$position = array_search($currentKey, $keys) + 1;
if (isset($keys[$position])) {
$prevKey = $keys[$position];
if ($this->db[$prevKey]['type'] == 'published') {
// TODO: make it check pages from the same type instead
if ($this->db[$prevKey]['type'] == 'article') {
return $prevKey;
}
}
@ -542,7 +545,7 @@ class Pages extends dbJSON
{
$list = array();
foreach ($this->db as $key => $fields) {
if ($published && $fields['type'] == 'published') {
if ($published && $fields['type'] == 'article') {
array_push($list, $key);
} elseif ($static && $fields['type'] == 'static') {
array_push($list, $key);
@ -719,10 +722,10 @@ class Pages extends dbJSON
foreach ($this->db as $pageKey => $fields) {
if ($fields['type'] == 'scheduled') {
if ($fields['date'] <= $currentDate) {
$this->db[$pageKey]['type'] = 'published';
$this->db[$pageKey]['type'] = 'article';
$saveDatabase = true;
}
} elseif (($fields['type'] == 'published') && (ORDER_BY == 'date')) {
} elseif (($fields['type'] == 'article') && (ORDER_BY == 'date')) {
break;
}
}

View file

@ -360,7 +360,14 @@ class Page
// (boolean) Returns TRUE if the page is published, FALSE otherwise
public function published()
{
return ($this->getValue('type') === 'published');
// TODO: will use then the state
return ($this->getValue('type') === 'article');
}
// (boolean) Returns TRUE if the page is an article, FALSE otherwise
public function article()
{
return ($this->getValue('type') === 'article');
}
// (boolean) Returns TRUE if the page is scheduled, FALSE otherwise

View file

@ -477,4 +477,10 @@ class Site extends dbJSON
$customFields = Sanitize::htmlDecode($this->getField('customFields'));
return json_decode($customFields, true);
}
// Returns the custom fields as array
public function databaseVersion()
{
return 1;
}
}

View file

@ -352,7 +352,7 @@ class pluginAPI extends Plugin
global $pages;
// Parameters and the default values
$published = (isset($args['published']) ? $args['published'] == 'true' : true);
$published = (isset($args['article']) ? $args['article'] == 'true' : true);
$static = (isset($args['static']) ? $args['static'] == 'true' : false);
$draft = (isset($args['draft']) ? $args['draft'] == 'true' : false);
$sticky = (isset($args['sticky']) ? $args['sticky'] == 'true' : false);

View file

@ -62,7 +62,7 @@ class pluginDisqus extends Plugin
if ($WHERE_AM_I === 'page') {
global $page;
if ($page->published() && $this->getValue('enablePages')) {
if ($page->article() && $this->getValue('enablePages')) {
return $this->javascript();
}
if ($page->isStatic() && $this->getValue('enableStatic')) {

View file

@ -334,7 +334,7 @@ function install($adminPassword, $timezone)
'description' => '',
'username' => 'admin',
'tags' => array(),
'type' => (($slug == 'example-page-4-slug') ? 'static' : 'published'),
'type' => (($slug == 'example-page-4-slug') ? 'static' : 'article'),
'date' => $nextDate,
'dateModified' => '',
'allowComments' => true,