You are here

function flagactivity_token_values in Activity 6

Same name and namespace in other branches
  1. 5.4 contrib/flagactivity/flagactivity.module \flagactivity_token_values()

Token module integration. Defines available default token values.

File

contrib/flagactivity/flagactivity.module, line 63

Code

function flagactivity_token_values($type, $data = NULL, $options = array()) {
  static $nodes, $comments;
  if ($type == 'flagactivity' && !empty($data)) {
    switch ($data['content-type']) {
      case 'node':
        if (!isset($nodes[$data['content-id']])) {
          $nodes[$data['content-id']] = db_fetch_object(db_query('SELECT title, type FROM {node} WHERE nid = %d', $data['content-id']));
        }
        $node = $nodes[$data['content-id']];
        $data['node-type'] = theme('activity_node_type', $node->type);
        $data['content-title'] = check_plain($node->title);
        $data['content-type'] = $data['node-type'];
        $data['content-link'] = l($data['content-title'], 'node/' . $data['content-id']);
        break;
      case 'comment':
        if (!isset($coments[$data['content-id']])) {
          $comments[$data['content-id']] = db_fetch_object(db_query('SELECT n.title, n.type, n.nid, c.subject FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid WHERE c.cid = %d', $data['content-id']));
        }
        $comment = $comments[$data['content-id']];
        $data['node-type'] = theme('activity_node_type', $comment->type);
        $data['content-title'] = $comment->subject ? check_plain($comment->subject) : check_plain($comment->title);
        $data['content-link'] = l($data['content-title'], 'node/' . $comment->nid, array(
          'fragment' => 'comment-' . $data['content-id'],
        ));
        break;
      case 'user':
        if (!isset($authors[$data['content-id']])) {
          $authors[$data['content-id']] = activity_user_load($data['content-id']);
        }
        $user = $authors[$data['content-id']];
        $data['content-link'] = theme('activity_username', $user);
        break;
    }
    return $data;
  }
}