You are here

protected function SpamspanTrait::filterTagContents in SpamSpan filter 8.2

Same name and namespace in other branches
  1. 8 src/SpamspanTrait.php \Drupal\spamspan\SpamspanTrait::filterTagContents()

Clean up the contents of <a> tag.

Remove emails from the tag contents, otherwise the tag contents are themselves converted into a spamspan, with undesirable consequences. See bug #305464.

Applies Xss::filter.

Parameters

string $contents: The tag contents.

Return value

string Cleaned up contents.

1 call to SpamspanTrait::filterTagContents()
SpamspanTrait::output in src/SpamspanTrait.php
A helper function for the callbacks.

File

src/SpamspanTrait.php, line 286

Class

SpamspanTrait
Trait SpamspanTrait.

Namespace

Drupal\spamspan

Code

protected function filterTagContents($contents) {
  if (!empty($contents)) {
    $contents = preg_replace(SpamspanInterface::PATTERN_EMAIL_BARE, '', $contents);

    // Remove anything except certain inline elements, just in case.
    // Nested <a> elements are illegal.
    // <img> needs to be here to allow for graphic @.
    $contents = Xss::filter($contents, [
      'em',
      'strong',
      'cite',
      'b',
      'i',
      'code',
      'span',
      'img',
      '!--',
      'br',
    ]);
  }
  return $contents;
}