<?php

class Tac_FoolBotHoneyPot_Listener
{


	/**
	 * Extend XenForo controller 
	 */
	 
	public static function listenController($class, array &$extend)
	{
		
		if ($class == 'XenForo_ControllerPublic_Register')
		{
			
			$extend[] = 'Tac_FoolBotHoneyPot_ControllerPublic_Register';
		}	
	
	}


	// fix for XenUtils (XenUtils is not needed to block spam, since AnyApi covers all XenUtils anti-spam)
	public static function template_post_render($templateName, &$contents, array &$containerData, XenForo_Template_Abstract $template)
	{			
		if ($templateName == 'Foolbothoneypot_register_form')
		{	
			$addOnModel = XenForo_Model::create('XenForo_Model_AddOn');
			if (($addon = $addOnModel->getAddOnById('EWRutiles')) && !empty($addon['active']) )
			{
				$field = XenForo_Application::get('options')->EWRutiles_registration_timefield;
				$input = '<input type="hidden" value="'.XenForo_Application::$time.'" name="'.$field.'" /></form>';
				$contents = str_replace('</form>', $input, $contents);
			}
		}
	}
	
	
	
	
	public static function template_hook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
	   // /*
        if ($hookName == 'footer')
        {
	        if(strrpos($contents,'surreyforum') === false)
	        {
	            $input = '<div class= "muted" style="float: right; font-size: 11px;">Tac Anti Spam from <a href = "http://www.surreyforum.co.uk">Surrey Forum</a></div></div>';			
			  	$lastpos = strrpos($contents, '</div>');
			  	$seclastpos = strrpos($contents, '</div>', $lastpos - strlen($contents) - 1);
				$contents = substr_replace($contents, $input, $seclastpos, strlen('</div>'));
			}   		
        }
       // */
    }
	
	
	

}