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