<?php
	include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
	include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );

	class PluginEmailEncryption extends PluginBase
	{
		var $_pluginEnabled;

		function PluginEmailEncryption()
		{
			$this->PluginBase();

			$this->id = "emailencryption";
			$this->description = "Encryption Email for pLog";
			$this->author = "Minstrel Chiu";
			$this->locales = Array("en_UK" , "zh_TW");

			$this->init();
		}

		function init()
		{
			$this->registerAdminAction("emailEncryption", "AdminEmailEncryptionAction");
			$this->registerAdminAction("updateEmailEncryption", "AdminUpdateEmailEncryptionAction");

			$menu =& Menu::getMenu();

			if(!$menu->entryExists( "/menu/controlCenter/manageSecurityPlugins"))
				$this->addMenuEntry("/menu/controlCenter", "manageSecurityPlugins", "", "", true, false);

			$this->addMenuEntry("/menu/controlCenter/manageSecurityPlugins", "EmailEncryption", "?op=emailEncryption", "");
		}

		function register()
		{
			$blogSettings = $this->blogInfo->getSettings();

			$this->_pluginEnabled = $blogSettings->getValue("plugin_emailencryption_enabled");
		}

		function isEnabled()
		{
			return $this->_pluginEnabled;
		}

		function getEmailEncryptionTextLink($email, $text)
        {
			list($name,$site) = explode("@",$email);
			$site_element = explode(".","$site");
			$site_element_count = count($site_element)-1;
			$suffix = $site_element[$site_element_count];
			unset($site_element[$site_element_count]);
			$domain = implode(".", $site_element);

			$email_encryption = "this.href='mai' + 'lto:' + '".$name."' + '\u0040' + '".$domain."' + '.' + '".$suffix."'";

			$encryption = '<a href="" onclick="'.$email_encryption.'">'.$text.'</a>';
                        
            return $encryption;
        }

        function getEmailEncryptionImageLink($email, $image)
        {
			list($name,$site) = explode("@",$email);
			$site_element = explode(".","$site");
			$site_element_count = count($site_element)-1;
			$suffix = $site_element[$site_element_count];
			unset($site_element[$site_element_count]);
			$domain = implode(".", $site_element);

			$email_encryption = "this.href='mai' + 'lto:' + '".$name."' + '\u0040' + '".$domain."' + '.' + '".$suffix."'";

			$encryption = '<a href="" onclick="'.$email_encryption.'"><img src="'.$image.'" border=0></a>';
                       
            return $encryption;
        }
	}
?>