Your IP : 216.73.216.68


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

<?php
/**
 * @version     SVN: <svn_id>
 * @package     JMailAlerts
 * @subpackage  com_jmailalerts
 * @author      Techjoomla <extensions@techjoomla.com>
 * @copyright   Copyright (c) 2009-2017 TechJoomla. All rights reserved.
 * @license     GNU General Public License version 2 or later.
 */

// No direct access.
defined('_JEXEC') or die();

jimport('joomla.filesystem.file');

/**
 * Class for JMA integration plugin
 *
 * @package     JMailAlerts
 * @subpackage  Plg_Sys_Jma_Integration
 * @since       2.5
 */
class PlgSystemPlg_Sys_Jma_Integration extends JPlugin
{
	/**
	 * onPrepareEmailJmaIntegration trigger method
	 *
	 * @param   string  $message_body  Email body
	 * @param   string  $cssdata       Email css
	 * @param   mixed   $userid        User id
	 *
	 * @return  [type]                 [description]
	 */
	public function onPrepareEmailJmaIntegration($message_body, $cssdata, $userid = null)
	{
		require_once JPATH_SITE . '/plugins/system/plg_sys_jma_integration/plg_sys_jma_integration/emails.php';

		$jma_obj   = new jmailalertsModelEmailsJMAIntegration;
		$skip_tags = array('[SITENAME]','[CONTENT]','[SITELINK]','[TIMESTAMP]');

		// Get all tags  from the template with whitespace as it is
		$remember_tags = $jma_obj->get_original_tmpl_tags($message_body, $skip_tags);

		// Get all tags  from the template removing whitespace in a correct needed array format
		$tmpl_tags     = $jma_obj->get_tmpl_tags($message_body, $skip_tags);

		// $final_trigger_tags=$jma_obj->get_final_trigger_tags($tmpl_tags,$user_plug,$userdata->id);
		$final_trigger_tags = $jma_obj->get_final_trigger_tags($tmpl_tags, null, null);

		// $plugins_data = $jma_obj->getPlugins($userdata->id,$userdata->date,$final_trigger_tags,$emails_config["enb_latest"]);

		$ignore_user_params     = 1;
		$ignore_special_plugins = $this->params->get('ignore_special_plugins');
		$plugins_data           = $jma_obj->getPlugins($userid, null, $final_trigger_tags, null, $ignore_user_params, $ignore_special_plugins);

		// Rebuild array for tag replacement in the same order as the plugins were triggered
		$count = 0;
		$user_subscribed_array = array();

		if ($plugins_data)
		{
			foreach ($plugins_data as $pd)
			{
				$plugins_data_name[] = $pd[0];

				if (isset($pd[0]))
				{
					// Plug_trigger
					$user_subscribed_array[$count][0] = $pd[0];
				}

				if (isset($pd[3]))
				{
					// Tag_to_replace
					$user_subscribed_array[$count][1] = $pd[3];
				}

				$count++;
			}
		}

		$i = 0;

		foreach ($user_subscribed_array as $plug)
		{
			if (isset($plugins_data[$i]))
			{
				$message_body = str_replace($plug[1], $plugins_data[$i][1], $message_body);
				$cssdata     .= $plugins_data[$i][2];

				if (!($plugins_data[$i][1] == ''))
				{
					$no_mail = 1;
				}
			}

			$i++;
		}

		// Replace all tags that are not part of user preferences directly with ''
		// @TODO need to take care of when processing special plugins
		foreach ($remember_tags as $rt)
		{
			$message_body = str_replace($rt, '', $message_body);
		}

		$result                 = array();
		$result['message_body'] = $message_body;
		$result['cssdata']      = $cssdata;

		return $result;
	}
}