page parents
This commit is contained in:
parent
e858f15f47
commit
6e7613b181
@ -93,8 +93,8 @@ define('SALT_LENGTH', 8);
|
|||||||
// Page brake string
|
// Page brake string
|
||||||
define('PAGE_BREAK', '<!-- pagebreak -->');
|
define('PAGE_BREAK', '<!-- pagebreak -->');
|
||||||
|
|
||||||
// No parent character, md5('No parent')
|
// Parent key for the array $pagesByParents
|
||||||
define('NO_PARENT_CHAR', '3849abb4cb7abd24c2d8dac17b216f17');
|
define('PARENT', 'BLUDIT3849abb4cb7abd24c2d8dac17b216f17');
|
||||||
|
|
||||||
// Items per page for admin area
|
// Items per page for admin area
|
||||||
define('ITEMS_PER_PAGE_ADMIN', 10);
|
define('ITEMS_PER_PAGE_ADMIN', 10);
|
||||||
|
@ -4,17 +4,23 @@
|
|||||||
// Variables
|
// Variables
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// Array with all published pages
|
// Array with pages, each page is a Object Page
|
||||||
$pages = array();
|
$pages = array();
|
||||||
|
|
||||||
// Array with all pages (published, fixed, sticky, draft, scheduled)
|
// Page filtered by the user, is a Object Page
|
||||||
$allPages = array();
|
|
||||||
|
|
||||||
// Object Page for the page filtered by the user
|
|
||||||
$page = $Page = false;
|
$page = $Page = false;
|
||||||
|
|
||||||
// Array with all page parents published
|
// Array with pages order by parent
|
||||||
//$pageParents = array();
|
/*
|
||||||
|
array(
|
||||||
|
PARENT => array(), // all parent pages
|
||||||
|
parentKey1 => array(), // all children of parentKey1
|
||||||
|
parentKey2 => array(), // all children of parentKey2
|
||||||
|
...
|
||||||
|
parentKeyN => array(), // all children of parentKeyN
|
||||||
|
)
|
||||||
|
*/
|
||||||
|
$pagesByParent = array(PARENT=>array());
|
||||||
|
|
||||||
// Array with all published pages, the array is a key=>Page-object
|
// Array with all published pages, the array is a key=>Page-object
|
||||||
$pagesByKey = array();
|
$pagesByKey = array();
|
||||||
@ -40,7 +46,6 @@ if( $dbPages->scheduler() ) {
|
|||||||
|
|
||||||
// Build specific page
|
// Build specific page
|
||||||
if( $Url->whereAmI()==='page' ) {
|
if( $Url->whereAmI()==='page' ) {
|
||||||
|
|
||||||
// Build the page
|
// Build the page
|
||||||
$page = $Page = buildPage( $Url->slug() );
|
$page = $Page = buildPage( $Url->slug() );
|
||||||
|
|
||||||
@ -48,7 +53,7 @@ if( $Url->whereAmI()==='page' ) {
|
|||||||
if($page===false) {
|
if($page===false) {
|
||||||
$Url->setNotFound(true);
|
$Url->setNotFound(true);
|
||||||
}
|
}
|
||||||
// The page is not published, still scheduled or draft
|
// The page is not published, scheduled or draft
|
||||||
elseif( $page->scheduled() || $page->draft() ) {
|
elseif( $page->scheduled() || $page->draft() ) {
|
||||||
$Url->setNotFound(true);
|
$Url->setNotFound(true);
|
||||||
}
|
}
|
||||||
@ -69,6 +74,11 @@ elseif( $Url->whereAmI()==='admin' ) {
|
|||||||
buildPagesForAdmin();
|
buildPagesForAdmin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ORDER_BY==='position') {
|
||||||
|
$allPages = false; // All pages are published, draft, scheduled
|
||||||
|
buildPagesByParent(false);
|
||||||
|
}
|
||||||
|
|
||||||
// Set page 404 not found
|
// Set page 404 not found
|
||||||
if( $Url->notFound() ) {
|
if( $Url->notFound() ) {
|
||||||
$Url->setWhereAmI('page');
|
$Url->setWhereAmI('page');
|
||||||
|
@ -307,6 +307,7 @@ class dbPages extends dbJSON
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns an array with a list of pages
|
// Returns an array with a list of pages
|
||||||
|
// The database is sorted by date or by position
|
||||||
// (int) $pageNumber, the page number
|
// (int) $pageNumber, the page number
|
||||||
// (int) $amountOfItems, amount of items to return
|
// (int) $amountOfItems, amount of items to return
|
||||||
// (boolean) $onlyPublished, TRUE to return only published pages
|
// (boolean) $onlyPublished, TRUE to return only published pages
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||||
|
|
||||||
// (object) Returns a Page object, the class is page.class.php, FALSE if something fail to load the page
|
// (object) 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;
|
||||||
global $dbCategories;
|
global $dbCategories;
|
||||||
@ -140,6 +139,7 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false)
|
|||||||
if($page!==false) {
|
if($page!==false) {
|
||||||
// $pagesByKey
|
// $pagesByKey
|
||||||
$pagesByKey[$pageKey] = $page;
|
$pagesByKey[$pageKey] = $page;
|
||||||
|
|
||||||
// $pages
|
// $pages
|
||||||
array_push($pages, $page);
|
array_push($pages, $page);
|
||||||
}
|
}
|
||||||
@ -147,6 +147,30 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false)
|
|||||||
return $pages;
|
return $pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildPagesByParent($allPages=true) {
|
||||||
|
global $dbPages;
|
||||||
|
global $pagesByParent;
|
||||||
|
|
||||||
|
$keys = array_keys($dbPages->db);
|
||||||
|
foreach($keys as $pageKey) {
|
||||||
|
$page = buildPage($pageKey);
|
||||||
|
if($page!==false) {
|
||||||
|
if($allPages || $page->published()) {
|
||||||
|
$parentKey = $page->parentKey();
|
||||||
|
// FALSE if the page is parent
|
||||||
|
if($parentKey===false) {
|
||||||
|
array_push($pagesByParent[PARENT], $page);
|
||||||
|
} else {
|
||||||
|
if( !isset($pagesByParent[$parentKey]) ) {
|
||||||
|
$pagesByParent[$parentKey] = array();
|
||||||
|
}
|
||||||
|
array_push($pagesByParent[$parentKey], $page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Returns TRUE if the plugin is enabled, FALSE otherwise
|
// Returns TRUE if the plugin is enabled, FALSE otherwise
|
||||||
function pluginEnabled($pluginName) {
|
function pluginEnabled($pluginName) {
|
||||||
global $plugins;
|
global $plugins;
|
||||||
|
@ -240,47 +240,6 @@ class Page {
|
|||||||
return $this->getValue('description');
|
return $this->getValue('description');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Returns relative time (e.g. "1 minute ago")
|
|
||||||
// Based on http://stackoverflow.com/a/18602474
|
|
||||||
// Modified for Bludit
|
|
||||||
// $complete = false : short version
|
|
||||||
// $complete = true : full version
|
|
||||||
public function relativeTime($complete = false) {
|
|
||||||
$current = new DateTime;
|
|
||||||
$past = new DateTime($this->getValue('date'));
|
|
||||||
$elapsed = $current->diff($past);
|
|
||||||
|
|
||||||
$elapsed->w = floor($elapsed->d / 7);
|
|
||||||
$elapsed->d -= $elapsed->w * 7;
|
|
||||||
|
|
||||||
$string = array(
|
|
||||||
'y' => 'year',
|
|
||||||
'm' => 'month',
|
|
||||||
'w' => 'week',
|
|
||||||
'd' => 'day',
|
|
||||||
'h' => 'hour',
|
|
||||||
'i' => 'minute',
|
|
||||||
's' => 'second',
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach($string as $key => &$value) {
|
|
||||||
if($elapsed->$key) {
|
|
||||||
$value = $elapsed->$key . ' ' . $value . ($elapsed->$key > 1 ? 's' : ' ');
|
|
||||||
} else {
|
|
||||||
unset($string[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$complete) {
|
|
||||||
$string = array_slice($string, 0 , 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $string ? implode(', ', $string) . ' ago' : 'Just now';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the tags
|
// Returns the tags
|
||||||
// (boolean) $returnsArray, TRUE to get the tags as an array, FALSE to get the tags separeted by comma
|
// (boolean) $returnsArray, TRUE to get the tags as an array, FALSE to get the tags separeted by comma
|
||||||
public function tags($returnsArray=false)
|
public function tags($returnsArray=false)
|
||||||
@ -302,8 +261,6 @@ class Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function json($returnsArray=false)
|
public function json($returnsArray=false)
|
||||||
{
|
{
|
||||||
$tmp['key'] = $this->key();
|
$tmp['key'] = $this->key();
|
||||||
@ -456,4 +413,44 @@ class Page {
|
|||||||
return $tmp;
|
return $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Returns relative time (e.g. "1 minute ago")
|
||||||
|
// Based on http://stackoverflow.com/a/18602474
|
||||||
|
// Modified for Bludit
|
||||||
|
// $complete = false : short version
|
||||||
|
// $complete = true : full version
|
||||||
|
public function relativeTime($complete = false) {
|
||||||
|
$current = new DateTime;
|
||||||
|
$past = new DateTime($this->getValue('date'));
|
||||||
|
$elapsed = $current->diff($past);
|
||||||
|
|
||||||
|
$elapsed->w = floor($elapsed->d / 7);
|
||||||
|
$elapsed->d -= $elapsed->w * 7;
|
||||||
|
|
||||||
|
$string = array(
|
||||||
|
'y' => 'year',
|
||||||
|
'm' => 'month',
|
||||||
|
'w' => 'week',
|
||||||
|
'd' => 'day',
|
||||||
|
'h' => 'hour',
|
||||||
|
'i' => 'minute',
|
||||||
|
's' => 'second',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach($string as $key => &$value) {
|
||||||
|
if($elapsed->$key) {
|
||||||
|
$value = $elapsed->$key . ' ' . $value . ($elapsed->$key > 1 ? 's' : ' ');
|
||||||
|
} else {
|
||||||
|
unset($string[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$complete) {
|
||||||
|
$string = array_slice($string, 0 , 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $string ? implode(', ', $string) . ' ago' : 'Just now';
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -47,6 +47,7 @@ class pluginPages extends Plugin {
|
|||||||
global $Url;
|
global $Url;
|
||||||
global $Site;
|
global $Site;
|
||||||
global $dbPages;
|
global $dbPages;
|
||||||
|
global $pagesByParent;
|
||||||
|
|
||||||
// Amount of pages to show
|
// Amount of pages to show
|
||||||
$amountOfItems = $this->getValue('amountOfItems');
|
$amountOfItems = $this->getValue('amountOfItems');
|
||||||
@ -66,6 +67,28 @@ class pluginPages extends Plugin {
|
|||||||
$html .= '<div class="plugin-content">';
|
$html .= '<div class="plugin-content">';
|
||||||
$html .= '<ul>';
|
$html .= '<ul>';
|
||||||
|
|
||||||
|
if(ORDER_BY==='position') {
|
||||||
|
foreach($pagesByParent[PARENT] as $parent) {
|
||||||
|
$html .= '<li class="parent">';
|
||||||
|
$html .= '<h3>';
|
||||||
|
$html .= $parent->title();
|
||||||
|
$html .= '</h3>';
|
||||||
|
|
||||||
|
if(!empty($pagesByParent[$parent->key()])) {
|
||||||
|
$html .= '<ul class="child">';
|
||||||
|
foreach($pagesByParent[$parent->key()] as $child) {
|
||||||
|
$html .= '<li class="child">';
|
||||||
|
$html .= '<a class="child" href="'.$child->permalink().'">';
|
||||||
|
$html .= $child->title();
|
||||||
|
$html .= '</a>';
|
||||||
|
$html .= '</li>';
|
||||||
|
}
|
||||||
|
$html .= '</ul>';
|
||||||
|
}
|
||||||
|
$html .= '</li>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
// Show Home page link
|
// Show Home page link
|
||||||
if( $this->getValue('homeLink') ) {
|
if( $this->getValue('homeLink') ) {
|
||||||
$html .= '<li>';
|
$html .= '<li>';
|
||||||
@ -86,6 +109,7 @@ class pluginPages extends Plugin {
|
|||||||
$html .= '</a>';
|
$html .= '</a>';
|
||||||
$html .= '</li>';
|
$html .= '</li>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$html .= '</ul>';
|
$html .= '</ul>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
6
bl-themes/docs/css/grids-responsive-min.css
vendored
6
bl-themes/docs/css/grids-responsive-min.css
vendored
File diff suppressed because one or more lines are too long
6
bl-themes/docs/css/pure-min.css
vendored
6
bl-themes/docs/css/pure-min.css
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,42 +1,28 @@
|
|||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// CSS from theme/css/
|
echo Theme::charset('utf-8');
|
||||||
Theme::css(array(
|
echo Theme::viewport('width=device-width, initial-scale=1, user-scalable=no');
|
||||||
'pure-min.css',
|
|
||||||
'grids-responsive-min.css',
|
|
||||||
'blog.css',
|
|
||||||
'rainbow.github.css'
|
|
||||||
));
|
|
||||||
|
|
||||||
// Javascript from theme/js/
|
echo Theme::headTitle();
|
||||||
Theme::javascript('rainbow.min.js');
|
echo Theme::headDescription();
|
||||||
|
|
||||||
// <meta name="keywords" content="HTML,CSS,XML,JavaScript">
|
echo Theme::favicon('img/favicon.png');
|
||||||
if( $Url->whereAmI()=='page' ) {
|
|
||||||
Theme::keywords( $Page->tags() );
|
echo Theme::css('css/pure-min.css');
|
||||||
Theme::description( $Page->description() );
|
echo Theme::css('css/grids-responsive-min.css');
|
||||||
echo '<title>'.$Page->title().' - '.$Site->title().'</title>';
|
echo Theme::css('css/blog.css');
|
||||||
}
|
echo Theme::css('css/rainbow.github.css');
|
||||||
else {
|
|
||||||
Theme::description( $Site->description() );
|
echo Theme::js('js/rainbow.min.js');
|
||||||
echo '<title>'.$Site->title().'</title>';
|
|
||||||
}
|
// Load plugins with the hook siteHead
|
||||||
|
Theme::plugins('siteHead');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<link rel="shortcut icon" href="<?php echo HTML_PATH_THEME ?>img/favicon.png" type="image/png">
|
|
||||||
|
|
||||||
<!-- Custom Fonts -->
|
|
||||||
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600&subset=latin,cyrillic-ext,greek-ext,greek,vietnamese,cyrillic,latin-ext" rel="stylesheet" type="text/css">
|
|
||||||
|
|
||||||
<!-- Pure and Google Fonts -->
|
<!-- Pure and Google Fonts -->
|
||||||
|
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600&subset=latin,cyrillic-ext,greek-ext,greek,vietnamese,cyrillic,latin-ext" rel="stylesheet" type="text/css">
|
||||||
<style>
|
<style>
|
||||||
html, button, input, select, textarea,
|
html, button, input, select, textarea,
|
||||||
.pure-g [class *= "pure-u"] {
|
.pure-g [class *= "pure-u"] {
|
||||||
font-family: 'Open Sans', sans-serif;
|
font-family: 'Open Sans', sans-serif;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<!-- Plugins Site Head -->
|
|
||||||
<?php Theme::plugins('siteHead') ?>
|
|
||||||
|
@ -1,46 +1,28 @@
|
|||||||
<div class="sidebar-content">
|
<div class="sidebar-content">
|
||||||
|
|
||||||
<h1 class="title"><?php echo $Site->title() ?></h1>
|
<h1 class="title"><?php echo $Site->title() ?></h1>
|
||||||
|
|
||||||
<!-- Plugins Sidebar -->
|
|
||||||
<?php //Theme::plugins('siteSidebar') ?>
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$html = '<div class="plugin plugin-pages">';
|
$html = '<div class="plugin plugin-pages">';
|
||||||
$html .= '<div class="plugin-content">';
|
$html .= '<div class="plugin-content">';
|
||||||
$html .= '<ul>';
|
$html .= '<ul class="parent">';
|
||||||
|
|
||||||
$parents = $pagesParents[NO_PARENT_CHAR];
|
foreach($pagesByParent[PARENT] as $parent) {
|
||||||
foreach($parents as $parent)
|
$html .= '<li class="parent">';
|
||||||
{
|
|
||||||
if($parent->published())
|
|
||||||
{
|
|
||||||
// Print the parent
|
|
||||||
$html .= '<li>';
|
|
||||||
$html .= '<span class="parent">'.$parent->title().'</span>';
|
$html .= '<span class="parent">'.$parent->title().'</span>';
|
||||||
|
|
||||||
// Check if the parent has children
|
if(!empty($pagesByParent[$parent->key()])) {
|
||||||
if(isset($pagesParents[$parent->key()]))
|
$html .= '<ul class="child">';
|
||||||
{
|
foreach($pagesByParent[$parent->key()] as $child) {
|
||||||
$children = $pagesParents[$parent->key()];
|
$html .= '<li class="child">';
|
||||||
|
$html .= '<a class="child" href="'.$child->permalink().'">';
|
||||||
// Print children
|
$html .= $child->title();
|
||||||
$html .= '<ul>';
|
$html .= '</a>';
|
||||||
foreach($children as $child)
|
|
||||||
{
|
|
||||||
if($child->published())
|
|
||||||
{
|
|
||||||
$html .= '<li>';
|
|
||||||
$html .= '<a class="children" href="'.$child->permalink().'">'.$child->title().'</a>';
|
|
||||||
$html .= '</li>';
|
$html .= '</li>';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$html .= '</ul>';
|
$html .= '</ul>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= '</li>';
|
$html .= '</li>';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= '</ul>';
|
$html .= '</ul>';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user