♻️ (content): separate sticky from type
This commit is contained in:
parent
a1456f1cc8
commit
6291f97a72
17 changed files with 102 additions and 71 deletions
|
@ -35,11 +35,11 @@ function filterContentOwner($list) {
|
|||
// Main after POST
|
||||
// ============================================================================
|
||||
|
||||
$published = $pages->getList($url->pageNumber(), ITEMS_PER_PAGE_ADMIN);
|
||||
$published = $pages->getList($url->pageNumber(), ITEMS_PER_PAGE_ADMIN, ['article'], ['published'], false, false);
|
||||
$drafts = $pages->getDraftDB(['article'], true);
|
||||
$scheduled = $pages->getScheduledDB(['article'],true);
|
||||
$static = $pages->getStaticDB(['published'],true);
|
||||
$sticky = $pages->getStickyDB(['published'],true);
|
||||
$sticky = $pages->getStickyDB(['article'],['published'],true);
|
||||
$autosave = $pages->getAutosaveDB(['article'],true);
|
||||
|
||||
// If the user is an Author filter the content he/she can edit
|
||||
|
|
|
@ -156,6 +156,16 @@ echo Bootstrap::formInputHidden(array(
|
|||
'rows' => 5,
|
||||
'placeholder' => $L->get('this-field-can-help-describe-the-content')
|
||||
));
|
||||
|
||||
// Sticky
|
||||
echo Bootstrap::formCheckbox(array(
|
||||
'name' => 'sticky',
|
||||
'label' => $L->g('Sticky'),
|
||||
'labelForCheckbox' => $L->g('Put this article in first position in the article list.'),
|
||||
'placeholder' => '',
|
||||
'checked' => $page->sticky(),
|
||||
'tip' => ""
|
||||
));
|
||||
?>
|
||||
|
||||
<!-- Cover Image -->
|
||||
|
@ -211,7 +221,6 @@ echo Bootstrap::formInputHidden(array(
|
|||
'selected' => $page->type(),
|
||||
'options' => array(
|
||||
'article' => '- ' . $L->g('Default') . ' -',
|
||||
'sticky' => $L->g('Sticky'),
|
||||
'static' => $L->g('Static')
|
||||
),
|
||||
'tip' => ''
|
||||
|
@ -488,9 +497,10 @@ foreach ($customFields as $field => $options) {
|
|||
$("#jsbuttonPreview").on("click", function() {
|
||||
var uuid = $("#jsuuid").val();
|
||||
var title = $("#jstitle").val();
|
||||
var type = $("#jstype").val();
|
||||
var content = editorGetContent();
|
||||
var ajax = new koblogAjax();
|
||||
koblogAjax.saveAsDraft(uuid, title, content).then(function(data) {
|
||||
koblogAjax.saveAsDraft(uuid, title, type, content).then(function(data) {
|
||||
var preview = window.open("<?php echo DOMAIN_PAGES . 'autosave-' . $page->uuid() . '?preview=' . md5('autosave-' . $page->uuid()) ?>", "koblog-preview");
|
||||
preview.focus();
|
||||
});
|
||||
|
@ -525,6 +535,7 @@ foreach ($customFields as $field => $options) {
|
|||
var uuid = $("#jsuuid").val();
|
||||
var title = $("#jstitle").val() + "[<?php $L->p('Autosave') ?>]";
|
||||
var content = editorGetContent();
|
||||
var type = $("#jstype").val();
|
||||
// Autosave when content has at least 100 characters
|
||||
if (content.length < 100) {
|
||||
return false;
|
||||
|
@ -532,7 +543,7 @@ foreach ($customFields as $field => $options) {
|
|||
// Autosave only when the user change the content
|
||||
if (currentContent != content) {
|
||||
currentContent = content;
|
||||
koblogAjax.saveAsDraft(uuid, title, content).then(function(data) {
|
||||
koblogAjax.saveAsDraft(uuid, title, type, content).then(function(data) {
|
||||
if (data.status == 0) {
|
||||
showAlert("<?php $L->p('Autosave') ?>");
|
||||
}
|
||||
|
|
|
@ -192,7 +192,6 @@ echo Bootstrap::formInputHidden(array(
|
|||
'selected' => '',
|
||||
'options' => array(
|
||||
'article' => '- ' . $L->g('Default') . ' -',
|
||||
'sticky' => $L->g('Sticky'),
|
||||
'static' => $L->g('Static')
|
||||
),
|
||||
'tip' => ''
|
||||
|
@ -443,8 +442,9 @@ foreach ($customFields as $field => $options) {
|
|||
$("#jsbuttonPreview").on("click", function() {
|
||||
var uuid = $("#jsuuid").val();
|
||||
var title = $("#jstitle").val();
|
||||
var type = $("#jstype").val();
|
||||
var content = editorGetContent();
|
||||
koblogAjax.saveAsDraft(uuid, title, content).then(function(data) {
|
||||
koblogAjax.saveAsDraft(uuid, title, type, content).then(function(data) {
|
||||
var preview = window.open("<?php echo DOMAIN_PAGES . 'autosave-' . $uuid . '?preview=' . md5('autosave-' . $uuid) ?>", "koblog-preview");
|
||||
preview.focus();
|
||||
});
|
||||
|
@ -486,6 +486,7 @@ foreach ($customFields as $field => $options) {
|
|||
setInterval(function() {
|
||||
var uuid = $("#jsuuid").val();
|
||||
var title = $("#jstitle").val() + "[<?php $L->p('Autosave') ?>]";
|
||||
var type = $("#jstype").val();
|
||||
var content = editorGetContent();
|
||||
// Autosave when content has at least 100 characters
|
||||
if (content.length < 100) {
|
||||
|
@ -494,7 +495,7 @@ foreach ($customFields as $field => $options) {
|
|||
// Autosave only when the user change the content
|
||||
if (currentContent != content) {
|
||||
currentContent = content;
|
||||
koblogAjax.saveAsDraft(uuid, title, content).then(function(data) {
|
||||
koblogAjax.saveAsDraft(uuid, title, type, content).then(function(data) {
|
||||
if (data.status == 0) {
|
||||
showAlert("<?php $L->p('Autosave') ?>");
|
||||
}
|
||||
|
|
|
@ -4,23 +4,18 @@ header('Content-Type: application/json');
|
|||
/*
|
||||
| Search for pages that have in the title the string $query and returns the array of pages
|
||||
|
|
||||
| @_GET['published'] boolean True to search in published database
|
||||
| @_GET['static'] boolean True to search in static database
|
||||
| @_GET['sticky'] boolean True to search in sticky database
|
||||
| @_GET['scheduled'] boolean True to search in scheduled database
|
||||
| @_GET['draft'] boolean True to search in draft database
|
||||
| @_GET['query'] string Text to search in the title
|
||||
| @_GET['type'] the type to search in the database
|
||||
| @_GET['state'] the state to search in the database
|
||||
| @_GET['sticky'] boolean False to not search sticky post
|
||||
|
|
||||
| @return array
|
||||
*/
|
||||
|
||||
// $_GET
|
||||
// ----------------------------------------------------------------------------
|
||||
$published = empty($_GET['published']) ? false:true;
|
||||
$static = empty($_GET['static']) ? false:true;
|
||||
$sticky = empty($_GET['sticky']) ? false:true;
|
||||
$scheduled = empty($_GET['scheduled']) ? false:true;
|
||||
$draft = empty($_GET['draft']) ? false:true;
|
||||
$type = empty($GET_['type']) ? ['article'] : explode(",", $GET_['type']);
|
||||
$state = empty($GET_['state']) ? ['published'] : explode(",", $GET_['state']);
|
||||
$sticky = isset($_GET['sticky']) ? $_GET['sticky'] != false:true; // True by default
|
||||
$query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false;
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
@ -30,7 +25,7 @@ if ($query===false) {
|
|||
|
||||
$pageNumber = 1;
|
||||
$numberOfItems = -1;
|
||||
$pagesKey = $pages->getList($pageNumber, $numberOfItems, $published, $static, $sticky, $draft, $scheduled);
|
||||
$pagesKey = $pages->getList($pageNumber, $numberOfItems, $type, $state, $sticky);
|
||||
$tmp = array();
|
||||
foreach ($pagesKey as $pageKey) {
|
||||
try {
|
||||
|
|
|
@ -28,7 +28,7 @@ foreach ($pagesKey as $pageKey) {
|
|||
$page = new Page($pageKey);
|
||||
if ($page->isParent() || !$checkIsParent) {
|
||||
// Check page status
|
||||
if ($page->article() || $page->sticky() || $page->isStatic()) {
|
||||
if ($page->published()) {
|
||||
// Check if the query contains in the title
|
||||
$lowerTitle = Text::lowercase($page->title());
|
||||
if (Text::stringContains($lowerTitle, $query)) {
|
||||
|
|
|
@ -18,7 +18,9 @@ header('Content-Type: application/json');
|
|||
$title = isset($_POST['title']) ? $_POST['title'] : false;
|
||||
$content = isset($_POST['content']) ? $_POST['content'] : false;
|
||||
$uuid = isset($_POST['uuid']) ? $_POST['uuid'] : false;
|
||||
$type = isset($_POST['type']) ? $_POST['type'] : 'draft';
|
||||
$type = isset($_POST['type']) ? $_POST['type'] : 'article';
|
||||
$type = isset($_POST['state']) ? $_POST['state'] : 'draft';
|
||||
$type = isset($_POST['sticky']) ? $_POST['state'] : false;
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Check UUID
|
||||
|
@ -32,7 +34,9 @@ $page = array(
|
|||
'slug'=>$uuid,
|
||||
'title'=>$title,
|
||||
'content'=>$content,
|
||||
'type'=>$type
|
||||
'type'=>$type,
|
||||
'state'=>$state,
|
||||
'sticky'=>$sticky,
|
||||
);
|
||||
|
||||
// Get the page key by the UUID
|
||||
|
|
|
@ -29,7 +29,6 @@ class Categories extends dbList {
|
|||
if (isset($this->db[$categoryKey]['list'])) {
|
||||
if (
|
||||
(($db[$pageKey]['type']=='article') ||
|
||||
($db[$pageKey]['type']=='sticky') ||
|
||||
($db[$pageKey]['type']=='static')) &&
|
||||
($db[$pageKey]['state']=='published')
|
||||
) {
|
||||
|
|
|
@ -135,15 +135,14 @@ function buildPagesFor($for, $categoryKey = false, $tagKey = false, $authorKey =
|
|||
$pageNumber = $url->pageNumber();
|
||||
|
||||
if ($for == 'home') {
|
||||
$onlyPublished = true;
|
||||
$numberOfItems = $site->itemsPerPage();
|
||||
$list = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
|
||||
$list = $pages->getList($pageNumber, $numberOfItems, ['article'], ['published'], true, true);
|
||||
|
||||
// Include sticky pages only in the first page
|
||||
if ($pageNumber == 1) {
|
||||
$sticky = $pages->getStickyDB();
|
||||
$list = array_merge($sticky, $list);
|
||||
}
|
||||
// if ($pageNumber == 1) {
|
||||
// $sticky = $pages->getStickyDB();
|
||||
// $list = array_merge($sticky, $list);
|
||||
// }
|
||||
} elseif ($for == 'category') {
|
||||
$numberOfItems = $site->itemsPerPage();
|
||||
$list = $categories->getList($categoryKey, $pageNumber, $numberOfItems);
|
||||
|
|
|
@ -19,12 +19,21 @@ class KoblogUpdater {
|
|||
} elseif ($fields['type'] === "scheduled") {
|
||||
$pages->db[$key]['type'] = "article";
|
||||
$pages->db[$key]['state'] = "scheduled";
|
||||
} elseif ($fields['type'] === "sticky") {
|
||||
$pages->db[$key]['type'] = "article";
|
||||
$pages->db[$key]['state'] = "published";
|
||||
$pages->db[$key]['sticky'] = true;
|
||||
}
|
||||
|
||||
// S'il n'y a toujours rien, c'est qu'il est publié
|
||||
if ($pages->db[$key]['state'] === null) {
|
||||
$pages->db[$key]['state'] = "published";
|
||||
}
|
||||
|
||||
// S'il n'y a toujours pas de sticky, c'est qu'il ne l'est pas
|
||||
if ($pages->db[$key]['sticky'] === null) {
|
||||
$pages->db[$key]['sticky'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $pages->save();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class koblogAjax {
|
||||
|
||||
static async saveAsDraft(uuid, title, content) {
|
||||
static async saveAsDraft(uuid, title, type, content) {
|
||||
let url = HTML_PATH_ADMIN_ROOT+"ajax/save-as-draft"
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
|
@ -14,7 +14,8 @@ class koblogAjax {
|
|||
'uuid': "autosave-" + uuid,
|
||||
'title': title,
|
||||
'content': content,
|
||||
'type': 'autosave'
|
||||
'type': type,
|
||||
'state': 'autosave'
|
||||
}),
|
||||
});
|
||||
const json = await response.json();
|
||||
|
|
|
@ -9,8 +9,9 @@ class Pages extends dbJSON
|
|||
'description' => '',
|
||||
'username' => '',
|
||||
'tags' => array(),
|
||||
'type' => 'article', // article, static, sticky
|
||||
'type' => 'article', // article, static
|
||||
'state' => 'published', // draft, scheduled, autosave
|
||||
'sticky' => false,
|
||||
'date' => '',
|
||||
'dateModified' => '',
|
||||
'position' => 0,
|
||||
|
@ -396,7 +397,7 @@ class Pages extends dbJSON
|
|||
return $tmp;
|
||||
}
|
||||
|
||||
public function getFilteredDB($types = [], $states = [], $onlyKeys)
|
||||
public function getFilteredDB($types = [], $states = [], $sticky = false, $onlyKeys)
|
||||
{
|
||||
$tmp = $this->db;
|
||||
foreach ($tmp as $key => $fields) {
|
||||
|
@ -406,6 +407,9 @@ class Pages extends dbJSON
|
|||
if (!empty($states) && !in_array($fields['state'], $states)) {
|
||||
unset($tmp[$key]);
|
||||
}
|
||||
if (!$sticky && $fields['sticky'] == true) {
|
||||
unset($tmp[$key]);
|
||||
}
|
||||
}
|
||||
if ($onlyKeys) {
|
||||
return array_keys($tmp);
|
||||
|
@ -418,32 +422,32 @@ class Pages extends dbJSON
|
|||
// $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);
|
||||
return $this->getFilteredDB($types, ['published'], true, $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);
|
||||
return $this->getFilteredDB($types, ['draft'], true, $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);
|
||||
return $this->getFilteredDB($types, ['autosave'], true, $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);
|
||||
return $this->getFilteredDB($types, ['scheduled'], true, $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($states = ['published'], $onlyKeys = true)
|
||||
{
|
||||
$tmp = $this->getFilteredDB(['static'], $states, false);
|
||||
$tmp = $this->getFilteredDB(['static'], $states, false, false);
|
||||
uasort($tmp, array($this, 'sortByPositionLowToHigh'));
|
||||
if ($onlyKeys) {
|
||||
return array_keys($tmp);
|
||||
|
@ -452,9 +456,18 @@ class Pages extends dbJSON
|
|||
}
|
||||
|
||||
// Returns an array with a list of keys of sticky pages
|
||||
public function getStickyDB($states = ['published'], $onlyKeys = true)
|
||||
public function getStickyDB($types = ['article'], $states = ['published'], $onlyKeys = true)
|
||||
{
|
||||
return $this->getFilteredDB(['sticky'], $states, $onlyKeys);
|
||||
$tmp = $this->getFilteredDB($types, $states, true, false);
|
||||
foreach ($tmp as $key => $fields) {
|
||||
if ($fields['sticky'] == false) {
|
||||
unset($tmp[$key]);
|
||||
}
|
||||
}
|
||||
if ($onlyKeys) {
|
||||
return array_keys($tmp);
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// Returns the next number of the bigger position
|
||||
|
@ -506,23 +519,16 @@ class Pages extends dbJSON
|
|||
// (int) $pageNumber, the page number
|
||||
// (int) $numberOfItems, amount of items to return, if -1 returns all the items
|
||||
// (boolean) $onlyPublished, TRUE to return only published pages
|
||||
public function getList($pageNumber, $numberOfItems, $published = true, $static = false, $sticky = false, $draft = false, $scheduled = false)
|
||||
public function getList($pageNumber, $numberOfItems, $types = ['article'], $states = ['published'], $sticky = true, $sortHomepage = false)
|
||||
{
|
||||
$list = array();
|
||||
foreach ($this->db as $key => $fields) {
|
||||
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['state'] == 'draft') {
|
||||
array_push($list, $key);
|
||||
} elseif ($scheduled && $fields['state'] == 'scheduled') {
|
||||
array_push($list, $key);
|
||||
}
|
||||
$tmp = $this->getFilteredDB($types, $states, $sticky, false);
|
||||
|
||||
if ($sortHomepage) {
|
||||
uasort($tmp, array($this, 'sortHomepage'));
|
||||
}
|
||||
|
||||
$list = array_keys($tmp);
|
||||
|
||||
if ($numberOfItems == -1) {
|
||||
return $list;
|
||||
}
|
||||
|
@ -640,6 +646,17 @@ class Pages extends dbJSON
|
|||
return $a['date'] < $b['date'];
|
||||
}
|
||||
|
||||
private function sortHomepage($a, $b)
|
||||
{
|
||||
if ($a['sticky'] && !$b['sticky']) {
|
||||
return false;
|
||||
} elseif (!$a['sticky'] && $b['sticky']) {
|
||||
return true;
|
||||
} else {
|
||||
return $this->sortByDateHighToLow($a, $b);
|
||||
}
|
||||
}
|
||||
|
||||
function generateUUID()
|
||||
{
|
||||
return md5(uniqid() . time());
|
||||
|
|
|
@ -390,7 +390,7 @@ class Page
|
|||
// (boolean) Returns TRUE if the page is sticky, FALSE otherwise
|
||||
public function sticky()
|
||||
{
|
||||
return ($this->getValue('type') == 'sticky');
|
||||
return ($this->getValue('sticky'));
|
||||
}
|
||||
|
||||
// (boolean) Returns TRUE if the page is static, FALSE otherwise
|
||||
|
|
|
@ -352,16 +352,14 @@ class pluginAPI extends Plugin
|
|||
global $pages;
|
||||
|
||||
// Parameters and the default values
|
||||
$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);
|
||||
$scheduled = (isset($args['scheduled']) ? $args['scheduled'] == 'true' : false);
|
||||
$types = (isset($args['type']) ? $args['type'] : ['article']);
|
||||
$state = (isset($args['state']) ? $args['state'] : ['published']);
|
||||
$sticky = (isset($args['sticky']) ? $args['sticky'] == 'true' : true);
|
||||
$untagged = (isset($args['untagged']) ? $args['untagged'] == 'true' : false);
|
||||
|
||||
$numberOfItems = (isset($args['numberOfItems']) ? $args['numberOfItems'] : 10);
|
||||
$pageNumber = (isset($args['pageNumber']) ? $args['pageNumber'] : 1);
|
||||
$list = $pages->getList($pageNumber, $numberOfItems, $published, $static, $sticky, $draft, $scheduled);
|
||||
$list = $pages->getList($pageNumber, $numberOfItems, $types, $state, $sticky);
|
||||
|
||||
$tmp = array(
|
||||
'status' => '0',
|
||||
|
|
|
@ -95,10 +95,9 @@ class pluginNavigation extends Plugin
|
|||
// Pages order by date
|
||||
else {
|
||||
// List of published pages
|
||||
$onlyPublished = true;
|
||||
$pageNumber = 1;
|
||||
$numberOfItems = $this->getValue('numberOfItems');
|
||||
$publishedPages = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
|
||||
$publishedPages = $pages->getList($pageNumber, $numberOfItems, ['article'], ['published']);
|
||||
|
||||
foreach ($publishedPages as $pageKey) {
|
||||
try {
|
||||
|
|
|
@ -50,11 +50,9 @@ class pluginRSS extends Plugin
|
|||
$list = $pages->getList(
|
||||
$pageNumber = 1,
|
||||
$numberOfItems,
|
||||
$published = true,
|
||||
$static = true,
|
||||
$sticky = true,
|
||||
$draft = false,
|
||||
$scheduled = false
|
||||
$type = ['article', 'static'],
|
||||
$state = ['published'],
|
||||
$sticky = true
|
||||
);
|
||||
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||
|
|
|
@ -187,7 +187,7 @@ EOF;
|
|||
{
|
||||
// Get all pages published
|
||||
global $pages;
|
||||
$list = $pages->getList($pageNumber = 1, $numberOfItems = -1, $published = true, $static = true, $sticky = true, $draft = false, $scheduled = false);
|
||||
$list = $pages->getList($pageNumber = 1, $numberOfItems = -1, $type = []);
|
||||
|
||||
$cache = array();
|
||||
foreach ($list as $pageKey) {
|
||||
|
|
|
@ -53,7 +53,7 @@ class pluginSitemap extends Plugin {
|
|||
$xml .= '<loc>'.$site->url().'</loc>';
|
||||
$xml .= '</url>';
|
||||
|
||||
$list = $pages->getList($pageNumber=1, $numberOfItems=-1, $published=true, $static=true, $sticky=true, $draft=false, $scheduled=false);
|
||||
$list = $pages->getList($pageNumber=1, $numberOfItems=-1, [], ['published'], true, false);
|
||||
foreach ($list as $pageKey) {
|
||||
try {
|
||||
// Create the page object from the page key
|
||||
|
|
Loading…
Reference in a new issue