1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Builds placeholder replacement tokens for comment_notify.module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_token_info().
|
10 |
|
|
*/
|
11 |
|
|
function comment_notify_token_info() {
|
12 |
|
|
// Comment tokens.
|
13 |
|
|
$info['tokens']['comment']['unsubscribe-url'] = array(
|
14 |
|
|
'name' => t('Unsubscribe URL'),
|
15 |
|
|
'description' => t('The URL to disable notifications for the comment.'),
|
16 |
|
|
'type' => 'url',
|
17 |
|
|
);
|
18 |
|
|
|
19 |
|
|
// Comment subscriber token type (extends the comment token type).
|
20 |
|
|
$info['types']['comment-subscribed'] = array(
|
21 |
|
|
'name' => t('Subscribed comment'),
|
22 |
|
|
'description' => t('Tokens related to a comment that is subscribed to new comments.'),
|
23 |
|
|
'type' => 'comment',
|
24 |
|
|
);
|
25 |
|
|
|
26 |
|
|
return $info;
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
/**
|
30 |
|
|
* Implements hook_tokens().
|
31 |
|
|
*/
|
32 |
|
|
function comment_notify_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
33 |
|
|
$url_options = array('absolute' => TRUE);
|
34 |
|
|
if (isset($options['language'])) {
|
35 |
|
|
$url_options['language'] = $options['language'];
|
36 |
|
|
$language_code = $options['language']->language;
|
37 |
|
|
}
|
38 |
|
|
else {
|
39 |
|
|
$language_code = NULL;
|
40 |
|
|
}
|
41 |
|
|
$sanitize = !empty($options['sanitize']);
|
42 |
|
|
|
43 |
|
|
$replacements = array();
|
44 |
|
|
|
45 |
|
|
if ($type == 'comment' && !empty($data['comment'])) {
|
46 |
|
|
$comment = $data['comment'];
|
47 |
|
|
|
48 |
|
|
foreach ($tokens as $name => $original) {
|
49 |
|
|
switch ($name) {
|
50 |
|
|
case 'unsubscribe-url':
|
51 |
|
|
if ($unsubscribe_url = comment_notify_get_unsubscribe_url($comment)) {
|
52 |
|
|
$replacements[$original] = url($unsubscribe_url, $url_options);
|
53 |
|
|
}
|
54 |
|
|
break;
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
// [comment:unsubscribe-url:*] chained token replacements.
|
59 |
|
|
if (($unsubscribe_url_tokens = token_find_with_prefix($tokens, 'unsubscribe-url')) && $unsubscribe_url = comment_notify_get_unsubscribe_url($comment)) {
|
60 |
|
|
$replacements += token_generate('url', $unsubscribe_url_tokens, array('path' => $unsubscribe_url), $options);
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
// Comment subscriber tokens (pass through to comment token replacement).
|
65 |
|
|
if ($type == 'comment-subscribed' && !empty($data['comment-subscribed'])) {
|
66 |
|
|
$replacements += token_generate('comment', $tokens, array('comment' => $data['comment-subscribed']), $options);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
return $replacements;
|
70 |
|
|
} |