You are here

function comment_notify_tokens in Comment Notify 7

Same name and namespace in other branches
  1. 8 comment_notify.tokens.inc \comment_notify_tokens()

Implements hook_tokens().

File

./comment_notify.tokens.inc, line 32
Builds placeholder replacement tokens for comment_notify.module.

Code

function comment_notify_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $url_options = array(
    'absolute' => TRUE,
  );
  if (isset($options['language'])) {
    $url_options['language'] = $options['language'];
  }
  $replacements = array();
  if ($type == 'comment' && !empty($data['comment'])) {
    $comment = $data['comment'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'unsubscribe-url':
          if ($unsubscribe_url = comment_notify_get_unsubscribe_url($comment)) {
            $replacements[$original] = url($unsubscribe_url, $url_options);
          }
          break;
      }
    }

    // [comment:unsubscribe-url:*] chained token replacements.
    if (($unsubscribe_url_tokens = token_find_with_prefix($tokens, 'unsubscribe-url')) && ($unsubscribe_url = comment_notify_get_unsubscribe_url($comment))) {
      $replacements += token_generate('url', $unsubscribe_url_tokens, array(
        'path' => $unsubscribe_url,
      ), $options);
    }
  }

  // Comment subscriber tokens (pass through to comment token replacement).
  if ($type == 'comment-subscribed' && !empty($data['comment-subscribed'])) {
    $replacements += token_generate('comment', $tokens, array(
      'comment' => $data['comment-subscribed'],
    ), $options);
  }
  return $replacements;
}