[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/cck/includes/ -> content.token.inc (source)

   1  <?php
   2  // $Id: content.token.inc,v 1.5.2.14 2011/01/05 10:34:57 yched Exp $
   3  
   4  /**
   5   * @file
   6   * Implementation of hook_content_build_modes
   7   * (on behalf of token.module)
   8   */
   9  function token_content_build_modes() {
  10    return array(
  11      'token' => array(
  12        'title' => t('Token'),
  13        'build modes' => array(
  14          'token' => array(
  15            'title' => t('Token'),
  16            'views style' => FALSE,
  17          ),
  18        ),
  19      ),
  20    );
  21  }
  22  
  23  // Two helper functions that generate appropriate tokens for CCK-added fields.
  24  function content_token_values($type, $object = NULL, $options = array()) {
  25    $tokens = array();
  26    if ($type == 'node') {
  27      // Prevent against invalid 'nodes' built by broken 3rd party code.
  28      if (isset($object->type)) {
  29        // Let PHP free the $node object when we are done. Working directly on the
  30        // incoming $object causes memory leak issues on long-running scripts such
  31        // as migrations. See http://drupal.org/node/736440.
  32        $node = drupal_clone($object);
  33        $content_type = content_types($node->type);
  34        $node->build_mode = 'token';
  35        $node->content = array();
  36        content_view($node);
  37        // The formatted values will only be known after the content has been rendered.
  38        drupal_render($node->content);
  39        content_alter($node);
  40  
  41        $field_types = _content_field_types();
  42        foreach ($content_type['fields'] as $field_name => $field) {
  43          $items = isset($node->{$field_name}) ? $node->{$field_name} : array();
  44          $function = $field_types[$field['type']]['module'] . '_token_values';
  45          if (!empty($items) && function_exists($function)) {
  46            $token_values = (array) $function('field', $items, $options);
  47            foreach ($token_values as $token => $value) {
  48              $tokens[$field_name .'-'. $token] = $value;
  49            }
  50          }
  51        }
  52      }
  53    }
  54    return $tokens;
  55  }
  56  
  57  function content_token_list($type = 'all') {
  58    if ($type == 'node' || $type == 'all') {
  59      $list = array();
  60      $field_types = _content_field_types();
  61  
  62      foreach (content_fields() as $field) {
  63        $sub_list = array();
  64        $function = $field_types[$field['type']]['module'] . '_token_list';
  65        if (function_exists($function)) {
  66          $sub_list = $function('field');
  67          foreach ($sub_list as $category => $token_list) {
  68            foreach ($token_list as $token => $description) {
  69              $list['CCK '. $category][$field['field_name'] .'-'. $token] = $description;
  70            }
  71          }
  72        }
  73      }
  74  
  75      return $list;
  76    }
  77  }
  78  
  79  if (module_exists('nodereference')) {
  80    function nodereference_token_list($type = 'all') {
  81      if ($type == 'field' || $type == 'all') {
  82        $tokens = array();
  83  
  84        $tokens['node reference']['nid']   = t('Referenced node ID');
  85        $tokens['node reference']['title'] = t('Referenced node title');
  86        $tokens['node reference']['title-raw'] = t('Referenced node unfiltered title. WARNING - raw user input.');
  87        $tokens['node reference']['link']  = t("Formatted html link to the referenced node.");
  88        $tokens['node reference']['path']  = t("Relative path alias to the referenced node.");
  89        $tokens['node reference']['url']  = t("Absolute path alias to the referenced node.");
  90  
  91        return $tokens;
  92      }
  93    }
  94  
  95    function nodereference_token_values($type, $object = NULL, $options = array()) {
  96      if ($type == 'field') {
  97        $item = $object[0];
  98  
  99        $title = is_numeric($item['nid']) ? _nodereference_titles($item['nid']) : '';
 100        $tokens['nid']   = $item['nid'];
 101        $tokens['title'] = $title ? check_plain($title) : '';
 102        $tokens['title-raw'] = $title;
 103        $tokens['link']  = isset($item['view']) ? $item['view'] : '';
 104        $tokens['path'] = is_numeric($item['nid']) ? url('node/' . $item['nid']) : '';
 105        $tokens['url'] = is_numeric($item['nid']) ? url('node/' . $item['nid'], array('absolute' => TRUE)) : '';
 106  
 107        return $tokens;
 108      }
 109    }
 110  }
 111  
 112  if (module_exists('number')) {
 113    function number_token_list($type = 'all') {
 114      if ($type == 'field' || $type == 'all') {
 115        $tokens = array();
 116  
 117        $tokens['number']['raw']       = t('Raw number value');
 118        $tokens['number']['formatted'] = t('Formatted number value');
 119  
 120        return $tokens;
 121      }
 122    }
 123  
 124    function number_token_values($type, $object = NULL, $options = array()) {
 125      if ($type == 'field') {
 126        $item = $object[0];
 127  
 128        $tokens['raw']       = $item['value'];
 129        $tokens['formatted'] = isset($item['view']) ? $item['view'] : '';
 130  
 131        return $tokens;
 132      }
 133    }
 134  }
 135  
 136  if (module_exists('text')) {
 137    function text_token_list($type = 'all') {
 138      if ($type == 'field' || $type == 'all') {
 139        $tokens = array();
 140  
 141        $tokens['text']['raw']       = t('Raw, unfiltered text');
 142        $tokens['text']['formatted'] = t('Formatted and filtered text');
 143  
 144        return $tokens;
 145      }
 146    }
 147  
 148    function text_token_values($type, $object = NULL, $options = array()) {
 149      if ($type == 'field') {
 150        $item = $object[0];
 151  
 152        $tokens['raw']  = $item['value'];
 153        $tokens['formatted'] = isset($item['view']) ? $item['view'] : '';
 154        return $tokens;
 155      }
 156    }
 157  }
 158  
 159  if (module_exists('userreference')) {
 160    function userreference_token_list($type = 'all') {
 161      if ($type == 'field' || $type == 'all') {
 162        $tokens = array();
 163  
 164        $tokens['user reference']['uid']   = t('Referenced user ID');
 165        $tokens['user reference']['name']  = t('Referenced user name');
 166        $tokens['user reference']['link']  = t('Formatted HTML link to referenced user');
 167        $tokens['user reference']['path']  = t("Relative path alias to the referenced user.");
 168        $tokens['user reference']['url']  = t("Absolute path alias to the referenced user.");
 169  
 170        return $tokens;
 171      }
 172    }
 173  
 174    function userreference_token_values($type, $object = NULL, $options = array()) {
 175      if ($type == 'field') {
 176        $item = $object[0];
 177  
 178        $tokens['uid']   = $item['uid'];
 179        $tokens['name']  = isset($item['view']) ? strip_tags($item['view']) : '';
 180        $tokens['link']  = isset($item['view']) ? $item['view'] : '';
 181        $tokens['path'] = is_numeric($item['uid']) ? url('user/' . $item['uid']) : '';
 182        $tokens['url'] = is_numeric($item['uid']) ? url('user/' . $item['uid'], array('absolute' => TRUE)) : '';
 183  
 184        return $tokens;
 185      }
 186    }
 187  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7