function qa_page_q_single_click_a($answer, $question, $answers, $commentsfollows, $allowselectmove, &$error) { $userid = qa_get_logged_in_userid(); $handle = qa_get_logged_in_handle(); $cookieid = qa_cookie_get(); $prefix = 'a' . $answer['postid'] . '_'; if (qa_clicked($prefix . 'doselect') && $question['aselectable'] && ($allowselectmove || !isset($question['selchildid']) && !qa_opt('do_close_on_select')) && qa_page_q_click_check_form_code($answer, $error)) { qa_question_set_selchildid($userid, $handle, $cookieid, $question, $answer['postid'], $answers); return true; } if (qa_clicked($prefix . 'dounselect') && $question['aselectable'] && $question['selchildid'] == $answer['postid'] && ($allowselectmove || !qa_opt('do_close_on_select')) && qa_page_q_click_check_form_code($answer, $error)) { qa_question_set_selchildid($userid, $handle, $cookieid, $question, null, $answers); return true; } if (qa_clicked($prefix . 'dohide') && $answer['hideable'] || qa_clicked($prefix . 'doreject') && $answer['moderatable']) { if (qa_page_q_click_check_form_code($answer, $error)) { qa_answer_set_hidden($answer, true, $userid, $handle, $cookieid, $question, $commentsfollows); return true; } } if (qa_clicked($prefix . 'doreshow') && $answer['reshowable'] || qa_clicked($prefix . 'doapprove') && $answer['moderatable']) { if (qa_page_q_click_check_form_code($answer, $error)) { if ($answer['moderatable'] || $answer['reshowimmed']) { $status = QA_POST_STATUS_NORMAL; } else { $in = qa_page_q_prepare_post_for_filters($answer); $filtermodules = qa_load_modules_with('filter', 'filter_answer'); // run through filters but only for queued status foreach ($filtermodules as $filtermodule) { $tempin = $in; // always pass original answer in because we aren't modifying anything else $filtermodule->filter_answer($tempin, $temperrors, $question, $answer); $in['queued'] = $tempin['queued']; // only preserve queued status in loop } $status = $in['queued'] ? QA_POST_STATUS_QUEUED : QA_POST_STATUS_NORMAL; } qa_answer_set_status($answer, $status, $userid, $handle, $cookieid, $question, $commentsfollows); return true; } } if (qa_clicked($prefix . 'dodelete') && $answer['deleteable'] && qa_page_q_click_check_form_code($answer, $error)) { qa_answer_delete($answer, $question, $userid, $handle, $cookieid); return true; } if (qa_clicked($prefix . 'doclaim') && $answer['claimable'] && qa_page_q_click_check_form_code($answer, $error)) { if (qa_user_limits_remaining(QA_LIMIT_ANSWERS)) { // already checked 'permit_post_a' qa_answer_set_userid($answer, $userid, $handle, $cookieid); return true; } else { $error = qa_lang_html('question/answer_limit'); } } if (qa_clicked($prefix . 'doflag') && $answer['flagbutton'] && qa_page_q_click_check_form_code($answer, $error)) { require_once QA_INCLUDE_DIR . 'app/votes.php'; $error = qa_flag_error_html($answer, $userid, qa_request()); if (!$error) { if (qa_flag_set_tohide($answer, $userid, $handle, $cookieid, $question)) { qa_answer_set_hidden($answer, true, null, null, null, $question, $commentsfollows); } // hiding not really by this user so pass nulls return true; } } if (qa_clicked($prefix . 'dounflag') && $answer['unflaggable'] && qa_page_q_click_check_form_code($answer, $error)) { require_once QA_INCLUDE_DIR . 'app/votes.php'; qa_flag_clear($answer, $userid, $handle, $cookieid); return true; } if (qa_clicked($prefix . 'doclearflags') && $answer['clearflaggable'] && qa_page_q_click_check_form_code($answer, $error)) { require_once QA_INCLUDE_DIR . 'app/votes.php'; qa_flags_clear_all($answer, $userid, $handle, $cookieid); return true; } return false; }
function qa_post_set_selchildid($questionid, $answerid, $byuserid = null) { $oldquestion = qa_post_get_full($questionid, 'Q'); $byhandle = qa_post_userid_to_handle($byuserid); $answers = qa_post_get_question_answers($questionid); if (isset($answerid) && !isset($answers[$answerid])) { qa_fatal_error('Answer ID could not be found: ' . $answerid); } qa_question_set_selchildid($byuserid, $byuserid, null, $oldquestion, $answerid, $answers); }
function qa_page_q_single_click_a($answer, $question, $answers, $commentsfollows, $allowselectmove, &$error) { $userid = qa_get_logged_in_userid(); $handle = qa_get_logged_in_handle(); $cookieid = qa_cookie_get(); $prefix = 'a' . $answer['postid'] . '_'; if (qa_page_q_clicked($prefix . 'doselect') && $question['aselectable'] && ($allowselectmove || !isset($question['selchildid']) && !qa_opt('do_close_on_select'))) { qa_question_set_selchildid($userid, $handle, $cookieid, $question, $answer['postid'], $answers); return true; } if (qa_page_q_clicked($prefix . 'dounselect') && $question['aselectable'] && $question['selchildid'] == $answer['postid'] && ($allowselectmove || !qa_opt('do_close_on_select'))) { qa_question_set_selchildid($userid, $handle, $cookieid, $question, null, $answers); return true; } if (qa_page_q_clicked($prefix . 'dohide') && $answer['hideable'] || qa_page_q_clicked($prefix . 'doreject') && $answer['moderatable']) { qa_answer_set_hidden($answer, true, $userid, $handle, $cookieid, $question, $commentsfollows); return true; } if (qa_page_q_clicked($prefix . 'doreshow') && $answer['reshowable'] || qa_page_q_clicked($prefix . 'doapprove') && $answer['moderatable']) { qa_answer_set_hidden($answer, false, $userid, $handle, $cookieid, $question, $commentsfollows); return true; } if (qa_page_q_clicked($prefix . 'dodelete') && $answer['deleteable']) { qa_answer_delete($answer, $question, $userid, $handle, $cookieid); return true; } if (qa_page_q_clicked($prefix . 'doclaim') && $answer['claimable']) { if (qa_limits_remaining($userid, QA_LIMIT_ANSWERS)) { // already checked 'permit_post_a' qa_answer_set_userid($answer, $userid, $handle, $cookieid); return true; } else { $error = qa_lang_html('question/answer_limit'); } } if (qa_page_q_clicked($prefix . 'doflag') && $answer['flagbutton']) { require_once QA_INCLUDE_DIR . 'qa-app-votes.php'; $error = qa_flag_error_html($answer, $userid, qa_request()); if (!$error) { if (qa_flag_set_tohide($answer, $userid, $handle, $cookieid, $question)) { qa_answer_set_hidden($answer, true, null, null, null, $question, $commentsfollows); } // hiding not really by this user so pass nulls return true; } } if (qa_page_q_clicked($prefix . 'dounflag') && $answer['unflaggable']) { require_once QA_INCLUDE_DIR . 'qa-app-votes.php'; qa_flag_clear($answer, $userid, $handle, $cookieid); return true; } if (qa_page_q_clicked($prefix . 'doclearflags') && $answer['clearflaggable']) { require_once QA_INCLUDE_DIR . 'qa-app-votes.php'; qa_flags_clear_all($answer, $userid, $handle, $cookieid); return true; } return false; }
function qa_answer_set_status($oldanswer, $status, $userid, $handle, $cookieid, $question, $commentsfollows) { require_once QA_INCLUDE_DIR . 'app/format.php'; $washidden = $oldanswer['type'] == 'A_HIDDEN'; $wasqueued = $oldanswer['type'] == 'A_QUEUED'; $wasrequeued = $wasqueued && isset($oldanswer['updated']); qa_post_unindex($oldanswer['postid']); foreach ($commentsfollows as $comment) { if ($comment['basetype'] == 'C' && $comment['parentid'] == $oldanswer['postid']) { qa_post_unindex($comment['postid']); } } $setupdated = false; $event = null; if ($status == QA_POST_STATUS_QUEUED) { $newtype = 'A_QUEUED'; if (!$wasqueued) { $event = 'a_requeue'; } // same event whether it was hidden or shown before } elseif ($status == QA_POST_STATUS_HIDDEN) { $newtype = 'A_HIDDEN'; if (!$washidden) { $event = $wasqueued ? 'a_reject' : 'a_hide'; if (!$wasqueued) { $setupdated = true; } } if ($question['selchildid'] == $oldanswer['postid']) { // remove selected answer qa_question_set_selchildid(null, null, null, $question, null, $answers); } } elseif ($status == QA_POST_STATUS_NORMAL) { $newtype = 'A'; if ($wasqueued) { $event = 'a_approve'; } elseif ($washidden) { $event = 'a_reshow'; $setupdated = true; } } else { qa_fatal_error('Unknown status in qa_answer_set_status(): ' . $status); } qa_db_post_set_type($oldanswer['postid'], $newtype, $setupdated ? $userid : null, $setupdated ? qa_remote_ip_address() : null, QA_UPDATE_VISIBLE); if ($wasqueued && $status == QA_POST_STATUS_NORMAL && qa_opt('moderate_update_time')) { // ... for approval of a post, can set time to now instead if ($wasrequeued) { qa_db_post_set_updated($oldanswer['postid'], null); } else { qa_db_post_set_created($oldanswer['postid'], null); } } qa_update_q_counts_for_a($question['postid']); qa_db_points_update_ifuser($oldanswer['userid'], array('aposts', 'aselecteds')); if ($wasqueued || $status == QA_POST_STATUS_QUEUED) { qa_db_queuedcount_update(); } if ($oldanswer['flagcount']) { qa_db_flaggedcount_update(); } if ($question['type'] == 'Q' && $status == QA_POST_STATUS_NORMAL) { // even if answer visible, don't index if question is hidden or queued qa_post_index($oldanswer['postid'], 'A', $question['postid'], $oldanswer['parentid'], null, $oldanswer['content'], $oldanswer['format'], qa_viewer_text($oldanswer['content'], $oldanswer['format']), null, $oldanswer['categoryid']); foreach ($commentsfollows as $comment) { if ($comment['type'] == 'C' && $comment['parentid'] == $oldanswer['postid']) { // and don't index hidden/queued comments qa_post_index($comment['postid'], $comment['type'], $question['postid'], $comment['parentid'], null, $comment['content'], $comment['format'], qa_viewer_text($comment['content'], $comment['format']), null, $comment['categoryid']); } } } $eventparams = array('postid' => $oldanswer['postid'], 'parentid' => $oldanswer['parentid'], 'parent' => $question, 'content' => $oldanswer['content'], 'format' => $oldanswer['format'], 'text' => qa_viewer_text($oldanswer['content'], $oldanswer['format']), 'categoryid' => $oldanswer['categoryid'], 'name' => $oldanswer['name']); if (isset($event)) { qa_report_event($event, $userid, $handle, $cookieid, $eventparams + array('oldanswer' => $oldanswer)); } if ($wasqueued && $status == QA_POST_STATUS_NORMAL && !$wasrequeued) { require_once QA_INCLUDE_DIR . 'util/string.php'; qa_report_event('a_post', $oldanswer['userid'], $oldanswer['handle'], $oldanswer['cookieid'], $eventparams + array('notify' => isset($oldanswer['notify']), 'email' => qa_email_validate($oldanswer['notify']) ? $oldanswer['notify'] : null, 'delayed' => $oldanswer['created'])); } }
} } // Process incoming selection of the best answer if ($question['aselectable']) { if (qa_clicked('select_')) { $inselect = ''; } // i.e. unselect current selection foreach ($answers as $answerid => $answer) { if (qa_clicked('select_' . $answerid)) { $inselect = $answerid; break; } } if (isset($inselect)) { qa_question_set_selchildid($qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $question, strlen($inselect) ? $inselect : null, $answers); qa_report_write_action($qa_login_userid, $qa_cookieid, strlen($inselect) ? 'a_select' : 'a_unselect', $questionid, strlen($inselect) ? $answerid : $question['selchildid'], null); qa_redirect($qa_request, null, null, null, qa_anchor('A', $answerid)); } } // Process hiding or showing or claiming or comment on a question if (qa_clicked('dohideq') && $question['hideable']) { qa_question_set_hidden($question, true, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $answers, $commentsfollows); qa_report_write_action($qa_login_userid, $qa_cookieid, 'q_hide', $questionid, null, null); qa_redirect($qa_request); } if (qa_clicked('doshowq') && $question['reshowable']) { qa_question_set_hidden($question, false, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $answers, $commentsfollows); qa_report_write_action($qa_login_userid, $qa_cookieid, 'q_reshow', $questionid, null, null); qa_redirect($qa_request); }