From a1799a3d0e658c16f7a79f18c07a1b5af3578a0c Mon Sep 17 00:00:00 2001 From: dignajar Date: Sat, 31 Oct 2015 19:54:42 -0300 Subject: [PATCH] Improves on pages system --- admin/views/manage-pages.php | 2 +- kernel/boot/init.php | 4 +-- kernel/boot/rules/70.pages.php | 45 +++++++++++++++--------------- kernel/boot/rules/99.paginator.php | 2 +- kernel/dbpages.class.php | 2 +- kernel/dbposts.class.php | 2 +- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/admin/views/manage-pages.php b/admin/views/manage-pages.php index 26f3bcd2..fa8754ac 100644 --- a/admin/views/manage-pages.php +++ b/admin/views/manage-pages.php @@ -27,7 +27,7 @@ echo ' } echo ''; - echo ''.($Page->parentKey()?NO_PARENT_CHAR:'').''.($Page->published()?'':''.$Language->g('Draft').' ').($Page->title()?$Page->title():''.$Language->g('Empty title').' ').''; + echo ''.($Page->parentKey()?'- ':'').''.($Page->published()?'':''.$Language->g('Draft').' ').($Page->title()?$Page->title():''.$Language->g('Empty title').' ').''; echo ''.$parentTitle.''; echo ''.$Page->position().''; echo ''.$Url->filters('page').'/'.$Page->key().''; diff --git a/kernel/boot/init.php b/kernel/boot/init.php index 9a79f49c..56d8b319 100644 --- a/kernel/boot/init.php +++ b/kernel/boot/init.php @@ -54,8 +54,8 @@ define('SALT_LENGTH', 8); // Page brake string define('PAGE_BREAK', ''); -// No parent character -define('NO_PARENT_CHAR', '—-'); +// No parent character, md5('No parent') +define('NO_PARENT_CHAR', '3849abb4cb7abd24c2d8dac17b216f17'); // Post per page on Manage->Posts define('POSTS_PER_PAGE_ADMIN', 10); diff --git a/kernel/boot/rules/70.pages.php b/kernel/boot/rules/70.pages.php index 17706471..50d93add 100644 --- a/kernel/boot/rules/70.pages.php +++ b/kernel/boot/rules/70.pages.php @@ -4,7 +4,10 @@ // Variables // ============================================================================ +// Array with all pages. $pages = array(); + +// Array with all pages, order by parent. $pagesParents = array(NO_PARENT_CHAR=>array()); // ============================================================================ @@ -33,12 +36,14 @@ function build_page($key) // Page object, content from FILE. $Page = new Page($key); if( !$Page->isValid() ) { + Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from file with key: '.$key); return false; } // Page database, content from DATABASE JSON. $db = $dbPages->getDb($key); if( !$db ) { + Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from database with key: '.$key); return false; } @@ -63,7 +68,6 @@ function build_page($key) $user = $dbUsers->getDb( $Page->username() ); $Page->setField('authorFirstName', $user['firstName'], false); - $Page->setField('authorLastName', $user['lastName'], false); } @@ -86,9 +90,12 @@ function build_all_pages() if($Page!==false) { + // --- Order pages by parents --- + // Generate all posible parents. if( $Page->parentKey()===false ) { + // Add the parent key in the dbPages $dbPages->addParentKey($Page->key()); $pagesParents[NO_PARENT_CHAR][$Page->key()] = $Page; @@ -98,33 +105,27 @@ function build_all_pages() $pagesParents[$Page->parentKey()][$Page->key()] = $Page; } - // $pages array + // --- All pages in 1 array --- $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(); - foreach($pagesParents 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) + foreach($tmpNoParents as $parentKey=>$childrenPages) { // 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 @@ -133,7 +134,7 @@ function build_all_pages() } } - $pagesParents = array(NO_PARENT_CHAR=>$tmpNoParents) + $tmp; + $pagesParents = array(NO_PARENT_CHAR=>$tmp) + $tmpPageWithParent; } // ============================================================================ diff --git a/kernel/boot/rules/99.paginator.php b/kernel/boot/rules/99.paginator.php index a6dc929a..31b99f2b 100644 --- a/kernel/boot/rules/99.paginator.php +++ b/kernel/boot/rules/99.paginator.php @@ -20,7 +20,7 @@ Paginator::set('postPerPage', $postPerPage); // Number of posts Paginator::set('numberOfPosts', $numberOfPosts); -$numberOfPages = (int) ceil($numberOfPosts / $postPerPage) -1; +$numberOfPages = (int) max(ceil($numberOfPosts / $postPerPage) -1, 0); Paginator::set('numberOfPages', $numberOfPages); $showOlder = $numberOfPages > $currentPage; diff --git a/kernel/dbpages.class.php b/kernel/dbpages.class.php index 709edeb3..410553ad 100644 --- a/kernel/dbpages.class.php +++ b/kernel/dbpages.class.php @@ -289,7 +289,7 @@ class dbPages extends dbJSON return $newKey; } - // Return an array with all page's databases. + // Return an array with all databases. public function getAll() { return $this->db; diff --git a/kernel/dbposts.class.php b/kernel/dbposts.class.php index 113d8dff..b78a2cb2 100644 --- a/kernel/dbposts.class.php +++ b/kernel/dbposts.class.php @@ -96,7 +96,7 @@ class dbPosts extends dbJSON // Generate the database key. $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'); if( Text::isEmpty($args['username']) ) { return false;