Your IP : 216.73.216.248


Current Path : /home/digilove/www/41423/
Upload File :
Current File : /home/digilove/www/41423/acymailing.tar

contentplugin/contentplugin.php000064400000006425152345456710013062 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

class plgAcymailingContentplugin extends JPlugin
{

	function __construct(&$subject, $config){
		parent::__construct($subject, $config);

		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'contentplugin');
			$this->params = new acyParameter( $plugin->params );
		}

		$this->paramsContent = JComponentHelper::getParams('com_content');
		JPluginHelper::importPlugin('content');
		$this->dispatcherContent = JDispatcher::getInstance();

		$excludedHandlers = array('plgContentEmailCloak','pluginImageShow');
		$excludedNames = array('system' => array('SEOGenerator','SEOSimple'), 'content' => array('webeecomment','highslide','smartresizer','phocagallery'));
		$excludedType = array_keys($excludedNames);

		if(!ACYMAILING_J16){
			foreach ($this->dispatcherContent->_observers as $id => $observer){
				if (is_array($observer) AND in_array($observer['handler'],$excludedHandlers)){
					$this->dispatcherContent->_observers[$id]['event'] = '';
				}elseif(is_object($observer)){
					if(in_array($observer->_type,$excludedType) AND in_array($observer->_name,$excludedNames[$observer->_type])){
						$this->dispatcherContent->_observers[$id] = null;
					}
				}
			}
		}

		if(!class_exists('JSite')) include_once(ACYMAILING_ROOT.'includes'.DS.'application.php');

	}

	function acymailing_replacetags(&$email,$send = true){

		$art = new stdClass();
		$art->title = $email->subject;
		$art->introtext = $email->body;
		$art->fulltext = $email->body;
		$art->attribs = '';
		$art->state=1;
		$art->created_by=@$email->userid;
		$art->images = '';
		$art->id = 0;
		$art->section = 0;
		$art->catid = 0;

		$context = 'com_acymailing';


		try{
			if(!empty($email->body)){
				$art->text = $email->body;
				if(!ACYMAILING_J16){
					$resultsPlugin = $this->dispatcherContent->trigger('onPrepareContent', array (&$art, &$this->paramsContent, 0 ));
				}else{
					if($send) $art->text .= '{emailcloak=off}';
					$resultsPlugin = $this->dispatcherContent->trigger('onContentPrepare', array ($context,&$art, &$this->paramsContent, 0 ));
					if($send) $art->text = str_replace(array('{emailcloak=off}','{* emailcloak=off}'),'',$art->text);
				}
				$email->body = $art->text;
			}
			if(!empty($email->altbody)){
				$art->text = $email->altbody;
				if(!ACYMAILING_J16){
					$resultsPlugin = $this->dispatcherContent->trigger('onPrepareContent', array (&$art, &$this->paramsContent, 0 ));
				}else{
					if($send) $art->text .= '{emailcloak=off}';
					$resultsPlugin = $this->dispatcherContent->trigger('onContentPrepare', array ($context,&$art, &$this->paramsContent, 0 ));
					if($send) $art->text = str_replace(array('{emailcloak=off}','{* emailcloak=off}'),'',$art->text);
				}
				$email->altbody = $art->text;
			}
		}catch(Exception $e){
			acymailing_display(array('An error occured with the AcyMailing contentplugin plugin, you may want to disable it from the AcyMailing configuration page',$e->getMessage()),'error');
		}

	}
}//endclass
contentplugin/contentplugin.xml000064400000002577152345456710013077 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing : trigger Joomla Content plugins</name>
	<creationDate>November 2009</creationDate>
	<version>3.7.0</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin enables you to trigger the content plugin system on AcyMailing. The Joomla Content plugin system has not been developed to be triggered from the backend and so you may have some non compatible plugins, that's why this plugin is not enabled by default</description>
	<files>
		<filename plugin="contentplugin">contentplugin.php</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-contentplugin"/>
	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-contentplugin"/>
			</fieldset>
		</fields>
	</config>
</extension>
contentplugin/index.html000064400000000054152345456710011445 0ustar00<html><body bgcolor="#FFFFFF"></body></html>managetext/index.html000064400000000054152345456710010711 0ustar00<html><body bgcolor="#FFFFFF"></body></html>managetext/managetext.php000064400000033055152345456710011571 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
defined('_JEXEC') or die('Restricted access');

class plgAcymailingManagetext extends JPlugin{
	var $foundtags = array();

	function __construct(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'managetext');
			$this->params = new acyParameter($plugin->params);
		}
	}

	function acymailing_replacetags(&$email, $send = true){
		$this->_replaceConstant($email);
		$this->_replaceRandom($email);
	}

	function acymailing_replaceusertags(&$email, &$user, $send = true){
		$this->_removetext($email);
		$this->_addfooter($email);
		$this->_ifstatement($email, $user);
	}

	private function _replaceConstant(&$email){
		$acypluginsHelper = acymailing_get('helper.acyplugins');
		$tags = $acypluginsHelper->extractTags($email, '(?:const|trans|config)');
		if(empty($tags)) return;

		$jconfig = JFactory::getConfig();

		$tagsReplaced = array();
		foreach($tags as $i => $oneTag){
			$val = '';
			$arrayVal = array();
			foreach($oneTag as $valname => $oneValue){
				if($valname == 'id'){
					$val = trim(strip_tags($oneValue));
				}elseif($valname != 'default'){
					$arrayVal[] = '{'.$valname.'}';
				}
			}

			if(empty($val)) continue;
			$tagValues = explode(':', $i);
			$type = ltrim($tagValues[0], '{');
			if($type == 'const'){
				$tagsReplaced[$i] = defined($val) ? constant($val) : 'Constant not defined : '.$val;
			}elseif($type == 'config'){
				if($val == 'sitename'){
					$tagsReplaced[$i] = ACYMAILING_J30 ? $jconfig->get($val) : $jconfig->getValue('config.'.$val);
				}
			}else{
				static $done = false;
				if(!$done && strpos($val, 'COM_USERS') !== false){
					$done = true;
					$lang = JFactory::getLanguage();
					$lang->load('com_users', JPATH_SITE);
					$lang->load('com_users', JPATH_ADMINISTRATOR);
				}
				if(!empty($arrayVal)){
					$tagsReplaced[$i] = nl2br(vsprintf(JText::_($val), $arrayVal));
				}else{
					$tagsReplaced[$i] = JText::_($val);
				}
			}
		}

		$acypluginsHelper->replaceTags($email, $tagsReplaced, true);
	}

	private function _replaceRandom(&$email){
		$pluginHelper = acymailing_get('helper.acyplugins');
		$randTag = $pluginHelper->extractTags($email, "rand");
		if(empty($randTag)) return;
		foreach($randTag as $oneRandTag){
			$results[$oneRandTag->id] = explode(';', $oneRandTag->id);
			$randNumber = rand(0, count($results[$oneRandTag->id]) - 1);
			$results[$oneRandTag->id][count($results[$oneRandTag->id])] = $results[$oneRandTag->id][$randNumber];
		}

		$tags = array();
		foreach(array_keys($results) as $oneResult){
			$tags['{rand:'.$oneResult.'}'] = end($results[$oneResult]);
		}

		if(empty($tags)) return;
		$pluginHelper->replaceTags($email, $tags, true);
	}


	private function _ifstatement(&$email, $user, $loop = 1){
		if(isset($this->noIfStatementTags[$email->mailid])) return;

		$isAdmin = JFactory::getApplication()->isAdmin();

		if($loop > 3){
			if($isAdmin) acymailing_display('You cannot have more than 3 nested {if} tags.', 'warning');
			return;
		}

		$match = '#{if:(((?!{if).)*)}(((?!{if).)*){/if}#Uis';
		$variables = array('subject', 'body', 'altbody', 'From', 'FromName', 'ReplyTo');
		$found = false;
		foreach($variables as $var){
			if(empty($email->$var)) continue;
			if(is_array($email->$var)){
				foreach($email->$var as $i => &$arrayField){
					if(empty($arrayField) || !is_array($arrayField)) continue;
					foreach($arrayField as $key => &$oneval){
						$found = preg_match_all($match, $oneval, $results[$var.$i.'-'.$key]) || $found;
						if(empty($results[$var.$i.'-'.$key][0])) unset($results[$var.$i.'-'.$key]);
					}
				}
			}else{
				$found = preg_match_all($match, $email->$var, $results[$var]) || $found;
				if(empty($results[$var][0])) unset($results[$var]);
			}
		}

		if(!$found){
			if($loop == 1) $this->noIfStatementTags[$email->mailid] = true;
			return;
		}

		static $a = false;

		$tags = array();
		foreach($results as $var => $allresults){
			foreach($allresults[0] as $i => $oneTag){
				if(isset($tags[$oneTag])) continue;
				if(!preg_match('#^([^=!<>~]+)(=|!=|<|>|&gt;|&lt;|~|!~)([^=!<>~]+)$#i', $allresults[1][$i], $operators)){
					if($isAdmin) acymailing_display('Operation not found : '.$allresults[1][$i], 'error');
					$tags[$oneTag] = $allresults[3][$i];
					continue;
				};
				$field = trim($operators[1]);
				$prop = '';

				$operatorsParts = explode('.', $operators[1]);
				$operatorComp = 'acymailing';
				if(count($operatorsParts) == 2 && in_array($operatorsParts[0], array('acymailing', 'joomla', 'var'))){
					$operatorComp = $operatorsParts[0];
					$field = $operatorsParts[1];
				}

				if($operatorComp == 'joomla'){
					if(!empty($user->userid)){
						if($field == 'gid' && ACYMAILING_J16){
							$db = JFactory::getDBO();
							$db->setQuery('SELECT group_id FROM #__user_usergroup_map WHERE user_id = '.intval($user->userid));
							$prop = implode(';', acymailing_loadResultArray($db));
						}else{
							$db = JFactory::getDBO();
							$db->setQuery('SELECT * FROM #__users WHERE id = '.intval($user->userid));
							$juser = $db->loadObject();
							if(isset($juser->{$field})){
								$prop = strtolower($juser->{$field});
							}else{
								if($isAdmin && !$a) acymailing_display('User variable not set : '.$field.' in '.$allresults[1][$i], 'error');
								$a = true;
							}
						}
					}
				}elseif($operatorComp == 'var'){
					$prop = strtolower($field);
				}else{
					if(!isset($user->{$field})){
						if($isAdmin && !$a) acymailing_display('User variable not set : '.$field.' in '.$allresults[1][$i], 'error');
						$a = true;
					}else{
						$prop = strtolower($user->{$field});
					}
				}

				$tags[$oneTag] = '';
				$val = trim(strtolower($operators[3]));
				if($operators[2] == '=' && ($prop == $val || in_array($prop, explode(';', $val)) || in_array($val, explode(';', $prop)))){
					$tags[$oneTag] = $allresults[3][$i];
				}elseif($operators[2] == '!=' && $prop != $val){
					$tags[$oneTag] = $allresults[3][$i];
				}elseif(($operators[2] == '>' || $operators[2] == '&gt;') && $prop > $val){
					$tags[$oneTag] = $allresults[3][$i];
				}elseif(($operators[2] == '<' || $operators[2] == '&lt;') && $prop < $val){
					$tags[$oneTag] = $allresults[3][$i];
				}elseif($operators[2] == '~' && strpos($prop, $val) !== false){
					$tags[$oneTag] = $allresults[3][$i];
				}elseif($operators[2] == '!~' && strpos($prop, $val) === false){
					$tags[$oneTag] = $allresults[3][$i];
				}
			}
		}

		foreach($variables as &$var){
			if(empty($email->$var)) continue;
			if(is_array($email->$var)){
				foreach($email->$var as &$arrayField){
					if(empty($arrayField) || !is_array($arrayField)) continue;
					foreach($arrayField as &$oneval){
						$oneval = str_replace(array_keys($tags), $tags, $oneval);
					}
				}
			}else{
				$email->$var = str_replace(array_keys($tags), $tags, $email->$var);
			}
		}
		$this->_ifstatement($email, $user, $loop + 1);
	}

	private function _removetext(&$email){
		$removetext = $this->params->get('removetext', '{reg},{/reg},{pub},{/pub}');
		if(!empty($removetext)){
			$removeArray = explode(',', trim($removetext, ' ,'));
			if(!empty($email->body)) $email->body = str_replace($removeArray, '', $email->body);
			if(!empty($email->altbody)) $email->altbody = str_replace($removeArray, '', $email->altbody);
		}


		$removetags = $this->params->get('removetags', 'youtube');
		if(!empty($removetags)){
			$regex = array();
			$removeArray = explode(',', trim($removetags, ' ,'));
			foreach($removeArray as $oneTag){
				if(empty($oneTag)) continue;
				$regex[] = '#(?:{|%7B)'.preg_quote($oneTag, '#').'(?:}|%7D).*(?:{|%7B)/'.preg_quote($oneTag, '#').'(?:}|%7D)#Uis';
				$regex[] = '#(?:{|%7B)'.preg_quote($oneTag, '#').'[^}]*(?:}|%7D)#Uis';
			}

			if(!empty($email->body)) $email->body = preg_replace($regex, '', $email->body);
			if(!empty($email->altbody)) $email->altbody = preg_replace($regex, '', $email->altbody);
		}
	}

	private function _addfooter(&$email){
		$footer = $this->params->get('footer');
		if(!empty($footer)){
			if(strpos($email->body, '</body>')){
				$email->body = str_replace('</body>', '<br />'.$footer.'</body>', $email->body);
			}else{
				$email->body .= '<br />'.$footer;
			}

			if(!empty($email->altbody)){
				$email->altbody .= "\n".$footer;
			}
		}
	}

	function onAcyDisplayFilters(&$type, $context = "massactions"){
		$app = JFactory::getApplication();
		if($this->params->get('displayfilter_'.$context, true) == false || ($this->params->get('frontendaccess') == 'none' && !$app->isAdmin())) return;

		$type['limitrand'] = JText::sprintf('ACY_RAND_LIMIT', 'X');

		$return = '<div id="filter__num__limitrand">'.JText::sprintf('ACY_RAND_LIMIT', '<input type="text" style="width:60px" value="30" name="filter[__num__][limitrand][nbusers]" />').'</div>';

		return $return;
	}

	function onAcyDisplayFilter_limitrand($filter){
		return JText::sprintf('ACY_RAND_LIMIT', $filter['nbusers']);
	}


	function onAcyProcessFilter_limitrand(&$query, $filter, $num){
		$query->limit = intval($filter['nbusers']);
		$query->orderBy = 'RAND()';
	}

	function onAcyDisplayActions(&$type){
		$type['addqueue'] = JText::_('ADD_QUEUE');
		$type['removequeue'] = JText::_('REMOVE_QUEUE');

		$db = JFactory::getDBO();
		$db->setQuery("SELECT `mailid`,`subject`, `type` FROM `#__acymailing_mail` WHERE `type` NOT IN ('notification','autonews','joomlanotification') OR `alias` = 'confirmation' ORDER BY `type`,`senddate` DESC LIMIT 5000");
		$allEmails = $db->loadObjectList();

		$emailsToDisplay = array();
		$typeNews = '';
		foreach($allEmails as $oneMail){
			if($oneMail->type != $typeNews){
				if(!empty($typeNews)) $emailsToDisplay[] = JHTML::_('select.option', '</OPTGROUP>');
				$typeNews = $oneMail->type;
				if($oneMail->type == 'news'){
					$label = JText::_('NEWSLETTERS');
				}elseif($oneMail->type == 'followup'){
					$label = JText::_('FOLLOWUP');
				}elseif($oneMail->type == 'welcome'){
					$label = JText::_('MSG_WELCOME');
				}elseif($oneMail->type == 'unsub'){
					$label = JText::_('MSG_UNSUB');
				}else{
					$label = $oneMail->type;
				}
				$emailsToDisplay[] = JHTML::_('select.option', '<OPTGROUP>', $label);
			}
			$emailsToDisplay[] = JHTML::_('select.option', $oneMail->mailid, $oneMail->subject.' ['.$oneMail->mailid.']');
		}
		$emailsToDisplay[] = JHTML::_('select.option', '</OPTGROUP>');

		$addqueue = '<div id="action__num__addqueue">'.JHTML::_('select.genericlist', $emailsToDisplay, "action[__num__][addqueue][mailid]", 'class="inputbox" size="1"').'<br /><label for="addqueuesenddate__num__">'.JText::_('SEND_DATE').' </label> <input type="text" value="{time}" id="addqueuesenddate__num__" name="action[__num__][addqueue][senddate]" onclick="displayDatePicker(this,event)"/></div>';

		$allMessages = JHTML::_('select.option', 0, JText::_('ACY_ALL'));
		array_unshift($emailsToDisplay, $allMessages);
		$removequeue = '<div id="action__num__removequeue">'.JHTML::_('select.genericlist', $emailsToDisplay, "action[__num__][removequeue][mailid]", 'class="inputbox" size="1"').'</div>';
		return $addqueue.$removequeue;
	}

	function onAcyProcessAction_addqueue($cquery, $action, $num){
		$action['mailid'] = intval($action['mailid']);
		if(empty($action['mailid'])) return 'Mailid not valid';
		if(empty($action['senddate'])) return 'Send date not valid';

		$action['senddate'] = acymailing_replaceDate($action['senddate']);
		if(!is_numeric($action['senddate'])) $action['senddate'] = acymailing_getTime($action['senddate']);
		if(empty($action['senddate'])) return 'send date not valid';

		$query = 'INSERT IGNORE INTO `#__acymailing_queue` (`mailid`,`subid`,`senddate`,`priority`) '.$cquery->getQuery(array($action['mailid'], 'sub.`subid`', $action['senddate'], '2'));
		$db = JFactory::getDBO();
		$db->setQuery($query);
		$db->query();
		return JText::sprintf('ADDED_QUEUE', $db->getAffectedRows());
	}

	function onAcyProcessAction_removequeue($cquery, $action, $num){
		$action['mailid'] = intval($action['mailid']);
		if(!empty($action['mailid'])) $cquery->where['queueremove'] = 'queueremove.mailid = '.$action['mailid'];

		$query = 'DELETE queueremove.* FROM `#__acymailing_queue` as queueremove ';
		$query .= 'JOIN `#__acymailing_subscriber` as sub ON queueremove.subid = sub.subid ';
		if(!empty($cquery->join)) $query .= ' JOIN '.implode(' JOIN ', $cquery->join);
		if(!empty($cquery->leftjoin)) $query .= ' LEFT JOIN '.implode(' LEFT JOIN ', $cquery->leftjoin);
		if(!empty($cquery->where)) $query .= ' WHERE ('.implode(') AND (', $cquery->where).')';

		$db = JFactory::getDBO();
		$db->setQuery($query);
		$db->query();

		unset($cquery->where['queueremove']);

		return JText::sprintf('SUCC_DELETE_ELEMENTS', $db->getAffectedRows());
	}

	function onAcyProcessAction_displayUsers($cquery, $action, $num){

		$res = array();
		$res['countTotal'] = $cquery->count();

		if(empty($cquery->limit) || $cquery->limit > 50) $cquery->limit = 20;

		$query = $cquery->getQuery(array('sub.`subid`', 'sub.email', 'sub.name'));
		$db = JFactory::getDBO();
		$db->setQuery($query);
		$users = $db->loadObjectList();

		$res['users'] = $users;
		return $res;
	}

}//endclass
managetext/managetext.xml000064400000006517152345456710011605 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing Manage text</name>
	<creationDate>October 2010</creationDate>
	<version>1.0.0</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin enables you to remove some text from your Newsletter or add a signature at the end of all your Newsletters or add/remove an e-mail from the queue...</description>
	<files>
		<filename plugin="managetext">managetext.php</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-managetext"/>
		<param name="removetext" type="text" size="100" default="{reg},{/reg},{pub},{/pub}" label="Text to remove" description="Enter the different strings you want AcyMailing to remove and separate them with a comma. Example : {reg},{/reg},{pub},{/pub}" />
		<param name="removetags" type="text" size="100" default="youtube" label="Code to remove" description="AcyMailing will remove all tags specified in this option and its content, separate them with a comma" />

		<param name="footer" type="textarea" rows="5" cols="35" default="" label="Footer" description="Write the text you want to be added at the end of each e-mail" />
		<param name="@spacer" type="spacer" default="" label="" description="" />

		<param name="frontendaccess" type="list" default="all" label="Front-end Access for filter" description="You can restrict the access to the filter 'Randomly select X Users' on the Front-end">
			<option value="all">Always display this filter</option>
			<option value="none">Don't display this filter on the front-end</option>
		</param>
	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-managetext"/>
				<field name="removetext" type="text" size="100" default="{reg},{/reg},{pub},{/pub}" label="Text to remove" description="Enter the different strings you want AcyMailing to remove and separate them with a comma. Example : {reg},{/reg},{pub},{/pub}" />
				<field name="removetags" type="text" size="100" default="youtube" label="Code to remove" description="AcyMailing will remove all tags specified in this option and its content, separate them with a comma" />

				<field name="footer" type="textarea" rows="5" cols="35" default="" label="Footer" description="Write the text you want to be added at the end of each e-mail" filter="SAFEHTML" />
				<field name="@spacer" type="spacer" default="" label="" description="" />

				<field name="frontendaccess" type="list" default="all" label="Front-end Access for filter" description="You can restrict the access to the filter 'Randomly select X Users' on the Front-end">
					<option value="all">Always display this filter</option>
					<option value="none">Don't display this filter on the front-end</option>
				</field>
			</fieldset>
		</fields>
	</config>
</extension>
online/index.html000064400000000054152345456710010040 0ustar00<html><body bgcolor="#FFFFFF"></body></html>online/online.php000064400000013423152345456710010044 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

class plgAcymailingOnline extends JPlugin{
	function __construct(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'online');
			$this->params = new acyParameter($plugin->params);
		}
	}

	function acymailing_getPluginType(){

		$app = JFactory::getApplication();
		if($this->params->get('frontendaccess') == 'none' && !$app->isAdmin()) return;
		$onePlugin = new stdClass();
		$onePlugin->name = JText::_('WEBSITE_LINKS');
		$onePlugin->function = 'acymailingtagonline_show';
		$onePlugin->help = 'plugin-online';

		return $onePlugin;
	}

	function acymailingtagonline_show(){

		$others = array();
		$config = acymailing_config();
		$others['readonline'] = array('default' => JText::_('VIEW_ONLINE', true), 'desc' => JText::_('VIEW_ONLINE_LINK'));
		if($config->get('forward', true)){
			$others['forward'] = array('default' => JText::_('FORWARD_FRIEND', true), 'desc' => JText::_('FORWARD_FRIEND_LINK'));
		}

		?>
		<script language="javascript" type="text/javascript">
			<!--
			var selectedTag = '';
			function changeTag(tagName){
				selectedTag = tagName;
				defaultText = new Array();
				<?php
								$k = 0;
								foreach($others as $tagname => $tag){
									echo "document.getElementById('tr_$tagname').className = 'row$k';";
									echo "defaultText['$tagname'] = '".$tag['default']."';";
								}
								$k = 1-$k;
				?>
				document.getElementById('tr_' + tagName).className = 'selectedrow';
				document.adminForm.tagtext.value = defaultText[tagName];
				setOnlineTag();
			}

			function setOnlineTag(){
				if(!selectedTag) changeTag('readonline');
				otherinfo = '';
				for(var i = 0; i < document.adminForm.template.length; i++){
					if(document.adminForm.template[i].checked){
						otherinfo += '|template:' + document.adminForm.template[i].value;
					}
				}
				setTag('<a href=' + '"{' + selectedTag + otherinfo + '}{/' + selectedTag + '}" target="_blank" style="text-decoration:none;"><span class="acymailing_online">' + document.adminForm.tagtext.value + '</span></a>');
			}
			//-->
		</script>
		<?php
		echo JText::_('FIELD_TEXT').' : <input type="text" name="tagtext" size="100px" onchange="setOnlineTag();" /><br /><br />';
		$radios = array();
		$radios[] = JHTML::_('select.option', "standard", JText::_('IN_TEMPLATE'));
		$radios[] = JHTML::_('select.option', "notemplate", JText::_('WITHOUT_TEMPLATE'));
		echo JHTML::_('acyselect.radiolist', $radios, 'template', 'size="1" onclick="setOnlineTag();"', 'value', 'text', 'notemplate');
		echo '<div class="onelineblockoptions">
				<table class="acymailing_table" cellpadding="1">';
		$k = 0;
		foreach($others as $tagname => $tag){
			echo '<tr style="cursor:pointer" class="row'.$k.'" onclick="changeTag(\''.$tagname.'\');" id="tr_'.$tagname.'" ><td class="acytdcheckbox" ></td><td>'.$tag['desc'].'</td></tr>';
			$k = 1 - $k;
		}
		echo '</table></div>';
	}

	function acymailing_replaceusertags(&$email, &$user, $send = true){
		$match = '#(?:{|%7B)(readonline|forward)([^}]*)(?:}|%7D)(.*)(?:{|%7B)/(readonline|forward)(?:}|%7D)#Uis';
		$variables = array('body', 'altbody');
		$found = false;
		foreach($variables as $var){
			if(empty($email->$var)) continue;
			$found = preg_match_all($match, $email->$var, $results[$var]) || $found;
			if(empty($results[$var][0])) unset($results[$var]);
		}

		if(!$found) return;

		$config = acymailing_config();

		$tags = array();

		foreach($results as $var => $allresults){
			foreach($allresults[0] as $i => $oneTag){
				if(isset($tags[$oneTag])) continue;
				$arguments = explode('|', strip_tags(str_replace('%7C', '|', $allresults[2][$i])));
				$tag = new stdClass();
				$tag->type = $allresults[1][$i];
				$tag->template = ($tag->type == 'readonline') ? $this->params->get('viewtemplate', 'notemplate') : $this->params->get('forwardtemplate', 'notemplate');
				$tag->itemid = $config->get('itemid', 0);
				for($j = 0, $a = count($arguments); $j < $a; $j++){
					$args = explode(':', $arguments[$j]);
					$arg0 = trim($args[0]);
					if(empty($arg0)) continue;
					if(isset($args[1])){
						$tag->$arg0 = $args[1];
					}else{
						$tag->$arg0 = true;
					}
				}

				$addkey = (!empty($email->key) && $this->params->get('addkey', 'yes') == 'yes') ? '&key='.$email->key : '';
				$adduserkey = (!empty($user->key) && $this->params->get('adduserkey', 'yes') == 'yes') ? '&subid='.$user->subid.'-'.$user->key : '';
				$tmpl = ($tag->template == 'notemplate') ? '&tmpl=component' : '';
				$item = empty($tag->itemid) ? '' : '&Itemid='.$tag->itemid;
				$lang = empty($email->language) ? '' : '&lang='.$email->language;

				if($tag->type == 'readonline'){
					$link = acymailing_frontendLink('index.php?option=com_acymailing&ctrl=archive&task=view&mailid='.$email->mailid.$addkey.$adduserkey.$tmpl.$item.$lang);
				}elseif($tag->type == 'forward'){
					$link = acymailing_frontendLink('index.php?option=com_acymailing&ctrl=archive&task=forward&mailid='.$email->mailid.$addkey.$adduserkey.$tmpl.$item.$lang);
				}

				if(empty($allresults[3][$i])){
					$tags[$oneTag] = $link;
				}else $tags[$oneTag] = '<a style="text-decoration:none;" href="'.$link.'"><span class="acymailing_online">'.$allresults[3][$i].'</span></a>';
			}
		}

		$email->body = str_replace(array_keys($tags), $tags, $email->body);
		if(!empty($email->altbody)) $email->altbody = str_replace(array_keys($tags), $tags, $email->altbody);
	}
}//endclass
online/online.xml000064400000010450152345456710010052 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing Tag : Website links</name>
	<creationDate>September 2009</creationDate>
	<version>3.7.0</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin enables you to add links in your Newsletter such as "read in your browser" or "forward to a friend"</description>
	<files>
		<filename plugin="online">online.php</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-online"/>
		<param name="addkey" type="radio" default="yes" label="Add Newsletter key" description="Add the Newsletter key in the link so the online version will be always accessible from the link inserted in the Newsletter">
			<option value="yes">Yes</option>
			<option value="no">No</option>
		</param>
		<param name="adduserkey" type="radio" default="yes" label="Add User key" description="Add the user key in the link so the online version will contain the personal information as well">
			<option value="yes">Yes</option>
			<option value="no">No</option>
		</param>
		<param name="viewtemplate" type="radio" default="notemplate" label="Display the online version - DEPRECATED" description="This option is not useful any more, please use the option when inserting the tag instead">
			<option value="standard">Standard template</option>
			<option value="notemplate">No template</option>
		</param>
		<param name="forwardtemplate" type="radio" default="notemplate" label="Display the forward version - DEPRECATED" description="This option is not useful any more, please use the option when inserting the tag instead">
			<option value="standard">Standard template</option>
			<option value="notemplate">No template</option>
		</param>
		<param name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
			<option value="all">Always display this tag system</option>
			<option value="none">Don't display this tag system on the front-end</option>
		</param>
	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-online"/>
				<field name="addkey" type="radio" default="yes" label="Add Newsletter key" description="Add the Newsletter key in the link so the online version will be always accessible from the link inserted in the Newsletter">
					<option value="yes">Yes</option>
					<option value="no">No</option>
				</field>
				<field name="adduserkey" type="radio" default="yes" label="Add User key" description="Add the user key in the link so the online version will contain the personal information as well">
					<option value="yes">Yes</option>
					<option value="no">No</option>
				</field>
				<field name="viewtemplate" type="radio" default="notemplate" label="Display the online version - DEPRECATED" description="This option is not useful any more, please use the option when inserting the tag instead">
					<option value="standard">Standard template</option>
					<option value="notemplate">No template</option>
				</field>
				<field name="forwardtemplate" type="radio" default="notemplate" label="Display the forward version - DEPRECATED" description="This option is not useful any more, please use the option when inserting the tag instead">
					<option value="standard">Standard template</option>
					<option value="notemplate">No template</option>
				</field>
				<field name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
					<option value="all">Always display this tag system</option>
					<option value="none">Don't display this tag system on the front-end</option>
				</field>
			</fieldset>
		</fields>
	</config>
</extension>
share/index.html000064400000000054152345456710007656 0ustar00<html><body bgcolor="#FFFFFF"></body></html>share/share.php000064400000016710152345456710007502 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

class plgAcymailingShare extends JPlugin{
	var $pictresults = array();

