/** * Vote action (Vote a post action) * * @throws \Modules\Core\Exceptions\HTTPException * @return int Votes after the vote */ public function vote() { //Check if user is authorized \Modules\Core\Library\Authorize::isAuthorized(); $post = new Posts(); $vote = new Votes(); $filter = new Filter(); $filter->add('vote', function ($value) { if ($value > 0) { return 1; } if ($value < 0) { return -1; } return 0; }); $params = array('id' => $this->getDI()->get('requestBody')->id, 'uid' => \Modules\Core\Library\Authorize::getUid(), 'vote' => $filter->sanitize((int) $this->getDI()->get('requestBody')->vote, 'vote')); $userVote = Votes::find("id = 0x" . $params['id'] . " AND uid = 0x" . $params['uid']); $oldVote = 0; if (isset($userVote->getFirst()->vote)) { $oldVote = $userVote->getFirst()->vote; } if ((int) $oldVote == (int) $params['vote']) { $params['vote'] = 0; } $vote->save($params); return $post->getVotes($this->getDI()->get('requestBody')->id); }
/** * Check login status * * @throws \Modules\Core\Exceptions\HTTPException * @return string */ public function loginStatus() { //Check if user is authorized \Modules\Core\Library\Authorize::isAuthorized(); return md5(uniqid()); }