mirror of
https://github.com/e107inc/e107.git
synced 2025-08-08 23:56:58 +02:00
Renormalized all text file line endings
This commit is contained in:
@@ -1,133 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Full SEF URLs support and the most risky one, almost the same as sef_noid, just working with rules only
|
||||
*/
|
||||
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_news_sef_full_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
'config' => array(
|
||||
'allowMain' => true,
|
||||
'legacy' => '{e_BASE}news.php',
|
||||
'format' => 'path',
|
||||
'defaultRoute' => 'list/items',
|
||||
'urlSuffix' => '',
|
||||
'allowVars' => false,
|
||||
'matchValue' => 'empty',
|
||||
|
||||
'mapVars' => array(
|
||||
'news_id' => 'id',
|
||||
'news_sef' => 'name',
|
||||
),
|
||||
),
|
||||
|
||||
'rules' => array(
|
||||
'/' => array('list/items', 'allowVars' => array('page'), 'legacyQuery' => 'default.0.{page}', ),
|
||||
'Category' => array('list/items', 'allowVars' => array('page'), 'legacyQuery' => 'default.0.{page}', ),
|
||||
'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}'),
|
||||
'Tag/<tag:{secure}>' => array('list/tag', 'allowVars' => array('page'), 'legacyQuery' => 'tag={tag}&page={page}'),
|
||||
'Author/<author:{secure}>' => array('list/author', 'allowVars' => array('page'), 'legacyQuery' => 'author={author}&page={$page}'),
|
||||
|
||||
'<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}'),
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
/**
|
||||
* 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_NEWS, // Module name
|
||||
'label' => LAN_EURL_NEWS_REWRITEF_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_NEWS_REWRITEF_DESCR, //
|
||||
'examples' => array("{SITEURL}news/news-category/news-title","{SITEURL}news/category/news-category")
|
||||
),
|
||||
'generate' => array('table'=> 'news', 'primary'=>'news_id', 'input'=>'news_title', 'output'=>'news_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');
|
||||
if(($id = $request->getRequestParam('id')))
|
||||
{
|
||||
$request->setRequestParam('name', $id);
|
||||
return;
|
||||
}
|
||||
elseif(!$name) return;
|
||||
elseif(is_numeric($name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = e107::getDb('url');
|
||||
$name = e107::getParser()->toDB($name);
|
||||
if($sql->select('news', 'news_id', "news_sef='{$name}'")) // TODO - it'll be news_sef (new) field
|
||||
{
|
||||
$name = $sql->fetch();
|
||||
$request->setRequestParam('name', $name['news_id']);
|
||||
}
|
||||
else $request->setRequestParam('name', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* list/items by name callback
|
||||
* @param eRequest $request
|
||||
*/
|
||||
public function categoryIdByTitle(eRequest $request)
|
||||
{
|
||||
$name = $request->getRequestParam('name');
|
||||
if(($id = $request->getRequestParam('id')))
|
||||
{
|
||||
$request->setRequestParam('name', $id);
|
||||
return;
|
||||
}
|
||||
elseif(!$name) return;
|
||||
elseif(is_numeric($name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = e107::getDb('url');
|
||||
$id = e107::getParser()->toDB($name);
|
||||
if($sql->select('news_category', 'category_id', "category_sef='{$name}'")) // TODO - it'll be category_sef (new) field
|
||||
{
|
||||
$name = $sql->fetch();
|
||||
$request->setRequestParam('name', $name['category_id']);
|
||||
}
|
||||
else $request->setRequestParam('name', 0);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Full SEF URLs support and the most risky one, almost the same as sef_noid, just working with rules only
|
||||
*/
|
||||
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_news_sef_full_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
'config' => array(
|
||||
'allowMain' => true,
|
||||
'legacy' => '{e_BASE}news.php',
|
||||
'format' => 'path',
|
||||
'defaultRoute' => 'list/items',
|
||||
'urlSuffix' => '',
|
||||
'allowVars' => false,
|
||||
'matchValue' => 'empty',
|
||||
|
||||
'mapVars' => array(
|
||||
'news_id' => 'id',
|
||||
'news_sef' => 'name',
|
||||
),
|
||||
),
|
||||
|
||||
'rules' => array(
|
||||
'/' => array('list/items', 'allowVars' => array('page'), 'legacyQuery' => 'default.0.{page}', ),
|
||||
'Category' => array('list/items', 'allowVars' => array('page'), 'legacyQuery' => 'default.0.{page}', ),
|
||||
'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}'),
|
||||
'Tag/<tag:{secure}>' => array('list/tag', 'allowVars' => array('page'), 'legacyQuery' => 'tag={tag}&page={page}'),
|
||||
'Author/<author:{secure}>' => array('list/author', 'allowVars' => array('page'), 'legacyQuery' => 'author={author}&page={$page}'),
|
||||
|
||||
'<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}'),
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
/**
|
||||
* 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_NEWS, // Module name
|
||||
'label' => LAN_EURL_NEWS_REWRITEF_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_NEWS_REWRITEF_DESCR, //
|
||||
'examples' => array("{SITEURL}news/news-category/news-title","{SITEURL}news/category/news-category")
|
||||
),
|
||||
'generate' => array('table'=> 'news', 'primary'=>'news_id', 'input'=>'news_title', 'output'=>'news_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');
|
||||
if(($id = $request->getRequestParam('id')))
|
||||
{
|
||||
$request->setRequestParam('name', $id);
|
||||
return;
|
||||
}
|
||||
elseif(!$name) return;
|
||||
elseif(is_numeric($name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = e107::getDb('url');
|
||||
$name = e107::getParser()->toDB($name);
|
||||
if($sql->select('news', 'news_id', "news_sef='{$name}'")) // TODO - it'll be news_sef (new) field
|
||||
{
|
||||
$name = $sql->fetch();
|
||||
$request->setRequestParam('name', $name['news_id']);
|
||||
}
|
||||
else $request->setRequestParam('name', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* list/items by name callback
|
||||
* @param eRequest $request
|
||||
*/
|
||||
public function categoryIdByTitle(eRequest $request)
|
||||
{
|
||||
$name = $request->getRequestParam('name');
|
||||
if(($id = $request->getRequestParam('id')))
|
||||
{
|
||||
$request->setRequestParam('name', $id);
|
||||
return;
|
||||
}
|
||||
elseif(!$name) return;
|
||||
elseif(is_numeric($name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = e107::getDb('url');
|
||||
$id = e107::getParser()->toDB($name);
|
||||
if($sql->select('news_category', 'category_id', "category_sef='{$name}'")) // TODO - it'll be category_sef (new) field
|
||||
{
|
||||
$name = $sql->fetch();
|
||||
$request->setRequestParam('name', $name['category_id']);
|
||||
}
|
||||
else $request->setRequestParam('name', 0);
|
||||
}
|
||||
}
|
||||
|
@@ -1,327 +1,327 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* SEF URLs support, example of manually (rules-less) created/parsed urls
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_news_sef_noid_url extends eUrlConfig
|
||||
{
|
||||
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
'config' => array(
|
||||
'allowMain' => true,
|
||||
'noSingleEntry' => false, // [optional] default false; disallow this module to be shown via single entry point when this config is used
|
||||
'legacy' => '{e_BASE}news.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
|
||||
'selfParse' => true, // [optional] default false; use only this->parse() method, no core routine URL parsing
|
||||
'selfCreate' => true, // [optional] default false; use only this->create() method, no core routine URL creating
|
||||
'defaultRoute' => 'list/items', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
'urlSuffix' => '.html', // [optional] default empty; string to append to the URL (e.g. .html)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* When returning array, module or it's corresponding alias will be prefixed
|
||||
* Create link so that it can be mapped by the parse() method
|
||||
* - view/item?id=xxx -> news/xxx
|
||||
* - list/items[?page=xxx] -> news[?page=xxx]
|
||||
* - list/category?id=xxx[&page=xxx] -> news/Category/xxx?page=xxx
|
||||
* - list/category?id=0[&page=xxx] -> news?page=xxx
|
||||
* - list/short?id=xxx[&page=xxx] -> news/Short/xxx?page=xxx
|
||||
* - list/category?id=xxx[&page=xxx] -> news?page=xxx
|
||||
* - list/day?id=xxx -> news/Day-id
|
||||
* - list/month?id=xxx -> news/Month-id
|
||||
* - list/year?id=xxx -> news/Year-id
|
||||
* - list/nextprev?route=xxx -> PARSED_ROUTE?page=[FROM] (recursive parse() call)
|
||||
* - list/all
|
||||
* - list/tag
|
||||
*/
|
||||
public function create($route, $params = array(), $options = array())
|
||||
{
|
||||
|
||||
if('--FROM--' != vartrue($params['page'])) $page = varset($params['page']) ? intval($params['page']) : '0';
|
||||
else $page = '--FROM--';
|
||||
|
||||
if(!$route) $route = 'list/items';
|
||||
if(is_string($route)) $route = explode('/', $route, 2);
|
||||
if('index' == $route[0])
|
||||
{
|
||||
$route[0] = 'list';
|
||||
$route[1] = 'items';
|
||||
}
|
||||
elseif('index' == $route[1])
|
||||
{
|
||||
$route[1] = 'items';
|
||||
}
|
||||
|
||||
$r = array();
|
||||
$parm = array();
|
||||
|
||||
if($route[0] == 'view')
|
||||
{
|
||||
## 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']; // TODO - news_sef
|
||||
|
||||
switch ($route[1])
|
||||
{
|
||||
case 'item':
|
||||
$r[0] = $params['id']; // news/ID
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif($route[0] == 'list')
|
||||
{
|
||||
## news are passing array as it is retrieved from the DB, map vars to proper values
|
||||
if(isset($params['category_id']) && !empty($params['category_id'])) $params['id'] = $params['category_id'];
|
||||
if(isset($params['category_sef']) && !empty($params['category_sef'])) $params['name'] = $params['category_sef']; // TODO - news_sef
|
||||
|
||||
switch ($route[1])
|
||||
{
|
||||
|
||||
case 'items':
|
||||
$r[0] = '';
|
||||
if($page) $parm = array('page' => $page); // news?page=xxx
|
||||
break;
|
||||
|
||||
case 'all':
|
||||
$r[0] = 'All';
|
||||
if($page) $parm = array('page' => $page); // news/All?page=xxx
|
||||
break;
|
||||
|
||||
case 'tag': // news/tag/xxxx
|
||||
$r[0] = 'tag';
|
||||
$r[1] = $params['tag'];
|
||||
if($page) $parm = array('page' => $page);
|
||||
break;
|
||||
|
||||
case 'author': // news/author/xxxx
|
||||
$r[0] = 'author';
|
||||
$r[1] = $params['author'];
|
||||
if($page) $parm = array('page' => $page);
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
case 'short':
|
||||
if(!vartrue($params['id']))
|
||||
{
|
||||
$r[0] = '';
|
||||
if($page) $parm = array('page' => $page); // news?page=xxx
|
||||
}
|
||||
else
|
||||
{
|
||||
// news/Category/Category-Name?page=xxx
|
||||
// news/Short/Category-Name?page=xxx
|
||||
$r[0] = $route[1] == 'category' ? 'Category' : 'Short';
|
||||
$r[1] = !empty($params['name']) ? $params['name'] : $params['id'];
|
||||
if($page) $parm = array('page' => $page);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'day':
|
||||
case 'month':
|
||||
case 'year':
|
||||
$r = array($route[1], intval($params['id']));
|
||||
if($page) $parm = array('page' => $page);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($r)) return false;
|
||||
|
||||
|
||||
//XXX TODO Find a better place to put this check.
|
||||
$urlFormat = e107::getConfig()->get('url_sef_translate');
|
||||
if($urlFormat == 'dashl' || $urlFormat == 'underscorel' || $urlFormat == 'plusl') // convert template to lowercase when using lowercase SEF URL format.
|
||||
{
|
||||
$r[0] = strtolower($r[0]);
|
||||
}
|
||||
|
||||
|
||||
return array($r, $parm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually parse request
|
||||
* Pathinfo DOESN'T contain leading 'module' (e.g news or alias 'Blog')
|
||||
* Retruned route shouldn't contain module as well, unless you manipulate $request directly and set $request->routed to true
|
||||
* Mapped URLs:
|
||||
* - news/News-Item -> extend.xxx
|
||||
* - news/Category/Category-Name?page=10 -> list.xxx.10
|
||||
* - news/Day|Month-xxx -> day|month-xxx
|
||||
*/
|
||||
public function parse($pathInfo, $params = array(), eRequest $request = null, eRouter $router = null, $config = array())
|
||||
{
|
||||
|
||||
$page = !empty($params['page']) ? intval($params['page']) : '0';
|
||||
if(!$pathInfo)
|
||||
{
|
||||
## this var is used by default from legacy() method
|
||||
## you may override legacy() method
|
||||
## Keep in mind legacy() is not triggered at all if parse() returns false or $request->routed is set to true
|
||||
$this->legacyQueryString = $page ? 'default.0.'.$page : '';
|
||||
return $config['defaultRoute'];
|
||||
}
|
||||
|
||||
## no controller/action pair - news item view - map to extend.xxx
|
||||
if(strpos($pathInfo, '/') === false && strtolower($pathInfo) != 'all')
|
||||
{
|
||||
|
||||
$route = 'view/item';
|
||||
$id = is_numeric($pathInfo) ? intval($pathInfo) : $this->itemIdByTitle($pathInfo);
|
||||
if(!$id)
|
||||
{
|
||||
## let news.php handle missing news item
|
||||
$this->legacyQueryString = 'extend.0';
|
||||
return $route;
|
||||
}
|
||||
$this->legacyQueryString = 'extend.'.$id;
|
||||
return $route;
|
||||
}
|
||||
|
||||
$parts = explode('/', $pathInfo, 2);
|
||||
$parts[0] = strtolower($parts[0]);
|
||||
switch ($parts[0])
|
||||
{
|
||||
# map to list.xxx.xxx
|
||||
case 'short':
|
||||
case 'category':
|
||||
# Hardcoded leading string for categories, could be pref or LAN constant
|
||||
if(!vartrue($parts[1]))
|
||||
{
|
||||
## force not found as we don't want to have duplicated content (default.0.xxx)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!is_numeric($parts[1])) $id = $this->categoryIdByTitle($parts[1]);
|
||||
else $id = intval($parts[1]);
|
||||
}
|
||||
if(!$id)
|
||||
{
|
||||
# let news.php handle it
|
||||
$id = 0;
|
||||
}
|
||||
$action = $parts[0] == 'short' ? 'cat' : 'list';
|
||||
$this->legacyQueryString = $action.'.'.$id.'.'.$page;
|
||||
return 'item/list';
|
||||
break;
|
||||
|
||||
# could be pref or LAN constant
|
||||
case 'day':
|
||||
if(!vartrue($parts[1])) $id = 0;
|
||||
else $id = intval($parts[1]);
|
||||
|
||||
$this->legacyQueryString = 'day.'.$id.'.'.$page;
|
||||
return 'list/day';
|
||||
break;
|
||||
|
||||
# could be pref or LAN constant
|
||||
case 'month':
|
||||
if(!vartrue($parts[1])) $id = 0;
|
||||
else $id = intval($parts[1]);
|
||||
|
||||
$this->legacyQueryString = 'month.'.$id.'.'.$page;
|
||||
return 'list/month';
|
||||
break;
|
||||
|
||||
# could be pref or LAN constant - not supported yet
|
||||
case 'year':
|
||||
if(!vartrue($parts[1])) $id = 0;
|
||||
else $id = intval($parts[1]);
|
||||
|
||||
$this->legacyQueryString = 'year.'.$id.'.'.$page;
|
||||
//return 'list/year';
|
||||
break;
|
||||
|
||||
case 'all':
|
||||
$this->legacyQueryString = 'all.0.'.$page;
|
||||
return 'list/all';
|
||||
break;
|
||||
|
||||
case 'tag': // url: news/tag/xxxxx
|
||||
$this->legacyQueryString = 'tag='.$parts[1];
|
||||
return 'list/tag';
|
||||
break;
|
||||
|
||||
case 'author': // url: news/author/xxxxx
|
||||
$this->legacyQueryString = 'author='.$parts[1].'&page='.$page;
|
||||
return 'list/author';
|
||||
break;
|
||||
|
||||
# force not found
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_NEWS, // Module name
|
||||
'label' => LAN_EURL_NEWS_REWRITE_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_NEWS_REWRITE_DESCR, //
|
||||
'examples' => array("{SITEURL}news/news-title")
|
||||
),
|
||||
'generate' => array('table'=> 'news', 'primary'=>'news_id', 'input'=>'news_title', 'output'=>'news_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 ###
|
||||
|
||||
//retrieve news_id by news_sef (
|
||||
public function itemIdByTitle($id)
|
||||
{
|
||||
$sql = e107::getDb('url');
|
||||
$tp = e107::getParser();
|
||||
$id = $tp->toDB($id);
|
||||
if($sql->select('news', 'news_id', "news_sef='{$id}'"))
|
||||
{
|
||||
$id = $sql->fetch();
|
||||
return $id['news_id'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//retrieve category_id by Title (XXX - category_sef column, equals to category_sef if not set explicit)
|
||||
public function categoryIdByTitle($id)
|
||||
{
|
||||
$sql = e107::getDb('url');
|
||||
$tp = e107::getParser();
|
||||
$id = $tp->toDB($id);
|
||||
if($sql->select('news_category', 'category_id', "category_sef='{$id}'"))
|
||||
{
|
||||
$id = $sql->fetch();
|
||||
return $id['category_id'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* SEF URLs support, example of manually (rules-less) created/parsed urls
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_news_sef_noid_url extends eUrlConfig
|
||||
{
|
||||
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
'config' => array(
|
||||
'allowMain' => true,
|
||||
'noSingleEntry' => false, // [optional] default false; disallow this module to be shown via single entry point when this config is used
|
||||
'legacy' => '{e_BASE}news.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
|
||||
'selfParse' => true, // [optional] default false; use only this->parse() method, no core routine URL parsing
|
||||
'selfCreate' => true, // [optional] default false; use only this->create() method, no core routine URL creating
|
||||
'defaultRoute' => 'list/items', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
'urlSuffix' => '.html', // [optional] default empty; string to append to the URL (e.g. .html)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* When returning array, module or it's corresponding alias will be prefixed
|
||||
* Create link so that it can be mapped by the parse() method
|
||||
* - view/item?id=xxx -> news/xxx
|
||||
* - list/items[?page=xxx] -> news[?page=xxx]
|
||||
* - list/category?id=xxx[&page=xxx] -> news/Category/xxx?page=xxx
|
||||
* - list/category?id=0[&page=xxx] -> news?page=xxx
|
||||
* - list/short?id=xxx[&page=xxx] -> news/Short/xxx?page=xxx
|
||||
* - list/category?id=xxx[&page=xxx] -> news?page=xxx
|
||||
* - list/day?id=xxx -> news/Day-id
|
||||
* - list/month?id=xxx -> news/Month-id
|
||||
* - list/year?id=xxx -> news/Year-id
|
||||
* - list/nextprev?route=xxx -> PARSED_ROUTE?page=[FROM] (recursive parse() call)
|
||||
* - list/all
|
||||
* - list/tag
|
||||
*/
|
||||
public function create($route, $params = array(), $options = array())
|
||||
{
|
||||
|
||||
if('--FROM--' != vartrue($params['page'])) $page = varset($params['page']) ? intval($params['page']) : '0';
|
||||
else $page = '--FROM--';
|
||||
|
||||
if(!$route) $route = 'list/items';
|
||||
if(is_string($route)) $route = explode('/', $route, 2);
|
||||
if('index' == $route[0])
|
||||
{
|
||||
$route[0] = 'list';
|
||||
$route[1] = 'items';
|
||||
}
|
||||
elseif('index' == $route[1])
|
||||
{
|
||||
$route[1] = 'items';
|
||||
}
|
||||
|
||||
$r = array();
|
||||
$parm = array();
|
||||
|
||||
if($route[0] == 'view')
|
||||
{
|
||||
## 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']; // TODO - news_sef
|
||||
|
||||
switch ($route[1])
|
||||
{
|
||||
case 'item':
|
||||
$r[0] = $params['id']; // news/ID
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif($route[0] == 'list')
|
||||
{
|
||||
## news are passing array as it is retrieved from the DB, map vars to proper values
|
||||
if(isset($params['category_id']) && !empty($params['category_id'])) $params['id'] = $params['category_id'];
|
||||
if(isset($params['category_sef']) && !empty($params['category_sef'])) $params['name'] = $params['category_sef']; // TODO - news_sef
|
||||
|
||||
switch ($route[1])
|
||||
{
|
||||
|
||||
case 'items':
|
||||
$r[0] = '';
|
||||
if($page) $parm = array('page' => $page); // news?page=xxx
|
||||
break;
|
||||
|
||||
case 'all':
|
||||
$r[0] = 'All';
|
||||
if($page) $parm = array('page' => $page); // news/All?page=xxx
|
||||
break;
|
||||
|
||||
case 'tag': // news/tag/xxxx
|
||||
$r[0] = 'tag';
|
||||
$r[1] = $params['tag'];
|
||||
if($page) $parm = array('page' => $page);
|
||||
break;
|
||||
|
||||
case 'author': // news/author/xxxx
|
||||
$r[0] = 'author';
|
||||
$r[1] = $params['author'];
|
||||
if($page) $parm = array('page' => $page);
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
case 'short':
|
||||
if(!vartrue($params['id']))
|
||||
{
|
||||
$r[0] = '';
|
||||
if($page) $parm = array('page' => $page); // news?page=xxx
|
||||
}
|
||||
else
|
||||
{
|
||||
// news/Category/Category-Name?page=xxx
|
||||
// news/Short/Category-Name?page=xxx
|
||||
$r[0] = $route[1] == 'category' ? 'Category' : 'Short';
|
||||
$r[1] = !empty($params['name']) ? $params['name'] : $params['id'];
|
||||
if($page) $parm = array('page' => $page);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'day':
|
||||
case 'month':
|
||||
case 'year':
|
||||
$r = array($route[1], intval($params['id']));
|
||||
if($page) $parm = array('page' => $page);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($r)) return false;
|
||||
|
||||
|
||||
//XXX TODO Find a better place to put this check.
|
||||
$urlFormat = e107::getConfig()->get('url_sef_translate');
|
||||
if($urlFormat == 'dashl' || $urlFormat == 'underscorel' || $urlFormat == 'plusl') // convert template to lowercase when using lowercase SEF URL format.
|
||||
{
|
||||
$r[0] = strtolower($r[0]);
|
||||
}
|
||||
|
||||
|
||||
return array($r, $parm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually parse request
|
||||
* Pathinfo DOESN'T contain leading 'module' (e.g news or alias 'Blog')
|
||||
* Retruned route shouldn't contain module as well, unless you manipulate $request directly and set $request->routed to true
|
||||
* Mapped URLs:
|
||||
* - news/News-Item -> extend.xxx
|
||||
* - news/Category/Category-Name?page=10 -> list.xxx.10
|
||||
* - news/Day|Month-xxx -> day|month-xxx
|
||||
*/
|
||||
public function parse($pathInfo, $params = array(), eRequest $request = null, eRouter $router = null, $config = array())
|
||||
{
|
||||
|
||||
$page = !empty($params['page']) ? intval($params['page']) : '0';
|
||||
if(!$pathInfo)
|
||||
{
|
||||
## this var is used by default from legacy() method
|
||||
## you may override legacy() method
|
||||
## Keep in mind legacy() is not triggered at all if parse() returns false or $request->routed is set to true
|
||||
$this->legacyQueryString = $page ? 'default.0.'.$page : '';
|
||||
return $config['defaultRoute'];
|
||||
}
|
||||
|
||||
## no controller/action pair - news item view - map to extend.xxx
|
||||
if(strpos($pathInfo, '/') === false && strtolower($pathInfo) != 'all')
|
||||
{
|
||||
|
||||
$route = 'view/item';
|
||||
$id = is_numeric($pathInfo) ? intval($pathInfo) : $this->itemIdByTitle($pathInfo);
|
||||
if(!$id)
|
||||
{
|
||||
## let news.php handle missing news item
|
||||
$this->legacyQueryString = 'extend.0';
|
||||
return $route;
|
||||
}
|
||||
$this->legacyQueryString = 'extend.'.$id;
|
||||
return $route;
|
||||
}
|
||||
|
||||
$parts = explode('/', $pathInfo, 2);
|
||||
$parts[0] = strtolower($parts[0]);
|
||||
switch ($parts[0])
|
||||
{
|
||||
# map to list.xxx.xxx
|
||||
case 'short':
|
||||
case 'category':
|
||||
# Hardcoded leading string for categories, could be pref or LAN constant
|
||||
if(!vartrue($parts[1]))
|
||||
{
|
||||
## force not found as we don't want to have duplicated content (default.0.xxx)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!is_numeric($parts[1])) $id = $this->categoryIdByTitle($parts[1]);
|
||||
else $id = intval($parts[1]);
|
||||
}
|
||||
if(!$id)
|
||||
{
|
||||
# let news.php handle it
|
||||
$id = 0;
|
||||
}
|
||||
$action = $parts[0] == 'short' ? 'cat' : 'list';
|
||||
$this->legacyQueryString = $action.'.'.$id.'.'.$page;
|
||||
return 'item/list';
|
||||
break;
|
||||
|
||||
# could be pref or LAN constant
|
||||
case 'day':
|
||||
if(!vartrue($parts[1])) $id = 0;
|
||||
else $id = intval($parts[1]);
|
||||
|
||||
$this->legacyQueryString = 'day.'.$id.'.'.$page;
|
||||
return 'list/day';
|
||||
break;
|
||||
|
||||
# could be pref or LAN constant
|
||||
case 'month':
|
||||
if(!vartrue($parts[1])) $id = 0;
|
||||
else $id = intval($parts[1]);
|
||||
|
||||
$this->legacyQueryString = 'month.'.$id.'.'.$page;
|
||||
return 'list/month';
|
||||
break;
|
||||
|
||||
# could be pref or LAN constant - not supported yet
|
||||
case 'year':
|
||||
if(!vartrue($parts[1])) $id = 0;
|
||||
else $id = intval($parts[1]);
|
||||
|
||||
$this->legacyQueryString = 'year.'.$id.'.'.$page;
|
||||
//return 'list/year';
|
||||
break;
|
||||
|
||||
case 'all':
|
||||
$this->legacyQueryString = 'all.0.'.$page;
|
||||
return 'list/all';
|
||||
break;
|
||||
|
||||
case 'tag': // url: news/tag/xxxxx
|
||||
$this->legacyQueryString = 'tag='.$parts[1];
|
||||
return 'list/tag';
|
||||
break;
|
||||
|
||||
case 'author': // url: news/author/xxxxx
|
||||
$this->legacyQueryString = 'author='.$parts[1].'&page='.$page;
|
||||
return 'list/author';
|
||||
break;
|
||||
|
||||
# force not found
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_NEWS, // Module name
|
||||
'label' => LAN_EURL_NEWS_REWRITE_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_NEWS_REWRITE_DESCR, //
|
||||
'examples' => array("{SITEURL}news/news-title")
|
||||
),
|
||||
'generate' => array('table'=> 'news', 'primary'=>'news_id', 'input'=>'news_title', 'output'=>'news_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 ###
|
||||
|
||||
//retrieve news_id by news_sef (
|
||||
public function itemIdByTitle($id)
|
||||
{
|
||||
$sql = e107::getDb('url');
|
||||
$tp = e107::getParser();
|
||||
$id = $tp->toDB($id);
|
||||
if($sql->select('news', 'news_id', "news_sef='{$id}'"))
|
||||
{
|
||||
$id = $sql->fetch();
|
||||
return $id['news_id'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//retrieve category_id by Title (XXX - category_sef column, equals to category_sef if not set explicit)
|
||||
public function categoryIdByTitle($id)
|
||||
{
|
||||
$sql = e107::getDb('url');
|
||||
$tp = e107::getParser();
|
||||
$id = $tp->toDB($id);
|
||||
if($sql->select('news_category', 'category_id', "category_sef='{$id}'"))
|
||||
{
|
||||
$id = $sql->fetch();
|
||||
return $id['category_id'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -1,210 +1,210 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Most balanced config - performance and friendly URLs
|
||||
* It contains a lot of examples (mostly complex), use them to play around and learn things :/
|
||||
* Generally, things are much more simpler...
|
||||
*
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_news_sef_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
'config' => array(
|
||||
'legacy' => '{e_BASE}news.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script; override per rule is allowed
|
||||
'format' => 'path', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'defaultRoute' => 'list/items', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
'urlSuffix' => '',
|
||||
'allowMain' => true,
|
||||
|
||||
### default vars mapping (create URL), override per rule is allowed
|
||||
'mapVars' => array(
|
||||
'news_id' => 'id',
|
||||
'news_sef' => 'name',
|
||||
),
|
||||
|
||||
### match will only check if parameter is empty to invalidate the assembling vs current rule
|
||||
'matchValue' => 'empty',
|
||||
|
||||
### Numerical array containing allowed vars by default (create URL, used for legacyQuery parsing in parse routine as well),
|
||||
### false means - disallow all vars beside those required by the rules
|
||||
### Override per rule is allowed
|
||||
'allowVars' => false,
|
||||
|
||||
### Best news - you don't need to write one and the same
|
||||
### regex over and over again. Even better news - you might avoid
|
||||
### writing regex at all! Just use the core regex templates, they
|
||||
### should fit almost every case.
|
||||
### Here is a test custom regex template:
|
||||
'varTemplates' => array('testIt' => '[\d]+'),
|
||||
|
||||
/* Predefined Core regex templates, see usage below
|
||||
'az' => '[A-Za-z]+', // NOTE - it won't match non-latin word characters!
|
||||
'alphanum' => '[\w\pL]+',
|
||||
'sefsecure' => '[\w\pL.\-\s!,]+',
|
||||
'secure' => '[^\/\'"\\<%]+',
|
||||
'number' => '[\d]+',
|
||||
'username' => '[\w\pL.\-\s!,]+',
|
||||
'azOptional' => '[A-Za-z]{0,}',
|
||||
'alphanumOptional' => '[\w\pL]{0,}',
|
||||
'sefsecureOptional' => '[\w\pL.\-\s!,]{0,}',
|
||||
'secureOptional' => '[^\/\'"\\<%]{0,}',
|
||||
'numberOptional' => '[\d]{0,}',
|
||||
'usernameOptional' => '[\w\pL.\-\s!,]{0,}',
|
||||
*/
|
||||
),
|
||||
|
||||
'rules' => array(
|
||||
### simple matches first - PERFORMANCE
|
||||
'' => array('list/items', 'allowVars' => array('page'), 'legacyQuery' => 'default.0.{page}', ),
|
||||
'Category' => array('list/items', 'allowVars' => array('page'), 'legacyQuery' => 'default.0.{page}', ),
|
||||
|
||||
## URL with ID and Title - no DB call, balanced performance, name optional
|
||||
## Demonstrating the usage of custom user defined regex template defined above - 'testIt'
|
||||
'Category/<id:{testIt}>/<name:{sefsecure}>' => array('list/category', 'allowVars' => array('page'), 'mapVars' => array('category_id' => 'id', 'category_sef' => 'name'), 'legacyQuery' => 'list.{id}.{page}'),
|
||||
|
||||
## URL with Title only - prettiest and slowest! Example with direct regex - no templates
|
||||
//'Category/<name:{sefsecure}>' => array('list/category', 'allowVars' => array('page'), 'mapVars' => array('category_sef' => 'name'), 'legacyQuery' => 'list.{name}.{page}', 'parseCallback' => 'categoryIdByTitle'),
|
||||
|
||||
## URL with ID only - best performance, fallback when no sef name provided
|
||||
'Category/<id:{number}>' => array('list/category', 'allowVars' => array('page'), 'legacyQuery' => 'list.{id}.{page}', 'mapVars' => array('category_id' => 'id')),
|
||||
|
||||
### View item requested by id or string, if you remove the catch ALL example, uncomment at least on row from this block
|
||||
### leading category name example - could be enabled together with the next example to handle creating of URLs without knowing the category title
|
||||
// 'View/<category:[\w\pL.\-\s]+>/<name:[\w\pL.\-\s]+>' => array('view/item', 'mapVars' => array('news_sef' => 'name', 'category_sef' => 'category'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
|
||||
// to be noted here - value 'name' is replaced by item id within the callback method; TODO replace news_sef with news_sef field
|
||||
// 'View/<name:{sefsecure}>' => array('view/item', 'mapVars' => array('news_sef' => 'name', 'news_id' => 'id'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
|
||||
// 'View/<id:{number}>' => array('view/item', 'mapVars' => array('news_id' => 'id'), 'legacyQuery' => 'extend.{id}'),
|
||||
|
||||
## All news
|
||||
'All' => array('list/all', 'allowVars' => array('page'), 'legacyQuery' => 'all.0.{page}'),
|
||||
|
||||
## URL with ID and Title - no DB call, balanced performance!
|
||||
'Short/<id:{number}>/<name:{sefsecure}>' => array('list/short', 'allowVars' => array('page'), 'mapVars' => array('category_id' => 'id', 'category_sef' => 'name'), 'legacyQuery' => 'cat.{id}.{page}'),
|
||||
## fallback when name is not provided
|
||||
'Short/<id:{number}>' => array('list/short', 'allowVars' => array('page'), 'mapVars' => array('category_id' => 'id'), 'legacyQuery' => 'cat.{id}.{page}'),
|
||||
|
||||
// less used after
|
||||
//'Brief/<id:[\d]+>' => array('list/short', 'allowVars' => array('page'), 'legacyQuery' => 'cat.{id}.{page}', 'mapVars' => array('category_id' => 'id')),
|
||||
'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}'),
|
||||
//'Year/<id:[\d]+>' => array('list/year', 'allowVars' => array('page'), 'legacyQuery' => 'year.{id}.{page}'), not supported yet
|
||||
|
||||
### View news item - kinda catch all - very bad performance when News is chosen as default namespace - two additional DB queries on every site call!
|
||||
## Leading category name - uncomment to enable
|
||||
//'<category:{sefsecure}>/<name:{sefsecure}>' => array('view/item', 'mapVars' => array('category_sef' => 'category', 'news_sef' => 'name', 'news_id' => 'id'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
|
||||
'View/<id:{number}>/<category:{sefsecure}>/<name:{sefsecure}>' => array('view/item', 'mapVars' => array('category_sef' => 'category', 'news_sef' => 'name', 'news_id' => 'id'), 'legacyQuery' => 'extend.{id}'),
|
||||
// Base location as item view - fallback if category sef is missing
|
||||
//'<name:{sefsecure}>' => array('view/item', 'mapVars' => array('news_id' => 'id', 'news_sef' => 'name'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
|
||||
// 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}'),
|
||||
|
||||
'Tag/<tag:{secure}>' => array('list/tag', 'allowVars' => array('page'), 'legacyQuery' => 'tag={tag}&page={page}'),
|
||||
|
||||
'Author/<author:{secure}>' => array('list/author', 'allowVars' => array('page'), 'legacyQuery' => 'author={author}&page={page}'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query mapping in format route?params:
|
||||
* - 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
|
||||
* - list/short?id=xxx[&page=xxx] -> cat.id.page
|
||||
* - list/day?id=xxx -> ?day-id
|
||||
* - list/month?id=xxx -> ?month-id
|
||||
* - list/year?id=xxx -> ?year-id
|
||||
* - list/nextprev?route=xxx -> PARSED_ROUTE.[FROM] (recursive parse() call)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 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_NEWS, // Module name
|
||||
'label' => LAN_EURL_NEWS_REWRITEX_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_NEWS_REWRITEX_DESCR, //
|
||||
'examples' => array('{SITEURL}news/1/news-title')
|
||||
),
|
||||
'generate' => array('table'=> 'news', 'primary'=>'news_id', 'input'=>'news_title', 'output'=>'news_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');
|
||||
if(($id = $request->getRequestParam('id')))
|
||||
{
|
||||
$request->setRequestParam('name', $id);
|
||||
return;
|
||||
}
|
||||
elseif(!$name) return;
|
||||
elseif(is_numeric($name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = e107::getDb('url');
|
||||
$name = e107::getParser()->toDB($name);
|
||||
if($sql->db_Select('news', 'news_id', "news_sef='{$name}'")) // TODO - it'll be news_sef (new) field
|
||||
{
|
||||
$name = $sql->db_Fetch();
|
||||
$request->setRequestParam('name', $name['news_id']);
|
||||
}
|
||||
else $request->setRequestParam('name', 0);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* list/items by name callback
|
||||
* @param eRequest $request
|
||||
*/
|
||||
/*public function categoryIdByTitle(eRequest $request)
|
||||
{
|
||||
$name = $request->getRequestParam('name');
|
||||
if(($id = $request->getRequestParam('id')))
|
||||
{
|
||||
$request->setRequestParam('name', $id);
|
||||
return;
|
||||
}
|
||||
elseif(!$name) return;
|
||||
elseif(is_numeric($name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = e107::getDb('url');
|
||||
$id = e107::getParser()->toDB($name);
|
||||
if($sql->db_Select('news_category', 'category_id', "category_sef='{$name}'")) // TODO - it'll be category_sef (new) field
|
||||
{
|
||||
$name = $sql->db_Fetch();
|
||||
$request->setRequestParam('name', $name['category_id']);
|
||||
}
|
||||
else $request->setRequestParam('name', 0);
|
||||
}*/
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Most balanced config - performance and friendly URLs
|
||||
* It contains a lot of examples (mostly complex), use them to play around and learn things :/
|
||||
* Generally, things are much more simpler...
|
||||
*
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_news_sef_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
'config' => array(
|
||||
'legacy' => '{e_BASE}news.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script; override per rule is allowed
|
||||
'format' => 'path', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'defaultRoute' => 'list/items', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
'urlSuffix' => '',
|
||||
'allowMain' => true,
|
||||
|
||||
### default vars mapping (create URL), override per rule is allowed
|
||||
'mapVars' => array(
|
||||
'news_id' => 'id',
|
||||
'news_sef' => 'name',
|
||||
),
|
||||
|
||||
### match will only check if parameter is empty to invalidate the assembling vs current rule
|
||||
'matchValue' => 'empty',
|
||||
|
||||
### Numerical array containing allowed vars by default (create URL, used for legacyQuery parsing in parse routine as well),
|
||||
### false means - disallow all vars beside those required by the rules
|
||||
### Override per rule is allowed
|
||||
'allowVars' => false,
|
||||
|
||||
### Best news - you don't need to write one and the same
|
||||
### regex over and over again. Even better news - you might avoid
|
||||
### writing regex at all! Just use the core regex templates, they
|
||||
### should fit almost every case.
|
||||
### Here is a test custom regex template:
|
||||
'varTemplates' => array('testIt' => '[\d]+'),
|
||||
|
||||
/* Predefined Core regex templates, see usage below
|
||||
'az' => '[A-Za-z]+', // NOTE - it won't match non-latin word characters!
|
||||
'alphanum' => '[\w\pL]+',
|
||||
'sefsecure' => '[\w\pL.\-\s!,]+',
|
||||
'secure' => '[^\/\'"\\<%]+',
|
||||
'number' => '[\d]+',
|
||||
'username' => '[\w\pL.\-\s!,]+',
|
||||
'azOptional' => '[A-Za-z]{0,}',
|
||||
'alphanumOptional' => '[\w\pL]{0,}',
|
||||
'sefsecureOptional' => '[\w\pL.\-\s!,]{0,}',
|
||||
'secureOptional' => '[^\/\'"\\<%]{0,}',
|
||||
'numberOptional' => '[\d]{0,}',
|
||||
'usernameOptional' => '[\w\pL.\-\s!,]{0,}',
|
||||
*/
|
||||
),
|
||||
|
||||
'rules' => array(
|
||||
### simple matches first - PERFORMANCE
|
||||
'' => array('list/items', 'allowVars' => array('page'), 'legacyQuery' => 'default.0.{page}', ),
|
||||
'Category' => array('list/items', 'allowVars' => array('page'), 'legacyQuery' => 'default.0.{page}', ),
|
||||
|
||||
## URL with ID and Title - no DB call, balanced performance, name optional
|
||||
## Demonstrating the usage of custom user defined regex template defined above - 'testIt'
|
||||
'Category/<id:{testIt}>/<name:{sefsecure}>' => array('list/category', 'allowVars' => array('page'), 'mapVars' => array('category_id' => 'id', 'category_sef' => 'name'), 'legacyQuery' => 'list.{id}.{page}'),
|
||||
|
||||
## URL with Title only - prettiest and slowest! Example with direct regex - no templates
|
||||
//'Category/<name:{sefsecure}>' => array('list/category', 'allowVars' => array('page'), 'mapVars' => array('category_sef' => 'name'), 'legacyQuery' => 'list.{name}.{page}', 'parseCallback' => 'categoryIdByTitle'),
|
||||
|
||||
## URL with ID only - best performance, fallback when no sef name provided
|
||||
'Category/<id:{number}>' => array('list/category', 'allowVars' => array('page'), 'legacyQuery' => 'list.{id}.{page}', 'mapVars' => array('category_id' => 'id')),
|
||||
|
||||
### View item requested by id or string, if you remove the catch ALL example, uncomment at least on row from this block
|
||||
### leading category name example - could be enabled together with the next example to handle creating of URLs without knowing the category title
|
||||
// 'View/<category:[\w\pL.\-\s]+>/<name:[\w\pL.\-\s]+>' => array('view/item', 'mapVars' => array('news_sef' => 'name', 'category_sef' => 'category'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
|
||||
// to be noted here - value 'name' is replaced by item id within the callback method; TODO replace news_sef with news_sef field
|
||||
// 'View/<name:{sefsecure}>' => array('view/item', 'mapVars' => array('news_sef' => 'name', 'news_id' => 'id'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
|
||||
// 'View/<id:{number}>' => array('view/item', 'mapVars' => array('news_id' => 'id'), 'legacyQuery' => 'extend.{id}'),
|
||||
|
||||
## All news
|
||||
'All' => array('list/all', 'allowVars' => array('page'), 'legacyQuery' => 'all.0.{page}'),
|
||||
|
||||
## URL with ID and Title - no DB call, balanced performance!
|
||||
'Short/<id:{number}>/<name:{sefsecure}>' => array('list/short', 'allowVars' => array('page'), 'mapVars' => array('category_id' => 'id', 'category_sef' => 'name'), 'legacyQuery' => 'cat.{id}.{page}'),
|
||||
## fallback when name is not provided
|
||||
'Short/<id:{number}>' => array('list/short', 'allowVars' => array('page'), 'mapVars' => array('category_id' => 'id'), 'legacyQuery' => 'cat.{id}.{page}'),
|
||||
|
||||
// less used after
|
||||
//'Brief/<id:[\d]+>' => array('list/short', 'allowVars' => array('page'), 'legacyQuery' => 'cat.{id}.{page}', 'mapVars' => array('category_id' => 'id')),
|
||||
'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}'),
|
||||
//'Year/<id:[\d]+>' => array('list/year', 'allowVars' => array('page'), 'legacyQuery' => 'year.{id}.{page}'), not supported yet
|
||||
|
||||
### View news item - kinda catch all - very bad performance when News is chosen as default namespace - two additional DB queries on every site call!
|
||||
## Leading category name - uncomment to enable
|
||||
//'<category:{sefsecure}>/<name:{sefsecure}>' => array('view/item', 'mapVars' => array('category_sef' => 'category', 'news_sef' => 'name', 'news_id' => 'id'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
|
||||
'View/<id:{number}>/<category:{sefsecure}>/<name:{sefsecure}>' => array('view/item', 'mapVars' => array('category_sef' => 'category', 'news_sef' => 'name', 'news_id' => 'id'), 'legacyQuery' => 'extend.{id}'),
|
||||
// Base location as item view - fallback if category sef is missing
|
||||
//'<name:{sefsecure}>' => array('view/item', 'mapVars' => array('news_id' => 'id', 'news_sef' => 'name'), 'legacyQuery' => 'extend.{name}', 'parseCallback' => 'itemIdByTitle'),
|
||||
// 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}'),
|
||||
|
||||
'Tag/<tag:{secure}>' => array('list/tag', 'allowVars' => array('page'), 'legacyQuery' => 'tag={tag}&page={page}'),
|
||||
|
||||
'Author/<author:{secure}>' => array('list/author', 'allowVars' => array('page'), 'legacyQuery' => 'author={author}&page={page}'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query mapping in format route?params:
|
||||
* - 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
|
||||
* - list/short?id=xxx[&page=xxx] -> cat.id.page
|
||||
* - list/day?id=xxx -> ?day-id
|
||||
* - list/month?id=xxx -> ?month-id
|
||||
* - list/year?id=xxx -> ?year-id
|
||||
* - list/nextprev?route=xxx -> PARSED_ROUTE.[FROM] (recursive parse() call)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 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_NEWS, // Module name
|
||||
'label' => LAN_EURL_NEWS_REWRITEX_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_NEWS_REWRITEX_DESCR, //
|
||||
'examples' => array('{SITEURL}news/1/news-title')
|
||||
),
|
||||
'generate' => array('table'=> 'news', 'primary'=>'news_id', 'input'=>'news_title', 'output'=>'news_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');
|
||||
if(($id = $request->getRequestParam('id')))
|
||||
{
|
||||
$request->setRequestParam('name', $id);
|
||||
return;
|
||||
}
|
||||
elseif(!$name) return;
|
||||
elseif(is_numeric($name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = e107::getDb('url');
|
||||
$name = e107::getParser()->toDB($name);
|
||||
if($sql->db_Select('news', 'news_id', "news_sef='{$name}'")) // TODO - it'll be news_sef (new) field
|
||||
{
|
||||
$name = $sql->db_Fetch();
|
||||
$request->setRequestParam('name', $name['news_id']);
|
||||
}
|
||||
else $request->setRequestParam('name', 0);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* list/items by name callback
|
||||
* @param eRequest $request
|
||||
*/
|
||||
/*public function categoryIdByTitle(eRequest $request)
|
||||
{
|
||||
$name = $request->getRequestParam('name');
|
||||
if(($id = $request->getRequestParam('id')))
|
||||
{
|
||||
$request->setRequestParam('name', $id);
|
||||
return;
|
||||
}
|
||||
elseif(!$name) return;
|
||||
elseif(is_numeric($name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = e107::getDb('url');
|
||||
$id = e107::getParser()->toDB($name);
|
||||
if($sql->db_Select('news_category', 'category_id', "category_sef='{$name}'")) // TODO - it'll be category_sef (new) field
|
||||
{
|
||||
$name = $sql->db_Fetch();
|
||||
$request->setRequestParam('name', $name['category_id']);
|
||||
}
|
||||
else $request->setRequestParam('name', 0);
|
||||
}*/
|
||||
}
|
@@ -1,208 +1,208 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Default config - create ONLY - old legacy URLs
|
||||
* All possible config options added here - to be used as a reference.
|
||||
* A good programming practice is to remove all non-used options.
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_news_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
'config' => array(
|
||||
'allowMain' => false, // [optional] default false; disallow this module (while using this config) to be set as site main URL namespace
|
||||
'noSingleEntry' => true, // [optional] default false; disallow this module to be shown via single entry point when this config is used
|
||||
'legacy' => '{e_BASE}news.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script
|
||||
'format' => 'get', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'selfParse' => true, // [optional] default false; use only this->parse() method, no core routine URL parsing
|
||||
'selfCreate' => true, // [optional] default false; use only this->create() method, no core routine URL creating
|
||||
'defaultRoute' => 'list/new',// [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
'errorRoute' => '', // [optional] default empty; route (no leading module) used when module is found but no inner route is matched, leave empty to force error 404 page
|
||||
'urlSuffix' => '', // [optional] default empty; string to append to the URL (e.g. .html), not used when format is 'get' or legacy non-empty
|
||||
|
||||
### [optional] used only when assembling URLs via rules();
|
||||
### if 'empty' - check if the required parameter is empty (results in assemble fail),
|
||||
### if 1 or true - it uses the route pattern to match every parameter - EXTREMELY SLOW, be warned
|
||||
'matchValue' => false,
|
||||
|
||||
|
||||
### [optional] vars mapping (create URL routine), override per rule is allowed
|
||||
### Keys of this array will be used as a map for finding values from the provided parameters array.
|
||||
### Those values will be assigned to new keys - corresponding values of mapVars array
|
||||
### It gives extremely flexibility when used with allowVars. For example we pass $news item array as
|
||||
### it's retrieved from the DB, with no modifications. This gives us the freedom to create any variations of news
|
||||
### URLs using the DB data with a single line URL rule. Another aspect of this feature is the simplified code
|
||||
### for URL assembling - we just do eRouter::create($theRoute, $newsDbArray)
|
||||
### Not used when in selfCreate mod (create url)
|
||||
'mapVars' => array(
|
||||
//'news_id' => 'id',
|
||||
//'news_sef' => 'name',
|
||||
),
|
||||
|
||||
### [optional] allowed vars definition (create URL routine), override per rule is allowed
|
||||
### This numerical array serves as a filter for passed vars when creating URLs
|
||||
### Everything outside this scope is ignored while assembling URLs. Exception are route variables.
|
||||
### For example: when <id:[\d]+> is present in the route string, there is no need to extra allow 'id'
|
||||
### To disallow everything but route variables, set allowVars to false
|
||||
### When format is get, false value will disallow everything (no params) and default preserved variables
|
||||
### will be extracted from mapVars (if available)
|
||||
### Default value is empty array
|
||||
### Not used when in selfCreate mod (create url)
|
||||
'allowVars' => array(/*'page', 'name'*/),
|
||||
|
||||
### Those are regex templates, allowing us to avoid the repeating regex patterns writing in your rules.
|
||||
### varTemplates are merged with the core predefined templates. Full list with core regex templates and examples can be found
|
||||
### in rewrite_extended news URL config
|
||||
'varTemplates' => array(/*'testIt' => '[\d]+'*/),
|
||||
),
|
||||
|
||||
'rules' => array(), // rule set array - can't be used with format 'get' and noSingleEntry true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* If create returns string, 'module' value won't be prefixed from the router
|
||||
* Query mapping in format route?params:
|
||||
* - view/item?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
|
||||
* - list/short?id=xxx[&page=xxx] -> cat.id.page
|
||||
* - list/day?id=xxx -> ?day-id
|
||||
* - list/month?id=xxx -> ?month-id
|
||||
* - list/year?id=xxx -> ?year-id
|
||||
* - list/nextprev?route=xxx -> PARSED_ROUTE.[FROM] (recursive parse() call)
|
||||
*/
|
||||
public function create($route, $params = array(),$options = array())
|
||||
{
|
||||
if(!$params) return 'news.php';
|
||||
|
||||
if(!$route) $route = 'list/items';
|
||||
if(is_string($route)) $route = explode('/', $route, 2);
|
||||
if('index' == $route[0])
|
||||
{
|
||||
$route[0] = 'list';
|
||||
$route[1] = 'items';
|
||||
}
|
||||
elseif('index' == $route[1])
|
||||
{
|
||||
$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'];
|
||||
//if(isset($params['category_sef']) && !empty($params['category_sef'])) $params['category'] = $params['category_sef'];
|
||||
|
||||
$url = 'news.php?';
|
||||
if('--FROM--' != vartrue($params['page'])) $page = varset($params['page']) ? intval($params['page']) : '0';
|
||||
else $page = '--FROM--';
|
||||
|
||||
if($route[0] == 'view')
|
||||
{
|
||||
switch ($route[1])
|
||||
{
|
||||
case 'item':
|
||||
$url .= 'extend.'.$params['id']; //item.* view is deprecated
|
||||
break;
|
||||
|
||||
default:
|
||||
$url = 'news.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif($route[0] == 'list')
|
||||
{
|
||||
switch ($route[1])
|
||||
{
|
||||
case '':
|
||||
case 'items':
|
||||
if(!$page) $url = 'news.php';
|
||||
else $url .= 'default.0.'.$page; //item.* view is deprecated
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
if(!vartrue($params['id']))
|
||||
{
|
||||
$url .= 'default.0.'.$page;
|
||||
}
|
||||
else
|
||||
{
|
||||
$url .= 'list.'.$params['id'].'.'.$page; // 'category_id' would break news_categories_menu.
|
||||
}
|
||||
break;
|
||||
|
||||
case 'all':
|
||||
$url .= 'all.'.$params['id'].'.'.$page;
|
||||
break;
|
||||
|
||||
case 'tag':
|
||||
$url .= 'tag='.$params['tag'].'&page='.$page;
|
||||
break;
|
||||
|
||||
case 'author':
|
||||
$url .= 'author='.$params['author'].'&page='.$page;
|
||||
break;
|
||||
|
||||
case 'short':
|
||||
$url .= 'cat.'.$params['id'].'.'.$page;
|
||||
break;
|
||||
|
||||
case 'day':
|
||||
case 'month':
|
||||
case 'year':
|
||||
if($page) $page = '.'.$page;
|
||||
$url .= $route[1].'.'.$params['id'].$page;
|
||||
break;
|
||||
|
||||
default:
|
||||
$url = 'news.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = 'news.php';
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function parse($pathInfo, $params = array(), eRequest $request = null, eRouter $router = null, $config = array())
|
||||
{
|
||||
// this config doesn't support parsing, it's done by the module entry script (news.php)
|
||||
// this means News are not available via single entry point if this config is currently active
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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_NEWS, // Module name
|
||||
'label' => LAN_EURL_DEFAULT, // Current profile name
|
||||
'description' => LAN_EURL_LEGACY, //
|
||||
'examples' => array("{SITEURL}news.php?extend.1")
|
||||
),
|
||||
// 'generate' => array('table'=> 'news', 'primary'=>'news_id', 'input'=>'news_title', 'output'=>'news_sef'),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Default config - create ONLY - old legacy URLs
|
||||
* All possible config options added here - to be used as a reference.
|
||||
* A good programming practice is to remove all non-used options.
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_news_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
'config' => array(
|
||||
'allowMain' => false, // [optional] default false; disallow this module (while using this config) to be set as site main URL namespace
|
||||
'noSingleEntry' => true, // [optional] default false; disallow this module to be shown via single entry point when this config is used
|
||||
'legacy' => '{e_BASE}news.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script
|
||||
'format' => 'get', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'selfParse' => true, // [optional] default false; use only this->parse() method, no core routine URL parsing
|
||||
'selfCreate' => true, // [optional] default false; use only this->create() method, no core routine URL creating
|
||||
'defaultRoute' => 'list/new',// [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
'errorRoute' => '', // [optional] default empty; route (no leading module) used when module is found but no inner route is matched, leave empty to force error 404 page
|
||||
'urlSuffix' => '', // [optional] default empty; string to append to the URL (e.g. .html), not used when format is 'get' or legacy non-empty
|
||||
|
||||
### [optional] used only when assembling URLs via rules();
|
||||
### if 'empty' - check if the required parameter is empty (results in assemble fail),
|
||||
### if 1 or true - it uses the route pattern to match every parameter - EXTREMELY SLOW, be warned
|
||||
'matchValue' => false,
|
||||
|
||||
|
||||
### [optional] vars mapping (create URL routine), override per rule is allowed
|
||||
### Keys of this array will be used as a map for finding values from the provided parameters array.
|
||||
### Those values will be assigned to new keys - corresponding values of mapVars array
|
||||
### It gives extremely flexibility when used with allowVars. For example we pass $news item array as
|
||||
### it's retrieved from the DB, with no modifications. This gives us the freedom to create any variations of news
|
||||
### URLs using the DB data with a single line URL rule. Another aspect of this feature is the simplified code
|
||||
### for URL assembling - we just do eRouter::create($theRoute, $newsDbArray)
|
||||
### Not used when in selfCreate mod (create url)
|
||||
'mapVars' => array(
|
||||
//'news_id' => 'id',
|
||||
//'news_sef' => 'name',
|
||||
),
|
||||
|
||||
### [optional] allowed vars definition (create URL routine), override per rule is allowed
|
||||
### This numerical array serves as a filter for passed vars when creating URLs
|
||||
### Everything outside this scope is ignored while assembling URLs. Exception are route variables.
|
||||
### For example: when <id:[\d]+> is present in the route string, there is no need to extra allow 'id'
|
||||
### To disallow everything but route variables, set allowVars to false
|
||||
### When format is get, false value will disallow everything (no params) and default preserved variables
|
||||
### will be extracted from mapVars (if available)
|
||||
### Default value is empty array
|
||||
### Not used when in selfCreate mod (create url)
|
||||
'allowVars' => array(/*'page', 'name'*/),
|
||||
|
||||
### Those are regex templates, allowing us to avoid the repeating regex patterns writing in your rules.
|
||||
### varTemplates are merged with the core predefined templates. Full list with core regex templates and examples can be found
|
||||
### in rewrite_extended news URL config
|
||||
'varTemplates' => array(/*'testIt' => '[\d]+'*/),
|
||||
),
|
||||
|
||||
'rules' => array(), // rule set array - can't be used with format 'get' and noSingleEntry true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* If create returns string, 'module' value won't be prefixed from the router
|
||||
* Query mapping in format route?params:
|
||||
* - view/item?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
|
||||
* - list/short?id=xxx[&page=xxx] -> cat.id.page
|
||||
* - list/day?id=xxx -> ?day-id
|
||||
* - list/month?id=xxx -> ?month-id
|
||||
* - list/year?id=xxx -> ?year-id
|
||||
* - list/nextprev?route=xxx -> PARSED_ROUTE.[FROM] (recursive parse() call)
|
||||
*/
|
||||
public function create($route, $params = array(),$options = array())
|
||||
{
|
||||
if(!$params) return 'news.php';
|
||||
|
||||
if(!$route) $route = 'list/items';
|
||||
if(is_string($route)) $route = explode('/', $route, 2);
|
||||
if('index' == $route[0])
|
||||
{
|
||||
$route[0] = 'list';
|
||||
$route[1] = 'items';
|
||||
}
|
||||
elseif('index' == $route[1])
|
||||
{
|
||||
$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'];
|
||||
//if(isset($params['category_sef']) && !empty($params['category_sef'])) $params['category'] = $params['category_sef'];
|
||||
|
||||
$url = 'news.php?';
|
||||
if('--FROM--' != vartrue($params['page'])) $page = varset($params['page']) ? intval($params['page']) : '0';
|
||||
else $page = '--FROM--';
|
||||
|
||||
if($route[0] == 'view')
|
||||
{
|
||||
switch ($route[1])
|
||||
{
|
||||
case 'item':
|
||||
$url .= 'extend.'.$params['id']; //item.* view is deprecated
|
||||
break;
|
||||
|
||||
default:
|
||||
$url = 'news.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif($route[0] == 'list')
|
||||
{
|
||||
switch ($route[1])
|
||||
{
|
||||
case '':
|
||||
case 'items':
|
||||
if(!$page) $url = 'news.php';
|
||||
else $url .= 'default.0.'.$page; //item.* view is deprecated
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
if(!vartrue($params['id']))
|
||||
{
|
||||
$url .= 'default.0.'.$page;
|
||||
}
|
||||
else
|
||||
{
|
||||
$url .= 'list.'.$params['id'].'.'.$page; // 'category_id' would break news_categories_menu.
|
||||
}
|
||||
break;
|
||||
|
||||
case 'all':
|
||||
$url .= 'all.'.$params['id'].'.'.$page;
|
||||
break;
|
||||
|
||||
case 'tag':
|
||||
$url .= 'tag='.$params['tag'].'&page='.$page;
|
||||
break;
|
||||
|
||||
case 'author':
|
||||
$url .= 'author='.$params['author'].'&page='.$page;
|
||||
break;
|
||||
|
||||
case 'short':
|
||||
$url .= 'cat.'.$params['id'].'.'.$page;
|
||||
break;
|
||||
|
||||
case 'day':
|
||||
case 'month':
|
||||
case 'year':
|
||||
if($page) $page = '.'.$page;
|
||||
$url .= $route[1].'.'.$params['id'].$page;
|
||||
break;
|
||||
|
||||
default:
|
||||
$url = 'news.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = 'news.php';
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function parse($pathInfo, $params = array(), eRequest $request = null, eRouter $router = null, $config = array())
|
||||
{
|
||||
// this config doesn't support parsing, it's done by the module entry script (news.php)
|
||||
// this means News are not available via single entry point if this config is currently active
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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_NEWS, // Module name
|
||||
'label' => LAN_EURL_DEFAULT, // Current profile name
|
||||
'description' => LAN_EURL_LEGACY, //
|
||||
'examples' => array("{SITEURL}news.php?extend.1")
|
||||
),
|
||||
// 'generate' => array('table'=> 'news', 'primary'=>'news_id', 'input'=>'news_title', 'output'=>'news_sef'),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,151 +1,151 @@
|
||||
<?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_noid_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)
|
||||
|
||||
'allowVars' => array(
|
||||
'page',
|
||||
),
|
||||
),
|
||||
|
||||
'rules' => array(
|
||||
'chapter/<name:{sefsecureOptional}>' => array('chapter/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id', 'chapter_sef'=>'name'), 'legacyQuery' => 'ch={id}', 'parseCallback' => 'chapterIdByTitle'),
|
||||
'book/<name:{sefsecureOptional}>' => array('book/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id', 'chapter_sef'=>'name'), 'legacyQuery' => 'bk={id}', 'parseCallback' => 'chapterIdByTitle'),
|
||||
'<name:{secure}>' => array('view/index', 'mapVars' => array('page_id'=>'id', 'page_sef'=>'name'), 'legacyQuery' => '{id}.{page}', 'parseCallback' => 'itemIdByTitle'),
|
||||
### Used for assembling only
|
||||
'<other:{secure}>' => array('view/other', 'mapVars' => array('page_id'=>'id', 'page_sef'=>'other'), 'legacyQuery' => '{id}.{page}', 'parseCallback' => 'itemIdByTitle'),
|
||||
'/' => array('list/index', 'allowVars' => false, '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/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}'"))
|
||||
{
|
||||
$name = $sql->fetch();
|
||||
$request->setRequestParam('name', $name['page_id'])
|
||||
->setRequestParam('id', $name['page_id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ADMIN)
|
||||
{
|
||||
e107::getMessage()->addError("Couldn't find a page with a SEF URL value of '".$name."'");
|
||||
}
|
||||
$request->setRequestParam('name', 0)
|
||||
->setRequestParam('id', 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}'"))
|
||||
{
|
||||
$name = $sql->fetch();
|
||||
$request->setRequestParam('id', $name['chapter_id'])
|
||||
->setRequestParam('name', $name['chapter_id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ADMIN)
|
||||
{
|
||||
e107::getMessage()->addError("Couldn't find a book or chapter with a SEF URL value of '".$name."'");
|
||||
}
|
||||
$request->setRequestParam('id', 0)
|
||||
->setRequestParam('name', 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
<?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_noid_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)
|
||||
|
||||
'allowVars' => array(
|
||||
'page',
|
||||
),
|
||||
),
|
||||
|
||||
'rules' => array(
|
||||
'chapter/<name:{sefsecureOptional}>' => array('chapter/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id', 'chapter_sef'=>'name'), 'legacyQuery' => 'ch={id}', 'parseCallback' => 'chapterIdByTitle'),
|
||||
'book/<name:{sefsecureOptional}>' => array('book/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id', 'chapter_sef'=>'name'), 'legacyQuery' => 'bk={id}', 'parseCallback' => 'chapterIdByTitle'),
|
||||
'<name:{secure}>' => array('view/index', 'mapVars' => array('page_id'=>'id', 'page_sef'=>'name'), 'legacyQuery' => '{id}.{page}', 'parseCallback' => 'itemIdByTitle'),
|
||||
### Used for assembling only
|
||||
'<other:{secure}>' => array('view/other', 'mapVars' => array('page_id'=>'id', 'page_sef'=>'other'), 'legacyQuery' => '{id}.{page}', 'parseCallback' => 'itemIdByTitle'),
|
||||
'/' => array('list/index', 'allowVars' => false, '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/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}'"))
|
||||
{
|
||||
$name = $sql->fetch();
|
||||
$request->setRequestParam('name', $name['page_id'])
|
||||
->setRequestParam('id', $name['page_id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ADMIN)
|
||||
{
|
||||
e107::getMessage()->addError("Couldn't find a page with a SEF URL value of '".$name."'");
|
||||
}
|
||||
$request->setRequestParam('name', 0)
|
||||
->setRequestParam('id', 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}'"))
|
||||
{
|
||||
$name = $sql->fetch();
|
||||
$request->setRequestParam('id', $name['chapter_id'])
|
||||
->setRequestParam('name', $name['chapter_id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ADMIN)
|
||||
{
|
||||
e107::getMessage()->addError("Couldn't find a book or chapter with a SEF URL value of '".$name."'");
|
||||
}
|
||||
$request->setRequestParam('id', 0)
|
||||
->setRequestParam('name', 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,67 +1,67 @@
|
||||
<?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_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',
|
||||
),
|
||||
),
|
||||
|
||||
'rules' => array(
|
||||
'<id:{number}>/<name:{sefsecureOptional}>' => array('view/index', 'legacyQuery' => '{id}.{page}', ),
|
||||
### Used for assembling only
|
||||
'<id:{number}>/<other:{sefsecureOptional}>' => array('view/other', 'mapVars' => array('page_id'=>'id', 'page_sef'=>'other'), 'legacyQuery' => '{id}.{page}', ),
|
||||
'chapter/<id:{number}>/<name:{sefsecureOptional}>' => array('chapter/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id','chapter_sef'=>'name'), 'legacyQuery' => 'ch={id}' ),
|
||||
'book/<id:{number}>/<name:{sefsecureOptional}>' => array('book/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id','chapter_sef'=>'name'), 'legacyQuery' => 'bk={id}' ),
|
||||
|
||||
### page list
|
||||
'/' => array('list/index', 'legacyQuery' => '', ),
|
||||
) // rule set array
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_SEF_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_PAGE_SEF_DESCR, //
|
||||
'examples' => array("{SITEURL}page/1/page-name")
|
||||
),
|
||||
'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;
|
||||
}
|
||||
}
|
||||
<?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_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',
|
||||
),
|
||||
),
|
||||
|
||||
'rules' => array(
|
||||
'<id:{number}>/<name:{sefsecureOptional}>' => array('view/index', 'legacyQuery' => '{id}.{page}', ),
|
||||
### Used for assembling only
|
||||
'<id:{number}>/<other:{sefsecureOptional}>' => array('view/other', 'mapVars' => array('page_id'=>'id', 'page_sef'=>'other'), 'legacyQuery' => '{id}.{page}', ),
|
||||
'chapter/<id:{number}>/<name:{sefsecureOptional}>' => array('chapter/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id','chapter_sef'=>'name'), 'legacyQuery' => 'ch={id}' ),
|
||||
'book/<id:{number}>/<name:{sefsecureOptional}>' => array('book/index', 'allowVars' => false, 'mapVars' => array('chapter_id'=>'id','chapter_sef'=>'name'), 'legacyQuery' => 'bk={id}' ),
|
||||
|
||||
### page list
|
||||
'/' => array('list/index', 'legacyQuery' => '', ),
|
||||
) // rule set array
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_SEF_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_PAGE_SEF_DESCR, //
|
||||
'examples' => array("{SITEURL}page/1/page-name")
|
||||
),
|
||||
'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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,131 +1,131 @@
|
||||
<?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_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'noSingleEntry' => true, // [optional] default false; disallow this module to be shown via single entry point when this config is used
|
||||
'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' => 'get', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'selfParse' => true, // [optional] default false; use only this->parse() method, no core routine URL parsing
|
||||
'selfCreate' => true, // [optional] default false; use only this->create() method, no core routine URL creating
|
||||
'defaultRoute' => '', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
'errorRoute' => '', // [optional] default empty; route (no leading module) used when module is found but no inner route is matched, leave empty to force error 404 page
|
||||
'urlSuffix' => '', // [optional] default empty; string to append to the URL (e.g. .html)
|
||||
'mapVars' => array(),
|
||||
'allowVars' => array(),
|
||||
),
|
||||
|
||||
'rules' => array() // rule set array
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function create($route, $params = array(), $options = array())
|
||||
{
|
||||
if(!$params) return 'page.php';
|
||||
|
||||
if(is_string($route))
|
||||
{
|
||||
$route = explode('/', $route, 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(!varset($route[1])) $route[1] = 'index';
|
||||
|
||||
$url = 'page.php?';
|
||||
|
||||
if(isset($params['chapter_id']) && !empty($params['chapter_id']))
|
||||
{
|
||||
$params['id'] = $params['chapter_id'];
|
||||
}
|
||||
|
||||
switch ($route[0])
|
||||
{
|
||||
case 'book':
|
||||
|
||||
if(!empty($params['book_id']))
|
||||
{
|
||||
$params['id'] = $params['book_id'];
|
||||
}
|
||||
|
||||
$url .= "bk=".intval($params['id']);
|
||||
break;
|
||||
|
||||
case 'chapter':
|
||||
$url .= "ch=".intval($params['id']);
|
||||
break;
|
||||
|
||||
case 'view':
|
||||
default:
|
||||
## aliases as retrieved from the DB, map vars to proper values
|
||||
if(isset($params['page_title']) && !empty($params['page_title']))
|
||||
{
|
||||
$params['name'] = $params['page_title'];
|
||||
}
|
||||
|
||||
if(isset($params['page_id']) && !empty($params['page_id']))
|
||||
{
|
||||
$params['id'] = $params['page_id'];
|
||||
}
|
||||
|
||||
if('--FROM--' != vartrue($params['page']))
|
||||
{
|
||||
$page = varset($params['page']) ? intval($params['page']) : '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
$page = '--FROM--';
|
||||
}
|
||||
|
||||
$url .= "id=".intval($params['id']).($page ? '.'.$page : '');
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_DEFAULT, // Current profile name
|
||||
'description' => LAN_EURL_LEGACY, //
|
||||
'examples' => array("{SITEURL}page.php?1","{SITEURL}page.php?id=1")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
public function parse($pathInfo, $params = array(), eRequest $request = null, eRouter $router = null, $config = array())
|
||||
{
|
||||
// this config doesn't support parsing, it's done by the module entry script (news.php)
|
||||
// this means News are not available via single entry point if this config is currently active
|
||||
return false;
|
||||
}
|
||||
}
|
||||
<?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_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'noSingleEntry' => true, // [optional] default false; disallow this module to be shown via single entry point when this config is used
|
||||
'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' => 'get', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'selfParse' => true, // [optional] default false; use only this->parse() method, no core routine URL parsing
|
||||
'selfCreate' => true, // [optional] default false; use only this->create() method, no core routine URL creating
|
||||
'defaultRoute' => '', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
'errorRoute' => '', // [optional] default empty; route (no leading module) used when module is found but no inner route is matched, leave empty to force error 404 page
|
||||
'urlSuffix' => '', // [optional] default empty; string to append to the URL (e.g. .html)
|
||||
'mapVars' => array(),
|
||||
'allowVars' => array(),
|
||||
),
|
||||
|
||||
'rules' => array() // rule set array
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function create($route, $params = array(), $options = array())
|
||||
{
|
||||
if(!$params) return 'page.php';
|
||||
|
||||
if(is_string($route))
|
||||
{
|
||||
$route = explode('/', $route, 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(!varset($route[1])) $route[1] = 'index';
|
||||
|
||||
$url = 'page.php?';
|
||||
|
||||
if(isset($params['chapter_id']) && !empty($params['chapter_id']))
|
||||
{
|
||||
$params['id'] = $params['chapter_id'];
|
||||
}
|
||||
|
||||
switch ($route[0])
|
||||
{
|
||||
case 'book':
|
||||
|
||||
if(!empty($params['book_id']))
|
||||
{
|
||||
$params['id'] = $params['book_id'];
|
||||
}
|
||||
|
||||
$url .= "bk=".intval($params['id']);
|
||||
break;
|
||||
|
||||
case 'chapter':
|
||||
$url .= "ch=".intval($params['id']);
|
||||
break;
|
||||
|
||||
case 'view':
|
||||
default:
|
||||
## aliases as retrieved from the DB, map vars to proper values
|
||||
if(isset($params['page_title']) && !empty($params['page_title']))
|
||||
{
|
||||
$params['name'] = $params['page_title'];
|
||||
}
|
||||
|
||||
if(isset($params['page_id']) && !empty($params['page_id']))
|
||||
{
|
||||
$params['id'] = $params['page_id'];
|
||||
}
|
||||
|
||||
if('--FROM--' != vartrue($params['page']))
|
||||
{
|
||||
$page = varset($params['page']) ? intval($params['page']) : '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
$page = '--FROM--';
|
||||
}
|
||||
|
||||
$url .= "id=".intval($params['id']).($page ? '.'.$page : '');
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_DEFAULT, // Current profile name
|
||||
'description' => LAN_EURL_LEGACY, //
|
||||
'examples' => array("{SITEURL}page.php?1","{SITEURL}page.php?id=1")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
public function parse($pathInfo, $params = array(), eRequest $request = null, eRouter $router = null, $config = array())
|
||||
{
|
||||
// this config doesn't support parsing, it's done by the module entry script (news.php)
|
||||
// this means News are not available via single entry point if this config is currently active
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -1,50 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* Search routing config
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_search_rewrite_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'legacy' => '{e_BASE}search.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script to be included
|
||||
'format' => 'path', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'defaultRoute' => 'index/index', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
|
||||
),
|
||||
|
||||
// rule set array
|
||||
'rules' => array(
|
||||
'/' => array('index/index', 'defaultVars' => array('id' => 0)),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_SEARCH, // Module name
|
||||
'label' => LAN_EURL_SEARCH_REWRITE_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_SEARCH_REWRITE_DESCR, //
|
||||
'examples' => array("{SITEURL}search/")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* Search routing config
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_search_rewrite_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'legacy' => '{e_BASE}search.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script to be included
|
||||
'format' => 'path', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'defaultRoute' => 'index/index', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
|
||||
),
|
||||
|
||||
// rule set array
|
||||
'rules' => array(
|
||||
'/' => array('index/index', 'defaultVars' => array('id' => 0)),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_SEARCH, // Module name
|
||||
'label' => LAN_EURL_SEARCH_REWRITE_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_SEARCH_REWRITE_DESCR, //
|
||||
'examples' => array("{SITEURL}search/")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
}
|
||||
|
@@ -1,67 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* Search routing config
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_search_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'noSingleEntry' => true, // [optional] default false; disallow this module to be shown via single entry point when this config is used
|
||||
'legacy' => '{e_BASE}search.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script
|
||||
'format' => 'get', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'selfParse' => true, // [optional] default false; use only this->parse() method, no core routine URL parsing
|
||||
'selfCreate' => true, // [optional] default false; use only this->create() method, no core routine URL creating
|
||||
'defaultRoute' => '', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
),
|
||||
|
||||
'rules' => array() // rule set array
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query mapping
|
||||
*/
|
||||
public function create($route, $params = array(), $options=array())
|
||||
{
|
||||
if(!$params) return 'search.php';
|
||||
|
||||
return 'search.php?'.eFront::instance()->getRouter()->createPathInfo($params, $options);
|
||||
}
|
||||
|
||||
/*
|
||||
public function parse($pathInfo)
|
||||
{
|
||||
// this config doesn't support parsing, it's done by the module entry script (search.php)
|
||||
// this means Search is not available via single entry point if this config is currently active
|
||||
return false;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 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_SEARCH, // Module name
|
||||
'label' => LAN_EURL_DEFAULT, // Current profile name
|
||||
'description' => LAN_EURL_LEGACY, //
|
||||
'examples' => array("{SITEURL}search.php")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* Search routing config
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_search_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'noSingleEntry' => true, // [optional] default false; disallow this module to be shown via single entry point when this config is used
|
||||
'legacy' => '{e_BASE}search.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script
|
||||
'format' => 'get', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'selfParse' => true, // [optional] default false; use only this->parse() method, no core routine URL parsing
|
||||
'selfCreate' => true, // [optional] default false; use only this->create() method, no core routine URL creating
|
||||
'defaultRoute' => '', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
),
|
||||
|
||||
'rules' => array() // rule set array
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query mapping
|
||||
*/
|
||||
public function create($route, $params = array(), $options=array())
|
||||
{
|
||||
if(!$params) return 'search.php';
|
||||
|
||||
return 'search.php?'.eFront::instance()->getRouter()->createPathInfo($params, $options);
|
||||
}
|
||||
|
||||
/*
|
||||
public function parse($pathInfo)
|
||||
{
|
||||
// this config doesn't support parsing, it's done by the module entry script (search.php)
|
||||
// this means Search is not available via single entry point if this config is currently active
|
||||
return false;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 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_SEARCH, // Module name
|
||||
'label' => LAN_EURL_DEFAULT, // Current profile name
|
||||
'description' => LAN_EURL_LEGACY, //
|
||||
'examples' => array("{SITEURL}search.php")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
}
|
||||
|
@@ -1,53 +1,53 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* System routing config
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_system_rewrite_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'allowMain' => true,
|
||||
'format' => 'path',
|
||||
'defaultRoute' => 'error/notfound',
|
||||
'errorRoute' => 'error/notfound',
|
||||
|
||||
),
|
||||
|
||||
// rule set array
|
||||
'rules' => array(
|
||||
'error404' => 'error/notfound',
|
||||
'hello' => 'error/hello-world',
|
||||
'<controller>/<action>' => '<controller>/<action>',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_SYSTEM, // Module name
|
||||
'label' => LAN_EURL_SYSTEM_REWRITE_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_SYSTEM_REWRITE_DESCR, //
|
||||
'examples' => array("{SITEURL}system/error/404")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* System routing config
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_system_rewrite_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'allowMain' => true,
|
||||
'format' => 'path',
|
||||
'defaultRoute' => 'error/notfound',
|
||||
'errorRoute' => 'error/notfound',
|
||||
|
||||
),
|
||||
|
||||
// rule set array
|
||||
'rules' => array(
|
||||
'error404' => 'error/notfound',
|
||||
'hello' => 'error/hello-world',
|
||||
'<controller>/<action>' => '<controller>/<action>',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_SYSTEM, // Module name
|
||||
'label' => LAN_EURL_SYSTEM_REWRITE_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_SYSTEM_REWRITE_DESCR, //
|
||||
'examples' => array("{SITEURL}system/error/404")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
}
|
||||
|
@@ -1,44 +1,44 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* System routing config
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_system_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'format' => 'get', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'defaultRoute' => 'error/notfound', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_SYSTEM, // Module name
|
||||
'label' => LAN_EURL_SYSTEM_DEFAULT_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_SYSTEM_DEFAULT_DESCR, //
|
||||
'examples' => array("{SITEURL}?route=system/error/notfound")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* System routing config
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_system_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'format' => 'get', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'defaultRoute' => 'error/notfound', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_SYSTEM, // Module name
|
||||
'label' => LAN_EURL_SYSTEM_DEFAULT_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_SYSTEM_DEFAULT_DESCR, //
|
||||
'examples' => array("{SITEURL}?route=system/error/notfound")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
}
|
||||
|
@@ -1,102 +1,102 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* User routing config
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_user_rewrite_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'noSingleEntry' => false, // [optional] default false; disallow this module to be shown via single entry point when this config is used
|
||||
'legacy' => '{e_BASE}user.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script to be included
|
||||
'format' => 'path', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'selfParse' => false, // [optional] default false; use only this->parse() method, no core routine URL parsing
|
||||
'selfCreate' => false, // [optional] default false; use only this->create() method, no core routine URL creating
|
||||
'defaultRoute' => 'myprofile/view', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
'errorRoute' => '', // [optional] default empty; route (no leading module) used when module is found but no inner route is matched, leave empty to force error 404 page
|
||||
'urlSuffix' => '', // [optional] default empty; string to append to the URL (e.g. .html)
|
||||
'mapVars' => array( // vars mapping (create URL)
|
||||
'user_id' => 'id',
|
||||
'user_name' => 'name',
|
||||
),
|
||||
'allowVars' => false, // allowed vars (create URL, used for legacyQuery parsing in parse routine as well), false means - disallow all vars beside those required by the rules
|
||||
'legacyQuery' => '' // default legacy query string template, null to disable, override possible by rule
|
||||
),
|
||||
|
||||
// rule set array
|
||||
'rules' => array(
|
||||
// simple matches first - PERFORMANCE
|
||||
'' => array('myprofile/view', 'defaultVars' => array('id' => 0)),
|
||||
'settings' => array('myprofile/edit', 'defaultVars' => array('id' => 0), 'legacy' => '{e_BASE}usersettings.php'),
|
||||
'list' => array('profile/list', 'allowVars' => array('page'), 'legacyQuery' => '{page}'),
|
||||
'login' => array('login/index', 'legacy' => '{e_BASE}login.php'),
|
||||
'register' => array('register/index', 'legacy' => '{e_BASE}signup.php'),
|
||||
|
||||
// Regex involved next
|
||||
//'<id:[\d]+>' => array('profile/view', 'legacyQuery' => 'id.{id}'),
|
||||
// 'edit/<id:[\d]+>' => array('profile/edit', 'legacy' => '{e_ADMIN}users.php', 'legacyQuery' => 'mode=main&action=edit&id={id}'),
|
||||
|
||||
// Named requests - important to be in the end in this order!
|
||||
// 'edit/<name:[\w\pL.\-\s]+>' => array('profile/edit','legacy' => '{e_ADMIN}users.php', 'legacyQuery' => 'mode=main&action=edit&id={id}', 'parseCallback' => 'idByName'),
|
||||
// Last one - close to catch all!
|
||||
'<name:[\w\pL.\-\s\|]+>' => array('profile/view', 'legacyQuery' => 'id.{id}', 'parseCallback' => 'idByName'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_USER, // Module name
|
||||
'label' => LAN_EURL_USER_REWRITE_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_USER_REWRITE_DESCR, //
|
||||
'examples' => array("{SITEURL}user/UserDisplayName")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
### CUSTOM METHODS ###
|
||||
|
||||
/**
|
||||
* profile/edit & profile/view callback
|
||||
* @param eRequest $request
|
||||
*/
|
||||
public function idByName(eRequest $request)
|
||||
{
|
||||
$name = $request->getRequestParam('name');
|
||||
if(!$name) return;
|
||||
|
||||
// if id only is passed, don't do DB query
|
||||
if(is_numeric($name))
|
||||
{
|
||||
$request->setRequestParam('id', $name)->setRequestParam('name', null);
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = e107::getDb('url');
|
||||
$name = e107::getParser()->toDB($name);
|
||||
|
||||
if($sql->select('user', 'user_id', "user_name='{$name}' OR REPLACE(user_name, ' ', '-') ='{$name}' " )) // XXX - new user_sef field? Discuss.
|
||||
{
|
||||
$name = $sql->fetch();
|
||||
$request->setRequestParam('id', $name['user_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* User routing config
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_user_rewrite_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'noSingleEntry' => false, // [optional] default false; disallow this module to be shown via single entry point when this config is used
|
||||
'legacy' => '{e_BASE}user.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script to be included
|
||||
'format' => 'path', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'selfParse' => false, // [optional] default false; use only this->parse() method, no core routine URL parsing
|
||||
'selfCreate' => false, // [optional] default false; use only this->create() method, no core routine URL creating
|
||||
'defaultRoute' => 'myprofile/view', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
'errorRoute' => '', // [optional] default empty; route (no leading module) used when module is found but no inner route is matched, leave empty to force error 404 page
|
||||
'urlSuffix' => '', // [optional] default empty; string to append to the URL (e.g. .html)
|
||||
'mapVars' => array( // vars mapping (create URL)
|
||||
'user_id' => 'id',
|
||||
'user_name' => 'name',
|
||||
),
|
||||
'allowVars' => false, // allowed vars (create URL, used for legacyQuery parsing in parse routine as well), false means - disallow all vars beside those required by the rules
|
||||
'legacyQuery' => '' // default legacy query string template, null to disable, override possible by rule
|
||||
),
|
||||
|
||||
// rule set array
|
||||
'rules' => array(
|
||||
// simple matches first - PERFORMANCE
|
||||
'' => array('myprofile/view', 'defaultVars' => array('id' => 0)),
|
||||
'settings' => array('myprofile/edit', 'defaultVars' => array('id' => 0), 'legacy' => '{e_BASE}usersettings.php'),
|
||||
'list' => array('profile/list', 'allowVars' => array('page'), 'legacyQuery' => '{page}'),
|
||||
'login' => array('login/index', 'legacy' => '{e_BASE}login.php'),
|
||||
'register' => array('register/index', 'legacy' => '{e_BASE}signup.php'),
|
||||
|
||||
// Regex involved next
|
||||
//'<id:[\d]+>' => array('profile/view', 'legacyQuery' => 'id.{id}'),
|
||||
// 'edit/<id:[\d]+>' => array('profile/edit', 'legacy' => '{e_ADMIN}users.php', 'legacyQuery' => 'mode=main&action=edit&id={id}'),
|
||||
|
||||
// Named requests - important to be in the end in this order!
|
||||
// 'edit/<name:[\w\pL.\-\s]+>' => array('profile/edit','legacy' => '{e_ADMIN}users.php', 'legacyQuery' => 'mode=main&action=edit&id={id}', 'parseCallback' => 'idByName'),
|
||||
// Last one - close to catch all!
|
||||
'<name:[\w\pL.\-\s\|]+>' => array('profile/view', 'legacyQuery' => 'id.{id}', 'parseCallback' => 'idByName'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_USER, // Module name
|
||||
'label' => LAN_EURL_USER_REWRITE_LABEL, // Current profile name
|
||||
'description' => LAN_EURL_USER_REWRITE_DESCR, //
|
||||
'examples' => array("{SITEURL}user/UserDisplayName")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
### CUSTOM METHODS ###
|
||||
|
||||
/**
|
||||
* profile/edit & profile/view callback
|
||||
* @param eRequest $request
|
||||
*/
|
||||
public function idByName(eRequest $request)
|
||||
{
|
||||
$name = $request->getRequestParam('name');
|
||||
if(!$name) return;
|
||||
|
||||
// if id only is passed, don't do DB query
|
||||
if(is_numeric($name))
|
||||
{
|
||||
$request->setRequestParam('id', $name)->setRequestParam('name', null);
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = e107::getDb('url');
|
||||
$name = e107::getParser()->toDB($name);
|
||||
|
||||
if($sql->select('user', 'user_id', "user_name='{$name}' OR REPLACE(user_name, ' ', '-') ='{$name}' " )) // XXX - new user_sef field? Discuss.
|
||||
{
|
||||
$name = $sql->fetch();
|
||||
$request->setRequestParam('id', $name['user_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,130 +1,130 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* User routing config
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_user_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'noSingleEntry' => true, // [optional] default false; disallow this module to be shown via single entry point when this config is used
|
||||
'legacy' => '{e_BASE}user.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script
|
||||
'format' => 'get', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'selfParse' => true, // [optional] default false; use only this->parse() method, no core routine URL parsing
|
||||
'selfCreate' => true, // [optional] default false; use only this->create() method, no core routine URL creating
|
||||
'defaultRoute' => '', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
'errorRoute' => '', // [optional] default empty; route (no leading module) used when module is found but no inner route is matched, leave empty to force error 404 page
|
||||
'urlSuffix' => '', // [optional] default empty; string to append to the URL (e.g. .html)
|
||||
'mapVars' => array(),
|
||||
'allowVars' => array(),
|
||||
),
|
||||
|
||||
'rules' => array() // rule set array
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query mapping in format route?params:
|
||||
* - profile/view?id=xxx -> user.php?id.xxx
|
||||
* - profile/list?page=xxx -> user.php?xxx
|
||||
* - myprofile/view -> user.php
|
||||
* - profile/edit?id=xxx -> usersettings.php?xxx
|
||||
* - myprofile/edit -> usersettings.php
|
||||
* - login/index (or just 'login') -> login.php
|
||||
* - register/index (or just 'register') -> signup.php
|
||||
*/
|
||||
public function create($route, $params = array(), $options = array())
|
||||
{
|
||||
// Some routes require no params
|
||||
//if(!$params) return 'user.php';
|
||||
|
||||
if(is_string($route)) $route = explode('/', $route, 2);
|
||||
if(!varset($route[1])) $route[1] = 'index';
|
||||
|
||||
## aliases as retrieved from the DB, map vars to proper values
|
||||
if(isset($params['user_name']) && !empty($params['user_name'])) $params['id'] = $params['user_name'];
|
||||
if(isset($params['user_id']) && !empty($params['user_id'])) $params['id'] = $params['user_id'];
|
||||
|
||||
$url = 'user.php';
|
||||
$page = vartrue($params['page']) ? intval($params['page']) : '0';
|
||||
|
||||
if($route[0] == 'profile')
|
||||
{
|
||||
// Params required for user view, list & edit
|
||||
if(!$params) return 'user.php';
|
||||
|
||||
switch ($route[1])
|
||||
{
|
||||
case '':
|
||||
case 'view':
|
||||
$url .= '?id.'.$params['id'];
|
||||
break;
|
||||
|
||||
case 'list':
|
||||
$url .= $page ? '?'.$page : '';
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
//$url = e_ADMIN_ABS."user.php?mode=main&action=edit&id=".$params['id'];// 'usersettings.php?'.$params['id'];
|
||||
$url = e_ADMIN."users.php?mode=main&action=edit&id=".$params['id'];// 'usersettings.php?'.$params['id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif($route[0] == 'myprofile')
|
||||
{
|
||||
switch ($route[1])
|
||||
{
|
||||
case '':
|
||||
case 'view':
|
||||
// user.php
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
$url = 'usersettings.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif($route[0] == 'login')
|
||||
{
|
||||
$url = 'login.php';
|
||||
}
|
||||
elseif($route[0] == 'register') $url = 'signup.php'; // XXX signup URL parameters
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_USER, // Module name
|
||||
'label' => LAN_EURL_DEFAULT, // Current profile name
|
||||
'description' => LAN_EURL_LEGACY, //
|
||||
'examples' => array("{SITEURL}user.php?id.1")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
public function parse($pathInfo, $params = array(), eRequest $request = NULL, eRouter $router = NULL, $config = array())
|
||||
{
|
||||
// this config doesn't support parsing, it's done by the module entry script (news.php)
|
||||
// this means News are not available via single entry point if this config is currently active
|
||||
return false;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||
* $Id$
|
||||
*
|
||||
* User routing config
|
||||
*/
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
class core_user_url extends eUrlConfig
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return array(
|
||||
|
||||
'config' => array(
|
||||
'noSingleEntry' => true, // [optional] default false; disallow this module to be shown via single entry point when this config is used
|
||||
'legacy' => '{e_BASE}user.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script
|
||||
'format' => 'get', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
|
||||
'selfParse' => true, // [optional] default false; use only this->parse() method, no core routine URL parsing
|
||||
'selfCreate' => true, // [optional] default false; use only this->create() method, no core routine URL creating
|
||||
'defaultRoute' => '', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
|
||||
'errorRoute' => '', // [optional] default empty; route (no leading module) used when module is found but no inner route is matched, leave empty to force error 404 page
|
||||
'urlSuffix' => '', // [optional] default empty; string to append to the URL (e.g. .html)
|
||||
'mapVars' => array(),
|
||||
'allowVars' => array(),
|
||||
),
|
||||
|
||||
'rules' => array() // rule set array
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query mapping in format route?params:
|
||||
* - profile/view?id=xxx -> user.php?id.xxx
|
||||
* - profile/list?page=xxx -> user.php?xxx
|
||||
* - myprofile/view -> user.php
|
||||
* - profile/edit?id=xxx -> usersettings.php?xxx
|
||||
* - myprofile/edit -> usersettings.php
|
||||
* - login/index (or just 'login') -> login.php
|
||||
* - register/index (or just 'register') -> signup.php
|
||||
*/
|
||||
public function create($route, $params = array(), $options = array())
|
||||
{
|
||||
// Some routes require no params
|
||||
//if(!$params) return 'user.php';
|
||||
|
||||
if(is_string($route)) $route = explode('/', $route, 2);
|
||||
if(!varset($route[1])) $route[1] = 'index';
|
||||
|
||||
## aliases as retrieved from the DB, map vars to proper values
|
||||
if(isset($params['user_name']) && !empty($params['user_name'])) $params['id'] = $params['user_name'];
|
||||
if(isset($params['user_id']) && !empty($params['user_id'])) $params['id'] = $params['user_id'];
|
||||
|
||||
$url = 'user.php';
|
||||
$page = vartrue($params['page']) ? intval($params['page']) : '0';
|
||||
|
||||
if($route[0] == 'profile')
|
||||
{
|
||||
// Params required for user view, list & edit
|
||||
if(!$params) return 'user.php';
|
||||
|
||||
switch ($route[1])
|
||||
{
|
||||
case '':
|
||||
case 'view':
|
||||
$url .= '?id.'.$params['id'];
|
||||
break;
|
||||
|
||||
case 'list':
|
||||
$url .= $page ? '?'.$page : '';
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
//$url = e_ADMIN_ABS."user.php?mode=main&action=edit&id=".$params['id'];// 'usersettings.php?'.$params['id'];
|
||||
$url = e_ADMIN."users.php?mode=main&action=edit&id=".$params['id'];// 'usersettings.php?'.$params['id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif($route[0] == 'myprofile')
|
||||
{
|
||||
switch ($route[1])
|
||||
{
|
||||
case '':
|
||||
case 'view':
|
||||
// user.php
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
$url = 'usersettings.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif($route[0] == 'login')
|
||||
{
|
||||
$url = 'login.php';
|
||||
}
|
||||
elseif($route[0] == 'register') $url = 'signup.php'; // XXX signup URL parameters
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_USER, // Module name
|
||||
'label' => LAN_EURL_DEFAULT, // Current profile name
|
||||
'description' => LAN_EURL_LEGACY, //
|
||||
'examples' => array("{SITEURL}user.php?id.1")
|
||||
),
|
||||
'form' => array(), // Under construction - additional configuration options
|
||||
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
|
||||
);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
public function parse($pathInfo, $params = array(), eRequest $request = NULL, eRouter $router = NULL, $config = array())
|
||||
{
|
||||
// this config doesn't support parsing, it's done by the module entry script (news.php)
|
||||
// this means News are not available via single entry point if this config is currently active
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user