	function __construct(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'share');
			$this->params = new acyParameter($plugin->params);
		}
	}

	function acymailing_getPluginType(){

		$app = JFactory::getApplication();
		if($this->params->get('frontendaccess') == 'none' && !$app->isAdmin()) return;
		$onePlugin = new stdClass();
		$onePlugin->name = JText::sprintf('SOCIAL_SHARE', '...');
		$onePlugin->function = 'acymailingtagshare_show';
		$onePlugin->help = 'plugin-share';

		return $onePlugin;
	}

	function _getPictures($folder){
		$allFolders = JFolder::folders($folder);
		foreach($allFolders as $oneFolder){
			$this->_getPictures($folder.DS.$oneFolder);
		}
		$allFiles = JFolder::files($folder, $this->regex);
		foreach($allFiles as $oneFile){
			$this->pictresults[substr($oneFile, 0, 4)][$oneFile.filesize($folder.DS.$oneFile)] = $folder.DS.$oneFile;
		}
	}

	function acymailingtagshare_show(){

		$networks = array();
		$networks['facebook'] = 'Facebook';
		$networks['linkedin'] = 'LinkedIn';
		$networks['twitter'] = 'Twitter';
		$networks['hyves'] = 'Hyves';
		$networks['google'] = 'Google+';
		$networks['print'] = JText::_('ACY_PRINT');

		$k = 0;
		jimport('joomla.filesystem.folder');
		$this->regex = '('.implode('|', array_keys($networks)).').*(png|gif|jpeg|jpg)';
		$this->_getPictures(ACYMAILING_MEDIA);

		echo '<br style="clear:both;">';
		foreach($networks as $name => $desc){
			$shortName = substr($name, 0, 4);
			if(empty($this->pictresults[$shortName])) continue;

			if($desc == JText::_('ACY_PRINT')){
				$legendTxt = $desc;
			}else{
				$legendTxt = JText::sprintf('SOCIAL_SHARE', $desc);
			}

			echo '<div class="onelineblockoptions">
					<span class="acyblocktitle">'.$legendTxt.'</span>';
			foreach($this->pictresults[$shortName] as $onePict){
				$imgPath = preg_replace('#^'.preg_quote(ACYMAILING_ROOT, '#').'#i', ACYMAILING_LIVE, $onePict);
				$imgPath = str_replace(DS, '/', $imgPath);

				if($desc == JText::_('ACY_PRINT')){
					$insertedtag = '<a target="_blank" href="{print:newsletter}" title="'.JText::_('ACY_PRINT').'" ><img src="'.$imgPath.'" alt="'.$desc.'" /></a>';
				}else $insertedtag = '<a target="_blank" href="{sharelink:'.$name.'}" title="'.JText::sprintf('SOCIAL_SHARE', $desc).'" ><img src="'.$imgPath.'" alt="'.$desc.'" /></a>';

				echo '<img style="max-width:200px;cursor:pointer;padding:5px;" onclick="setTag(\''.htmlentities($insertedtag).'\');insertTag();" src="'.$imgPath.'" />';
			}
			echo '</div>';
			$k = 1 - $k;
		}
	}


	function acymailing_replacetags(&$email, $send = true){
		$match = '#(?:{|%7B)(share|sharelink):(.*)(?:}|%7D)#Ui';
		$variables = array('body', 'altbody');
		$found = false;
		$results = array();
		foreach($variables as $var){
			if(empty($email->$var)) continue;
			$found = preg_match_all($match, $email->$var, $results[$var]) || $found;
			if(empty($results[$var][0])) unset($results[$var]);
		}

		if(!$found) return;

		$archiveLink = acymailing_frontendLink('index.php?option=com_acymailing&ctrl=archive&task=view&mailid='.$email->mailid, $this->params->get('template', 'component') == 'component' ? true : false);
		if(empty($email->published)){
			$archiveLink .= (strpos($archiveLink, '?') ? '&' : '?').'time='.time();
		}

		$tags = array();
		foreach($results as $var => $allresults){
			foreach($allresults[0] as $numres => $tagname){
				if(isset($tags[$tagname])) continue;
				$arguments = explode('|', $allresults[2][$numres]);
				$tag = new stdClass();
				$tag->network = $arguments[0];
				for($i = 1, $a = count($arguments); $i < $a; $i++){
					$args = explode(':', $arguments[$i]);
					if(isset($args[1])){
						$tag->{$args[0]} = $args[1];
					}else{
						$tag->{$args[0]} = true;
					}
				}

				$link = '';
				if($tag->network == 'facebook'){
					$link = 'http://www.facebook.com/sharer.php?u='.urlencode($archiveLink).'&t='.urlencode($email->subject);
					$tags[$tagname] = '<a target="_blank" href="'.$link.'" title="'.JText::sprintf('SOCIAL_SHARE', 'Facebook').'"><img alt="Facebook" src="'.ACYMAILING_LIVE.$this->params->get('picturefb', 'media/com_acymailing/images/facebookshare.png').'" /></a>';
				}elseif($tag->network == 'twitter'){
					$text = JText::sprintf('SHARE_TEXT', $archiveLink);
					$link = 'http://twitter.com/home?status='.urlencode($text);
					$tags[$tagname] = '<a target="_blank" href="'.$link.'" title="'.JText::sprintf('SOCIAL_SHARE', 'Twitter').'"><img alt="Twitter" src="'.ACYMAILING_LIVE.$this->params->get('picturetwitter', 'media/com_acymailing/images/twittershare.png').'" /></a>';
				}elseif($tag->network == 'linkedin'){
					$link = 'http://www.linkedin.com/shareArticle?mini=true&url='.urlencode($archiveLink).'&title='.urlencode($email->subject);
					$tags[$tagname] = '<a target="_blank" href="'.$link.'" title="'.JText::sprintf('SOCIAL_SHARE', 'LinkedIn').'"><img alt="LinkedIn" src="'.ACYMAILING_LIVE.$this->params->get('picturelinkedin', 'media/com_acymailing/images/linkedin.png').'" /></a>';
				}elseif($tag->network == 'hyves'){
					$link = 'http://www.hyves-share.nl/button/respect/?hc_hint=1&url='.urlencode($archiveLink).'&title='.urlencode($email->subject);
					$tags[$tagname] = '<a target="_blank" href="'.$link.'" title="'.JText::sprintf('SOCIAL_SHARE', 'Hyves').'"><img alt="Hyves" src="'.ACYMAILING_LIVE.$this->params->get('picturehyves', 'media/com_acymailing/images/hyvesshare.png').'" /></a>';
				}elseif($tag->network == 'google'){
					$link = 'https://plus.google.com/share?url='.urlencode($archiveLink);
					$tags[$tagname] = '<a target="_blank" href="'.$link.'" title="'.JText::sprintf('SOCIAL_SHARE', 'Google+').'"><img alt="Google+" src="'.ACYMAILING_LIVE.$this->params->get('picturegoogleplus', 'media/com_acymailing/images/google_plusshare.png').'" /></a>';
				}

				if($allresults[1][$numres] == 'sharelink'){
					$tags[$tagname] = $link;
				}

				if(file_exists(ACYMAILING_MEDIA.'plugins'.DS.'share.php')){
					ob_start();
					require(ACYMAILING_MEDIA.'plugins'.DS.'share.php');
					$tags[$tagname] = ob_get_clean();
				}
			}
		}

		$email->body = str_replace(array_keys($tags), $tags, $email->body);
		$email->altbody = str_replace(array_keys($tags), '', $email->altbody);
	}

	function acymailing_replaceusertags(&$email, &$user, $send = true){
		$variables = array('subject', 'body', 'altbody');
		$acypluginsHelper = acymailing_get('helper.acyplugins');
		$tags = $acypluginsHelper->extractTags($email, 'print');

		$archiveLink = acymailing_frontendLink('index.php?option=com_acymailing&ctrl=archive&task=view&mailid='.$email->mailid, $this->params->get('template', 'component') == 'component' ? true : false);
		$addkey = (!empty($email->key)) ? '&key='.$email->key : '';
		$adduserkey = (!empty($user->key)) ? '&subid='.$user->subid.'-'.$user->key : '';
		$link = $archiveLink.'&print=1'.$addkey.$adduserkey;

		foreach($variables as $var){
			if(empty($email->$var)) continue;
			$email->$var = str_replace(array_keys($tags), $link, $email->$var);
		}
	}
}//endclass
share/share.xml000064400000007724152345456710007520 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing : share on social networks</name>
	<creationDate>August 2010</creationDate>
	<version>1.0.0</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin enables you to add a share icon for social networks</description>
	<files>
		<filename plugin="share">share.php</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-share"/>
		<param name="template" type="radio" default="component" label="Display the online version" description="Select if you want to display the online version (when the user will share your link on the social network) without any Joomla module (no template) or inside your default Joomla Template">
			<option value="standard">Standard template</option>
			<option value="component">No template</option>
		</param>

		<param name="picturefb" type="text" label="Facebook picture - DEPRECATED" default="media/com_acymailing/images/facebookshare.png" />
		<param name="picturetwitter" type="text" label="Twitter picture - DEPRECATED" default="media/com_acymailing/images/twittershare.png" />
		<param name="picturelinkedin" type="text" label="LinkedIn picture - DEPRECATED" default="media/com_acymailing/images/linkedin.png" />
		<param name="picturehyves" type="text" label="Hyves picture - DEPRECATED" default="media/com_acymailing/images/hyvesshare.png" />
		<param name="picturegoogleplus" type="text" label="Google+ picture - DEPRECATED" default="media/com_acymailing/images/google_plusshare.png" />
		<param name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
			<option value="all">Always display this tag system</option>
			<option value="none">Don't display this tag system on the front-end</option>
		</param>

	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-share"/>
				<field name="template" type="radio" default="component" label="Display the online version" description="Select if you want to display the online version (when the user will share your link on the social network) without any Joomla module (no template) or inside your default Joomla Template">
					<option value="standard">Standard template</option>
					<option value="component">No template</option>
				</field>

				<field name="picturefb" type="text" label="Facebook picture - DEPRECATED" default="media/com_acymailing/images/facebookshare.png" />
				<field name="picturetwitter" type="text" label="Twitter picture - DEPRECATED" default="media/com_acymailing/images/twittershare.png" />
				<field name="picturelinkedin" type="text" label="LinkedIn picture - DEPRECATED" default="media/com_acymailing/images/linkedin.png" />
				<field name="picturehyves" type="text" label="Hyves picture - DEPRECATED" default="media/com_acymailing/images/hyvesshare.png" />
				<field name="picturegoogleplus" type="text" label="Google+ picture - DEPRECATED" default="media/com_acymailing/images/google_plusshare.png" />
				<field name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
					<option value="all">Always display this tag system</option>
					<option value="none">Don't display this tag system on the front-end</option>
				</field>

			</fieldset>
		</fields>
	</config>
</extension>
stats/index.html000064400000000054152345456710007712 0ustar00<html><body bgcolor="#FFFFFF"></body></html>stats/stats.php000064400000012270152345456710007567 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

class plgAcymailingStats extends JPlugin{
	function __construct(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'stats');
			$this->params = new acyParameter($plugin->params);
		}
	}

	function acymailing_replaceusertags(&$email, &$user, $send = true){
		if(!empty($email->altbody)){
			$email->altbody = str_replace(array('{statpicture}', '{nostatpicture}'), '', $email->altbody);
		}

		if(!$email->sendHTML OR empty($email->type) OR !in_array($email->type, array('news', 'autonews', 'followup', 'welcome', 'unsub', 'joomlanotification', 'action')) OR strpos($email->body, '{nostatpicture}')){
			$email->body = str_replace(array('{statpicture}', '{nostatpicture}'), '', $email->body);
			return;
		}

		if(empty($user->subid) || !$send){
			$pictureLink = ACYMAILING_LIVE.$this->params->get('picture', 'media/com_acymailing/images/statpicture.png');
		}else{
			$config = acymailing_config();
			$itemId = $config->get('itemid', 0);
			$item = empty($itemId) ? '' : '&Itemid='.$itemId;
			$pictureLink = acymailing_frontendLink('index.php?option=com_acymailing&ctrl=stats&mailid='.$email->mailid.'&subid='.$user->subid.$item);
		}

		$widthsize = $this->params->get('width', 50);
		$heightsize = $this->params->get('height', 1);
		$width = empty($widthsize) ? '' : ' width="'.$widthsize.'" ';
		$height = empty($heightsize) ? '' : ' height="'.$heightsize.'" ';

		$statPicture = '<img class="spict" alt="'.$this->params->get('alttext', '').'" src="'.$pictureLink.'"  border="0" '.$height.$width.'/>';

		if(strpos($email->body, '{statpicture}')){
			$email->body = str_replace('{statpicture}', $statPicture, $email->body);
		}elseif(strpos($email->body, '</body>')) $email->body = str_replace('</body>', $statPicture.'</body>', $email->body);
		else $email->body .= $statPicture;
	}//endfct

	function acymailing_getstatpicture(){
		return $this->params->get('picture', 'media/com_acymailing/images/statpicture.png');
	}

	function onAcyDisplayTriggers(&$triggers){
		$triggers['opennews'] = JText::_('ON_OPEN_NEWS');
	}

	function onAcyDisplayFilters(&$type, $context = "massactions"){

		if($context != "massactions" AND !$this->params->get('displayfilter_'.$context, false)) return;

		$type['deliverstat'] = JText::_('STATISTICS');

		$db = JFactory::getDBO();
		$db->setQuery("SELECT `mailid`,CONCAT(`subject`,' [',".$db->Quote(JText::_('ACY_ID').' ').", CAST(`mailid` AS char),']') as 'value' FROM `#__acymailing_mail` WHERE `type` IN('news','welcome','unsub','followup','notification','joomlanotification') ORDER BY `senddate` DESC LIMIT 5000");
		$allemails = $db->loadObjectList();
		$element = new stdClass();
		$element->mailid = 0;
		$element->value = JText::_('EMAIL_NAME');
		array_unshift($allemails, $element);

		$actions = array();
		$actions[] = JHTML::_('select.option', 'open', JText::_('OPEN'));
		$actions[] = JHTML::_('select.option', 'notopen', JText::_('NOT_OPEN'));
		$actions[] = JHTML::_('select.option', 'failed', JText::_('FAILED'));
		if(acymailing_level(3)) $actions[] = JHTML::_('select.option', 'bounce', JText::_('BOUNCES'));
		$actions[] = JHTML::_('select.option', 'htmlsent', JText::_('SENT_HTML'));
		$actions[] = JHTML::_('select.option', 'textsent', JText::_('SENT_TEXT'));
		$actions[] = JHTML::_('select.option', 'notsent', JText::_('NOT_SENT'));

		$return = '<div id="filter__num__deliverstat">'.JHTML::_('select.genericlist', $actions, "filter[__num__][deliverstat][action]", 'class="inputbox" onchange="countresults(__num__)" size="1"', 'value', 'text');
		$return .= ' '.JHTML::_('select.genericlist', $allemails, "filter[__num__][deliverstat][mailid]", 'onchange="countresults(__num__)" class="inputbox" size="1" style="max-width:200px"', 'mailid', 'value').'</div>';

		return $return;
	}

	function onAcyProcessFilterCount_deliverstat(&$query, $filter, $num){
		$this->onAcyProcessFilter_deliverstat($query, $filter, $num);
		return JText::sprintf('SELECTED_USERS', $query->count());
	}

	function onAcyProcessFilter_deliverstat(&$query, $filter, $num){
		$alias = 'stats'.$num;
		$jl = '#__acymailing_userstats AS '.$alias.' ON '.$alias.'.subid = sub.subid';
		if(!empty($filter['mailid'])) $jl .= ' AND '.$alias.'.mailid = '.intval($filter['mailid']);

		$query->leftjoin[$alias] = $jl;

		if($filter['action'] == 'open'){
			$where = $alias.'.open > 0';
		}elseif($filter['action'] == 'notopen'){
			$where = $alias.'.open = 0';
		}elseif($filter['action'] == 'failed'){
			$where = $alias.'.fail = 1';
		}elseif($filter['action'] == 'bounce'){
			$where = $alias.'.bounce = 1';
		}elseif($filter['action'] == 'htmlsent'){
			$where = $alias.'.html = 1';
		}elseif($filter['action'] == 'textsent'){
			$where = $alias.'.html = 0';
		}elseif($filter['action'] == 'notsent'){
			$where = $alias.'.subid IS NULL';
		}

		$query->where[] = $where;
	}
}//endclass
stats/stats.xml000064400000006350152345456710007602 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing : Statistics Plugin</name>
	<creationDate>September 2009</creationDate>
	<version>3.7.0</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin is used to handle statistics on any AcyMailing e-mail</description>
	<files>
		<filename plugin="stats">stats.php</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-stats"/>
		<param name="picture" type="text" size="60" label="Stat picture" default="media/com_acymailing/images/statpicture.png" description="Path of the statistic picture"/>
		<param name="alttext" type="text" size="60" default="" label="Alt Text" description="Alternatif text which will be displayed if the user does not accept to load your images" />
		<param name="width" type="text" size="2" default="50" label="Stat picture width" description="An image will be added in your HTML e-mails to be able to handle statistics. You can modify the width of the stat picture." />
		<param name="height" type="text" size="2" default="1" label="Stat picture height" description="An image will be added in your HTML e-mails to be able to handle statistics. You can modify the height of the stat picture." />
		<param name="displayfilter_mail" type="radio" default="0" label="Display filter" description="Display the statistics filter on the Newsletter creation interface">
			<option value="0">JOOMEXT_NO</option>
			<option value="1">JOOMEXT_YES</option>
		</param>
	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-stats"/>
				<field name="picture" type="text" size="60" label="Stat picture" default="media/com_acymailing/images/statpicture.png" description="Path of the statistic picture"/>
				<field name="alttext" type="text" size="60" default="" label="Alt Text" description="Alternatif text which will be displayed if the user does not accept to load your images" />
				<field name="width" type="text" size="2" default="50" label="Stat picture width" description="An image will be added in your HTML e-mails to be able to handle statistics. You can modify the width of the stat picture." />
				<field name="height" type="text" size="2" default="1" label="Stat picture height" description="An image will be added in your HTML e-mails to be able to handle statistics. You can modify the height of the stat picture." />
				<field name="displayfilter_mail" type="radio" default="0" label="Display filter" description="Display the statistics filter on the Newsletter creation interface">
					<option value="0">JOOMEXT_NO</option>
					<option value="1">JOOMEXT_YES</option>
				</field>
			</fieldset>
		</fields>
	</config>
</extension>
tablecontents/index.html000064400000000054152345456710011421 0ustar00<html><body bgcolor="#FFFFFF"></body></html>tablecontents/tablecontents.php000064400000021407152345456710013007 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
defined('_JEXEC') or die('Restricted access');

class plgAcymailingTablecontents extends JPlugin{

	var $noResult = array();

	function __construct(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'tablecontents');
			$this->params = new acyParameter($plugin->params);
		}
	}

	function acymailing_getPluginType(){
		$onePlugin = new stdClass();
		$onePlugin->name = JText::_('ACY_TABLECONTENTS');
		$onePlugin->function = 'acymailingtablecontents_show';
		$onePlugin->help = 'plugin-tablecontents';

		return $onePlugin;
	}

	function acymailingtablecontents_show(){

		$contenttype = array();
		$contenttype[] = JHTML::_('select.option', '', JText::_('ACY_EXISTINGANCHOR'));
		for($i = 1; $i < 6; $i++){
			$contenttype[] = JHTML::_('select.option', "|type:h".$i, 'H'.$i);
		}
		$contenttype[] = JHTML::_('select.option', 'class', JText::_('CLASS_NAME'));

		$contentsubtype = array();
		$contentsubtype[] = JHTML::_('select.option', '', JText::_('ACY_NONE'));
		for($i = 1; $i < 6; $i++){
			$contentsubtype[] = JHTML::_('select.option', "|subtype:h".$i, 'H'.$i);
		}
		$contentsubtype[] = JHTML::_('select.option', 'class', JText::_('CLASS_NAME'));

		?>

		<script language="javascript" type="text/javascript">
			<!--
			function updateTag(){
				var tag = '{tableofcontents';
				if(document.adminForm.contenttype.value){
					if(document.adminForm.contenttype.value == 'class'){
						document.adminForm.classvalue.style.display = '';
						tag += '|class:' + document.adminForm.classvalue.value;
					}else{
						document.adminForm.classvalue.style.display = 'none';
						tag += document.adminForm.contenttype.value;
					}
				}
				if(document.adminForm.contentsubtype.value){
					if(document.adminForm.contentsubtype.value == 'class'){
						document.adminForm.subclassvalue.style.display = '';
						tag += '|subclass:' + document.adminForm.subclassvalue.value;
					}else{
						document.adminForm.subclassvalue.style.display = 'none';
						tag += document.adminForm.contentsubtype.value;
					}
				}
				tag += '}';

				setTag(tag);
			}
			//-->
		</script>
		<div class="onelineblockoptions">
			<span class="acyblocktitle"><?php echo JText::_('ACY_GENERATEANCHOR'); ?></span>
			<table width="100%" class="acymailing_table">
				<tr>
					<td><?php echo JText::sprintf('ACY_LEVEL', 1)?></td>
					<td><?php echo JHTML::_('select.genericlist', $contenttype, 'contenttype', 'size="1" onchange="updateTag();"', 'value', 'text'); ?><input type="text" style="display:none" onchange="updateTag();" name="classvalue"/></td>
				</tr>
				<tr>
					<td><?php echo JText::sprintf('ACY_LEVEL', 2)?></td>
					<td><?php echo JHTML::_('select.genericlist', $contentsubtype, 'contentsubtype', 'size="1" onchange="updateTag();"', 'value', 'text'); ?><input type="text" style="display:none" onchange="updateTag();" name="subclassvalue"/></td>
				</tr>
			</table>
		</div>
		<?php
		$doc = JFactory::getDocument();
		$doc->addScriptDeclaration("window.addEvent('domready', function(){ updateTag(); });");
	}


	function acymailing_replaceusertags(&$email, &$user, $send = true){

		if(isset($this->noResult[intval($email->mailid)])) return;

		$match = '#{tableofcontents(.*)}#Ui';

		$variables = array('subject', 'body', 'altbody');

		$found = false;
		foreach($variables as $var){
			if(empty($email->$var)) continue;
			$found = preg_match_all($match, $email->$var, $results[$var]) || $found;
			if(empty($results[$var][0])) unset($results[$var]);
		}

		if(!$found){
			$this->noResult[intval($email->mailid)] = true;
			return;
		}

		$mailerHelper = acymailing_get('helper.mailer');

		$htmlreplace = array();
		$textreplace = array();
		foreach($results as $var => $allresults){
			foreach($allresults[0] as $i => $oneTag){
				if(isset($htmlreplace[$oneTag])) continue;

				$article = $this->_generateTable($allresults, $i, $email);
				$htmlreplace[$oneTag] = $article;
				$textreplace[$oneTag] = $mailerHelper->textVersion($article);
				$subjectreplace[$oneTag] = strip_tags($article);
			}
		}
		$email->body = str_replace(array_keys($htmlreplace), $htmlreplace, $email->body);
		$email->altbody = str_replace(array_keys($textreplace), $textreplace, $email->altbody);
		$email->subject = str_replace(array_keys($subjectreplace), $subjectreplace, $email->subject);
	}

	function _generateTable(&$results, $i, &$email){

		$arguments = explode('|', strip_tags($results[1][$i]));
		$tag = new stdClass();
		$tag->divider = $this->params->get('divider', 'br');
		$tag->before = '';
		$tag->after = '';
		$tag->subdivider = $this->params->get('divider', 'br');
		$tag->subbefore = '';
		$tag->subafter = '';
		for($i = 1, $a = count($arguments); $i < $a; $i++){
			$args = explode(':', $arguments[$i]);
			if(isset($args[1])){
				$tag->{$args[0]} = $args[1];
			}else{
				$tag->{$args[0]} = true;
			}
		}

		if($tag->divider == 'br'){
			$tag->divider = '<br />';
			$tag->subbefore = $tag->subdivider = '<br /> - ';
		}elseif($tag->divider == 'space'){
			$tag->subdivider = ', ';
			$tag->divider = ' ';
			$tag->subbefore = ' ( ';
			$tag->subafter = ' ) ';
		}elseif($tag->divider == 'li'){
			$tag->subdivider = $tag->divider = '</li><li>';
			$tag->subbefore = $tag->before = '<ul><li>';
			$tag->subafter = $tag->after = '</li></ul>';
		}

		$this->updateMail = array();
		$this->links = array();
		$this->sublinks = array();
		$anchorLinks = $this->_findLinks($tag, $email);
		if(!empty($tag->subtype) || !empty($tag->subclass)){
			$anchorSubLinks = $this->_findLinks($tag, $email, true);
			if(empty($this->links)){
				$this->links = $this->sublinks;
				unset($this->sublinks);
			}
		}

		$links = $this->links;
		if(!empty($tag->limit)){
			$links = array_slice($links, 0, $tag->limit);
		}

		if(empty($links)) return '';
		if(!empty($this->updateMail)) $email->body = str_replace(array_keys($this->updateMail), $this->updateMail, $email->body);

		if(!empty($this->sublinks)){
			$sublinks = $this->sublinks;
			foreach($links as $ilink => $oneLink){
				$allsublinks = array();
				$from = $anchorLinks['pos'][$ilink];
				$to = empty($anchorLinks['pos'][$ilink + 1]) ? 9999999999999 : $anchorLinks['pos'][$ilink + 1];
				foreach($sublinks as $isublink => $oneSubLink){
					if($anchorSubLinks['pos'][$isublink] > $to) break;
					if($anchorSubLinks['pos'][$isublink] > $from) $allsublinks[] = $oneSubLink;
				}
				if(!empty($allsublinks)) $links[$ilink] = $links[$ilink].$tag->subbefore.implode($tag->subdivider, $allsublinks).$tag->subafter;
			}
		}

		$result = '<div class="tableofcontents">'.$tag->before.implode($tag->divider, $links).$tag->after.'</div>';
		if(file_exists(ACYMAILING_MEDIA.'plugins'.DS.'tablecontents.php')){
			ob_start();
			require(ACYMAILING_MEDIA.'plugins'.DS.'tablecontents.php');
			$result = ob_get_clean();
		}
		return $result;
	}

	function _findLinks(&$tag, &$email, $sub = false){
		if($sub){
			$varType = 'subtype';
			$varClass = 'subclass';
			$varLink = &$this->sublinks;
		}else{
			$varType = 'type';
			$varClass = 'class';
			$varLink = &$this->links;
		}
		if(!empty($tag->$varType)){
			preg_match_all('#<'.$tag->$varType.'[^>]*>((?!</ *'.$tag->$varType.'>).)*</ *'.$tag->$varType.'>#Uis', $email->body, $anchorresults);
		}elseif(!empty($tag->class)){
			preg_match_all('#<[^>]*class="'.$tag->$varClass.'"[^>]*>(<[^>]*>|[^<>])*</.*>#Uis', $email->body, $anchorresults);
			$tag->$varType = 'item';
		}else{
			preg_match_all('#<a[^>]*name="([^">]*)"[^>]*>((?!</ *a>).)*</ *a>#Uis', $email->body, $anchorresults);
		}

		if(empty($anchorresults)) return '';


		foreach($anchorresults[0] as $i => $oneContent){
			$anchorresults['pos'][$i] = strpos($email->body, $oneContent);
			$linktext = strip_tags($oneContent);
			if(empty($linktext)) continue;
			if(empty($tag->$varType)){
				$varLink[$i] = '<a href="#'.$anchorresults[1][$i].'" class="oneitem" >'.$linktext.'</a>';
			}else{
				$varLink[$i] = '<a href="#'.$tag->$varType.$i.'" class="oneitem oneitem'.$tag->$varType.'" >'.$linktext.'</a>';
				if(preg_match('#<a[^>]*>[^<]*'.preg_quote($oneContent, '#').'#Uis', $email->body, $linkBefore)){
					$this->updateMail[$linkBefore[0]] = '<a name="'.$tag->$varType.$i.'"></a>'.$linkBefore[0];
				}else{
					$this->updateMail[$oneContent] = '<a name="'.$tag->$varType.$i.'"></a>'.$oneContent;
				}
			}
		}

		return $anchorresults;
	}
}//endclass
tablecontents/tablecontents.xml000064400000003264152345456710013021 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing table of contents generator</name>
	<creationDate>January 2011</creationDate>
	<version>1.0.0</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin enables you to generate table of contents</description>
	<files>
		<filename plugin="tablecontents">tablecontents.php</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-tablecontents"/>
		<param name="divider" type="radio" default="br" label="Divider" description="Separator added between each link">
			<option value="br">Carriage return</option>
			<option value="space">Space</option>
			<option value="li">ul / li</option>
		</param>
	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-tablecontents"/>
				<field name="divider" type="radio" default="br" label="Divider" description="Separator added between each link">
					<option value="br">Carriage return</option>
					<option value="space">Space</option>
					<option value="li">ul / li</option>
				</field>
			</fieldset>
		</fields>
	</config>
</extension>
tagcbuser/index.html000064400000000054152345456710010533 0ustar00<html><body bgcolor="#FFFFFF"></body></html>tagcbuser/tagcbuser.php000064400000032251152345456710011232 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

class plgAcymailingTagcbuser extends JPlugin{
	var $sendervalues = array();

