1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Page Navigation work.

This commit is contained in:
Cameron
2017-10-17 16:22:56 -07:00
parent eac0ad60fb
commit 898e081656
6 changed files with 240 additions and 51 deletions

View File

@@ -769,6 +769,30 @@ class e107_db_debug {
} }
} }
/**
* var_dump to debug log
* @param mixed $message
*/
function dump($message, $TraceLev= 1)
{
ob_start();
var_dump($message);
$content = ob_get_contents();
ob_end_clean();
$bt = debug_backtrace();
$this->aLog[] = array(
'Message' => $content,
'Function' => (isset($bt[$TraceLev]['type']) && ($bt[$TraceLev]['type'] == '::' || $bt[$TraceLev]['type'] == '->') ? $bt[$TraceLev]['class'].$bt[$TraceLev]['type'].$bt[$TraceLev]['function'].'()' : $bt[$TraceLev]['function']).'()',
'File' => varset($bt[$TraceLev]['file']),
'Line' => varset($bt[$TraceLev]['line'])
);
// $this->aLog[] = array ('Message' => $content, 'Function' => '', 'File' => '', 'Line' => '' );
}
// //
// Simple debug-level 'console' log // Simple debug-level 'console' log
// Record a "nice" debug message with // Record a "nice" debug message with
@@ -777,6 +801,8 @@ class e107_db_debug {
function log($message,$TraceLev=1) function log($message,$TraceLev=1)
{ {
if(is_array($message) || is_object($message)) if(is_array($message) || is_object($message))
{ {
$message = "<pre>".print_r($message,true)."</pre>"; $message = "<pre>".print_r($message,true)."</pre>";

View File

@@ -1805,7 +1805,7 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; }
return true; return true;
} }
if(vartrue($data['link_active'])) // Can be used by e_sitelink.php if(!empty($data['link_active'])) // Can be used by e_sitelink.php
{ {
return true; return true;
} }
@@ -1894,9 +1894,9 @@ class navigation_shortcodes extends e_shortcode
*/ */
function sc_link_name($parm='') function sc_link_name($parm='')
{ {
if(!varset($this->var['link_name'])) if(empty($this->var['link_name']))
{ {
return; return null;
} }
if(substr($this->var['link_name'],0,8) == 'submenu.') // BC Fix. if(substr($this->var['link_name'],0,8) == 'submenu.') // BC Fix.
@@ -2024,7 +2024,7 @@ class navigation_shortcodes extends e_shortcode
{ {
$tp = e107::getParser(); $tp = e107::getParser();
if (!vartrue($this->var['link_button'])) return ''; if (empty($this->var['link_button'])) return '';
// if($icon = $tp->toGlyph($this->var['link_button'])) // if($icon = $tp->toGlyph($this->var['link_button']))
// { // {
@@ -2089,7 +2089,7 @@ class navigation_shortcodes extends e_shortcode
{ {
$active = (e107::getNav()->isActive($val, $this->activeSubFound, true)) ? "_active" : ""; $active = (e107::getNav()->isActive($val, $this->activeSubFound, true)) ? "_active" : "";
$this->setVars($val); // isActive is allowed to alter data $this->setVars($val); // isActive is allowed to alter data
$tmpl = vartrue($val['link_sub']) ? varset($this->template['submenu_loweritem'.$active]) : varset($this->template['submenu_item'.$active]); $tmpl = !empty($val['link_sub']) ? varset($this->template['submenu_loweritem'.$active]) : varset($this->template['submenu_item'.$active]);
$text .= e107::getParser()->parseTemplate($tmpl, TRUE, $this); $text .= e107::getParser()->parseTemplate($tmpl, TRUE, $this);
if($active) $this->activeSubFound = true; if($active) $this->activeSubFound = true;
} }

View File

@@ -0,0 +1,61 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2015 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*
*/
if (!defined('e107_INIT')) { exit; }
//v2.x Standard for extending menu configuration within Menu Manager. (replacement for v1.x config.php)
// TODO add fields
class page_menu
{
function __construct()
{
// e107::lan('_blank','menu',true); // English_menu.php or {LANGUAGE}_menu.php
}
/**
* Configuration Fields.
* @return array
*/
public function config($menu='')
{
$fields = array();
$fields['caption'] = array('title'=> LAN_CAPTION, 'type'=>'text', 'multilan'=>true, 'writeParms'=>array('size'=>'xxlarge'));
// $fields['blankCount'] = array('title'=> "Enabled", 'type'=>'number');
// $fields['blankCustom'] = array('title'=> "Enabled", 'type'=>'method'); // see below.
return $fields;
}
}
// optional - for when using custom methods above.
/*
class _blank_menu_form extends e_form
{
function blankCustom($curVal)
{
$frm = e107::getForm();
$opts = array(1,2,3,4);
$frm->select('blankCustom', $opts, $curVal);
}
}*/
?>

View File

@@ -41,7 +41,7 @@ class page_shortcodes extends e_shortcode
* Page Navigation * Page Navigation
* @example {PAGE_NAVIGATION: template=navdoc&auto=1} in your Theme template. * @example {PAGE_NAVIGATION: template=navdoc&auto=1} in your Theme template.
*/ */
function sc_page_navigation($parm='') // TODO when No $parm provided, auto-detect based on URL which book/chapters to display. function sc_page_navigation($parm=null) // TODO when No $parm provided, auto-detect based on URL which book/chapters to display.
{ {
// $parm = eHelper::scParams($parm); // $parm = eHelper::scParams($parm);
@@ -102,7 +102,7 @@ class page_shortcodes extends e_shortcode
$data = $data['body']; $data = $data['body'];
} }
if(empty($data)){ return; } if(empty($data)){ return null; }
return e107::getNav()->render($data, $template) ; return e107::getNav()->render($data, $template) ;

View File

@@ -15,23 +15,31 @@ class page_sitelink // include plugin-folder in the name.
{ {
private $chapterSef = array(); private $chapterSef = array();
private $chapterParent = array(); private $chapterParent = array();
private $chapterName = array();
function __construct() function __construct()
{ {
$sql = e107::getDb(); $sql = e107::getDb();
$books = $sql->retrieve("SELECT chapter_id,chapter_sef,chapter_parent FROM #page_chapters ORDER BY chapter_id ASC" , true); $books = $sql->retrieve("SELECT chapter_id,chapter_name,chapter_sef,chapter_parent FROM #page_chapters ORDER BY chapter_id ASC" , true);
foreach($books as $row) foreach($books as $row)
{ {
$id = $row['chapter_id']; $id = $row['chapter_id'];
$this->chapterSef[$id] = $row['chapter_sef']; $this->chapterSef[$id] = $row['chapter_sef'];
$this->chapterParent[$id] = $row['chapter_parent']; $this->chapterParent[$id] = $row['chapter_parent'];
$this->chapterName[$id] = $row['chapter_name'];
} }
} }
private function getName($chapter)
{
return varset($this->chapterName[$chapter], null);
}
private function getSef($chapter) private function getSef($chapter)
{ {
return vartrue($this->chapterSef[$chapter],'--sef-not-assigned--'); return vartrue($this->chapterSef[$chapter],'--sef-not-assigned--');
@@ -54,6 +62,19 @@ class page_sitelink // include plugin-folder in the name.
'description' => "A list of all books" 'description' => "A list of all books"
); );
/* // TODO - get these working.
$links[] = array(
'name' => "All Books &amp; chapters",
'function' => "bookNavChapters",
'description' => "A list of all books and their chapters"
);
$links[] = array(
'name' => "All Books, Chapters &amp; Pages",
'function' => "bookNavChaptersPages",
'description' => "A list of all books, chapters and pages"
);
*/
$books = $sql->retrieve("SELECT * FROM #page_chapters WHERE chapter_parent =0 ORDER BY chapter_order ASC" , true); $books = $sql->retrieve("SELECT * FROM #page_chapters WHERE chapter_parent =0 ORDER BY chapter_order ASC" , true);
foreach($books as $row) foreach($books as $row)
@@ -64,6 +85,13 @@ class page_sitelink // include plugin-folder in the name.
'parm' => $row['chapter_id'], 'parm' => $row['chapter_id'],
'description' => "A list of all chapters from the book ".$row['chapter_name'] 'description' => "A list of all chapters from the book ".$row['chapter_name']
); );
$links[] = array(
'name' => "All Chapters &amp; Pages from ".$row['chapter_name'],
'function' => "chapterNavPages",
'parm' => $row['chapter_id'],
'description' => "A list of all chapters and pages from the book ".$row['chapter_name']
);
} }
$chaps = $sql->retrieve("SELECT * FROM #page_chapters WHERE chapter_parent !=0 ORDER BY chapter_order ASC" , true); $chaps = $sql->retrieve("SELECT * FROM #page_chapters WHERE chapter_parent !=0 ORDER BY chapter_order ASC" , true);
@@ -91,14 +119,37 @@ class page_sitelink // include plugin-folder in the name.
/** /**
* Return a tree of all books and their chapters. * Return a tree of all books and their chapters.
*/ */
public function bookNav($book) public function bookNav($book=0)
{ {
return $this->pageNav('book=0'); $parm = array('book'=>$book);
return $this->pageNav($parm);
}
//TODO
public function bookNavChapters($book=0)
{
$parm = array('book'=>$book, 'chapters'=>true);
return $this->pageNav($parm);
}
//TODO
public function bookNavChaptersPages($book=0)
{
$parm = array('book'=>$book, 'chapters'=>true, 'pages'=>true);
return $this->pageNav($parm);
}
public function chapterNavPages($id)
{
return $this->chapterNav($id, true);
} }
public function pagesFromChapter($id) public function pagesFromChapter($id)
{ {
return $this->pageList($id); return $this->pageList($id);
} }
@@ -133,12 +184,22 @@ class page_sitelink // include plugin-folder in the name.
// $row['chapter_sef'] = '--sef-not-assigned--'; // $row['chapter_sef'] = '--sef-not-assigned--';
} }
$arr[] = array( $arr[] = $this->pageArray($row);
}
return $arr;
}
private function pageArray($row,$options=array())
{
return array(
'link_id' => $row['page_id'], 'link_id' => $row['page_id'],
'link_name' => $row['page_title'] ? $row['page_title'] : 'No title', // FIXME lan 'link_name' => $row['page_title'] ? $row['page_title'] : 'No title', // FIXME lan
'link_url' => e107::getUrl()->create('page/view', $row, array('allow' => 'page_sef,page_title,page_id,chapter_sef,book_sef')), 'link_url' => e107::getUrl()->create('page/view', $row, array('allow' => 'page_sef,page_title,page_id,chapter_sef,book_sef')),
'link_description' => '', 'link_description' => '',
// 'link_button' => $row['menu_image'], 'link_button' => (!empty($options['icon']) && $options['icon'] === 'menu_image') ? $row['menu_image'] : '',
'link_category' => '', 'link_category' => '',
'link_order' => $row['page_order'], 'link_order' => $row['page_order'],
'link_parent' => $row['page_chapter'], 'link_parent' => $row['page_chapter'],
@@ -149,31 +210,36 @@ class page_sitelink // include plugin-folder in the name.
); );
}
return $arr;
} }
/** /**
* Return a list of all chapters from a sepcific book. * Return a list of all chapters from a sepcific book.
*/ */
public function chapterNav($book) public function chapterNav($book, $loadPages=false)
{ {
$sql = e107::getDb(); $sql = e107::getDb();
$tp = e107::getParser(); $tp = e107::getParser();
if($sql->select("page_chapters", "*", "chapter_parent = ".intval($book)." AND chapter_visibility IN (".USERCLASS_LIST.") ORDER BY chapter_order ASC ")) if($sql->select("page_chapters", "*", "chapter_parent = ".intval($book)." AND chapter_visibility IN (".USERCLASS_LIST.") ORDER BY chapter_order ASC "))
{ {
$sublinks = array(); $chapters = array();
$ids = array();
while($row = $sql->fetch()) while($row = $sql->fetch())
{ {
$ids[] = $row['chapter_id'];
$id = $row['chapter_id'];
$sef = $row; $sef = $row;
$sef['chapter_sef'] = $this->getSef($row['chapter_id']); $sef['chapter_sef'] = $this->getSef($row['chapter_id']);
$sef['book_sef'] = $this->getSef($row['chapter_parent']); $sef['book_sef'] = $this->getSef($row['chapter_parent']);
$sublinks[] = array( $chapters[$id] = array(
'link_name' => $tp->toHtml($row['chapter_name'],'','TITLE'), 'link_name' => $tp->toHtml($row['chapter_name'],'','TITLE'),
'link_url' => e107::getUrl()->create('page/chapter/index', $sef), // 'page.php?ch='.$row['chapter_id'], 'link_url' => e107::getUrl()->create('page/chapter/index', $sef), // 'page.php?ch='.$row['chapter_id'],
'link_description' => '', 'link_description' => '',
@@ -183,25 +249,50 @@ class page_sitelink // include plugin-folder in the name.
'link_parent' => $row['chapter_parent'], 'link_parent' => $row['chapter_parent'],
'link_open' => '', 'link_open' => '',
'link_class' => 0, 'link_class' => 0,
'link_sub' => array(),
'link_identifier' => 'page-nav-'.intval($row['chapter_id']) // used for css id. 'link_identifier' => 'page-nav-'.intval($row['chapter_id']) // used for css id.
); );
} }
return $sublinks;
if($loadPages === true)
{
$pages = $sql->retrieve("SELECT * FROM #page WHERE page_title !='' AND page_chapter IN (".implode(",",$ids).") AND page_class IN (".USERCLASS_LIST.") ORDER BY page_order", true);
foreach($pages as $row)
{
$chap = $row['page_chapter'];
$chapters[$chap]['link_sub'][] = $this->pageArray($row);
}
// e107::getDebug()->log($pages);
}
return $chapters;
} }
} }
function pageNav($parm='') function pageNav($parm=null)
{ {
$frm = e107::getForm(); $frm = e107::getForm();
$options = array(); $options = array();
if(vartrue($parm))
if(!empty($parm))
{
if(is_string($parm))
{ {
parse_str($parm,$options); parse_str($parm,$options);
} }
$options = $parm;
}
$sql = e107::getDb(); $sql = e107::getDb();
$sublinks = array(); $sublinks = array();
$arr = array(); $arr = array();
@@ -252,6 +343,13 @@ class page_sitelink // include plugin-folder in the name.
$data = $sql->retrieve($query, true); $data = $sql->retrieve($query, true);
$_pdata = array(); $_pdata = array();
/*
if(empty($data))
{
e107::getDebug()->log($query);
e107::getDebug()->dump($data);
}
*/
foreach($data as $row) foreach($data as $row)
{ {
@@ -266,7 +364,7 @@ class page_sitelink // include plugin-folder in the name.
$row['page_sef'] = '--sef-not-assigned--'; $row['page_sef'] = '--sef-not-assigned--';
} }
$sublinks[$pid][] = $_pdata[] = array( $sublinks[$pid][] = $_pdata[] = $this->pageArray($row,$options); /* array(
'link_id' => $row['page_id'], 'link_id' => $row['page_id'],
'link_name' => $row['page_title'] ? $row['page_title'] : 'No title', // FIXME lan 'link_name' => $row['page_title'] ? $row['page_title'] : 'No title', // FIXME lan
'link_url' => e107::getUrl()->create('page/view', $row, array('allow' => 'page_sef,page_title,page_id,chapter_sef,book_sef')), 'link_url' => e107::getUrl()->create('page/view', $row, array('allow' => 'page_sef,page_title,page_id,chapter_sef,book_sef')),
@@ -280,33 +378,31 @@ class page_sitelink // include plugin-folder in the name.
'link_active' => (isset($options['cpage']) && $row['page_id'] == $options['cpage']), 'link_active' => (isset($options['cpage']) && $row['page_id'] == $options['cpage']),
'link_identifier' => 'page-nav-'.intval($row['page_id']) // used for css id. 'link_identifier' => 'page-nav-'.intval($row['page_id']) // used for css id.
); );*/
} }
$filter = "chapter_visibility IN (".USERCLASS_LIST.") " ; $filter = "chapter_visibility IN (".USERCLASS_LIST.") " ;
if(vartrue($options['chapter'])) if(!empty($options['chapter']))
{ {
//$filter = "chapter_id > ".intval($options['chapter']);
$title = $sql->retrieve('page_chapters', 'chapter_name', 'chapter_id='.intval($options['chapter']).' AND chapter_visibility IN ('.USERCLASS_LIST.')' ); $title = $sql->retrieve('page_chapters', 'chapter_name', 'chapter_id='.intval($options['chapter']).' AND chapter_visibility IN ('.USERCLASS_LIST.')' );
$outArray = array(); $outArray = array();
if(!$title) return e107::getNav()->compile($_pdata, $outArray, $options['chapter']);
if(!$title)
{
return e107::getNav()->compile($_pdata, $outArray, $options['chapter']);
}
return array('title' => $title, 'body' => e107::getNav()->compile($_pdata, $outArray, $options['chapter'])); return array('title' => $title, 'body' => e107::getNav()->compile($_pdata, $outArray, $options['chapter']));
} }
$parent = 0; $parent = 0;
$title = false; $title = false;
if(vartrue($options['book']))
if(!empty($options['book']))
{ {
// XXX discuss the idea here
//$filter = "chapter_id > ".intval($options['book']);
$filter = "chapter_parent = ".intval($options['book']); $filter = "chapter_parent = ".intval($options['book']);
$parent = intval($options['book']); $title = $this->getName($options['book']); // set the caption as main book title.
$title = $sql->retrieve('page_chapters', 'chapter_name', 'chapter_id='.intval($options['book']));
// print_a('parent='.$parent);
} }
@@ -315,7 +411,7 @@ class page_sitelink // include plugin-folder in the name.
{ {
$row['book_sef'] = $this->getSef($row['chapter_parent']); $row['book_sef'] = $this->getSef($row['chapter_parent']);
if(!vartrue($row['chapter_sef'])) if(empty($row['chapter_sef']))
{ {
$row['chapter_sef'] = '--sef-not-assigned--'; $row['chapter_sef'] = '--sef-not-assigned--';
} }
@@ -324,8 +420,6 @@ class page_sitelink // include plugin-folder in the name.
'link_id' => $row['chapter_id'], 'link_id' => $row['chapter_id'],
'link_name' => $row['chapter_name'], 'link_name' => $row['chapter_name'],
'link_url' => ($row['chapter_parent'] == 0) ? e107::getUrl()->create('page/book/index', $row) : e107::getUrl()->create('page/chapter/index', $row), // ,'page.php?bk='.$row['chapter_id'] : 'page.php?ch='.$row['chapter_id'], 'link_url' => ($row['chapter_parent'] == 0) ? e107::getUrl()->create('page/book/index', $row) : e107::getUrl()->create('page/chapter/index', $row), // ,'page.php?bk='.$row['chapter_id'] : 'page.php?ch='.$row['chapter_id'],
// 'link_url' => vartrue($row['chapter_sef'],'#'),
'link_description' => '', 'link_description' => '',
'link_button' => $row['chapter_icon'], 'link_button' => $row['chapter_icon'],
'link_category' => '', 'link_category' => '',
@@ -333,16 +427,21 @@ class page_sitelink // include plugin-folder in the name.
'link_parent' => $row['chapter_parent'], 'link_parent' => $row['chapter_parent'],
'link_open' => '', 'link_open' => '',
'link_class' => 0, 'link_class' => 0,
'link_sub' => ((empty($options['book']) || !empty($options['pages'])) && empty($options['auto'])) ? varset($sublinks[$row['chapter_id']]) : '', //XXX always test with docs template in bootstrap before changing. 'link_sub' => ((empty($options['book']) || !empty($options['pages'])) && empty($options['auto'])) ? varset($sublinks[$row['chapter_id']]) : false, //XXX always test with docs template in bootstrap before changing.
'link_active' => $row['chapter_parent'] == 0 ? isset($options['cbook']) && $options['cbook'] == $row['chapter_id'] : isset($options['cchapter']) && $options['cchapter'] == $row['chapter_id'], 'link_active' => $row['chapter_parent'] == 0 ? isset($options['cbook']) && $options['cbook'] == $row['chapter_id'] : isset($options['cchapter']) && $options['cchapter'] == $row['chapter_id'],
'link_identifier' => 'page-nav-'.intval($row['chapter_id']) // used for css id. 'link_identifier' => 'page-nav-'.intval($row['chapter_id']) // used for css id.
); );
} }
/*
if(!empty($options['book']))
{
e107::getDebug()->dump($arr);
}*/
$outArray = array(); $outArray = array();
$parent = vartrue($options['book']) ? intval($options['book']) : 0; $parent = vartrue($options['book']) ? intval($options['book']) : 0;
$ret = e107::getNav()->compile($arr, $outArray, $parent); $ret = e107::getNav()->compile($arr, $outArray, $parent);
if(!$title) return $ret; if(!$title) return $ret;

View File

@@ -20,7 +20,7 @@ $parm = eHelper::scParams($parm);
$tmpl = e107::getCoreTemplate('chapter','nav',true,true); // always merge and allow override $tmpl = e107::getCoreTemplate('chapter','nav',true,true); // always merge and allow override
$template = $tmpl['showPage']; $template = $tmpl['showPage'];
/*
$request = e107::getRegistry('core/page/request'); $request = e107::getRegistry('core/page/request');
if($request && is_array($request)) if($request && is_array($request))
{ {
@@ -58,7 +58,11 @@ if(isset($data['title']) && !vartrue($template['noAutoTitle']))
} }
if(empty($data)) return; if(empty($data)) return;
$text = e107::getNav()->render($data, $template) ; $text = e107::getNav()->render($data, $template) ;*/
$pg = new page_shortcodes;
$text = $pg->sc_page_navigation($parm);
/** /**
* Expandable menu support. * Expandable menu support.
@@ -75,4 +79,3 @@ if($expandable)
### Render ### Render
e107::getRender()->tablerender($template['caption'], $text, 'page-navigation-menu'); e107::getRender()->tablerender($template['caption'], $text, 'page-navigation-menu');
?>