FilterSpamspan.php in SpamSpan filter 8
File
src/Plugin/Filter/FilterSpamspan.php
View source
<?php
namespace Drupal\spamspan\Plugin\Filter;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;
use Drupal\spamspan\SpamspanDomTrait;
use Drupal\spamspan\SpamspanInterface;
use Drupal\spamspan\SpamspanSettingsFormTrait;
use Drupal\spamspan\SpamspanTrait;
class FilterSpamspan extends FilterBase implements SpamspanInterface {
use SpamspanTrait;
use SpamspanDomTrait;
use SpamspanSettingsFormTrait;
const PATTERN_IMG_INLINE = '/data\\:(?:.+?)base64(?:.+?)(?=["|\'])/';
const PATTERN_IMG_PLACEHOLDER = '__spamspan_img_placeholder__';
protected $textAltered = FALSE;
public function tips($long = FALSE) {
return $this
->t('Each email address will be obfuscated in a human readable fashion or, if JavaScript is enabled, replaced with a spam resistent clickable link. Email addresses will get the default web form unless specified. If replacement text (a persons name) is required a webform is also required. Separate each part with the "|" pipe symbol. Replace spaces in names with "_".');
}
public function process($text, $langcode) {
$this->textAltered = FALSE;
$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);
}
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;
}
protected function processAsText($text, &$altered) {
$text = $this
->replaceMailtoLinks($text, $altered);
if (!empty($this->settings['spamspan_use_form'])) {
$text = $this
->replaceEmailAddressesWithOptions($text, $altered);
}
$text = $this
->replaceBareEmailAddresses($text, $altered);
return $text;
}
}