Route – class for work with semantic URL. It define in the file includes/route.php. The class object is created in the administrative and public parts and in modules available for treatment through a variable $this->diafan->_route
. The class is used in models of modules and handlers POST-requests.
Properties of class Route
– variables inherent in the link. List of all available variables set in the files adm/includes/init.php (for administrative part) and includes/init.php (for public part). It available through the array $this->diafan->rewrite_variable_names_all
.
Variables inherent in the link in public part of the site:
integer page – number of page for pagination.
Example:
// http://site.com/news/page2/
// second page of news list if disabled category
$this->diafan->_route->page = 2;
integer show – module item ID if disabled autogenerate semantic URLs.
Example:
// http://site.com/news/show2/
// page of news item ID=2
$this->diafan->_route->show = 2;
integer add – adding new item.
Example:
// http://site.com/ads/add1/
// page of ad adding
$this->diafan->_route->add = 1;
integer edit – item editing.
Example:
// http://site.com/ads/edit15/
// page of editing of ad ID=15
$this->diafan->_route->edit = 15;
integer param – feature value ID.
Example:
// http://site.com/shop/param3/
// page of red (ID=3) products
$this->diafan->_route->param = 3;
integer dpage – number of page additional pagination.
Example:
// http://site.com/shop/palatki/52d/dpage3/
// third page of a list of comments on the product page
$this->diafan->_route->dpage = 3;
integer cat – category ID.
Example:
// http://site.com/shop/cat5/
// page of products category ID=5
$this->diafan->_route->cat = 5;
integer brand – brand ID.
Example:
// http://site.com/shop/brand1/
// page of brand ID=1
$this->diafan->_route->brand = 1;
integer year – year.
Example:
// http://site.com/news/year2013/
// list of news for 2013 year
$this->diafan->_route->year = 2013;
integer month – month.
Example:
// http://site.com/ads/year2013/month11/
// list of news for november 2013 year
$this->diafan->_route->month = 11;
integer step – step.
Example:
// http://site.com/shop/cart/step2/
// step 2 during the ordering process in the shop
$this->diafan->_route->step = 2;
integer sort – sorting direction.
Example:
// http://site.com/shop/palatki/sort2/
// all items in this category sorted by price descending
$this->diafan->_route->sort = 2;
Variables inherent in the link in administrative part of the site:
integer page – number of page for pagination.
Example:
// http://site.com/admin/news/page2/
// second page of news list
$this->diafan->_route->page = 2;
integer addnew – additing of new item.
Example:
// http://site.com/admin/ab/category/addnew1/
// page of ads category additing
$this->diafan->_route->addnew = 1;
integer edit – item editing.
Example:
// http://site.com/admin/news/edit15/
// page of editing of news item ID=15
$this->diafan->_route->edit = 15;
integer site – site page ID.
Example:
// http://site.com/admin/shop/site3/
// list of products attached to site page ID=3
$this->diafan->_route->site = 3;
integer cat – category ID.
Example:
// http://site.com/admin/shop/cat5/
// list of products attached to category ID=5
$this->diafan->_route->cat = 5;
integer parent – parent ID.
Example:
// http://site.com/admin/site/parent4/
// pages list; revealed subpages for page ID=4
$this->diafan->_route->parent = 4;
integer error – error ID.
Example:
// http://site.com/admin/shop/error7/
// the page on which the error will be displayed:
// Attention! It does not set the GD library. Module operation is impossible. Call your provider during downtime!
$this->diafan->_route->error = 7;
integer success – success message.
Example:
// http://site.com/admin/shop/success1/
// page which will display a message:
// Changes saved!
$this->diafan->_route->success = 1;
var variable_names_site = array('cat', 'param', 'show', 'dpage', 'rpage', 'brand', 'year', 'month', 'day', 'step', 'sort', 'add', 'edit', 'page') – переменные, передаваемые в URL в пользовательской части.
var variable_names_admin = array ('edit', 'savenew', 'save', 'addnew', 'site', 'cat', 'parent', 'page', 'error', 'success') – переменные, передаваемые в URL в административной части.
void save (string $rewrite, string $text, integer $element_id, string $module_name, string $element_type, integer $site_id, [integer $cat_id = 0], [integer $parent_id = 0], [boolean $add_parents = false], [boolean $change_children = false]) – Сохраняет ЧПУ.
Example:
// generate and save semantic URL of Product ID=54 from the name, according to the settings
// at the beginning of the semantic URL will be added to the semantic URL of category ID=2
// or semantic URL of site page ID=3
$this->diafan->_route->save('', 'Backpack "Contour 50"', 54, 'shop', 'element', 3, 2, 0, true);
// save semantic URL of site page ID=5
// replace the first part of the semantic URL in nested pages
$this->diafan->_route->save('about', 'About company', 5, 'site', 'element', 5, 0, 0, true, true);
/* for example it was as follows page structure:
About company /company/
History /company/history/
Philosophy /company/philosophy/
Feedback /feedback/
function result:
About company /about/
History /about/history/
Philosophy /about/philosophy/
Feedback /feedback/
*/
void delete (integer|array $element_ids, string $module_name, [string $element_type = 'element']) – Удаляет ЧПУ одного или нескольких элементов.
string generate_rewrite (string $text) – Генерирует псевдоссылку.
Example:
$rewrite = $this->diafan->_route->generate_rewrite('Backpack "Contour 50"');
// return: backpack-contour-50, if the conversion method in the "Site settings" is set as "translit"
string link (integer $site_id, [integer $element_id = 0], [string $module_name = ''], [string $element_type = 'element'], [boolean $insert_route_end = true]) – Генерирует ссылку.
Example:
// get a link to the page of brand ID=1
// attached to the site page ID=3
$link = $this->diafan->_route->link(3, 1, "shop", "brand");
// get a link to the page ID=5
$link = $this->diafan->_route->link(5);
void prepare (integer $site_id, integer $element_id, string $module_name, [string $element_type = 'element']) – Подготавливает ЧПУ.
Example:
// in this example, it will send three SQL-queries to the database
// for getting semantic URLs of specified products
$ids = array(3, 5, 7);
foreach($ids as $id)
{
$link[$id] = $this->diafan->_route->link(3, $id, "shop");
}
Example:
// in this example, it will send one SQL-query to the database
// for getting semantic URLs of specified products
$ids = array(3, 5, 7);
foreach($ids as $id)
{
$this->diafan->_route->prepare(3, $id, 'shop');
}
foreach($ids as $id)
{
$link[$id] = $this->diafan->_route->link(3, $id, "shop");
}
string|boolean false module (string $module_name, [boolean $route_end = true]) – Получает ЧПУ страницы сайта по названию модуля.
Example:
// get a link to the cart page
$link = BASE_PATH_HREF.$this->diafan->_route->module("cart");
mixed id_module (string $module_name, [mixed $site_id = 0], [boolean $return_array = true]) – Определяет номер страницы, к которой прикреплен модуль, доступной текущему пользователю.
Example:
// determine the ID page of the site to which the module "Private Messages" is attached
$site_id = $this->diafan->_route->id_module("messages", 0, false);
// сhoose among the given values ID pages of sites, which is attached module "Online shop"
$site_ids = $this->diafan->_route->id_module("shop", array(3, 5, 6));
string current_link ([string|array $exclude = ''], [array $include = array()]) – Выдает URL текущей страницы с включенными или исключенными переменными.
Example:
// remove from the current page address variables 'page' and 'dpage' and add 'add1/'
$link = $this->diafan->_route->current_link(array("page", "dpage"), array("add" => 1));
// for example, for page http://site.com/shop/palatki/page3/dpage2/sort2/
// result http://site.com/shop/palatki/sort2/add1/
string current_admin_link ([string|array $exclude = '']) – Выдает URL текущей страницы административной части с включенными переменными.
Example:
// remove from the current page address variables 'page' and 'parent'
$link = $this->diafan->_route->current_admin_link(array("page", "parent"));
// for example, for page http://site.com/admin/site/parent15/page2/
// result http://site.com/admin/site/
array|boolean false search (string $rewrite, [boolean $arguments_in_url = false]) – Ищет псевдоссылку в базе данных.
Example:
print_r( $this->diafan->_route->search('shop'));
/* output:
Array
(
[module_name] => site
[element_id] => 3
[element_type] => element
[rewrite] => shop
) */
string replace_link_to_id (string $text) – Заменяет ссылки на идентификаторы.
Example:
// prepare text entered via the visual editor
// before being stored in the database
$text = $this->diafan->_route->replace_link_to_id($_POST["text"]);
string replace_id_to_link (string $text) – Заменяет идентификаторы ссылки на ЧПУ.
Example:
// transform text, obtained from the database before displaying
echo $this->diafan->_route->replace_id_to_link($text);