page parents
This commit is contained in:
parent
e858f15f47
commit
6e7613b181
|
@ -93,8 +93,8 @@ define('SALT_LENGTH', 8);
|
|||
// Page brake string
|
||||
define('PAGE_BREAK', '<!-- pagebreak -->');
|
||||
|
||||
// No parent character, md5('No parent')
|
||||
define('NO_PARENT_CHAR', '3849abb4cb7abd24c2d8dac17b216f17');
|
||||
// Parent key for the array $pagesByParents
|
||||
define('PARENT', 'BLUDIT3849abb4cb7abd24c2d8dac17b216f17');
|
||||
|
||||
// Items per page for admin area
|
||||
define('ITEMS_PER_PAGE_ADMIN', 10);
|
||||
|
|
|
@ -4,17 +4,23 @@
|
|||
// Variables
|
||||
// ============================================================================
|
||||
|
||||
// Array with all published pages
|
||||
// Array with pages, each page is a Object Page
|
||||
$pages = array();
|
||||
|
||||
// Array with all pages (published, fixed, sticky, draft, scheduled)
|
||||
$allPages = array();
|
||||
|
||||
// Object Page for the page filtered by the user
|
||||
// Page filtered by the user, is a Object Page
|
||||
$page = $Page = false;
|
||||
|
||||
// Array with all page parents published
|
||||
//$pageParents = array();
|
||||
// Array with pages order by parent
|
||||
/*
|
||||
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
|
||||
$pagesByKey = array();
|
||||
|
@ -40,7 +46,6 @@ if( $dbPages->scheduler() ) {
|
|||
|
||||
// Build specific page
|
||||
if( $Url->whereAmI()==='page' ) {
|
||||
|
||||
// Build the page
|
||||
$page = $Page = buildPage( $Url->slug() );
|
||||
|
||||
|
@ -48,7 +53,7 @@ if( $Url->whereAmI()==='page' ) {
|
|||
if($page===false) {
|
||||
$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() ) {
|
||||
$Url->setNotFound(true);
|
||||
}
|
||||
|
@ -69,6 +74,11 @@ elseif( $Url->whereAmI()==='admin' ) {
|
|||
buildPagesForAdmin();
|
||||
}
|
||||
|
||||
if(ORDER_BY==='position') {
|
||||
$allPages = false; // All pages are published, draft, scheduled
|
||||
buildPagesByParent(false);
|
||||
}
|
||||
|
||||
// Set page 404 not found
|
||||
if( $Url->notFound() ) {
|
||||
$Url->setWhereAmI('page');
|
||||
|
|
|
@ -307,6 +307,7 @@ class dbPages extends dbJSON
|
|||
}
|
||||
|
||||
// Returns an array with a list of pages
|
||||
// The database is sorted by date or by position
|
||||
// (int) $pageNumber, the page number
|
||||
// (int) $amountOfItems, amount of items to return
|
||||
// (boolean) $onlyPublished, TRUE to return only published pages
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<?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
|
||||
function buildPage($key)
|
||||
{
|
||||
function buildPage($key) {
|
||||
global $dbPages;
|
||||
global $dbUsers;
|
||||
global $dbCategories;
|
||||
|
@ -140,6 +139,7 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false)
|
|||
if($page!==false) {
|
||||
// $pagesByKey
|
||||
$pagesByKey[$pageKey] = $page;
|
||||
|
||||
// $pages
|
||||
array_push($pages, $page);
|
||||
}
|
||||
|
@ -147,6 +147,30 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false)
|
|||
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
|
||||
function pluginEnabled($pluginName) {
|
||||
global $plugins;
|
||||
|
|
|
@ -240,47 +240,6 @@ class Page {
|
|||
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
|
||||
// (boolean) $returnsArray, TRUE to get the tags as an array, FALSE to get the tags separeted by comma
|
||||
public function tags($returnsArray=false)
|
||||
|
@ -302,8 +261,6 @@ class Page {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function json($returnsArray=false)
|
||||
{
|
||||
$tmp['key'] = $this->key();
|
||||
|
@ -456,4 +413,44 @@ class Page {
|
|||
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 $Site;
|
||||
global $dbPages;
|
||||
global $pagesByParent;
|
||||
|
||||
// Amount of pages to show
|
||||
$amountOfItems = $this->getValue('amountOfItems');
|
||||
|
@ -66,6 +67,28 @@ class pluginPages extends Plugin {
|
|||
$html .= '<div class="plugin-content">';
|
||||
$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
|
||||
if( $this->getValue('homeLink') ) {
|
||||
$html .= '<li>';
|
||||
|
@ -86,6 +109,7 @@ class pluginPages extends Plugin {
|
|||
$html .= '</a>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '</ul>';
|
||||
$html .= '</div>';
|
||||
|
|
File diff suppressed because one or more lines are too long
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
|
||||
// CSS from theme/css/
|
||||
Theme::css(array(
|
||||
'pure-min.css',
|
||||
'grids-responsive-min.css',
|
||||
'blog.css',
|
||||
'rainbow.github.css'
|
||||
));
|
||||
echo Theme::charset('utf-8');
|
||||
echo Theme::viewport('width=device-width, initial-scale=1, user-scalable=no');
|
||||
|
||||
// Javascript from theme/js/
|
||||
Theme::javascript('rainbow.min.js');
|
||||
echo Theme::headTitle();
|
||||
echo Theme::headDescription();
|
||||
|
||||
// <meta name="keywords" content="HTML,CSS,XML,JavaScript">
|
||||
if( $Url->whereAmI()=='page' ) {
|
||||
Theme::keywords( $Page->tags() );
|
||||
Theme::description( $Page->description() );
|
||||
echo '<title>'.$Page->title().' - '.$Site->title().'</title>';
|
||||
}
|
||||
else {
|
||||
Theme::description( $Site->description() );
|
||||
echo '<title>'.$Site->title().'</title>';
|
||||
}
|
||||
echo Theme::favicon('img/favicon.png');
|
||||
|
||||
echo Theme::css('css/pure-min.css');
|
||||
echo Theme::css('css/grids-responsive-min.css');
|
||||
echo Theme::css('css/blog.css');
|
||||
echo Theme::css('css/rainbow.github.css');
|
||||
|
||||
echo Theme::js('js/rainbow.min.js');
|
||||
|
||||
// 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 -->
|
||||
<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>
|
||||
html, button, input, select, textarea,
|
||||
.pure-g [class *= "pure-u"] {
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- Plugins Site Head -->
|
||||
<?php Theme::plugins('siteHead') ?>
|
||||
|
|
|
@ -1,47 +1,29 @@
|
|||
<div class="sidebar-content">
|
||||
|
||||
<h1 class="title"><?php echo $Site->title() ?></h1>
|
||||
|
||||
<!-- Plugins Sidebar -->
|
||||
<?php //Theme::plugins('siteSidebar') ?>
|
||||
|
||||
<?php
|
||||
|
||||
$html = '<div class="plugin plugin-pages">';
|
||||
$html .= '<div class="plugin-content">';
|
||||
$html .= '<ul>';
|
||||
$html .= '<ul class="parent">';
|
||||
|
||||
$parents = $pagesParents[NO_PARENT_CHAR];
|
||||
foreach($parents as $parent)
|
||||
{
|
||||
if($parent->published())
|
||||
{
|
||||
// Print the parent
|
||||
$html .= '<li>';
|
||||
foreach($pagesByParent[PARENT] as $parent) {
|
||||
$html .= '<li class="parent">';
|
||||
$html .= '<span class="parent">'.$parent->title().'</span>';
|
||||
|
||||
// Check if the parent has children
|
||||
if(isset($pagesParents[$parent->key()]))
|
||||
{
|
||||
$children = $pagesParents[$parent->key()];
|
||||
|
||||
// Print children
|
||||
$html .= '<ul>';
|
||||
foreach($children as $child)
|
||||
{
|
||||
if($child->published())
|
||||
{
|
||||
$html .= '<li>';
|
||||
$html .= '<a class="children" href="'.$child->permalink().'">'.$child->title().'</a>';
|
||||
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>';
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '</ul>';
|
||||
$html .= '</div>';
|
||||
|
|
Loading…
Reference in New Issue