source: sipes/modules_contrib/token/token_comment.inc @ 6e81fb4

stableversion-3.0
Last change on this file since 6e81fb4 was d5990f8, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se actualizo el modulo

  • Propiedad mode establecida a 100755
File size: 3.9 KB
Línea 
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 * Implements hook_token_list() on behalf of comment.module.
17 */
18function comment_token_list($type = 'all') {
19  $tokens = array();
20
21  if ($type == 'comment' || $type == 'all') {
22    $tokens['comment']['comment-cid']             = t('The unique ID of the comment.');
23    $tokens['comment']['comment-nid']             = t('The unique ID of the node the comment was posted to.');
24    $tokens['comment']['comment-title']           = t('The title of the comment.');
25    $tokens['comment']['comment-title-raw']       = t('The title of the comment.');
26    $tokens['comment']['comment-body']            = t('The formatted content of the comment itself.');
27    $tokens['comment']['comment-body-raw']        = t('The formatted content of the comment itself.');
28
29    $tokens['comment']['comment-author-uid']      = t('The unique ID of the author of the comment.');
30    $tokens['comment']['comment-author-name']     = t('The name left by the comment author.');
31    $tokens['comment']['comment-author-name-raw'] = t('The name left by the comment author.');
32    $tokens['comment']['comment-author-homepage'] = t('The home page URL left by the comment author.');
33
34    $tokens['comment']['comment-author-mail']     = t('The email address left by the comment author.');
35    $tokens['comment']['comment-author-mail-raw'] = t('The email address left by the comment author.');
36
37    $tokens['comment'] += token_get_date_token_info(t('Comment creation'), 'comment-');
38
39    $tokens['comment']['comment-node-title']      = t('The title of the node the comment was posted to.');
40    $tokens['comment']['comment-node-title-raw']  = t('The title of the node the comment was posted to.');
41  }
42
43  return $tokens;
44}
45
46/**
47 * Implements hook_token_values() on behalf of comment.module.
48 */
49function comment_token_values($type, $object = NULL, $options = array()) {
50  $values = array();
51
52  if ($type == 'comment' && !empty($object)) {
53    // Cast to an object just in case fussy Drupal gave us an array
54    $comment = (object) $object;
55
56    $values['comment-cid']             = $comment->cid;
57    $values['comment-nid']             = $comment->nid;
58    $values['comment-title']           = check_plain($comment->subject);
59    $values['comment-body']            = check_markup($comment->comment, $comment->format, FALSE);
60    $values['comment-author-name']     = check_plain($comment->name);
61    $values['comment-author-uid']      = $comment->uid;
62    $values['comment-author-homepage'] = check_url($comment->homepage);
63
64    // Raw counterparts of user supplied data.
65    $values['comment-title-raw']       = $comment->subject;
66    $values['comment-body-raw']        = $comment->comment;
67    $values['comment-author-name-raw'] = $comment->name;
68
69    if (!empty($comment->mail)) {
70      $account_mail = $comment->mail;
71    }
72    elseif (!empty($comment->uid)) {
73      $account_mail = db_result(db_query("SELECT mail FROM {users} WHERE uid = %d", $comment->uid));
74    }
75    else {
76      $account_mail = '';
77    }
78    $values['comment-author-mail']     = check_plain($account_mail);
79    $values['comment-author-mail-raw'] = $account_mail;
80
81    // Included in case a consuming module wants to format the body
82    $values['comment-body-format']     = $comment->format;
83
84    $values += token_get_date_token_values($comment->timestamp, 'comment-');
85
86    $values['comment-node-title-raw']  = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $comment->nid));
87    $values['comment-node-title']      = check_plain($values['comment-node-title-raw']);
88  }
89
90  return $values;
91}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.