You are here

function comment_token_values in Token 5

Same name and namespace in other branches
  1. 6 token_comment.inc \comment_token_values()

Implementation of hook_token_values().

File

./token_comment.inc, line 18
Implementations of token module hooks for the core comment module.

Code

function comment_token_values($type, $object = NULL, $options = array()) {
  $values = array();
  switch ($type) {
    case 'comment':

      // Cast to an object just in case fussy Drupal gave us an array
      $comment = (object) $object;
      $values['comment-cid'] = $comment->cid;
      $values['comment-nid'] = $comment->nid;
      $values['comment-title'] = check_plain($comment->subject);
      $values['comment-body'] = check_markup($comment->comment, $comment->format, FALSE);
      $values['comment-author-name'] = check_plain($comment->name);
      $values['comment-author-uid'] = $comment->uid;
      $values['comment-author-homepage'] = check_url($comment->homepage);

      // Raw counterparts of user supplied data.
      $values['comment-title-raw'] = $comment->subject;
      $values['comment-body-raw'] = $comment->comment;
      $values['comment-author-name-raw'] = $comment->name;
      if (!empty($comment->mail)) {
        $account_mail = $comment->mail;
      }
      elseif (!empty($comment->uid)) {
        $account_mail = db_result(db_query("SELECT mail FROM {users} WHERE uid = %d", $comment->uid));
      }
      else {
        $account_mail = '';
      }
      $values['comment-author-mail'] = check_plain($account_mail);
      $values['comment-author-mail-raw'] = $account_mail;

      // Included in case a consuming module wants to format the body
      $values['comment-body-format'] = $comment->format;
      $values += token_get_date_token_values($comment->timestamp, 'comment-');
      $values['comment-node-title-raw'] = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $comment->nid));
      $values['comment-node-title'] = check_plain($values['comment-node-title-raw']);
      break;
  }
  return $values;
}