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));
}
function qa_delete_user($userid)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'qa-db-votes.php';
    require_once QA_INCLUDE_DIR . 'qa-db-users.php';
    require_once QA_INCLUDE_DIR . 'qa-db-post-update.php';
    require_once QA_INCLUDE_DIR . 'qa-db-points.php';
    $postids = qa_db_uservoteflag_user_get($userid);
    // posts this user has flagged or voted on, whose counts need updating
    qa_db_user_delete($userid);
    foreach ($postids as $postid) {
        // hoping there aren't many of these - saves a lot of new SQL code...
        qa_db_post_recount_votes($postid);
        qa_db_post_recount_flags($postid);
    }
    $postuserids = qa_db_posts_get_userids($postids);
    foreach ($postuserids as $postuserid) {
        qa_db_points_update_ifuser($postuserid, array('avoteds', 'qvoteds', 'upvoteds', 'downvoteds'));
    }
}
function qa_comment_set_userid($oldcomment, $userid, $handle, $cookieid)
{
    require_once QA_INCLUDE_DIR . 'db/votes.php';
    $postid = $oldcomment['postid'];
    qa_db_post_set_userid($postid, $userid);
    qa_db_uservote_remove_own($postid);
    qa_db_post_recount_votes($postid);
    qa_db_points_update_ifuser($oldcomment['userid'], array('cposts'));
    qa_db_points_update_ifuser($userid, array('cposts'));
    qa_report_event('c_claim', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $oldcomment['parentid'], 'oldcomment' => $oldcomment));
}