	function __construct(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'tagcbuser');
			$this->params = new JParameter($plugin->params);
		}
	}

	function acymailing_getPluginType(){

		$app = JFactory::getApplication();
		if(!file_exists(ACYMAILING_ROOT.'components'.DS.'com_comprofiler'.DS.'comprofiler.php')) return;
		if($this->params->get('frontendaccess') == 'none' && !$app->isAdmin()) return;
		$onePlugin = new stdClass();
		$onePlugin->name = JText::_('CB User');
		$onePlugin->function = 'acymailingtagcb_show';
		$onePlugin->help = 'plugin-tagcbuser';

		return $onePlugin;
	}

	function onAcyDisplayFilters(&$type, $context = "massactions"){

		if($this->params->get('displayfilter_'.$context, true) == false) return;
		if(!file_exists(ACYMAILING_ROOT.'components'.DS.'com_comprofiler'.DS.'comprofiler.php')) return;

		$db = JFactory::getDBO();
		$fields = acymailing_getColumns('#__comprofiler');
		if(empty($fields)) return;

		$db->setQuery('SELECT name,title FROM #__comprofiler_fields WHERE `table` LIKE '.$db->Quote('#__comprofiler'));
		$fieldTitles = $db->loadObjectList('name');

		$languages = array();
		if(file_exists(JPATH_SITE.DS.'components'.DS.'com_comprofiler'.DS.'plugin'.DS.'language'.DS.'default_language'.DS.'language.php')){
			if(!defined('CBLIB')) include_once(JPATH_SITE.DS.'libraries/CBLib/CB/Application/CBApplication.php');
			$languages = include_once JPATH_SITE.DS.'components'.DS.'com_comprofiler'.DS.'plugin'.DS.'language'.DS.'default_language'.DS.'language.php';
		}elseif(file_exists(JPATH_SITE.DS.'components'.DS.'com_comprofiler'.DS.'plugin'.DS.'language'.DS.'default_language'.DS.'default_language.php')){
			include_once JPATH_SITE.DS.'components'.DS.'com_comprofiler'.DS.'plugin'.DS.'language'.DS.'default_language'.DS.'default_language.php';
		}

		ksort($fields);
		$cbfield = array();
		foreach($fields as $oneField => $fieldType){
			$text = $oneField;
			if(!empty($fieldTitles[$oneField])){
				if(!empty($languages[$fieldTitles[$oneField]->title])){
					$text .= ' ('.$languages[$fieldTitles[$oneField]->title].')';
				}else{
					if(defined($fieldTitles[$oneField]->title)){
						$text .= ' ('.constant($fieldTitles[$oneField]->title).')';
					}else $text .= ' ('.$fieldTitles[$oneField]->title.')';
				}
			}
			$cbfield[] = JHTML::_('select.option', $oneField, $text);
		}
		$type['cbfield'] = JText::_('CB_FIELD');

		$operators = acymailing_get('type.operators');
		$operators->extra = 'onchange="countresults(__num__)"';

		$return = '<div id="filter__num__cbfield">'.JHTML::_('select.genericlist', $cbfield, "filter[__num__][cbfield][map]", 'class="inputbox" size="1" onchange="countresults(__num__)"', 'value', 'text');
		$return .= ' '.$operators->display("filter[__num__][cbfield][operator]").' <input onchange="countresults(__num__)" class="inputbox" type="text" name="filter[__num__][cbfield][value]" style="width:200px" value="" /></div>';

		return $return;
	}

	function onAcyProcessFilter_cbfield(&$query, $filter, $num){
		$query->leftjoin['cbfield'] = '#__comprofiler AS cbfield ON cbfield.id = sub.userid';
		$query->where[] = $query->convertQuery('cbfield', $filter['map'], $filter['operator'], $filter['value']);
	}

	function onAcyProcessFilterCount_cbfield(&$query, $filter, $num){
		$this->onAcyProcessFilter_cbfield($query, $filter, $num);
		return JText::sprintf('SELECTED_USERS', $query->count());
	}

	function acymailingtagcb_show(){
		?>

		<script language="javascript" type="text/javascript">
			function applyTag(tagname){
				var string = '{cbtag:' + tagname;
				for(var i = 0; i < document.adminForm.typeinfo.length; i++){
					if(document.adminForm.typeinfo[i].checked){
						string += '|info:' + document.adminForm.typeinfo[i].value;
					}
				}
				string += '}';
				setTag(string);
				insertTag();
			}
		</script>
		<?php
		$typeinfo = array();
		$typeinfo[] = JHTML::_('select.option', "receiver", JText::_('RECEIVER_INFORMATION'));
		$typeinfo[] = JHTML::_('select.option', "sender", JText::_('SENDER_INFORMATIONS'));
		echo JHTML::_('acyselect.radiolist', $typeinfo, 'typeinfo', '', 'value', 'text', 'receiver');

		$text = '<table class="acymailing_table" cellpadding="1">';
		$db = JFactory::getDBO();
		$fields = acymailing_getColumns('#__comprofiler');

		$db->setQuery('SELECT name,type FROM #__comprofiler_fields');
		$fieldType = $db->loadObjectList('name');

		$k = 0;

		$text .= '<tr style="cursor:pointer" class="row1" onclick="applyTag(\'thumb\');" ><td class="acytdcheckbox"></td><td>Thumb Avatar</td></tr>';
		foreach($fields as $fieldname => $oneField){
			$type = '';
			if(strpos(strtolower($oneField), 'date') !== false) $type = '|type:date';
			if(!empty($fieldType[$fieldname]) AND $fieldType[$fieldname]->type == 'image') $type = '|type:image';
			$text .= '<tr style="cursor:pointer" class="row'.$k.'" onclick="applyTag(\''.$fieldname.$type.'\');" ><td class="acytdcheckbox"></td><td>'.$fieldname.'</td></tr>';
			$k = 1 - $k;
		}


		$db->setQuery("SELECT * FROM #__comprofiler_fields WHERE tablecolumns = '' AND published = 1");
		$otherFields = $db->loadObjectList();
		foreach($otherFields as $oneField){
			$text .= '<tr style="cursor:pointer" class="row'.$k.'" onclick="applyTag(\'cbapi_'.$oneField->name.'\');" ><td class="acytdcheckbox"></td><td>'.$oneField->name.'</td></tr>';
			$k = 1 - $k;
		}

		$text .= '</table>';

		echo $text;
	}

	function acymailing_replaceusertags(&$email, &$user, $send = true){
		$match = '#(?:{|%7B)cbtag:(.*)(?:}|%7D)#Ui';
		$variables = array('subject', 'body', 'altbody');
		$found = false;
		foreach($variables as $var){
			if(empty($email->$var)) continue;
			$found = preg_match_all($match, $email->$var, $results[$var]) || $found;
			if(empty($results[$var][0])) unset($results[$var]);
		}

		if(!$found) return;

		$uservalues = null;
		$db = JFactory::getDBO();
		if(!empty($user->userid)){
			$db->setQuery('SELECT * FROM '.acymailing_table('comprofiler', false).' WHERE user_id = '.$user->userid.' LIMIT 1');
			$uservalues = $db->loadObject();
		}

		$db->setQuery('SELECT fieldid, `table`, name, type, params FROM #__comprofiler_fields');
		$fieldObjects = $db->loadObjectList('name');

		include_once(ACYMAILING_ROOT.'administrator'.DS.'components'.DS.'com_comprofiler'.DS.'plugin.foundation.php');
		cbimport('cb.database');
		$pluginsHelper = acymailing_get('helper.acyplugins');
		$currentCBUser = null;

		$tags = array();
		foreach($results as $var => $allresults){
			foreach($allresults[0] as $i => $oneTag){
				if(isset($tags[$oneTag])) continue;

				$arguments = explode('|', $allresults[1][$i]);
				$field = $arguments[0];
				unset($arguments[0]);
				$mytag = new stdClass();
				$mytag->default = $this->params->get('default_'.$field, '');
				if(!empty($arguments)){
					foreach($arguments as $onearg){
						$args = explode(':', $onearg);
						if(isset($args[1])){
							$mytag->{$args[0]} = $args[1];
						}else{
							$mytag->{$args[0]} = 1;
						}
					}
				}

				$values = new stdClass();

				if(!empty($mytag->info) AND $mytag->info == 'sender'){
					if(empty($this->sendervalues[$email->mailid]) AND !empty($email->userid)){
						$db->setQuery('SELECT * FROM #__comprofiler WHERE user_id = '.$email->userid.' LIMIT 1');
						$this->sendervalues[$email->mailid] = $db->loadObject();
					}
					if(!empty($this->sendervalues[$email->mailid])) $values = $this->sendervalues[$email->mailid];
				}else{
					$values = $uservalues;
				}

				if(substr($field, 0, 6) == 'cbapi_'){
					if(!empty($mytag->info) AND $mytag->info == 'sender'){
						if(empty($this->sendervalues[$email->mailid]->$field) AND !empty($email->userid)){
							$currentSender = CBuser::getInstance($email->userid);
							$values->$field = $currentSender->getField(substr($field, 6), $mytag->default, 'html', 'none', 'profile', 0, true);
							$this->sendervalues[$email->mailid]->$field = $values->$field;
						}elseif(!empty($this->sendervalues[$email->mailid]->$field)){
							$values->$field = @$this->sendervalues[$email->mailid]->$field;
						}
					}elseif(!empty($user->userid)){
						if(empty($currentCBUser)) $currentCBUser = CBuser::getInstance($user->userid);
						if(!empty($currentCBUser)) $values->$field = $currentCBUser->getField(substr($field, 6), $mytag->default, 'html', 'none', 'profile', 0, true);
						if(empty($values->$field) && !empty($fieldObjects[substr($field, 6)]) && $fieldObjects[substr($field, 6)]->type == 'progress'){
							$fieldObjects[substr($field, 6)]->decodedParams = json_decode($fieldObjects[substr($field, 6)]->params);
							if(!empty($fieldObjects[substr($field, 6)]->decodedParams->prg_fields)){
								$requiredFields = explode('|*|', $fieldObjects[substr($field, 6)]->decodedParams->prg_fields);
								$filled_in = 0;
								foreach($fieldObjects as $oneField){
									if(!in_array($oneField->fieldid, $requiredFields) || !in_array($oneField->table, array('#__comprofiler', '#__users'))) continue;
									$fieldName = $oneField->name;
									if(!empty($currentCBUser->_cbuser->$fieldName)) $filled_in++;
								}
								$values->$field = intval(($filled_in * 100) / count($requiredFields)).'%';
							}
						}
					}
				}

				$replaceme = isset($values->$field) ? $values->$field : $mytag->default;
				if(!empty($mytag->type)){
					if($mytag->type == 'image' AND !empty($replaceme)){
						$replaceme = '<img src="'.ACYMAILING_LIVE.'images/comprofiler/'.$replaceme.'" alt="'.htmlspecialchars(@$user->name, ENT_COMPAT, 'UTF-8').'" />';
					}
				}

				if($field == 'thumb'){
					$replaceme = '<img src="'.ACYMAILING_LIVE.'images/comprofiler/tn'.$values->avatar.'" alt="'.htmlspecialchars(@$user->name, ENT_COMPAT, 'UTF-8').'" />';
				}elseif($field == 'avatar'){
					$replaceme = '<img src="'.ACYMAILING_LIVE.'images/comprofiler/'.$values->avatar.'" alt="'.htmlspecialchars(@$user->name, ENT_COMPAT, 'UTF-8').'" />';
				}

				$tags[$oneTag] = $replaceme;
				$pluginsHelper->formatString($tags[$oneTag], $mytag);
			}
		}

		foreach($results as $var => $allresults){
			$email->$var = str_replace(array_keys($tags), $tags, $email->$var);
		}
	}

	function onAcyDisplayActions(&$type){
		$fields = acymailing_getColumns('#__comprofiler');

		$field = array();
		$field[] = JHTML::_('select.option', 0, '- - -');
		foreach($fields as $oneField => $fieldType){
			if(in_array($oneField, array('id', 'user_id', 'hits', 'message_last_sent', 'message_number_sent', 'canvas', 'cbactivation'))) continue;
			$field[] = JHTML::_('select.option', $oneField, $oneField);
		}

		$content = '<div id="action__num__cbfieldval">'.JHTML::_('select.genericlist', $field, "action[__num__][cbfieldval][map]", 'class="inputbox" size="1"', 'value', 'text');
		$content .= ' = <input class="inputbox" type="text" id="action__num__cbfieldvalvalue" name="action[__num__][cbfieldval][value]" style="width:200px" value=""></div>';

		$type['cbfieldval'] = 'Community Builder: '.jtext::_('FIELD');

		return $content;
	}

	function onAcyProcessAction_cbfieldval($cquery, $action, $num){

		$replace = array('{year}', '{month}', '{weekday}', '{day}', '{hour}', '{minute}');
		$replaceBy = array(date('Y'), date('m'), date('N'), date('d'), date('H'), date('i'));
		$newValue = str_replace($replace, $replaceBy, acymailing_replaceDate($action['value']));

		if(preg_match_all('#{(year|month|weekday|day)\|(add|remove):([^}]*)}#Uis', $newValue, $results)){
			foreach($results[0] as $i => $oneMatch){
				$format = str_replace(array('year', 'month', 'weekday', 'day'), array('Y','m','N','d'), $results[1][$i]);
				$delay = str_replace(array('add', 'remove'), array('+', '-'), $results[2][$i]).intval($results[3][$i]).' '.str_replace('weekday', 'day', $results[1][$i]);
				$newValue = str_replace($oneMatch, date($format, strtotime($delay)), $newValue);
			}
		}

		if(empty($action['operator'])) $action['operator'] = '=';

		$fields = array_keys(acymailing_getColumns('#__comprofiler'));
		if(!in_array($action['map'], $fields)) return 'Unexisting field: '.$action['map'].' | The available fields are: '.implode(', ', $fields);

		$query = 'UPDATE #__comprofiler AS cb JOIN #__acymailing_subscriber AS sub ON cb.user_id = sub.userid';
		if(!empty($cquery->join)) $query .= ' JOIN '.implode(' JOIN ', $cquery->join);
		if(!empty($cquery->leftjoin)) $query .= ' LEFT JOIN '.implode(' LEFT JOIN ', $cquery->leftjoin);

		$query .= " SET cb.`".acymailing_secureField($action['map'])."` = ".$cquery->db->Quote($newValue);
		if(!empty($cquery->where)) $query .= ' WHERE ('.implode(') AND (', $cquery->where).')';

		$cquery->db->setQuery($query);
		$cquery->db->query();
		$nbAffected = $cquery->db->getAffectedRows();
		return JText::sprintf('NB_MODIFIED', $nbAffected);
	}
}//endclass
tagcbuser/tagcbuser.xml000064400000003651152345456710011245 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing Tag and filter : Community Builder</name>
	<creationDate>September 2009</creationDate>
	<version>3.7.2</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin enables you to add information from the CB Profile of the user in your newsletters. It also allows you to filter the users based on CB fields and modify these field values</description>
	<files>
		<filename plugin="tagcbuser">tagcbuser.php</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-tagcbuser"/>
		<param name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
			<option value="all">Always display this tag system</option>
			<option value="none">Don't display this tag system on the front-end</option>
		</param>
	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-tagcbuser"/>
				<field name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
					<option value="all">Always display this tag system</option>
					<option value="none">Don't display this tag system on the front-end</option>
				</field>
			</fieldset>
		</fields>
	</config>
</extension>
tagcbuser/tagcbuser_j30.xml000064400000001602152345456710011713 0ustar00<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="3.0" method="upgrade" group="acymailing">
	<name>AcyMailing Tag and filter : Community Builder</name>
	<creationDate>September 2009</creationDate>
	<version>3.7.2</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin enables you to add information from the CB Profile of the user in your newsletters. It also allows you to filter the users based on CB fields and modify these field values</description>
	<files>
		<filename plugin="tagcbuser">tagcbuser.php</filename>
		<filename>tagcbuser.xml</filename>
		<filename>index.html</filename>
	</files>
</extension>
tagcontent/index.html000064400000000054152345456710010722 0ustar00<html><body bgcolor="#FFFFFF"></body></html>tagcontent/tagcontent.php000064400000170113152345456710011610 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php defined('_JEXEC') or die('Restricted access'); ?>
<?php

