<?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; } }