You are here

function vud_widget_proxy in Vote Up/Down 6.2

Same name and namespace in other branches
  1. 6.3 vud.theme.inc \vud_widget_proxy()
  2. 7.2 vud.theme.inc \vud_widget_proxy()
  3. 7 vud.theme.inc \vud_widget_proxy()

Proxy widget function that hook_theme() calls.

1 string reference to 'vud_widget_proxy'
vud_theme in ./vud.theme.inc
Implementation of hook_theme().

File

./vud.theme.inc, line 119
Theme functions

Code

function vud_widget_proxy($content_id, $type, $tag, $widget_theme, $readonly = NULL, $widget_message_code = VUD_WIDGET_MESSAGE_ERROR) {
  $plugin = vud_widget_get($widget_theme);
  if (empty($plugin) || empty($plugin['widget template'])) {
    return;
  }
  $variables = array(
    'content_id' => $content_id,
    'type' => $type,
    'widget_theme' => $widget_theme,
    'plugin' => $plugin,
    'tag' => $tag ? $tag : variable_get('vud_tag', 'vote'),
    'id' => 'widget-' . $type . '-' . $content_id,
    'link_class_up' => 'vud-link-up',
    'link_class_down' => 'vud-link-down',
  );
  global $user;
  $uid = votingapi_current_user_identifier();
  ctools_add_js('ajax-responder');
  ctools_include('ajax');
  if ($type == 'comment') {
    drupal_add_css(drupal_get_path('module', 'vud_comment') . '/vud_comment.css');
  }
  vud_add_files('css', $plugin);

  // Search and add the CSS files.
  vud_add_files('js', $plugin);

  // Search and add the JS files.
  $base_criteria = array(
    'content_type' => $type,
    'content_id' => $content_id,
    'tag' => $variables['tag'],
  );
  $criteria = $base_criteria + $uid;
  $user_vote = votingapi_select_single_vote_value($criteria);
  if ($user_vote > 0) {
    $variables['class_up'] = 'up-active';
    $variables['class_down'] = 'down-inactive';
  }
  elseif ($user_vote < 0) {
    $variables['class_up'] = 'up-inactive';
    $variables['class_down'] = 'down-active';
  }
  else {
    $variables['class_up'] = 'up-inactive';
    $variables['class_down'] = 'down-inactive';
  }
  $token_up = drupal_get_token("vote/{$type}/{$content_id}/1/{$tag}/{$widget_theme}");
  $token_down = drupal_get_token("vote/{$type}/{$content_id}/-1/{$tag}/{$widget_theme}");
  $result_criteria = array(
    'content_type' => $type,
    'content_id' => $content_id,
    'value_type' => 'points',
    'tag' => $tag,
    'function' => 'sum',
  );
  $raw_points = votingapi_select_single_result_value($result_criteria);
  $variables['raw_points'] = $raw_points;
  $vote_result = (int) $raw_points;
  $criteria = array(
    'content_type' => $type,
    'content_id' => $content_id,
    'value_type' => 'points',
    'tag' => $tag,
    'function' => 'count',
  );
  $vote_count = (int) votingapi_select_single_result_value($criteria);
  $variables['vote_count'] = $vote_count;
  $variables['unsigned_points'] = $vote_result;
  $criteria = array(
    'content_type' => $type,
    'content_id' => $content_id,
    'value_type' => 'points',
    'tag' => $tag,
    'function' => 'positives',
  );
  $positives = (int) votingapi_select_single_result_value($criteria);
  $variables['up_points'] = $positives;
  $criteria = array(
    'content_type' => $type,
    'content_id' => $content_id,
    'value_type' => 'points',
    'tag' => $tag,
    'function' => 'negatives',
  );
  $negatives = (int) votingapi_select_single_result_value($criteria);
  $variables['down_points'] = $negatives;
  if ($vote_result > 0) {
    $variables['class'] = 'positive';
    $variables['points'] = '+' . $vote_result;
  }
  else {
    $variables['points'] = $vote_result;
    if ($vote_result < 0) {
      $variables['class'] = 'negative';
    }
    else {
      $variables['class'] = 'neutral';
    }
  }
  $variables['vote_label'] = format_plural(abs($vote_result), 'vote', 'votes');
  $variables['readonly'] = $readonly;
  $link_up = url("vote/{$type}/{$content_id}/1/{$tag}/{$widget_theme}/{$token_up}");
  $link_down = url("vote/{$type}/{$content_id}/-1/{$tag}/{$widget_theme}/{$token_down}");
  $message_on_deny = variable_get('vud_message_on_deny', FALSE);
  $variables['show_links'] = !$readonly || $message_on_deny;
  $variables['show_up_as_link'] = $variables['show_links'] && $user_vote <= 0;
  $variables['show_down_as_link'] = $variables['show_links'] && $user_vote >= 0;
  if ($readonly) {
    $variables['link_class_up'] .= ' denied';
    $variables['link_class_down'] .= ' denied';
    if ($message_on_deny) {
      ctools_include('modal');
      ctools_modal_add_js();
      $variables['link_class_up'] .= ' ctools-use-modal';
      $variables['link_class_down'] .= ' ctools-use-modal';
      $link_up = url(sprintf('vud/nojs/denied/%d', $widget_message_code));
      $link_down = url(sprintf('vud/nojs/denied/%d', $widget_message_code));
    }
    else {

      // no vote access, so avoid show the link at template
      $link_up = '#';
      $link_down = '#';
    }
  }
  else {
    $variables['link_class_up'] .= ' ctools-use-ajax';
    $variables['link_class_down'] .= ' ctools-use-ajax';
  }
  $variables['link_up'] = $link_up;
  $variables['link_down'] = $link_down;
  $template_file = vud_pseudo_theming($type, 'widget', $plugin, $variables);
  return $plugin['render function']($template_file, $variables);
}