コード例 #1
0
ファイル: SendMail.php プロジェクト: khanhdeux/typo3test
 /**
  * Generate and send Email
  *
  * @param string $template Template file in Templates/Email/
  * @param array $receiver Combination of Email => Name
  * @param array $sender Combination of Email => Name
  * @param string $subject Mail subject
  * @param array $variables Variables for assignMultiple
  * @param array $typoScript Add TypoScript to overwrite values
  * @return bool mail was sent?
  */
 public function send($template, $receiver, $sender, $subject, $variables = array(), $typoScript = array())
 {
     // config
     $email = $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $this->cObj = $this->configurationManager->getContentObject();
     if (!empty($variables['user']) && method_exists($variables['user'], '_getProperties')) {
         $this->cObj->start($variables['user']->_getProperties());
     }
     if (!$this->cObj->cObjGetSingle($typoScript['_enable'], $typoScript['_enable.']) || count($receiver) === 0) {
         return FALSE;
     }
     // add embed images to mail body
     if ($this->cObj->cObjGetSingle($typoScript['embedImage'], $typoScript['embedImage.'])) {
         $images = GeneralUtility::trimExplode(',', $this->cObj->cObjGetSingle($typoScript['embedImage'], $typoScript['embedImage.']), 1);
         $imageVariables = array();
         foreach ($images as $image) {
             $imageVariables[] = $email->embed(\Swift_Image::fromPath($image));
         }
         $variables = array_merge($variables, array('embedImages' => $imageVariables));
     }
     /**
      * Generate and send Email
      */
     $email->setTo($receiver)->setFrom($sender)->setSubject($subject)->setCharset($GLOBALS['TSFE']->metaCharset)->setBody($this->getMailBody($template, $variables), 'text/html');
     // overwrite email receiver
     if ($this->cObj->cObjGetSingle($typoScript['receiver.']['email'], $typoScript['receiver.']['email.']) && $this->cObj->cObjGetSingle($typoScript['receiver.']['name'], $typoScript['receiver.']['name.'])) {
         $email->setTo(array($this->cObj->cObjGetSingle($typoScript['receiver.']['email'], $typoScript['receiver.']['email.']) => $this->cObj->cObjGetSingle($typoScript['receiver.']['name'], $typoScript['receiver.']['name.'])));
     }
     // overwrite email sender
     if ($this->cObj->cObjGetSingle($typoScript['sender.']['email'], $typoScript['sender.']['email.']) && $this->cObj->cObjGetSingle($typoScript['sender.']['name'], $typoScript['sender.']['name.'])) {
         $email->setFrom(array($this->cObj->cObjGetSingle($typoScript['sender.']['email'], $typoScript['sender.']['email.']) => $this->cObj->cObjGetSingle($typoScript['sender.']['name'], $typoScript['sender.']['name.'])));
     }
     // overwrite email subject
     if ($this->cObj->cObjGetSingle($typoScript['subject'], $typoScript['subject.'])) {
         $email->setSubject($this->cObj->cObjGetSingle($typoScript['subject'], $typoScript['subject.']));
     }
     // overwrite email CC receivers
     if ($this->cObj->cObjGetSingle($typoScript['cc'], $typoScript['cc.'])) {
         $email->setCc($this->cObj->cObjGetSingle($typoScript['cc'], $typoScript['cc.']));
     }
     // overwrite email priority
     if ($this->cObj->cObjGetSingle($typoScript['priority'], $typoScript['priority.'])) {
         $email->setPriority($this->cObj->cObjGetSingle($typoScript['priority'], $typoScript['priority.']));
     }
     // add attachments from typoscript
     if ($this->cObj->cObjGetSingle($typoScript['attachments'], $typoScript['attachments.'])) {
         $files = GeneralUtility::trimExplode(',', $this->cObj->cObjGetSingle($typoScript['attachments'], $typoScript['attachments.']), 1);
         foreach ($files as $file) {
             $email->attach(\Swift_Attachment::fromPath($file));
         }
     }
     $email->send();
     return $email->isSent();
 }
コード例 #2
0
 /**
  * Initialize Validator Function
  *
  * @return void
  */
 protected function init()
 {
     $this->configuration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
     $this->cObj = $this->configurationManager->getContentObject();
     $this->piVars = GeneralUtility::_GP('tx_femanager_pi1');
     $this->actionName = $this->piVars['__referrer']['@action'];
 }
