<?php
/**
 * Module Helper File
 *
 * @package     Cache Cleaner
 * @version     1.3.0
 *
 * @author      Peter van Westen <peter@nonumber.nl>
 * @link        http://www.nonumber.nl
 * @copyright   Copyright (C) 2010 NoNumber! All Rights Reserved
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

class modCacheCleaner
{
	function render( $params )
	{
		JHTML::_( 'behavior.modal' );

		$document =& JFactory::getDocument();
		$script = "
			var cachecleaner_root = '".JURI::base( true )."';
			var cachecleaner_msg = '".str_replace( "'", "\'", JText::_( 'Cleaning Cache' ) )."';
			var cachecleaner_msg_inactive = '".str_replace( "'", "\'", JText::_( 'System plugin not enabled' ) )."';
			var cachecleaner_msg_success = '".str_replace( "'", "\'", JText::_( 'Cache cleaned' ) )."';
			var cachecleaner_msg_failure = '".str_replace( "'", "\'", JText::_( 'Cache could not be cleaned' ) )."';";
		$document->addScriptDeclaration( $script );
		$document->addScript( JURI::base( true ).'/modules/mod_cachecleaner/cachecleaner/js/cachecleaner.js' );
		$document->addStyleSheet( JURI::base( true ).'/modules/mod_cachecleaner/cachecleaner/css/cachecleaner.css' );

		$text = JText::_( $params->get( 'icon_text', 'Clean Cache' ) );
		$title = $text;
		$class = '';
		if ( $params->get( 'display_link', 'both' ) == 'text' ) {
			$class = 'no_icon';
		} else if ( $params->get( 'display_link', 'both' ) == 'icon' ) {
			$text = '&nbsp;';
			$class = 'no_text';
		}
		if ( $params->get( 'display_tooltip', 1 ) ) {
			JHTML::_( 'behavior.tooltip' );
			$class .= ' hasTip';
			$title = JText::_( 'Cache Cleaner' ).'::'.JText::_( 'Clean your cache' );
		}

		echo '<a href="javascript://" onclick="cachecleaner_load();return false;" onfocus="this.blur();" class="'.trim( $class ).'" id="cachecleaner" title="'.$title.'"><span>'.$text.'</span></a>';
	}
}