You are here

public function EmailTokenEvaluator::containsUnsafeTokens in Easy Email 8

Same name and namespace in other branches
  1. 2.0.x src/Service/EmailTokenEvaluator.php \Drupal\easy_email\Service\EmailTokenEvaluator::containsUnsafeTokens()

Parameters

\Drupal\easy_email\Entity\EasyEmailInterface $email:

Return value

bool

Overrides EmailTokenEvaluatorInterface::containsUnsafeTokens

File

src/Service/EmailTokenEvaluator.php, line 70

Class

EmailTokenEvaluator

Namespace

Drupal\easy_email\Service

Code

public function containsUnsafeTokens(EasyEmailInterface $email) {
  $tokens = [];
  if ($email
    ->hasField('body_html')) {
    $html_body = $email
      ->getHtmlBody();
    $body_tokens = $this->token
      ->scan($html_body['value']);
    if (!empty($body_tokens['easy_email'])) {
      $tokens = array_merge($tokens, $body_tokens['easy_email']);
    }
  }
  if ($email
    ->hasField('body_plain')) {
    $body_tokens = $this->token
      ->scan($email
      ->getPlainBody());
    if (!empty($body_tokens['easy_email'])) {
      $tokens = array_merge($tokens, $body_tokens['easy_email']);
    }
  }
  foreach ($tokens as $token) {
    if (preg_match('/:one-time-login-url\\]$/', $token) || preg_match('/:cancel-url\\]$/', $token)) {
      return TRUE;
    }
  }
  return FALSE;
}