Pages parents fixed

This commit is contained in:
Diego Najar 2017-07-05 22:55:03 +02:00
parent 556e5a2f73
commit 168483f771
6 changed files with 44 additions and 40 deletions

View File

@ -252,6 +252,11 @@ class Plugin {
return file_exists($this->filenameDb); return file_exists($this->filenameDb);
} }
public function workspace()
{
return PATH_PLUGINS_DATABASES.$this->directoryName.DS;
}
public function init() public function init()
{ {
// This method is used on childre classes. // This method is used on childre classes.

View File

@ -18,7 +18,7 @@
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{ {
if( createNewPage($_POST)!==false ) { if( createPage($_POST)!==false ) {
Alert::set( $Language->g('Page added successfully') ); Alert::set( $Language->g('Page added successfully') );
} }

View File

@ -151,14 +151,17 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
'tip'=>$L->g('To schedule the post just select the date and time'), 'tip'=>$L->g('To schedule the post just select the date and time'),
'label'=>$L->g('Date') 'label'=>$L->g('Date')
)); ));
/*
// If the page is parent then doesn't can have a parent.
if(count($page->children())===0)
{
// Parent input // Parent input
// Check if the page has children
if(count($page->children())===0) {
$options = array(); $options = array();
$options[NO_PARENT_CHAR] = '('.$Language->g('No parent').')'; $parentsList = $dbPages->getParents();
$options += $dbPages->parentKeyList(); $parentsKey = array_keys($parentsList);
foreach($parentsKey as $pageKey) {
$parent = buildPage($pageKey);
$options[$pageKey] = $parent->title();
}
unset($options[$page->key()]); unset($options[$page->key()]);
HTML::formSelect(array( HTML::formSelect(array(
@ -167,10 +170,11 @@ if(count($page->children())===0)
'class'=>'uk-width-1-1 uk-form-medium', 'class'=>'uk-width-1-1 uk-form-medium',
'options'=>$options, 'options'=>$options,
'selected'=>$page->parentKey(), 'selected'=>$page->parentKey(),
'tip'=>'' 'tip'=>'',
'addEmptySpace'=>true
)); ));
} }
*/
// Position input // Position input
HTML::formInputText(array( HTML::formInputText(array(
'name'=>'position', 'name'=>'position',

View File

@ -137,12 +137,13 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
'label'=>$L->g('Date') 'label'=>$L->g('Date')
)); ));
/*
// Parent input // Parent input
$options = array(); $options = array();
$parents = $dbPages->getParents(true); $parentsList = $dbPages->getParents();
foreach( $parents as $key=>$fields ) { $parentsKey = array_keys($parentsList);
$options[$key] = $pagesByKey[$key]->title(); foreach($parentsKey as $pageKey) {
$parent = buildPage($pageKey);
$options[$pageKey] = $parent->title();
} }
HTML::formSelect(array( HTML::formSelect(array(
@ -154,7 +155,7 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
'tip'=>'', 'tip'=>'',
'addEmptySpace'=>true 'addEmptySpace'=>true
)); ));
*/
// Position input // Position input
HTML::formInputText(array( HTML::formInputText(array(
'name'=>'position', 'name'=>'position',

View File

@ -33,7 +33,7 @@ class dbPages extends dbJSON
$dataForFile = array(); // This data will be saved in the file $dataForFile = array(); // This data will be saved in the file
// Generate key // Generate key
$key = $this->generateKey($args['slug']); $key = $this->generateKey($args['slug'], $args['parent']);
// Generate UUID // Generate UUID
$args['uuid'] = $this->generateUUID(); $args['uuid'] = $this->generateUUID();
@ -117,7 +117,7 @@ class dbPages extends dbJSON
$dataForDb = array(); $dataForDb = array();
$dataForFile = 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 the page is draft then the created time is the current
if( $this->db[$args['key']]['status']=='draft' ) { if( $this->db[$args['key']]['status']=='draft' ) {
@ -345,21 +345,16 @@ class dbPages extends dbJSON
return count($this->db); 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(); $db = $this->getPublishedDB();
} foreach($db as $key=>$fields) {
else { // if the key has slash then is a child
$db = $this->db;
}
foreach( $db as $key=>$fields ) {
if( Text::stringContains($key, '/') ) { if( Text::stringContains($key, '/') ) {
unset($db[$key]); unset($db[$key]);
} }
} }
return $db; return $db;
} }
@ -454,13 +449,13 @@ class dbPages extends dbJSON
} }
// Generate a valid Key/Slug // 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)) { if(Text::isEmpty($text)) {
$text = 'empty'; $text = 'empty';
} }
if( Text::isEmpty($parent) || ($parent==NO_PARENT_CHAR) ) { if( empty($parent) ) {
$newKey = Text::cleanUrl($text); $newKey = Text::cleanUrl($text);
} }
else { else {

View File

@ -436,7 +436,6 @@ class Page {
public function children() public function children()
{ {
$tmp = array(); $tmp = array();
//$paths = glob(PATH_PAGES.$this->getValue('key').DS.'*', GLOB_ONLYDIR);
$paths = Filesystem::listDirectories(PATH_PAGES.$this->getValue('key').DS); $paths = Filesystem::listDirectories(PATH_PAGES.$this->getValue('key').DS);
foreach($paths as $path) { foreach($paths as $path) {
array_push($tmp, basename($path)); array_push($tmp, basename($path));