Improves on pages system

This commit is contained in:
dignajar 2015-10-31 19:54:42 -03:00
parent 6958133db5
commit a1799a3d0e
6 changed files with 29 additions and 28 deletions

View File

@ -27,7 +27,7 @@ echo '
} }
echo '<tr>'; echo '<tr>';
echo '<td>'.($Page->parentKey()?NO_PARENT_CHAR:'').'<a href="'.HTML_PATH_ADMIN_ROOT.'edit-page/'.$Page->key().'">'.($Page->published()?'':'<span class="label-draft">'.$Language->g('Draft').'</span> ').($Page->title()?$Page->title():'<span class="label-empty-title">'.$Language->g('Empty title').'</span> ').'</a></td>'; echo '<td>'.($Page->parentKey()?'- ':'').'<a href="'.HTML_PATH_ADMIN_ROOT.'edit-page/'.$Page->key().'">'.($Page->published()?'':'<span class="label-draft">'.$Language->g('Draft').'</span> ').($Page->title()?$Page->title():'<span class="label-empty-title">'.$Language->g('Empty title').'</span> ').'</a></td>';
echo '<td>'.$parentTitle.'</td>'; echo '<td>'.$parentTitle.'</td>';
echo '<td class="uk-text-center">'.$Page->position().'</td>'; echo '<td class="uk-text-center">'.$Page->position().'</td>';
echo '<td><a target="_blank" href="'.$Page->permalink().'">'.$Url->filters('page').'/'.$Page->key().'</a></td>'; echo '<td><a target="_blank" href="'.$Page->permalink().'">'.$Url->filters('page').'/'.$Page->key().'</a></td>';

View File

@ -54,8 +54,8 @@ define('SALT_LENGTH', 8);
// Page brake string // Page brake string
define('PAGE_BREAK', '<!-- pagebreak -->'); define('PAGE_BREAK', '<!-- pagebreak -->');
// No parent character // No parent character, md5('No parent')
define('NO_PARENT_CHAR', '—-'); define('NO_PARENT_CHAR', '3849abb4cb7abd24c2d8dac17b216f17');
// Post per page on Manage->Posts // Post per page on Manage->Posts
define('POSTS_PER_PAGE_ADMIN', 10); define('POSTS_PER_PAGE_ADMIN', 10);

View File

@ -4,7 +4,10 @@
// Variables // Variables
// ============================================================================ // ============================================================================
// Array with all pages.
$pages = array(); $pages = array();
// Array with all pages, order by parent.
$pagesParents = array(NO_PARENT_CHAR=>array()); $pagesParents = array(NO_PARENT_CHAR=>array());
// ============================================================================ // ============================================================================
@ -33,12 +36,14 @@ function build_page($key)
// Page object, content from FILE. // Page object, content from FILE.
$Page = new Page($key); $Page = new Page($key);
if( !$Page->isValid() ) { if( !$Page->isValid() ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from file with key: '.$key);
return false; return false;
} }
// Page database, content from DATABASE JSON. // Page database, content from DATABASE JSON.
$db = $dbPages->getDb($key); $db = $dbPages->getDb($key);
if( !$db ) { if( !$db ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from database with key: '.$key);
return false; return false;
} }
@ -63,7 +68,6 @@ function build_page($key)
$user = $dbUsers->getDb( $Page->username() ); $user = $dbUsers->getDb( $Page->username() );
$Page->setField('authorFirstName', $user['firstName'], false); $Page->setField('authorFirstName', $user['firstName'], false);
$Page->setField('authorLastName', $user['lastName'], false); $Page->setField('authorLastName', $user['lastName'], false);
} }
@ -86,9 +90,12 @@ function build_all_pages()
if($Page!==false) if($Page!==false)
{ {
// --- Order pages by parents ---
// Generate all posible parents. // Generate all posible parents.
if( $Page->parentKey()===false ) if( $Page->parentKey()===false )
{ {
// Add the parent key in the dbPages
$dbPages->addParentKey($Page->key()); $dbPages->addParentKey($Page->key());
$pagesParents[NO_PARENT_CHAR][$Page->key()] = $Page; $pagesParents[NO_PARENT_CHAR][$Page->key()] = $Page;
@ -98,33 +105,27 @@ function build_all_pages()
$pagesParents[$Page->parentKey()][$Page->key()] = $Page; $pagesParents[$Page->parentKey()][$Page->key()] = $Page;
} }
// $pages array // --- All pages in 1 array ---
$pages[$Page->key()] = $Page; $pages[$Page->key()] = $Page;
} }
} }
// ======== Order pages ======== // ======== Sort pages ========
// DEBUG: No me gusta esta forma de ordenar $tmpNoParents = $pagesParents[NO_PARENT_CHAR];
unset($pagesParents[NO_PARENT_CHAR]);
// Order children // Sort children
$tmpPageWithParent = array();
foreach($pagesParents as $parentKey=>$childrenPages)
{
$tmpPageWithParent[$parentKey] = $childrenPages;
uasort($tmpPageWithParent[$parentKey], 'orderChildren');
}
// Sort parents
$tmp = array(); $tmp = array();
foreach($pagesParents as $parentKey=>$childrenPages) foreach($tmpNoParents as $parentKey=>$childrenPages)
{
$tmp[$parentKey] = $childrenPages;
uasort($tmp[$parentKey], 'orderChildren');
}
if(isset($tmp[NO_PARENT_CHAR]))
{
$tmpNoParents = $tmp[NO_PARENT_CHAR];
unset($tmp[NO_PARENT_CHAR]);
}
$pagesParents = $tmp;
// Order parents.
foreach($pagesParents as $parentKey=>$childrenPages)
{ {
// DEBUG: Workaround, Esto es un bug, cuando se usa el Cli mode // DEBUG: Workaround, Esto es un bug, cuando se usa el Cli mode
// DEBUG: Se genera un padre sin index.txt y adentro hay un hijo // DEBUG: Se genera un padre sin index.txt y adentro hay un hijo
@ -133,7 +134,7 @@ function build_all_pages()
} }
} }
$pagesParents = array(NO_PARENT_CHAR=>$tmpNoParents) + $tmp; $pagesParents = array(NO_PARENT_CHAR=>$tmp) + $tmpPageWithParent;
} }
// ============================================================================ // ============================================================================

View File

@ -20,7 +20,7 @@ Paginator::set('postPerPage', $postPerPage);
// Number of posts // Number of posts
Paginator::set('numberOfPosts', $numberOfPosts); Paginator::set('numberOfPosts', $numberOfPosts);
$numberOfPages = (int) ceil($numberOfPosts / $postPerPage) -1; $numberOfPages = (int) max(ceil($numberOfPosts / $postPerPage) -1, 0);
Paginator::set('numberOfPages', $numberOfPages); Paginator::set('numberOfPages', $numberOfPages);
$showOlder = $numberOfPages > $currentPage; $showOlder = $numberOfPages > $currentPage;

View File

@ -289,7 +289,7 @@ class dbPages extends dbJSON
return $newKey; return $newKey;
} }
// Return an array with all page's databases. // Return an array with all databases.
public function getAll() public function getAll()
{ {
return $this->db; return $this->db;

View File

@ -96,7 +96,7 @@ class dbPosts extends dbJSON
// Generate the database key. // Generate the database key.
$key = $this->generateKey($args['slug']); $key = $this->generateKey($args['slug']);
// The user is always the who is loggued. // The user is always who is loggued.
$args['username'] = Session::get('username'); $args['username'] = Session::get('username');
if( Text::isEmpty($args['username']) ) { if( Text::isEmpty($args['username']) ) {
return false; return false;