You are here

function newsletter_tokens in Newsletter 7

Same name and namespace in other branches
  1. 7.2 newsletter.module \newsletter_tokens()

Implements hook_tokens().

File

./newsletter.module, line 637
Defines menu items for newsletter administration, permissions and basic drupal hooks.

Code

function newsletter_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $sanitize = !empty($options['sanitize']);
  $replacements = array();
  if ($type == 'newsletter' && isset($data['newsletter_list'])) {
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'list_name':
          $replacements[$original] = $sanitize ? filter_xss($data['newsletter_list']->title) : $data['newsletter_list']->title;
          break;
        case 'list_description':
          $replacements[$original] = $sanitize ? filter_xss($data['newsletter_list']->description) : $data['newsletter_list']->description;
          break;
        case 'list_category':
          $replacements[$original] = $sanitize ? filter_xss($data['newsletter_list']->category) : $data['newsletter_list']->category;
          break;
      }
    }
  }
  if ($type == 'newsletter' && isset($data['newsletter_subscriber'])) {
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'confirmation_url':
          $replacements[$original] = url('newsletter/confirm/' . $data['newsletter_subscriber']->hash, array(
            'absolute' => TRUE,
          ));
          break;
        case 'subscription_ip':
          $replacements[$original] = $sanitize ? filter_xss($data['newsletter_subscriber']->ip) : $data['newsletter_subscriber']->ip;
          break;
        case 'unsubscribe_url':
          $replacements[$original] = url('newsletter/unsubscribe/' . $data['newsletter_subscriber']->hash, array(
            'absolute' => TRUE,
          ));
          break;
        case 'edit_subscription_url':
          $replacements[$original] = url('newsletter/edit/' . $data['newsletter_subscriber']->hash, array(
            'absolute' => TRUE,
          ));
          break;
        case 'subscriber_firstname':
          $replacements[$original] = $sanitize ? filter_xss($data['newsletter_subscriber']->firstname) : $data['newsletter_subscriber']->firstname;
          break;
        case 'subscriber_lastname':
          $replacements[$original] = $sanitize ? filter_xss($data['newsletter_subscriber']->lastname) : $data['newsletter_subscriber']->lastname;
          break;
        case 'subscriber_email':
          $replacements[$original] = $sanitize ? filter_xss($data['newsletter_subscriber']->email) : $data['newsletter_subscriber']->email;
          break;
        case 'subscription_time':
          $replacements[$original] = format_date($data['newsletter_subscriber']->created, 'long');
          break;
      }
    }
  }
  return $replacements;
}