class plgAcymailingTagcontent extends JPlugin{
	public function __construct(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'tagcontent');
			$this->params = new acyParameter($plugin->params);
		}
		$this->db = JFactory::getDBO();
		$this->acypluginsHelper = acymailing_get('helper.acyplugins');
	}

	public function acymailing_getPluginType(){
		$app = JFactory::getApplication();
		if($this->params->get('frontendaccess') == 'none' && !$app->isAdmin()) return;

		$onePlugin = new stdClass();
		$onePlugin->name = JText::_('JOOMLA_CONTENT');
		$onePlugin->function = 'acymailingtagcontent_show';
		$onePlugin->help = 'plugin-tagcontent';

		return $onePlugin;
	}

	public function acymailingtagcontent_show(){
		$app = JFactory::getApplication();

		$pageInfo = new stdClass();
		$pageInfo->filter = new stdClass();
		$pageInfo->filter->order = new stdClass();
		$pageInfo->limit = new stdClass();
		$pageInfo->elements = new stdClass();

		$my = JFactory::getUser();
		$lang = JFactory::getLanguage();
		$lang->load('com_content', JPATH_SITE);

		$paramBase = ACYMAILING_COMPONENT.'.tagcontent';
		$pageInfo->filter->order->value = $app->getUserStateFromRequest($paramBase.".filter_order", 'filter_order', 'a.id', 'cmd');
		$pageInfo->filter->order->dir = $app->getUserStateFromRequest($paramBase.".filter_order_Dir", 'filter_order_Dir', 'desc', 'word');
		if(strtolower($pageInfo->filter->order->dir) !== 'desc') $pageInfo->filter->order->dir = 'asc';
		$pageInfo->search = $app->getUserStateFromRequest($paramBase.".search", 'search', '', 'string');
		$pageInfo->search = JString::strtolower(trim($pageInfo->search));
		$pageInfo->filter_cat = $app->getUserStateFromRequest($paramBase.".filter_cat", 'filter_cat', '', 'int');
		$pageInfo->contenttype = $app->getUserStateFromRequest($paramBase.".contenttype", 'contenttype', $this->params->get('default_type', 'intro'), 'string');
		$pageInfo->author = $app->getUserStateFromRequest($paramBase.".author", 'author', $this->params->get('default_author', '0'), 'string');
		$pageInfo->titlelink = $app->getUserStateFromRequest($paramBase.".titlelink", 'titlelink', $this->params->get('default_titlelink', 'link'), 'string');
		$pageInfo->lang = $app->getUserStateFromRequest($paramBase.".lang", 'lang', '', 'string');
		$pageInfo->pict = $app->getUserStateFromRequest($paramBase.".pict", 'pict', $this->params->get('default_pict', 1), 'string');
		$pageInfo->pictheight = $app->getUserStateFromRequest($paramBase.".pictheight", 'pictheight', $this->params->get('maxheight', 150), 'string');
		$pageInfo->pictwidth = $app->getUserStateFromRequest($paramBase.".pictwidth", 'pictwidth', $this->params->get('maxwidth', 150), 'string');


		$pageInfo->limit->value = $app->getUserStateFromRequest($paramBase.'.list_limit', 'limit', $app->getCfg('list_limit'), 'int');
		$pageInfo->limit->start = $app->getUserStateFromRequest($paramBase.'.limitstart', 'limitstart', 0, 'int');

		$picts = array();
		$picts[] = JHTML::_('select.option', "1", JText::_('JOOMEXT_YES'));
		$pictureHelper = acymailing_get('helper.acypict');
		if($pictureHelper->available()) $picts[] = JHTML::_('select.option', "resized", JText::_('RESIZED'));
		$picts[] = JHTML::_('select.option', "0", JText::_('JOOMEXT_NO'));

		$contenttype = array();
		$contenttype[] = JHTML::_('select.option', "title", JText::_('TITLE_ONLY'));
		$contenttype[] = JHTML::_('select.option', "intro", JText::_('INTRO_ONLY'));
		$contenttype[] = JHTML::_('select.option', "text", JText::_('FIELD_TEXT'));
		$contenttype[] = JHTML::_('select.option', "full", JText::_('FULL_TEXT'));

		$titlelink = array();
		$titlelink[] = JHTML::_('select.option', "link", JText::_('JOOMEXT_YES'));
		$titlelink[] = JHTML::_('select.option', "0", JText::_('JOOMEXT_NO'));

		$authorname = array();
		$authorname[] = JHTML::_('select.option', "author", JText::_('JOOMEXT_YES'));
		$authorname[] = JHTML::_('select.option', "0", JText::_('JOOMEXT_NO'));

		$searchFields = array('a.id', 'a.title', 'a.alias', 'a.created_by', 'b.name', 'b.username');
		if(!empty($pageInfo->search)){
			$searchVal = '\'%'.acymailing_getEscaped($pageInfo->search, true).'%\'';
			$filters[] = implode(" LIKE $searchVal OR ", $searchFields)." LIKE $searchVal";
		}

		if(!empty($pageInfo->filter_cat)){
			$filters[] = "a.catid = ".$pageInfo->filter_cat;
		}

		if($this->params->get('displayart', 'all') == 'onlypub'){
			$filters[] = "a.state = 1";
		}else{
			$filters[] = "a.state != -2";
		}

		if(!$app->isAdmin()){
			if(!ACYMAILING_J16){
				$filters[] = 'a.`access` <= '.(int)$my->get('aid');
			}else{
				$groups = implode(',', $my->getAuthorisedViewLevels());
				$filters[] = 'a.`access` IN ('.$groups.')';
			}
		}

		if($this->params->get('frontendaccess') == 'author' && !$app->isAdmin()){
			$filters[] = "a.created_by = ".intval($my->id);
		}

		$whereQuery = '';
		if(!empty($filters)){
			$whereQuery = ' WHERE ('.implode(') AND (', $filters).')';
		}

		$query = 'SELECT SQL_CALC_FOUND_ROWS a.*,b.name,b.username,a.created_by FROM '.acymailing_table('content', false).' as a';
		$query .= ' LEFT JOIN `#__users` AS b ON b.id = a.created_by';
		if(!empty($whereQuery)) $query .= $whereQuery;
		if(!empty($pageInfo->filter->order->value)){
			$query .= ' ORDER BY '.$pageInfo->filter->order->value.' '.$pageInfo->filter->order->dir;
		}

		$this->db->setQuery($query, $pageInfo->limit->start, $pageInfo->limit->value);
		$rows = $this->db->loadObjectList();

		if(!empty($pageInfo->search)){
			$rows = acymailing_search($pageInfo->search, $rows);
		}

		$this->db->setQuery('SELECT FOUND_ROWS()');
		$pageInfo->elements->total = $this->db->loadResult();
		$pageInfo->elements->page = count($rows);

		if(!ACYMAILING_J16){
			$query = 'SELECT a.id, a.id as catid, a.title as category, b.title as section, b.id as secid from #__categories as a ';
			$query .= 'INNER JOIN #__sections as b on a.section = b.id ORDER BY b.ordering,a.ordering';

			$this->db->setQuery($query);
			$categories = $this->db->loadObjectList('id');
			$categoriesValues = array();
			$categoriesValues[] = JHTML::_('select.option', '', JText::_('ACY_ALL'));
			$currentSec = '';
			foreach($categories as $catid => $oneCategorie){
				if($currentSec != $oneCategorie->section){
					if(!empty($currentSec)) $this->values[] = JHTML::_('select.option', '</OPTGROUP>');
					$categoriesValues[] = JHTML::_('select.option', '<OPTGROUP>', $oneCategorie->section);
					$currentSec = $oneCategorie->section;
				}
				$categoriesValues[] = JHTML::_('select.option', $catid, $oneCategorie->category);
			}
		}else{
			$query = "SELECT * from #__categories WHERE `extension` = 'com_content' ORDER BY lft ASC";

			$this->db->setQuery($query);
			$categories = $this->db->loadObjectList('id');
			$categoriesValues = array();
			$categoriesValues[] = JHTML::_('select.option', '', JText::_('ACY_ALL'));
			foreach($categories as $catid => $oneCategorie){
				$categories[$catid]->title = str_repeat('- - ', $categories[$catid]->level).$categories[$catid]->title;
				$categoriesValues[] = JHTML::_('select.option', $catid, $categories[$catid]->title);
			}
		}

		jimport('joomla.html.pagination');
		$pagination = new JPagination($pageInfo->elements->total, $pageInfo->limit->start, $pageInfo->limit->value);

		$tabs = acymailing_get('helper.acytabs');
		echo $tabs->startPane('joomlacontent_tab');
		echo $tabs->startPanel(JText::_('JOOMLA_CONTENT'), 'joomlacontent_content');

		?>
		<script language="javascript" type="text/javascript">
			<!--
			var selectedContents = new Array();
			function applyContent(contentid, rowClass){
				var tmp = selectedContents.indexOf(contentid)
				if(tmp != -1){
					window.document.getElementById('content' + contentid).className = rowClass;
					delete selectedContents[tmp];
				}else{
					window.document.getElementById('content' + contentid).className = 'selectedrow';
					selectedContents.push(contentid);
				}
				updateTag();
			}

			function updateTag(){
				var tag = '';
				var otherinfo = '';
				for(var i = 0; i < document.adminForm.contenttype.length; i++){
					if(document.adminForm.contenttype[i].checked){
						selectedtype = document.adminForm.contenttype[i].value;
						otherinfo += '| type:' + document.adminForm.contenttype[i].value;
					}
				}
				for(var i = 0; i < document.adminForm.titlelink.length; i++){
					if(document.adminForm.titlelink[i].checked && document.adminForm.titlelink[i].value.length > 1){
						otherinfo += '| ' + document.adminForm.titlelink[i].value;
					}
				}
				if(selectedtype != 'title'){
					for(var i = 0; i < document.adminForm.author.length; i++){
						if(document.adminForm.author[i].checked && document.adminForm.author[i].value.length > 1){
							otherinfo += '| ' + document.adminForm.author[i].value;
						}
					}
					for(var i = 0; i < document.adminForm.pict.length; i++){
						if(document.adminForm.pict[i].checked){
							otherinfo += '| pict:' + document.adminForm.pict[i].value;
							if(document.adminForm.pict[i].value == 'resized'){
								document.getElementById('pictsize').style.display = '';
								if(document.adminForm.pictwidth.value) otherinfo += '| maxwidth:' + document.adminForm.pictwidth.value;
								if(document.adminForm.pictheight.value) otherinfo += '| maxheight:' + document.adminForm.pictheight.value;
							}else{
								document.getElementById('pictsize').style.display = 'none';
							}
						}
					}
					document.getElementById('format').style.display = '';
				}else{
					document.getElementById('format').style.display = 'none';
				}

				if(document.adminForm.contentformat && document.adminForm.contentformat.value){
					otherinfo += '| format:' + document.adminForm.contentformat.value;
				}

				if(window.document.getElementById('jflang') && window.document.getElementById('jflang').value != ''){
					otherinfo += '|lang:';
					otherinfo += window.document.getElementById('jflang').value;
				}

				for(var i in selectedContents){
					if(selectedContents[i] && !isNaN(i)){
						tag = tag + '{joomlacontent:' + selectedContents[i] + otherinfo + '}<br />';
					}
				}
				setTag(tag);
			}
			//-->
		</script>
		<div class="onelineblockoptions">
			<table width="100%" class="acymailing_table">
				<tr>
					<td>
						<?php echo JText::_('DISPLAY'); ?>
					</td>
					<td colspan="2">
						<?php echo JHTML::_('acyselect.radiolist', $contenttype, 'contenttype', 'size="1" onclick="updateTag();"', 'value', 'text', $pageInfo->contenttype); ?>
					</td>
					<td>
						<?php $jflanguages = acymailing_get('type.jflanguages');
						$jflanguages->onclick = 'onchange="updateTag();"';
						echo $jflanguages->display('lang', $pageInfo->lang); ?>
					</td>
				</tr>
				<tr id="format" class="acyplugformat">
					<td valign="top">
						<?php echo JText::_('FORMAT'); ?>
					</td>
					<td valign="top">
						<?php echo $this->acypluginsHelper->getFormatOption('tagcontent'); ?>
					</td>
					<td valign="top"><?php echo JText::_('DISPLAY_PICTURES'); ?></td>
					<td valign="top"><?php echo JHTML::_('acyselect.radiolist', $picts, 'pict', 'size="1" onclick="updateTag();"', 'value', 'text', $pageInfo->pict); ?>
						<span id="pictsize" <?php if($pageInfo->pict != 'resized') echo 'style="display:none;"'; ?>><br/><?php echo JText::_('CAPTCHA_WIDTH') ?>
							<input name="pictwidth" type="text" onchange="updateTag();" value="<?php echo $pageInfo->pictwidth; ?>" style="width:30px;"/>
							x <?php echo JText::_('CAPTCHA_HEIGHT') ?>
							<input name="pictheight" type="text" onchange="updateTag();" value="<?php echo $pageInfo->pictheight; ?>" style="width:30px;"/>
						</span>
					</td>
				</tr>
				<tr>
					<td>
						<?php echo JText::_('CLICKABLE_TITLE'); ?>
					</td>
					<td>
						<?php echo JHTML::_('acyselect.radiolist', $titlelink, 'titlelink', 'size="1" onclick="updateTag();"', 'value', 'text', $pageInfo->titlelink); ?>
					</td>
					<td>
						<?php echo JText::_('AUTHOR_NAME'); ?>
					</td>
					<td>
						<?php echo JHTML::_('acyselect.radiolist', $authorname, 'author', 'size="1" onclick="updateTag();"', 'value', 'text', (string)$pageInfo->author); ?>
					</td>
				</tr>
			</table>
		</div>
		<div class="onelineblockoptions">
			<table class="acymailing_table_options">
				<tr>
					<td width="100%">
						<?php acymailing_listingsearch($pageInfo->search); ?>
					</td>
					<td nowrap="nowrap">
						<?php echo JHTML::_('select.genericlist', $categoriesValues, 'filter_cat', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', (int)$pageInfo->filter_cat); ?>
					</td>
				</tr>
			</table>

			<table class="acymailing_table" cellpadding="1" width="100%">
				<thead>
				<tr>
					<th class="title">
					</th>
					<th class="title">
						<?php echo JHTML::_('grid.sort', JText::_('FIELD_TITLE'), 'a.title', $pageInfo->filter->order->dir, $pageInfo->filter->order->value); ?>
					</th>
					<th class="title">
						<?php echo JHTML::_('grid.sort', JText::_('ACY_AUTHOR'), 'b.name', $pageInfo->filter->order->dir, $pageInfo->filter->order->value); ?>
					</th>
					<th class="title">
						<?php echo JHTML::_('grid.sort', JText::_(ACYMAILING_J16 ? 'COM_CONTENT_PUBLISHED_DATE' : 'START PUBLISHING'), 'a.publish_up', $pageInfo->filter->order->dir, $pageInfo->filter->order->value); ?>
					</th>
					<th class="title">
						<?php echo JHTML::_('grid.sort', JText::_('ACY_CREATED'), 'a.created', $pageInfo->filter->order->dir, $pageInfo->filter->order->value); ?>
					</th>
					<th class="title titleid">
						<?php echo JHTML::_('grid.sort', JText::_('ACY_ID'), 'a.id', $pageInfo->filter->order->dir, $pageInfo->filter->order->value); ?>
					</th>
				</tr>
				</thead>
				<tfoot>
				<tr>
					<td colspan="6">
						<?php echo $pagination->getListFooter(); ?>
						<?php echo $pagination->getResultsCounter(); ?>
					</td>
				</tr>
				</tfoot>
				<tbody>
				<?php
				$k = 0;
				for($i = 0, $a = count($rows); $i < $a; $i++){
					$row =& $rows[$i];
					?>
					<tr id="content<?php echo $row->id ?>" class="<?php echo "row$k"; ?>" onclick="applyContent(<?php echo $row->id.",'row$k'" ?>);" style="cursor:pointer;">
						<td class="acytdcheckbox"></td>
						<td>
							<?php
							$text = '<b>'.JText::_('JOOMEXT_ALIAS').': </b>'.$row->alias;
							echo acymailing_tooltip($text, $row->title, '', $row->title);
							?>
						</td>
						<td>
							<?php
							if(!empty($row->name)){
								$text = '<b>'.JText::_('JOOMEXT_NAME').' : </b>'.$row->name;
								$text .= '<br /><b>'.JText::_('ACY_USERNAME').' : </b>'.$row->username;
								$text .= '<br /><b>'.JText::_('ACY_ID').' : </b>'.$row->created_by;
								echo acymailing_tooltip($text, $row->name, '', $row->name);
							}
							?>
						</td>
						<td align="center">
							<?php echo JHTML::_('date', strip_tags($row->publish_up), JText::_('DATE_FORMAT_LC4')); ?>
						</td>
						<td align="center">
							<?php echo JHTML::_('date', strip_tags($row->created), JText::_('DATE_FORMAT_LC4')); ?>
						</td>
						<td align="center">
							<?php echo $row->id; ?>
						</td>
					</tr>
					<?php
					$k = 1 - $k;
				}
				?>
				</tbody>
			</table>
		</div>
		<input type="hidden" name="boxchecked" value="0"/>
		<input type="hidden" name="filter_order" value="<?php echo $pageInfo->filter->order->value; ?>"/>
		<input type="hidden" name="filter_order_Dir" value="<?php echo $pageInfo->filter->order->dir; ?>"/>
		<?php
		echo $tabs->endPanel();
		echo $tabs->startPanel(JText::_('TAG_CATEGORIES'), 'joomlacontent_auto');

		$type = JRequest::getString('type');

		?>
		<script language="javascript" type="text/javascript">
			<!--
			window.onload = function(){
				if(window.document.getElementById('tagsauto')){
					window.document.getElementById('tagsauto').onchange = updateAutoTag;
				}
			}
			var selectedCategories = new Array();
			<?php if(!ACYMAILING_J16){ ?>
			function applyAutoContent(secid, catid, rowClass){
				if(selectedCategories[secid] && selectedCategories[secid][catid]){
					window.document.getElementById('content_sec' + secid + '_cat' + catid).className = rowClass;
					delete selectedCategories[secid][catid];
				}else{
					if(!selectedCategories[secid]) selectedCategories[secid] = new Array();
					if(secid == 0){
						for(var isec in selectedCategories){
							for(var icat in selectedCategories[isec]){
								if(selectedCategories[isec][icat] == 'content'){
									window.document.getElementById('content_sec' + isec + '_cat' + icat).className = 'row0';
									delete selectedCategories[isec][icat];
								}
							}
						}
					}else{
						if(selectedCategories[0] && selectedCategories[0][0]){
							window.document.getElementById('content_sec0_cat0').className = 'row0';
							delete selectedCategories[0][0];
						}

						if(catid == 0){
							for(var icat in selectedCategories[secid]){
								if(selectedCategories[secid][icat] == 'content'){
									window.document.getElementById('content_sec' + secid + '_cat' + icat).className = 'row0';
									delete selectedCategories[secid][icat];
								}
							}
						}else{
							if(selectedCategories[secid][0]){
								window.document.getElementById('content_sec' + secid + '_cat0').className = 'row0';
								delete selectedCategories[secid][0];
							}
						}
					}

					window.document.getElementById('content_sec' + secid + '_cat' + catid).className = 'selectedrow';
					selectedCategories[secid][catid] = 'content';
				}

				updateAutoTag();
			}
			<?php }else{ ?>
			function applyAutoContent(catid, rowClass){
				if(selectedCategories[catid]){
					window.document.getElementById('content_cat' + catid).className = rowClass;
					delete selectedCategories[catid];
				}else{
					window.document.getElementById('content_cat' + catid).className = 'selectedrow';
					selectedCategories[catid] = 'content';
				}

				updateAutoTag();
			}
			<?php } ?>

			function updateAutoTag(){
				tag = '{autocontent:';
				<?php if(!ACYMAILING_J16){ ?>
				for(var isec in selectedCategories){
					for(var icat in selectedCategories[isec]){
						if(selectedCategories[isec][icat] == 'content'){
							if(icat != 0){
								tag += 'cat' + icat + '-';
							}else{
								tag += 'sec' + isec + '-';
							}
						}
					}
				}
				<?php }else{ ?>
				for(var icat in selectedCategories){
					if(selectedCategories[icat] == 'content'){
						tag += icat + '-';
					}
				}
				<?php } ?>

				if(document.adminForm.min_article && document.adminForm.min_article.value && document.adminForm.min_article.value != 0){
					tag += '| min:' + document.adminForm.min_article.value;
				}
				if(document.adminForm.max_article.value && document.adminForm.max_article.value != 0){
					tag += '| max:' + document.adminForm.max_article.value;
				}
				if(document.adminForm.contentorder.value){
					tag += "| order:" + document.adminForm.contentorder.value + "," + document.adminForm.contentorderdir.value;
				}
				if(document.adminForm.contentfilter && document.adminForm.contentfilter.value){
					tag += document.adminForm.contentfilter.value;
				}
				if(document.adminForm.meta_article && document.adminForm.meta_article.value){
					tag += '| meta:' + document.adminForm.meta_article.value;
				}

				for(var i = 0; i < document.adminForm.contenttypeauto.length; i++){
					if(document.adminForm.contenttypeauto[i].checked){
						selectedtype = document.adminForm.contenttypeauto[i].value;
						tag += '| type:' + document.adminForm.contenttypeauto[i].value;
					}
				}

				for(var i = 0; i < document.adminForm.titlelinkauto.length; i++){
					if(document.adminForm.titlelinkauto[i].checked && document.adminForm.titlelinkauto[i].value.length > 1){
						tag += '|' + document.adminForm.titlelinkauto[i].value;
					}
				}
				if(selectedtype != 'title'){
					for(var i = 0; i < document.adminForm.authorauto.length; i++){
						if(document.adminForm.authorauto[i].checked && document.adminForm.authorauto[i].value.length > 1){
							tag += '|' + document.adminForm.authorauto[i].value;
						}
					}
					for(var i = 0; i < document.adminForm.pictauto.length; i++){
						if(document.adminForm.pictauto[i].checked){
							tag += '| pict:' + document.adminForm.pictauto[i].value;
							if(document.adminForm.pictauto[i].value == 'resized'){
								document.getElementById('pictsizeauto').style.display = '';
								if(document.adminForm.pictwidthauto.value) tag += '| maxwidth:' + document.adminForm.pictwidthauto.value;
								if(document.adminForm.pictheightauto.value) tag += '| maxheight:' + document.adminForm.pictheightauto.value;
							}else{
								document.getElementById('pictsizeauto').style.display = 'none';
							}
						}
					}
					document.getElementById('formatauto').style.display = '';
				}else{
					document.getElementById('formatauto').style.display = 'none';
				}

				if(document.getElementById('contentformatautoinvert').value == 1) tag += '| invert';
				if(document.adminForm.contentformatauto && document.adminForm.contentformatauto.value){
					tag += '| format:' + document.adminForm.contentformatauto.value;
				}

				if(document.adminForm.cols && document.adminForm.cols.value > 1){
					tag += '| cols:' + document.adminForm.cols.value;
				}
				if(window.document.getElementById('jflangauto') && window.document.getElementById('jflangauto').value != ''){
					tag += '| lang:' + window.document.getElementById('jflangauto').value;
				}
				if(window.document.getElementById('jlang') && window.document.getElementById('jlang').value != ''){
					tag += '| language:' + window.document.getElementById('jlang').value;
				}

				if(window.document.getElementById('tagsauto')){
					var tmp = 0;
					for(var i = 0; i < window.document.getElementById('tagsauto').length; i++){
						if(window.document.getElementById('tagsauto')[i].selected){
							if(tmp == 0){
								tag += '| tags:' + window.document.getElementById('tagsauto')[i].value;
								tmp = 1;
							}else{
								tag += ',' + window.document.getElementById('tagsauto')[i].value;
							}
						}
					}
				}

				tag += '}';

				setTag(tag);
			}
			//-->
		</script>
		<div class="onelineblockoptions">
			<table width="100%" class="acymailing_table">
				<tr>
					<td>
						<?php echo JText::_('DISPLAY'); ?>
					</td>
					<td colspan="2">
						<?php echo JHTML::_('acyselect.radiolist', $contenttype, 'contenttypeauto', 'size="1" onclick="updateAutoTag();"', 'value', 'text', $this->params->get('default_type', 'intro')); ?>
					</td>
					<td id="languagesauto">
						<?php $jflanguages = acymailing_get('type.jflanguages');
						$jflanguages->onclick = 'onchange="updateAutoTag();"';
						$jflanguages->id = 'jflangauto';
						echo $jflanguages->display('langauto');
						if(empty($jflanguages->found)){
							echo $jflanguages->displayJLanguages('jlangauto');
						}
						?>
					</td>
				</tr>
				<tr id="formatauto" class="acyplugformat">
					<td valign="top">
						<?php echo JText::_('FORMAT'); ?>
					</td>
					<td valign="top">
						<?php echo $this->acypluginsHelper->getFormatOption('tagcontent', 'TOP_LEFT', false, 'updateAutoTag'); ?>
					</td>
					<td valign="top"><?php echo JText::_('DISPLAY_PICTURES'); ?></td>
					<td valign="top"><?php echo JHTML::_('acyselect.radiolist', $picts, 'pictauto', 'size="1" onclick="updateAutoTag();"', 'value', 'text', $this->params->get('default_pict', '1')); ?>
						<span id="pictsizeauto" <?php if($this->params->get('default_pict', '1') != 'resized') echo 'style="display:none;"'; ?> ><br/><?php echo JText::_('CAPTCHA_WIDTH') ?>
							<input name="pictwidthauto" type="text" onchange="updateAutoTag();" value="<?php echo $this->params->get('maxwidth', '150'); ?>" style="width:30px;"/>
							x <?php echo JText::_('CAPTCHA_HEIGHT') ?>
							<input name="pictheightauto" type="text" onchange="updateAutoTag();" value="<?php echo $this->params->get('maxheight', '150'); ?>" style="width:30px;"/>
						</span>
					</td>
				</tr>
				<tr>
					<td>
						<?php echo JText::_('CLICKABLE_TITLE'); ?>
					</td>
					<td>
						<?php echo JHTML::_('acyselect.radiolist', $titlelink, 'titlelinkauto', 'size="1" onclick="updateAutoTag();"', 'value', 'text', $this->params->get('default_titlelink', 'link')); ?>
					</td>
					<td>
						<?php echo JText::_('AUTHOR_NAME'); ?>
					</td>
					<td>
						<?php echo JHTML::_('acyselect.radiolist', $authorname, 'authorauto', 'size="1" onclick="updateAutoTag();"', 'value', 'text', (string)$this->params->get('default_author', '0')); ?>
					</td>
				</tr>
				<tr>
					<?php if(version_compare(JVERSION, '3.1.0', '>=')){ ?>
						<td valign="top">
							<?php echo JText::_('TAGS'); ?>
						</td>
						<td>
							<?php
							$form = JForm::getInstance('acytagcontenttags', JPATH_SITE.DS.'components'.DS.'com_acymailing'.DS.'params'.DS.'tagcontenttags.xml');
							foreach($form->getFieldset('tagcontenttagfield') as $field){
								echo $field->input;
							}
							?>
						</td>
					<?php }else{ ?>
						<td colspan="2"></td>
					<?php } ?>
					<td valign="top"><?php echo JText::_('FIELD_COLUMNS'); ?></td>
					<td valign="top">
						<select name="cols" style="width:150px" onchange="updateAutoTag();" size="1">
							<?php for($o = 1; $o < 11; $o++) echo '<option value="'.$o.'">'.$o.'</option>'; ?>
						</select>
					</td>
				</tr>
				<tr>
					<td>
						<?php echo JText::_('MAX_ARTICLE'); ?>
					</td>
					<td>
						<input type="text" name="max_article" style="width:50px" value="20" onchange="updateAutoTag();"/>
					</td>
					<td>
						<?php echo JText::_('ACY_ORDER'); ?>
					</td>
					<td>
						<?php
						$values = array('id' => 'ACY_ID', 'ordering' => 'ACY_ORDERING', 'created' => 'CREATED_DATE', 'modified' => 'MODIFIED_DATE', 'title' => 'FIELD_TITLE');
						if(ACYMAILING_J16) $values['publish_up'] = 'COM_CONTENT_PUBLISHED_DATE';
						echo $this->acypluginsHelper->getOrderingField($values, 'id', 'DESC', 'updateAutoTag');
						?>
					</td>
				</tr>
				<?php if($this->params->get('metaselect')){ ?>
					<tr>
						<td>
							<?php echo JText::_('META_KEYWORDS'); ?>
						</td>
						<td colspan="3">
							<input type="text" name="meta_article" style="width:200px" value="" onchange="updateAutoTag();"/>
						</td>
					</tr>
				<?php } ?>
				<?php if($type == 'autonews'){ ?>
					<tr>
						<td>
							<?php echo JText::_('MIN_ARTICLE'); ?>
						</td>
						<td>
							<input type="text" name="min_article" style="width:50px" value="1" onchange="updateAutoTag();"/>
						</td>
						<td>
							<?php echo JText::_('JOOMEXT_FILTER'); ?>
						</td>
						<td>
							<?php $filter = acymailing_get('type.contentfilter');
							$filter->onclick = "updateAutoTag();";
							echo $filter->display('contentfilter', '|filter:created'); ?>
						</td>
					</tr>
				<?php } ?>
			</table>
		</div>

		<div class="onelineblockoptions">
			<table class="acymailing_table" cellpadding="1" width="100%">
				<thead>
				<tr>
					<th class="title"></th>
					<?php if(!ACYMAILING_J16){ ?>
						<th class="title">
							<?php echo JText::_('SECTION'); ?>
						</th>
					<?php } ?>
					<th class="title">
						<?php echo JText::_('TAG_CATEGORIES'); ?>
					</th>
				</tr>
				</thead>
				<tbody>
				<?php
				$k = 0;
				if(!ACYMAILING_J16){
					?>
					<tr id="content_sec0_cat0" class="<?php echo "row$k"; ?>" onclick="applyAutoContent(0,0,'<?php echo "row$k" ?>');" style="cursor:pointer;">
						<td class="acytdcheckbox"></td>
						<td style="font-weight: bold;">
							<?php
							echo JText::_('ACY_ALL');
							?>
						</td>
						<td style="text-align:center;font-weight: bold;">
							<?php
							echo JText::_('ACY_ALL');
							?>
						</td>
					</tr>

					<?php
				}

				$k = 1 - $k;
				$currentSection = '';
				foreach($categories as $row){

					if(!ACYMAILING_J16 && $currentSection != $row->section){
						?>
						<tr id="content_sec<?php echo $row->secid ?>_cat0" class="<?php echo "row$k"; ?>" onclick="applyAutoContent(<?php echo $row->secid ?>,0,'<?php echo "row$k" ?>');" style="cursor:pointer;">
							<td class="acytdcheckbox"></td>
							<td style="font-weight: bold;">
								<?php
								echo $row->section;
								?>
							</td>
							<td style="text-align:center;font-weight: bold;">
								<?php
								echo JText::_('ACY_ALL');
								?>
							</td>
						</tr>
						<?php
						$k = 1 - $k;
						$currentSection = $row->section;
					}
					if(!ACYMAILING_J16){
						?>
						<tr id="content_sec<?php echo $row->secid ?>_cat<?php echo $row->catid ?>" class="<?php echo "row$k"; ?>" onclick="applyAutoContent(<?php echo $row->secid ?>,<?php echo $row->catid ?>,'<?php echo "row$k" ?>');" style="cursor:pointer;">
							<td class="acytdcheckbox"></td>
							<td>
							</td>
							<td>
								<?php
								echo $row->category;
								?>
							</td>
						</tr>
						<?php
					}else{ ?>
						<tr id="content_cat<?php echo $row->id ?>" class="<?php echo "row$k"; ?>" onclick="applyAutoContent(<?php echo $row->id ?>,'<?php echo "row$k" ?>');" style="cursor:pointer;">
							<td class="acytdcheckbox"></td>
							<td>
								<?php
								echo $row->title;
								?>
							</td>
						</tr>
					<?php }
					$k = 1 - $k;
				}
				?>
				</tbody>
			</table>
		</div>
		<?php

		echo $tabs->endPanel();
		echo $tabs->endPane();
	}

	public function acymailing_replacetags(&$email, $send = true){
		$this->_replaceAuto($email);
		$this->_replaceArticles($email);
	}

	private function _replaceArticles(&$email){
		$tags = $this->acypluginsHelper->extractTags($email, 'joomlacontent');
		if(empty($tags)) return;

		$this->newslanguage = new stdClass();
		if(!empty($email->language)){
			$this->db->setQuery('SELECT lang_id, lang_code FROM #__languages WHERE sef = '.$this->db->quote($email->language).' LIMIT 1');
			$this->newslanguage = $this->db->loadObject();
		}

		$this->currentcatid = -1;
		$this->readmore = empty($email->template->readmore) ? JText::_('JOOMEXT_READ_MORE') : '<img class="readmorepict" src="'.ACYMAILING_LIVE.$email->template->readmore.'" alt="'.JText::_('JOOMEXT_READ_MORE', true).'" />';

		require_once JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php';

		if($this->params->get('integration') == 'flexicontent' && file_exists(JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'helpers'.DS.'route.php')){
			require_once JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'helpers'.DS.'route.php';
		}

		$tagsReplaced = array();
		foreach($tags as $i => $oneTag){
			if(isset($tagsReplaced[$i])) continue;
			$tagsReplaced[$i] = $this->_replaceContent($oneTag);
		}

		$this->acypluginsHelper->replaceTags($email, $tagsReplaced, true);
	}

	private function _replaceContent(&$tag){
		$oldFormat = empty($tag->format);

		if(!ACYMAILING_J16){
			$query = 'SELECT a.*,b.name as authorname, c.alias as catalias, c.title as cattitle, c.image AS catpict, s.alias as secalias, s.title as sectitle FROM '.acymailing_table('content', false).' as a ';
			$query .= 'LEFT JOIN '.acymailing_table('users', false).' as b ON a.created_by = b.id ';
			$query .= ' LEFT JOIN '.acymailing_table('categories', false).' AS c ON c.id = a.catid ';
			$query .= ' LEFT JOIN '.acymailing_table('sections', false).' AS s ON s.id = a.sectionid ';
			$query .= 'WHERE a.id = '.$tag->id.' LIMIT 1';
		}else{
			$query = 'SELECT a.*,b.name as authorname, c.alias as catalias, c.title as cattitle, c.params AS catparams FROM '.acymailing_table('content', false).' as a ';
			$query .= 'LEFT JOIN '.acymailing_table('users', false).' as b ON a.created_by = b.id ';
			$query .= ' LEFT JOIN '.acymailing_table('categories', false).' AS c ON c.id = a.catid ';
			$query .= 'WHERE a.id = '.$tag->id.' LIMIT 1';
		}

		$this->db->setQuery($query);
		$article = $this->db->loadObject();

		if(empty($article)){
			$app = JFactory::getApplication();
			if($app->isAdmin()) $app->enqueueMessage('The article "'.$tag->id.'" could not be loaded', 'notice');
			return '';
		}

		if(empty($tag->lang) && !empty($this->newslanguage) && !empty($this->newslanguage->lang_code)) $tag->lang = $this->newslanguage->lang_code.','.$this->newslanguage->lang_id;

		$this->acypluginsHelper->translateItem($article, $tag, 'content');

		$varFields = array();
		foreach($article as $fieldName => $oneField){
			$varFields['{'.$fieldName.'}'] = $oneField;
		}

		$this->acypluginsHelper->cleanHtml($article->introtext);
		$this->acypluginsHelper->cleanHtml($article->fulltext);


		if($this->params->get('integration') == 'jreviews' && !empty($article->images)){
			$firstpict = explode('|', trim(reset(explode("\n", $article->images))).'|||||||');
			if(!empty($firstpict[0])){
				$picturePath = file_exists(ACYMAILING_ROOT.'images'.DS.'stories'.DS.str_replace('/', DS, $firstpict[0])) ? ACYMAILING_LIVE.'images/stories/'.$firstpict[0] : ACYMAILING_LIVE.'images/'.$firstpict[0];
				$myPict = '<img src="'.$picturePath.'" alt="" hspace="5" style="margin:5px" align="left" border="'.intval($firstpict[5]).'" />';
				$article->introtext = $myPict.$article->introtext;
			}
		}
		$completeId = $article->id;
		$completeCat = $article->catid;

		if(!empty($article->alias)) $completeId .= ':'.$article->alias;
		if(!empty($article->catalias)) $completeCat .= ':'.$article->catalias;

		if(empty($tag->itemid)){
			if(!ACYMAILING_J16){
				$completeSec = $article->sectionid;
				if(!empty($article->secalias)) $completeSec .= ':'.$article->secalias;
				if($this->params->get('integration') == 'flexicontent' && class_exists('FlexicontentHelperRoute')){
					$link = FlexicontentHelperRoute::getItemRoute($completeId, $completeCat, $completeSec);
				}else{
					$link = ContentHelperRoute::getArticleRoute($completeId, $completeCat, $completeSec);
				}
			}else{
				if($this->params->get('integration') == 'flexicontent' && class_exists('FlexicontentHelperRoute')){
					$link = FlexicontentHelperRoute::getItemRoute($completeId, $completeCat);
				}else{
					$link = ContentHelperRoute::getArticleRoute($completeId, $completeCat);
				}
			}
		}else{
			$link = 'index.php?option=com_content&view=article&id='.$completeId.'&catid='.$completeCat;
		}


		if($this->params->get('integration') == 'flexicontent' && !class_exists('FlexicontentHelperRoute')){
			$link = 'index.php?option=com_flexicontent&view=items&id='.$completeId;
		}elseif($this->params->get('integration') == 'jaggyblog'){
			$link = 'index.php?option=com_jaggyblog&task=viewpost&id='.$completeId;
		}

		if(!empty($tag->itemid)) $link .= '&Itemid='.$tag->itemid;

		if(!empty($tag->lang)) $link .= (strpos($link, '?') ? '&' : '?').'lang='.substr($tag->lang, 0, strpos($tag->lang, ACYMAILING_J16 ? '-' : ','));
		if(!empty($tag->autologin)) $link .= (strpos($link, '?') ? '&' : '?').'user={usertag:username|urlencode}&passw={usertag:password|urlencode}';

		if(empty($tag->lang) && !empty($article->language) && $article->language != '*'){
			if(!isset($this->langcodes[$article->language])){
				$this->db->setQuery('SELECT sef FROM #__languages WHERE lang_code = '.$this->db->Quote($article->language).' ORDER BY `published` DESC LIMIT 1');
				$this->langcodes[$article->language] = $this->db->loadResult();
				if(empty($this->langcodes[$article->language])) $this->langcodes[$article->language] = $article->language;
			}
			$link .= (strpos($link, '?') ? '&' : '?').'lang='.$this->langcodes[$article->language];
		}

		$link = acymailing_frontendLink($link);
		$varFields['{link}'] = $link;

		$afterTitle = '';
		$afterArticle = '';
		$contentText = '';
		$pictPath = '';

		if(!empty($tag->author)){
			$authorName = empty($article->created_by_alias) ? $article->authorname : $article->created_by_alias;
			if($tag->type == 'title') $afterTitle .= '<br />';
			$afterTitle .= '<span class="authorname">'.$authorName.'</span><br />';
		}

		$dateFormat = empty($tag->dateformat) ? JText::_('DATE_FORMAT_LC2') : $tag->dateformat;
		if(!empty($tag->created)){
			if($tag->type == 'title') $afterTitle .= '<br />';
			$varFields['{createddate}'] = JHTML::_('date', $article->created, $dateFormat);
			$afterTitle .= '<span class="createddate">'.$varFields['{createddate}'].'</span><br />';
		}

		if(!empty($tag->modified)){
			if($tag->type == 'title') $afterTitle .= '<br />';
			$varFields['{modifieddate}'] = JHTML::_('date', $article->modified, $dateFormat);
			$afterTitle .= '<span class="modifieddate">'.$varFields['{modifieddate}'].'</span><br />';
		}

		if(!isset($tag->pict) && $tag->type != 'title'){
			if($this->params->get('removepictures', 'never') == 'always' || ($this->params->get('removepictures', 'never') == 'intro' && $tag->type == "intro")){
				$tag->pict = 0;
			}else{
				$tag->pict = 1;
			}
		}

		if(strpos($article->introtext, 'jseblod') !== false && file_exists(ACYMAILING_ROOT.'plugins'.DS.'content'.DS.'cckjseblod.php')){
			global $mainframe;
			include_once(ACYMAILING_ROOT.'plugins'.DS.'content'.DS.'cckjseblod.php');
			if(function_exists('plgContentCCKjSeblod')){
				$paramsContent = JComponentHelper::getParams('com_content');
				$article->text = $article->introtext.$article->fulltext;
				plgContentCCKjSeblod($article, $paramsContent);
				$article->introtext = $article->text;
				$article->fulltext = '';
			}
		}

		if($tag->type != "title"){
			if($tag->type == "intro"){
				$forceReadMore = false;
				$mytag = new stdClass();
				$mytag->wrap = $this->params->get('wordwrap', 0);
				if(empty($article->fulltext)){
					$article->introtext = $this->acypluginsHelper->wrapText($article->introtext, $mytag);
					if(!empty($this->acypluginsHelper->wraped)) $forceReadMore = true;
				}
			}

			if(empty($article->fulltext) || $tag->type != "text"){
				$contentText .= $article->introtext;
			}

			if($tag->type != "intro" && !empty($article->fulltext)){
				if($tag->type != "text" && !empty($article->introtext) && !preg_match('#^<[div|p]#i', trim($article->fulltext))){
					$contentText .= '<br />';
				}
				$contentText .= $article->fulltext;
			}

			$contentText = $this->acypluginsHelper->wrapText($contentText, $tag);
			if(!empty($this->acypluginsHelper->wraped)) $forceReadMore = true;

			if(!empty($tag->clean)){
				$contentText = strip_tags($contentText, '<p><br><span><ul><li><h1><h2><h3><h4><a>');
			}

			if(ACYMAILING_J16 && !empty($article->images) && !empty($tag->pict)){
				$picthtml = '';
				$images = json_decode($article->images);
				$pictVar = ($tag->type == 'intro') ? 'image_intro' : 'image_fulltext';
				$floatVar = ($tag->type == 'intro') ? 'float_intro' : 'float_fulltext';
				if(!empty($images->$pictVar)){
					if($images->$floatVar != 'right'){
						if(empty($tag->format)) $tag->format = 'TOP_LEFT';
						$images->$floatVar = 'left';
					}elseif(empty($tag->format)) $tag->format = 'TOP_RIGHT';
					$style = 'float:'.$images->$floatVar.';padding-'.(($images->$floatVar == 'right') ? 'left' : 'right').':10px;padding-bottom:10px;';
					if(!empty($tag->link) && empty($tag->nopictlink)) $picthtml .= '<a href="'.$link.'" style="text-decoration:none" >';
					$alt = '';
					$altVar = $pictVar.'_alt';
					if(!empty($images->$altVar)) $alt = $images->$altVar;
					$picthtml .= '<img'.(empty($tag->nopictstyle) ? ' style="'.$style.'"' : '').' alt="'.$alt.'" border="0" src="'.JURI::root().$images->$pictVar.'" />';
					$pictPath = JURI::root().$images->$pictVar;
					if(!empty($tag->link) && empty($tag->nopictlink)) $picthtml .= '</a>';
					$varFields['{picthtml}'] = $picthtml;
				}
			}

			$contentText = preg_replace('/^\s*(<img[^>]*>)\s*(?:<br[^>]*>\s*)*/i', '$1', $contentText);

			if(file_exists(JPATH_SITE.DS.'plugins'.DS.'attachments') && empty($tag->noattach)){
				try{
					$query = 'SELECT display_name, url, filename '.'FROM #__attachments '.'WHERE (parent_entity = "article" '.'AND parent_id = '.intval($tag->id).')';
					if(ACYMAILING_J16){
						$query .= ' OR (parent_entity = "category" '.'AND parent_id = '.intval($article->catid).')';
					}
					$this->db->setQuery($query);
					$attachments = $this->db->loadObjectList();
				}catch(Exception $e){
					$attachments = array();
				}

				if(!empty($attachments)){
					$afterArticle .= '<br />'.JText::_('ATTACHED_FILES').' :';
					foreach($attachments as $oneAttachment){
						$afterArticle .= '<br /><a href="'.$oneAttachment->url.'">'.(empty($oneAttachment->display_name) ? $oneAttachment->filename : $oneAttachment->display_name).'</a>';
					}
				}
			}

			if(!empty($tag->share)){
				$links = array();
				$shareOpt = explode(',', $tag->share);
				foreach($shareOpt as $socialNetwork){
					$knownNetwork = true;
					$socialNetwork = strtolower(trim($socialNetwork));
					if($socialNetwork == 'facebook'){
						$linkShare = 'http://www.facebook.com/sharer.php?u='.urlencode($link).'&t='.urlencode($article->title);
						$picSrc = (file_exists(ACYMAILING_MEDIA.'plugins'.DS.'facebook.png') ? 'media/com_acymailing/plugins/facebook.png' : 'media/com_acymailing/images/facebookshare.png');
						$altText = 'Facebook';
					}elseif($socialNetwork == 'twitter'){
						$text = JText::sprintf('SHARE_TEXT', $link);
						$linkShare = 'http://twitter.com/home?status='.urlencode($text);
						$picSrc = (file_exists(ACYMAILING_MEDIA.'plugins'.DS.'twitter.png') ? 'media/com_acymailing/plugins/twitter.png' : 'media/com_acymailing/images/twittershare.png');
						$altText = 'Twitter';
					}elseif($socialNetwork == 'linkedin'){
						$linkShare = 'http://www.linkedin.com/shareArticle?mini=true&url='.urlencode($link).'&title='.urlencode($article->title);
						$picSrc = (file_exists(ACYMAILING_MEDIA.'plugins'.DS.'linkedin.png') ? 'media/com_acymailing/plugins/linkedin.png' : 'media/com_acymailing/images/linkedin.png');
						$altText = 'LinkedIn';
					}elseif($socialNetwork == 'hyves'){
						$linkShare = 'http://www.hyves-share.nl/button/respect/?hc_hint=1&url='.urlencode($link).'&title='.urlencode($article->title);
						$picSrc = (file_exists(ACYMAILING_MEDIA.'plugins'.DS.'hyves.png') ? 'media/com_acymailing/plugins/hyves.png' : 'media/com_acymailing/images/hyvesshare.png');
						$altText = 'Hyves';
					}elseif($socialNetwork == 'google'){
						$linkShare = 'https://plus.google.com/share?url='.urlencode($link);
						$picSrc = (file_exists(ACYMAILING_MEDIA.'plugins'.DS.'google.png') ? 'media/com_acymailing/plugins/google.png' : 'media/com_acymailing/images/google_plusshare.png');
						$altText = 'Google+';
					}elseif($socialNetwork == 'mailto'){
						$linkShare = 'mailto:?subject='.urlencode($article->title).'&body='.urlencode($article->title.' ('.$link.')');
						$picSrc = (file_exists(ACYMAILING_MEDIA.'plugins'.DS.'mailto.png') ? 'media/com_acymailing/plugins/mailto.png' : 'media/com_acymailing/images/mailto.png');
						$altText = 'MailTo';
					}else{
						$knownNetwork = false;
						acymailing_display('Network not found: '.$socialNetwork.'. Availables networks are facebook, twitter, linkedin, hyves, google and mailto.', 'warning');
					}
					if($knownNetwork){
						array_push($links, '<a target="_blank" href="'.$linkShare.'" title="'.JText::sprintf('SOCIAL_SHARE', $altText).'"><img alt="'.$altText.'" src="'.$picSrc.'" /></a>');
					}
				}
				$afterArticle .= '<br />'.(!empty($tag->sharetxt) ? $tag->sharetxt.' ' : '').implode(' ', $links);
			}
		}

		if(!empty($tag->jtags) && version_compare(JVERSION, '3.1.0', '>=')){
			$this->db->setQuery('SELECT t.id, t.alias, t.title FROM #__tags AS t JOIN #__contentitem_tag_map AS m ON t.id = m.tag_id WHERE t.published = 1 AND m.type_alias = "com_content.article" AND m.content_item_id = '.intval($tag->id));
			$tags = $this->db->loadObjectList();
			if(!empty($tags)){
				$afterArticle .= '<br />';
				foreach($tags as $oneTag){
					$afterArticle .= ' <a href="index.php?option=com_tags&view=tag&id='.$oneTag->id.'-'.$oneTag->alias.'">'.$oneTag->title.'</a> ';
				}
			}
		}

		$readMoreText = empty($tag->readmore) ? $this->readmore : $tag->readmore;
		$varFields['{readmore}'] = '<a class="acymailing_readmore_link" style="text-decoration:none;" target="_blank" href="'.$link.'"><span class="acymailing_readmore">'.$readMoreText.'</span></a>';

		if($tag->type == "intro" && empty($tag->noreadmore) && (!empty($article->fulltext) || $forceReadMore)){
			if(!empty($afterArticle)) $afterArticle .= '<br />';
			$afterArticle .= $varFields['{readmore}'];
		}

		$format = new stdClass();
		$format->tag = $tag;
		$format->title = empty($tag->notitle) ? $article->title : '';
		$format->afterTitle = $afterTitle;
		$format->afterArticle = $afterArticle;
		$format->imagePath = $pictPath;
		$format->description = $contentText;
		$format->link = empty($tag->link) ? '' : $link;
		$format->cols = 2;
		$result = $this->acypluginsHelper->getStandardDisplay($format);

		if(!empty($tag->theme)){
			if(preg_match('#<img[^>]*>#Uis', $article->introtext.$article->fulltext, $pregresult)){
				$cleanContent = strip_tags($result, '<p><br><span><ul><li><h1><h2><h3><h4><a>');
				$tdwidth = (empty($tag->maxwidth) ? $this->params->get('maxwidth', 150) : $tag->maxwidth) + 20;
				$result = '<table cellspacing="0" width="500" cellpadding="0" border="0" ><tr><td class="contentpicture" width="'.$tdwidth.'" valign="top" align="center"><a href="'.$link.'" target="_blank" style="border:0px;text-decoration:none">'.$pregresult[0].'</a></td><td class="contenttext">'.$cleanContent.'</td></tr></table>';
			}
		}

		if($tag->type != 'title') $result = '<div class="acymailing_content">'.$result.'</div>';

		if(!(empty($tag->cattitle) && empty($tag->catpict)) && ((!strpos($article->catid, ',') && $this->currentcatid != $article->catid) || (strpos($article->catid, ',') && !in_array($this->currentcatid, explode(',', $article->catid))))){
			if(strpos($article->catid, ',')){
				$catids = explode(',', $article->catid);
				$this->currentcatid = $catids[0];
			}else{
				$this->currentcatid = $article->catid;
			}

			if(ACYMAILING_J16){
				$params = json_decode($article->catparams);
				$article->catpict = $params->image;
			}

			$resultTitle = $article->cattitle;

			if(!empty($tag->catpict) && !empty($article->catpict)){
				$style = '';
				if(!empty($tag->catmaxwidth)) $style .= 'max-width:'.intval($tag->catmaxwidth).'px;';
				if(!empty($tag->catmaxheight)) $style .= 'max-height:'.intval($tag->catmaxheight).'px;';
				$resultTitle = '<img'.(empty($style) ? '' : ' style="'.$style.'"').' alt="" src="'.$article->catpict.'" />';
				if(!empty($tag->cattitlelink)) $resultTitle = '<a href="index.php?option=com_content&view=category&id='.$this->currentcatid.'">'.$resultTitle.'</a>';
			}else{
				if(!empty($tag->cattitlelink)) $resultTitle = '<a href="index.php?option=com_content&view=category&id='.$this->currentcatid.'">'.$resultTitle.'</a>';
				$resultTitle = '<h3 class="cattitle">'.$resultTitle.'</h3>';
			}

			$result = $resultTitle.$result;
		}

		if($oldFormat){
			if(file_exists(ACYMAILING_MEDIA.'plugins'.DS.'tagcontent_html.php')){
				ob_start();
				require(ACYMAILING_MEDIA.'plugins'.DS.'tagcontent_html.php');
				$result = ob_get_clean();
			}elseif(file_exists(ACYMAILING_MEDIA.'plugins'.DS.'tagcontent.php')){
				ob_start();
				require(ACYMAILING_MEDIA.'plugins'.DS.'tagcontent.php');
				$result = ob_get_clean();
			}
		}elseif(!empty($tag->template) && file_exists(ACYMAILING_MEDIA.'plugins'.DS.$tag->template)){
			ob_start();
			require(ACYMAILING_MEDIA.'plugins'.DS.$tag->template);
			$result = ob_get_clean();
		}
		$result = str_replace(array_keys($varFields), $varFields, $result);

		$result = $this->acypluginsHelper->removeJS($result);
		$result = $this->acypluginsHelper->replaceVideos($result);

		$tag->maxheight = empty($tag->maxheight) ? $this->params->get('maxheight', 150) : $tag->maxheight;
		$tag->maxwidth = empty($tag->maxwidth) ? $this->params->get('maxwidth', 150) : $tag->maxwidth;
		$result = $this->acypluginsHelper->managePicts($tag, $result);

		if(!empty($tag->maxchar) && strlen(strip_tags($result)) > $tag->maxchar){
			$result = strip_tags($result);
			for($i = $tag->maxchar; $i > 0; $i--){
				if($result[$i] == ' ') break;
			}
			if(!empty($i)) $result = substr($result, 0, $i).@$tag->textafter;
		}

		return $result;
	}

	private function _replaceAuto(&$email){
		$this->acymailing_generateautonews($email);
		if(empty($this->tags)) return;
		$this->acypluginsHelper->replaceTags($email, $this->tags, true);
	}

	public function acymailing_generateautonews(&$email){
		$time = time();

		$tags = $this->acypluginsHelper->extractTags($email, 'autocontent');
		$return = new stdClass();
		$return->status = true;
		$return->message = '';
		$this->tags = array();

		if(empty($tags)) return $return;

		foreach($tags as $oneTag => $parameter){
			if(isset($this->tags[$oneTag])) continue;
			$allcats = explode('-', $parameter->id);
			$selectedArea = array();
			foreach($allcats as $oneCat){
				if(!ACYMAILING_J16){
					$sectype = substr($oneCat, 0, 3);
					$num = substr($oneCat, 3);
					if(empty($num)) continue;
					if($sectype == 'cat'){
						$selectedArea[] = 'catid = '.(int)$num;
					}elseif($sectype == 'sec'){
						$selectedArea[] = 'sectionid = '.(int)$num;
					}
				}else{
					if(empty($oneCat)) continue;
					$selectedArea[] = intval($oneCat);
				}
			}

			$query = 'SELECT a.id FROM `#__content` as a ';
			$where = array();

			if(!empty($parameter->tags) && version_compare(JVERSION, '3.1.0', '>=')){
				$tagsArray = explode(',', $parameter->tags);
				JArrayHelper::toInteger($tagsArray);
				if(!empty($tagsArray)){
					foreach($tagsArray as $oneTagId){
						$query .= 'JOIN #__contentitem_tag_map AS tagsmap'.$oneTagId.' ON (a.id = tagsmap'.$oneTagId.'.content_item_id AND tagsmap'.$oneTagId.'.type_alias LIKE "com_content.article" AND tagsmap'.$oneTagId.'.tag_id = '.$oneTagId.') ';
					}
				}
			}

			if(!empty($parameter->featured)){
				if(ACYMAILING_J16){
					$where[] = 'a.featured = 1';
				}else{
					$query .= 'JOIN `#__content_frontpage` as b ON a.id = b.content_id ';
					$where[] = 'b.content_id IS NOT NULL';
				}
			}

			if(!empty($parameter->nofeatured)){
				if(ACYMAILING_J16){
					$where[] = 'a.featured = 0';
				}else{
					$query .= 'LEFT JOIN `#__content_frontpage` as b ON a.id = b.content_id ';
					$where[] = 'b.content_id IS NULL';
				}
			}

			if(ACYMAILING_J16 && !empty($parameter->subcats) && !empty($selectedArea)){
				$this->db->setQuery('SELECT lft,rgt FROM #__categories WHERE id IN ('.implode(',', $selectedArea).')');
				$catinfos = $this->db->loadObjectList();
				if(!empty($catinfos)){
					$whereCats = array();
					foreach($catinfos as $onecat){
						$whereCats[] = 'lft > '.$onecat->lft.' AND rgt < '.$onecat->rgt;
					}
					$this->db->setQuery('SELECT id FROM #__categories WHERE ('.implode(') OR (', $whereCats).')');
					$othercats = acymailing_loadResultArray($this->db);
					$selectedArea = array_merge($selectedArea, $othercats);
				}
			}

			if(!empty($selectedArea)){
				if(!ACYMAILING_J16){
					$where[] = implode(' OR ', $selectedArea);
				}else{
					$filter_cat = '`catid` IN ('.implode(',', $selectedArea).')';
					if(file_exists(JPATH_SITE.DS.'components'.DS.'com_multicats')){
						$filter_cat = '`catid` REGEXP "^([0-9]+,)*'.implode('(,[0-9]+)*$" OR `catid` REGEXP "^([0-9]+,)*', $selectedArea).'(,[0-9]+)*$"';
					}
					$where[] = $filter_cat;
				}
			}

			if(!empty($parameter->excludedcats)){
				$excludedCats = explode('-', $parameter->excludedcats);
				JArrayHelper::toInteger($excludedCats);
				$filter_cat = '`catid` NOT IN ("'.implode('","', $excludedCats).'")';
				if(file_exists(JPATH_SITE.DS.'components'.DS.'com_multicats')){
					$filter_cat = '`catid` NOT REGEXP "^([0-9]+,)*'.implode('(,[0-9]+)*$" AND `catid` NOT REGEXP "^([0-9]+,)*', $excludedCats).'(,[0-9]+)*$"';
				}
				$where[] = $filter_cat;
			}

			if(!empty($parameter->filter) && !empty($email->params['lastgenerateddate'])){
				$condition = '(`publish_up` > \''.date('Y-m-d H:i:s', $email->params['lastgenerateddate'] - date('Z')).'\' AND `publish_up` < \''.date('Y-m-d H:i:s', $time - date('Z')).'\')';
				$condition .= ' OR (`created` > \''.date('Y-m-d H:i:s', $email->params['lastgenerateddate'] - date('Z')).'\' AND `created` < \''.date('Y-m-d H:i:s', $time - date('Z')).'\')';
				if($parameter->filter == 'modify'){
					$modify = '(`modified` > \''.date('Y-m-d H:i:s', $email->params['lastgenerateddate'] - date('Z')).'\' AND `modified` < \''.date('Y-m-d H:i:s', $time - date('Z')).'\')';
					if(!empty($parameter->maxpublished)) $modify = '('.$modify.' AND `publish_up` > \''.date('Y-m-d H:i:s', time() - date('Z') - ((int)$parameter->maxpublished * 60 * 60 * 24)).'\')';
					$condition .= ' OR '.$modify;
				}

				$where[] = $condition;
			}

			if(!empty($parameter->maxcreated)){
				$date = $parameter->maxcreated;
				if(strpos($parameter->maxcreated, '[time]') !== false) $date = acymailing_replaceDate(str_replace('[time]', '{time}', $parameter->maxcreated));
				if(!is_numeric($date)) $date = strtotime($parameter->maxcreated);
				if(empty($date)){
					acymailing_display('Wrong date format ('.$parameter->maxcreated.' in '.$oneTag.'), please use YYYY-MM-DD', 'warning');
				}
				$where[] = '`created` < '.$this->db->Quote(date('Y-m-d H:i:s', $date)).' OR `publish_up` < '.$this->db->Quote(date('Y-m-d H:i:s', $date));
			}else{
				$where[] = '`publish_up` < \''.date('Y-m-d H:i:s', $time - date('Z')).'\'';
			}

			if(!empty($parameter->mincreated)){
				$date = $parameter->mincreated;
				if(strpos($parameter->mincreated, '[time]') !== false) $date = acymailing_replaceDate(str_replace('[time]', '{time}', $parameter->mincreated));
				if(!is_numeric($date)) $date = strtotime($parameter->mincreated);
				if(empty($date)){
					acymailing_display('Wrong date format ('.$parameter->mincreated.' in '.$oneTag.'), please use YYYY-MM-DD', 'warning');
				}
				$where[] = '`created` > '.$this->db->Quote(date('Y-m-d H:i:s', $date)).' OR `publish_up` > '.$this->db->Quote(date('Y-m-d H:i:s', $date));
			}


			if(!empty($parameter->meta)){
				$allMetaTags = explode(',', $parameter->meta);
				$metaWhere = array();
				foreach($allMetaTags as $oneMeta){
					if(empty($oneMeta)) continue;
					$metaWhere[] = "`metakey` LIKE '%".acymailing_getEscaped($oneMeta, true)."%'";
				}
				if(!empty($metaWhere)) $where[] = implode(' OR ', $metaWhere);
			}

			$where[] = '`publish_down` > \''.date('Y-m-d H:i:s', $time - date('Z')).'\' OR `publish_down` = 0';
			if(empty($parameter->unpublished)){
				$where[] = 'state = 1';
			}else{
				$where[] = 'state = 0';
			}

			if(!ACYMAILING_J16){
				if(isset($parameter->access)){
					$where[] = 'access <= '.intval($parameter->access);
				}else{
					if($this->params->get('contentaccess', 'registered') == 'registered'){
						$where[] = 'access <= 1';
					}elseif($this->params->get('contentaccess', 'registered') == 'public') $where[] = 'access = 0';
				}
			}elseif(isset($parameter->access)){
				if(strpos($parameter->access, ',')){
					$allAccess = explode(',', $parameter->access);
					JArrayHelper::toInteger($allAccess);
					$where[] = 'access IN ('.implode(',', $allAccess).')';
				}else{
					$where[] = 'access = '.intval($parameter->access);
				}
			}

			if(ACYMAILING_J16 && !empty($parameter->language)){
				$allLanguages = explode(',', $parameter->language);
				$langWhere = 'language IN (';
				foreach($allLanguages as $oneLanguage){
					$langWhere .= $this->db->Quote(trim($oneLanguage)).',';
				}
				$where[] = trim($langWhere, ',').')';
			}

			$query .= ' WHERE ('.implode(') AND (', $where).')';
			if(!empty($parameter->order)){
				$ordering = explode(',', $parameter->order);
				if($ordering[0] == 'rand'){
					$query .= ' ORDER BY rand()';
				}else{
					$query .= ' ORDER BY `'.acymailing_secureField($ordering[0]).'` '.acymailing_secureField($ordering[1]).' , a.`id` DESC';
				}
			}

			$start = '';
			if(!empty($parameter->start)) $start = intval($parameter->start).',';

			if(empty($parameter->max)) $parameter->max = 100;

			$query .= ' LIMIT '.$start.(int)$parameter->max;

			$this->db->setQuery($query);
			$allArticles = acymailing_loadResultArray($this->db);

			if(!empty($parameter->min) && count($allArticles) < $parameter->min){
				$return->status = false;
				$return->message = 'Not enough articles for the tag '.$oneTag.' : '.count($allArticles).' / '.$parameter->min.' between '.acymailing_getDate($email->params['lastgenerateddate']).' and '.acymailing_getDate($time);
			}

			$stringTag = empty($parameter->noentrytext) ? '' : $parameter->noentrytext;
			if(!empty($allArticles)){
				if(file_exists(ACYMAILING_MEDIA.'plugins'.DS.'autocontent.php')){
					ob_start();
					require(ACYMAILING_MEDIA.'plugins'.DS.'autocontent.php');
					$stringTag = ob_get_clean();
				}else{
					$arrayElements = array();
					$numArticle = 1;
					foreach($allArticles as $oneArticleId){
						$args = array();
						$args[] = 'joomlacontent:'.$oneArticleId;
						$args[] = 'num:'.$numArticle++;
						if(!empty($parameter->invert) && $numArticle % 2 == 1) $args[] = 'invert';
						if(!empty($parameter->type)) $args[] = 'type:'.$parameter->type;
						if(!empty($parameter->format)) $args[] = 'format:'.$parameter->format;
						if(!empty($parameter->template)) $args[] = 'template:'.$parameter->template;
						if(!empty($parameter->jtags)) $args[] = 'jtags';
						if(!empty($parameter->link)) $args[] = 'link';
						if(!empty($parameter->author)) $args[] = 'author';
						if(!empty($parameter->autologin)) $args[] = 'autologin';
						if(!empty($parameter->cattitle)) $args[] = 'cattitle';
						if(!empty($parameter->cattitlelink)) $args[] = 'cattitlelink';
						if(!empty($parameter->lang)) $args[] = 'lang:'.$parameter->lang;
						if(!empty($parameter->theme)) $args[] = 'theme';
						if(!empty($parameter->clean)) $args[] = 'clean';
						if(!empty($parameter->notitle)) $args[] = 'notitle';
						if(!empty($parameter->nopictstyle)) $args[] = 'nopictstyle';
						if(!empty($parameter->nopictlink)) $args[] = 'nopictlink';
						if(!empty($parameter->created)) $args[] = 'created';
						if(!empty($parameter->noattach)) $args[] = 'noattach';
						if(!empty($parameter->itemid)) $args[] = 'itemid:'.$parameter->itemid;
						if(!empty($parameter->noreadmore)) $args[] = 'noreadmore';
						if(isset($parameter->pict)) $args[] = 'pict:'.$parameter->pict;
						if(!empty($parameter->wrap)) $args[] = 'wrap:'.$parameter->wrap;
						if(!empty($parameter->maxwidth)) $args[] = 'maxwidth:'.$parameter->maxwidth;
						if(!empty($parameter->maxheight)) $args[] = 'maxheight:'.$parameter->maxheight;
						if(!empty($parameter->readmore)) $args[] = 'readmore:'.$parameter->readmore;
						if(!empty($parameter->dateformat)) $args[] = 'dateformat:'.$parameter->dateformat;
						if(!empty($parameter->textafter)) $args[] = 'textafter:'.$parameter->textafter;
						if(!empty($parameter->maxchar)) $args[] = 'maxchar:'.$parameter->maxchar;
						if(!empty($parameter->share)) $args[] = 'share:'.$parameter->share;
						if(!empty($parameter->sharetxt)) $args[] = 'sharetxt:'.$parameter->sharetxt;
						if(!empty($parameter->catpict)) $args[] = 'catpict';
						if(!empty($parameter->catmaxwidth)) $args[] = 'catmaxwidth:'.$parameter->catmaxwidth;
						if(!empty($parameter->catmaxheight)) $args[] = 'catmaxheight:'.$parameter->catmaxheight;
						$arrayElements[] = '{'.implode('|', $args).'}';
					}
					$stringTag = $this->acypluginsHelper->getFormattedResult($arrayElements, $parameter);
				}
			}
			$this->tags[$oneTag] = $stringTag;
		}

		return $return;
	}
}//endclass
tagcontent/tagcontent.xml000064400000020433152345456710011620 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing Tag : content insertion</name>
	<creationDate>September 2009</creationDate>
	<version>3.7.0</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This AcyMailing plugin enables you to include Joomla Articles in any e-mail sent by AcyMailing</description>
	<files>
		<filename plugin="tagcontent">tagcontent.php</filename>
		<filename>tagcontent.xml</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-tagcontent"/>
		<param name="customtemplate" type="customtemplate" label="Custom template" description="Click on the Custom template button to create a custom layout that will override the default view" default="tagcontent"/>
		<param name="displayart" type="radio" default="all" label="Display articles" description="Select if you want to display all articles in the popup for article selection or only published articles">
			<option value="all">All articles</option>
			<option value="onlypub">Only published articles</option>
		</param>
		<param name="contentaccess" type="radio" default="registered" label="Content Access" description="If you use the automatic article insertion (via the categories tab), AcyMailing will only include articles having the selected access in your Newsletter">
			<option value="public">Public only</option>
			<option value="registered">Public and Registered</option>
			<option value="all">All</option>
		</param>
		<param name="frontendaccess" type="list" default="all" label="Front-end Access" description="Using AcyMailing Enterprise, you can restrict the access to this tag system">
			<option value="all">Display all articles</option>
			<option value="author">Display only author's articles</option>
			<option value="none">Don't display this tag system on the front-end</option>
		</param>
		<param name="metaselect" type="radio" default="0" label="Select articles by meta tags" description="Do you want to display an interface on the content category insertion to filter articles by meta tags? Meta tags must be separated by a comma.">
			<option value="0">JOOMEXT_NO</option>
			<option value="1">JOOMEXT_YES</option>
		</param>
		<param name="integration" type="radio" default="0" label="Act for another component" description="Some Joomla components use the content table to store their articles. This option enables you to make sure Acy will act for this third part component and not for the default Joomla content system" >
			<option value="0">Joomla content</option>
			<option value="jreviews">jReviews</option>
			<option value="flexicontent">FlexiContent</option>
			<option value="jaggyblog">JaggyBlog</option>
		</param>
		<param name="@spacer" type="spacer" default="" label="" description="" />
		<param name="default_type" type="radio" default="intro" label="DISPLAY" description="FIELD_DEFAULT">
			<option value="title">TITLE_ONLY</option>
			<option value="intro">INTRO_ONLY</option>
			<option value="text">FIELD_TEXT</option>
			<option value="full">FULL_TEXT</option>
		</param>
		<param name="wordwrap" type="text" size="10" default="0" label="Intro Word Wrapping" description="If you insert only the introduction and you didn't insert the read more link, AcyMailing will only load the first XX characters of your content. If you specify 0, AcyMailing won't wrap your content" />
		<param name="default_titlelink" type="radio" default="link" label="CLICKABLE_TITLE" description="FIELD_DEFAULT">
			<option value="link">JOOMEXT_YES</option>
			<option value="0">JOOMEXT_NO</option>
		</param>
		<param name="default_author" type="radio" default="0" label="AUTHOR_NAME" description="FIELD_DEFAULT">
			<option value="author">JOOMEXT_YES</option>
			<option value="0">JOOMEXT_NO</option>
		</param>
		<param name="default_pict" type="radio" default="1" label="DISPLAY_PICTURES" description="FIELD_DEFAULT">
			<option value="1">JOOMEXT_YES</option>
			<option value="resized">RESIZED</option>
			<option value="0">JOOMEXT_NO</option>
		</param>
		<param name="maxwidth" type="text" size="10" default="150" label="Max picture width" description="FIELD_DEFAULT" />
		<param name="maxheight" type="text" size="10" default="150" label="Max picture height" description="FIELD_DEFAULT" />

	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-tagcontent"/>
				<field name="customtemplate" type="customtemplate" label="Custom template" description="Click on the Custom template button to create a custom layout that will override the default view" default="tagcontent"/>
				<field name="displayart" type="radio" default="all" label="Display articles" description="Select if you want to display all articles in the popup for article selection or only published articles">
					<option value="all">All articles</option>
					<option value="onlypub">Only published articles</option>
				</field>
				<field name="frontendaccess" type="list" default="all" label="Front-end Access" description="Using AcyMailing Enterprise, you can restrict the access to this tag system">
					<option value="all">Display all articles</option>
					<option value="author">Display only author's articles</option>
					<option value="none">Don't display this tag system on the front-end</option>
				</field>
				<field name="metaselect" type="radio" default="0" label="Select articles by meta tags" description="Do you want to display an interface on the content category insertion to filter articles by meta tags? Meta tags must be separated by a comma.">
					<option value="0">No</option>
					<option value="1">Yes</option>
				</field>
				<field name="integration" type="radio" default="0" label="Act for another component" description="Some Joomla components use the content table to store their articles. This option enables you to make sure Acy will act for this third part component and not for the default Joomla content system" >
					<option value="0">Joomla content</option>
					<option value="jreviews">jReviews</option>
					<option value="flexicontent">FlexiContent</option>
					<option value="jaggyblog">JaggyBlog</option>
				</field>
				<field name="@spacer" type="spacer" default="" label="" description="" />
				<field name="default_type" type="radio" default="intro" label="DISPLAY" description="FIELD_DEFAULT">
					<option value="title">TITLE_ONLY</option>
					<option value="intro">INTRO_ONLY</option>
					<option value="text">FIELD_TEXT</option>
					<option value="full">FULL_TEXT</option>
				</field>
				<field name="wordwrap" type="text" size="10" default="0" label="Intro Word Wrapping" description="If you insert only the introduction and you didn't insert the read more link, AcyMailing will only load the first XX characters of your content. If you specify 0, AcyMailing won't wrap your content" />
				<field name="default_titlelink" type="radio" default="link" label="CLICKABLE_TITLE" description="FIELD_DEFAULT">
					<option value="link">JOOMEXT_YES</option>
					<option value="0">JOOMEXT_NO</option>
				</field>
				<field name="default_author" type="radio" default="" label="AUTHOR_NAME" description="FIELD_DEFAULT">
					<option value="author">JOOMEXT_YES</option>
					<option value="">JOOMEXT_NO</option>
				</field>
				<field name="default_pict" type="radio" default="1" label="DISPLAY_PICTURES" description="FIELD_DEFAULT">
					<option value="1">JOOMEXT_YES</option>
					<option value="resized">RESIZED</option>
					<option value="0">JOOMEXT_NO</option>
				</field>
				<field name="maxwidth" type="text" size="10" default="150" label="Max picture width" description="FIELD_DEFAULT" />
				<field name="maxheight" type="text" size="10" default="150" label="Max picture height" description="FIELD_DEFAULT" />
			</fieldset>
		</fields>
	</config>
