Pages parents fixed
This commit is contained in:
parent
556e5a2f73
commit
168483f771
@ -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.
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
||||
{
|
||||
if( createNewPage($_POST)!==false ) {
|
||||
if( createPage($_POST)!==false ) {
|
||||
Alert::set( $Language->g('Page added successfully') );
|
||||
}
|
||||
|
||||
|
@ -151,26 +151,30 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
|
||||
'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',
|
||||
|
@ -137,12 +137,13 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
|
||||
'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 '<div class="bl-publish-sidebar uk-width-2-10">';
|
||||
'tip'=>'',
|
||||
'addEmptySpace'=>true
|
||||
));
|
||||
*/
|
||||
|
||||
// Position input
|
||||
HTML::formInputText(array(
|
||||
'name'=>'position',
|
||||
|
@ -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 {
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user