/**
	 * Parses variables again
	 *
	 * @param	array		Variables and Markers array
	 * @param	array		Variables and Labels array
	 * @param	string		"web" or "mail"
	 * @return 	string		Changed string
	 */
	public function render($variablesMarkers = array(), $variablesLabels = array(), $type = 'web') {
		$parseObject = $this->objectManager->create('Tx_Fluid_View_StandaloneView');
		$parseObject->setTemplateSource($this->renderChildren());
		$parseObject->assignMultiple($this->div->htmlspecialcharsOnArray($variablesMarkers));

		$powermailAll = $this->div->powermailAll($variablesLabels, $this->configurationManager, $this->objectManager, $type, $this->settings);
		$parseObject->assign('powermail_all', $powermailAll);

		return html_entity_decode($parseObject->render());
	}
Example #2
0
	/**
	 * Returns the value
	 *
	 * @return string $value
	 */
	public function getValue() {
		// workarround to get array from database (checkbox values)
		if (Tx_Powermail_Utility_Div::is_serialized($this->value)) {
			return unserialize($this->value);
		}
		return $this->value;
	}
	/**
	 * Initializes the current action
	 *
	 * @return void
	 */
	protected function initializeAction() {
		$this->div = t3lib_div::makeInstance('Tx_Powermail_Utility_Div');
		Tx_Powermail_Utility_Div::mergeTypoScript2FlexForm($this->settings, 'Pi2'); // merge typoscript to flexform
		$this->piVars = $this->request->getArguments();

		// check if ts is included
		if (!isset($this->settings['staticTemplate'])) {
			$this->flashMessageContainer->add(Tx_Extbase_Utility_Localization::translate('error_no_typoscript_pi2', 'powermail'));
		}
	}
	/**
	 * Validation of given Params
	 *
	 * @param array $field
	 * @return bool
	 */
	public function isValid($field) {
		if (isset($_FILES['tx_powermail_pi1']['name']['field'])) {
			// session stuff
			$uploadSession = array();
			Tx_Powermail_Utility_Div::setSessionValue('upload', array(), true); // clean old session before

			foreach ($_FILES['tx_powermail_pi1']['name']['field'] as $uid => $filename) {

				// if no file given
				if (empty($filename)) {
					continue;
				}

				// Check extension
				if (!$this->checkExtension($filename, $uid)) {
					continue;
				}

				// Check filesize
				if (!$this->checkFilesize($uid)) {
					continue;
				}

				// create new filename with absolute path
				$newFile = $this->basicFileFunctions->getUniqueName($filename, t3lib_div::getFileAbsFileName($this->settings['misc.']['file.']['folder']));
				$uploadSession[] = $newFile; // create array for upload session
				if (!t3lib_div::upload_copy_move($_FILES['tx_powermail_pi1']['tmp_name']['field'][$uid], $newFile)) {
					$this->addError('upload_error', $uid);
					$this->isValid = false;
				}
			}

			// save uploaded filenames to session (to attach it later)
			Tx_Powermail_Utility_Div::setSessionValue('upload', $uploadSession, true);
		}

		return $this->isValid;
  	}
	/**
	 * Check if logged in User is allowed to edit
	 *
	 * @param 	array 		TypoScript and FlexForm Settings
	 * @param 	object 		Mail Object
	 * @return 	boolean
	 */
	public function render($settings = array(), $mail) {
		if ($this->div->isAllowedToEdit($settings, $mail)) {
			return true;
		}
		return false;
    }
	/**
	 * Initializes the current action
	 *
	 * @return void
	 */
	protected function initializeAction() {
		$this->cObj = $this->configurationManager->getContentObject();
		$typoScriptSetup = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
		$this->conf = $typoScriptSetup['plugin.']['tx_powermail.']['settings.']['setup.'];
		$this->div = t3lib_div::makeInstance('Tx_Powermail_Utility_Div');
		Tx_Powermail_Utility_Div::mergeTypoScript2FlexForm($this->settings); // merge typoscript to flexform (if flexform field also exists and is empty, take typoscript part)
		$this->signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__ . 'Settings', array($this));

		// check if ts is included
		if (!isset($this->settings['staticTemplate'])) {
			$this->flashMessageContainer->add(Tx_Extbase_Utility_Localization::translate('error_no_typoscript', 'powermail'));
		}

		// Debug Output
		if ($this->settings['debug']['settings']) {
			t3lib_utility_Debug::debug($this->settings, 'powermail debug: Show Settings');
		}
	}
	/**
	 * Reporting Marketing
	 *
	 * @return void
	 */
	public function reportingMarketingBeAction() {
		$mails = $this->mailsRepository->findAllInPid(t3lib_div::_GP('id'), $this->settings, $this->piVars);
		$firstMail = $this->mailsRepository->findFirstInPid(t3lib_div::_GP('id'));
		$groupedMarketingStuff = Tx_Powermail_Utility_Div::getGroupedMarketingStuff($mails);

		$this->view->assign('groupedMarketingStuff', $groupedMarketingStuff);
		$this->view->assign('mails', $mails);
		$this->view->assign('firstMail', $firstMail);
		$this->view->assign('piVars', $this->piVars);
		$this->view->assign('pid', t3lib_div::_GP('id'));
		$this->view->assign('token', t3lib_BEfunc::getUrlToken('tceAction'));
		$this->view->assign('perPage', ($this->settings['perPage'] ? $this->settings['perPage'] : 10));
	}
	/**
	 * Session Check: Checks if session was started correct on form delivery
	 *
	 * @param float $indication Indication if check fails
	 * @return void
	 */
	protected function sessionCheck($indication = 1.0) {
		// Stop sessionCheck if indicator was turned to 0 OR if last action was optinConfirm
		if (!$indication || $this->referrer == 'optinConfirm') {
			return;
		}
		$gp = t3lib_div::_GP('tx_powermail_pi1');
		$formUid = $gp['form'];
		$time = Tx_Powermail_Utility_Div::getFormStartFromSession($formUid);

		// if check failes
		if (!isset($time) || !$time) {
			$this->spamIndicator += $indication;
			$this->msg[] = __FUNCTION__ . ' failed';
		}
		return;
	}
