You are here

function vud_comment_link in Vote Up/Down 6.2

Same name and namespace in other branches
  1. 6.3 vud_comment/vud_comment.module \vud_comment_link()
  2. 7 vud_comment/vud_comment.module \vud_comment_link()

Implementation of hook_link().

File

vud_comment/vud_comment.module, line 163
Adds a voting widget to comments.

Code

function vud_comment_link($type, $object, $teaser = FALSE) {
  $links = array();
  switch ($type) {
    case 'comment':
      $comment =& $object;
      $votes_display_mode = variable_get('vud_comment_votes', 1);
      $widget_theme = variable_get('vud_comment_widget', 'plain');
      $tag = variable_get('vud_tag', 'vote');
      $node = node_load($comment->nid);
      $votable_node_type_comment = in_array($node->type, variable_get('vud_comment_node_types', array()), TRUE);
      if ($votable_node_type_comment && $votes_display_mode) {
        $links['vud_comment_votes_count'] = array(
          'title' => theme('vud_votes', $comment->cid, $type, $tag, $widget_theme),
          'html' => TRUE,
        );
      }
      if ($votable_node_type_comment && variable_get('vud_comment_reset', 0) && user_access('reset vote up/down votes')) {
        $criteria = array(
          'content_type' => $type,
          'content_id' => $comment->cid,
          'tag' => $tag,
        );
        $criteria += votingapi_current_user_identifier();
        $user_vote = votingapi_select_single_vote_value($criteria);
        if (!is_null($user_vote)) {
          $reset_token = drupal_get_token("votereset/comment/{$comment->cid}/{$tag}");
          $links['vud_comment_votes_reset_link'] = array(
            'title' => t('Reset your vote'),
            'href' => "votereset/comment/{$comment->cid}/{$tag}/{$reset_token}",
            'attributes' => array(
              'rel' => 'nofollow',
            ),
            'html' => TRUE,
          );
        }
      }
      break;
  }
  return $links;
}