/** * Get the link with auth code. * * @param Email $email * @param string $url * @param bool $isPreview * @param string $isPlainText * @return string The link url */ private function getLinkAuthCode(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 = ' . $TYPO3_DB->fullQuoteStr($url, 'tx_newsletter_domain_model_link') . ' AND newsletter = ' . $TYPO3_DB->fullQuoteStr($this->newsletter->getUid(), 'tx_newsletter_domain_model_link') . ' LIMIT 1'); $row = $TYPO3_DB->sql_fetch_row($res); if ($row) { $linkId = $row[0]; } else { $TYPO3_DB->exec_INSERTquery('tx_newsletter_domain_model_link', ['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); $arguments = []; $arguments['n'] = $this->newsletter->getUid(); $arguments['l'] = $authCode; if ($isPlainText) { $arguments['p'] = 1; } $newUrl = UriBuilder::buildFrontendUri($email->getPid(), 'Link', 'clicked', $arguments); return $newUrl; }