<?php

/*
*
* @name AntiCopy 1.0
* @type Joomla 1.6 Plugin
* @author Galaa
* @website http://galaa.mn/
* @email contact@galaa.mn
* @copyright Copyright (C) 2011 Galaa. All rights reserved.
* @license http://www.gnu.org/licenses/gpl.html - GNU GENERAL PUBLIC LICENSE
*
* AntiCopy Plugin is free software: 
* you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
*/

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

jimport( 'joomla.plugin.plugin' );

class plgSystemAntiCopy extends JPlugin {

	function onAfterDispatch() {
		$uri = JRequest::getURI();
		if( strpos( 'J'. $uri, 'administrator/' ) ){
			return;
		}

		$message = trim( $this->params->get( 'message' ) );
		$show_message = trim( $this->params->get( 'show_message' ) );
		$disallow_r_click = trim( $this->params->get( 'disallow_r_click' ) );
		$disallow_copy = trim( $this->params->get( 'disallow_copy' ) );

		$comment = "";
		if( $show_message )
			$comment = "//";

		$r_click = " 
					function clickExplorer() {
						if( document.all ) {
							${comment}alert('$message');
						}
						return false;
					}

					function clickOther(e) {
						if( document.layers || ( document.getElementById && !document.all ) ) {
							if ( e.which == 2 || e.which == 3 ) {
								${comment}alert('$message');
								return false;
							}
						}
					}
					if( document.layers ) {
						document.captureEvents( Event.MOUSEDOWN );
						document.onmousedown=clickOther;
					}
					else {
						document.onmouseup = clickOther;
						document.oncontextmenu = clickExplorer;
					} ";
		$script = " window.addEvent('domready', function() { 
				   
	
				    document.body.oncopy = function() { 
							${comment}alert('$message'); 
					";
		if( $disallow_copy )
			$script .= " return false; } }) ";
		else
			$script .= " } }); ";

		$doc =& JFactory::getDocument();
		$user =& JFactory::getUser();
		if($user->guest) {
			if( $disallow_r_click )
				$doc->addScriptDeclaration( " /* <![CDATA[ */ $r_click  /* ]]> */ ");
			$doc->addScriptDeclaration( " /* <![CDATA[ */ $script  /* ]]> */ " );
			if( $disallow_copy ){
				$doc->addScript(JURI::root(true) ."/plugins/system/anticopy/js/disableselection.js");
			}
		}

	}
}

?>
