You are here

function vud_node_node_view in Vote Up/Down 7

Implementation of hook_node_view().

File

vud_node/vud_node.module, line 144
Adds a voting widget to nodes.

Code

function vud_node_node_view($node, $view_mode, $langcode) {

  // avoid showing the widget in some node builds
  if (isset($node->in_preview) && $node->in_preview || $view_mode == 'search_index' || $view_mode == 'search_result' || $view_mode == 'rss') {
    return;
  }
  if (($can_edit = user_access('use vote up/down on nodes')) || user_access('view vote up/down count on nodes')) {
    $node_type = in_array($node->type, variable_get('vud_node_types', array()), TRUE);
    $widget_showmode = variable_get('vud_node_widget_show', VUD_NODE_DISPLAY_BOTH);
    $tag = variable_get('vud_tag', 'vote');
    $widget = variable_get('vud_node_widget', 'plain');
    $vote_on_teaser = (bool) variable_get('vud_node_widget_vote_on_teaser', TRUE);
    $widget_message_code = VUD_WIDGET_MESSAGE_ERROR;
    if (!$can_edit) {
      $widget_message_code = VUD_WIDGET_MESSAGE_DENIED;
    }
    elseif (!$vote_on_teaser) {
      $widget_message_code = VUD_NODE_WIDGET_MESSAGE_TEASER_DENIED;
    }
    $teaser = 0;
    if ($view_mode == 'teaser') {
      $teaser = 1;
    }
    if ($node_type) {
      switch ($widget_showmode) {
        case VUD_NODE_DISPLAY_TEASER_ONLY:
          if ($teaser == 1) {
            $node->content['vud_node_widget_display'] = array(
              '#markup' => theme('vud_widget', array(
                'entity_id' => $node->nid,
                'type' => 'node',
                'tag' => $tag,
                'widget_theme' => $widget,
                'readonly' => !$vote_on_teaser || !$can_edit,
                'widget_message_code' => $widget_message_code,
              )),
              '#weight' => -10,
            );
          }
          break;
        case VUD_NODE_DISPLAY_FULL_ONLY:
          if ($teaser == 0) {
            $node->content['vud_node_widget_display'] = array(
              '#markup' => theme('vud_widget', array(
                'entity_id' => $node->nid,
                'type' => 'node',
                'tag' => $tag,
                'widget_theme' => $widget,
                'readonly' => !$can_edit,
                'widget_message_code' => $widget_message_code,
              )),
              '#weight' => -10,
            );
          }
          break;
        case VUD_NODE_DISPLAY_BOTH:
          if ($teaser == 1) {
            $readonly = !$vote_on_teaser || !$can_edit;
          }
          else {
            $readonly = !$can_edit;
          }
          $node->content['vud_node_widget_display'] = array(
            '#markup' => theme('vud_widget', array(
              'entity_id' => $node->nid,
              'type' => 'node',
              'tag' => $tag,
              'widget_theme' => $widget,
              'readonly' => $readonly,
              'widget_message_code' => $widget_message_code,
            )),
            '#weight' => -10,
          );
          break;
      }
    }
  }
}