1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-11 00:54:49 +02:00

News SEF URL for tags. Automatically switch URL path to lowercase when lowercase url template is used.

This commit is contained in:
Cameron
2013-12-20 09:45:27 -08:00
parent 71d6e81c8b
commit 3030ca3570
9 changed files with 97 additions and 20 deletions

View File

@@ -35,14 +35,16 @@ class core_news_sef_full_url extends eUrlConfig
'Category/<name:{sefsecure}>' => array('list/category', 'allowVars' => array('page'), 'mapVars' => array('category_sef' => 'name'), 'legacyQuery' => 'list.{name}.{page}', 'parseCallback' => 'categoryIdByTitle'),
'All' => array('list/all', 'allowVars' => array('page'), 'legacyQuery' => 'all.0.{page}'),
'Short/<name:{sefsecure}>' => array('list/short', 'allowVars' => array('page'), 'mapVars' => array('category_sef' => 'name'), 'legacyQuery' => 'cat.{name}.{page}', 'parseCallback' => 'categoryIdByTitle'),
'Short/<id:{number}>' => array('list/short', 'allowVars' => array('page'), 'mapVars' => array('category_id' => 'id'), 'legacyQuery' => 'cat.{id}.{page}'),
'Day/<id:{number}>' => array('list/day', 'allowVars' => array('page'), 'legacyQuery' => 'day.{id}.{page}'),
'Month/<id:{number}>' => array('list/month', 'allowVars' => array('page'), 'legacyQuery' => 'month.{id}.{page}'),
'Short/<name:{sefsecure}>' => array('list/short', 'allowVars' => array('page'), 'mapVars' => array('category_sef' => 'name'), 'legacyQuery' => 'cat.{name}.{page}', 'parseCallback' => 'categoryIdByTitle'),
'Short/<id:{number}>' => array('list/short', 'allowVars' => array('page'), 'mapVars' => array('category_id' => 'id'), 'legacyQuery' => 'cat.{id}.{page}'),
'Day/<id:{number}>' => array('list/day', 'allowVars' => array('page'), 'legacyQuery' => 'day.{id}.{page}'),
'Month/<id:{number}>' => array('list/month', 'allowVars' => array('page'), 'legacyQuery' => 'month.{id}.{page}'),
'Tag/<tag:{secure}>' => array('list/tag', 'allowVars' => array('page'), 'legacyQuery' => 'tag={tag}'),
'<category:{sefsecure}>/<name:{sefsecure}>' => array('view/item', 'mapVars' => array('category_sef' => 'category', 'news_sef' => 'name'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
'<name:{sefsecure}>' => array('view/item', 'mapVars' => array('news_id' => 'id', 'news_sef' => 'name'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
'<id:{number}>' => array('view/item', 'mapVars' => array('news_id' => 'id'), 'legacyQuery' => 'extend.{id}'),
)
);

View File

@@ -97,6 +97,11 @@ class core_news_sef_noid_url extends eUrlConfig
if($page) $parm = array('page' => $page); // news/All?page=xxx
break;
case 'tag': // news/tag/xxxx
$r[0] = 'tag';
$r[1] = $params['tag'];
break;
case 'category':
case 'short':
if(!vartrue($params['id']))
@@ -154,8 +159,9 @@ class core_news_sef_noid_url extends eUrlConfig
}
## no controller/action pair - news item view - map to extend.xxx
if(strpos($pathInfo, '/') === false && $pathInfo != 'All')
if(strpos($pathInfo, '/') === false && strtolower($pathInfo) != 'all')
{
$route = 'view/item';
$id = is_numeric($pathInfo) ? intval($pathInfo) : $this->itemIdByTitle($pathInfo);
if(!$id)
@@ -228,6 +234,11 @@ class core_news_sef_noid_url extends eUrlConfig
return 'list/all';
break;
case 'tag':
$this->legacyQueryString = 'tag='.$parts[1];
return 'list/tag';
break;
# force not found
default:
return false;

View File

@@ -105,7 +105,10 @@ class core_news_sef_url extends eUrlConfig
// fallback if news sef is missing
'View/<id:{number}>/<name:{sefsecure}>' => array('view/item', 'mapVars' => array('news_id' => 'id', 'news_sef' => 'name'), 'legacyQuery' => 'extend.{id}'),
'View/<id:{number}>' => array('view/item', 'mapVars' => array('news_id' => 'id'), 'legacyQuery' => 'extend.{id}'),
'View/<id:{number}>' => array('view/item', 'mapVars' => array('news_id' => 'id'), 'legacyQuery' => 'extend.{id}'),
'Tag/<tag:{secure}>' => array('list/tag', 'allowVars' => array('page'), 'legacyQuery' => 'tag={tag}'),
)
);
@@ -113,7 +116,7 @@ class core_news_sef_url extends eUrlConfig
/**
* Query mapping in format route?params:
* - item/vew?id=xxx -> ?extend.id
* - item/view?id=xxx -> ?extend.id
* - list/items[?page=xxx] -> default.0.page
* - list/category?id=xxx[&page=xxx] -> list.id.page
* - list/category?id=0[&page=xxx] -> default.0.page

View File

@@ -95,6 +95,7 @@ class core_news_url extends eUrlConfig
$route[1] = 'items';
}
// return print_a($route,true);
## news are passing array as it is retrieved from the DB, map vars to proper values
if(isset($params['news_id']) && !empty($params['news_id'])) $params['id'] = $params['news_id'];
//if(isset($params['news_sef']) && !empty($params['news_sef'])) $params['id'] = $params['news_sef'];
@@ -142,6 +143,10 @@ class core_news_url extends eUrlConfig
$url .= 'all.'.$params['id'].'.'.$page;
break;
case 'tag':
$url .= 'tag='.$params['id'].'&page='.$page;
break;
case 'short':
$url .= 'cat.'.$params['id'].'.'.$page;
break;
@@ -158,7 +163,10 @@ class core_news_url extends eUrlConfig
break;
}
}
else $url = 'news.php';
else
{
$url = 'news.php';
}
return $url;
}

View File

@@ -72,6 +72,11 @@ 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');
if(($id = $request->getRequestParam('id')))
{
$request->setRequestParam('name', $id);
@@ -79,6 +84,9 @@ class core_page_sef_noid_url extends eUrlConfig
}
elseif(!$name || is_numeric($name)) return;
$sql = e107::getDb('url');
$name = e107::getParser()->toDB($name);
if($sql->db_Select('page', 'page_id', "menu_name='' AND page_sef='{$name}'"))