From a7539899309f2c099e08401b066794a86c1193bb Mon Sep 17 00:00:00 2001 From: SecretR Date: Thu, 24 Jul 2014 17:14:24 +0300 Subject: [PATCH] Fixed #694, rewrite of URL configurations, admin linking fixed --- e107_admin/cpage.php | 2 +- .../shortcodes/batch/page_shortcodes.php | 3 +- e107_core/url/page/sef_chapters_url.php | 41 ++++++++++--------- e107_core/url/page/sef_noid_url.php | 30 +++++++------- e107_core/url/page/sef_url.php | 7 ++-- 5 files changed, 44 insertions(+), 39 deletions(-) diff --git a/e107_admin/cpage.php b/e107_admin/cpage.php index d4fef73e7..934776063 100644 --- a/e107_admin/cpage.php +++ b/e107_admin/cpage.php @@ -435,7 +435,7 @@ class page_admin_ui extends e_admin_ui protected $sortField = 'page_order'; protected $orderStep = 10; //protected $url = array('profile'=>'page/view', 'name' => 'page_title', 'description' => '', 'link'=>'{e_BASE}page.php?id=[id]'); // 'link' only needed if profile not provided. - protected $url = array('route'=>'page/view/index', 'vars' => array('id' => 'page_id', 'name' => 'page_sef', 'chapter' => 'chapter_sef', 'book' => 'book_sef'), 'name' => 'page_title', 'description' => ''); // 'link' only needed if profile not provided. + protected $url = array('route'=>'page/view/index', 'vars' => array('id' => 'page_id', 'name' => 'page_sef', 'other' => 'page_sef', 'chapter' => 'chapter_sef', 'book' => 'book_sef'), 'name' => 'page_title', 'description' => ''); // 'link' only needed if profile not provided. protected $tabs = array("Page","Page Options","Menu", "Menu Options"); protected $featurebox = array('name'=>'page_title', 'description'=>'page_text', 'image' => 'menu_image', 'visibility' => 'page_class', 'url' => true); diff --git a/e107_core/shortcodes/batch/page_shortcodes.php b/e107_core/shortcodes/batch/page_shortcodes.php index 36487a113..7df5fc211 100644 --- a/e107_core/shortcodes/batch/page_shortcodes.php +++ b/e107_core/shortcodes/batch/page_shortcodes.php @@ -326,7 +326,8 @@ class cpage_shortcodes extends e_shortcode $urldata = array_merge($this->var, $chapter); $urldata['book_sef'] = $this->chapterData[$chapter['chapter_parent']]['chapter_sef']; } - return e107::getUrl()->create($route, $urldata, array('allow' => 'page_sef,page_title,page_id,chapter_sef,book_sef')); + + return e107::getUrl()->create($route, $urldata, array('allow' => 'page_sef,page_id,chapter_sef,book_sef')); } function sc_cpagemetadiz() diff --git a/e107_core/url/page/sef_chapters_url.php b/e107_core/url/page/sef_chapters_url.php index 75deae096..a1f93c56c 100644 --- a/e107_core/url/page/sef_chapters_url.php +++ b/e107_core/url/page/sef_chapters_url.php @@ -19,24 +19,19 @@ class core_page_sef_chapters_url extends eUrlConfig '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( - '//' => array('view/index', 'allowVars' => false, 'mapVars' => array('page_id'=>'id', 'page_sef'=>'name', 'chapter_sef'=>'chapter', 'book_sef'=>'book'), 'legacyQuery' => '{name}.{page}', 'parseCallback' => 'itemIdByTitle'), - '/' => array('chapter/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id', 'chapter_sef'=>'name', 'book_sef'=>'book'), 'legacyQuery' => 'ch={id}', 'parseCallback' => 'chapterIdByTitle'), - '' => array('book/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id', 'chapter_sef'=>'name'), 'legacyQuery' => '{type}={id}', 'parseCallback' => 'chapterIdByTitle'), - '' => array('view/other', 'allowVars' => false, 'legacyQuery' => '{type}={id}', 'parseCallback' => 'chapterIdByTitle'), - '/' => array('list/index', 'legacyQuery' => '', ), // page list + 'rules' => array( + ### match page view with no assigned chapter first to avoid namespace collisions + 'item/' => array('view/other', 'mapVars' => array('page_id'=>'id', 'page_sef'=>'name'),'legacyQuery' => '{id}.{page}', 'parseCallback' => 'itemIdByTitle'), + '//' => array('view/index', 'mapVars' => array('page_id'=>'id', 'page_sef'=>'name', 'chapter_sef'=>'chapter', 'book_sef'=>'book'), 'legacyQuery' => '{id}.{page}', 'parseCallback' => 'itemIdByTitle'), + '/' => array('chapter/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id', 'chapter_sef'=>'name', 'book_sef'=>'book'), 'legacyQuery' => 'ch={id}', 'parseCallback' => 'chapterIdByTitle'), + '' => array('book/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id', 'chapter_sef'=>'book'), 'legacyQuery' => 'bk={id}', 'parseCallback' => 'chapterIdByTitle'), + '/' => array('list/index', 'allowVars' => false, 'legacyQuery' => '', ), // page list ) ); } @@ -98,7 +93,8 @@ class core_page_sef_chapters_url extends eUrlConfig { $name = $sql->fetch(); //$request->setRequestParam('legacyQuery','{name}.{page}'); - $request->setRequestParam('name', $name['page_id']); + $request->setRequestParam('name', $name['page_id']) + ->setRequestParam('id', $name['page_id']); e107::getMessage()->addDebug("Set PAGE ID = '".$name['page_id']."'"); } @@ -132,7 +128,12 @@ class core_page_sef_chapters_url extends eUrlConfig public function chapterIdByTitle(eRequest $request) { $name = $request->getRequestParam('name'); - + if(null == $name) + { + // Book view + $name = $request->getRequestParam('book'); + } + if(($id = $request->getRequestParam('id'))) { $request->setRequestParam('name', $id); @@ -153,17 +154,19 @@ class core_page_sef_chapters_url extends eUrlConfig 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'); + $request->setRequestParam('id', $name['chapter_id']) + ->setRequestParam('name', $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. + /*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) diff --git a/e107_core/url/page/sef_noid_url.php b/e107_core/url/page/sef_noid_url.php index 8e2531737..1bfccff7a 100644 --- a/e107_core/url/page/sef_noid_url.php +++ b/e107_core/url/page/sef_noid_url.php @@ -19,23 +19,19 @@ class core_page_sef_noid_url extends eUrlConfig '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( + 'rules' => array( 'chapter/' => array('chapter/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id', 'chapter_sef'=>'name'), 'legacyQuery' => 'ch={id}', 'parseCallback' => 'chapterIdByTitle'), 'book/' => array('book/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id', 'chapter_sef'=>'name'), 'legacyQuery' => 'bk={id}', 'parseCallback' => 'chapterIdByTitle'), - '' => array('view/index', 'allowVars' => false, 'legacyQuery' => '{name}.{page}', 'parseCallback' => 'itemIdByTitle'), - '/' => array('list/index', 'legacyQuery' => '', ), // page list + '' => array('view/index', 'mapVars' => array('page_id'=>'id', 'page_sef'=>'name'), 'legacyQuery' => '{id}.{page}', 'parseCallback' => 'itemIdByTitle'), + ### Used for assembling only + '' => array('view/other', 'mapVars' => array('page_id'=>'id', 'page_sef'=>'other'), 'legacyQuery' => '{id}.{page}', 'parseCallback' => 'itemIdByTitle'), + '/' => array('list/index', 'allowVars' => false, 'legacyQuery' => '', ), // page list ) ); } @@ -71,7 +67,7 @@ class core_page_sef_noid_url extends eUrlConfig 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'); @@ -96,7 +92,8 @@ class core_page_sef_noid_url extends eUrlConfig if($sql->select('page', 'page_id', "page_sef='{$name}'")) { $name = $sql->fetch(); - $request->setRequestParam('name', $name['page_id']); + $request->setRequestParam('name', $name['page_id']) + ->setRequestParam('id', $name['page_id']); } else { @@ -104,7 +101,8 @@ class core_page_sef_noid_url extends eUrlConfig { e107::getMessage()->addError("Couldn't find a page with a SEF URL value of '".$name."'"); } - $request->setRequestParam('name', 0); + $request->setRequestParam('name', 0) + ->setRequestParam('id', 0); } } @@ -136,7 +134,8 @@ class core_page_sef_noid_url extends eUrlConfig if($sql->select('page_chapters', 'chapter_id', "chapter_sef='{$name}'")) { $name = $sql->fetch(); - $request->setRequestParam('id', $name['chapter_id']); + $request->setRequestParam('id', $name['chapter_id']) + ->setRequestParam('name', $name['chapter_id']); } else { @@ -144,7 +143,8 @@ class core_page_sef_noid_url extends eUrlConfig { e107::getMessage()->addError("Couldn't find a book or chapter with a SEF URL value of '".$name."'"); } - $request->setRequestParam('id', 0); + $request->setRequestParam('id', 0) + ->setRequestParam('name', 0); } } diff --git a/e107_core/url/page/sef_url.php b/e107_core/url/page/sef_url.php index 77aef7e13..4895c0d76 100644 --- a/e107_core/url/page/sef_url.php +++ b/e107_core/url/page/sef_url.php @@ -31,10 +31,11 @@ class core_page_sef_url extends eUrlConfig ), 'rules' => array( - ### using only title for pages is risky enough (non-unique title, possible bad characters) '/' => array('view/index', 'legacyQuery' => '{id}.{page}', ), - 'chapter//' => array('chapter/index', 'mapVars' => array('chapter_id'=>'id','chapter_sef'=>'name'), 'legacyQuery' => 'ch={id}' ), - 'book//' => array('book/index', 'mapVars' => array('chapter_id'=>'id','chapter_sef'=>'name'), 'legacyQuery' => 'bk={id}' ), + ### Used for assembling only + '/' => array('view/other', 'mapVars' => array('page_id'=>'id', 'page_sef'=>'other'), 'legacyQuery' => '{id}.{page}', ), + 'chapter//' => array('chapter/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id','chapter_sef'=>'name'), 'legacyQuery' => 'ch={id}' ), + 'book//' => array('book/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id','chapter_sef'=>'name'), 'legacyQuery' => 'bk={id}' ), ### page list '/' => array('list/index', 'legacyQuery' => '', ),