Your IP : 216.73.216.229


Current Path : /home/jeromecohp/www/plugins/system/plg_sys_eb_mailer/
Upload File :
Current File : /home/jeromecohp/www/plugins/system/plg_sys_eb_mailer/plg_sys_eb_mailer.php

<?php
/**
 * @package     EmailBeautifier
 * @subpackage  plg_sys_eb_mailer
 *
 * @author      Techjoomla <extensions@techjoomla.com>
 * @copyright   Copyright (C) 2009 - 2022 Techjoomla. All rights reserved.
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

// No direct access.
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;

jimport('joomla.filesystem.file');

$helper_file = JPATH_ADMINISTRATOR . '/components/com_emailbeautifier/helper.php';

if (File::exists($helper_file))
{
	require_once $helper_file;
}
else
{
	return;
}

/**
 * Loads EB mail library class
 *
 * @return  boolean
 *
 * @since   2.1.2
 */
function loadEBMailLib()
{
	// Check 1:: CHECK  IS THERE any template for  currently executing component then only go forword
	$db      = Factory::getDbo();
	$query   = $db->getQuery(true);
	$query->select('COUNT(*)');
	$query->from($db->qn('#__eb_templates'));
	$query->where($db->qn('#__eb_templates.published') . '=' . $db->quote('1'));
	$db->setQuery($query);
	$existtemplates = $db->loadResult();

	if (empty($existtemplates))
	{
		return;
	}

	$jinput  = Factory::getApplication()->input;
	$option  = $jinput->get('option', '', 'cmd');
	$ebdebug = $jinput->get('ebdebug', '', 'STRING');

	// If url contains ebdebug=techjoomla, return safely
	if ($ebdebug == 'techjoomla')
	{
		return false;
	}

	if (!class_exists('Folder'))
	{
		jimport('joomla.filesystem.folder');
	}

	$defines_file = JPATH_ADMINISTRATOR . '/components/com_emailbeautifier';

	// If EB not installed, return safely
	if (!Folder::exists($defines_file))
	{
		return false;
	}

	// Works for 2.5 and 3.0 not tested for 1.5
	$comparams = ComponentHelper::getParams('com_emailbeautifier');
	$bcc_list  = $comparams->get('bcc_list');
	$skiplist  = $comparams->get('skip_list');

	// Trim the whitespace from component names
	$skip_list = array_map('trim', explode("\n", $skiplist));

	// $skip_list=preg_split('/\r\n|\r|\n/', $emails_config['skip_list']);

	// @TODO trick: not sure if needed since version 1.0.1 - added for if skip list is empty
	if ((count($skip_list)) && !($skip_list[0]))
	{
		$skip_list[0] = 'com_techjoomla_example_skipper';
	}

	if (count($skip_list))
	{
		$option = $jinput->get('option', '', 'cmd');

		// If current components is not in skip list, then load modified EB libraries
		if (!(in_array($option, $skip_list, true)))
		{
			if (JVERSION >= '3.8.0')
			{
				$path = dirname(__FILE__) . '/mailer/Mail_3x.php';

				JLoader::register('Mail', $path);
				JLoader::load('Mail');
			}
			else
			{
				if ((version_compare(JVERSION, '2.5.0', '>=') == 1) && (version_compare(JVERSION, '3.0.0', '<') == 1))
				{
					$path = dirname(__FILE__) . '/mailer/mail_25.php';
				}
				elseif ((version_compare(JVERSION, '3.0.0', '>=') == 1) && (version_compare(JVERSION, '3.4.0', '<') == 1))
				{
					$path = dirname(__FILE__) . '/mailer/mail_30.php';
				}
				elseif ((version_compare(JVERSION, '3.4.0', '>=') == 1) && (version_compare(JVERSION, '3.10.0', '<') == 1))
				{
					$path = dirname(__FILE__) . '/mailer/mail_3.php';
				}
				elseif ((version_compare(JVERSION, '3.10.0', '>=') == 1) && (version_compare(JVERSION, '4.0.0', '<') == 1))
				{
					$path = dirname(__FILE__) . '/mailer/Mail_310x.php';
				}

				JLoader::register('Mail', $path);
				JLoader::load('Mail');
			}
		}
	}

	return true;
}

// Call above function
loadEBMailLib();

/**
 * Class for EmailBeautifier system plugin
 *
 * @package     EmailBeautifier
 * @subpackage  plg_sys_eb_mailer
 * @since       1.0
 */
class PlgSystemPlg_Sys_Eb_Mailer extends CMSPlugin
{
	/**
	 * Load the language file on instantiation.
	 *
	 * @var    boolean
	 * @since  2.1.0
	 */
	protected $autoloadLanguage = true;

	/**
	 * Constructor
	 *
	 * @param   string  &$subject  Name
	 * @param   array   $config    Array of config options
	 *
	 * @since   1.0
	 */
	public function __construct(& $subject, $config)
	{
		parent::__construct($subject, $config);

		$this->_plugin = PluginHelper::getPlugin('system', 'plg_sys_eb_mailer');
	}

	/**
	 *  Uses this sytem trigger to load modified mail libraries
	 *
	 * @return  boolean
	 *
	 * @since   1.0
	 */

	/*public function onAfterRoute()
	{
		loadEBMailLib();
	}*/
}