Projet

Général

Profil

Paste
Télécharger (1,42 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / feeds.tokens.inc @ ec2b0e7b

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_source_tokens = token_find_with_prefix($tokens, 'feed-source');
33
    $feed_source_token_exists = array_key_exists('feed-source', $tokens);
34

    
35
    if (empty($feed_source_tokens) && !$feed_source_token_exists) {
36
      return $replacements;
37
    }
38

    
39
    $feed_nid = feeds_get_feed_nid($data['node']->nid, 'node');
40

    
41
    if ($feed_nid && $feed_source = node_load($feed_nid)) {
42
      if (isset($tokens['feed-source'])) {
43
        $replacements[$tokens['feed-source']] = $sanitize ? check_plain($feed_source->title) : $feed_source->title;
44
      }
45

    
46
      // Chained node token relationships.
47
      if (!empty($feed_source_tokens)) {
48
        $replacements += token_generate('node', $feed_source_tokens, array('node' => $feed_source), $options);
49
      }
50
    }
51
  }
52

    
53
  return $replacements;
54
}