function _vote_up_down_get_uid in Vote Up/Down 5
Get a uid for anonymous vs. registered voting
3 calls to _vote_up_down_get_uid()
- theme_vote_up_down_widget in ./
vote_up_down.module - theme_vote_up_down_widget_alt in ./
vote_up_down.module - vote_up_down_vote in ./
vote_up_down.module - An voting get handler with AJAX support
File
- ./
vote_up_down.module, line 607 - vote_up_down is a module that adds a widget for +1/-1 votes on nodes. It depends upon Voting API. It's based upon "simplevote.module".
Code
function _vote_up_down_get_uid() {
global $user;
if ($user->uid) {
$uid = $user->uid;
}
else {
if (variable_get('vote_up_down_anonymous_vote', 0)) {
// Fake uid for anonymous users.
// If the IP is valid turn it into a integer and add the number of the current day.
// The current day is what limit anonymous voting to one vote per day and IP address.
$hostname = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
if ($long = ip2long($hostname)) {
$uid = abs($long) + date('z');
}
}
else {
$uid = NULL;
}
}
return $uid;
}