You are here

spamspan.module in SpamSpan filter 8

Implements the spamspan technique for hiding email addresses from spambots.

If javascript is disabled on the client-side, addresses appear as example [at] example [dot] com.

@author Lawrence Akka @copyright 2006-2010, Lawrence Akka @license http://www.gnu.org/licenses/gpl.txt GPL v 2.0

File

spamspan.module
View source
<?php

/**
 * @file
 * Implements the spamspan technique for hiding email addresses from spambots.
 *
 * @see http://www.spamspan.com
 *
 * If javascript is disabled on the client-side, addresses appear as
 * example [at] example [dot] com.
 *
 * @author Lawrence Akka
 * @copyright 2006-2010, Lawrence Akka
 * @license http://www.gnu.org/licenses/gpl.txt  GPL v 2.0
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;

/**
 * Implements hook_help().
 */
function spamspan_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.spamspan':
      return t('<p>The SpamSpan module obfuscates email addresses to help prevent spambots from collecting them. See the <a href="@url">Spamspan test page</a>.</p>', [
        '@url' => Url::fromRoute('spamspan.test')
          ->toString(),
      ]);
  }
}

/**
 * A simple utility function wrapping the main processing callback.
 *
 * This function may be called by other modules and themes.
 *
 * @param string $text
 *   Text, maybe containing email addresses.
 * @param array $settings
 *   An associative array of settings to be applied.
 *
 * @return string
 *   The input text with emails replaced by spans
 */
function spamspan($text = '', array $settings = []) {
  $plugin_manager = \Drupal::service('plugin.manager.filter');
  $configuration = $plugin_manager
    ->getDefinition('filter_spamspan');
  $configuration['settings'] = $settings + $configuration['settings'];
  $filter = $plugin_manager
    ->createInstance('filter_spamspan', $configuration);
  return $filter
    ->process($text, NULL)
    ->getProcessedText();
}

/**
 * Implements hook_theme().
 */
function spamspan_theme($existing, $type, $theme, $path) {
  return [
    'spamspan_at_sign' => [
      'variables' => [
        'path' => base_path() . drupal_get_path('module', 'spamspan') . '/image.gif',
        'settings' => [],
      ],
    ],
  ];
}

Functions

Namesort descending Description
spamspan A simple utility function wrapping the main processing callback.
spamspan_help Implements hook_help().
spamspan_theme Implements hook_theme().