1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 01:19:44 +01:00

Book and Chapter shortcodes now function on the Page template.

This commit is contained in:
Cameron 2014-01-15 07:02:10 -08:00
parent 2e29e5bef4
commit dc2494ad30
2 changed files with 167 additions and 7 deletions

View File

@ -18,6 +18,54 @@ if (!defined('e107_INIT')) { exit; }
class cpage_shortcodes extends e_shortcode
{
// var $var; // parsed DB values
private $chapterData = array();
// Grab all book/chapter data.
function __construct()
{
$books = e107::getDb()->retrieve("SELECT * FROM #page_chapters ORDER BY chapter_id ASC" , true);
foreach($books as $row)
{
$id = $row['chapter_id'];
$this->chapterData[$id] = $row;
}
}
// Return data for a specific chapter-id
function getChapter()
{
$id = $this->page['page_chapter'];
if(vartrue($this->chapterData[$id]['chapter_id']) && $this->chapterData[$id]['chapter_parent'] > 0)
{
return $this->chapterData[$id];
}
return false;
}
// Return data for a specific book-id
function getBook()
{
$pid = $this->page['page_chapter'];
$cid = $this->chapterData[$pid]['chapter_parent'];
$row = $this->chapterData[$cid];
if(vartrue($row['chapter_id']) && $row['chapter_parent'] < 1)
{
return $row;
}
return false; // not a book.
}
// ----------------- Shortcodes ---------------------------------------
function sc_cpagetitle($parm='')
{
@ -250,4 +298,84 @@ class cpage_shortcodes extends e_shortcode
}
// -------------------- Book - specific to the current page. -------------------------
function sc_book_name()
{
$tp = e107::getParser();
$row = $this->getBook();
return $tp->toHtml($row['chapter_name'], false, 'TITLE');
}
function sc_book_anchor()
{
$frm = e107::getForm();
$row = $this->getBook();
return $frm->name2id($row['chapter_name']);
}
function sc_book_icon()
{
$tp = e107::getParser();
$row = $this->getBook();
return $tp->toIcon($row['chapter_icon']);
}
function sc_book_description()
{
$tp = e107::getParser();
$row = $this->getBook();
return $tp->toHtml($row['chapter_meta_description'], true, 'BODY');
}
// -------------------- Chapter - specific to the current page. -------------------------
function sc_chapter_name()
{
$tp = e107::getParser();
$row = $this->getChapter();
return $tp->toHtml($row['chapter_name'], false, 'TITLE');
}
function sc_chapter_anchor()
{
$frm = e107::getForm();
$row = $this->getChapter();
return $frm->name2id($row['chapter_name']);
}
function sc_chapter_icon()
{
$tp = e107::getParser();
$row = $this->getChapter();
return $tp->toIcon($row['chapter_icon']);
}
function sc_chapter_description()
{
$tp = e107::getParser();
$row = $this->getChapter();
return $tp->toHtml($row['chapter_meta_description'], true, 'BODY');
}
}

View File

@ -92,6 +92,9 @@ class pageClass
public $cacheTitleString; /* current page title and comment flag cache string */
public $cacheData = null; /* cache data */
protected $chapterSef; /* authorized status */
protected $chapterParent;
protected $chapterData = array();
function __construct($debug=FALSE)
{
@ -142,8 +145,10 @@ class pageClass
foreach($books as $row)
{
$id = $row['chapter_id'];
$this->chapterSef[$id] = $row['chapter_sef'];
$id = $row['chapter_id'];
// $this->chapterSef[$id] = $row['chapter_sef'];
// $this->chapterParent[$id] = $row['chapter_parent'];
$this->chapterData[$id] = $row;
}
}
@ -177,7 +182,27 @@ class pageClass
private function getSef($chapter)
{
return varset($this->chapterSef[$chapter],'--sef-not-assigned--');
return vartrue($this->chapterData[$chapter]['chapter_sef'],'--sef-not-assigned--');
}
private function getParent($chapter)
{
return varset($this->chapterData[$chapter]['chapter_parent'], false);
}
private function getName($chapter)
{
return varset($this->chapterData[$chapter]['chapter_name'], false);
}
private function getDescription($chapter)
{
return varset($this->chapterData[$chapter]['chapter_meta_description'], false);
}
private function getIcon($chapter)
{
return varset($this->chapterData[$chapter]['chapter_icon'], false);
}
/**
@ -276,15 +301,22 @@ class pageClass
{
$tmp = $this->listPages(intval($row['chapter_id']));
$row['book_sef'] = $this->getSef($row['chapter_parent']);
$pages = ($tmp['text']);
$row['book_sef'] = $this->getSef($row['chapter_parent']);
$row['book_name'] = $this->getName($row['chapter_parent']);
$row['book_icon'] = $this->getIcon($row['chapter_parent']);
$row['book_description'] = $this->getDescription($row['chapter_parent']);
$var = array(
'BOOK_NAME' => $tp->toHtml($row['book_name']),
'BOOK_ANCHOR' => $frm->name2id($row['book_name']),
'BOOK_ICON' => $this->chapterIcon($row['book_icon']),
'BOOK_DESCRIPTION' => $tp->toHtml($row['book_description'],true,'BODY'),
'CHAPTER_NAME' => $tp->toHtml($row['chapter_name']),
'CHAPTER_ANCHOR' => $frm->name2id($row['chapter_name']),
'CHAPTER_ICON' => $this->chapterIcon($row['chapter_icon']),
'CHAPTER_DESCRIPTION' => $tp->toHtml($row['chapter_meta_description'],true,'BODY'),
'PAGES' => $pages,
'PAGES' => $tmp['text'],
'CHAPTER_URL' => e107::getUrl()->create('page/chapter/index', $row,'allow=chapter_id,chapter_sef,book_sef') // e_BASE."page.php?ch=".intval($row['chapter_id']) // FIXME SEF-URL
);