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_delete($postid) { $oldpost = qa_post_get_full($postid, 'QAC'); if (!$oldpost['hidden']) { qa_post_set_hidden($postid, true, null); $oldpost = qa_post_get_full($postid, 'QAC'); } switch ($oldpost['basetype']) { case 'Q': $answers = qa_post_get_question_answers($postid); $commentsfollows = qa_post_get_question_commentsfollows($postid); $closepost = qa_post_get_question_closepost($postid); if (count($answers) || count($commentsfollows)) { qa_fatal_error('Could not delete question ID due to dependents: ' . $postid); } qa_question_delete($oldpost, null, null, null, $closepost); break; case 'A': $question = qa_post_get_full($oldpost['parentid'], 'Q'); $commentsfollows = qa_post_get_answer_commentsfollows($postid); if (count($commentsfollows)) { qa_fatal_error('Could not delete answer ID due to dependents: ' . $postid); } qa_answer_delete($oldpost, $question, null, null, null); break; case 'C': $parent = qa_post_get_full($oldpost['parentid'], 'QA'); $question = qa_post_parent_to_question($parent); qa_comment_delete($oldpost, $question, $parent, null, null, null); break; } }
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; }
/** * Fetches the child posts of the question and delete them recursively * * @param $postid */ function ami_dhp_post_delete_recursive($postid) { require_once QA_INCLUDE_DIR . 'qa-app-admin.php'; require_once QA_INCLUDE_DIR . 'qa-db-admin.php'; require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; global $ami_dhp_posts_deleted; if (is_null($ami_dhp_posts_deleted)) { $ami_dhp_posts_deleted = array(); } if (in_array($postid, $ami_dhp_posts_deleted)) { return; } $oldpost = qa_post_get_full($postid, 'QAC'); if (!$oldpost['hidden']) { qa_post_set_hidden($postid, true, null); $oldpost = qa_post_get_full($postid, 'QAC'); } switch ($oldpost['basetype']) { case 'Q': $answers = qa_post_get_question_answers($postid); $commentsfollows = qa_post_get_question_commentsfollows($postid); $closepost = qa_post_get_question_closepost($postid); if (count($answers)) { foreach ($answers as $answer) { ami_dhp_post_delete_recursive($answer['postid']); } } if (count($commentsfollows)) { foreach ($commentsfollows as $commentsfollow) { ami_dhp_post_delete_recursive($commentsfollow['postid']); } } if (!in_array($oldpost['postid'], $ami_dhp_posts_deleted)) { qa_question_delete($oldpost, null, null, null, $closepost); $ami_dhp_posts_deleted[] = $oldpost['postid']; } break; case 'A': $question = qa_post_get_full($oldpost['parentid'], 'Q'); $commentsfollows = qa_post_get_answer_commentsfollows($postid); if (count($commentsfollows)) { foreach ($commentsfollows as $commentsfollow) { ami_dhp_post_delete_recursive($commentsfollow['postid']); } } if (!in_array($oldpost['postid'], $ami_dhp_posts_deleted)) { qa_answer_delete($oldpost, $question, null, null, null); $ami_dhp_posts_deleted[] = $oldpost['postid']; } break; case 'C': $parent = qa_post_get_full($oldpost['parentid'], 'QA'); $question = qa_post_parent_to_question($parent); if (!in_array($oldpost['postid'], $ami_dhp_posts_deleted)) { qa_comment_delete($oldpost, $question, $parent, null, null, null); $ami_dhp_posts_deleted[] = $oldpost['postid']; } break; } }
function qa_recalc_perform_step(&$state) { $continue = false; @(list($operation, $length, $next, $done) = explode(',', $state)); switch ($operation) { case 'doreindexposts': qa_recalc_transition($state, 'doreindexposts_postcount'); break; case 'doreindexposts_postcount': qa_db_qcount_update(); qa_db_acount_update(); qa_db_ccount_update(); qa_recalc_transition($state, 'doreindexposts_reindex'); break; case 'doreindexposts_reindex': $posts = qa_db_posts_get_for_reindexing($next, 10); if (count($posts)) { require_once QA_INCLUDE_DIR . 'qa-app-format.php'; $lastpostid = max(array_keys($posts)); qa_db_prepare_for_reindexing($next, $lastpostid); foreach ($posts as $postid => $post) { qa_post_index($postid, $post['type'], $post['questionid'], $post['title'], qa_viewer_text($post['content'], $post['format']), $post['tags'], true); } $next = 1 + $lastpostid; $done += count($posts); $continue = true; } else { qa_db_truncate_indexes($next); qa_recalc_transition($state, 'doreindexposts_wordcount'); } break; case 'doreindexposts_wordcount': $wordids = qa_db_words_prepare_for_recounting($next, 1000); if (count($wordids)) { $lastwordid = max($wordids); qa_db_words_recount($next, $lastwordid); $next = 1 + $lastwordid; $done += count($wordids); $continue = true; } else { qa_db_tagcount_update(); // this is quick so just do it here qa_recalc_transition($state, 'doreindexposts_complete'); } break; case 'dorecountposts': qa_recalc_transition($state, 'dorecountposts_postcount'); break; case 'dorecountposts_postcount': qa_db_qcount_update(); qa_db_acount_update(); qa_db_ccount_update(); qa_db_unaqcount_update(); qa_recalc_transition($state, 'dorecountposts_recount'); break; case 'dorecountposts_recount': $postids = qa_db_posts_get_for_recounting($next, 1000); if (count($postids)) { $lastpostid = max($postids); qa_db_posts_recount($next, $lastpostid); $next = 1 + $lastpostid; $done += count($postids); $continue = true; } else { qa_recalc_transition($state, 'dorecountposts_complete'); } break; case 'dorecalcpoints': qa_recalc_transition($state, 'dorecalcpoints_usercount'); break; case 'dorecalcpoints_usercount': qa_db_userpointscount_update(); // for progress update - not necessarily accurate qa_recalc_transition($state, 'dorecalcpoints_recalc'); break; case 'dorecalcpoints_recalc': $userids = qa_db_users_get_for_recalc_points($next, 10); if (count($userids)) { $lastuserid = max($userids); qa_db_users_recalc_points($next, $lastuserid); $next = 1 + $lastuserid; $done += count($userids); $continue = true; } else { qa_db_truncate_userpoints($next); qa_db_userpointscount_update(); // quick so just do it here qa_recalc_transition($state, 'dorecalcpoints_complete'); } break; case 'dorecalccategories': qa_recalc_transition($state, 'dorecalccategories_postcount'); break; case 'dorecalccategories_postcount': qa_db_acount_update(); qa_db_ccount_update(); qa_recalc_transition($state, 'dorecalccategories_postupdate'); break; case 'dorecalccategories_postupdate': $postids = qa_db_posts_get_for_recategorizing($next, 100); if (count($postids)) { $lastpostid = max($postids); qa_db_posts_recalc_categoryid($next, $lastpostid); qa_db_posts_calc_category_path($next, $lastpostid); $next = 1 + $lastpostid; $done += count($postids); $continue = true; } else { qa_recalc_transition($state, 'dorecalccategories_recount'); } break; case 'dorecalccategories_recount': $categoryids = qa_db_categories_get_for_recalcs($next, 10); if (count($categoryids)) { $lastcategoryid = max($categoryids); foreach ($categoryids as $categoryid) { qa_db_ifcategory_qcount_update($categoryid); } $next = 1 + $lastcategoryid; $done += count($categoryids); $continue = true; } else { qa_recalc_transition($state, 'dorecalccategories_backpaths'); } break; case 'dorecalccategories_backpaths': $categoryids = qa_db_categories_get_for_recalcs($next, 10); if (count($categoryids)) { $lastcategoryid = max($categoryids); qa_db_categories_recalc_backpaths($next, $lastcategoryid); $next = 1 + $lastcategoryid; $done += count($categoryids); $continue = true; } else { qa_recalc_transition($state, 'dorecalccategories_complete'); } break; case 'dodeletehidden': qa_recalc_transition($state, 'dodeletehidden_comments'); break; case 'dodeletehidden_comments': $posts = qa_db_posts_get_for_deleting('C', $next, 1); if (count($posts)) { $postid = $posts[0]; $oldcomment = qa_db_single_select(qa_db_full_post_selectspec(null, $postid)); $parent = qa_db_single_select(qa_db_full_post_selectspec(null, $oldcomment['parentid'])); if ($parent['basetype'] == 'Q') { $question = $parent; $answer = null; } else { $question = qa_db_single_select(qa_db_full_post_selectspec(null, $parent['parentid'])); $answer = $parent; } qa_comment_delete($oldcomment, $question, $answer, null, null, null); $next = 1 + $postid; $done++; $continue = true; } else { qa_recalc_transition($state, 'dodeletehidden_answers'); } break; case 'dodeletehidden_answers': $posts = qa_db_posts_get_for_deleting('A', $next, 1); if (count($posts)) { $postid = $posts[0]; $oldanswer = qa_db_single_select(qa_db_full_post_selectspec(null, $postid)); $question = qa_db_single_select(qa_db_full_post_selectspec(null, $oldanswer['parentid'])); qa_answer_delete($oldanswer, $question, null, null, null); $next = 1 + $postid; $done++; $continue = true; } else { qa_recalc_transition($state, 'dodeletehidden_questions'); } break; case 'dodeletehidden_questions': $posts = qa_db_posts_get_for_deleting('Q', $next, 1); if (count($posts)) { $postid = $posts[0]; $oldquestion = qa_db_single_select(qa_db_full_post_selectspec(null, $postid)); qa_question_delete($oldquestion, null, null, null); $next = 1 + $postid; $done++; $continue = true; } else { qa_recalc_transition($state, 'dodeletehidden_complete'); } break; default: $state = ''; break; } if ($continue) { $state = $operation . ',' . $length . ',' . $next . ',' . $done; } return $continue && $done < $length; }
} } // Process hide, show, delete, flag, unflag, edit, save, comment or follow-on button for answers foreach ($answers as $answerid => $answer) { if (qa_clicked('dohidea_' . $answerid) && $answer['hideable']) { qa_answer_set_hidden($answer, true, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $question, $commentsfollows); qa_report_write_action($qa_login_userid, $qa_cookieid, 'a_hide', $questionid, $answerid, null); qa_redirect($qa_request, null, null, null, qa_anchor('A', $answerid)); } if (qa_clicked('doshowa_' . $answerid) && $answer['reshowable']) { qa_answer_set_hidden($answer, false, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $question, $commentsfollows); qa_report_write_action($qa_login_userid, $qa_cookieid, 'a_reshow', $questionid, $answerid, null); qa_redirect($qa_request, null, null, null, qa_anchor('A', $answerid)); } if (qa_clicked('dodeletea_' . $answerid) && $answer['deleteable']) { qa_answer_delete($answer, $question, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid); qa_report_write_action($qa_login_userid, $qa_cookieid, 'a_delete', $questionid, $answerid, null); qa_redirect($qa_request); } if (qa_clicked('doclaima_' . $answerid) && $answer['claimable']) { if (qa_limits_remaining($qa_login_userid, 'A')) { // already checked 'permit_post_a' qa_answer_set_userid($answer, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid); qa_report_write_action($qa_login_userid, $qa_cookieid, 'a_claim', $questionid, $answerid, null); qa_redirect($qa_request, null, null, null, qa_anchor('A', $answerid)); } else { $pageerror = qa_lang_html('question/answer_limit'); } } if (qa_clicked('doflaga_' . $answerid) && $answer['flagbutton']) { require_once QA_INCLUDE_DIR . 'qa-app-votes.php';