function vud_widget_proxy in Vote Up/Down 6.3
Same name and namespace in other branches
- 6.2 vud.theme.inc \vud_widget_proxy()
- 7.2 vud.theme.inc \vud_widget_proxy()
- 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 123 - 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',
'link_class_reset' => 'vud-link-reset',
'reset_long_text' => t('Reset your vote'),
'reset_short_text' => t('(reset)'),
);
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 = user_access('use vote up/down') ? votingapi_select_single_vote_value($criteria) : 0;
if ($user_vote > 0) {
$variables['class_up'] = 'up-active';
$variables['class_down'] = 'down-inactive';
$variables['class_reset'] = 'reset-active';
}
elseif ($user_vote < 0) {
$variables['class_up'] = 'up-inactive';
$variables['class_down'] = 'down-active';
$variables['class_reset'] = 'reset-active';
}
else {
$variables['class_up'] = 'up-inactive';
$variables['class_down'] = 'down-inactive';
$variables['class_reset'] = 'reset-inactive';
}
$variables['show_reset'] = $variables['class_reset'] == 'reset-active' && vud_access_callback('reset vote up/down votes', $type, $content_id, NULL, $variables['tag']);
$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}");
$token_reset = drupal_get_token("votereset/{$type}/{$content_id}/{$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;
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}");
$link_reset = url("votereset/{$type}/{$content_id}/{$tag}/{$widget_theme}/{$token_reset}");
$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';
$variables['link_class_reset'] .= ' 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';
$variables['link_class_reset'] .= ' 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));
$link_reset = url(sprintf('vud/nojs/denied/%d', $widget_message_code));
}
else {
// no vote access, so avoid show the link at template
$link_up = '#';
$link_down = '#';
$link_reset = '#';
}
}
else {
$variables['link_class_up'] .= ' ctools-use-ajax';
$variables['link_class_down'] .= ' ctools-use-ajax';
$variables['link_class_reset'] .= ' ctools-use-ajax';
}
$variables['link_up'] = $link_up;
$variables['link_down'] = $link_down;
$variables['link_reset'] = $link_reset;
$template_file = vud_pseudo_theming($type, 'widget', $plugin, $variables);
return $plugin['render function']($template_file, $variables);
}