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 // Main after POST
// ============================================================================ // ============================================================================
$allPublishedPages = buildAllpages(true); $allPages = buildAllpages($publishedPages=true, $staticPages=true, $draftPages=false, $scheduledPages=false);
// Homepage select options // Homepage select options
$homepageOptions = array(' '=>'- '.$L->g('Latest content').' -'); $homepageOptions = array(' '=>'- '.$L->g('Latest content').' -');
foreach($allPublishedPages as $key=>$page) { foreach ($allPages as $key=>$page) {
$parentKey = $page->parentKey(); $parentKey = $page->parentKey();
if ($parentKey) { if ($parentKey) {
$homepageOptions[$key] = $pagesByParentByKey[PARENT][$parentKey]->title() .'->'. $page->title(); $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 // Parent input
// Check if the page has children // Check if the page has children
if(count($page->children())==0) { if (count($page->children())==0) {
$options = array(' '=>'- '.$L->g('No parent').' -'); $options = array(' '=>'- '.$L->g('No parent').' -');
$parentsList = $dbPages->getParents(); $parentsList = $dbPages->getParents();
$parentsKey = array_keys($parentsList); $parentsKey = array_keys($parentsList);
@ -180,9 +180,9 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
'selected'=>$page->parentKey(), 'selected'=>$page->parentKey(),
'tip'=>'' 'tip'=>''
)); ));
}
echo '<hr>'; echo '<hr>';
}
// Position input // Position input
HTML::formInputText(array( HTML::formInputText(array(

View File

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

View File

@ -264,7 +264,7 @@ class dbPages extends dbJSON
} }
// Returns a database with published pages // Returns a database with published pages
public function getPublishedDB() public function getPublishedDB($onlyKeys=false)
{ {
$tmp = $this->db; $tmp = $this->db;
foreach ($tmp as $key=>$fields) { foreach ($tmp as $key=>$fields) {
@ -272,6 +272,9 @@ class dbPages extends dbJSON
unset($tmp[$key]); unset($tmp[$key]);
} }
} }
if ($onlyKeys) {
return array_keys($tmp);
}
return $tmp; return $tmp;
} }
@ -293,7 +296,7 @@ class dbPages extends dbJSON
} }
// 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() public function getDraftDB($onlyKeys=false)
{ {
$tmp = $this->db; $tmp = $this->db;
foreach ($tmp as $key=>$fields) { foreach ($tmp as $key=>$fields) {
@ -301,11 +304,14 @@ class dbPages extends dbJSON
unset($tmp[$key]); unset($tmp[$key]);
} }
} }
if ($onlyKeys) {
return array_keys($tmp);
}
return $tmp; return $tmp;
} }
// 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() public function getScheduledDB($onlyKeys=false)
{ {
$tmp = $this->db; $tmp = $this->db;
foreach($tmp as $key=>$fields) { foreach($tmp as $key=>$fields) {
@ -313,6 +319,9 @@ class dbPages extends dbJSON
unset($tmp[$key]); unset($tmp[$key]);
} }
} }
if ($onlyKeys) {
return array_keys($tmp);
}
return $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 // Generate the global variable $pagesByParent, defined on 69.pages.php
// (boolean) $allPages, TRUE include all status, FALSE only include published status // (boolean) $allPages, TRUE include all status, FALSE only include published status
function buildPagesByParent($onlyPublished=true) { function buildPagesByParent($publishedPages=true, $staticPages=true) {
global $dbPages; global $dbPages;
global $pagesByParent; global $pagesByParent;
global $pagesByParentByKey; global $pagesByParentByKey;
// Get DB $onlyKeys = true;
$pageNumber = 1; $keys = array();
$amountOfItems = -1; if ($publishedPages) {
$db = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished); $keys = array_merge($keys, $dbPages->getPublishedDB($onlyKeys));
}
if ($staticPages) {
$keys = array_merge($keys, $dbPages->getStaticDB($onlyKeys));
}
// Get Keys foreach ($keys as $pageKey) {
$keys = array_keys($db);
foreach($keys as $pageKey) {
$page = buildPage($pageKey); $page = buildPage($pageKey);
if($page!==false) { if ($page!==false) {
$parentKey = $page->parentKey(); $parentKey = $page->parentKey();
// FALSE if the page is parent // FALSE if the page is parent
if($parentKey===false) { if ($parentKey===false) {
array_push($pagesByParent[PARENT], $page); array_push($pagesByParent[PARENT], $page);
$pagesByParentByKey[PARENT][$page->key()] = $page; $pagesByParentByKey[PARENT][$page->key()] = $page;
} else { } else {
if( !isset($pagesByParent[$parentKey]) ) { if (!isset($pagesByParent[$parentKey])) {
$pagesByParent[$parentKey] = array(); $pagesByParent[$parentKey] = array();
} }
array_push($pagesByParent[$parentKey], $page); array_push($pagesByParent[$parentKey], $page);
@ -221,19 +223,29 @@ function buildStaticPages() {
pageKeyN => Page object, pageKeyN => Page object,
) )
*/ */
function buildAllpages($onlyPublished=true) { function buildAllpages($publishedPages=true, $staticPages=true, $draftPages=true, $scheduledPages=true) {
global $dbPages; global $dbPages;
// Get DB // Get DB
$pageNumber = 1; $onlyKeys = true;
$amountOfItems = -1; $keys = array();
$db = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished); 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(); $tmp = array();
$keys = array_keys($db); foreach ($keys as $pageKey) {
foreach($keys as $pageKey) {
$page = buildPage($pageKey); $page = buildPage($pageKey);
if($page!==false) { if ($page!==false) {
$tmp[$page->key()] = $page; $tmp[$page->key()] = $page;
} }
} }