function photos_preprocess_photos_vote in Album Photos 7.3
Implements hook_preprocess_HOOK().
File
- ./
photos.module, line 2096 - Implementation of photos.module.
Code
function photos_preprocess_photos_vote(&$variables) {
global $user;
if ($variables['fid']) {
$fid = $variables['fid'];
$x = votingapi_select_votes(array(
'uid' => $user->uid,
'entity_type' => 'image',
'entity_id' => $fid,
));
if (!user_access('allowed to vote')) {
$variables['vote']['access'] = TRUE;
$variables['vote']['down']['#href'] = url('user/login', array(
'query' => drupal_get_destination(),
));
$variables['vote']['down']['#title'] = t('Login to vote');
$variables['vote']['up']['#href'] = $variables['vote']['down']['#href'];
$variables['vote']['up']['#title'] = $variables['vote']['down']['#title'];
}
else {
if (isset($x['0']['value']) && $x['0']['value'] == 1) {
$down_href = url('photos/image/' . $fid . '/vote/down', array(
'query' => drupal_get_destination(),
));
$up_href = '';
}
elseif (isset($x['0']['value']) && $x['0']['value'] == -1) {
$down_href = '';
$up_href = url('photos/image/' . $fid . '/vote/up', array(
'query' => drupal_get_destination(),
));
}
else {
$down_href = url('photos/image/' . $fid . '/vote/down', array(
'query' => drupal_get_destination(),
));
$up_href = url('photos/image/' . $fid . '/vote/up', array(
'query' => drupal_get_destination(),
));
}
$variables['vote']['up'] = array(
'#title' => t('I like this image'),
'#href' => $up_href,
);
$variables['vote']['down'] = array(
'#title' => t('I do not like this image'),
'#href' => $down_href,
);
}
$sum = votingapi_recalculate_results('image', $fid);
if (isset($sum['0']['value']) && $sum['0']['value']) {
$t_sum = $sum['2']['value'];
$t_average = $sum['1']['value'];
$t_count = $sum['0']['value'];
}
else {
$t_count = $t_sum = 0;
}
$variables['vote']['count'] = array(
'#count' => $t_count,
'#sum' => $t_sum,
'#average' => isset($t_average) ? $t_average : '',
'#title' => t('View voting users'),
);
if (user_access('view vote list')) {
$variables['vote']['count']['#href'] = url('photos/zoom/' . $fid . '/vote');
}
}
}