[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/token/ -> token_comment.inc (source)

   1  <?php
   2  
   3  /**
   4   * @file
   5   * Implementations of token module hooks for the core comment module.
   6   *
   7   * The token module requires specific hooks to be added to modules
   8   * so that those modules can return data about their objects to the
   9   * token API.  Until and unless token becomes a part of core, the
  10   * implementations of the token hooks for core modules are provided
  11   * in the token module itself.
  12   * @ingroup token
  13   */
  14  
  15  /**
  16   * Implementation of hook_token_values().
  17   */
  18  function comment_token_values($type, $object = NULL, $options = array()) {
  19    $values = array();
  20    switch ($type) {
  21      case 'comment':
  22  
  23        // Cast to an object just in case fussy Drupal gave us an array
  24        $comment = (object)$object;
  25  
  26        $values['comment-cid']             = $comment->cid;
  27        $values['comment-nid']             = $comment->nid;
  28        $values['comment-title']           = check_plain($comment->subject);
  29        $values['comment-body']            = check_markup($comment->comment, $comment->format, FALSE);
  30        $values['comment-author-name']     = check_plain($comment->name);
  31        $values['comment-author-uid']      = $comment->uid;
  32        $values['comment-author-homepage'] = check_url($comment->homepage);
  33  
  34        // Raw counterparts of user supplied data.
  35        $values['comment-title-raw']       = $comment->subject;
  36        $values['comment-body-raw']        = $comment->comment;
  37        $values['comment-author-name-raw'] = $comment->name;
  38  
  39        if (!empty($comment->mail)) {
  40          $account_mail = $comment->mail;
  41        }
  42        elseif (!empty($comment->uid)) {
  43          $account_mail = db_result(db_query("SELECT mail FROM {users} WHERE uid = %d", $comment->uid));
  44        }
  45        else {
  46          $account_mail = '';
  47        }
  48        $values['comment-author-mail']     = check_plain($account_mail);
  49        $values['comment-author-mail-raw'] = $account_mail;
  50  
  51        // Included in case a consuming module wants to format the body
  52        $values['comment-body-format']     = $comment->format;
  53  
  54        $values += token_get_date_token_values($comment->timestamp, 'comment-');
  55  
  56        $values['comment-node-title-raw']  = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $comment->nid));
  57        $values['comment-node-title']      = check_plain($values['comment-node-title-raw']);
  58        break;
  59    }
  60  
  61    return $values;
  62  }
  63  
  64  /**
  65   * Implementation of hook_token_list().
  66   */
  67  function comment_token_list($type = 'all') {
  68    if ($type == 'comment' || $type == 'all') {
  69      $tokens['comment']['comment-cid']             = t('The unique ID of the comment.');
  70      $tokens['comment']['comment-nid']             = t('The unique ID of the node the comment was posted to.');
  71      $tokens['comment']['comment-title']           = t('The title of the comment.');
  72      $tokens['comment']['comment-title-raw']       = t('The title of the comment.');
  73      $tokens['comment']['comment-body']            = t('The formatted content of the comment itself.');
  74      $tokens['comment']['comment-body-raw']        = t('The formatted content of the comment itself.');
  75  
  76      $tokens['comment']['comment-author-uid']      = t('The unique ID of the author of the comment.');
  77      $tokens['comment']['comment-author-name']     = t('The name left by the comment author.');
  78      $tokens['comment']['comment-author-name-raw'] = t('The name left by the comment author.');
  79      $tokens['comment']['comment-author-homepage'] = t('The home page URL left by the comment author.');
  80  
  81      $tokens['comment']['comment-author-mail']     = t('The email address left by the comment author.');
  82      $tokens['comment']['comment-author-mail-raw'] = t('The email address left by the comment author.');
  83  
  84      $tokens['comment'] += token_get_date_token_info(t('Comment creation'), 'comment-');
  85  
  86      $tokens['comment']['comment-node-title']      = t('The title of the node the comment was posted to.');
  87      $tokens['comment']['comment-node-title-raw']  = t('The title of the node the comment was posted to.');
  88  
  89      return $tokens;
  90    }
  91  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7