/
router.php
75 lines (66 loc) · 1.16 KB
/
router.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* @package Joomla.Site
* @subpackage com_banners
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* @return array A named array
* @return array
*/
function BannersBuildRoute(&$query)
{
$segments = array();
if (isset($query['task']))
{
$segments[] = $query['task'];
unset($query['task']);
}
if (isset($query['id']))
{
$segments[] = $query['id'];
unset($query['id']);
}
return $segments;
}
/**
* @return array A named array
* @param array
*
* Formats:
*
* index.php?/banners/task/id/Itemid
*
* index.php?/banners/id/Itemid
*/
function BannersParseRoute($segments)
{
$vars = array();
// view is always the first element of the array
$count = count($segments);
if ($count)
{
$count--;
$segment = array_shift($segments);
if (is_numeric($segment))
{
$vars['id'] = $segment;
}
else
{
$vars['task'] = $segment;
}
}
if ($count)
{
$segment = array_shift($segments);
if (is_numeric($segment))
{
$vars['id'] = $segment;
}
}
return $vars;
}