This commit is contained in:
Diego Najar 2017-12-17 21:16:30 +01:00
parent c88bb01323
commit ff1abc1e36
5 changed files with 45 additions and 19 deletions

View File

@ -48,18 +48,20 @@ function table($status, $icon='arrow-circle-o-down') {
foreach($list as $pageKey=>$fields) {
$page = buildPage($pageKey);
echo '<tr>';
echo '<td>
<a href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'">'
.($page->title()?$page->title():'<span class="label-empty-title">'.$Language->g('Empty title').'</span> ')
.'</a>
</td>';
if ($page) {
echo '<tr>';
echo '<td>
<a href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'">'
.($page->title()?$page->title():'<span class="label-empty-title">'.$Language->g('Empty title').'</span> ')
.'</a>
</td>';
echo '<td class="uk-text-center">'.( (ORDER_BY=='date') ? $page->dateRaw() : $page->position() ).'</td>';
echo '<td class="uk-text-center">'.( (ORDER_BY=='date') ? $page->dateRaw() : $page->position() ).'</td>';
$friendlyURL = Text::isEmpty($Url->filters('page')) ? '/'.$page->key() : '/'.$Url->filters('page').'/'.$page->key();
echo '<td><a target="_blank" href="'.$page->permalink().'">'.$friendlyURL.'</a></td>';
echo '</tr>';
$friendlyURL = Text::isEmpty($Url->filters('page')) ? '/'.$page->key() : '/'.$Url->filters('page').'/'.$page->key();
echo '<td><a target="_blank" href="'.$page->permalink().'">'.$friendlyURL.'</a></td>';
echo '</tr>';
}
}
}

View File

@ -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

View File

@ -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']);
}

View File

@ -151,6 +151,7 @@ class Text {
}
// Replace all occurrences of the search string with the replacement string.
// replace("%body%", "black", "<body text='%body%'>");
public static function replace($search, $replace, $string)
{
return str_replace($search,$replace,$string);

View File

@ -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));
}