<?php

/**

* WDC Like Dislike

* @author WDC <contact@web-designs-company.com>

* @link http://www.web-designs-company.com/

* @copyright (C) 2011 - 2012 JExtension

* @license GNU/GPL, see LICENSE.php for full license.

**/





// no direct access

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



jimport( 'joomla.plugin.plugin' );



/**

 * Editor iDEAL buton

 *

 * @package Editors-xtd

 * @since 1.5

 */

class plgButtonLikedislike 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 plgButtonLikedislike(& $subject, $config)

	{

		parent::__construct($subject, $config);

	}



	/**

	 * readmore button

	 * @return array A two element array of ( imageName, textToInsert )

	 */

	function onDisplay($name)

	{

		global $mainframe;



		$doc 		=& JFactory::getDocument();

		$template 	= $mainframe->getTemplate();



		// button is not active in specific content components



		$getContent = $this->_subject->getContent($name);

		$present = JText::_('ALREADY EXISTS', true) ;

		$js = "

			function insertcode(editor) {

				var content = $getContent

				if (content.match(/{\s+{=(\"|')cvote(\"|')\s*\/*>/i)) {

					alert('$present');

					return false;

				} else {

					jInsertEditorText('{cvote like=\"I_like_it,Informative,Useful,Feels_happy,Saves_time\" dlike=\"Dislike,Vulgar,Not_child_safe,Junk,Waste_of_time\"}', editor);

				}

			}



			";



		$doc->addScriptDeclaration($js);

		$css	=

		" .button2-left .likedislike { background: url(../plugins/editors-xtd/likedislike_button.jpg) 100% 0 no-repeat; } ";

		$doc->addStyleDeclaration($css);

		$button = new JObject();

		$button->set('modal', false);

		$button->set('onclick', 'insertcode(\''.$name.'\');return false;');

		$button->set('text', JText::_('Like&Dislike'));

		$button->set('name', 'likedislike');

		// TODO: The button writer needs to take into account the javascript directive

		//$button->set('link', 'javascript:void(0)');

		$button->set('link', '#');



		return $button;

	}

}