</extension>
tagsubscriber/index.html000064400000000054152345456710011413 0ustar00<html><body bgcolor="#FFFFFF"></body></html>tagsubscriber/tagsubscriber.php000064400000044545152345456710013003 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

class plgAcymailingTagsubscriber extends JPlugin{

	var $fields = array();

	function __construct(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'tagsubscriber');
			$this->params = new acyParameter($plugin->params);
		}
	}

	function acymailing_getPluginType(){
		$app = JFactory::getApplication();
		if($this->params->get('frontendaccess') == 'none' && !$app->isAdmin()) return;
		$onePlugin = new stdClass();
		$onePlugin->name = JText::_('SUBSCRIBER_SUBSCRIBER');
		$onePlugin->function = 'acymailingtagsubscriber_show';
		$onePlugin->help = 'plugin-tagsubscriber';

		return $onePlugin;
	}

	function acymailingtagsubscriber_show(){
		$fields = acymailing_getColumns('#__acymailing_subscriber');

		$descriptions['subid'] = JText::_('SUBSCRIBER_ID');
		$descriptions['email'] = JText::_('SUBSCRIBER_EMAIL');
		$descriptions['name'] = JText::_('SUBSCRIBER_NAME');
		$descriptions['userid'] = JText::_('SUBSCRIBER_USERID');
		$descriptions['ip'] = JText::_('SUBSCRIBER_IP');
		$descriptions['created'] = JText::_('SUBSCRIBER_CREATED');
		echo '<br style="clear:both;"/>';
		if(JRequest::getVar('type') == 'notification'){
			$text = '<div class="onelineblockoptions">
						<span class="acyblocktitle">'.JText::_('CURRENT_USER_INFO').'</span>
						<table class="acymailing_table" cellpadding="1">';
			$k = 0;
			foreach($fields as $fieldname => $oneField){
				if(!isset($descriptions[$fieldname]) AND $oneField == 'tinyint') continue;
				if(empty($descriptions[$fieldname])) $descriptions[$fieldname] = '';

				$type = '';
				if(in_array($fieldname, array('created', 'confirmed_date', 'lastclick_date', 'lastsent_date', 'lastopen_date'))) $type = '|type:time';
				$text .= '<tr style="cursor:pointer" class="row'.$k.'" onclick="setTag(\'{user:'.$fieldname.$type.'}\');insertTag();" ><td class="acytdcheckbox"></td><td>'.$fieldname.'</td><td>'.$descriptions[$fieldname].'</td></tr>';
				$k = 1 - $k;
			}
			$text .= '</table></div>';
			echo $text;
		}

		$text = '<div class="onelineblockoptions">
					<span class="acyblocktitle">'.JText::_('RECEIVER_INFORMATION').'</span>
					<table class="acymailing_table" cellpadding="1">';

		$others = array();
		$others['{subtag:name|part:first|ucfirst}'] = array('name' => JText::_('SUBSCRIBER_FIRSTPART'), 'desc' => JText::_('SUBSCRIBER_FIRSTPART').' '.JText::_('SUBSCRIBER_FIRSTPART_DESC'));
		$others['{subtag:name|part:last|ucfirst}'] = array('name' => JText::_('SUBSCRIBER_LASTPART'), 'desc' => JText::_('SUBSCRIBER_LASTPART').' '.JText::_('SUBSCRIBER_LASTPART_DESC'));

		$k = 0;

		foreach($others as $tagname => $tag){
			$text .= '<tr style="cursor:pointer" class="row'.$k.'" onclick="setTag(\''.$tagname.'\');insertTag();" ><td class="acytdcheckbox"></td><td>'.$tag['name'].'</td><td>'.$tag['desc'].'</td></tr>';
			$k = 1 - $k;
		}

		foreach($fields as $fieldname => $oneField){
			if(!isset($descriptions[$fieldname]) AND $oneField == 'tinyint') continue;
			if(empty($descriptions[$fieldname])) $descriptions[$fieldname] = '';

			$type = '';
			if(in_array($fieldname, array('created', 'confirmed_date', 'lastclick_date', 'lastopen_date', 'lastsent_date'))) $type = '|type:time';
			$text .= '<tr style="cursor:pointer" class="row'.$k.'" onclick="setTag(\'{subtag:'.$fieldname.$type.'}\');insertTag();" ><td class="acytdcheckbox"></td><td>'.$fieldname.'</td><td>'.$descriptions[$fieldname].'</td></tr>';
			$k = 1 - $k;
		}

		$text .= '</table></div>';

		echo $text;
	}

	function acymailing_replaceusertags(&$email, &$user, $send = true){
		$this->pluginsHelper = acymailing_get('helper.acyplugins');
		$extractedTags = $this->pluginsHelper->extractTags($email, 'subtag');
		if(empty($extractedTags)) return;

		$tags = array();
		foreach($extractedTags as $i => $oneTag){
			if(isset($tags[$i])) continue;
			$tags[$i] = $this->replaceSubTag($oneTag, $user);
		}

		$this->pluginsHelper->replaceTags($email, $tags);
	}

	private function replaceSubTag(&$mytag, $user){
		if(!empty($mytag->juser)){
			$subClass = acymailing_get('class.subscriber');
			if(strpos($mytag->juser, '@') !== false){
				$userTmp = $subClass->get($mytag->juser);
			}else{
				$db = JFactory::getDBO();
				$query = "SELECT * FROM #__users WHERE username= ".$db->quote($mytag->juser);
				$db->setQuery($query);
				$JuserTmp = $db->loadObject();
				if(!empty($JuserTmp->email)) $userTmp = $subClass->get($JuserTmp->email);
			}
			$app = JFactory::getApplication();
			if(!empty($userTmp)){
				$user = $userTmp;
			}else $app->enqueueMessage('User not found for tag juser', 'warning');
		}

		$field = $mytag->id;
		if(empty($mytag->titlevalue)){
			$replaceme = (isset($user->$field) && strlen($user->$field) > 0) ? $user->$field : $mytag->default;
		}else{
			$fieldClass = acymailing_get('class.fields');
			if(!isset($this->fields[$field])){
				$this->fields[$field] = $fieldClass->get($field);
			}
			$replaceme = (isset($user->$field) && strlen($user->$field) > 0 && !empty($this->fields[$field]->value[$user->$field]->value)) ? $fieldClass->trans($this->fields[$field]->value[$user->$field]->value) : $mytag->default;
		}
		$replaceme = nl2br($replaceme);

		$this->pluginsHelper->formatString($replaceme, $mytag);

		return $replaceme;
	}

	function onAcyDisplayFilters(&$type, $context = "massactions"){

		if($this->params->get('displayfilter_'.$context, true) == false) return;

		$db = JFactory::getDBO();
		$fields = acymailing_getColumns('#__acymailing_subscriber');
		if(empty($fields)) return;

		$field = array();
		$field[] = JHTML::_('select.option', 0, '- - -');
		foreach($fields as $oneField => $fieldType){
			$field[] = JHTML::_('select.option', $oneField, $oneField);
		}
		$type['acymailingfield'] = JText::_('ACYMAILING_FIELD');

		$jsOnChange = "displayCondFilter('displaySubscriberValues', 'toChange__num__',__num__,'map='+document.getElementById('filter__num__acymailingfieldmap').value+'&cond='+document.getElementById('filter__num__acymailingfieldoperator').value+'&value='+document.getElementById('filter__num__acymailingfieldvalue').value); ";

		$operators = acymailing_get('type.operators');
		$operators->extra = 'onchange="'.$jsOnChange.'"';

		$return = '<div id="filter__num__acymailingfield">'.JHTML::_('select.genericlist', $field, "filter[__num__][acymailingfield][map]", 'onchange="'.$jsOnChange.'" class="inputbox" size="1"', 'value', 'text');
		$return .= ' '.$operators->display("filter[__num__][acymailingfield][operator]").' <span id="toChange__num__"><input onchange="countresults(__num__)" class="inputbox" type="text" name="filter[__num__][acymailingfield][value]" style="width:200px" value="" id="filter__num__acymailingfieldvalue"></span></div>';

		return $return;
	}

	function onAcyTriggerFct_displaySubscriberValues(){
		$num = JRequest::getInt('num');
		$map = JRequest::getCmd('map');
		$cond = JRequest::getVar('cond', '', '', 'string', JREQUEST_ALLOWHTML);
		$value = JRequest::getVar('value', '', '', 'string', JREQUEST_ALLOWHTML);

		$emptyInputReturn = '<input onchange="countresults('.$num.')" class="inputbox" type="text" name="filter['.$num.'][acymailingfield][value]" id="filter'.$num.'acymailingfieldvalue" style="width:200px" value="'.$value.'">';
		$dateInput = '<input onClick="displayDatePicker(this,event)" onchange="countresults('.$num.')" class="inputbox" type="text" name="filter['.$num.'][acymailingfield][value]" id="filter'.$num.'acymailingfieldvalue" style="width:200px" value="'.$value.'">';

		if(in_array($map, array('created', 'confirmed_date', 'lastopen_date', 'lastclick_date'))) return $dateInput;

		if(empty($map) || $map == 'key' || !in_array($cond, array('=', '!='))) return $emptyInputReturn;

		$db = JFactory::getDBO();
		$query = 'SELECT DISTINCT `'.acymailing_secureField($map).'` AS value FROM #__acymailing_subscriber LIMIT 100';
		$db->setQuery($query);
		$prop = $db->loadObjectList();

		if(empty($prop) || count($prop) >= 100 || (count($prop) == 1 && (empty($prop[0]->value) || $prop[0]->value == '-'))) return $emptyInputReturn;

		return JHTML::_('select.genericlist', $prop, "filter[$num][acymailingfield][value]", 'onchange="countresults('.$num.')" class="inputbox" size="1" style="width:200px"', 'value', 'value', $value, 'filter'.$num.'acymailingfieldvalue');
	}

	function onAcyDisplayFilter_acymailingfield($filter){
		return JText::_('ACYMAILING_FIELD').' : '.$filter['map'].' '.$filter['operator'].' '.$filter['value'];
	}

	function onAcyProcessFilter_acymailingfield(&$query, $filter, $num){
		if(empty($filter['map'])) return;
		$type = '';
		$value = acymailing_replaceDate($filter['value']);

		if(strpos($filter['value'], '{time}') !== false && !in_array($filter['map'], array('created', 'confirmed_date', 'lastclick_date', 'lastopen_date', 'lastsent_date'))){
			$value = strftime('%Y-%m-%d', $value);
		}

		if(in_array($filter['map'], array('created', 'confirmed_date', 'lastclick_date', 'lastopen_date', 'lastsent_date'))){
			if(!is_numeric($value)) $value = strtotime($value);
			$type = 'timestamp';
		}

		$query->where[] = $query->convertQuery('sub', $filter['map'], $filter['operator'], $value, $type);
	}

	function onAcyProcessFilterCount_acymailingfield(&$query, $filter, $num){
		$this->onAcyProcessFilter_acymailingfield($query, $filter, $num);
		return JText::sprintf('SELECTED_USERS', $query->count());
	}

	function onAcyDisplayActions(&$type){
		$type['acymailingfield'] = JText::_('BOUNCE_ACTION');
		$status = array();
		$status[] = JHTML::_('select.option', 'confirm', JText::_('CONFIRM_USERS'));
		$status[] = JHTML::_('select.option', 'unconfirm', JText::_('ACY_ACTION_UNCONFIRM'));
		$status[] = JHTML::_('select.option', 'enable', JText::_('ENABLE_USERS'));
		$status[] = JHTML::_('select.option', 'block', JText::_('BLOCK_USERS'));
		$status[] = JHTML::_('select.option', 'delete', JText::_('DELETE_USERS'));

		$content = '<div id="action__num__acymailingfield">'.JHTML::_('select.genericlist', $status, "action[__num__][acymailingfield][action]", 'class="inputbox" size="1"', 'value', 'text').'</div>';

		if(!acymailing_level(3)) return $content;

		$db = JFactory::getDBO();
		$fields = acymailing_getColumns('#__acymailing_subscriber');
		if(empty($fields)) return $content;

		$field = array();
		$field[] = JHTML::_('select.option', 0, '- - -');
		foreach($fields as $oneField => $fieldType){
			if(in_array($oneField, array('name', 'email', 'subid', 'created', 'ip'))) continue;
			$field[] = JHTML::_('select.option', $oneField, $oneField);
		}

		$jsOnChange = "if(document.getElementById('action__num__acymailingfieldvalvalue')!= undefined){ currentVal=document.getElementById('action__num__acymailingfieldvalvalue').value;} else{currentVal='';}
			displayCondFilter('displayFieldPossibleValues', 'toChangeAction__num__',__num__,'map='+document.getElementById('action__num__acymailingfieldvalmap').value+'&value='+currentVal+'&operator='+document.getElementById('action__num__acymailingfieldvaloperator').value); ";

		$operator = array();
		$operator[] = JHTML::_('select.option', '=', '=');
		$operator[] = JHTML::_('select.option', '+', '+');
		$operator[] = JHTML::_('select.option', '-', '-');
		$operator[] = JHTML::_('select.option', 'addend', JText::_('ACY_OPERATOR_ADDEND'));
		$operator[] = JHTML::_('select.option', 'addbegin', JText::_('ACY_OPERATOR_ADDBEGINNING'));

		$content .= '<div id="action__num__acymailingfieldval">'.JHTML::_('select.genericlist', $field, "action[__num__][acymailingfieldval][map]", 'onchange="'.$jsOnChange.'" class="inputbox" size="1"', 'value', 'text');
		$content .= ' '.JHTML::_('select.genericlist', $operator, "action[__num__][acymailingfieldval][operator]", 'onchange="'.$jsOnChange.'" class="inputbox" size="1" style="width:150px;"', 'value', 'text', '=');
		$content .= ' <span id="toChangeAction__num__"><input class="inputbox" type="text" id="action__num__acymailingfieldvalvalue" name="action[__num__][acymailingfieldval][value]" style="width:200px" value=""></span></div>';

		$type['acymailingfieldval'] = JText::_('SET_SUBSCRIBER_VALUE');

		return $content;
	}

	function onAcyTriggerFct_displayFieldPossibleValues(){
		$num = JRequest::getInt('num');
		$map = JRequest::getCmd('map');
		$value = JRequest::getString('value');
		$operator = JRequest::getString('operator');

		if(in_array($operator, array('addend', 'addbegin'))){
			$emptyInputReturn = '<textarea class="inputbox" type="text" name="action['.$num.'][acymailingfieldval][value]" id="action'.$num.'acymailingfieldvalvalue" style="width:200px">'.$value.'</textarea>';
		}else{
			$emptyInputReturn = '<input class="inputbox" type="text" name="action['.$num.'][acymailingfieldval][value]" id="action'.$num.'acymailingfieldvalvalue" style="width:200px" value="'.$value.'">';
		}

		if(empty($map) || $map == 'key' || $operator != '=') return $emptyInputReturn;

		$fieldClass = acymailing_get('class.fields');
		$myField = $fieldClass->get($map);
		if(empty($myField) || !in_array($myField->type, array('radio', 'checkbox', 'singledropdown', 'multipledropdown'))) return $emptyInputReturn;

		return $fieldClass->display($myField, '', 'action['.$num.'][acymailingfieldval][value]');
	}

	function onAcyProcessAction_acymailingfieldval($cquery, $action, $num){

		$value = is_array($action['value']) ? implode(',', $action['value']) : $action['value'];
		$replace = array('{year}', '{month}', '{weekday}', '{day}');
		$replaceBy = array(date('Y'), date('m'), date('N'), date('d'));
		$value = str_replace($replace, $replaceBy, $value);

		if(preg_match_all('#{(year|month|weekday|day)\|(add|remove):([^}]*)}#Uis', $value, $results)){
			foreach($results[0] as $i => $oneMatch){
				$format = str_replace(array('year', 'month', 'weekday', 'day'), array('Y','m','N','d'), $results[1][$i]);
				$delay = str_replace(array('add', 'remove'), array('+', '-'), $results[2][$i]).intval($results[3][$i]).' '.str_replace('weekday', 'day', $results[1][$i]);
				$value = str_replace($oneMatch, date($format, strtotime($delay)), $value);
			}
		}

		if(empty($action['operator'])) $action['operator'] = '=';

		preg_match_all('#(?:{|%7B)field:(.*)(?:}|%7D)#Ui', $value, $tags);
		$fields = array_keys(acymailing_getColumns('#__acymailing_subscriber'));
		if(!in_array($action['map'], $fields)) return 'Unexisting field: '.$action['map'].' | The available fields are: '.implode(', ', $fields);

		if(in_array($action['operator'], array('+', '-'))){
			if(empty($tags) || empty($tags[1])){
				$value = intval($value);
			}else{
				if(count($tags[1]) > 1 || substr($value, 0, 1) != '{' || substr($value, strlen($value) - 1, 1) != '}'){
					return 'You can\'t use more than one tag for the + and - operators (you also can\'t add or remove a value from the inserted tag for these two operators)';
				}
				if(!in_array($tags[1][0], $fields)) return 'Unexisting field: '.$tags[1][0].' | The available fields are: '.implode(', ', $fields);
				$value = 'sub.`'.acymailing_secureField($tags[1][0]).'`';
			}
		}else{
			$value = $cquery->db->Quote($value);
			if(!empty($tags)){
				foreach($tags[1] as $i => $oneField){
					if(!in_array($oneField, $fields)) return 'Unexisting field: '.$oneField.' | The available fields are: '.implode(', ', $fields);
					$value = str_replace($tags[0][$i], "', sub.`".acymailing_secureField($oneField)."`, '", $value);
				}
				$value = "CONCAT(".$value.")";
			}
		}

		$query = 'UPDATE #__acymailing_subscriber AS sub';
		if(!empty($cquery->join)) $query .= ' JOIN '.implode(' JOIN ', $cquery->join);
		if(!empty($cquery->leftjoin)) $query .= ' LEFT JOIN '.implode(' LEFT JOIN ', $cquery->leftjoin);

		if($action['operator'] == '='){
			$newValue = $value;
		}elseif(in_array($action['operator'], array('+', '-'))){
			$newValue = "sub.`".acymailing_secureField($action['map'])."` ".$action['operator']." ".$value;
		}elseif($action['operator'] == 'addend'){
			$newValue = "CONCAT(sub.`".acymailing_secureField($action['map'])."`, ".$value.")";
		}elseif($action['operator'] == 'addbegin'){
			$newValue = "CONCAT(".$value.", sub.`".acymailing_secureField($action['map'])."`)";
		}else{
			return 'Non existing operator: '.$action['operator'];
		}

		$query .= " SET sub.`".acymailing_secureField($action['map'])."` = ".$newValue;
		if(!empty($cquery->where)) $query .= ' WHERE ('.implode(') AND (', $cquery->where).')';

		$cquery->db->setQuery($query);
		$cquery->db->query();
		$nbAffected = $cquery->db->getAffectedRows();
		return JText::sprintf('NB_MODIFIED', $nbAffected);
	}

	function onAcyProcessAction_acymailingfield($cquery, $action, $num){

		$subClass = acymailing_get('class.subscriber');

		if($action['action'] == 'confirm'){
			$cquery->where['confirmed'] = 'sub.confirmed = 0';
			$cquery->db->setQuery($cquery->getQuery(array('sub.subid')));
			$allSubids = acymailing_loadResultArray($cquery->db);
			if(!empty($allSubids)){
				$subClass->sendConf = false;
				$subClass->sendWelcome = false;
				$subClass->sendNotif = false;
				foreach($allSubids as $oneId){
					$subClass->confirmSubscription($oneId);
				}
			}
			unset($cquery->where['confirmed']);
			return JText::sprintf('NB_CONFIRMED', count($allSubids));
		}

		if($action['action'] == 'enable'){
			$action['map'] = 'enabled';
			$action['value'] = 1;
			return $this->onAcyProcessAction_acymailingfieldval($cquery, $action, $num);
		}

		if($action['action'] == 'block'){
			$action['map'] = 'enabled';
			$action['value'] = 0;
			return $this->onAcyProcessAction_acymailingfieldval($cquery, $action, $num);
		}

		if($action['action'] == 'unconfirm'){
			$action['map'] = 'confirmed';
			$action['value'] = 0;
			return $this->onAcyProcessAction_acymailingfieldval($cquery, $action, $num);
		}

		if($action['action'] == 'delete'){
			$query = $cquery->getQuery(array('sub.subid'));
			$cquery->db->setQuery($query);
			$allSubids = acymailing_loadResultArray($cquery->db);
			$nbAffected = $subClass->delete($allSubids);
			return JText::sprintf('IMPORT_DELETE', $nbAffected);
		}

		return 'Filter AcyMailingField error, action not found : '.$action['action'];
	}
}//endclass
tagsubscriber/tagsubscriber.xml000064400000004615152345456710013006 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing Tag : Subscriber information</name>
	<creationDate>juin 2016</creationDate>
	<version>5.5.0</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin enables you to add information of the subscriber in your Newsletter</description>
	<files>
		<filename plugin="tagsubscriber">tagsubscriber.php</filename>
		<filename>index.html</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-tagsubscriber"/>
		<param name="displayfilter_mail" type="radio" default="1" label="Display filter" description="Display the subscriber fields filter on the Newsletter creation interface">
			<option value="0">JOOMEXT_NO</option>
			<option value="1">JOOMEXT_YES</option>
		</param>
		<param name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
			<option value="all">Always display this tag system</option>
			<option value="none">Don't display this tag system on the front-end</option>
		</param>
	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-tagsubscriber"/>
				<field name="displayfilter_mail" type="radio" default="1" label="Display filter" description="Display the subscriber fields filter on the Newsletter creation interface">
					<option value="0">JOOMEXT_NO</option>
					<option value="1">JOOMEXT_YES</option>
				</field>
				<field name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
					<option value="all">Always display this tag system</option>
					<option value="none">Don't display this tag system on the front-end</option>
				</field>
			</fieldset>
		</fields>
	</config>
