archive.php 3.57 KB
<?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
========================================================= */

defined('_JEXEC') or die;

class MonthlyArchiveControllerArchive extends JControllerLegacy
{
	public function &getModel($name = 'Archive', $prefix = 'StartupModel', $config = array())
	{
		$model = parent::getModel($name, $prefix, array('ignore_request' => true));

		return $model;
	}

	public function goToURL()
	{
		// config
		$config = JFactory::getConfig();
		$sef = $config->get('sef');

		// Get menu item
		$menu_item = JFactory::getApplication()->getMenu()->getItems( 'link', 'index.php?option=com_monthlyarchive', true );
		$default_menu_item_id = (!empty($menu_item)) ? $menu_item->id : '';
		
		// Get the variables from URL
		$get_orderby = JFactory::getApplication()->input->get('orderby', '', 'STRING');
		$get_category = JFactory::getApplication()->input->get('category', '', 'INT');
		$get_author = JFactory::getApplication()->input->get('author', '', 'INT');
		$get_year = JFactory::getApplication()->input->get('year', '', 'STRING');
		$get_month = JFactory::getApplication()->input->get('month', '', 'INT');
		$get_month = (is_numeric($get_month) && $get_month > 0) ? sprintf("%02d", $get_month) : $get_month;
		$get_menu_item_id = JFactory::getApplication()->input->get('Itemid', $default_menu_item_id, 'INT');
		
		// build menu item id with property
		$menu_item_id = '&Itemid='.$get_menu_item_id;
		
		$app = JFactory::getApplication();
		$input = $app->input;

        $app->setUserState('com_monthlyarchive.archive.limitstart', 0);
		$input->set('limitstart', 0);

        $app->setUserState('com_monthlyarchive.archive.filter.orderby', $get_orderby);
		$input->set('filter.orderby', $get_orderby);

		$app->setUserState('com_monthlyarchive.archive.filter.category', $get_category);
		$input->set('filter.category', $get_category);

		$app->setUserState('com_monthlyarchive.archive.filter.author', $get_author);
		$input->set('filter.author', $get_author);

		if ($get_year == 'all')
		{
			$redirect_link = ($sef) ? JRoute::_('index.php?option=com_monthlyarchive&year=all'.$menu_item_id) : 'index.php?option=com_monthlyarchive&view=archive&year=all'.$menu_item_id;
			$this->setRedirect($redirect_link);
		}
		elseif (!empty($get_month))
		{
			$input->set('filter.date', $get_year.'-'.$get_month);
			$redirect_link = ($sef) ? JRoute::_('index.php?option=com_monthlyarchive&year='.(int) $get_year.'&month='.$get_month.''.$menu_item_id) : 'index.php?option=com_monthlyarchive&view=archive&year='.(int) $get_year.'&month='.$get_month.''.$menu_item_id;
			$this->setRedirect($redirect_link);
		}
		elseif (!empty($get_year))
		{
			$input->set('filter.date', $get_year);
			$redirect_link = ($sef) ? JRoute::_('index.php?option=com_monthlyarchive&year='.(int) $get_year.''.$menu_item_id) : 'index.php?option=com_monthlyarchive&view=archive&year='.(int) $get_year.''.$menu_item_id;
			$this->setRedirect($redirect_link);
		}
		else
		{
			$redirect_link = ($sef) ? JRoute::_('index.php?option=com_monthlyarchive'.$menu_item_id) : 'index.php?option=com_monthlyarchive&view=archive'.$menu_item_id;
			$this->setRedirect($redirect_link);
		}
	}
}