You are here

function heartbeat_comments_tokens in Heartbeat 7

Implements hook_tokens().

File

modules/heartbeat_comments/heartbeat_comments.module, line 229
Heartbeat comments for activity.

Code

function heartbeat_comments_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $url_options = array(
    'absolute' => TRUE,
  );
  if (isset($options['language'])) {
    $url_options['language'] = $options['language'];
    $language_code = $options['language']->language;
  }
  else {
    $language_code = NULL;
  }
  $sanitize = !empty($options['sanitize']);
  $replacements = array();
  if ($type == 'heartbeat_comment' && !empty($data['heartbeat_comment'])) {
    $comment = $data['heartbeat_comment'];
    $activity = HeartbeatMessagePool::getInstance()
      ->getMessage($comment->uaid);
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'heartbeat-comment-id':
          $replacements[$original] = isset($comment->nid) ? $comment->cid : $comment->hcid;
          break;
        case 'heartbeat-comment-body':
          $replacements[$original] = check_markup($comment->comment);
          break;
        case 'heartbeat-comment-body-raw':
          $replacements[$original] = $comment->comment;
          break;
        case 'heartbeat-comment-author-uid':
          $replacements[$original] = $comment->uid;
          break;
        case 'heartbeat-comment-date':
          $replacements[$original] = isset($comment->nid) ? format_date($comment->time, 'small') : $comment->time;
          break;
        case 'heartbeat-comment-uaid':
          $replacements[$original] = $comment->uaid;
          break;
        case 'heartbeat-message':
          $replacements[$original] = check_plain($activity->message);
          break;
        case 'heartbeat-message-raw':
          $replacements[$original] = $activity->message;
          break;
        case 'heartbeat-message-url':
          $replacements[$original] = url('heartbeat/message/' . $activity->uaid, array(
            'absolute' => TRUE,
          ));
          break;
        case 'heartbeat-message-link':
          $replacements[$original] = theme('heartbeat_time_ago', array(
            'heartbeat_activity' => $activity,
          ));
          break;
      }
    }
  }
  return $replacements;
}