router.php
2.59 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/* ======================================================
# Monthly Archive - Joomla! Component v4.3.3 (PRO version)
# -------------------------------------------------------
# For Joomla! 3.x
# Author: Yiannis Christodoulou (yiannis@web357.eu)
# Copyright (©) 2009-2018 Web357. All rights reserved.
# License: GNU/GPLv3, http://www.gnu.org/licenses/gpl-3.0.html
# Website: https://www.web357.eu/
# Demo: http://demo.web357.eu/?item=monthlyarchive
# Support: support@web357.eu
# Last modified: 09 Feb 2018, 13:55:18
========================================================= */
// No direct access
defined('_JEXEC') or die;
JLoader::registerPrefix('Monthlyarchive', JPATH_SITE . '/components/com_monthlyarchive/');
class MonthlyarchiveRouter extends JComponentRouterBase
{
public function build(&$query)
{
$segments = array();
$view = null;
if (isset($query['view']))
{
$segments[] = $query['view'];
$view = $query['view'];
unset($query['view']);
}
if (isset($query['year']))
{
$segments[] = $query['year'];
$view = $query['year'];
unset($query['year']);
}
if (isset($query['month']))
{
$segments[] = $query['month'];
$view = $query['month'];
unset($query['month']);
}
return $segments;
}
public function parse(&$segments)
{
$vars = array();
// View is always the first element of the array
//$vars['view'] = array_shift($segments);
$vars['view'] = 'archive';
while (!empty($segments))
{
$segment = array_pop($segments);
// If it's the YEAR, let's put on the request
if ((is_numeric($segment) && strlen($segment) == 4) || $segment == 'all')
{
$vars['year'] = $segment;
}
// If it's the MONTH, let's put on the request
if (is_numeric($segment) && strlen($segment) == 2)
{
$vars['month'] = $segment;
}
}
$year = (int) (isset($vars['year'])) ? $vars['year'] : '';
$month = (int) (isset($vars['month'])) ? $vars['month'] : '';
// if month exists
if ($month > 0 && $month <= 12 && (strlen($year) == 4 || $year == 'all'))
{
return $vars;
}
elseif ($month && (strlen($year) == 4 || $year == 'all'))
{
if ($month > 0 && $month <= 12)
{
return $vars;
}
else
{
JError::raiseError( 404, 'The month does not exists');
}
}
elseif (!$month && (strlen($year) == 4 || $year == 'all'))
{
return $vars;
}
elseif (strlen($month) == 2 && !empty($month) && $month > 0 && $month <= 12 && (strlen($year) == 4 || $year == 'all'))
{
return $vars;
}
else
{
return $vars;
//JError::raiseError( 404, 'The month/year does not exists');
}
return $vars;
}
}