コード例 #3
0
 /**
  * Get the URI for an AJAX Request.
  *
  * @return string the AJAX URI
  */
 protected function getAjaxUri()
 {
     list($table, $uid) = explode(':', $this->configurationManager->getContentObject()->currentRecord);
     $pluginName = $this->arguments['pluginName'];
     $extensionName = $this->arguments['extensionName'];
     $pluginNamespace = $this->extensionService->getPluginNamespace($extensionName, $pluginName);
     $arguments = $this->hasArgument('arguments') ? $this->arguments['arguments'] : array();
     $ajaxContext = array('record' => $table . '_' . $uid, 'path' => 'tt_content.list.20.' . str_replace('tx_', '', $pluginNamespace));
     $additionalParams['tx_typoscriptrendering']['context'] = json_encode($ajaxContext);
     $uriBuilder = $this->controllerContext->getUriBuilder();
     $argumentPrefix = $uriBuilder->getArgumentPrefix();
     $uriBuilder->reset()->setArguments(array_merge(array($argumentPrefix => $arguments), $additionalParams))->setSection($this->arguments['section'])->setAddQueryString(TRUE)->setArgumentsToBeExcludedFromQueryString(array($argumentPrefix, 'cHash'))->setFormat($this->arguments['format'])->setUseCacheHash(TRUE);
     // TYPO3 6.0 compatibility check:
     if (method_exists($uriBuilder, 'setAddQueryStringMethod')) {
         $uriBuilder->setAddQueryStringMethod($this->arguments['addQueryStringMethod']);
     }
     return $uriBuilder->build();
 }
コード例 #4
0
 /**
  * @param null $hashVars
  * @return string
  */
 private function getCacheID($hashVars = null)
 {
     $additionalHashVars = array('pid' => $GLOBALS['TSFE']->id, 'lang' => $GLOBALS['TSFE']->sys_language_uid, 'uid' => $this->_configurationManager->getContentObject()->data['uid']);
     if (!is_null($GLOBALS['TSFE']->fe_user->user)) {
         $additionalHashVars[] = $GLOBALS['TSFE']->fe_user->user['ses_id'];
     }
     $additionalHashVars = array_merge($additionalHashVars, $this->_request->getArguments());
     $hashVars = array_merge($additionalHashVars, $hashVars);
     $hashString = join('|', array_values($hashVars)) . join('|', array_keys($hashVars));
     return md5($hashString);
 }
コード例 #5
0
 /**
  * @param string $action Target action
  * @param array $arguments Arguments
  * @param string $controller Target controller. If NULL current controllerName is used
  * @param string $extensionName Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used
  * @param string $pluginName Target plugin. If empty, the current plugin name is used
  * @param integer $pageUid target page. See TypoLink destination
  * @param string $section the anchor to be added to the URI
  * @param string $format The requested format, e.g. ".html
  * @param boolean $linkAccessRestrictedPages If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.
  * @param array $additionalParams additional query parameters that won't be prefixed like $arguments (overrule $arguments)
  * @param boolean $absolute If set, an absolute URI is rendered
  * @param boolean $addQueryString If set, the current query parameters will be kept in the URI
  * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE
  * @param string $addQueryStringMethod Set which parameters will be kept. Only active if $addQueryString = TRUE
  * @param string $contextRecord The record that the rendering should depend upon. e.g. current (default: record is fetched from current Extbase plugin), tt_content:12 (tt_content record with uid 12), pages:15 (pages record with uid 15), 'currentPage' record of current page
  * @return string Rendered link
  */
 public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $pageUid = NULL, $section = '', $format = '', $linkAccessRestrictedPages = FALSE, array $additionalParams = array(), $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $addQueryStringMethod = NULL, $contextRecord = 'current')
 {
     if ($contextRecord === 'current') {
         $contextRecord = $this->configurationManager->getContentObject()->currentRecord;
     }
     if ($pluginName === NULL) {
         $pluginName = $this->controllerContext->getRequest()->getPluginName();
     }
     if ($extensionName === NULL) {
         $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
     }
     $renderingConfiguration = $this->buildTypoScriptRenderingConfiguration($extensionName, $pluginName, $contextRecord);
     $additionalParams['tx_typoscriptrendering']['context'] = json_encode($renderingConfiguration);
     $uriBuilder = $this->controllerContext->getUriBuilder();
     $uriBuilder->reset()->setTargetPageUid($pageUid)->setUseCacheHash(TRUE)->setSection($section)->setFormat($format)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString);
     // TYPO3 6.0 compatibility check:
     if (method_exists($uriBuilder, 'setAddQueryStringMethod')) {
         $uriBuilder->setAddQueryStringMethod($addQueryStringMethod);
     }
     return $uriBuilder->uriFor($action, $arguments, $controller, $extensionName, $pluginName);
 }
コード例 #6
0
 /**
  * Initialize Validator Function
  *
  * @return void
  */
 protected function init()
 {
     $this->cObj = $this->configurationManager->getContentObject();
     $piVars = GeneralUtility::_GP('tx_femanager_pi1');
     $this->actionName = $piVars['__referrer']['@action'];
 }
コード例 #7
0
 /**
  * Returns TRUE if what we are outputting may be cached
  *
  * @return boolean
  */
 protected function isCached()
 {
     $userObjType = $this->configurationManager->getContentObject()->getUserObjectType();
     return $userObjType !== ContentObjectRenderer::OBJECTTYPE_USER_INT;
 }
