Example #1
0
function qa_vote_set($post, $userid, $handle, $cookieid, $vote)
{
    require_once QA_INCLUDE_DIR . 'qa-db-points.php';
    require_once QA_INCLUDE_DIR . 'qa-db-hotness.php';
    require_once QA_INCLUDE_DIR . 'qa-db-votes.php';
    require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
    $vote = (int) min(1, max(-1, $vote));
    $oldvote = (int) qa_db_uservote_get($post['postid'], $userid);
    qa_db_uservote_set($post['postid'], $userid, $vote);
    qa_db_post_recount_votes($post['postid']);
    $postisanswer = $post['basetype'] == 'A';
    $columns = array();
    if ($vote > 0 || $oldvote > 0) {
        $columns[] = $postisanswer ? 'aupvotes' : 'qupvotes';
    }
    if ($vote < 0 || $oldvote < 0) {
        $columns[] = $postisanswer ? 'adownvotes' : 'qdownvotes';
    }
    qa_db_points_update_ifuser($userid, $columns);
    qa_db_points_update_ifuser($post['userid'], array($postisanswer ? 'avoteds' : 'qvoteds', 'upvoteds', 'downvoteds'));
    if ($post['basetype'] == 'Q') {
        qa_db_hotness_update($post['postid']);
    }
    if ($vote < 0) {
        $action = $postisanswer ? 'a_vote_down' : 'q_vote_down';
    } elseif ($vote > 0) {
        $action = $postisanswer ? 'a_vote_up' : 'q_vote_up';
    } else {
        $action = $postisanswer ? 'a_vote_nil' : 'q_vote_nil';
    }
    qa_report_write_action($userid, null, $action, $postisanswer ? null : $post['postid'], $postisanswer ? $post['postid'] : null, null);
    qa_report_event($action, $userid, $handle, $cookieid, array('postid' => $post['postid'], 'vote' => $vote, 'oldvote' => $oldvote));
}
Example #2
0
function qa_vote_set($post, $userid, $handle, $cookieid, $vote)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'db/points.php';
    require_once QA_INCLUDE_DIR . 'db/hotness.php';
    require_once QA_INCLUDE_DIR . 'db/votes.php';
    require_once QA_INCLUDE_DIR . 'db/post-create.php';
    require_once QA_INCLUDE_DIR . 'app/limits.php';
    //rimossi due  cast (int)
    $vote = min(1, max(-1, $vote));
    $oldvote = qa_db_uservote_get($post['postid'], $userid);
    qa_db_uservote_set($post['postid'], $userid, $vote);
    qa_db_post_recount_votes($post['postid']);
    $postisanswer = $post['basetype'] == 'A';
    if ($postisanswer) {
        qa_db_post_acount_update($post['parentid']);
        qa_db_unupaqcount_update();
    }
    $columns = array();
    if ($vote > 0 || $oldvote > 0) {
        $columns[] = $postisanswer ? 'aupvotes' : 'qupvotes';
    }
    if ($vote < 0 || $oldvote < 0) {
        $columns[] = $postisanswer ? 'adownvotes' : 'qdownvotes';
    }
    qa_db_points_update_ifuser($userid, $columns);
    qa_db_points_update_ifuser($post['userid'], array($postisanswer ? 'avoteds' : 'qvoteds', 'upvoteds', 'downvoteds'));
    if ($post['basetype'] == 'Q') {
        qa_db_hotness_update($post['postid']);
    }
    if ($vote < 0) {
        $event = $postisanswer ? 'a_vote_down' : 'q_vote_down';
    } elseif ($vote > 0) {
        $event = $postisanswer ? 'a_vote_up' : 'q_vote_up';
    } else {
        $event = $postisanswer ? 'a_vote_nil' : 'q_vote_nil';
    }
    qa_report_event($event, $userid, $handle, $cookieid, array('postid' => $post['postid'], 'userid' => $post['userid'], 'vote' => $vote, 'oldvote' => $oldvote));
}