function photos_image_vote in Album Photos 6.2
Same name and namespace in other branches
- 7.3 inc/photos.image.inc \photos_image_vote()
1 string reference to 'photos_image_vote'
- photos_menu in ./
photos.module
File
- inc/
photos.image.inc, line 47
Code
function photos_image_vote($fid) {
global $user;
if (user_access('allowed to vote')) {
switch (arg(4)) {
case 'up':
$value = 1;
break;
case 'down':
$value = -1;
break;
default:
exit;
}
$vote = array(
'content_type' => 'image',
'content_id' => $fid,
'tag' => 'vote',
'value_type' => 'points',
'uid' => $user->uid,
'value' => $value,
);
$t = votingapi_set_votes($vote);
if ($t['image'][$fid][0]['value']) {
$x['sum'] = $t['image'][$fid][2]['value'];
$x['average'] = $t['image'][$fid][1]['value'];
$x['count'] = $t['image'][$fid][0]['value'];
}
}
if (!$_GET['destination']) {
drupal_set_header('Content-Type: text/plain;');
if ($x['count']) {
foreach ($x as $key => $val) {
$array[] = '"' . $key . '":' . $val;
}
echo '{' . implode(',', $array) . '}';
}
else {
echo '{"count": 0}';
}
}
else {
if ($x['count']) {
drupal_set_message(t('Vote success.'));
}
else {
drupal_set_message(t('Vote failure.'));
}
return drupal_goto();
}
}