public function FilterSpamspan::process in SpamSpan filter 8.2
Same name and namespace in other branches
- 8 src/Plugin/Filter/FilterSpamspan.php \Drupal\spamspan\Plugin\Filter\FilterSpamspan::process()
Performs the filter processing.
Parameters
string $text: The text string to be filtered.
string $langcode: The language code of the text to be filtered.
Return value
\Drupal\filter\FilterProcessResult The filtered text, wrapped in a FilterProcessResult object, and possibly with associated assets, cacheability metadata and placeholders.
Overrides FilterInterface::process
See also
\Drupal\filter\FilterProcessResult
File
- src/
Plugin/ Filter/ FilterSpamspan.php, line 63
Class
- FilterSpamspan
- Provides a filter to obfuscate email addresses.
Namespace
Drupal\spamspan\Plugin\FilterCode
public function process($text, $langcode) {
$this->textAltered = FALSE;
// HTML image tags need to be handled separately, as they may contain base64
// encoded images slowing down the email regex function.
// Therefore, remove all image contents and add them back later.
// See https://drupal.org/node/1243042 for details.
$images = [
[],
];
preg_match_all(self::PATTERN_IMG_INLINE, $text, $images);
$text = preg_replace(self::PATTERN_IMG_INLINE, self::PATTERN_IMG_PLACEHOLDER, $text);
if (!empty($this->settings['spamspan_parse_dom'])) {
$text = $this
->processAsDom($text, $this->textAltered);
}
else {
$text = $this
->processAsText($text, $this->textAltered);
}
// Revert back to the original image contents.
foreach ($images[0] as $image) {
$text = preg_replace('/' . self::PATTERN_IMG_PLACEHOLDER . '/', $image, $text, 1);
}
$result = new FilterProcessResult($text);
if ($this->textAltered) {
$result
->addAttachments([
'library' => [
'spamspan/obfuscate',
],
]);
if ($this->settings['spamspan_use_graphic']) {
$result
->addAttachments([
'library' => [
'spamspan/atsign',
],
]);
}
}
return $result;
}