<?php
/**
* @version 1.0.0
* @package RSFiles! 1.0.0
* @copyright (C) 2009 www.rsjoomla.com
* @license GPL, http://www.gnu.org/licenses/gpl-2.0.html
*/

defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.event.plugin');


// check if RSFiles! is installed
if (!file_exists( JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_rsfiles'.DS.'rsfiles.php' )) return;

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

	function onDisplay($name)
	{		
		global $mainframe;
		if (!$mainframe->isAdmin()) return;
		JHTML::_('behavior.modal');
		
		$doc 		=& JFactory::getDocument();
		$js = "function rsf_placeholder(what,template)
			{
				var text = '{rsfiles path=\"'+what+'\" template=\"' + template + '\"}';
				jInsertEditorText(text, '$name');
				window.parent.document.getElementById('sbox-window').close();
				return false; 
			}
			";

		$doc->addScriptDeclaration($js);
		
		$button = new JObject();
		$button->set('modal', true);
		$button->set('options', '{handler: \'iframe\', size: {x: 750, y: 500}}');
		$button->set('text', 'RSFiles!');
		$button->set('name', 'blank');
		$button->set('link', 'index.php?option=com_rsfiles&task=showfiles&tmpl=component');
		
		return $button;
	}
}
?>