1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

New SEF-URL for book/chapter/page (a few bugs remain)

This commit is contained in:
Cameron 2014-01-10 18:27:42 -08:00
parent ed5634574f
commit 7bebfc1901
6 changed files with 268 additions and 11 deletions

View File

@ -183,6 +183,11 @@ class cpage_shortcodes extends e_shortcode
return $url;
}
if(trim($this->page['page_text']) == '') // Hide the button when there is no page content. (avoids templates with and without buttons)
{
return "<!-- Button Removed: No page text exists! -->";
}
parse_str($parm,$options);
$text = vartrue($options['text'], LAN_READ_MORE);
@ -234,6 +239,8 @@ class cpage_shortcodes extends e_shortcode
function sc_cpageurl()
{
return e107::getUrl()->create('page/view', $this->page, array('allow' => 'page_sef,page_title,page_id'));
$route = ($this->page['page_chapter'] == 0) ? 'page/view/other' : 'page/view';
return e107::getUrl()->create($route, $this->page, array('allow' => 'page_sef,page_title,page_id,chapter_sef,book_sef'));
}
}

View File

@ -0,0 +1,178 @@
<?php
/**
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id$
*
* Custom page routing config
*/
if (!defined('e107_INIT')){ exit; }
class core_page_sef_chapters_url extends eUrlConfig
{
public function config()
{
return array(
'config' => array(
'allowMain' => true,
'legacy' => '{e_BASE}page.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script
'format' => 'path', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
'defaultRoute' => 'view/index',// [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
'urlSuffix' => '', // [optional] default empty; string to append to the URL (e.g. .html)
'mapVars' => array(
'page_id' => 'id',
'page_sef' => 'name',
),
'allowVars' => array(
'page',
),
),
### using only title for pages is risky enough (empty sef for old DB's)
'rules' => array(
'<book:{sefsecure}>/<chapter:{sefsecure}>/<name:{secure}>' => array('view/index', 'allowVars' => false, 'mapVars' => array('page_id'=>'id', 'page_sef'=>'name', 'chapter_sef'=>'chapter', 'book_sef'=>'book'), 'legacyQuery' => '{name}.{page}', 'parseCallback' => 'itemIdByTitle'),
'<book:{sefsecure}>/<name:{sefsecure}>' => array('chapter/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id', 'chapter_sef'=>'name', 'book_sef'=>'book'), 'legacyQuery' => 'ch={id}', 'parseCallback' => 'chapterIdByTitle'),
'<name:{sefsecure}>' => array('book/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id', 'chapter_sef'=>'name'), 'legacyQuery' => '{type}={id}', 'parseCallback' => 'chapterIdByTitle'),
'<name:{secure}>' => array('view/other', 'allowVars' => false, 'legacyQuery' => '{type}={id}', 'parseCallback' => 'chapterIdByTitle'),
'/' => array('list/index', 'legacyQuery' => '', ), // page list
)
);
}
/**
* Admin callback
* Language file not loaded as all language data is inside the lan_eurl.php (loaded by default on administration URL page)
*/
public function admin()
{
// static may be used for performance
static $admin = array(
'labels' => array(
'name' => LAN_EURL_CORE_PAGE, // Module name
'label' => LAN_EURL_PAGE_SEFNOID_LABEL, // Current profile name
'description' => LAN_EURL_PAGE_SEFNOID_DESCR, //
'examples' => array("{SITEURL}page/book-title/chapter-title/page-title")
),
'generate' => array('table'=> 'page', 'primary'=>'page_id', 'input'=>'page_title', 'output'=>'page_sef'),
'form' => array(), // Under construction - additional configuration options
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
);
return $admin;
}
### CUSTOM METHODS ###
/**
* view/item by name callback
* @param eRequest $request
*/
public function itemIdByTitle(eRequest $request)
{
$name = $request->getRequestParam('name');
// e107::getMessage()->addDebug('name = '.$name);
// e107::getMessage()->addDebug(print_r($request,true));
// e107::getAdminLog()->toFile('page_sef_noid_url');
if(($id = $request->getRequestParam('id')))
{
$request->setRequestParam('name', $id);
return;
}
elseif(!$name || is_numeric($name))
{
if(ADMIN)
{
e107::getMessage()->addError("One of your pages is missing a SEF URL value");
}
return;
}
$sql = e107::getDb('url');
$name = e107::getParser()->toDB($name);
if($sql->select('page', 'page_id', "page_sef='{$name}'")) // First check for pages.
{
$name = $sql->fetch();
//$request->setRequestParam('legacyQuery','{name}.{page}');
$request->setRequestParam('name', $name['page_id']);
e107::getMessage()->addDebug("Set PAGE ID = '".$name['page_id']."'");
}
/*
elseif($sql->select('page_chapters', 'chapter_id', "chapter_sef='{$name}'")) // First check books and chapters.
{
$name = $sql->fetch();
$request->setRequestParam('legacyQuery','ch='.$name['chapter_id']);
$request->setRequestParam('name', $name['chapter_id']);
}
*/
else
{
if(ADMIN)
{
e107::getMessage()->addError("Couldn't find a page with a SEF URL value of '".$name."'");
}
$request->setRequestParam('name', 0);
}
}
/**
* chapter/index and book/index by name callback
* @param eRequest $request
*/
public function chapterIdByTitle(eRequest $request)
{
$name = $request->getRequestParam('name');
if(($id = $request->getRequestParam('id')))
{
$request->setRequestParam('name', $id);
return;
}
elseif(!$name || is_numeric($name))
{
if(ADMIN)
{
e107::getMessage()->addError("One of your page-chapters is missing a SEF URL value");
}
return;
}
$sql = e107::getDb('url');
$name = e107::getParser()->toDB($name);
if($sql->select('page_chapters', 'chapter_id', "chapter_sef='{$name}'")) // First check books and chapters.
{
$name = $sql->fetch();
$request->setRequestParam('id', $name['chapter_id']);
$request->setRequestParam('type', 'bk');
e107::getMessage()->addDebug("Set CHAPTER ID = '".$name['chapter_id']."'");
}
elseif($sql->select('page', 'page_id', "page_sef='{$name}'")) // fall back to pages.
{
$name = $sql->fetch();
$request->setRequestParam('id', $name['page_id']);
$request->setRequestParam('type', 'id');
e107::getMessage()->addDebug("Set PAGE ID = '".$name['page_id']."'");
}
else
{
if(ADMIN)
{
e107::getMessage()->addError("Couldn't find a book, chapter or page with a SEF URL value of '".$name."'");
}
$request->setRequestParam('id', 0);
}
}
}