コード例 #8
0
ファイル: Div.php プロジェクト: woehrlag/Intranet
 /**
  * Generate and send Email
  *
  * @param \string $template					Template file in Templates/Email/
  * @param \array $receiver					Combination of Email => Name
  * @param \array $sender					Combination of Email => Name
  * @param \string $subject					Mail subject
  * @param \array $variables					Variables for assignMultiple
  * @param \array $typoScript				Add TypoScript to overwrite values
  * @return \bool							Mail was sent?
  */
 public function sendEmail($template, $receiver, $sender, $subject, $variables = array(), $typoScript = array())
 {
     // config
     $email = $this->objectManager->get('\\TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $this->cObj = $this->configurationManager->getContentObject();
     if (!empty($variables['user']) && method_exists($variables['user'], '_getProperties')) {
         $this->cObj->start($variables['user']->_getProperties());
     }
     if (!$this->cObj->cObjGetSingle($typoScript['_enable'], $typoScript['_enable.']) || count($receiver) === 0) {
         return FALSE;
     }
     // add embed images to mail body
     if ($this->cObj->cObjGetSingle($typoScript['embedImage'], $typoScript['embedImage.'])) {
         $images = GeneralUtility::trimExplode(',', $this->cObj->cObjGetSingle($typoScript['embedImage'], $typoScript['embedImage.']), 1);
         $imageVariables = array();
         foreach ($images as $image) {
             $imageVariables[] = $email->embed(\Swift_Image::fromPath($image));
         }
         $variables = array_merge($variables, array('embedImages' => $imageVariables));
     }
     /**
      * Generate Email Body
      */
     $emailBodyObject = $this->objectManager->get('\\TYPO3\\CMS\\Fluid\\View\\StandaloneView');
     $emailBodyObject->getRequest()->setControllerExtensionName('Femanager');
     $emailBodyObject->getRequest()->setPluginName('Pi1');
     $emailBodyObject->getRequest()->setControllerName('New');
     $emailBodyObject->setTemplatePathAndFilename($this->getTemplatePath('Email/' . ucfirst($template) . '.html'));
     $emailBodyObject->setLayoutRootPath($this->getTemplateFolder('layout'));
     $emailBodyObject->setPartialRootPath($this->getTemplateFolder('partial'));
     $emailBodyObject->assignMultiple($variables);
     /**
      * Generate and send Email
      */
     $email->setTo($receiver)->setFrom($sender)->setSubject($subject)->setCharset($GLOBALS['TSFE']->metaCharset)->setBody($emailBodyObject->render(), 'text/html');
     // overwrite email receiver
     if ($this->cObj->cObjGetSingle($typoScript['receiver.']['email'], $typoScript['receiver.']['email.']) && $this->cObj->cObjGetSingle($typoScript['receiver.']['name'], $typoScript['receiver.']['name.'])) {
         $email->setTo(array($this->cObj->cObjGetSingle($typoScript['receiver.']['email'], $typoScript['receiver.']['email.']) => $this->cObj->cObjGetSingle($typoScript['receiver.']['name'], $typoScript['receiver.']['name.'])));
     }
     // overwrite email sender
     if ($this->cObj->cObjGetSingle($typoScript['sender.']['email'], $typoScript['sender.']['email.']) && $this->cObj->cObjGetSingle($typoScript['sender.']['name'], $typoScript['sender.']['name.'])) {
         $email->setFrom(array($this->cObj->cObjGetSingle($typoScript['sender.']['email'], $typoScript['sender.']['email.']) => $this->cObj->cObjGetSingle($typoScript['sender.']['name'], $typoScript['sender.']['name.'])));
     }
     // overwrite email subject
     if ($this->cObj->cObjGetSingle($typoScript['subject'], $typoScript['subject.'])) {
         $email->setSubject($this->cObj->cObjGetSingle($typoScript['subject'], $typoScript['subject.']));
     }
     // overwrite email CC receivers
     if ($this->cObj->cObjGetSingle($typoScript['cc'], $typoScript['cc.'])) {
         $email->setCc($this->cObj->cObjGetSingle($typoScript['cc'], $typoScript['cc.']));
     }
     // overwrite email priority
     if ($this->cObj->cObjGetSingle($typoScript['priority'], $typoScript['priority.'])) {
         $email->setPriority($this->cObj->cObjGetSingle($typoScript['priority'], $typoScript['priority.']));
     }
     // add attachments from typoscript
     if ($this->cObj->cObjGetSingle($typoScript['attachments'], $typoScript['attachments.'])) {
         $files = GeneralUtility::trimExplode(',', $this->cObj->cObjGetSingle($typoScript['attachments'], $typoScript['attachments.']), 1);
         foreach ($files as $file) {
             $email->attach(\Swift_Attachment::fromPath($file));
         }
     }
     $email->send();
     return $email->isSent();
 }