public function notifyNewArgument(Question $q, Argument $a) { global $sDB, $sTimer, $sTemplate; $sTimer->start("notifyNewArgument"); $res = $sDB->exec("SELECT `notifications`.`userId`, `notifications`.`flags`, `users`.`email`, `users`.`userName` FROM `notifications`\n LEFT JOIN `users` ON `users`.`userId` = `notifications`.`userId`\n WHERE `questionId` = '" . i($q->questionId()) . "';"); while ($row = mysql_fetch_object($res)) { // no notifications for our own arguments. /*if($a->userId() == $row->userId) { continue; }*/ $uId = new BaseConvert($row->userId); $qId = new BaseConvert($q->questionId()); $profileUrl = $sTemplate->getShortUrlBase() . "u" . $uId->val(); $unfollowUrl = $sTemplate->getShortUrlBase() . "f" . $qId->val(); $url = $a->shortUrl(); if (!SHORTURL_BASE) { $profileUrl = $sTemplate->getRoot() . "user/" . $row->userId . "/"; $unfollowUrl = $sTemplate->getRoot() . "unfollow.php?qId=" . $q->questionId(); $url = $a->fullurl(); } $subject = $sTemplate->getString("NOTIFICATION_NEW_ARGUMENT_SUBJECT"); $message = $sTemplate->getString("NOTIFICATION_NEW_ARGUMENT_BODY", array("[USERNAME]", "[AUTHOR]", "[URL]", "[QUESTION]", "[ARGUMENT]", "[UNFOLLOW_URL]", "[PROFILE_URL]"), array($row->userName, $a->author(), $url, $q->title(), $a->headline(), $unfollowUrl, $profileUrl)); $this->sendMail($row->email, "", $subject, $message); } $sTimer->stop("notifyNewArgument"); }
function drawArgumentBoxFull(Question $q, Argument $a, $basePath) { global $sTemplate, $sUser; $ret = ""; $argumentId = $a->argumentId(); $numPoints = $a->score(); $ret .= ' <div class = "argument_full"> <div class = "stats question_stats"> <div class = "points question_points">' . $numPoints . '</div> <div class = "points_text question_points_text">' . $sTemplate->getStringNumber("QUESTION_POINTS", array(), array(), $numPoints) . '</div> ' . voteUp('question_vote_up', $q->questionId(), $argumentId, $a->type(), $q->type(), $q->flags()) . ' ' . voteDn('question_vote_dn', $q->questionId(), $argumentId, $a->type(), $q->type(), $q->flags()) . ' </div> <div class = "argument_title"><a href = "' . $a->url($basePath) . '">' . $a->headline() . '</a></div>'; $ret .= '<div class = "argument_abstract_extended argument_abstract_cursive">' . $a->abstractText() . '</div>'; $ret .= '<div class = "argument_details_extended">' . $a->details() . '</div>'; if ($a->canEdit($sUser)) { $ret .= '<div class = "author question_author"><a href = "' . $a->url($basePath) . 'edit/">' . $sTemplate->getString("ARGUMENT_EDIT", array("[TIMELEFT]"), array($a->timeLeftEdit())) . '</a></div>'; } else { $ret .= '<div class = "author question_author">' . $sTemplate->getString("QUESTION_AUTHOR", array("[TIMESINCE]", "[USERNAME]"), array($a->timeSince(), $a->authorLink())) . '</div>'; } $ret .= ' <div class = "argument_' . ($a->type() == ARGUMENT_PRO ? "pro" : "con") . '_bar"></div> </div>'; if (!$a->parentId()) { $numArguments = $a->numArguments(); $ret .= ' <div class = "counter_argument_box_full_line"></div> <a href = "' . $a->urlCounterArguments($basePath) . '"> <div class = "counter_argument_box_full ' . ($a->type() == ARGUMENT_PRO ? "counter_argument_box_full_pro" : "counter_argument_box_full_con") . '"> <div class = "count">' . $numArguments . '</div> <div class = "count_text">' . $sTemplate->getStringNumber("NUM_COUNTER_ARGUMENTS", array(), array(), $numArguments) . '</div> <div class = "plus_sign"></div> </div> </a>'; } return $ret; }
public function vote(Question $question, $argumentId, $vote, $user = false, $forceVote = false) { global $sUser, $sDB, $sQuery, $sPermissions; $questionId = $question->questionId(); if ($user == false) { $user = $sUser; if (!$sUser->isLoggedIn() && ($question->type() != QUESTION_TYPE_UNLISTED || !$question->hasFlag(QUESTION_FLAG_PART_ALL))) { return false; } } if (!in_array($vote, array(VOTE_UP, VOTE_DN, VOTE_NONE))) { return false; } if ($sPermissions->getPermission($user, ACTION_VOTE) == PERMISSION_DISALLOWED) { return false; } $cookieData = false; if (!$user->isLoggedIn()) { $cookieData = $_COOKIE['voteData']; if ($cookieData) { $cookieData = unserialize($cookieData); if (is_array($cookieData)) { if (is_array($cookieData[$questionId])) { if ($cookieData[$questionId][$argumentId]) { validateVote($cookieData[$questionId][$argumentId]); } } else { $cookieData[$questionId] = array(); } } else { $cookieData = array(); $cookieData[$questionId] = array(); } } else { $cookieData = array(); $cookieData[$questionId] = array(); } } if ($argumentId && !$forceVote) { $faction = $user->getFactionByQuestionId($questionId); if ($faction == FACTION_NONE) { return false; } $argument = $sQuery->getArgumentById($argumentId); if ($argument->type() != $faction) { return false; } } if ($user->isLoggedIn()) { $this->lazyUpdateUserStats($questionId, $argumentId, $vote, $user->getUserId()); $sDB->exec("DELETE FROM `user_votes` WHERE `userId` = '" . i($user->getUserId()) . "' AND `questionId` = '" . i($questionId) . "' AND `argumentId` = '" . i($argumentId) . "';"); } else { // check if a vote state exists in the user's cookie if ($cookieData[$questionId][$argumentId]) { validateVote($cookieData[$questionId][$argumentId]); $sDB->exec("DELETE FROM `user_votes` WHERE `userId` = '" . i($user->getUserId()) . "' AND `questionId` = '" . i($questionId) . "' AND `argumentId` = '" . i($argumentId) . "' LIMIT 1;"); unset($cookieData[$questionId]); } } if ($vote != VOTE_NONE) { $sDB->exec("INSERT INTO `user_votes` (`voteId`, `userId`, `questionId`, `argumentId`, `vote`, `dateAdded`)\n VALUES (NULL, '" . i($user->getUserId()) . "', '" . i($questionId) . "', '" . i($argumentId) . "', '" . i($vote) . "', '" . time() . "');"); if (!$user->isLoggedIn()) { $cookieData[$questionId][$argumentId] = $vote; } } $this->updateQuestionStats($questionId); if (!$user->isLoggedIn()) { setcookie("voteData", serialize($cookieData)); } return true; }
public function handlePacket() { global $sUser, $sDB, $sTemplate, $sLog; $requestObj = $this->_requestObj; $response = $this->_response; $qId = $requestObj->getInt(array("data", "qId")); $faction = $requestObj->getInt(array("data", "faction")); $response->data->result = 0; $response->opcode = SMSG_SELECT_FACTION_RESPONSE; if (!validateFaction($faction, false)) { return false; } $question = new Question($qId); if ($question->questionId() == 0) { return false; } $sUser->setFactionByQuestionId($qId, $faction); $sStatistics->updateQuestionStats($qId); $response->data->result = 1; }