You are here

function vote_up_down_link in Vote Up/Down 5

Same name and namespace in other branches
  1. 6 vote_up_down.module \vote_up_down_link()

Implementation of hook_link().

File

./vote_up_down.module, line 250
vote_up_down is a module that adds a widget for +1/-1 votes on nodes. It depends upon Voting API. It's based upon "simplevote.module".

Code

function vote_up_down_link($type, $node = NULL, $teaser = FALSE) {
  $links = array();
  switch ($type) {
    case 'node':
      $node_type = in_array($node->type, variable_get('vote_up_down_node_types', array()), TRUE);
      if ($node_type && user_access('view up-down vote')) {
        if (variable_get('vote_up_down_reset_vote', 0) && user_access('use up-down vote')) {
          $token = drupal_get_token("vote_up_down/{$type}/{$node->nid}/0");
          $links['vote_up_down_reset'] = array(
            'title' => t('Reset vote'),
            'href' => "vote_up_down/{$type}/{$node->nid}/0",
            'attributes' => array(
              'title' => t('Reset your vote.'),
            ),
            'query' => drupal_get_destination() . '&token=' . $token,
          );
        }
        if ($teaser && variable_get('vote_up_down_link_node', 0) && variable_get('vote_up_down_link_node', 0) != 2) {
          $links['vote_up_down_points'] = theme('vote_up_down_points', $node->nid, $type, TRUE);
        }
        else {
          if (!$teaser && variable_get('vote_up_down_link_node', 0) > 1) {
            $links['vote_up_down_points'] = theme('vote_up_down_points', $node->nid, $type, TRUE);
          }
        }
      }
      break;
    case 'comment':
      if (variable_get('vote_up_down_reset_vote', 0) && user_access('use up-down vote') && (variable_get('vote_up_down_widget_comment', 0) || variable_get('vote_up_down_link_comment', 0))) {
        $token = drupal_get_token("vote_up_down/{$type}/{$node->cid}/0");
        $links['vote_up_down_reset_c'] = array(
          'title' => t('Reset vote'),
          'href' => "vote_up_down/{$type}/{$node->cid}/0",
          'attributes' => array(
            'title' => t('Reset your vote.'),
          ),
          'query' => drupal_get_destination() . '&token=' . $token,
        );
      }
      if (variable_get('vote_up_down_link_comment', 0) && user_access('view up-down vote')) {
        $links['vote_up_down_points_c'] = theme('vote_up_down_points', $node->cid, $type, TRUE);
      }
      break;
  }
  return $links;
}