<?php
/**
 * Mobile Joomla! Pro
 * http://www.mobilejoomla.com
 *
 * @version		1.2.13.pro
 * @license		GNU/GPL v2 - http://www.gnu.org/licenses/gpl-2.0.html
 * @copyright	(C) 2008-2015 Kuneri Ltd.
 * @date		February 2015
 */
defined('_JEXEC') or die('Restricted access');

jimport('joomla.plugin.plugin');

class plgMobileMJPro_Update extends JPlugin
{
	function __construct(&$subject, $config)
	{
		parent::__construct($subject, $config);
	}

	function onMJBeforeDispatch($task)
	{
		if($task!='update' || JRequest::getWord('state')!='download')
			return;

		jimport('joomla.installer.helper');
		_initStatus();
		$url = 'http://www.mobilejoomla.com/latest.php?app=mjpro&domain='.$_SERVER['HTTP_HOST'];
		$filename = JInstallerHelper::downloadPackage($url);
		if($filename)
		{
			$app = JFactory::getApplication();
			$option = JRequest::getString('option');
			$app->setUserState( "$option.updatefilename", $filename );
		}
		_sendStatus();
	}
}
