1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * Add tokens pertaining to the Revisioning module. |
---|
6 | * |
---|
7 | * For examples see the Token module, files token/token_<module>.inc |
---|
8 | * |
---|
9 | * Added to the set are the following, which are not provided by token_node.inc |
---|
10 | * vid: Node revision ID |
---|
11 | * revision-title: Revision title |
---|
12 | * revision-author-uid: Revision author's user id |
---|
13 | * revision-author-name: Revision author's user name |
---|
14 | * revision-author-name-raw: Revision author's user name -- aw user input. |
---|
15 | * revision-author-mail: Revision author's e-mail |
---|
16 | * revision-author-mail-raw: Revision author's e-mail -- raw user input. |
---|
17 | * |
---|
18 | * @ingroup token |
---|
19 | */ |
---|
20 | |
---|
21 | /** |
---|
22 | * Implementation of hook_token_list(). |
---|
23 | */ |
---|
24 | function revisioning_token_list($type = 'all') { |
---|
25 | if ($type == 'node' || $type == 'all') { |
---|
26 | $tokens = array(); |
---|
27 | $tokens['node']['vid'] = t('Node revision ID'); |
---|
28 | $tokens['node']['revision-title'] = t('Revision title'); |
---|
29 | $tokens['node']['revision-log'] = t('Revision log message'); |
---|
30 | $tokens['node']['revision-author-uid'] = t("Revision author's user id"); |
---|
31 | $tokens['node']['revision-author-name'] = t("Revision author's user name"); |
---|
32 | $tokens['node']['revision-author-name-raw'] = t("Revision author's user name. WARNING - raw user input."); |
---|
33 | $tokens['node']['revision-author-mail'] = t("Revision author's e-mail"); |
---|
34 | $tokens['node']['revision-author-mail-raw'] = t("Revision author's e-mail. WARNING - raw user input."); |
---|
35 | return $tokens; |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | /** |
---|
40 | * Implementation of hook_token_values(). |
---|
41 | */ |
---|
42 | function revisioning_token_values($type, $object = NULL, $options = array()) { |
---|
43 | $values = array(); |
---|
44 | switch ($type) { |
---|
45 | case 'node': |
---|
46 | $values['vid'] = $object->vid; |
---|
47 | $values['revision-title'] = $object->title; |
---|
48 | $values['revision-log'] = isset($object->log) ? $object->log : ''; |
---|
49 | if (empty($object->revision_uid)) { // Can happen in Rules context |
---|
50 | $object->revision_uid = revisioning_get_revision_uid($object->vid); |
---|
51 | } |
---|
52 | _set_revision_author_values($object->revision_uid, $values); |
---|
53 | break; |
---|
54 | |
---|
55 | case 'op': |
---|
56 | switch ($object) { |
---|
57 | case 'publish': |
---|
58 | case 'revert': |
---|
59 | case 'unpublish': |
---|
60 | $nid = arg(1); |
---|
61 | $revision = node_load($nid, node_tools_get_current_node_revision_id($nid)); |
---|
62 | $values['vid'] = $revision->vid; |
---|
63 | $values['revision-title'] = $revision->title; |
---|
64 | $values['revision-log'] = isset($revision->log) ? $revision->log : ''; |
---|
65 | _set_revision_author_values($revision->revision_uid, $values); |
---|
66 | } |
---|
67 | break; |
---|
68 | } |
---|
69 | return $values; |
---|
70 | } |
---|
71 | |
---|
72 | function _set_revision_author_values($uid, &$values) { |
---|
73 | $account = db_fetch_object(db_query('SELECT name, mail FROM {users} WHERE uid=%d', $uid)); |
---|
74 | $values['revision-author-uid'] = $uid; |
---|
75 | $values['revision-author-name'] = check_plain($account->name); |
---|
76 | $values['revision-author-name-raw'] = $account->name; |
---|
77 | $values['revision-author-mail'] = check_plain($account->mail); |
---|
78 | $values['revision-author-mail-raw'] = $account->mail; |
---|
79 | } |
---|