This commit is contained in:
Diego Najar 2017-10-22 14:36:16 +02:00
parent 4ccd4ae24d
commit 047afee2e8
5 changed files with 48 additions and 27 deletions

View File

@ -29,11 +29,11 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// ============================================================================
// Main after POST
// ============================================================================
$allPublishedPages = buildAllpages(true);
$allPages = buildAllpages($publishedPages=true, $staticPages=true, $draftPages=false, $scheduledPages=false);
// Homepage select options
$homepageOptions = array(' '=>'- '.$L->g('Latest content').' -');
foreach($allPublishedPages as $key=>$page) {
foreach ($allPages as $key=>$page) {
$parentKey = $page->parentKey();
if ($parentKey) {
$homepageOptions[$key] = $pagesByParentByKey[PARENT][$parentKey]->title() .'->'. $page->title();

View File

@ -162,7 +162,7 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
// Parent input
// Check if the page has children
if(count($page->children())==0) {
if (count($page->children())==0) {
$options = array(' '=>'- '.$L->g('No parent').' -');
$parentsList = $dbPages->getParents();
$parentsKey = array_keys($parentsList);
@ -180,9 +180,9 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
'selected'=>$page->parentKey(),
'tip'=>''
));
}
echo '<hr>';
echo '<hr>';
}
// Position input
HTML::formInputText(array(

View File

@ -100,7 +100,7 @@ if ($dbPages->scheduler()) {
}
// Generate pages parent tree, only published pages
buildPagesByParent(true);
buildPagesByParent(true, true);
// Set home page is the user defined one
if ($Site->homepage() && $Url->whereAmI()==='home') {

View File

@ -264,7 +264,7 @@ class dbPages extends dbJSON
}
// Returns a database with published pages
public function getPublishedDB()
public function getPublishedDB($onlyKeys=false)
{
$tmp = $this->db;
foreach ($tmp as $key=>$fields) {
@ -272,6 +272,9 @@ class dbPages extends dbJSON
unset($tmp[$key]);
}
}
if ($onlyKeys) {
return array_keys($tmp);
}
return $tmp;
}
@ -293,7 +296,7 @@ class dbPages extends dbJSON
}
// Returns an array with a list of keys/database of draft pages
public function getDraftDB()
public function getDraftDB($onlyKeys=false)
{
$tmp = $this->db;
foreach ($tmp as $key=>$fields) {
@ -301,11 +304,14 @@ class dbPages extends dbJSON
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()
public function getScheduledDB($onlyKeys=false)
{
$tmp = $this->db;
foreach($tmp as $key=>$fields) {
@ -313,6 +319,9 @@ class dbPages extends dbJSON
unset($tmp[$key]);
}
}
if ($onlyKeys) {
return array_keys($tmp);
}
return $tmp;
}

View File

@ -168,28 +168,30 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
// Generate the global variable $pagesByParent, defined on 69.pages.php
// (boolean) $allPages, TRUE include all status, FALSE only include published status
function buildPagesByParent($onlyPublished=true) {
function buildPagesByParent($publishedPages=true, $staticPages=true) {
global $dbPages;
global $pagesByParent;
global $pagesByParentByKey;
// Get DB
$pageNumber = 1;
$amountOfItems = -1;
$db = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
$onlyKeys = true;
$keys = array();
if ($publishedPages) {
$keys = array_merge($keys, $dbPages->getPublishedDB($onlyKeys));
}
if ($staticPages) {
$keys = array_merge($keys, $dbPages->getStaticDB($onlyKeys));
}
// Get Keys
$keys = array_keys($db);
foreach($keys as $pageKey) {
foreach ($keys as $pageKey) {
$page = buildPage($pageKey);
if($page!==false) {
if ($page!==false) {
$parentKey = $page->parentKey();
// FALSE if the page is parent
if($parentKey===false) {
if ($parentKey===false) {
array_push($pagesByParent[PARENT], $page);
$pagesByParentByKey[PARENT][$page->key()] = $page;
} else {
if( !isset($pagesByParent[$parentKey]) ) {
if (!isset($pagesByParent[$parentKey])) {
$pagesByParent[$parentKey] = array();
}
array_push($pagesByParent[$parentKey], $page);
@ -221,19 +223,29 @@ function buildStaticPages() {
pageKeyN => Page object,
)
*/
function buildAllpages($onlyPublished=true) {
function buildAllpages($publishedPages=true, $staticPages=true, $draftPages=true, $scheduledPages=true) {
global $dbPages;
// Get DB
$pageNumber = 1;
$amountOfItems = -1;
$db = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
$onlyKeys = true;
$keys = array();
if ($publishedPages) {
$keys = array_merge($keys, $dbPages->getPublishedDB($onlyKeys));
}
if ($staticPages) {
$keys = array_merge($keys, $dbPages->getStaticDB($onlyKeys));
}
if ($draftPages) {
$keys = array_merge($keys, $dbPages->getDraftDB($onlyKeys));
}
if ($scheduledPages) {
$keys = array_merge($keys, $dbPages->getScheduledDB($onlyKeys));
}
$tmp = array();
$keys = array_keys($db);
foreach($keys as $pageKey) {
foreach ($keys as $pageKey) {
$page = buildPage($pageKey);
if($page!==false) {
if ($page!==false) {
$tmp[$page->key()] = $page;
}
}