</extension>
tagsubscription/index.html000064400000000054152345456710011774 0ustar00<html><body bgcolor="#FFFFFF"></body></html>tagsubscription/tagsubscription.php000064400000100241152345456710013727 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

class plgAcymailingTagsubscription extends JPlugin{
	var $listunsubscribe = false;
	var $lists = array();
	var $listsowner = array();
	var $listsinfo = array();
	var $campaigns = array();

	function __construct(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'tagsubscription');
			$this->params = new acyParameter($plugin->params);
		}
		$this->db = JFactory::getDBO();
		$this->acypluginsHelper = acymailing_get('helper.acyplugins');
	}

	function acymailing_getPluginType(){

		$app = JFactory::getApplication();
		if($this->params->get('frontendaccess') == 'none' && !$app->isAdmin()) return;
		$onePlugin = new stdClass();
		$onePlugin->name = JText::_('SUBSCRIPTION');
		$onePlugin->function = 'acymailingtagsubscription_show';
		$onePlugin->help = 'plugin-tagsubscription';

		return $onePlugin;
	}

	function acymailingtagsubscription_show(){

		$others = array();
		$others['unsubscribe'] = array('name' => JText::_('UNSUBSCRIBE_LINK'), 'default' => JText::_('UNSUBSCRIBE', true));
		$others['modify'] = array('name' => JText::_('MODIFY_SUBSCRIPTION_LINK'), 'default' => JText::_('MODIFY_SUBSCRIPTION', true));
		$others['confirm'] = array('name' => JText::_('CONFIRM_SUBSCRIPTION_LINK'), 'default' => JText::_('CONFIRM_SUBSCRIPTION', true));

		?>
		<script language="javascript" type="text/javascript">
			<!--
			var selectedTag = '';
			function changeTag(tagName){
				selectedTag = tagName;
				defaultText = new Array();
				<?php
				$k = 0;
				foreach($others as $tagname => $tag){
					echo "document.getElementById('tr_$tagname').className = 'row$k';";
					echo "defaultText['$tagname'] = '".$tag['default']."';";
				}
				$k = 1 - $k;
				?>
				document.getElementById('tr_' + tagName).className = 'selectedrow';
				document.adminForm.tagtext.value = defaultText[tagName];
				setSubscriptionTag();
			}

			function setSubscriptionTag(){
				var tag = '{' + selectedTag;
				if(document.getElementById('tagmenu').value != 0) tag += "|itemid:" + document.getElementById('tagmenu').value;
				tag += '}' + document.adminForm.tagtext.value + '{/' + selectedTag + '}'
				setTag(tag);
			}
			//-->
		</script>
		<?php

		$doc = JFactory::getDocument();
		$doc->addScriptDeclaration("window.addEvent('domready', function(){ changeTag('unsubscribe'); });");

		$text = '<div class="onelineblockoptions">
					<span class="acyblocktitle">'.JText::_('SUBSCRIPTION').'</span>
					<table class="acymailing_table" cellpadding="1">';
		$this->db->setQuery('SELECT 0 AS id, "- - -" AS title UNION SELECT id, title FROM #__menu WHERE link LIKE "%com_acymailing%" AND client_id = 0 AND published = 1');
		$menus = $this->db->loadObjectList();
		$text .= '<tr>
					<td><label for="tagtext">'.JText::_('FIELD_TEXT').': </label><input type="text" name="tagtext" id="tagtext" onchange="setSubscriptionTag();"></td>
					<td><label for="tagmenu">'.JText::_('ACY_MENU').': </label>'.JHTML::_('select.genericlist', $menus, "tagmenu", 'class="inputbox" size="1" onchange="setSubscriptionTag();"', 'id', 'title', '').'</td>
				</tr>';
		$text .= '</table>
					<table class="acymailing_table" cellpadding="1">';

		$k = 0;
		foreach($others as $tagname => $tag){
			$text .= '<tr style="cursor:pointer" class="row'.$k.'" onclick="changeTag(\''.$tagname.'\');" id="tr_'.$tagname.'" ><td class="acytdcheckbox"></td><td>'.$tag['name'].'</td></tr>';
			$k = 1 - $k;
		}
		$text .= '</table></div>';

		$others = array();
		$others['name'] = JText::_('LIST_NAME');
		$others['names'] = JText::_('ACY_LIST_NAMES');
		$others['description'] = JText::_('ACY_DESCRIPTION');
		$others['count'] = trim(JText::_('GEOLOC_NB_USERS', true), ':');
		$others['count|listid:0'] = trim(JText::_('GEOLOC_NB_USERS', true), ':').' ('.JText::_('ALL_LISTS').')';
		$others['id'] = JText::_('ACY_ID', true);

		$text .= '<div class="onelineblockoptions">
					<span class="acyblocktitle">'.JText::_('LIST').'</span>
					<table class="acymailing_table" cellpadding="1">';

		$k = 0;
		foreach($others as $tagname => $tag){
			$text .= '<tr style="cursor:pointer" class="row'.$k.'" onclick="setTag(\'{list:'.$tagname.'}\');insertTag();" id="tr_'.$tagname.'" ><td class="acytdcheckbox"></td><td>'.$tag.'</td></tr>';
			$k = 1 - $k;
		}

		$text .= '</table></div>';

		$text .= '<div class="onelineblockoptions">
					<span class="acyblocktitle">'.JText::_('NEWSLETTER').'</span>
					<table class="acymailing_table" cellpadding="1">';
		$othersMail = array('mailid', 'subject', 'alias', 'key', 'altbody');
		$k = 0;
		foreach($othersMail as $tag){
			$text .= '<tr style="cursor:pointer" class="row'.$k.'" onclick="setTag(\'{mail:'.$tag.'}\');insertTag();" id="tr_'.$tag.'" ><td class="acytdcheckbox"></td><td>'.$tag.'</td></tr>';
			$k = 1 - $k;
		}
		$text .= '</table></div>';

		echo $text;
	}

	function onAcyDisplayActions(&$type){
		$type['list'] = JText::_('ACYMAILING_LIST');
		$status = array();
		$status[] = JHTML::_('select.option', 1, JText::_('SUBSCRIBE_TO'));
		$status[] = JHTML::_('select.option', 0, JText::_('REMOVE_FROM'));
		$status[] = JHTML::_('select.option', -1, JText::_('ACY_UNSUB_FROM'));

		$lists = $this->_getLists();
		$otherlists = array();
		$onChange = '';
		if(acymailing_level(3)){
			$db = JFactory::getDBO();
			$db->setQuery('SELECT b.listid, b.name FROM #__acymailing_listcampaign as a JOIN #__acymailing_list as b on a.listid = b.listid GROUP BY b.listid ORDER BY b.ordering ASC');
			$otherlists = $db->loadObjectList('listid');
			$onChange = 'onchange="onAcyDisplayAction_list(__num__);"';

			$js = "function onAcyDisplayAction_list(num){
				if(!document.getElementById('campaigndelay'+num)) return;
				if(document.getElementById('subliststatus'+num).value == 1 && document.getElementById('sublistvalue'+num).value.indexOf('_campaign') > 0){
					document.getElementById('campaigndelay'+num).style.display = 'inline';
				}else{
					document.getElementById('campaigndelay'+num).style.display = 'none';
				}
			}";
			$doc = JFactory::getDocument();
			$doc->addScriptDeclaration($js);
		}

		$listsdrop = array();
		foreach($lists as $oneList){
			if(!empty($otherlists[$oneList->listid])) $listsdrop[] = JHTML::_('select.option', $oneList->listid.'_campaign', $otherlists[$oneList->listid]->name.' + '.JText::_('CAMPAIGN'));
			$listsdrop[] = JHTML::_('select.option', $oneList->listid, $oneList->name);
		}

		$return = '<div id="action__num__list">'.JHTML::_('select.genericlist', $status, "action[__num__][list][status]", 'class="inputbox" size="1" '.$onChange, 'value', 'text', '', 'subliststatus__num__').' '.JHTML::_('select.genericlist', $listsdrop, "action[__num__][list][selectedlist]", 'class="inputbox" size="1" '.$onChange, 'value', 'text', '', 'sublistvalue__num__');
		if(!empty($otherlists)){
			$delay = array();
			$delay[] = JHTML::_('select.option', 'day', JText::_('DAYS'));
			$delay[] = JHTML::_('select.option', 'week', JText::_('WEEKS'));
			$delay[] = JHTML::_('select.option', 'month', JText::_('MONTHS'));

			$listHours = array();
			$listHours[] = JHTML::_('select.option', '', '- -');
			for($i = 0; $i < 24; $i++){
				$listHours[] = JHTML::_('select.option', ($i < 10 ? '0'.$i : $i), ($i < 10 ? '0'.$i : $i));
			}
			$hours = JHTML::_('select.genericlist', $listHours, 'action[__num__][list][sendhours]', 'class="inputbox" size="1" style="width:60px;"', 'value', 'text', '');

			$listMinutess = array();
			$listMinutess[] = JHTML::_('select.option', '', '- -');
			for($i = 0; $i < 60; $i += 5){
				$listMinutess[] = JHTML::_('select.option', ($i < 10 ? '0'.$i : $i), ($i < 10 ? '0'.$i : $i));
			}
			$minutes = JHTML::_('select.genericlist', $listMinutess, 'action[__num__][list][sendminutes]', 'class="inputbox" size="1" style="width:60px;"', 'value', 'text', '');

			$return .= '<br /><span id="campaigndelay__num__">'.JText::sprintf('TRIGGER_CAMPAIGN', '<input type="text" name="action[__num__][list][delaynum]" value="0" style="width:50px" />', JHTML::_('select.genericlist', $delay, "action[__num__][list][delaytype]", 'class="inputbox" size="1" style="width:120px;"', 'value', 'text')).' @ '.$hours.' : '.$minutes;
			$return .= '<br />'.JText::sprintf('ACY_CAMPAIGN_NB_FOLLOW_SKIPED', '<input type="text" name="action[__num__][list][skipedfollowups]" value="0" style="width:25px;" />').'</span>';
		}
		$return .= '</div>';

		return $return;
	}

	private function _getLists(){
		if(!empty($this->allLists)) return $this->allLists;
		$list = acymailing_get('class.list');
		$app = JFactory::getApplication();
		if($app->isAdmin()){
			$this->allLists = $list->getLists();
		}else{
			$this->allLists = $list->getFrontendLists();
		}

		return $this->allLists;
	}

	private function _getCampaigns(){

		$list = acymailing_get('class.list');
		$app = JFactory::getApplication();
		if($app->isAdmin()){
			return $list->getAllCampaigns();
		}
		return $list->getFrontendCampaigns();
	}

	function onAcyDisplayFilters(&$type, $context = "massactions"){

		if($this->params->get('displayfilter_'.$context, true) == false) return;

		$type['list'] = JText::_('ACYMAILING_LIST');
		$status = acymailing_get('type.statusfilterlist');
		$status->extra = 'onchange="countresults(__num__);"';

		$lists = $this->_getLists();
		$campaigns = $this->_getCampaigns();
		$listsdrop = array();

		$listsdrop[] = JHTML::_('select.option', '<OPTGROUP>', JText::_('LISTS'));
		foreach($lists as $oneList){
			$listsdrop[] = JHTML::_('select.option', $oneList->listid, $oneList->name);
		}
		$listsdrop[] = JHTML::_('select.option', '</OPTGROUP>');

		if(count($campaigns) > 0){
			$listsdrop[] = JHTML::_('select.option', '<OPTGROUP>', JText::_('ACY_CAMPAIGNS'));
			foreach($campaigns as $campaign){
				$listsdrop[] = JHTML::_('select.option', $campaign->listid, $campaign->name);
			}
			$listsdrop[] = JHTML::_('select.option', '</OPTGROUP>');
		}

		$dates = array();
		$dates[] = JHTML::_('select.option', 0, JText::_('SUBSCRIPTION_DATE'));
		$dates[] = JHTML::_('select.option', 1, JText::_('UNSUBSCRIPTION_DATE'));

		$filter = '<div id="filter__num__list">'.$status->display("filter[__num__][list][status]", 1, false).' '.JHTML::_('select.genericlist', $listsdrop, "filter[__num__][list][selectedlist]", 'class="inputbox" style="max-width:200px" size="1" onchange="countresults(__num__)"', 'value', 'text');
		$filter .= '<br /><input type="text" name="filter[__num__][list][subdateinf]" onclick="displayDatePicker(this,event)" onchange="countresults(__num__)" style="width:60px;" /> < '.JHTML::_('select.genericlist', $dates, "filter[__num__][list][dates]", 'class="inputbox" style="max-width:200px" size="1" onchange="countresults(__num__)"', 'value', 'text').' < <input type="text" name="filter[__num__][list][subdatesup]" onclick="displayDatePicker(this,event)" onchange="countresults(__num__)" style="width:60px;" /></div>';
		return $filter;
	}

	function onAcyProcessFilter_list(&$query, $filter, $num){
		$otherconditions = '';
		$field = empty($filter['dates']) ? 'subdate' : 'unsubdate';
		if(!empty($filter['subdateinf'])){
			$filter['subdateinf'] = acymailing_replaceDate($filter['subdateinf']);
			if(!is_numeric($filter['subdateinf'])) $filter['subdateinf'] = strtotime($filter['subdateinf']);
			if(!empty($filter['subdateinf'])) $otherconditions .= ' AND list'.$num.'.'.$field.' > '.$filter['subdateinf'];
		}

		if(!empty($filter['subdatesup'])){
			$filter['subdatesup'] = acymailing_replaceDate($filter['subdatesup']);
			if(!is_numeric($filter['subdatesup'])) $filter['subdatesup'] = strtotime($filter['subdatesup']);
			if(!empty($filter['subdatesup'])) $otherconditions .= ' AND list'.$num.'.'.$field.' < '.$filter['subdatesup'];
		}

		$query->leftjoin['list'.$num] = '#__acymailing_listsub AS list'.$num.' ON sub.subid = list'.$num.'.subid AND list'.$num.'.listid = '.intval($filter['selectedlist']).$otherconditions;
		if($filter['status'] == -2){
			$query->where[] = 'list'.$num.'.listid IS NULL';
		}else{
			$query->where[] = 'list'.$num.'.status = '.intval($filter['status']);
		}
	}

	function onAcyProcessFilterCount_list(&$query, $filter, $num){
		$this->onAcyProcessFilter_list($query, $filter, $num);
		return JText::sprintf('SELECTED_USERS', $query->count());
	}

	function onAcyProcessAction_list($cquery, $action, $num){
		$listid = intval($action['selectedlist']);
		$listClass = acymailing_get('class.list');
		if(is_numeric($action['selectedlist'])){
			$myList = $listClass->get($listid);
			if(empty($myList->listid)){
				return 'ERROR : List '.$listid.' not found';
			}

			if(empty($action['status'])){
				$query = 'DELETE listremove.* FROM '.acymailing_table('listsub').' AS listremove ';
				$query .= 'JOIN #__acymailing_subscriber AS sub ON listremove.subid = sub.subid ';
				if(!empty($cquery->join)) $query .= ' JOIN '.implode(' JOIN ', $cquery->join);
				if(!empty($cquery->leftjoin)) $query .= ' LEFT JOIN '.implode(' LEFT JOIN ', $cquery->leftjoin);
				$query .= ' WHERE listremove.listid = '.$listid;
				if(!empty($cquery->where)) $query .= ' AND ('.implode(') AND (', $cquery->where).')';
			}elseif($action['status'] == -1){
				$query = 'UPDATE '.acymailing_table('listsub').' AS listsub'.$num.' JOIN '.acymailing_table('subscriber').' AS sub ON listsub'.$num.'.subid = sub.subid ';
				if(!empty($cquery->join)) $query .= ' JOIN '.implode(' JOIN ', $cquery->join);
				if(!empty($cquery->leftjoin)) $query .= ' LEFT JOIN '.implode(' LEFT JOIN ', $cquery->leftjoin);
				$query .= ' SET listsub'.$num.'.status = -1, listsub'.$num.'.unsubdate = '.time().' WHERE listsub'.$num.'.listid = '.$listid;
				if(!empty($cquery->where)) $query .= ' AND ('.implode(') AND (', $cquery->where).')';
			}else{
				$query = 'INSERT IGNORE INTO '.acymailing_table('listsub').' (listid,subid,subdate,status) ';
				$query .= $cquery->getQuery(array($listid, 'sub.subid', time(), 1));
			}
			$cquery->db->setQuery($query);
			$cquery->db->query();
			$nbsubscribed = $cquery->db->getAffectedRows();

			if(empty($action['status'])){
				return JText::sprintf('IMPORT_REMOVE', $nbsubscribed, '<b><i>'.$myList->name.'</i></b>');
			}elseif($action['status'] == -1){
				return JText::sprintf('NB_UNSUB_USERS', $nbsubscribed);
			}else{
				return JText::sprintf('IMPORT_SUBSCRIBE_CONFIRMATION', $nbsubscribed, '<b><i>'.$myList->name.'</i></b>');
			}
		}

		$myList = $listClass->get($listid);
		if(empty($myList->listid)){
			return 'ERROR : List '.$listid.' not found';
		}
		if(empty($action['status'])){
			$query = 'SELECT listremove.`subid` FROM #__acymailing_listsub as listremove';
			$query .= ' JOIN #__acymailing_subscriber as sub ON listremove.subid = sub.subid ';
			$condition = ' WHERE listremove.listid = '.$listid;
		}elseif($action['status'] == -1){
			$query = 'SELECT listunsub.`subid` FROM #__acymailing_listsub as listunsub JOIN #__acymailing_subscriber as sub ON listunsub.subid = sub.subid ';
			$condition = ' WHERE listunsub.listid = '.$listid.' AND listunsub.status != -1';
		}else{
			$query = 'SELECT sub.`subid` FROM #__acymailing_subscriber as sub';
			$query .= ' LEFT JOIN #__acymailing_listsub as listsubscribe ON listsubscribe.subid = sub.subid AND listsubscribe.listid = '.$listid;
			$condition = ' WHERE listsubscribe.subid IS NULL';
		}
		if(!empty($cquery->join)) $query .= ' JOIN '.implode(' JOIN ', $cquery->join);
		if(!empty($cquery->leftjoin)) $query .= ' LEFT JOIN '.implode(' LEFT JOIN ', $cquery->leftjoin);
		$query .= $condition;
		if(!empty($cquery->where)) $query .= ' AND ('.implode(') AND (', $cquery->where).')';
		if(!empty($cquery->orderBy)) $query .= ' ORDER BY '.$cquery->orderBy;
		if(!empty($cquery->limit)) $query .= ' LIMIT '.intval($cquery->limit);
		$cquery->db->setQuery($query);
		$subids = acymailing_loadResultArray($cquery->db);

		if(!empty($subids)){
			$listsubClass = acymailing_get('class.listsub');
			$time = time();
			$timeFunction = 'acymailing_getTime';
			if(!isset($action['sendhours']) || strlen($action['sendhours']) < 1){
				$action['sendhours'] = '%H';
				$timeFunction = 'strftime';
			}
			if(!isset($action['sendminutes']) || strlen($action['sendminutes']) < 1) $action['sendminutes'] = '%M';
			$format = '%Y-%m-%d '.$action['sendhours'].':'.$action['sendminutes'].':00';
			if($action['status'] == 1 && !empty($action['delaynum'])){
				$listsubClass->campaigndelay = $timeFunction(strftime($format, strtotime('+'.intval($action['delaynum']).' '.$action['delaytype'])));
			}else{
				$listsubClass->campaigndelay = $timeFunction(strftime($format, $time));
			}
			if($listsubClass->campaigndelay < $time){
				$listsubClass->campaigndelay = 0;
			}else $listsubClass->campaigndelay -= $time;

			if(!empty($action['skipedfollowups'])){
				$action['skipedfollowups'] = intval($action['skipedfollowups']);
				if(!empty($action['skipedfollowups'])) $listsubClass->skipedfollowups = $action['skipedfollowups'];
			}
			$listsubClass->checkAccess = false;
			$listsubClass->sendNotif = false;
			$listsubClass->sendConf = false;
			foreach($subids as $subid){
				if(empty($action['status'])){
					$listsubClass->removeSubscription($subid, array($listid));
				}elseif($action['status'] == -1) $listsubClass->updateSubscription($subid, array('-1' => array($listid)));
				else $listsubClass->addSubscription($subid, array('1' => array($listid)));
			}
		}

		$nbsubscribed = count($subids);
		if(empty($action['status'])){
			return JText::sprintf('IMPORT_REMOVE', $nbsubscribed, '<b><i>'.$myList->name.'</i></b>');
		}elseif($action['status'] == -1){
			return JText::sprintf('NB_UNSUB_USERS', $nbsubscribed);
		}else{
			return JText::sprintf('IMPORT_SUBSCRIBE_CONFIRMATION', $nbsubscribed, '<b><i>'.$myList->name.'</i></b>');
		}
	}

	function acymailing_replaceusertags(&$email, &$user, $send = true){
		$this->_replacesubscriptiontags($email, $user);
		$this->_replacelisttags($email, $user, $send);
	}

	function acymailing_replacetags(&$email, $send = true){
		$this->_replacemailtags($email);
	}

	private function _replacemailtags(&$email){
		$variables = array('subject', 'body', 'altbody');
		$acypluginsHelper = acymailing_get('helper.acyplugins');
		$result = $acypluginsHelper->extractTags($email, 'mail');
		$tags = array();

		foreach($result as $key => $oneTag){
			$field = $oneTag->id;
			if(!empty($email) && !empty($email->$field)){
				$text = $email->$field;
				$acypluginsHelper->formatString($text, $oneTag);
				$tags[$key] = $text;
			}else{
				$tags[$key] = $oneTag->default;
			}
		}

		foreach($variables as $var){
			if(empty($email->$var)) continue;
			$email->$var = str_replace(array_keys($tags), $tags, $email->$var);
		}
	}

	private function _replacelisttags(&$email, &$user, $send){
		if(!empty($email->ReplyTo)){
			$toDelete = 0;
			foreach($email->ReplyTo as $i => $replyto){
				if(trim($i) != '{list:members}') continue;
				$toDelete = $i;
				break;
			}
			if(!empty($toDelete)){
				unset($email->ReplyTo[$toDelete]);
				$acyConfig = acymailing_config();
				$listMembers = $this->loadlistmembers($email, $user);
				foreach($listMembers as $member){
					if($acyConfig->get('add_names', true) && !empty($member->name)){
						$replyToName = $email->cleanText(trim($member->name));
					}else{
						$replyToName = '';
					}
					$email->AddReplyTo($email->cleanText($member->email), $replyToName);
				}
			}
		}

		$this->acypluginsHelper = acymailing_get('helper.acyplugins');
		$tags = $this->acypluginsHelper->extractTags($email, 'list');
		if(empty($tags)) return;

		$replaceTags = array();
		foreach($tags as $oneTag => $parameter){
			$method = '_list'.trim(strtolower($parameter->id));

			if(method_exists($this, $method)){
				$replaceTags[$oneTag] = $this->$method($email, $user, $parameter);
			}else{
				$replaceTags[$oneTag] = 'Method not found : '.$method;
			}
		}

		$this->acypluginsHelper->replaceTags($email, $replaceTags, true);
	}

	private function _getattachedlistid($email, $subid){

		$mailid = $email->mailid;
		$type = strtolower($email->type);

		if(isset($this->lists[$mailid][$subid])) return $this->lists[$mailid][$subid];


		$db = JFactory::getDBO();

		if($type == 'followup'){
			$db->setQuery('SELECT a.listid
							FROM #__acymailing_listsub AS a
							JOIN #__acymailing_listcampaign AS b
								ON a.listid = b.listid
							JOIN #__acymailing_listmail AS c
								ON b.campaignid = c.listid
							WHERE a.subid = '.intval($subid).'
								AND c.mailid = '.intval($mailid).'
							ORDER BY a.status DESC LIMIT 1');
			$listid = $db->loadResult();
			if(!empty($listid)){
				$this->lists[$mailid][$subid] = $listid;
				return $listid;
			}
		}

		if(in_array($type, array('news', 'autonews'))){
			if(!empty($subid)){
				$db->setQuery('SELECT a.listid FROM #__acymailing_listsub as a JOIN #__acymailing_listmail as b ON a.listid = b.listid WHERE a.subid = '.intval($subid).' AND b.mailid = '.intval($mailid).' ORDER BY a.status DESC LIMIT 1');
				$listid = $db->loadResult();
				if(!empty($listid)){
					$this->lists[$mailid][$subid] = $listid;
					return $listid;
				}
			}

			$db->setQuery('SELECT a.listid FROM #__acymailing_listmail as a JOIN #__acymailing_list as b ON a.listid = b.listid WHERE a.mailid = '.intval($mailid).' ORDER BY b.published DESC , b.visible DESC LIMIT 1');
			$listid = $db->loadResult();
			if(!empty($listid)){
				$this->lists[$mailid][$subid] = $listid;
				return $listid;
			}
		}

		if($type == 'welcome' && !empty($subid)){
			$db->setQuery('SELECT a.listid FROM #__acymailing_list as a JOIN #__acymailing_listsub as b ON a.listid = b.listid WHERE a.welmailid = '.intval($mailid).' AND b.subid = '.intval($subid).' ORDER BY b.subdate DESC LIMIT 1');
			$listid = $db->loadResult();
			if(!empty($listid)){
				$this->lists[$mailid][$subid] = $listid;
				return $listid;
			}
		}

		if($type == 'unsub' && !empty($subid)){
			$db->setQuery('SELECT a.listid FROM #__acymailing_list as a JOIN #__acymailing_listsub as b ON a.listid = b.listid WHERE a.unsubmailid = '.intval($mailid).' AND b.subid = '.intval($subid).' ORDER BY b.unsubdate DESC LIMIT 1');
			$listid = $db->loadResult();
			if(!empty($listid)){
				$this->lists[$mailid][$subid] = $listid;
				return $listid;
			}
		}

		$allLists = array_merge(JRequest::getVar('subscription', '', '', 'array'), explode(',', JRequest::getVar('hiddenlists', '', '', 'string')));
		$data = JRequest::getVar('data', '', '', 'array');
		if(!empty($data['listsub'])){
			$allLists = array_merge($allLists, array_keys($data['listsub']));
		}

		if(!empty($allLists) && in_array($type, array('unsub', 'welcome'))){
			JArrayHelper::toInteger($allLists);
			$db->setQuery('SELECT a.listid FROM #__acymailing_list as a WHERE (a.welmailid = '.intval($mailid).' OR unsubmailid = '.intval($mailid).') AND listid IN ('.implode(',', $allLists).') ORDER BY a.published DESC, a.visible DESC LIMIT 1');
			$listid = $db->loadResult();
			if(!empty($listid)){
				$this->lists[$mailid][$subid] = $listid;
				return $listid;
			}

			$db->setQuery('SELECT a.listid FROM #__acymailing_list as a WHERE (a.welmailid = '.intval($mailid).' OR unsubmailid = '.intval($mailid).') ORDER BY a.published DESC, a.visible DESC LIMIT 1');
			$listid = $db->loadResult();
			if(!empty($listid)){
				$this->lists[$mailid][$subid] = $listid;
				return $listid;
			}
		}

		if(!empty($allLists)){
			foreach($allLists as $listid){
				if(!empty($listid)){
					$this->lists[$mailid][$subid] = intval($listid);
					return intval($listid);
				}
			}
		}

		if(!empty($subid)){
			$db->setQuery('SELECT a.listid FROM #__acymailing_listsub as a JOIN #__acymailing_list as b ON a.listid = b.listid WHERE a.subid = '.intval($subid).' ORDER BY b.published DESC , b.visible DESC LIMIT 1');
			$listid = $db->loadResult();
			if(!empty($listid)){
				$this->lists[$mailid][$subid] = $listid;
				return $listid;
			}
		}
	}


	private function _listcount(&$email, &$user, &$parameter){
		if(!isset($parameter->listid)){
			$listid = $this->_getattachedlistid($email, $user->subid);
		}else{
			$listid = $parameter->listid;
		}

		$db = JFactory::getDBO();
		if(empty($listid)){
			$db->setQuery('SELECT COUNT(subid) FROM #__acymailing_subscriber');
		}else{
			$db->setQuery('SELECT COUNT(subid) FROM #__acymailing_listsub WHERE listid = '.intval($listid).' AND status = 1');
		}

		return $db->loadResult();
	}

	private function _listsubscription(&$email, &$user, &$parameter){
		if(empty($user->subid)) return "";
		$listSubClass = acymailing_get('class.listsub');
		return $listSubClass->getSubscriptionString($user->subid);
	}

	private function _listnames(&$email, &$user, &$parameter){
		if(empty($user->subid)) return "";
		$listSubClass = acymailing_get('class.listsub');
		$usersubscription = $listSubClass->getSubscription($user->subid);
		if(empty($usersubscription)){
			$subscribedLists = $this->_getFormListNames();
			if(empty($subscribedLists)) return '';
			return implode(isset($parameter->separator) ? $parameter->separator : ', ', $subscribedLists);
		}
		$lists = array();
		if(!empty($usersubscription)){
			foreach($usersubscription as $onesub){
				if($onesub->status < 1 || empty($onesub->published)) continue;
				$lists[] = $onesub->name;
			}
		}
		return implode(isset($parameter->separator) ? $parameter->separator : ', ', $lists);
	}


	private function _getFormListNames(){
		$allLists = array_merge(JRequest::getVar('subscription', '', '', 'array'), explode(',', JRequest::getVar('hiddenlists', '', '', 'string')));
		$data = JRequest::getVar('data', '', '', 'array');
		if(!empty($data['listsub'])){
			foreach($data['listsub'] as $i => $oneList){
				if($oneList['status'] != 1) unset($data['listsub'][$i]);
			}
			$allLists = array_merge($allLists, array_keys($data['listsub']));
		}
		if(empty($allLists)) return array();

		JArrayHelper::toInteger($allLists);
		foreach($allLists as $i => $oneList){
			if(empty($oneList)) unset($allLists[$i]);
		}
		if(empty($allLists)) return array();

		$db = JFactory::getDBO();
		$db->setQuery('SELECT name FROM #__acymailing_list WHERE listid IN ('.implode(',', $allLists).')');
		return acymailing_loadResultArray($db);
	}

	private function _listowner(&$email, &$user, &$parameter){
		if(empty($user->subid)) return '';
		$listid = $this->_getattachedlistid($email, $user->subid);
		if(empty($listid)) return "";

		if(!isset($this->listsowner[$listid])){
			$db = JFactory::getDBO();
			$db->setQuery('SELECT u.* FROM #__acymailing_list as list JOIN #__users as u ON u.id = list.userid WHERE list.listid = '.intval($listid));
			$this->listsowner[$listid] = $db->loadObject();
		}

		if(!in_array($parameter->field, array('username', 'name', 'email'))) return 'Field not found : '.$parameter->field;

		return @$this->listsowner[$listid]->{$parameter->field};
	}

	private function _loadlist($listid){
		if(isset($this->listsinfo[$listid])) return;

		$db = JFactory::getDBO();
		$db->setQuery('SELECT * FROM #__acymailing_list WHERE listid = '.intval($listid));
		$this->listsinfo[$listid] = $db->loadObject();
	}

	private function _listname(&$email, &$user, &$parameter){
		if(empty($user->subid)) return '';
		$listid = $this->_getattachedlistid($email, $user->subid);
		if(empty($listid)) return "No list => no name!";

		$this->_loadlist($listid);

		return @$this->listsinfo[$listid]->name;
	}

	private function _listdescription(&$email, &$user, &$parameter){
		if(empty($user->subid)) return '';
		$listid = $this->_getattachedlistid($email, $user->subid);
		if(empty($listid)) return "No list => no description!";

		$this->_loadlist($listid);

		return @$this->listsinfo[$listid]->description;
	}

	private function _listid(&$email, &$user, &$parameter){
		if(empty($user->subid)) return '';
		$listid = $this->_getattachedlistid($email, $user->subid);
		if(empty($listid)) return "No list => no ID!";

		return $listid;
	}

	private function loadlistmembers(&$email, &$user){
		if(empty($user->subid)) return '';
		$listid = $this->_getattachedlistid($email, $user->subid);
		if(empty($listid)) return array();

		$db = JFactory::getDBO();
		$db->setQuery('SELECT s.email, s.name FROM #__acymailing_listsub AS l JOIN #__acymailing_subscriber AS s ON s.subid=l.subid WHERE l.listid='.intval($listid).' AND l.status=1 AND s.enabled=1 AND s.accept=1');
		return $db->loadObjectList();
	}

	private function _replacesubscriptiontags(&$email, &$user){
		$match = '#(?:{|%7B)(modify[^}]*|confirm[^}]*|unsubscribe[^}]*)(?:}|%7D)(.*)(?:{|%7B)/(modify|confirm|unsubscribe)(?:}|%7D)#Uis';
		$variables = array('subject', 'body', 'altbody');
		$found = false;
		$results = array();
		foreach($variables as $var){
			if(empty($email->$var)) continue;
			$found = preg_match_all($match, $email->$var, $results[$var]) || $found;
			if(empty($results[$var][0])) unset($results[$var]);
		}

		if(!$found) return;

		$tags = array();
		$this->listunsubscribe = false;
		foreach($results as $var => $allresults){
			foreach($allresults[0] as $i => $oneTag){
				if(isset($tags[$oneTag])) continue;
				$tags[$oneTag] = $this->replaceSubscriptionTag($allresults, $i, $user, $email);
			}
		}

		foreach(array_keys($results) as $var){
			$email->$var = str_replace(array_keys($tags), $tags, $email->$var);
		}
	}

	function replaceSubscriptionTag(&$allresults, $i, &$user, &$email){
		if(empty($user->subid)){
			return '';
		}

		if(empty($user->key)){
			$user->key = acymailing_generateKey(14);
			$db = JFactory::getDBO();
			$db->setQuery('UPDATE '.acymailing_table('subscriber').' SET `key`= '.$db->Quote($user->key).' WHERE subid = '.(int)$user->subid.' LIMIT 1');
			$db->query();
		}

		$config = acymailing_config();
		$lang = empty($email->language) ? '' : '&lang='.$email->language;

		$parameters = $this->acypluginsHelper->extractTag($allresults[1][$i]);
		$itemId = $this->params->get(strtolower($parameters->id).'itemid', $config->get('itemid', 0));
		$itemId = empty($parameters->itemid) ? $itemId : intval($parameters->itemid);
		$item = empty($itemId) ? '' : '&Itemid='.$itemId;

		if($parameters->id == 'confirm'){ //confirm your subscription link
			$myLink = acymailing_frontendLink('index.php?subid='.$user->subid.'&option=com_acymailing&ctrl=user&task=confirm&key='.urlencode($user->key).$item.$lang, (bool)$this->params->get('confirmtemplate', false));
			if(empty($allresults[2][$i])) return $myLink;
			return '<a target="_blank" href="'.$myLink.'">'.$allresults[2][$i].'</a>';
		}elseif($parameters->id == 'modify'){ //modify your subscription link
			$myLink = acymailing_frontendLink('index.php?subid='.$user->subid.'&option=com_acymailing&ctrl=user&task=modify&key='.urlencode($user->key).$item.$lang, (bool)$this->params->get('modifytemplate', false));
			if(empty($allresults[2][$i])) return $myLink;
			return '<a style="text-decoration:none;" target="_blank" href="'.$myLink.'"><span class="acymailing_unsub">'.$allresults[2][$i].'</span></a>';
		}//unsubscribe link
		$myLink = acymailing_frontendLink('index.php?subid='.$user->subid.'&option=com_acymailing&ctrl=user&task=out&mailid='.$email->mailid.'&key='.urlencode($user->key).$item.$lang, (bool)$this->params->get('unsubscribetemplate', false));

		if(!$this->listunsubscribe && $this->params->get('listunsubscribe', 0) && method_exists($email, 'addCustomHeader')){
			$this->listunsubscribe = true;
			$mailto = $this->params->get('listunsubscribeemail');
			if(empty($mailto)) $mailto = @$email->replyemail;
			if(empty($mailto)) $mailto = $config->get('reply_email');
			$email->addCustomHeader('List-Unsubscribe: <'.$myLink.'>, <mailto:'.$mailto.'?subject=unsubscribe_user_'.$user->subid.'&body=Please%20unsubscribe%20user%20ID%20'.$user->subid.'>');
		}
		if(empty($allresults[2][$i])) return $myLink;
		return '<a style="text-decoration:none;" target="_blank" href="'.$myLink.'"><span class="acymailing_unsub">'.$allresults[2][$i].'</span></a>';
	}
}//endclass
tagsubscription/tagsubscription.xml000064400000013740152345456710013747 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing Tag : Manage the Subscription</name>
	<creationDate>juin 2016</creationDate>
	<version>5.5.0</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin enables you to add link to manage the subscription of the user</description>
	<files>
		<filename plugin="tagsubscription">tagsubscription.php</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-tagsubscription"/>
		<param name="unsubscribetemplate" type="radio" default="0" label="Display the unsubscribe page" description="Select if you want to display the unsubscribe page (when the user clicks on the unsubscribe link) without any Joomla module (no template) or inside your default Joomla Template">
			<option value="0">Standard template</option>
			<option value="1">No template</option>
		</param>
		<param name="listunsubscribe" type="radio" default="0" label="Add list-unsubscribe header" description="If you insert an unsubscribe link, should Acy also insert the link in the list-unsubscribe field? See www.list-unsubscribe.com">
			<option value="0">JOOMEXT_NO</option>
			<option value="1">JOOMEXT_YES</option>
		</param>
		<param name="listunsubscribeemail" type="text" size="20" default="" label="List-unsubscribe e-mail" description="The GMail feedback loops works with a list-unsubscribe e-mail address. By default Acy will add the reply-to e-mail address but you can specify another e-mail address there" />
		<param name="modifytemplate" type="radio" default="0" label="Display the modify your subscription" description="Select if you want to display the modify your subscription page (when the user clicks on the modify you subscription link) without any Joomla module (no template) or inside your default Joomla Template">
			<option value="0">Standard template</option>
			<option value="1">No template</option>
		</param>
		<param name="confirmtemplate" type="radio" default="0" label="Display the confirmation page" description="Select if you want to display the confirmation page (when the user clicks on the confirmation link) without any Joomla module (no template) or inside your default Joomla Template">
			<option value="0">Standard template</option>
			<option value="1">No template</option>
		</param>
		<param name="displayfilter_mail" type="radio" default="1" label="Display filter" description="Display the subscription filter on the Newsletter creation interface">
			<option value="0">JOOMEXT_NO</option>
			<option value="1">JOOMEXT_YES</option>
		</param>
		<param name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
			<option value="all">Always display this tag system</option>
			<option value="none">Don't display this tag system on the front-end</option>
		</param>
	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-tagsubscription"/>
				<field name="unsubscribetemplate" type="radio" default="0" label="Display the unsubscribe page" description="Select if you want to display the unsubscribe page (when the user clicks on the unsubscribe link) without any Joomla module (no template) or inside your default Joomla Template">
					<option value="0">Standard template</option>
					<option value="1">No template</option>
				</field>
				<field name="listunsubscribe" type="radio" default="0" label="Add list-unsubscribe header" description="If you insert an unsubscribe link, should Acy also insert the link in the list-unsubscribe field? See www.list-unsubscribe.com">
					<option value="0">JOOMEXT_NO</option>
					<option value="1">JOOMEXT_YES</option>
				</field>
				<field name="listunsubscribeemail" type="text" size="20" default="" label="List-unsubscribe e-mail" description="The GMail feedback loops works with a list-unsubscribe e-mail address. By default Acy will add the reply-to e-mail address but you can specify another e-mail address there" />
				<field name="modifytemplate" type="radio" default="0" label="Display the modify your subscription" description="Select if you want to display the modify your subscription page (when the user clicks on the modify you subscription link) without any Joomla module (no template) or inside your default Joomla Template">
					<option value="0">Standard template</option>
					<option value="1">No template</option>
				</field>
				<field name="confirmtemplate" type="radio" default="0" label="Display the confirmation page" description="Select if you want to display the confirmation page (when the user clicks on the confirmation link) without any Joomla module (no template) or inside your default Joomla Template">
					<option value="0">Standard template</option>
					<option value="1">No template</option>
				</field>
				<field name="displayfilter_mail" type="radio" default="1" label="Display filter" description="Display the subscription filter on the Newsletter creation interface">
					<option value="0">JOOMEXT_NO</option>
					<option value="1">JOOMEXT_YES</option>
				</field>
				<field name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
					<option value="all">Always display this tag system</option>
					<option value="none">Don't display this tag system on the front-end</option>
				</field>
			</fieldset>
		</fields>
	</config>
