You are here

function hrules_token_values in Heartbeat 6.4

Implementation of hook_token_values().

File

modules/heartbeat_rules/hrules.module, line 105
Heartbeat rules implementation module

Code

function hrules_token_values($type, $object = NULL, $options = array()) {
  $values = array();
  switch ($type) {
    case 'boolean':
      $values['1-or-0'] = $object ? '1' : '0';
      break;
    case 'rules_data_type_heartbeat_message_id':
      $values['message-id'] = $object;
      $values['message-id-raw'] = (int) $object;
      break;
    case 'rules_data_type_heartbeat_access':
      $values['message-access'] = (int) $object;
      break;
    case 'heartbeat_message':
      $values['heartbeat-message-uaid'] = $object->uaid;
      $values['heartbeat-message-type'] = $object->message_id;
      $values['heartbeat-message-uid'] = $object->uid;
      $values['heartbeat-message-nid'] = $object->nid;
      $values['heartbeat-message-language'] = $object->language;
      $values['heartbeat-message-nid-target'] = $object->nid_target;
      $values['heartbeat-message-uid-target'] = $object->uid_target;
      $values['heartbeat-message'] = $object->message;
      $values['heartbeat-message-raw'] = check_plain($object->message);
      $values['heartbeat-message-url'] = url('heartbeat/message/' . $object->uaid, array(
        'absolute' => TRUE,
      ));
      $values['heartbeat-message-link'] = l(_theme_time_ago($object->timestamp), 'heartbeat/message/' . $object->uaid, array(
        'html' => TRUE,
      ));
      $values['heartbeat-actor-picture'] = l(theme('user_picture', $object->actor), 'user/' . $object->actor->uid, array(
        'html' => TRUE,
      ));
      break;
    case 'node':
      $values['title-link'] = l($object->title, 'node/' . $object->nid);
      $account = heartbeat_user_load($object->uid);
      $values['author-name-url'] = l($account->name, 'user/' . $account->uid, array(
        'attributes' => array(
          'class' => 'user',
        ),
      ));
      if (module_exists('image') && isset($object->images)) {
        $thumbnail = theme('image', $object->images['thumbnail'], $object->title, $object->title);
        $values['node-image-thumbnail-link'] = l($thumbnail, 'node/' . $object->nid, array(
          'html' => TRUE,
        ));
        $preview = theme('image', $object->images['preview'], $object->title, $object->title);
        $values['node-image-preview-link'] = l($preview, 'node/' . $object->nid, array(
          'html' => TRUE,
        ));
      }
      break;
    case 'user':
      if ($object->uid) {
        $name = check_plain($object->name);
        $values['user-name-url'] = l($name, 'user/' . $object->uid, array(
          'alias' => 'TRUE',
          'attributes' => array(
            'class' => 'user',
          ),
        ));
        $values['user-profile-url'] = l($name, 'profile/' . $object->name, array(
          'attributes' => array(
            'class' => 'user',
          ),
        ));
        $values['heartbeat-user-picture'] = l(theme('user_picture', $object), 'user/' . $object->uid, array(
          'html' => TRUE,
        ));
      }
      else {
        $anon = variable_get('anonymous', 'Anonymous');
        $values['user-name-url'] = $anon;
        $values['user-profile-url'] = $anon;
        $values['heartbeat-user-picture'] = '<span class="user-picture">' . $anon . '</span>';
      }
      break;
    case 'global':
      break;
  }
  return $values;
}