You are here

function vud_votes_proxy in Vote Up/Down 7

Same name and namespace in other branches
  1. 6.3 vud.theme.inc \vud_votes_proxy()
  2. 6.2 vud.theme.inc \vud_votes_proxy()
  3. 7.2 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 322
Theme functions

Code

function vud_votes_proxy($variables) {
  $plugin = vud_widget_get($variables['widget_theme']);
  if (empty($plugin) || empty($plugin['votes template'])) {
    return;
  }
  $template_file = $plugin['path'] . '/' . $plugin['votes template'] . $plugin['extension'];
  $variables['plugin'] = $plugin;
  $variables['id'] = 'votes-' . $variables['type'] . '-' . $variables['entity_id'];
  $criteria = array(
    'entity_type' => $variables['type'],
    'entity_id' => $variables['entity_id'],
    'value_type' => 'points',
    'tag' => $variables['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($variables['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 '';
}