<?php
/**
* Add MooFAQ Button plugin
* @package MooFAQ
* @Copyright (C) 2007 - 2010 Ideal Custom Software Development, All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* @author Douglas Machado
**/

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

jimport('joomla.event.plugin');


class plgButtonAdd_ce_form extends JPlugin
{
    /**
     * Constructor
     *
     * For php4 compatability we must not use the __constructor as a constructor for plugins
     * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
     * This causes problems with cross-referencing necessary for the observer design pattern.
     *
     * @param       object $subject The object to observe
     * @param       array  $config  An array that holds the plugin configuration
     * @since 1.5
     */
    function plgButtonAdd_ce_form(& $subject, $config) 
    {
        parent::__construct($subject, $config);
    }

    /**
     * Add Attachment button
     *
     * @return a button
     */
    function onDisplay($name)
    {   
        // Avoid displaying the button for anything except content articles
        $app = JFactory::getApplication();
        $option	= JRequest::getVar('option');
        if ( $option != 'com_content' OR !$app->isAdmin() ) {
            return new JObject();
		}
 
        // Get the article ID
        $cid = JRequest::getVar( 'cid', array(0), '', 'array');
        $id = 0;
        if ( count($cid) > 0 ) {
            $id = intval($cid[0]);
            }
        if ( $id == 0) {
            $nid = JRequest::getVar( 'id', null);
            if ( !is_null($nid) ) {
                $id = intval($nid);
                }
            }

        // Create the button object
        $button = new JObject();
            
        // Load the language file from the backend
        $lang = & JFactory::getLanguage();
        $lang->load('com_contact_enhanced', JPATH_ADMINISTRATOR);
        
        // ??? Where is the tooltip coming from?
        // (Would like to use different tip for create article button)
 
        // set up the style sheet (to get the visual for the button working)
        $doc =& JFactory::getDocument();
        $button->set('options', "{handler: 'iframe', size: {x: 300, y: 200}}");
		$link = "index.php?option=com_contact_enhanced&task=add_ce_form&article_id=$id&tmpl=component&e_name=".$name;
		$doc->addStyleSheet( JURI::base() . 'components/com_contact_enhanced/assets/css/contact_enhanced.css');
        
        $button->set('modal', true);
        $button->set('class', 'modal');
        $button->set('text', JText::_('CE_PLUGIN_EDITOR_ADD_FORM'));
        $button->set('name', 'add_ce_form');
        $button->set('link', $link);
        $button->set('image', 'add_ce_form/add_ce_form.png');

        return $button;
    }
}
?>
