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_answer_create($userid, $handle, $cookieid, $content, $format, $text, $notify, $email, $question, $queued = false) { $postid = qa_db_post_create($queued ? 'A_QUEUED' : 'A', $question['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), null, $content, $format, null, qa_combine_notify_email($userid, $notify, $email), $question['categoryid']); qa_db_posts_calc_category_path($postid); if (!$queued) { if ($question['type'] == 'Q') { // don't index answer if parent question is hidden or queued qa_post_index($postid, 'A', $question['postid'], $question['postid'], null, $content, $format, $text, null, $question['categoryid']); } qa_db_post_acount_update($question['postid']); qa_db_hotness_update($question['postid']); qa_db_points_update_ifuser($userid, 'aposts'); qa_db_acount_update(); qa_db_unaqcount_update(); } qa_report_event($queued ? 'a_queue' : 'a_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $question['postid'], 'parent' => $question, 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $question['categoryid'], 'notify' => $notify, 'email' => $email)); return $postid; }
function qa_answer_to_comment($oldanswer, $parentid, $content, $format, $text, $notify, $userid, $handle, $cookieid, $question, $answers, $commentsfollows) { $parent = isset($answers[$parentid]) ? $answers[$parentid] : $question; qa_post_unindex($oldanswer['postid']); $setupdated = strcmp($oldanswer['content'], $content) || strcmp($oldanswer['format'], $format); $setuserid = $setupdated ? $userid : null; $setip = $setupdated ? qa_remote_ip_address() : null; qa_db_post_set_type($oldanswer['postid'], $oldanswer['hidden'] ? 'C_HIDDEN' : 'C', $setuserid, $setip); qa_db_post_set_parent($oldanswer['postid'], $parentid, $setuserid, $setip); qa_db_post_set_content($oldanswer['postid'], $oldanswer['title'], $content, $format, $oldanswer['tags'], $notify, $setuserid, $setip); foreach ($commentsfollows as $commentfollow) { if ($commentfollow['parentid'] == $oldanswer['postid']) { // do same thing for comments and follows qa_db_post_set_parent($commentfollow['postid'], $parentid, null, null); } } qa_db_points_update_ifuser($oldanswer['userid'], array('aposts', 'aselecteds', 'cposts')); qa_db_post_acount_update($question['postid']); qa_db_hotness_update($question['postid']); qa_db_acount_update(); qa_db_ccount_update(); qa_db_unaqcount_update(); if (!($oldanswer['hidden'] || $question['hidden'] || $parent['hidden'])) { // only index if none of the things it depends on are hidden require_once QA_INCLUDE_DIR . 'qa-app-format.php'; qa_post_index($oldanswer['postid'], 'C', $question['postid'], null, $text, null); } qa_report_event('a_to_c', $userid, $handle, $cookieid, array('postid' => $oldanswer['postid'], 'parentid' => $parentid, 'parenttype' => $parent['basetype'], 'questionid' => $question['postid'], 'content' => $content, 'format' => $format, 'text' => $text, 'oldcontent' => $oldanswer['content'], 'oldformat' => $oldanswer['format'])); }
function qa_answer_create($userid, $handle, $cookieid, $content, $format, $text, $notify, $email, $question) { $postid = qa_db_post_create('A', $question['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), null, $content, $format, null, qa_combine_notify_email($userid, $notify, $email), $question['categoryid']); qa_db_posts_calc_category_path($postid); if (!$question['hidden']) { // don't index answer if parent question is hidden qa_post_index($postid, 'A', $question['postid'], null, $text, null); } qa_db_post_acount_update($question['postid']); qa_db_hotness_update($question['postid']); qa_db_points_update_ifuser($userid, 'aposts'); qa_db_acount_update(); qa_db_unaqcount_update(); if (isset($question['notify']) && !qa_post_is_by_user($question, $userid, $cookieid)) { require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; require_once QA_INCLUDE_DIR . 'qa-app-options.php'; require_once QA_INCLUDE_DIR . 'qa-util-string.php'; $blockwordspreg = qa_get_block_words_preg(); $sendtitle = qa_block_words_replace($question['title'], $blockwordspreg); $sendtext = qa_block_words_replace($text, $blockwordspreg); qa_send_notification($question['userid'], $question['notify'], @$question['handle'], qa_lang('emails/q_answered_subject'), qa_lang('emails/q_answered_body'), array('^a_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => $sendtitle, '^a_content' => $sendtext, '^url' => qa_path(qa_q_request($question['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor('A', $postid)))); } // notify all members of the category about the new post require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; require_once QA_INCLUDE_DIR . 'mp-db-users.php'; require_once QA_INCLUDE_DIR . 'mp-app-users.php'; // find list of members of the category $recipients = mp_get_category_userids(mp_get_categoryid()); // remove the current user from the list of recipients unset($recipients[$userid]); // get details for current category $currentcategory = mp_get_categoryinfo(mp_get_categoryid()); foreach ($recipients as $recipient) { // retrieve the user flags $userflags = mp_get_user_flags($recipient['userid']); // check user flags to determine whether user should be notified or not // of the new answer post if (!($userflags & QA_USER_FLAGS_NOTIFY_ANSWERS)) { // for each member, send notification qa_send_notification($recipient['userid'], null, null, qa_lang('emails/q_answered_with_category_subject'), qa_lang('emails/q_answered_with_category_body'), array('^a_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => $question['title'], '^a_content' => $text, '^url' => qa_path(qa_q_request($question['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor('A', $postid)), '^category_title' => $currentcategory['title'] . $userflags)); } } qa_report_event('a_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $question['postid'], 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $question['categoryid'], 'notify' => $notify, 'email' => $email)); return $postid; }
function qa_update_q_counts_for_a($questionid) { qa_db_post_acount_update($questionid); qa_db_hotness_update($questionid); qa_db_acount_update(); qa_db_unaqcount_update(); qa_db_unupaqcount_update(); }
function qa_answer_to_comment($oldanswer, $parentid, $content, $format, $text, $notify, $userid, $handle, $cookieid, $question, $answers, $commentsfollows) { $parent = isset($answers[$parentid]) ? $answers[$parentid] : $question; qa_post_unindex($oldanswer['postid']); $contentchanged = strcmp($oldanswer['content'], $content) || strcmp($oldanswer['format'], $format); qa_db_post_set_type($oldanswer['postid'], substr_replace($oldanswer['type'], 'C', 0, 1), $userid, qa_remote_ip_address(), QA_UPDATE_TYPE); qa_db_post_set_parent($oldanswer['postid'], $parentid); qa_db_post_set_content($oldanswer['postid'], $oldanswer['title'], $content, $format, $oldanswer['tags'], $notify, $contentchanged ? $userid : null, $contentchanged ? qa_remote_ip_address() : null); foreach ($commentsfollows as $commentfollow) { if ($commentfollow['parentid'] == $oldanswer['postid']) { // do same thing for comments and follows qa_db_post_set_parent($commentfollow['postid'], $parentid); } } qa_db_points_update_ifuser($oldanswer['userid'], array('aposts', 'aselecteds', 'cposts')); qa_db_post_acount_update($question['postid']); qa_db_hotness_update($question['postid']); qa_db_acount_update(); qa_db_ccount_update(); qa_db_unaqcount_update(); qa_db_unupaqcount_update(); if ($oldanswer['type'] == 'A' && $question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A')) { // only if all fully visible qa_post_index($oldanswer['postid'], 'C', $question['postid'], $parentid, null, $content, $format, $text, null, $oldanswer['categoryid']); } qa_report_event('a_to_c', $userid, $handle, $cookieid, array('postid' => $oldanswer['postid'], 'parentid' => $parentid, 'parenttype' => $parent['basetype'], 'questionid' => $question['postid'], 'content' => $content, 'format' => $format, 'text' => $text, 'oldcontent' => $oldanswer['content'], 'oldformat' => $oldanswer['format'], 'oldanswer' => $oldanswer, 'contentchanged' => $contentchanged)); }