From 168483f7714afa5fb98a6fe46053a1d798df7ed6 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Wed, 5 Jul 2017 22:55:03 +0200 Subject: [PATCH] Pages parents fixed --- bl-kernel/abstract/plugin.class.php | 5 +++ bl-kernel/admin/controllers/new-page.php | 2 +- bl-kernel/admin/views/edit-page.php | 42 +++++++++++++----------- bl-kernel/admin/views/new-page.php | 11 ++++--- bl-kernel/dbpages.class.php | 23 +++++-------- bl-kernel/page.class.php | 1 - 6 files changed, 44 insertions(+), 40 deletions(-) diff --git a/bl-kernel/abstract/plugin.class.php b/bl-kernel/abstract/plugin.class.php index e439f0f2..29b4ca88 100644 --- a/bl-kernel/abstract/plugin.class.php +++ b/bl-kernel/abstract/plugin.class.php @@ -252,6 +252,11 @@ class Plugin { return file_exists($this->filenameDb); } + public function workspace() + { + return PATH_PLUGINS_DATABASES.$this->directoryName.DS; + } + public function init() { // This method is used on childre classes. diff --git a/bl-kernel/admin/controllers/new-page.php b/bl-kernel/admin/controllers/new-page.php index 31e85d29..528372cc 100644 --- a/bl-kernel/admin/controllers/new-page.php +++ b/bl-kernel/admin/controllers/new-page.php @@ -18,7 +18,7 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) { - if( createNewPage($_POST)!==false ) { + if( createPage($_POST)!==false ) { Alert::set( $Language->g('Page added successfully') ); } diff --git a/bl-kernel/admin/views/edit-page.php b/bl-kernel/admin/views/edit-page.php index 93c7f8c4..7f8445e9 100644 --- a/bl-kernel/admin/views/edit-page.php +++ b/bl-kernel/admin/views/edit-page.php @@ -151,26 +151,30 @@ echo '
'; 'tip'=>$L->g('To schedule the post just select the date and time'), 'label'=>$L->g('Date') )); -/* -// If the page is parent then doesn't can have a parent. -if(count($page->children())===0) -{ - // Parent input - $options = array(); - $options[NO_PARENT_CHAR] = '('.$Language->g('No parent').')'; - $options += $dbPages->parentKeyList(); - unset($options[$page->key()]); - HTML::formSelect(array( - 'name'=>'parent', - 'label'=>$L->g('Parent'), - 'class'=>'uk-width-1-1 uk-form-medium', - 'options'=>$options, - 'selected'=>$page->parentKey(), - 'tip'=>'' - )); -} -*/ + // Parent input + // Check if the page has children + if(count($page->children())===0) { + $options = array(); + $parentsList = $dbPages->getParents(); + $parentsKey = array_keys($parentsList); + foreach($parentsKey as $pageKey) { + $parent = buildPage($pageKey); + $options[$pageKey] = $parent->title(); + } + unset($options[$page->key()]); + + HTML::formSelect(array( + 'name'=>'parent', + 'label'=>$L->g('Parent'), + 'class'=>'uk-width-1-1 uk-form-medium', + 'options'=>$options, + 'selected'=>$page->parentKey(), + 'tip'=>'', + 'addEmptySpace'=>true + )); + } + // Position input HTML::formInputText(array( 'name'=>'position', diff --git a/bl-kernel/admin/views/new-page.php b/bl-kernel/admin/views/new-page.php index 02fe9047..b832f24e 100644 --- a/bl-kernel/admin/views/new-page.php +++ b/bl-kernel/admin/views/new-page.php @@ -137,12 +137,13 @@ echo '
'; 'label'=>$L->g('Date') )); -/* // Parent input $options = array(); - $parents = $dbPages->getParents(true); - foreach( $parents as $key=>$fields ) { - $options[$key] = $pagesByKey[$key]->title(); + $parentsList = $dbPages->getParents(); + $parentsKey = array_keys($parentsList); + foreach($parentsKey as $pageKey) { + $parent = buildPage($pageKey); + $options[$pageKey] = $parent->title(); } HTML::formSelect(array( @@ -154,7 +155,7 @@ echo '
'; 'tip'=>'', 'addEmptySpace'=>true )); -*/ + // Position input HTML::formInputText(array( 'name'=>'position', diff --git a/bl-kernel/dbpages.class.php b/bl-kernel/dbpages.class.php index a9e28a6e..ff6a81f7 100644 --- a/bl-kernel/dbpages.class.php +++ b/bl-kernel/dbpages.class.php @@ -33,7 +33,7 @@ class dbPages extends dbJSON $dataForFile = array(); // This data will be saved in the file // Generate key - $key = $this->generateKey($args['slug']); + $key = $this->generateKey($args['slug'], $args['parent']); // Generate UUID $args['uuid'] = $this->generateUUID(); @@ -117,7 +117,7 @@ class dbPages extends dbJSON $dataForDb = array(); $dataForFile = array(); - $newKey = $this->generateKey($args['slug'], NO_PARENT_CHAR, false, $args['key']); + $newKey = $this->generateKey($args['slug'], $args['parent'], false, $args['key']); // If the page is draft then the created time is the current if( $this->db[$args['key']]['status']=='draft' ) { @@ -345,21 +345,16 @@ class dbPages extends dbJSON return count($this->db); } - public function getParents($onlyPublished=true) + // Returns an array with all parents pages key, a parent page is not a child + public function getParents() { - if( $onlyPublished ) { - $db = $this->getPublishedDB(); - } - else { - $db = $this->db; - } - - foreach( $db as $key=>$fields ) { + $db = $this->getPublishedDB(); + foreach($db as $key=>$fields) { + // if the key has slash then is a child if( Text::stringContains($key, '/') ) { unset($db[$key]); } } - return $db; } @@ -454,13 +449,13 @@ class dbPages extends dbJSON } // Generate a valid Key/Slug - public function generateKey($text, $parent=NO_PARENT_CHAR, $returnSlug=false, $oldKey='') + public function generateKey($text, $parent=false, $returnSlug=false, $oldKey='') { if(Text::isEmpty($text)) { $text = 'empty'; } - if( Text::isEmpty($parent) || ($parent==NO_PARENT_CHAR) ) { + if( empty($parent) ) { $newKey = Text::cleanUrl($text); } else { diff --git a/bl-kernel/page.class.php b/bl-kernel/page.class.php index 617c3720..cef2baec 100644 --- a/bl-kernel/page.class.php +++ b/bl-kernel/page.class.php @@ -436,7 +436,6 @@ class Page { public function children() { $tmp = array(); - //$paths = glob(PATH_PAGES.$this->getValue('key').DS.'*', GLOB_ONLYDIR); $paths = Filesystem::listDirectories(PATH_PAGES.$this->getValue('key').DS); foreach($paths as $path) { array_push($tmp, basename($path));