View File

@ -2784,6 +2784,20 @@ class e_parser
return '<div class="video-responsive">'.$video.'</div>';
}
if($type == 'mp4') //TODO FIXME
{
return '
<div class="video-responsive">
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>';
}
return false;
}

View File

@ -23,7 +23,7 @@ class page_shortcodes extends e_shortcode
if(($action == 'listPages' || $action == 'listChapters') && vartrue($this->request['id']))
{
$this->var = e107::getDb()->retrieve('page_chapters','chapter_name, chapter_meta_description','chapter_id = '.intval($this->request['id']).' LIMIT 1');
$this->var = e107::getDb()->retrieve('page_chapters','chapter_name, chapter_meta_description, chapter_sef','chapter_id = '.intval($this->request['id']).' LIMIT 1');
}
if($action == 'showPage' && vartrue($this->request['id'])) // get chapter and description from current.

View File

@ -13,6 +13,29 @@ if (!defined('e107_INIT')) { exit; }
class page_sitelink // include plugin-folder in the name.
{
private $chapterSef = array();
function __construct()
{
$sql = e107::getDb();
$books = $sql->retrieve("SELECT chapter_id,chapter_sef FROM #page_chapters ORDER BY chapter_id ASC" , true);
foreach($books as $row)
{
$id = $row['chapter_id'];
$this->chapterSef[$id] = $row['chapter_sef'];
}
}
function getSef($chapter)
{
return varset($this->chapterSef[$chapter],'--sef-not-assigned--');
}
function config()
{
$links = array();
@ -68,9 +91,13 @@ class page_sitelink // include plugin-folder in the name.
while($row = $sql->fetch())
{
$sef = $row;
$sef['chapter_sef'] = $this->getSef($row['chapter_id']);
$sef['book_sef'] = $this->getSef($row['chapter_parent']);
$sublinks[] = array(
'link_name' => $tp->toHtml($row['chapter_name'],'','TITLE'),
'link_url' => e107::getUrl()->create('page/chapter/index', $row), // 'page.php?ch='.$row['chapter_id'],
'link_url' => e107::getUrl()->create('page/chapter/index', $sef), // 'page.php?ch='.$row['chapter_id'],
'link_description' => '',
'link_button' => $row['chapter_icon'],
'link_category' => '',
@ -150,10 +177,14 @@ class page_sitelink // include plugin-folder in the name.
foreach($data as $row)
{
$pid = $row['page_chapter'];
$row['chapter_sef'] = $this->getSef($row['page_chapter']);
$row['book_sef'] = $this->getSef(); //XXX FIXME - needs to contain the chapter_parent (ie. the 'book')
$sublinks[$pid][] = $_pdata[] = array(
'link_id' => $row['page_id'],
'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')),
'link_url' => e107::getUrl()->create('page/view', $row, array('allow' => 'page_sef,page_title,page_id,chapter_sef,book_sef')),
'link_description' => '',
'link_button' => $row['menu_image'],
'link_category' => '',
@ -195,6 +226,7 @@ class page_sitelink // include plugin-folder in the name.
$books = $sql->retrieve("SELECT * FROM #page_chapters WHERE ".$filter." ORDER BY chapter_order ASC" , true);
foreach($books as $row)
{
$row['book_sef'] = $this->getSef($row['chapter_parent']);
$arr[] = array(
'link_id' => $row['chapter_id'],

View File

@ -91,6 +91,7 @@ class pageClass
public $cacheString; /* current page cache string */
public $cacheTitleString; /* current page title and comment flag cache string */
public $cacheData = null; /* cache data */
protected $chapterSef; /* authorized status */
function __construct($debug=FALSE)
{
@ -137,6 +138,13 @@ class pageClass
$this->debug .= "<b>pageSelected</b> ".$this->pageSelected." <br />";
}
$books = e107::getDb()->retrieve("SELECT chapter_id,chapter_sef FROM #page_chapters ORDER BY chapter_id ASC" , true);
foreach($books as $row)
{
$id = $row['chapter_id'];
$this->chapterSef[$id] = $row['chapter_sef'];
}
}
@ -167,6 +175,11 @@ class pageClass
private function getSef($chapter)
{
return varset($this->chapterSef[$chapter],'--sef-not-assigned--');
}
/**
* @todo Check userclasses
* @todo sef urls
@ -191,13 +204,18 @@ class pageClass
while($row = $sql->fetch())
{
$sef = $row;
$sef['book_sef'] = $this->getSef($row['chapter_id']);
$sef['page_sef'] = $this->getSef($row['chapter_id']);
$var = array(
'BOOK_NAME' => $tp->toHtml($row['chapter_name']),
'BOOK_ANCHOR' => $frm->name2id($row['chapter_name']),
'BOOK_ICON' => $this->chapterIcon($row['chapter_icon']),
'BOOK_DESCRIPTION' => $tp->toHtml($row['chapter_meta_description'],true,'BODY'),
'CHAPTERS' => $this->listChapters(intval($row['chapter_id'])),
'BOOK_URL' => e107::getUrl()->create('page/book/index', $row,'allow=chapter_id,chapter_sef') // e_BASE."page.php?bk=".intval($row['chapter_id']) // FIXME SEF-URL
'CHAPTERS' => $this->listChapters(intval($row['chapter_id']), $row['chapter_sef']),
'BOOK_URL' => e107::getUrl()->create('page/book/index', $sef,'allow=chapter_id,chapter_sef,book_sef,page_sef') // e_BASE."page.php?bk=".intval($row['chapter_id']) // FIXME SEF-URL
);
$text .= $tp->simpleParse($template['item'],$var);
@ -256,14 +274,17 @@ class pageClass
while($row = $sql->fetch())
{
$tmp = $this->listPages(intval($row['chapter_id']));
$tmp = $this->listPages(intval($row['chapter_id']),$book_sef, $row['chapter_sef']);
$row['book_sef'] = $this->getSef($row['chapter_parent']);
$var = array(
'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' => $tmp['text'],
'CHAPTER_URL' => e107::getUrl()->create('page/chapter/index', $row,'allow=chapter_id,chapter_sef') // e_BASE."page.php?ch=".intval($row['chapter_id']) // FIXME SEF-URL
'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
);
$text .= $tp->simpleParse($template['item'],$var);
@ -314,9 +335,11 @@ class pageClass
$frm = e107::getForm();
// retrieve the template to use for this chapter.
$row = $sql->retrieve('page_chapters','chapter_id,chapter_icon,chapter_name,chapter_meta_description,chapter_template','chapter_id = '.intval($chapt).' LIMIT 1');
$row = $sql->retrieve('page_chapters','chapter_id,chapter_icon,chapter_name,chapter_parent, chapter_meta_description,chapter_template','chapter_id = '.intval($chapt).' LIMIT 1');
$layout = vartrue($row['chapter_template'],'default');
$bookSef = $this->getSef($row['chapter_parent']);
$tml = e107::getCoreTemplate('chapter','', true, true); // always merge
$tmpl = varset($tml[$layout]);
@ -351,10 +374,13 @@ class pageClass
'text' => $tp->toHtml($page['page_text'],true)
);
$page['chapter_sef'] = $this->getSef($page['page_chapter']); // $chapter_sef;
$page['book_sef'] = $bookSef;
$this->page = $page;
$this->batch->setVars(new e_vars($data))->setScVar('page', $this->page);
$url = e107::getUrl()->create('page/view', $page, 'allow=page_id,page_sef');
// $url = e107::getUrl()->create('page/view', $page, 'allow=page_id,page_sef,chapter_sef,book_sef');
// $text .= "<li><a href='".$url."'>".$tp->toHtml($page['page_title'])."</a></li>";
$text .= e107::getParser()->parseTemplate($template['item'], true, $this->batch);
}