You are here

function vud_votes_proxy in Vote Up/Down 6.2

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

Proxy votes display function, that hook_theme() calls.

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

File

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

Code

function vud_votes_proxy($content_id, $type, $tag, $widget_theme) {
  $plugin = vud_widget_get($widget_theme);
  if (empty($plugin) || empty($plugin['votes template'])) {
    return;
  }
  $template_file = $plugin['path'] . '/' . $plugin['votes template'] . $plugin['extension'];
  $variables = array(
    'content_id' => $content_id,
    'type' => $type,
    'widget_theme' => $widget_theme,
    'plugin' => $plugin,
    'id' => 'votes-' . $type . '-' . $content_id,
  );
  $variables['tag'] = $tag;
  $criteria = array(
    'content_type' => $type,
    'content_id' => $content_id,
    'value_type' => 'points',
    'tag' => $tag,
    'function' => 'sum',
  );
  $vote_result = (int) votingapi_select_single_result_value($criteria);
  $variables['unsigned_points'] = $vote_result;
  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');
  vud_add_files('css', $plugin);

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

  // Search and add the JS files.
  $template_file = vud_pseudo_theming($type, 'votes', $plugin, $variables);

  // not all widget use votes.tpl.php
  if (function_exists($plugin['render function'])) {
    return $plugin['render function']($template_file, $variables);
  }
  return '';
}