<?php

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.plugin.plugin');
require_once(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_kip'.DS.'helpers'.DS.'ipfilter.php');
require_once(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_kip'.DS.'classes'.DS.'config.php');

class plgSystemKip extends JPlugin 
{
	function plgSystemKip(& $subject, $config)
	{
		parent :: __construct($subject, $config);
		$this->loadLanguage('com_kip');
	}
	
	function onAfterInitialise()
	{
		$app =& JFactory::getApplication();
		$client_id = intval($app->isAdmin());
		if(KipHelperIpfilter::isIpBlocked($_SERVER['REMOTE_ADDR'], $client_id))
			KipHelperIpfilter::terminateApplication($client_id);
		$user = & JFactory::getUser();
		if($user->id && KipHelperIpfilter::isIpBlockedForUser($_SERVER['REMOTE_ADDR'], $user->id))
		{
			KipHelperIpfilter::logUserOut($userid, $client_id);
			
			$config = & KipConfig::getInstance();
			if($config->get('users.filtering_warning'))
				JError::raiseWarning(ERROR_BANNED_IP, JText::sprintf( 'IP blocked for user', $_SERVER['REMOTE_ADDR'] ));
		}
	}

	function onLoginFailure(){
		//print_r(func_get_args());
		//print_r(JError::getErrors());
		//exit;
	}

}