</extension>
tagtime/index.html000064400000000054152345456710010206 0ustar00<html><body bgcolor="#FFFFFF"></body></html>tagtime/tagtime.php000064400000007223152345456710010361 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

class plgAcymailingTagtime extends JPlugin{

	function __construct(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'tagtime');
			$this->params = new acyParameter($plugin->params);
		}
	}


	function acymailing_getPluginType(){

		$app = JFactory::getApplication();
		if($this->params->get('frontendaccess') == 'none' && !$app->isAdmin()) return;
		$onePlugin = new stdClass();
		$onePlugin->name = JText::_('ACY_TIME');
		$onePlugin->function = 'acymailingtagtime_show';
		$onePlugin->help = 'plugin-tagtime';

		return $onePlugin;
	}

	function acymailingtagtime_show(){

		$text = '<br style="clear:both;"/><div class="onelineblockoptions"><table class="acymailing_table" cellpadding="1">';

		$others = array();
		$others['{date}'] = 'DATE_FORMAT_LC';
		$others['{date:1}'] = 'DATE_FORMAT_LC1';
		$others['{date:2}'] = 'DATE_FORMAT_LC2';
		$others['{date:3}'] = 'DATE_FORMAT_LC3';
		$others['{date:4}'] = 'DATE_FORMAT_LC4';
		$others['{date:%m/%d/%Y}'] = '%m/%d/%Y';
		$others['{date:%d/%m/%y}'] = '%d/%m/%y';
		$others['{date:%A}'] = '%A';
		$others['{date:%B}'] = '%B';


		$k = 0;
		foreach($others as $tagname => $tag){
			$text .= '<tr style="cursor:pointer" class="row'.$k.'" onclick="setTag(\''.$tagname.'\');insertTag();" ><td class="acytdcheckbox"></td><td>'.$tag.'</td><td>'.acymailing_getDate(time(), JText::_($tag)).'</td></tr>';
			$k = 1 - $k;
		}

		$text .= '</table></div>';

		echo $text;
	}

	function acymailing_replacetags(&$email, $send = true){

		$match = '#{date:?([^:].*)?}#Ui';
		$variables = array('subject', 'body', 'altbody');

		foreach($variables as $var){
			$email->$var = str_replace(array('{mailid}', '%7Bmailid%7D', '{emailsubject}'), array($email->mailid, $email->mailid, $email->subject), $email->$var);
		}
		$email->body = str_replace('{textversion}', nl2br($email->altbody), $email->body);


		$found = false;
		foreach($variables as $var){
			if(empty($email->$var)) continue;
			$found = preg_match_all($match, $email->$var, $results[$var]) || $found;
			if(empty($results[$var][0])) unset($results[$var]);
		}

		if(!$found) return;

		$tags = array();
		foreach($results as $var => $allresults){
			foreach($allresults[0] as $i => $oneTag){
				if(isset($tags[$oneTag])) continue;
				$arguments = explode('|', strip_tags($allresults[1][$i]));
				$parameter = new stdClass();
				$parameter->format = $arguments[0];
				for($i = 1; $i < count($arguments); $i++){
					$args = explode(':', $arguments[$i]);
					$arg0 = trim($args[0]);
					if(isset($args[1])){
						$parameter->$arg0 = $args[1];
					}else{
						$parameter->$arg0 = true;
					}
				}

				$time = time();
				if(!empty($parameter->senddate) && !empty($email->senddate)) $time = $email->senddate;
				if(!empty($parameter->add)) $time += intval($parameter->add);
				if(!empty($parameter->remove)) $time -= intval($parameter->remove);

				if(empty($parameter->format) OR is_numeric($parameter->format)){
					$tags[$oneTag] = acymailing_getDate($time, JText::_('DATE_FORMAT_LC'.$parameter->format));
				}else{
					$tags[$oneTag] = acymailing_getDate($time, $parameter->format);
				}
			}
		}

		foreach(array_keys($results) as $var){
			$email->$var = str_replace(array_keys($tags), $tags, $email->$var);
		}
	}
}//endclass
tagtime/tagtime.xml000064400000003422152345456710010367 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing Tag : Date / Time</name>
	<creationDate>juin 2016</creationDate>
	<version>5.5.0</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin enables you to add time or date in your Newsletter</description>
	<files>
		<filename plugin="tagtime">tagtime.php</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-tagtime"/>
		<param name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
			<option value="all">Always display this tag system</option>
			<option value="none">Don't display this tag system on the front-end</option>
		</param>
	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-tagtime"/>
				<field name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
					<option value="all">Always display this tag system</option>
					<option value="none">Don't display this tag system on the front-end</option>
				</field>
			</fieldset>
		</fields>
	</config>
