1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Builds placeholder replacement tokens for feed-related data.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_token_info().
|
10
|
*/
|
11
|
function feeds_token_info() {
|
12
|
// @todo This token could be for any entity type.
|
13
|
$info['tokens']['node']['feed-source'] = array(
|
14
|
'name' => t('Feed source'),
|
15
|
'description' => t('The node the feed item was sourced from.'),
|
16
|
'type' => 'node',
|
17
|
);
|
18
|
|
19
|
return $info;
|
20
|
}
|
21
|
|
22
|
/**
|
23
|
* Implements hook_tokens().
|
24
|
*/
|
25
|
function feeds_tokens($type, $tokens, array $data, array $options) {
|
26
|
$replacements = array();
|
27
|
|
28
|
if ($type == 'node' && !empty($data['node']) && !empty($data['node']->nid)) {
|
29
|
|
30
|
$sanitize = !empty($options['sanitize']);
|
31
|
|
32
|
$feed_nid = feeds_get_feed_nid($data['node']->nid, 'node');
|
33
|
|
34
|
if ($feed_nid && $feed_source = node_load($feed_nid)) {
|
35
|
foreach ($tokens as $name => $original) {
|
36
|
switch ($name) {
|
37
|
case 'feed-source':
|
38
|
$replacements[$original] = $sanitize ? check_plain($feed_source->title) : $feed_source->title;
|
39
|
break;
|
40
|
}
|
41
|
}
|
42
|
|
43
|
// Chained node token relationships.
|
44
|
if ($feed_source_tokens = token_find_with_prefix($tokens, 'feed-source')) {
|
45
|
$replacements += token_generate('node', $feed_source_tokens, array('node' => $feed_source), $options);
|
46
|
}
|
47
|
}
|
48
|
}
|
49
|
|
50
|
return $replacements;
|
51
|
}
|