Example #9
0
	/**
	 * This is the main-function for sending Mails
	 *
	 * @param array $mail Array with all needed mail information
	 * 		$mail['receiverName'] = 'Name';
	 * 		$mail['receiverEmail'] = '*****@*****.**';
	 *		$mail['senderName'] = 'Name';
	 * 		$mail['senderEmail'] = '*****@*****.**';
	 * 		$mail['subject'] = 'Subject line';
	 * 		$mail['template'] = 'PathToTemplate/';
	 * 		$mail['rteBody'] = 'This is the <b>content</b> of the RTE';
	 * 		$mail['format'] = 'both'; // or plain or html
	 * @param array $fields All arguments from POST or GET
	 * @param array $settings TypoScript Settings
	 * @param string $type Email to "sender" or "receiver"
	 * @param Tx_Extbase_Object_ObjectManager $objectManager
	 * @param object $configurationManager
	 * @return boolean Mail was successfully sent?
	 */
	public function sendTemplateEmail($mail, $fields, $settings, $type, $objectManager, $configurationManager) {
		/*****************
		 * Settings
		 ****************/
		$cObj = $configurationManager->getContentObject();
		$typoScriptService = $objectManager->get('Tx_Extbase_Service_TypoScriptService');
		$conf = $typoScriptService->convertPlainArrayToTypoScriptArray($settings);

		// parsing variables with fluid engine to allow viewhelpers and variables in some flexform fields
		$parse = array(
			'receiverName',
			'receiverEmail',
			'senderName',
			'senderEmail',
			'subject'
		);
		foreach ($parse as $value) {
			$mail[$value] = $this->fluidParseString($mail[$value], $objectManager, $this->getVariablesWithMarkers($fields));
		}

		// Debug Output
		if ($settings['debug']['mail']) {
			t3lib_utility_Debug::debug($mail, 'powermail debug: Show Mail');
		}

		// stop mail process if receiver or sender email is not valid
		if (!t3lib_div::validEmail($mail['receiverEmail']) || !t3lib_div::validEmail($mail['senderEmail'])) {
			return false;
		}

		// stop mail process if subject is empty
		if (empty($mail['subject'])) {
			return false;
		}

		// generate mail body
		$extbaseFrameworkConfiguration = $configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
		$templatePathAndFilename = t3lib_div::getFileAbsFileName($extbaseFrameworkConfiguration['view']['templateRootPath']) . $mail['template'] . '.html';
		$emailView = $objectManager->create('Tx_Fluid_View_StandaloneView');
		$emailView->getRequest()->setControllerExtensionName('Powermail'); // extension name for translate viewhelper
		$emailView->getRequest()->setPluginName('Pi1');
		$emailView->getRequest()->setControllerName('Forms');
		$emailView->setFormat('html');
		$emailView->setTemplatePathAndFilename($templatePathAndFilename);
		$emailView->setPartialRootPath(t3lib_div::getFileAbsFileName($extbaseFrameworkConfiguration['view']['partialRootPath']));
		$emailView->setLayoutRootPath(t3lib_div::getFileAbsFileName($extbaseFrameworkConfiguration['view']['layoutRootPath']));

		// get variables
			// additional variables
		if (isset($mail['variables']) && is_array($mail['variables'])) {
			$emailView->assignMultiple($mail['variables']);
		}
			// markers in HTML Template
		$variablesWithMarkers = $this->getVariablesWithMarkers($fields);
		$emailView->assign('variablesWithMarkers', $this->htmlspecialcharsOnArray($variablesWithMarkers));
		$emailView->assignMultiple($variablesWithMarkers);
			// powermail_all
		$variables = $this->getVariablesWithLabels($fields);
		$content = $this->powermailAll($variables, $configurationManager, $objectManager, 'mail', $settings);
		$emailView->assign('powermail_all', $content);
			// from rte
		$emailView->assign('powermail_rte', $mail['rteBody']);
		$variablesWithLabels = $this->getVariablesWithLabels($fields);
		$emailView->assign('variablesWithLabels', $variablesWithLabels);
		$emailView->assign('marketingInfos', self::getMarketingInfos());
		$emailBody = $emailView->render();


		/*****************
		 * generate mail
		 ****************/
		$message = t3lib_div::makeInstance('t3lib_mail_Message');
		$message
			->setTo(array($mail['receiverEmail'] => $mail['receiverName']))
			->setFrom(array($mail['senderEmail'] => $mail['senderName']))
			->setSubject($mail['subject'])
			->setCharset($GLOBALS['TSFE']->metaCharset);

		// overwrite subject
		if ($cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['subject'], $conf[$type . '.']['overwrite.']['subject.'])) {
			$message->setSubject($cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['subject'], $conf[$type . '.']['overwrite.']['subject.']));
		}

		// add cc receivers
		if ($cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['cc'], $conf[$type . '.']['overwrite.']['cc.'])) {
			$ccArray = t3lib_div::trimExplode(',', $cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['cc'], $conf[$type . '.']['overwrite.']['cc.']), 1);
			$message->setCc($ccArray);
		}

		// add bcc receivers
		if ($cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['bcc'], $conf[$type . '.']['overwrite.']['bcc.'])) {
			$bccArray = t3lib_div::trimExplode(',', $cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['bcc'], $conf[$type . '.']['overwrite.']['bcc.']), 1);
			$message->setBcc($bccArray);
		}

		// add Return Path
		if ($cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['returnPath'], $conf[$type . '.']['overwrite.']['returnPath.'])) {
			$message->setReturnPath($cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['returnPath'], $conf[$type . '.']['overwrite.']['returnPath.']));
		}

		// add Reply Addresses
		if (
			$cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['replyToEmail'], $conf[$type . '.']['overwrite.']['replyToEmail.'])
			&&
			$cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['replyToName'], $conf[$type . '.']['overwrite.']['replyToName.'])
		) {
			$replyArray = array(
				$cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['replyToEmail'], $conf[$type . '.']['overwrite.']['replyToEmail.']) =>
					$cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['replyToName'], $conf[$type . '.']['overwrite.']['replyToName.'])
			);
			$message->setReplyTo($replyArray);
		}

		// add priority
		if ($settings[$type]['overwrite']['priority']) {
			$message->setPriority(intval($settings[$type]['overwrite']['priority']));
		}

		// add attachments from upload fields
		if ($settings[$type]['attachment']) {
			$uploadsFromSession = Tx_Powermail_Utility_Div::getSessionValue('upload'); // read upload session
			foreach ((array) $uploadsFromSession as $file) {
				$message->attach(Swift_Attachment::fromPath($file));
			}
		}

		// add attachments from typoscript
		if ($cObj->cObjGetSingle($conf[$type . '.']['addAttachment'], $conf[$type . '.']['addAttachment.'])) {
			$files = t3lib_div::trimExplode(',', $cObj->cObjGetSingle($conf[$type . '.']['addAttachment'], $conf[$type . '.']['addAttachment.']), 1);
			foreach ($files as $file) {
				$message->attach(Swift_Attachment::fromPath($file));
			}
		}
		if ($mail['format'] != 'plain') {
			$message->setBody($emailBody, 'text/html');
		}
		if ($mail['format'] != 'html') {
			$message->addPart($this->makePlain($emailBody), 'text/plain');
		}
		$message->send();

		return $message->isSent();
	}
Example #10
0
	/**
	 * Returns the settings
	 * 		option1 =>
	 * 			label => Red Shoes
	 * 			value => red
	 * 			selected => 1
	 *
	 * @return string $settings
	 */
	public function getSettings() {
		return Tx_Powermail_Utility_Div::optionArray($this->settings);
	}