</extension>
taguser/index.html000064400000000054152345456710010226 0ustar00<html><body bgcolor="#FFFFFF"></body></html>taguser/taguser.php000064400000034415152345456710010424 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

class plgAcymailingTaguser extends JPlugin{

	var $sendervalues = array();

	function __construct(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'taguser');
			$this->params = new acyParameter($plugin->params);
		}
	}

	function acymailing_getPluginType(){

		$app = JFactory::getApplication();
		if($this->params->get('frontendaccess') == 'none' && !$app->isAdmin()) return;
		$onePlugin = new stdClass();
		$onePlugin->name = JText::_('TAGUSER_TAGUSER');
		$onePlugin->function = 'acymailingtaguser_show';
		$onePlugin->help = 'plugin-taguser';

		return $onePlugin;
	}

	function acymailingtaguser_show(){
		?>

		<script language="javascript" type="text/javascript">
			function applyTag(tagname){
				var string = '{usertag:' + tagname;
				for(var i = 0; i < document.adminForm.typeinfo.length; i++){
					if(document.adminForm.typeinfo[i].checked){
						string += '|info:' + document.adminForm.typeinfo[i].value;
					}
				}
				string += '}';
				setTag(string);
				insertTag();
			}
		</script>
		<?php
		$typeinfo = array();
		$typeinfo[] = JHTML::_('select.option', "receiver", JText::_('RECEIVER_INFORMATION'));
		$typeinfo[] = JHTML::_('select.option', "sender", JText::_('SENDER_INFORMATIONS'));
		echo JHTML::_('acyselect.radiolist', $typeinfo, 'typeinfo', '', 'value', 'text', 'receiver');


		$notallowed = array('password', 'params', 'sendemail', 'gid', 'block', 'email', 'name', 'id');
		$text = '<div class="onelineblockoptions"><table class="acymailing_table" cellpadding="1">';
		$db = JFactory::getDBO();
		$fields = acymailing_getColumns('#__users');
		if(ACYMAILING_J30) $fields = array_merge($fields, array('usertype' => 'usertype'));

		$descriptions['username'] = JText::_('TAGUSER_USERNAME');
		$descriptions['usertype'] = JText::_('TAGUSER_GROUP');
		$descriptions['lastvisitdate'] = JText::_('TAGUSER_LASTVISIT');
		$descriptions['registerdate'] = JText::_('TAGUSER_REGISTRATION');

		$k = 0;
		foreach($fields as $fieldname => $oneField){
			if(in_array(strtolower($fieldname), $notallowed)) continue;
			$type = '';
			if(strpos(strtolower($oneField), 'date') !== false) $type = '|type:date';
			$text .= '<tr style="cursor:pointer" class="row'.$k.'" onclick="applyTag(\''.$fieldname.$type.'\');" ><td class="acytdcheckbox"></td><td>'.$fieldname.'</td><td>'.@$descriptions[strtolower($fieldname)].'</td></tr>';
			$k = 1 - $k;
		}

		if(ACYMAILING_J16){
			$db->setQuery('SELECT DISTINCT `profile_key` FROM `#__user_profiles`');
			$extraFields = $db->loadObjectList();
			if(!empty($extraFields)){
				foreach($extraFields as $oneField){
					$text .= '<tr style="cursor:pointer" class="row'.$k.'" onclick="applyTag(\''.$oneField->profile_key.'|type:extra\');" ><td class="acytdcheckbox"></td><td>'.$oneField->profile_key.'</td><td></td></tr>';
					$k = 1 - $k;
				}
			}
		}
		if(ACYMAILING_J30){
			$link = 'index.php/component/users/?task=registration.activate&token={usertag:activation|info:receiver}';
		}elseif(ACYMAILING_J16){
			$link = 'index.php?option=com_users&task=registration.activate&token={usertag:activation|info:receiver}';
		}else{
			$link = 'index.php?option=com_user&task=activate&activation={usertag:activation|info:receiver}';
		}
		$text .= '<tr style="cursor:pointer" class="row'.$k.'" onclick="setTag(\''.htmlentities('<a target="_blank" href="'.$link.'">'.JText::_('JOOMLA_CONFIRM_ACCOUNT').'</a>').'\'); insertTag();" ><td class="acytdcheckbox"></td><td>confirmJoomla</td><td>'.JText::_('JOOMLA_CONFIRM_LINK').'</td></tr>';

		$text .= '</table></div>';

		echo $text;
	}

	function acymailing_replaceusertags(&$email, &$user, $send = true){
		$pluginsHelper = acymailing_get('helper.acyplugins');
		$extractedTags = $pluginsHelper->extractTags($email, 'usertag');
		if(empty($extractedTags)) return;

		$tags = array();
		$db = JFactory::getDBO();
		$receivervalues = array();
		foreach($extractedTags as $i => $mytag){
			if(isset($tags[$i])) continue;
			$mytag->default = $this->params->get('default_'.$mytag->id, '');


			$values = new stdClass();
			$idused = 0;
			$save = false;

			if(!empty($mytag->info) && $mytag->info == 'sender' && !empty($email->userid)){
				$idused = $email->userid;
				$save = true;
			}
			if(!empty($mytag->info) && $mytag->info == 'current'){
				$my = JFactory::getUser();
				if(!empty($my->id)) $idused = $my->id;
			}
			if((empty($mytag->info) || $mytag->info == 'receiver') && !empty($user->userid)){
				$idused = $user->userid;
			}

			if(!empty($idused) && empty($this->sendervalues[$idused]) && empty($receivervalues[$idused])){
				$db->setQuery('SELECT * FROM '.acymailing_table('users', false).' WHERE id = '.intval($idused).' LIMIT 1');
				$receivervalues[$idused] = $db->loadObject();

				if(ACYMAILING_J16){
					$db->setQuery('SELECT * FROM #__user_profiles WHERE user_id = '.intval($idused));
					$receivervalues[$idused]->extraFields = $db->loadObjectList('profile_key');
				}

				if($save) $this->sendervalues[$idused] = $receivervalues[$idused];
			}


			if(!empty($this->sendervalues[$idused])){
				$values = $this->sendervalues[$idused];
			}elseif(!empty($receivervalues[$idused])) $values = $receivervalues[$idused];

			if($mytag->id == 'usertype' && ACYMAILING_J16){
				if(empty($this->acyuserHelper)) $this->acyuserHelper = acymailing_get('helper.acyuser');
				$groups = $this->acyuserHelper->getUserGroups($idused);
				$allGroups = array();
				foreach($groups as $oneGroup) $allGroups[] = $oneGroup->title;
				$values->usertype = implode(', ', $allGroups);
			}

			if(empty($mytag->type) || $mytag->type != 'extra'){
				$replaceme = isset($values->{$mytag->id}) ? $values->{$mytag->id} : $mytag->default;
			}else{
				$replaceme = isset($values->extraFields[$mytag->id]) ? trim(json_decode($values->extraFields[$mytag->id]->profile_value), '"') : $mytag->default;
			}

			$tags[$i] = $replaceme;
			$pluginsHelper->formatString($tags[$i], $mytag);
		}

		$pluginsHelper->replaceTags($email, $tags);
	}//endfct

	function onAcyDisplayFilters(&$type, $context = "massactions"){

		if($this->params->get('displayfilter_'.$context, true) == false) return;

		$db = JFactory::getDBO();
		$fields = acymailing_getColumns('#__users');
		if(empty($fields)) return;

		$type['joomlafield'] = JText::_('JOOMLA_FIELD');
		$type['joomlagroup'] = JText::_('ACY_GROUP');

		$field = array();
		$field[] = JHTML::_('select.option', 0, '- - -');
		foreach($fields as $oneField => $fieldType){
			$field[] = JHTML::_('select.option', $oneField, $oneField);
		}

		if(ACYMAILING_J16){
			$db->setQuery('SELECT DISTINCT `profile_key` FROM `#__user_profiles`');
			$extraFields = $db->loadObjectList();
			if(!empty($extraFields)){
				foreach($extraFields as $oneField){
					$field[] = JHTML::_('select.option', 'customfield_'.$oneField->profile_key, $oneField->profile_key);
				}
			}
		}

		$jsOnChange = "displayCondFilter('displayUserValues', 'toChange__num__',__num__,'map='+document.getElementById('filter__num__joomlafieldmap').value+'&cond='+document.getElementById('filter__num__joomlafieldoperator').value+'&value='+document.getElementById('filter__num__joomlafieldvalue').value); ";

		$operators = acymailing_get('type.operators');
		$operators->extra = 'onchange="'.$jsOnChange.'countresults(__num__)"';

		$return = '<div id="filter__num__joomlafield">'.JHTML::_('select.genericlist', $field, "filter[__num__][joomlafield][map]", 'class="inputbox" size="1" onchange="'.$jsOnChange.'countresults(__num__)"', 'value', 'text');
		$return .= ' '.$operators->display("filter[__num__][joomlafield][operator]").' <span id="toChange__num__"><input onchange="countresults(__num__)" class="inputbox" type="text" name="filter[__num__][joomlafield][value]" id="filter__num__joomlafieldvalue" style="width:200px" value=""></span></div>';

		if(!ACYMAILING_J16){
			$acl = JFactory::getACL();
			$groups = $acl->get_group_children_tree(null, 'USERS', false);
		}else{
			$db = JFactory::getDBO();
			$db->setQuery('SELECT a.*, a.title as text, a.id as value FROM #__usergroups AS a ORDER BY a.lft ASC');
			$groups = $db->loadObjectList('id');
			foreach($groups as $id => $group){
				if(isset($groups[$group->parent_id])){
					$groups[$id]->level = empty($groups[$group->parent_id]->level) ? 1 : intval($groups[$group->parent_id]->level + 1);
					$groups[$id]->text = str_repeat('- - ', $groups[$id]->level).$groups[$id]->text;
				}
			}
		}

		$inoperator = acymailing_get('type.operatorsin');
		$inoperator->js = 'onchange="countresults(__num__)"';

		$return .= '<div id="filter__num__joomlagroup">'.$inoperator->display("filter[__num__][joomlagroup][type]").' '.JHTML::_('select.genericlist', $groups, "filter[__num__][joomlagroup][group]", 'class="inputbox" size="1" onchange="countresults(__num__)"', 'value', 'text').'<label for="filter__num__joomlagroupsubgroups"><input type="checkbox" value="1" id="filter__num__joomlagroupsubgroups" name="filter[__num__][joomlagroup][subgroups]" onchange="countresults(__num__)"/>'.JText::_('ACY_SUB_GROUPS').'</label></div>';

		return $return;
	}

	function onAcyTriggerFct_displayUserValues(){
		$num = JRequest::getInt('num');
		$map = JRequest::getCmd('map');
		$cond = JRequest::getVar('cond', '', '', 'string', JREQUEST_ALLOWHTML);
		$value = JRequest::getVar('value', '', '', 'string', JREQUEST_ALLOWHTML);

		$emptyInputReturn = '<input onchange="countresults('.$num.')" class="inputbox" type="text" name="filter['.$num.'][joomlafield][value]" id="filter'.$num.'joomlafieldvalue" style="width:200px" value="'.$value.'">';
		$dateInput = '<input onclick="displayDatePicker(this,event)" onchange="countresults('.$num.')" class="inputbox" type="text" name="filter['.$num.'][joomlafield][value]" id="filter'.$num.'joomlafieldvalue" style="width:200px" value="'.$value.'">';

		if(in_array($map, array('registerDate', 'lastvisitDate', 'lastResetTime'))) return $dateInput;

		if(empty($map) || in_array($map, array('password', 'params', 'optKey', 'otep')) || !in_array($cond, array('=', '!='))) return $emptyInputReturn;

		$db = JFactory::getDBO();
		$db->setQuery('SELECT DISTINCT `'.acymailing_secureField($map).'` AS value FROM #__users LIMIT 100');
		$prop = $db->loadObjectList();

		if(empty($prop) || count($prop) >= 100 || (count($prop) == 1 && (empty($prop[0]->value) || $prop[0]->value == '-'))) return $emptyInputReturn;

		return JHTML::_('select.genericlist', $prop, "filter[$num][joomlafield][value]", 'onchange="countresults('.$num.')" class="inputbox" size="1" style="width:200px"', 'value', 'value', $value, 'filter'.$num.'joomlafieldvalue');
	}

	function onAcyProcessFilterCount_joomlafield(&$query, $filter, $num){
		$this->onAcyProcessFilter_joomlafield($query, $filter, $num);
		return JText::sprintf('SELECTED_USERS', $query->count());
	}

	function onAcyDisplayFilter_joomlafield($filter){
		return JText::_('JOOMLA_FIELD').' : '.$filter['map'].' '.$filter['operator'].' '.$filter['value'];
	}


	function onAcyProcessFilter_joomlafield(&$query, $filter, $num){
		if(empty($filter['map'])) return;
		$type = '';
		if(strpos($filter['map'], 'customfield_') !== false){
			$query->leftjoin['joomlauserprofiles'.$num] = '#__user_profiles AS joomlauserprofiles'.$num.' ON joomlauserprofiles'.$num.'.user_id = sub.userid AND joomlauserprofiles'.$num.'.profile_key = '.$query->db->Quote(str_replace('customfield_', '', $filter['map']));
			$val = trim($filter['value'], '"');
			if(in_array($filter['operator'], array('=', '!=', '<', '>', '<=', '>=', 'BEGINS', 'LIKE', 'NOT LIKE'))){
				$val = '"'.$val;
			}
			if(in_array($filter['operator'], array('=', '!=', '<', '>', '<=', '>=', 'END', 'LIKE', 'NOT LIKE'))){
				$val = $val.'"';
			}

			$query->where[] = $query->convertQuery('joomlauserprofiles'.$num, 'profile_value', $filter['operator'], $val, $type);
		}else{
			$query->leftjoin['joomlauser'.$num] = '#__users AS joomlauser'.$num.' ON joomlauser'.$num.'.id = sub.userid';
			if(in_array($filter['map'], array('registerDate', 'lastvisitDate'))){
				$filter['value'] = acymailing_replaceDate($filter['value']);
				if(!is_numeric($filter['value']) && strtotime($filter['value']) !== false) $filter['value'] = strtotime($filter['value']);
				if(is_numeric($filter['value'])) $filter['value'] = strftime('%Y-%m-%d %H:%M:%S', $filter['value']);
				$type = 'datetime';
			}
			$query->where[] = $query->convertQuery('joomlauser'.$num, $filter['map'], $filter['operator'], $filter['value'], $type);
		}
	}

	function onAcyProcessFilterCount_joomlagroup(&$query, $filter, $num){
		$this->onAcyProcessFilter_joomlagroup($query, $filter, $num);
		return JText::sprintf('SELECTED_USERS', $query->count());
	}

	function onAcyProcessFilter_joomlagroup(&$query, $filter, $num){
		$operator = (empty($filter['type']) || $filter['type'] == 'IN') ? 'IS NOT NULL AND joomlauser'.$num.'.'.(ACYMAILING_J16 ? 'user_' : '').'id != 0' : "IS NULL";
		$filter['group'] = intval($filter['group']);

		if(!empty($filter['subgroups'])){
			$db = JFactory::getDBO();
			$groupTable = ACYMAILING_J16 ? 'usergroups' : 'core_acl_aro_groups';
			$db->setQuery('SELECT lft, rgt FROM #__'.$groupTable.' WHERE id = '.$filter['group']);
			$lftrgt = $db->loadObject();
			$db->setQuery('SELECT id FROM #__'.$groupTable.' WHERE lft > '.$lftrgt->lft.' AND rgt < '.$lftrgt->rgt);
			$allGroups = acymailing_loadResultArray($db);
			array_unshift($allGroups, $filter['group']);
			$value = ' IN ('.implode(', ', $allGroups).')';
		}else{
			$value = ' = '.$filter['group'];
		}

		if(!ACYMAILING_J16){
			$query->leftjoin['joomlauser'.$num] = "#__users AS joomlauser$num ON joomlauser$num.id = sub.userid AND joomlauser$num.gid".$value;
			$query->where[] = "joomlauser$num.id ".$operator;
		}else{
			$query->leftjoin['joomlauser'.$num] = "#__user_usergroup_map AS joomlauser$num ON joomlauser$num.user_id = sub.userid AND joomlauser$num.group_id".$value;
			$query->where[] = "joomlauser$num.user_id ".$operator;
		}
	}
}//endclass
taguser/taguser.xml000064400000004552152345456710010434 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing Tag : Joomla User Information</name>
	<creationDate>juin 2016</creationDate>
	<version>5.5.0</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved..</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin enables you to add informations of the Joomla user in the Newsletter</description>
	<files>
		<filename plugin="taguser">taguser.php</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-taguser"/>
		<param name="displayfilter_mail" type="radio" default="1" label="Display filter" description="Display the user fields filter and group filter on the Newsletter creation interface">
			<option value="0">JOOMEXT_NO</option>
			<option value="1">JOOMEXT_YES</option>
		</param>
		<param name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
			<option value="all">Always display this tag system</option>
			<option value="none">Don't display this tag system on the front-end</option>
		</param>
	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-taguser"/>
				<field name="displayfilter_mail" type="radio" default="1" label="Display filter" description="Display the user fields filter and group filter on the Newsletter creation interface">
					<option value="0">JOOMEXT_NO</option>
					<option value="1">JOOMEXT_YES</option>
				</field>
				<field name="frontendaccess" type="list" default="all" label="Front-end Access" description="You can restrict the access to this tag system with this option">
					<option value="all">Always display this tag system</option>
					<option value="none">Don't display this tag system on the front-end</option>
				</field>
			</fieldset>
		</fields>
	</config>
</extension>
template/index.html000064400000000054152345456710010367 0ustar00<html><body bgcolor="#FFFFFF"></body></html>template/template.php000064400000022522152345456710010722 0ustar00<?php
/**
 * @package	AcyMailing for Joomla!
 * @version	5.5.0
 * @author	acyba.com
 * @copyright	(C) 2009-2016 ACYBA S.A.R.L. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php

class plgAcymailingTemplate extends JPlugin{

	var $templates = array();
	var $tags = array();
	var $headerstyles = array();
	var $others = array();
	var $stylesheets = array();
	var $templateClass = '';
	var $config;

	function __construct(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('acymailing', 'template');
			$this->params = new acyParameter($plugin->params);
		}
		$this->config = acymailing_config();
		if(version_compare(PHP_VERSION, '5.0.0', '>=') && class_exists('DOMDocument') && function_exists('mb_convert_encoding')){
			require_once(ACYMAILING_FRONT.'inc'.DS.'emogrifier'.DS.'emogrifier.php');
		}
	}

	private function _applyTemplate(&$email, $addbody){
		if(empty($email->tempid)) return;

		if(!isset($this->templates[$email->tempid])){
			$this->headerstyles[$email->tempid] = array();
			$this->headerstyles[$email->tempid][] = '.ReadMsgBody{width: 100%;}';
			$this->headerstyles[$email->tempid][] = '.ExternalClass{width: 100%;}';
			$this->headerstyles[$email->tempid][] = 'div, p, a, li, td { -webkit-text-size-adjust:none; }';
			$this->headerstyles[$email->tempid][] = 'a[x-apple-data-detectors]{
			color: inherit !important;
			text-decoration: inherit !important;
			font-size: inherit !important;
			font-family: inherit !important;
			font-weight: inherit !i mportant;
			line-height: inherit !important;
			}';

			$this->templates[$email->tempid] = array();
			if(empty($this->templateClass)){
				$this->templateClass = acymailing_get('class.template');
			}
			if(!empty($email->template) && $email->tempid == $email->template->tempid){
				$template = $email->template;
			}else{
				$template = $email->template = $this->templateClass->get($email->tempid);
			}

			if(!empty($template->styles) OR !empty($template->stylesheet)){
				$this->stylesheets[$email->tempid] = $this->templateClass->buildCSS($template->styles, $template->stylesheet);

				if(preg_match_all('#@import[^;]*;#is', $this->stylesheets[$email->tempid], $results)){
					foreach($results[0] as $oneResult){
						array_unshift($this->headerstyles[$email->tempid], trim($oneResult));
					}
				}

				if(preg_match_all('#@media.*}[^{}]*}#Uis', $this->stylesheets[$email->tempid], $results)){

					foreach($results[0] as $oneResult){
						$this->stylesheets[$email->tempid] = str_replace($oneResult, '', $this->stylesheets[$email->tempid]);
						$this->headerstyles[$email->tempid][] = trim($oneResult);
					}
				}

				if(preg_match_all('#}([^}]+:hover[^{]*{[^{]*})#Uis', '} '.$this->stylesheets[$email->tempid], $results)){
					foreach($results[1] as $oneResult){
						$this->stylesheets[$email->tempid] = str_replace($oneResult, '', $this->stylesheets[$email->tempid]);
						$this->headerstyles[$email->tempid][] = trim($oneResult);
					}
				}
			}


			if(!empty($template->styles)){
				foreach($template->styles as $class => $style){
					if(empty($style)) continue;
					if(preg_match('#^tag_(.*)$#', $class, $result)){
						$this->tags[$email->tempid]['#< *'.$result[1].'((?:(?!style).)*)>#Ui'] = '<'.$result[1].' style="'.$style.'" $1>';
						if(strpos($style, '!important')) $this->headerstyles[$email->tempid][] = $result[1].'{ '.str_replace('!important', '', $style).' }';
					}elseif($class == 'color_bg'){
						$this->others[$email->tempid][$class] = $style;
					}else{
						$this->templates[$email->tempid]['class="'.$class.'"'] = 'style="'.$style.'"';
					}
				}
				if(!empty($template->styles['tag_a'])){
					$this->headerstyles[$email->tempid][] = 'a:visited{'.$template->styles['tag_a'].'}';
				}
			}
		}

		if($addbody AND !strpos($email->body, '</body>')){
			$before = '<html><head>'."\n";
			$before .= '<meta http-equiv="Content-Type" content="text/html; charset='.strtolower($this->config->get('charset')).'" />'."\n";
			$before .= '<meta name="viewport" content="width=device-width, initial-scale=1.0" />'."\n";
			$before .= '<title>'.$email->subject.'</title>'."\n";
			if(!empty($this->headerstyles[$email->tempid])){
				$before .= '<style type="text/css">'."\n";
				$before .= implode("\n", $this->headerstyles[$email->tempid])."\n";
				$before .= '</style>'."\n";
			}
			$before .= '</head>'."\n".'<body yahoo="fix"';
			if(!empty($this->others[$email->tempid]['color_bg'])) $before .= ' bgcolor="'.$this->others[$email->tempid]['color_bg'].'" ';
			$before .= '>'."\n";
			$email->body = $before.$email->body.'</body>'."\n".'</html>';
		}

		if(!empty($this->stylesheets[$email->tempid]) AND class_exists('acymailingEmogrifier')){
			$emogrifier = new acymailingEmogrifier($email->body, $this->stylesheets[$email->tempid]);
			$email->body = $emogrifier->emogrify();

			if(!$addbody AND strpos($email->body, '<!DOCTYPE') !== false){
				$email->body = preg_replace('#<\!DOCTYPE.*<body([^>]*)>#Usi', '', $email->body);
				$email->body = preg_replace('#</body>.*$#si', '', $email->body);
			}
		}else{
			if(!empty($this->templates[$email->tempid])){
				$email->body = str_replace(array_keys($this->templates[$email->tempid]), $this->templates[$email->tempid], $email->body);
			}

			if(!empty($this->tags[$email->tempid])){
				$email->body = preg_replace(array_keys($this->tags[$email->tempid]), $this->tags[$email->tempid], $email->body);
			}
		}

		$newbody = preg_replace('#(<(div|tr|td|table)[^>]*)title="[^"]*"#Uis', '$1', $email->body);
		if(!empty($newbody)) $email->body = $newbody;

		$newbody = preg_replace('# id="zone_[0-9]+"#Uis', ' ', $email->body);
		if(!empty($newbody)) $email->body = $newbody;

		$newbody = preg_replace('# *(acyeditor_text|acyeditor_picture|acyeditor_delete|acyeditor_sortable|ui-sortable) *#is', '', $email->body);
		$newbody = preg_replace('#(class|title|style|id)=" *"#Ui', '', $newbody);
		if(!empty($newbody)) $email->body = $newbody;
	}

	public function acymailing_replaceusertags(&$email, &$user, $send = true){

		if(!$email->sendHTML) return;

		if((!acymailing_level(1) || acymailing_level(4)) && !empty($email->type) && in_array($email->type,array('news','followup'))){
			$pict = '<div style="text-align:center;margin:10px auto;display:block;"><a target="_blank" href="https://www.acyba.com/?utm_source=acymailing&utm_medium=e-mail&utm_content=img&utm_campaign=powered-by"><img alt="Powered by AcyMailing" src="media/com_acymailing/images/poweredby.png" /></a></div>';

			if(strpos($email->body, '</body>')){
				$email->body = str_replace('</body>', $pict.'</body>', $email->body);
			}else{
				$email->body .= $pict;
			}
		}

		$this->_applyTemplate($email, $send);

		$email->body = preg_replace('#< *(tr|td|table)([^>]*)(style="[^"]*)background-image *: *url\(\'?([^)\']*)\'?\);?#Ui', '<$1 background="$4" $2 $3', $email->body);
		$email->body = acymailing_absoluteURL($email->body);

		if(preg_match_all('#< *img([^>]*)>#Ui', $email->body, $allPictures)){

			foreach($allPictures[0] as $i => $onePict){
				if(strpos($onePict, 'align=') !== false) continue;
				if(!preg_match('#(style="[^"]*)(float *: *)(right|left|top|bottom|middle)#Ui', $onePict, $pictParams)) continue;

				$newPict = str_replace('<img', '<img align="'.$pictParams[3].'" ', $onePict);

				$email->body = str_replace($onePict, $newPict, $email->body);

				if(strpos($onePict, 'hspace=') !== false) continue;

				$hspace = 5;
				if(preg_match('#margin(-right|-left)? *:([^";]*)#i', $onePict, $margins)){
					$currentMargins = explode(' ', trim($margins[2]));
					$myMargin = (count($currentMargins) > 1) ? $currentMargins[1] : $currentMargins[0];
					if(strpos($myMargin, 'px') !== false) $hspace = preg_replace('#[^0-9]#i', '', $myMargin);
				}

				$lastPict = str_replace('<img', '<img hspace="'.$hspace.'" ', $newPict);

				$email->body = str_replace($newPict, $lastPict, $email->body);
			}
		}

		if(!preg_match('#(<thead|<tfoot|< *tbody *[^> ]+ *>)#Ui', $email->body)){
			$email->body = preg_replace('#< *\/? *tbody *>#Ui', '', $email->body);
		}

		$email->body = preg_replace_callback('/src="([^"]* [^"]*)"/Ui', array($this, '_convertSpaces'), $email->body);

		$this->fixPictureSize($email->body);

		$acypluginsHelper = acymailing_get('helper.acyplugins');
		$acypluginsHelper->fixPictureDim($email->body);
	}//endfct

	public function _convertSpaces($matches){
		return "src='".str_replace(' ', '%20', $matches[1])."'";
	}

	private function fixPictureSize(&$body){
		if(!preg_match_all('#(<img)([^>]*>)#i', $body, $results)) return;

		$replace = array();
		$widthheight = array('width', 'height');
		foreach($results[0] as $num => $oneResult){
			$add = array();
			foreach($widthheight as $whword){
				if(preg_match('#'.$whword.' *=#i', $oneResult) || !preg_match('#[^a-z_\-]'.$whword.' *:([0-9 ]{1,8})px#i', $oneResult, $resultWH)) continue;

				if(empty($resultWH[1])) continue;
				$add[] = $whword.'="'.trim($resultWH[1]).'" ';
			}
			if(!empty($add)) $replace[$oneResult] = '<img '.implode(' ', $add).$results[2][$num];
		}

		if(empty($replace)) return;

		$body = str_replace(array_keys($replace), $replace, $body);
	}
}//endclass
template/template.xml000064400000002230152345456710010725 0ustar00<?xml version="1.0" encoding="utf-8"?>

<extension type="plugin" version="2.5" method="upgrade" group="acymailing">
	<name>AcyMailing Template Class Replacer</name>
	<creationDate>juin 2016</creationDate>
	<version>5.5.0</version>
	<author>Acyba</author>
	<authorEmail>dev@acyba.com</authorEmail>
	<authorUrl>http://www.acyba.com</authorUrl>
	<copyright>Copyright (C) 2009-2016 ACYBA SAS - All rights reserved.</copyright>
	<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
	<description>This plugin enables AcyMailing to replace CSS class in each email</description>
	<files>
		<filename plugin="template">template.php</filename>
	</files>
	<params addpath="/components/com_acymailing/params">
		<param name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-template"/>
	</params>
	<config>
		<fields name="params" addfieldpath="/components/com_acymailing/params">
			<fieldset name="basic">
				<field name="help" type="help" label="Help" description="Click on the help button to get some help" default="plugin-template"/>
			</fieldset>
		</fields>
	</config>
</extension>
index.html000064400000000054152345456710006554 0ustar00<html><body bgcolor="#FFFFFF"></body></html>