You are here

function sheetnode_token_values in Sheetnode 6

Implementation of hook_token_values().

File

./sheetnode.module, line 381

Code

function sheetnode_token_values($type, $object = NULL) {
  $tokens = array();
  if ($type == 'node' && $object->type == 'sheetnode') {
    require_once drupal_get_path('module', 'sheetnode') . '/socialcalc.inc';
    $socialcalc = socialcalc_parse($object->sheetnode['value']);
    $sc = $socialcalc['sheet'];
    if (!empty($sc['cells'])) {
      foreach ($sc['cells'] as $coord => $c) {
        $tokens['sheetnode-' . $coord] = isset($c['datavalue']) ? $c['datavalue'] : '';
      }
    }
  }
  if ($type == 'node' && $object->type != 'sheetnode') {
    foreach (content_fields(NULL, $object->type) as $field) {
      if ($field['type_name'] == $object->type && $field['type'] == 'sheetfield') {
        require_once drupal_get_path('module', 'sheetnode') . '/socialcalc.inc';
        $item = $object->{$field['field_name']}[0];

        // To act like other CCK fields
        $socialcalc = socialcalc_parse($item['value']);
        if (!empty($socialcalc['sheet'])) {
          $sc = $socialcalc['sheet'];
          if (!empty($sc['cells'])) {
            foreach ($sc['cells'] as $coord => $c) {
              $tokens[$field['field_name'] . '-' . $coord] = isset($c['datavalue']) ? $c['datavalue'] : '';
            }
          }
        }
      }
    }
  }
  return $tokens;
}