Improves on performance for parent pages
This commit is contained in:
parent
5a438ec442
commit
7253df6f73
|
@ -1,6 +1,6 @@
|
|||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
// Returns a Page object, the class is page.class.php, FALSE if something fail to load the page
|
||||
// Returns a Page-Object, the class is page.class.php, FALSE if something fail to load the page
|
||||
function buildPage($key) {
|
||||
global $dbPages;
|
||||
global $dbUsers;
|
||||
|
@ -64,19 +64,22 @@ function buildPage($key) {
|
|||
return $page;
|
||||
}
|
||||
|
||||
// Execute a re-index of categories
|
||||
// Re-index database of categories
|
||||
// If you create/edit/remove a page is necessary regenerate the database of categories
|
||||
function reindexCategories() {
|
||||
global $dbCategories;
|
||||
return $dbCategories->reindex();
|
||||
}
|
||||
|
||||
// Re-index database of tags
|
||||
// If you create/edit/remove a page is necessary regenerate the database of tags
|
||||
function reindexTags() {
|
||||
global $dbTags;
|
||||
return $dbTags->reindex();
|
||||
}
|
||||
|
||||
// Returns a Page Object, this generate on the fly a page-not-found
|
||||
// Generate on the fly a 404 page-not-found
|
||||
// Returns a Page-Object
|
||||
function buildErrorPage() {
|
||||
global $dbPages;
|
||||
global $Language;
|
||||
|
@ -91,9 +94,9 @@ function buildErrorPage() {
|
|||
}
|
||||
|
||||
// This function is only used from the rule 69.pages.php, DO NOT use this function!
|
||||
// This function generate a particular page from the slug of the url
|
||||
// This function generate a particular page from the current slug of the url
|
||||
// The page is stored on the global variable $page
|
||||
// If the slug has not a page associacted returns FALSE and set not-found
|
||||
// If the slug has not a page associacted returns FALSE and is set not-found as true
|
||||
function buildThePage() {
|
||||
global $Url;
|
||||
global $page, $Page;
|
||||
|
@ -102,12 +105,12 @@ function buildThePage() {
|
|||
$page = $Page = buildPage( $Url->slug() );
|
||||
|
||||
// The page doesn't exist
|
||||
if($page===false) {
|
||||
if ($page===false) {
|
||||
$Url->setNotFound();
|
||||
return false;
|
||||
}
|
||||
// The page is NOT published
|
||||
elseif( $page->scheduled() || $page->draft() ) {
|
||||
elseif ( $page->scheduled() || $page->draft() ) {
|
||||
$Url->setNotFound();
|
||||
return false;
|
||||
}
|
||||
|
@ -138,7 +141,9 @@ function buildPagesByTag() {
|
|||
return buildPagesFor('tag', false, $tagKey);
|
||||
}
|
||||
|
||||
// Generate the global variables $pages and $content, defined on 69.pages.php
|
||||
// This function is only used from the rule 69.pages.php, DO NOT use this function!
|
||||
// Generate the global variables $pages / $content, defined on 69.pages.php
|
||||
// This function is use for buildPagesForHome(), buildPagesByCategory(), buildPagesByTag()
|
||||
function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
|
||||
global $dbPages;
|
||||
global $dbCategories;
|
||||
|
@ -171,9 +176,9 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
|
|||
}
|
||||
|
||||
$pages = array(); // global variable
|
||||
foreach($list as $pageKey) {
|
||||
foreach ($list as $pageKey) {
|
||||
$page = buildPage($pageKey);
|
||||
if($page!==false) {
|
||||
if ($page!==false) {
|
||||
array_push($pages, $page);
|
||||
}
|
||||
}
|
||||
|
@ -181,6 +186,39 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
|
|||
return $pages;
|
||||
}
|
||||
|
||||
// Returns an array with all the static pages as Page-Object
|
||||
// The static pages are order by position all the time
|
||||
function buildStaticPages() {
|
||||
global $dbPages;
|
||||
|
||||
$list = array();
|
||||
$staticPages = $dbPages->getStaticDB();
|
||||
foreach ($staticPages as $pageKey) {
|
||||
$staticPage = buildPage($pageKey);
|
||||
array_push($list, $staticPage);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
// Returns an array with all the parent pages as Page-Object
|
||||
// The pages are order by the settings on the system
|
||||
function buildParentPages() {
|
||||
global $dbPages;
|
||||
|
||||
$list = array();
|
||||
$pagesKey = $dbPages->getPublishedDB();
|
||||
foreach ($pagesKey as $pageKey) {
|
||||
$page = buildPage($pageKey);
|
||||
if ($page->isParent()) {
|
||||
array_push($list, $page);
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
// Generate the global variable $pagesByParent, defined on 69.pages.php
|
||||
function buildPagesByParent($publishedPages=true, $staticPages=true) {
|
||||
global $dbPages;
|
||||
|
@ -212,20 +250,8 @@ function buildPagesByParent($publishedPages=true, $staticPages=true) {
|
|||
}
|
||||
}
|
||||
|
||||
function buildStaticPages() {
|
||||
global $dbPages;
|
||||
|
||||
$tmp = array();
|
||||
$staticPages = $dbPages->getStaticDB();
|
||||
foreach ($staticPages as $pageKey) {
|
||||
$staticPage = buildPage($pageKey);
|
||||
array_push($tmp, $staticPage);
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
// Returns an Array with all pages existing on the system
|
||||
// (boolean) $allPages, TRUE returns all pages with any status, FALSE all published pages
|
||||
/*
|
||||
array(
|
||||
pageKey1 => Page object,
|
||||
|
@ -263,7 +289,7 @@ function buildAllpages($publishedPages=true, $staticPages=true, $draftPages=true
|
|||
return $tmp;
|
||||
}
|
||||
|
||||
// Returns the plugin Object if is enabled and installed, FALSE otherwise
|
||||
// Returns the Plugin-Object if is enabled and installed, FALSE otherwise
|
||||
function getPlugin($pluginClassName) {
|
||||
global $plugins;
|
||||
|
||||
|
|
|
@ -435,6 +435,12 @@ class Page {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Returns TRUE if the page is a parent, has or not children
|
||||
public function isParent()
|
||||
{
|
||||
return $this->parentKey()===false;
|
||||
}
|
||||
|
||||
// Returns the parent method output, if the page doesn't have a parent returns FALSE
|
||||
public function parentMethod($method)
|
||||
{
|
||||
|
@ -447,19 +453,26 @@ class Page {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Returns TURE if the page has a parent, FALSE otherwise
|
||||
public function hasParent()
|
||||
{
|
||||
return $this->parentKey()!==false;
|
||||
}
|
||||
|
||||
// Returns TRUE if the page is a child, FALSE otherwise
|
||||
public function isChild()
|
||||
{
|
||||
return $this->parentKey()!==false;
|
||||
}
|
||||
|
||||
// Returns an array with all children as page-object
|
||||
// Returns TRUE if the page has children
|
||||
public function hasChildren()
|
||||
{
|
||||
$childrenKeys = $this->childrenKeys();
|
||||
return !empty($childrenKeys);
|
||||
}
|
||||
|
||||
// Returns an array with all children's keys
|
||||
public function childrenKeys()
|
||||
{
|
||||
return $this->getValue('childrenKeys');
|
||||
}
|
||||
|
||||
// Returns an array with all children as Page-Object
|
||||
public function children()
|
||||
{
|
||||
$list = array();
|
||||
|
@ -472,32 +485,6 @@ class Page {
|
|||
return $list;
|
||||
}
|
||||
|
||||
// Returns an array with all children's keys
|
||||
public function childrenKeys()
|
||||
{
|
||||
return $this->getValue('childrenKeys');
|
||||
}
|
||||
|
||||
// Returns an array with all children's key
|
||||
public function subpagesKeys()
|
||||
{
|
||||
return $this->childrenKeys();
|
||||
}
|
||||
|
||||
// Returns TRUE if the page has children
|
||||
public function hasSubpages()
|
||||
{
|
||||
$subpages = $this->subpages();
|
||||
return !empty($subpages);
|
||||
}
|
||||
|
||||
// Returns TRUE if the page is a parent
|
||||
public function isParent()
|
||||
{
|
||||
return $this->hasSubpages();
|
||||
}
|
||||
|
||||
|
||||
// Returns relative time (e.g. "1 minute ago")
|
||||
// Based on http://stackoverflow.com/a/18602474
|
||||
// Modified for Bludit
|
||||
|
|
|
@ -1,32 +1,26 @@
|
|||
<nav class="col-md-2 d-none d-md-block bg-light sidebar">
|
||||
<div class="sidebar-sticky">
|
||||
<?php
|
||||
// Get all pages published
|
||||
$pagesKeys = $dbPages->getPublishedDB();
|
||||
foreach ($pagesKeys as $pageKey) {
|
||||
// Build the page
|
||||
$page = buildPage($pageKey);
|
||||
// If the page is not a child this means the page is parent-page
|
||||
if (!$page->isChild()) {
|
||||
echo '<h6>'.$page->title().'</h6>';
|
||||
// Get all parent pages
|
||||
$parents = buildParentPages();
|
||||
foreach ($parents as $parent) {
|
||||
// Print the parent page title
|
||||
echo '<h6>'.$parent->title().'</h6>';
|
||||
|
||||
// Check if the parent page has children
|
||||
if ($parent->hasChildren()) {
|
||||
// Get the list of children
|
||||
$children = $parent->children();
|
||||
|
||||
// Get all children of the page
|
||||
$childrenKeys = $page->children();
|
||||
// Check if the page has children
|
||||
if ($childrenKeys!==false) {
|
||||
// Foreach child
|
||||
echo '<ul class="nav flex-column">';
|
||||
foreach ($childrenKeys as $childKey) {
|
||||
// Build the child
|
||||
$pageChild = buildPage($childKey);
|
||||
foreach ($children as $child) {
|
||||
echo '<li class="nav-item">';
|
||||
echo '<a class="nav-link active" href="'.$pageChild->permalink().'">'.$pageChild->title().'</a>';
|
||||
echo '<a class="nav-link active" href="'.$child->permalink().'">'.$child->title().'</a>';
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</nav>
|
Loading…
Reference in New Issue