private function onGuestVote() { if (!$this->votescore->isGuestVote()) { return $this->module->error('err_no_guest'); } $ip = GWF_IP6::getIP(GWF_IP_QUICK); if (false === ($vsr = GWF_VoteScoreRow::getByIP($this->votescore->getID(), $ip))) { if (false === $this->votescore->onGuestVote($this->score, $ip)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return $this->onVoted(false); } else { if ($vsr->isUserVote()) { return $this->module->message('err_vote_ip'); } if (!$vsr->isGuestVoteExpired($this->module->cfgGuestTimeout())) { $this->votescore->revertVote($vsr, $ip, 0); } if (false === $this->votescore->onGuestVote($this->score, $ip)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return $this->onVoted(false); } }
/** * Vote and revert votes safely. Return false or error msg. * @param int $score * @param int $userid * @return error msg or false */ public function onUserVoteSafe($score, $userid) { $userid = (int) $userid; $vsid = $this->getID(); # Revert Guest Vote with same IP $ip = GWF_IP6::getIP(GWF_IP_QUICK); // var_dump($ip); if (false !== ($vsr = GWF_VoteScoreRow::getByIP($vsid, $ip))) { // echo '<div>HAVE GUEST VOTE</div>'; // var_dump($vsr); if (!$vsr->isGuestVoteExpired(GWF_Module::getModule('Votes')->cfgGuestTimeout())) { if (false === $this->revertVote($vsr, $ip, 0)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } } } # Revert Users Vote if (false !== ($vsr = GWF_VoteScoreRow::getByUID($vsid, $userid))) { // echo '<div>HAVE OLD VOTE</div>'; if (false === $this->revertVote($vsr, 0, $userid)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } } # And Vote it if (false === $this->onUserVote($score, $userid, 0)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return false; # No error }