You are here

protected function SpamspanTrait::outputWhenUseForm in SpamSpan filter 8.2

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

A version of $this->output method.

To use when spamspan_use_form option is checked.

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

File

src/SpamspanTrait.php, line 308

Class

SpamspanTrait
Trait SpamspanTrait.

Namespace

Drupal\spamspan

Code

protected function outputWhenUseForm($name, $domain, $contents = '', array $headers = [], array $vars = []) {

  // Processing for forms.
  if (!empty($this->settings['spamspan_use_form'])) {
    $email = urlencode(base64_encode($name . '@' . $domain));

    // Put in the defaults if nothing set.
    if (empty($vars['custom_form_url'])) {
      $vars['custom_form_url'] = $this->settings['spamspan_form_default_url'];
    }
    if (empty($vars['custom_displaytext'])) {
      $vars['custom_displaytext'] = $this
        ->t($this->settings['spamspan_form_default_displaytext']);
    }
    $vars['custom_form_url'] = strip_tags($vars['custom_form_url']);
    $vars['custom_displaytext'] = strip_tags($vars['custom_displaytext']);
    $url_parts = parse_url($vars['custom_form_url']);
    if (!$url_parts) {
      $vars['custom_form_url'] = '';
    }
    else {
      if (empty($url_parts['host'])) {
        $vars['custom_form_url'] = base_path() . trim($vars['custom_form_url'], '/');
      }
    }
    $replace = [
      '%url' => $vars['custom_form_url'],
      '%displaytext' => $vars['custom_displaytext'],
      '%email' => $email,
    ];
    return strtr($this->settings['spamspan_form_pattern'], $replace);
  }
}