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.');
|
<?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) {
|
function buildPage($key) {
|
||||||
global $dbPages;
|
global $dbPages;
|
||||||
global $dbUsers;
|
global $dbUsers;
|
||||||
|
@ -64,19 +64,22 @@ function buildPage($key) {
|
||||||
return $page;
|
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
|
// If you create/edit/remove a page is necessary regenerate the database of categories
|
||||||
function reindexCategories() {
|
function reindexCategories() {
|
||||||
global $dbCategories;
|
global $dbCategories;
|
||||||
return $dbCategories->reindex();
|
return $dbCategories->reindex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Re-index database of tags
|
||||||
|
// If you create/edit/remove a page is necessary regenerate the database of tags
|
||||||
function reindexTags() {
|
function reindexTags() {
|
||||||
global $dbTags;
|
global $dbTags;
|
||||||
return $dbTags->reindex();
|
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() {
|
function buildErrorPage() {
|
||||||
global $dbPages;
|
global $dbPages;
|
||||||
global $Language;
|
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 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
|
// 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() {
|
function buildThePage() {
|
||||||
global $Url;
|
global $Url;
|
||||||
global $page, $Page;
|
global $page, $Page;
|
||||||
|
@ -102,12 +105,12 @@ function buildThePage() {
|
||||||
$page = $Page = buildPage( $Url->slug() );
|
$page = $Page = buildPage( $Url->slug() );
|
||||||
|
|
||||||
// The page doesn't exist
|
// The page doesn't exist
|
||||||
if($page===false) {
|
if ($page===false) {
|
||||||
$Url->setNotFound();
|
$Url->setNotFound();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// The page is NOT published
|
// The page is NOT published
|
||||||
elseif( $page->scheduled() || $page->draft() ) {
|
elseif ( $page->scheduled() || $page->draft() ) {
|
||||||
$Url->setNotFound();
|
$Url->setNotFound();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +141,9 @@ function buildPagesByTag() {
|
||||||
return buildPagesFor('tag', false, $tagKey);
|
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) {
|
function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
|
||||||
global $dbPages;
|
global $dbPages;
|
||||||
global $dbCategories;
|
global $dbCategories;
|
||||||
|
@ -171,9 +176,9 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$pages = array(); // global variable
|
$pages = array(); // global variable
|
||||||
foreach($list as $pageKey) {
|
foreach ($list as $pageKey) {
|
||||||
$page = buildPage($pageKey);
|
$page = buildPage($pageKey);
|
||||||
if($page!==false) {
|
if ($page!==false) {
|
||||||
array_push($pages, $page);
|
array_push($pages, $page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,6 +186,39 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
|
||||||
return $pages;
|
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
|
// Generate the global variable $pagesByParent, defined on 69.pages.php
|
||||||
function buildPagesByParent($publishedPages=true, $staticPages=true) {
|
function buildPagesByParent($publishedPages=true, $staticPages=true) {
|
||||||
global $dbPages;
|
global $dbPages;
|
||||||
|
@ -212,20 +250,8 @@ function buildPagesByParent($publishedPages=true, $staticPages=true) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildStaticPages() {
|
// DEPRECATED
|
||||||
global $dbPages;
|
|
||||||
|
|
||||||
$tmp = array();
|
|
||||||
$staticPages = $dbPages->getStaticDB();
|
|
||||||
foreach ($staticPages as $pageKey) {
|
|
||||||
$staticPage = buildPage($pageKey);
|
|
||||||
array_push($tmp, $staticPage);
|
|
||||||
}
|
|
||||||
return $tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns an Array with all pages existing on the system
|
// Returns an Array with all pages existing on the system
|
||||||
// (boolean) $allPages, TRUE returns all pages with any status, FALSE all published pages
|
|
||||||
/*
|
/*
|
||||||
array(
|
array(
|
||||||
pageKey1 => Page object,
|
pageKey1 => Page object,
|
||||||
|
@ -263,7 +289,7 @@ function buildAllpages($publishedPages=true, $staticPages=true, $draftPages=true
|
||||||
return $tmp;
|
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) {
|
function getPlugin($pluginClassName) {
|
||||||
global $plugins;
|
global $plugins;
|
||||||
|
|
||||||
|
|
|
@ -435,6 +435,12 @@ class Page {
|
||||||
return false;
|
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
|
// Returns the parent method output, if the page doesn't have a parent returns FALSE
|
||||||
public function parentMethod($method)
|
public function parentMethod($method)
|
||||||
{
|
{
|
||||||
|
@ -447,19 +453,26 @@ class Page {
|
||||||
return false;
|
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
|
// Returns TRUE if the page is a child, FALSE otherwise
|
||||||
public function isChild()
|
public function isChild()
|
||||||
{
|
{
|
||||||
return $this->parentKey()!==false;
|
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()
|
public function children()
|
||||||
{
|
{
|
||||||
$list = array();
|
$list = array();
|
||||||
|
@ -472,32 +485,6 @@ class Page {
|
||||||
return $list;
|
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")
|
// Returns relative time (e.g. "1 minute ago")
|
||||||
// Based on http://stackoverflow.com/a/18602474
|
// Based on http://stackoverflow.com/a/18602474
|
||||||
// Modified for Bludit
|
// Modified for Bludit
|
||||||
|
|
|
@ -1,30 +1,24 @@
|
||||||
<nav class="col-md-2 d-none d-md-block bg-light sidebar">
|
<nav class="col-md-2 d-none d-md-block bg-light sidebar">
|
||||||
<div class="sidebar-sticky">
|
<div class="sidebar-sticky">
|
||||||
<?php
|
<?php
|
||||||
// Get all pages published
|
// Get all parent pages
|
||||||
$pagesKeys = $dbPages->getPublishedDB();
|
$parents = buildParentPages();
|
||||||
foreach ($pagesKeys as $pageKey) {
|
foreach ($parents as $parent) {
|
||||||
// Build the page
|
// Print the parent page title
|
||||||
$page = buildPage($pageKey);
|
echo '<h6>'.$parent->title().'</h6>';
|
||||||
// If the page is not a child this means the page is parent-page
|
|
||||||
if (!$page->isChild()) {
|
|
||||||
echo '<h6>'.$page->title().'</h6>';
|
|
||||||
|
|
||||||
// Get all children of the page
|
// Check if the parent page has children
|
||||||
$childrenKeys = $page->children();
|
if ($parent->hasChildren()) {
|
||||||
// Check if the page has children
|
// Get the list of children
|
||||||
if ($childrenKeys!==false) {
|
$children = $parent->children();
|
||||||
// Foreach child
|
|
||||||
echo '<ul class="nav flex-column">';
|
echo '<ul class="nav flex-column">';
|
||||||
foreach ($childrenKeys as $childKey) {
|
foreach ($children as $child) {
|
||||||
// Build the child
|
echo '<li class="nav-item">';
|
||||||
$pageChild = buildPage($childKey);
|
echo '<a class="nav-link active" href="'.$child->permalink().'">'.$child->title().'</a>';
|
||||||
echo '<li class="nav-item">';
|
echo '</li>';
|
||||||
echo '<a class="nav-link active" href="'.$pageChild->permalink().'">'.$pageChild->title().'</a>';
|
|
||||||
echo '</li>';
|
|
||||||
}
|
|
||||||
echo '</ul>';
|
|
||||||
}
|
}
|
||||||
|
echo '</ul>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue