♻️ (pages): separate type and state
This commit is contained in:
parent
23de39ece8
commit
a1456f1cc8
10 changed files with 96 additions and 113 deletions
|
@ -36,11 +36,11 @@ function filterContentOwner($list) {
|
|||
// ============================================================================
|
||||
|
||||
$published = $pages->getList($url->pageNumber(), ITEMS_PER_PAGE_ADMIN);
|
||||
$drafts = $pages->getDraftDB(true);
|
||||
$scheduled = $pages->getScheduledDB(true);
|
||||
$static = $pages->getStaticDB(true);
|
||||
$sticky = $pages->getStickyDB(true);
|
||||
$autosave = $pages->getAutosaveDB(true);
|
||||
$drafts = $pages->getDraftDB(['article'], true);
|
||||
$scheduled = $pages->getScheduledDB(['article'],true);
|
||||
$static = $pages->getStaticDB(['published'],true);
|
||||
$sticky = $pages->getStickyDB(['published'],true);
|
||||
$autosave = $pages->getAutosaveDB(['article'],true);
|
||||
|
||||
// If the user is an Author filter the content he/she can edit
|
||||
if (checkRole(array('author'), false)) {
|
||||
|
|
|
@ -38,7 +38,7 @@ if (checkRole(array('author'), false)) {
|
|||
// ============================================================================
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
if ($_POST['type']==='delete') {
|
||||
if ($_POST['state']==='delete') {
|
||||
if (deletePage($_POST['key'])) {
|
||||
Alert::set( $L->g('The changes have been saved') );
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ echo Bootstrap::formInputHidden(array(
|
|||
|
||||
// Type = article, draft, sticky, static
|
||||
echo Bootstrap::formInputHidden(array(
|
||||
'name' => 'type',
|
||||
'value' => $page->type()
|
||||
'name' => 'state',
|
||||
'value' => $page->state()
|
||||
));
|
||||
|
||||
// Cover image
|
||||
|
@ -206,7 +206,7 @@ echo Bootstrap::formInputHidden(array(
|
|||
|
||||
// Type
|
||||
echo Bootstrap::formSelectBlock(array(
|
||||
'name' => 'typeSelector',
|
||||
'name' => 'type',
|
||||
'label' => $L->g('Type'),
|
||||
'selected' => $page->type(),
|
||||
'options' => array(
|
||||
|
@ -450,7 +450,7 @@ foreach ($customFields as $field => $options) {
|
|||
<script>
|
||||
$(document).ready(function() {
|
||||
$("#jsbuttonDeleteAccept").on("click", function() {
|
||||
$("#jstype").val("delete");
|
||||
$("#jsstate").val("delete");
|
||||
$("#jscontent").val("");
|
||||
$("#jsform").submit();
|
||||
});
|
||||
|
@ -498,8 +498,7 @@ foreach ($customFields as $field => $options) {
|
|||
|
||||
// Button Save
|
||||
$("#jsbuttonSave").on("click", function() {
|
||||
var value = $("#jstypeSelector option:selected").val();
|
||||
$("#jstype").val(value);
|
||||
$("#jsstate").val("published");
|
||||
|
||||
// Get the content
|
||||
$("#jscontent").val(editorGetContent());
|
||||
|
@ -511,7 +510,7 @@ foreach ($customFields as $field => $options) {
|
|||
// Button Save as draft
|
||||
$("#jsbuttonDraft").on("click", function() {
|
||||
// Set the type as draft
|
||||
$("#jstype").val("draft");
|
||||
$("#jsstate").val("draft");
|
||||
|
||||
// Get the content
|
||||
$("#jscontent").val(editorGetContent());
|
||||
|
|
|
@ -23,8 +23,8 @@ echo Bootstrap::formInputHidden(array(
|
|||
|
||||
// Type = article, draft, sticky, static
|
||||
echo Bootstrap::formInputHidden(array(
|
||||
'name' => 'type',
|
||||
'value' => 'article'
|
||||
'name' => 'state',
|
||||
'value' => 'published'
|
||||
));
|
||||
|
||||
// Cover image
|
||||
|
@ -187,7 +187,7 @@ echo Bootstrap::formInputHidden(array(
|
|||
|
||||
// Type
|
||||
echo Bootstrap::formSelectBlock(array(
|
||||
'name' => 'typeSelector',
|
||||
'name' => 'type',
|
||||
'label' => $L->g('Type'),
|
||||
'selected' => '',
|
||||
'options' => array(
|
||||
|
@ -454,8 +454,8 @@ foreach ($customFields as $field => $options) {
|
|||
$("#jsbuttonSave").on("click", function() {
|
||||
let actionParameters = '';
|
||||
|
||||
var value = $("#jstypeSelector option:selected").val();
|
||||
$("#jstype").val(value);
|
||||
var value = "published"
|
||||
$("#jsstate").val(value);
|
||||
actionParameters = '#' + value;
|
||||
|
||||
// Get the content
|
||||
|
@ -470,7 +470,7 @@ foreach ($customFields as $field => $options) {
|
|||
$("#jsbuttonDraft").on("click", function() {
|
||||
let actionParameters = '';
|
||||
|
||||
$("#jstype").val("draft");
|
||||
$("#jsstate").val("draft");
|
||||
actionParameters = '#draft';
|
||||
|
||||
// Get the content
|
||||
|
|
|
@ -18,7 +18,7 @@ class Archives extends dbList {
|
|||
$db = $pages->getDB($onlyKeys=false);
|
||||
$archiveIndex = array();
|
||||
foreach ($db as $pageKey=>$pageFields) {
|
||||
if (in_array($pageFields['type'], $GLOBALS['DB_TAGS_TYPES'])) {
|
||||
if (in_array($pageFields['type'], $GLOBALS['DB_TAGS_TYPES']) && $pageFields['state'] == "published") {
|
||||
$date = $pageFields['date'];
|
||||
$year = mb_substr($date, 0, 4);
|
||||
$month = mb_substr($date, 0, 7);
|
||||
|
|
|
@ -18,7 +18,7 @@ class Authors extends dbList {
|
|||
$db = $pages->getDB($onlyKeys=false);
|
||||
$authorsIndex = array();
|
||||
foreach ($db as $pageKey=>$pageFields) {
|
||||
if (in_array($pageFields['type'], $GLOBALS['DB_TAGS_TYPES'])) {
|
||||
if (in_array($pageFields['type'], $GLOBALS['DB_TAGS_TYPES']) && $pageFields['state'] == "published") {
|
||||
$authorName = $pageFields['username'];
|
||||
if (isset($authorsIndex[$authorName])) {
|
||||
array_push($authorsIndex[$authorName]['list'], $pageKey);
|
||||
|
|
|
@ -28,9 +28,10 @@ class Categories extends dbList {
|
|||
$categoryKey = $pageFields['category'];
|
||||
if (isset($this->db[$categoryKey]['list'])) {
|
||||
if (
|
||||
($db[$pageKey]['type']=='article') ||
|
||||
(($db[$pageKey]['type']=='article') ||
|
||||
($db[$pageKey]['type']=='sticky') ||
|
||||
($db[$pageKey]['type']=='static')
|
||||
($db[$pageKey]['type']=='static')) &&
|
||||
($db[$pageKey]['state']=='published')
|
||||
) {
|
||||
array_push($this->db[$categoryKey]['list'], $pageKey);
|
||||
}
|
||||
|
|
|
@ -9,8 +9,21 @@ class KoblogUpdater {
|
|||
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
|
||||
$pages->db[$key]['state'] = "published";
|
||||
} elseif ($fields['type'] === "draft") {
|
||||
$pages->db[$key]['type'] = "article";
|
||||
$pages->db[$key]['state'] = "draft";
|
||||
} elseif ($fields['type'] === "autosave") {
|
||||
$pages->db[$key]['type'] = "article";
|
||||
$pages->db[$key]['state'] = "autosave";
|
||||
} elseif ($fields['type'] === "scheduled") {
|
||||
$pages->db[$key]['type'] = "article";
|
||||
$pages->db[$key]['state'] = "scheduled";
|
||||
}
|
||||
|
||||
// S'il n'y a toujours rien, c'est qu'il est publié
|
||||
if ($pages->db[$key]['state'] === null) {
|
||||
$pages->db[$key]['state'] = "published";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ class Pages extends dbJSON
|
|||
'description' => '',
|
||||
'username' => '',
|
||||
'tags' => array(),
|
||||
'type' => 'article', // article, static, draft, sticky, scheduled, autosave
|
||||
'type' => 'article', // article, static, sticky
|
||||
'state' => 'published', // draft, scheduled, autosave
|
||||
'date' => '',
|
||||
'dateModified' => '',
|
||||
'position' => 0,
|
||||
|
@ -129,8 +130,8 @@ class Pages extends dbJSON
|
|||
}
|
||||
|
||||
// Schedule page
|
||||
if (($row['date'] > Date::current(DB_DATE_FORMAT)) && ($row['type'] == 'article')) {
|
||||
$row['type'] = 'scheduled';
|
||||
if (($row['date'] > Date::current(DB_DATE_FORMAT)) && ($row['state'] == 'published')) {
|
||||
$row['state'] = 'scheduled';
|
||||
}
|
||||
|
||||
// Create the directory
|
||||
|
@ -244,9 +245,8 @@ class Pages extends dbJSON
|
|||
$row['dateModified'] = Date::current(DB_DATE_FORMAT);
|
||||
|
||||
// Schedule page
|
||||
// TODO: will use the state then
|
||||
if (($row['date'] > Date::current(DB_DATE_FORMAT)) && ($row['type'] == 'article')) {
|
||||
$row['type'] = 'scheduled';
|
||||
$row['state'] = 'scheduled';
|
||||
}
|
||||
|
||||
// Move the directory from old key to new key only if the keys are different
|
||||
|
@ -396,14 +396,14 @@ class Pages extends dbJSON
|
|||
return $tmp;
|
||||
}
|
||||
|
||||
// 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)
|
||||
public function getFilteredDB($types = [], $states = [], $onlyKeys)
|
||||
{
|
||||
$tmp = $this->db;
|
||||
foreach ($tmp as $key => $fields) {
|
||||
if ($fields['type'] != 'article') {
|
||||
if (!empty($types) && !in_array($fields['type'], $types)) {
|
||||
unset($tmp[$key]);
|
||||
}
|
||||
if (!empty($states) && !in_array($fields['state'], $states)) {
|
||||
unset($tmp[$key]);
|
||||
}
|
||||
}
|
||||
|
@ -413,16 +413,37 @@ class Pages extends dbJSON
|
|||
return $tmp;
|
||||
}
|
||||
|
||||
// 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($types = ['article'], $onlyKeys = true)
|
||||
{
|
||||
return $this->getFilteredDB($types, ['published'], $onlyKeys);
|
||||
}
|
||||
|
||||
// Returns an array with a list of keys/database of draft pages
|
||||
public function getDraftDB($types = ['article'], $onlyKeys = true)
|
||||
{
|
||||
return $this->getFilteredDB($types, ['draft'], $onlyKeys);
|
||||
}
|
||||
|
||||
// Returns an array with a list of keys/database of autosave pages
|
||||
public function getAutosaveDB($types = ['article'], $onlyKeys = true)
|
||||
{
|
||||
return $this->getFilteredDB($types, ['autosave'], $onlyKeys);
|
||||
}
|
||||
|
||||
// Returns an array with a list of keys/database of scheduled pages
|
||||
public function getScheduledDB($types = ['article'], $onlyKeys = true)
|
||||
{
|
||||
return $this->getFilteredDB($types, ['scheduled'], $onlyKeys);
|
||||
}
|
||||
|
||||
// Returns an array with a list of keys/database of static pages
|
||||
// By default the static pages are sort by position
|
||||
public function getStaticDB($onlyKeys = true)
|
||||
public function getStaticDB($states = ['published'], $onlyKeys = true)
|
||||
{
|
||||
$tmp = $this->db;
|
||||
foreach ($tmp as $key => $fields) {
|
||||
if ($fields['type'] != 'static') {
|
||||
unset($tmp[$key]);
|
||||
}
|
||||
}
|
||||
$tmp = $this->getFilteredDB(['static'], $states, false);
|
||||
uasort($tmp, array($this, 'sortByPositionLowToHigh'));
|
||||
if ($onlyKeys) {
|
||||
return array_keys($tmp);
|
||||
|
@ -430,64 +451,10 @@ class Pages extends dbJSON
|
|||
return $tmp;
|
||||
}
|
||||
|
||||
// Returns an array with a list of keys/database of draft pages
|
||||
public function getDraftDB($onlyKeys = true)
|
||||
{
|
||||
$tmp = $this->db;
|
||||
foreach ($tmp as $key => $fields) {
|
||||
if ($fields['type'] != 'draft') {
|
||||
unset($tmp[$key]);
|
||||
}
|
||||
}
|
||||
if ($onlyKeys) {
|
||||
return array_keys($tmp);
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// Returns an array with a list of keys/database of autosave pages
|
||||
public function getAutosaveDB($onlyKeys = true)
|
||||
{
|
||||
$tmp = $this->db;
|
||||
foreach ($tmp as $key => $fields) {
|
||||
if ($fields['type'] != 'autosave') {
|
||||
unset($tmp[$key]);
|
||||
}
|
||||
}
|
||||
if ($onlyKeys) {
|
||||
return array_keys($tmp);
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// Returns an array with a list of keys/database of scheduled pages
|
||||
public function getScheduledDB($onlyKeys = true)
|
||||
{
|
||||
$tmp = $this->db;
|
||||
foreach ($tmp as $key => $fields) {
|
||||
if ($fields['type'] != 'scheduled') {
|
||||
unset($tmp[$key]);
|
||||
}
|
||||
}
|
||||
if ($onlyKeys) {
|
||||
return array_keys($tmp);
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// Returns an array with a list of keys of sticky pages
|
||||
public function getStickyDB($onlyKeys = true)
|
||||
public function getStickyDB($states = ['published'], $onlyKeys = true)
|
||||
{
|
||||
$tmp = $this->db;
|
||||
foreach ($tmp as $key => $fields) {
|
||||
if ($fields['type'] != 'sticky') {
|
||||
unset($tmp[$key]);
|
||||
}
|
||||
}
|
||||
if ($onlyKeys) {
|
||||
return array_keys($tmp);
|
||||
}
|
||||
return $tmp;
|
||||
return $this->getFilteredDB(['sticky'], $states, $onlyKeys);
|
||||
}
|
||||
|
||||
// Returns the next number of the bigger position
|
||||
|
@ -505,13 +472,12 @@ class Pages extends dbJSON
|
|||
// Returns the next page key of the current page key
|
||||
public function nextPageKey($currentKey)
|
||||
{
|
||||
if ($this->db[$currentKey]['type'] == 'article') {
|
||||
if ($this->db[$currentKey]['state'] == 'published') {
|
||||
$keys = array_keys($this->db);
|
||||
$position = array_search($currentKey, $keys) - 1;
|
||||
if (isset($keys[$position])) {
|
||||
$nextKey = $keys[$position];
|
||||
// TODO: make it check pages from the same type instead
|
||||
if ($this->db[$nextKey]['type'] == 'article') {
|
||||
if ($this->db[$nextKey]['type'] == $this->db[$currentKey]['type']) {
|
||||
return $nextKey;
|
||||
}
|
||||
}
|
||||
|
@ -522,13 +488,12 @@ class Pages extends dbJSON
|
|||
// Returns the previous page key of the current page key
|
||||
public function previousPageKey($currentKey)
|
||||
{
|
||||
if ($this->db[$currentKey]['type'] == 'article') {
|
||||
if ($this->db[$currentKey]['state'] == 'published') {
|
||||
$keys = array_keys($this->db);
|
||||
$position = array_search($currentKey, $keys) + 1;
|
||||
if (isset($keys[$position])) {
|
||||
$prevKey = $keys[$position];
|
||||
// TODO: make it check pages from the same type instead
|
||||
if ($this->db[$prevKey]['type'] == 'article') {
|
||||
if ($this->db[$prevKey]['type'] == $this->db[$currentKey]['type']) {
|
||||
return $prevKey;
|
||||
}
|
||||
}
|
||||
|
@ -545,15 +510,15 @@ class Pages extends dbJSON
|
|||
{
|
||||
$list = array();
|
||||
foreach ($this->db as $key => $fields) {
|
||||
if ($published && $fields['type'] == 'article') {
|
||||
if ($published && $fields['type'] == 'article' && $fields['state'] == 'published') {
|
||||
array_push($list, $key);
|
||||
} elseif ($static && $fields['type'] == 'static') {
|
||||
array_push($list, $key);
|
||||
} elseif ($sticky && $fields['type'] == 'sticky') {
|
||||
array_push($list, $key);
|
||||
} elseif ($draft && $fields['type'] == 'draft') {
|
||||
} elseif ($draft && $fields['state'] == 'draft') {
|
||||
array_push($list, $key);
|
||||
} elseif ($scheduled && $fields['type'] == 'scheduled') {
|
||||
} elseif ($scheduled && $fields['state'] == 'scheduled') {
|
||||
array_push($list, $key);
|
||||
}
|
||||
}
|
||||
|
@ -582,7 +547,7 @@ class Pages extends dbJSON
|
|||
public function count($onlyPublished = true)
|
||||
{
|
||||
if ($onlyPublished) {
|
||||
$db = $this->getPublishedDB(false);
|
||||
$db = $this->getPublishedDB(['article'], false);
|
||||
return count($db);
|
||||
}
|
||||
|
||||
|
|
|
@ -360,8 +360,7 @@ class Page
|
|||
// (boolean) Returns TRUE if the page is published, FALSE otherwise
|
||||
public function published()
|
||||
{
|
||||
// TODO: will use then the state
|
||||
return ($this->getValue('type') === 'article');
|
||||
return ($this->getValue('state') === 'published');
|
||||
}
|
||||
|
||||
// (boolean) Returns TRUE if the page is an article, FALSE otherwise
|
||||
|
@ -373,19 +372,19 @@ class Page
|
|||
// (boolean) Returns TRUE if the page is scheduled, FALSE otherwise
|
||||
public function scheduled()
|
||||
{
|
||||
return ($this->getValue('type') === 'scheduled');
|
||||
return ($this->getValue('state') === 'scheduled');
|
||||
}
|
||||
|
||||
// (boolean) Returns TRUE if the page is draft, FALSE otherwise
|
||||
public function draft()
|
||||
{
|
||||
return ($this->getValue('type') == 'draft');
|
||||
return ($this->getValue('state') == 'draft');
|
||||
}
|
||||
|
||||
// (boolean) Returns TRUE if the page is autosave, FALSE otherwise
|
||||
public function autosave()
|
||||
{
|
||||
return ($this->getValue('type') == 'autosave');
|
||||
return ($this->getValue('state') == 'autosave');
|
||||
}
|
||||
|
||||
// (boolean) Returns TRUE if the page is sticky, FALSE otherwise
|
||||
|
@ -406,6 +405,12 @@ class Page
|
|||
return $this->getValue('type');
|
||||
}
|
||||
|
||||
// (string) Returns state of the page
|
||||
public function state()
|
||||
{
|
||||
return $this->getValue('state');
|
||||
}
|
||||
|
||||
// Returns the title field
|
||||
public function title()
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue