From 3b6aac5ec2fad5fe1327a1b1b4bd40c7c66f180c Mon Sep 17 00:00:00 2001 From: dignajar Date: Sat, 21 Nov 2015 12:11:35 -0300 Subject: [PATCH] Bug fixed - Page position --- kernel/boot/rules/70.pages.php | 38 ++++++++++++++-------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/kernel/boot/rules/70.pages.php b/kernel/boot/rules/70.pages.php index 50d93add..1f232d2e 100644 --- a/kernel/boot/rules/70.pages.php +++ b/kernel/boot/rules/70.pages.php @@ -14,7 +14,7 @@ $pagesParents = array(NO_PARENT_CHAR=>array()); // Functions // ============================================================================ -function orderChildren($a, $b) +function sortPages($a, $b) { if ($a->position() == $b->position()) { return 0; @@ -23,10 +23,6 @@ function orderChildren($a, $b) return ($a->position() < $b->position()) ? -1 : 1; } -function orderParent($array, $values, $offset) { - return ( array_slice($array, 0, $offset, true) + $values + array_slice($array, $offset, NULL, true) ); -} - function build_page($key) { global $dbPages; @@ -110,31 +106,27 @@ function build_all_pages() } } - // ======== Sort pages ======== + // --- SORT PAGES --- - $tmpNoParents = $pagesParents[NO_PARENT_CHAR]; + // Sort parents. + $parents = $pagesParents[NO_PARENT_CHAR]; + uasort($parents, 'sortPages'); + + // Sort children. unset($pagesParents[NO_PARENT_CHAR]); - - // Sort children + $children = $pagesParents; $tmpPageWithParent = array(); - foreach($pagesParents as $parentKey=>$childrenPages) + foreach($children as $parentKey=>$childrenPages) { - $tmpPageWithParent[$parentKey] = $childrenPages; - uasort($tmpPageWithParent[$parentKey], 'orderChildren'); - } - - // Sort parents - $tmp = array(); - 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 - if(isset($pages[$parentKey])) { - $tmp = orderParent($tmp, array($parentKey=>$childrenPages), $pages[$parentKey]->position()); + // If the child doesn't have a valid parent, then doesn't included them. + if(isset($pages[$parentKey])) + { + $tmpPageWithParent[$parentKey] = $childrenPages; + uasort($tmpPageWithParent[$parentKey], 'sortPages'); } } - $pagesParents = array(NO_PARENT_CHAR=>$tmp) + $tmpPageWithParent; + $pagesParents = array(NO_PARENT_CHAR=>$parents) + $tmpPageWithParent; } // ============================================================================