diff --git a/bl-kernel/admin/views/content.php b/bl-kernel/admin/views/content.php
index 7927e23d..cb2ddbb3 100644
--- a/bl-kernel/admin/views/content.php
+++ b/bl-kernel/admin/views/content.php
@@ -48,18 +48,20 @@ function table($status, $icon='arrow-circle-o-down') {
foreach($list as $pageKey=>$fields) {
$page = buildPage($pageKey);
- echo '
';
- echo '
- '
- .($page->title()?$page->title():''.$Language->g('Empty title').' ')
- .'
- | ';
+ if ($page) {
+ echo '
';
+ echo '
+ '
+ .($page->title()?$page->title():''.$Language->g('Empty title').' ')
+ .'
+ | ';
- echo ''.( (ORDER_BY=='date') ? $page->dateRaw() : $page->position() ).' | ';
+ echo ''.( (ORDER_BY=='date') ? $page->dateRaw() : $page->position() ).' | ';
- $friendlyURL = Text::isEmpty($Url->filters('page')) ? '/'.$page->key() : '/'.$Url->filters('page').'/'.$page->key();
- echo ''.$friendlyURL.' | ';
- echo '
';
+ $friendlyURL = Text::isEmpty($Url->filters('page')) ? '/'.$page->key() : '/'.$Url->filters('page').'/'.$page->key();
+ echo ''.$friendlyURL.' | ';
+ echo '';
+ }
}
}
diff --git a/bl-kernel/dbpages.class.php b/bl-kernel/dbpages.class.php
index 1b0af9d0..3b36fdc5 100644
--- a/bl-kernel/dbpages.class.php
+++ b/bl-kernel/dbpages.class.php
@@ -19,9 +19,7 @@ class dbPages extends dbJSON
'category'=> array('inFile'=>false, 'value'=>''),
'md5file'=> array('inFile'=>false, 'value'=>''),
'uuid'=> array('inFile'=>false, 'value'=>''),
- 'allowComments'=> array('inFile'=>false, 'value'=>true),
- 'parent'=> array('inFile'=>false, 'value'=>''),
- 'slug'=> array('inFile'=>false, 'value'=>'')
+ 'allowComments'=> array('inFile'=>false, 'value'=>true)
);
function __construct()
@@ -61,6 +59,11 @@ class dbPages extends dbJSON
$args['slug'] = Text::truncate($tmpslug, 60, '');
}
+ // Parent
+ if (!isset($args['parent'])) {
+ $args['parent'] = '';
+ }
+
// Generate key
$key = $this->generateKey($args['slug'], $args['parent']);
@@ -156,6 +159,11 @@ class dbPages extends dbJSON
$args[$field] = $value;
}
+ // Parent
+ if (!isset($args['parent'])) {
+ $args['parent'] = '';
+ }
+
$newKey = $this->generateKey($args['slug'], $args['parent'], false, $args['key']);
// If the page is draft then the created time is the current
@@ -213,6 +221,9 @@ class dbPages extends dbJSON
// Remove the old key
unset( $this->db[$args['key']] );
+ // Reindex Orphan Children
+ $this->reindexChildren($args['key'], $newKey);
+
// Checksum MD5
$dataForDb['md5file'] = md5_file(PATH_PAGES.$newKey.DS.FILENAME);
@@ -228,6 +239,19 @@ class dbPages extends dbJSON
return $newKey;
}
+ // This function reindex the orphan children with the new parent key
+ // If a page has subpages and the page change his key is necesarry check the children key
+ public function reindexChildren($oldParentKey, $newParentKey) {
+ $tmp = $this->db;
+ foreach ($tmp as $key=>$fields) {
+ if (Text::startsWith($key, $oldParentKey.'/')) {
+ $newKey = Text::replace($oldParentKey.'/', $newParentKey.'/', $key);
+ $this->db[$newKey] = $this->db[$key];
+ unset($this->db[$key]);
+ }
+ }
+ }
+
public function delete($key)
{
// This is need it, because if the key is empty the Filesystem::deleteRecursive is going to delete PATH_PAGES
diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php
index 2e05710b..4ba40d42 100644
--- a/bl-kernel/functions.php
+++ b/bl-kernel/functions.php
@@ -167,7 +167,6 @@ 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($publishedPages=true, $staticPages=true) {
global $dbPages;
global $pagesByParent;
@@ -387,7 +386,7 @@ function editPage($args) {
}
// External Cover Image
- if ( !empty($args['externalCoverImage']) ) {
+ if (!empty($args['externalCoverImage'])) {
$args['coverImage'] = $args['externalCoverImage'];
unset($args['externalCoverImage']);
}
diff --git a/bl-kernel/helpers/text.class.php b/bl-kernel/helpers/text.class.php
index 012ba61c..f6ea1df5 100644
--- a/bl-kernel/helpers/text.class.php
+++ b/bl-kernel/helpers/text.class.php
@@ -151,6 +151,7 @@ class Text {
}
// Replace all occurrences of the search string with the replacement string.
+ // replace("%body%", "black", "");
public static function replace($search, $replace, $string)
{
return str_replace($search,$replace,$string);
diff --git a/bl-kernel/page.class.php b/bl-kernel/page.class.php
index 4b6bbf3b..a3613e11 100644
--- a/bl-kernel/page.class.php
+++ b/bl-kernel/page.class.php
@@ -399,7 +399,7 @@ class Page {
$explode = explode('/', $this->getValue('key'));
// Check if the page have a parent.
- if(!empty($explode[1])) {
+ if (!empty($explode[1])) {
return $explode[1];
}
@@ -410,7 +410,7 @@ class Page {
public function parentKey()
{
$explode = explode('/', $this->getValue('key'));
- if(isset($explode[1])) {
+ if (isset($explode[1])) {
return $explode[0];
}
@@ -421,7 +421,7 @@ class Page {
public function parentMethod($method)
{
$parentKey = $this->parentKey();
- if( $parentKey ) {
+ if ($parentKey) {
$page = buildPage($parentKey);
return $page->{$method}();
}
@@ -434,7 +434,7 @@ class Page {
{
$tmp = array();
$paths = Filesystem::listDirectories(PATH_PAGES.$this->getValue('key').DS);
- foreach($paths as $path) {
+ foreach ($paths as $path) {
array_push($tmp, basename($path));
}