public function getPlainText($content, $baseUrl) { $tmpFile = tempnam(sys_get_temp_dir(), 'html'); file_put_contents($tmpFile, $content); $cmd = escapeshellcmd(Tx_Newsletter_Tools::confParam('path_to_lynx')) . ' -dump -stdin < ' . escapeshellarg($tmpFile); exec($cmd, $output); unlink($tmpFile); $plainText = implode("\n", $output); return $plainText; }
/** * index action for the module controller * This will render the HTML needed for ExtJS application * * @return void */ public function indexAction() { $pageType = ''; $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('doktype', 'pages', 'uid =' . $this->pageId); if (!empty($record['doktype']) && $record['doktype'] == 254) { $pageType = 'folder'; } elseif (!empty($record['doktype'])) { $pageType = 'page'; } $configuration = array('pageId' => $this->pageId, 'pageType' => $pageType, 'emailShowUrl' => Tx_Newsletter_Tools::buildFrontendUri('show', array(), 'Email')); $this->view->assign('configuration', $configuration); }
/** * This method is designed to return some additional information about the task, * that may help to set it apart from other tasks from the same class * This additional information is used - for example - in the Scheduler's BE module * This method should be implemented in most task classes * * @return string Information to display */ public function getAdditionalInformation() { $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Extbase_Object_ObjectManager'); $newsletterRepository = $objectManager->get('Tx_Newsletter_Domain_Repository_NewsletterRepository'); $emailNotSentCount = 0; $newsletters = $newsletterRepository->findAllReadyToSend(); $newsletterCount = count($newsletters); foreach ($newsletters as $newsletter) { $emailNotSentCount += $newsletter->getEmailNotSentCount(); } $emailsPerRound = Tx_Newsletter_Tools::confParam('mails_per_round'); return Tx_Extbase_Utility_Localization::translate('task_send_emails_additional_information', 'newsletter', array($emailsPerRound, $emailNotSentCount, $newsletterCount)); }
/** * Returns the URL of the content of this newsletter * @return string */ public function getContentUrl($language = null) { $append_url = Tx_Newsletter_Tools::confParam('append_url'); $domain = $this->getDomain(); if (!is_null($language)) { $language = '&L=' . $language; } return "http://{$domain}/index.php?no_cache=1&id=" . $this->getPid() . $language . $append_url; }
/** * Sends an email to the address configured in extension settings when a recipient unsubscribe * @param Tx_Newsletter_Domain_Model_Newsletter $newsletter * @param Tx_Newsletter_Domain_Model_RecipientList $recipientList * @param Tx_Newsletter_Domain_Model_Email $email * @return void */ protected function notifyUnsubscribe($newsletter, $recipientList, Tx_Newsletter_Domain_Model_Email $email) { $notificationEmail = Tx_Newsletter_Tools::confParam('notification_email'); // Use the page-owner as user if ($notificationEmail == 'user') { $rs = $GLOBALS['TYPO3_DB']->sql_query("SELECT email\n\t\t\tFROM be_users\n\t\t\tLEFT JOIN pages ON be_users.uid = pages.perms_userid\n\t\t\tWHERE pages.uid = " . $newsletter->getPid()); list($notificationEmail) = $GLOBALS['TYPO3_DB']->sql_fetch_row($rs); } // If cannot find valid email, don't send any notification if (!\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($notificationEmail)) { return; } // Build email texts $baseUrl = 'http://' . $newsletter->getDomain(); $urlRecipient = $baseUrl . '/typo3/alt_doc.php?&edit[tx_newsletter_domain_model_email][' . $email->getUid() . ']=edit'; $urlRecipientList = $baseUrl . '/typo3/alt_doc.php?&edit[tx_newsletter_domain_model_recipientlist][' . $recipientList->getUid() . ']=edit'; $urlNewsletter = $baseUrl . '/typo3/alt_doc.php?&edit[tx_newsletter_domain_model_newsletter][' . $newsletter->getUid() . ']=edit'; $subject = Tx_Extbase_Utility_Localization::translate('unsubscribe_notification_subject', 'newsletter'); $body = Tx_Extbase_Utility_Localization::translate('unsubscribe_notification_body', 'newsletter', array($email->getRecipientAddress(), $urlRecipient, $recipientList->getTitle(), $urlRecipientList, $newsletter->getTitle(), $urlNewsletter)); // Actually sends email $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage'); $message->setTo($notificationEmail)->setFrom(array($newsletter->getSenderEmail() => $newsletter->getSenderName()))->setSubject($subject)->setBody($body, 'text/html'); $message->send(); }
/** * Return HTML code showing an extract of recipients (first X recipients) */ public function getExtract($limit = 30) { if ($this->getError()) { $out = "Error: " . $this->getError(); } else { $i = 0; while ($row = $this->getRecipient()) { // Dump formatted table header if ($i == 0) { $out .= '<tr>'; foreach (array_keys($row) as $key) { $out .= '<th style="padding-right: 1em;">' . $this->getFieldTitle($key) . "</th>"; } $out .= '</tr>'; } $out .= '<tr style="border: 1px grey solid; border-collapse: collapse;">'; foreach ($row as $field) { $out .= '<td style="padding-right: 1em;">' . $field . '</td>'; } $out .= '</tr>'; if (++$i == $limit) { break; } } $out = '<table style="border: 1px grey solid; border-collapse: collapse;">' . $out . '</table>'; $authCode = \TYPO3\CMS\Core\Utility\GeneralUtility::stdAuthCode($this->_getCleanProperties()); $uriXml = Tx_Newsletter_Tools::buildFrontendUri('export', array('uidRecipientList' => $this->getUid(), 'authCode' => $authCode, 'format' => 'xml'), 'RecipientList'); $uriCsv = Tx_Newsletter_Tools::buildFrontendUri('export', array('uidRecipientList' => $this->getUid(), 'authCode' => $authCode, 'format' => 'csv'), 'RecipientList'); $out .= '<p><strong>' . $i . '/' . $this->getCount() . '</strong> recipients (<a href="' . $uriXml . "\">export XML</a>, " . '<a href="' . $uriCsv . "\">export CSV</a>" . ')</p>'; } $out = '<h4>' . $this->getTitle() . '</h4>' . $out; return $out; }
private function getLinkAuthCode(Tx_Newsletter_Domain_Model_Email $email, $url, $isPreview, $isPlainText = false) { global $TYPO3_DB; $url = html_entity_decode($url); // First check in our local cache if (isset($this->linksCache[$url])) { $linkId = $this->linksCache[$url]; } elseif ($isPreview) { $linkId = count($this->linksCache); } else { // Look for the link database, it may already exist $res = $TYPO3_DB->sql_query('SELECT uid FROM tx_newsletter_domain_model_link WHERE url = "' . $url . '" AND newsletter = ' . $this->newsletter->getUid() . ' LIMIT 1'); $row = $TYPO3_DB->sql_fetch_row($res); if ($row) { $linkId = $row[0]; } else { $TYPO3_DB->exec_INSERTquery('tx_newsletter_domain_model_link', array('pid' => $this->newsletter->getPid(), 'url' => $url, 'newsletter' => $this->newsletter->getUid())); $linkId = $TYPO3_DB->sql_insert_id(); } } // Store link in cache $this->linksCache[$url] = $linkId; $authCode = md5($email->getAuthCode() . $linkId); $newUrl = Tx_Newsletter_Tools::buildFrontendUri('clicked', array(), 'Link') . '&url=' . urlencode($url) . '&n=' . $this->newsletter->getUid() . '&l=' . $authCode . ($isPlainText ? '&p=1' : ''); return $newUrl; }
/** * Dispatch actions to take according to current bounce level */ public function dispatch() { $this->findEmail(); // If couldn't find the original email we cannot do anything if (!$this->email) { Tx_Newsletter_Tools::log("Bounced email found but cannot find corresponding record in database. Skipped.", 1); return; } if ($this->bounceLevel != self::NEWSLETTER_NOT_A_BOUNCE) { if ($this->recipientList) { $this->recipientList->registerBounce($this->email->getRecipientAddress(), $this->bounceLevel); } $this->email->setBounceTime(new DateTime()); $emailRepository = $this->objectManager->get('Tx_Newsletter_Domain_Repository_EmailRepository'); $emailRepository->updateNow($this->email); } Tx_Newsletter_Tools::log("Bounced email found with bounce level " . $this->bounceLevel); }
/** * Returns a frontend URI independently of current context, with or without extbase, and with or without TSFE * @param string $actionName * @param array $controllerArguments * @param string $controllerName * @param string $extensionName * @param string $pluginName * @return string absolute URI */ public static function buildFrontendUri($actionName, array $controllerArguments, $controllerName, $extensionName = 'newsletter', $pluginName = 'p') { if (!self::$uriBuilder) { self::$uriBuilder = self::buildUriBuilder($extensionName, $pluginName); } $controllerArguments['action'] = $actionName; $controllerArguments['controller'] = $controllerName; $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Extbase_Object_ObjectManager'); $extensionService = $objectManager->get('Tx_Extbase_Service_ExtensionService'); $pluginNamespace = $extensionService->getPluginNamespace($extensionName, $pluginName); $arguments = array($pluginNamespace => $controllerArguments); self::$uriBuilder->reset()->setUseCacheHash(FALSE)->setCreateAbsoluteUri(TRUE)->setArguments($arguments); return self::$uriBuilder->buildFrontendUri() . '&type=1342671779'; }
/** * Creates a new Newsletter and forwards to the list action. * * @param Tx_Newsletter_Domain_Model_Newsletter $newNewsletter a fresh Newsletter object which has not yet been added to the repository * @return void * @dontverifyrequesthash * @dontvalidate $newNewsletter * @ignorevalidation $newNewsletter */ public function createAction(Tx_Newsletter_Domain_Model_Newsletter $newNewsletter = null) { $limitTestRecipientCount = 10; // This is a low limit, technically, but it does not make sense to test a newsletter for more people than that anyway $recipientList = $newNewsletter->getRecipientList(); $recipientList->init(); $count = $recipientList->getCount(); $validatedContent = $newNewsletter->getValidatedContent($language); // If we attempt to create a newsletter as a test but it has too many recipient, reject it (we cannot safely send several emails wihtout slowing down respoonse and/or timeout issues) if ($newNewsletter->getIsTest() && $count > $limitTestRecipientCount) { $this->addFlashMessage(Tx_Extbase_Utility_Localization::translate('flashmessage_test_maximum_recipients', 'newsletter', array($count, $limitTestRecipientCount)), Tx_Extbase_Utility_Localization::translate('flashmessage_test_maximum_recipients_title', 'newsletter'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); $this->view->assign('success', FALSE); } elseif (count($validatedContent['errors'])) { $this->addFlashMessage('The newsletter HTML content does not validate. See tab "Newsletter > Status" for details.', Tx_Extbase_Utility_Localization::translate('flashmessage_newsletter_invalid', 'newsletter'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); $this->view->assign('success', FALSE); } else { // If it's a test newsletter, it's planned to be sent right now if ($newNewsletter->getIsTest()) { $newNewsletter->setPlannedTime(new DateTime()); } // Save the new newsletter $this->newsletterRepository->add($newNewsletter); $this->persistenceManager->persistAll(); $this->view->assign('success', TRUE); // If it is test newsletter, send it immediately if ($newNewsletter->getIsTest()) { try { // Fill the spool and run the queue Tx_Newsletter_Tools::createSpool($newNewsletter); Tx_Newsletter_Tools::runSpoolOne($newNewsletter); $this->addFlashMessage(Tx_Extbase_Utility_Localization::translate('flashmessage_test_newsletter_sent', 'newsletter'), Tx_Extbase_Utility_Localization::translate('flashmessage_test_newsletter_sent_title', 'newsletter'), \TYPO3\CMS\Core\Messaging\FlashMessage::OK); } catch (Exception $exception) { $this->addFlashMessage($exception->getMessage(), Tx_Extbase_Utility_Localization::translate('flashmessage_test_newsletter_error', 'newsletter'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); } } else { $this->addFlashMessage(Tx_Extbase_Utility_Localization::translate('flashmessage_newsletter_queued', 'newsletter'), Tx_Extbase_Utility_Localization::translate('flashmessage_newsletter_queued_title', 'newsletter'), \TYPO3\CMS\Core\Messaging\FlashMessage::OK); } } $this->view->setVariablesToRender(array('data', 'success', 'flashMessages')); $this->view->setConfiguration(array('data' => self::resolveJsonViewConfiguration())); $this->view->assign('data', $newNewsletter); $this->view->assign('flashMessages', $this->controllerContext->getFlashMessageQueue()->getAllMessagesAndFlush()); }