function qa_page_q_single_click_c($comment, $question, $parent, &$error) { $userid = qa_get_logged_in_userid(); $handle = qa_get_logged_in_handle(); $cookieid = qa_cookie_get(); $prefix = 'c' . $comment['postid'] . '_'; if (qa_clicked($prefix . 'dohide') && $comment['hideable'] || qa_clicked($prefix . 'doreject') && $comment['moderatable']) { if (qa_page_q_click_check_form_code($parent, $error)) { qa_comment_set_hidden($comment, true, $userid, $handle, $cookieid, $question, $parent); return true; } } if (qa_clicked($prefix . 'doreshow') && $comment['reshowable'] || qa_clicked($prefix . 'doapprove') && $comment['moderatable']) { if (qa_page_q_click_check_form_code($parent, $error)) { if ($comment['moderatable'] || $comment['reshowimmed']) { $status = QA_POST_STATUS_NORMAL; } else { $in = qa_page_q_prepare_post_for_filters($comment); $filtermodules = qa_load_modules_with('filter', 'filter_comment'); // run through filters but only for queued status foreach ($filtermodules as $filtermodule) { $tempin = $in; // always pass original comment in because we aren't modifying anything else $filtermodule->filter_comment($tempin, $temperrors, $question, $parent, $comment); $in['queued'] = $tempin['queued']; // only preserve queued status in loop } $status = $in['queued'] ? QA_POST_STATUS_QUEUED : QA_POST_STATUS_NORMAL; } qa_comment_set_status($comment, $status, $userid, $handle, $cookieid, $question, $parent); return true; } } if (qa_clicked($prefix . 'dodelete') && $comment['deleteable'] && qa_page_q_click_check_form_code($parent, $error)) { qa_comment_delete($comment, $question, $parent, $userid, $handle, $cookieid); return true; } if (qa_clicked($prefix . 'doclaim') && $comment['claimable'] && qa_page_q_click_check_form_code($parent, $error)) { if (qa_user_limits_remaining(QA_LIMIT_COMMENTS)) { qa_comment_set_userid($comment, $userid, $handle, $cookieid); return true; } else { $error = qa_lang_html('question/comment_limit'); } } if (qa_clicked($prefix . 'doflag') && $comment['flagbutton'] && qa_page_q_click_check_form_code($parent, $error)) { require_once QA_INCLUDE_DIR . 'app/votes.php'; $error = qa_flag_error_html($comment, $userid, qa_request()); if (!$error) { if (qa_flag_set_tohide($comment, $userid, $handle, $cookieid, $question)) { qa_comment_set_hidden($comment, true, null, null, null, $question, $parent); } // hiding not really by this user so pass nulls return true; } } if (qa_clicked($prefix . 'dounflag') && $comment['unflaggable'] && qa_page_q_click_check_form_code($parent, $error)) { require_once QA_INCLUDE_DIR . 'app/votes.php'; qa_flag_clear($comment, $userid, $handle, $cookieid); return true; } if (qa_clicked($prefix . 'doclearflags') && $comment['clearflaggable'] && qa_page_q_click_check_form_code($parent, $error)) { require_once QA_INCLUDE_DIR . 'app/votes.php'; qa_flags_clear_all($comment, $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_c($comment, $question, $parent, &$error) { $userid = qa_get_logged_in_userid(); $handle = qa_get_logged_in_handle(); $cookieid = qa_cookie_get(); $prefix = 'c' . $comment['postid'] . '_'; if (qa_page_q_clicked($prefix . 'dohide') && $comment['hideable'] || qa_page_q_clicked($prefix . 'doreject') && $comment['moderatable']) { qa_comment_set_hidden($comment, true, $userid, $handle, $cookieid, $question, $parent); return true; } if (qa_page_q_clicked($prefix . 'doreshow') && $comment['reshowable'] || qa_page_q_clicked($prefix . 'doapprove') && $comment['moderatable']) { qa_comment_set_hidden($comment, false, $userid, $handle, $cookieid, $question, $parent); return true; } if (qa_page_q_clicked($prefix . 'dodelete') && $comment['deleteable']) { qa_comment_delete($comment, $question, $parent, $userid, $handle, $cookieid); return true; } if (qa_page_q_clicked($prefix . 'doclaim') && $comment['claimable']) { if (qa_limits_remaining($userid, QA_LIMIT_COMMENTS)) { qa_comment_set_userid($comment, $userid, $handle, $cookieid); return true; } else { $error = qa_lang_html('question/comment_limit'); } } if (qa_page_q_clicked($prefix . 'doflag') && $comment['flagbutton']) { require_once QA_INCLUDE_DIR . 'qa-app-votes.php'; $error = qa_flag_error_html($comment, $userid, qa_request()); if (!$error) { if (qa_flag_set_tohide($comment, $userid, $handle, $cookieid, $question)) { qa_comment_set_hidden($comment, true, null, null, null, $question, $parent); } // hiding not really by this user so pass nulls return true; } } if (qa_page_q_clicked($prefix . 'dounflag') && $comment['unflaggable']) { require_once QA_INCLUDE_DIR . 'qa-app-votes.php'; qa_flag_clear($comment, $userid, $handle, $cookieid); return true; } if (qa_page_q_clicked($prefix . 'doclearflags') && $comment['clearflaggable']) { require_once QA_INCLUDE_DIR . 'qa-app-votes.php'; qa_flags_clear_all($comment, $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; }
$commentanswerid = null; } $commentanswer = @$answers[$comment['parentid']]; $commentanswerid = $commentanswer['postid']; if (qa_clicked('dohidec_' . $commentid) && $comment['hideable']) { qa_comment_set_hidden($comment, true, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $question, $commentanswer); qa_report_write_action($qa_login_userid, $qa_cookieid, 'c_hide', $questionid, $commentanswerid, $commentid); qa_redirect($qa_request, null, null, null, qa_anchor($commentparenttype, $comment['parentid'])); } if (qa_clicked('doshowc_' . $commentid) && $comment['reshowable']) { qa_comment_set_hidden($comment, false, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $question, $commentanswer); qa_report_write_action($qa_login_userid, $qa_cookieid, 'c_reshow', $questionid, $commentanswerid, $commentid); qa_redirect($qa_request, null, null, null, qa_anchor($commentparenttype, $comment['parentid'])); } if (qa_clicked('dodeletec_' . $commentid) && $comment['deleteable']) { qa_comment_delete($comment, $question, $commentanswer, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid); qa_report_write_action($qa_login_userid, $qa_cookieid, 'c_delete', $questionid, $commentanswerid, $commentid); qa_redirect($qa_request, null, null, null, qa_anchor($commentparenttype, $comment['parentid'])); } if (qa_clicked('doclaimc_' . $commentid) && $comment['claimable']) { if (qa_limits_remaining($qa_login_userid, 'C')) { qa_comment_set_userid($comment, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid); qa_report_write_action($qa_login_userid, $qa_cookieid, 'c_claim', $questionid, $commentanswerid, $commentid); qa_redirect($qa_request, null, null, null, qa_anchor($commentparenttype, $comment['parentid'])); } else { $pageerror = qa_lang_html('question/comment_limit'); } } if (qa_clicked('doflagc_' . $commentid) && $comment['flagbutton']) { require_once QA_INCLUDE_DIR . 'qa-app-votes.php'; $pageerror = qa_flag_error_html($comment, $qa_login_userid, $qa_request);