function qa_recalc_perform_step(&$state) { $continue = false; @(list($operation, $length, $next, $done) = explode("\t", $state)); switch ($operation) { case 'doreindexcontent': qa_recalc_transition($state, 'doreindexcontent_pagereindex'); break; case 'doreindexcontent_pagereindex': $pages = qa_db_pages_get_for_reindexing($next, 10); if (count($pages)) { require_once QA_INCLUDE_DIR . 'app/format.php'; $lastpageid = max(array_keys($pages)); foreach ($pages as $pageid => $page) { if (!($page['flags'] & QA_PAGE_FLAGS_EXTERNAL)) { $searchmodules = qa_load_modules_with('search', 'unindex_page'); foreach ($searchmodules as $searchmodule) { $searchmodule->unindex_page($pageid); } $searchmodules = qa_load_modules_with('search', 'index_page'); if (count($searchmodules)) { $indextext = qa_viewer_text($page['content'], 'html'); foreach ($searchmodules as $searchmodule) { $searchmodule->index_page($pageid, $page['tags'], $page['heading'], $page['content'], 'html', $indextext); } } } } $next = 1 + $lastpageid; $done += count($pages); $continue = true; } else { qa_recalc_transition($state, 'doreindexcontent_postcount'); } break; case 'doreindexcontent_postcount': qa_db_qcount_update(); qa_db_acount_update(); qa_db_ccount_update(); qa_recalc_transition($state, 'doreindexcontent_postreindex'); break; case 'doreindexcontent_postreindex': $posts = qa_db_posts_get_for_reindexing($next, 10); if (count($posts)) { require_once QA_INCLUDE_DIR . 'app/format.php'; $lastpostid = max(array_keys($posts)); qa_db_prepare_for_reindexing($next, $lastpostid); qa_suspend_update_counts(); foreach ($posts as $postid => $post) { qa_post_unindex($postid); qa_post_index($postid, $post['type'], $post['questionid'], $post['parentid'], $post['title'], $post['content'], $post['format'], qa_viewer_text($post['content'], $post['format']), $post['tags'], $post['categoryid']); } $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_db_unselqcount_update(); qa_recalc_transition($state, 'dorecountposts_votecount'); break; case 'dorecountposts_votecount': $postids = qa_db_posts_get_for_recounting($next, 1000); if (count($postids)) { $lastpostid = max($postids); qa_db_posts_votes_recount($next, $lastpostid); $next = 1 + $lastpostid; $done += count($postids); $continue = true; } else { qa_recalc_transition($state, 'dorecountposts_acount'); } break; case 'dorecountposts_acount': $postids = qa_db_posts_get_for_recounting($next, 1000); if (count($postids)) { $lastpostid = max($postids); qa_db_posts_answers_recount($next, $lastpostid); $next = 1 + $lastpostid; $done += count($postids); $continue = true; } else { qa_db_unupaqcount_update(); 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_db_uapprovecount_update(); // needs to be somewhere and this is the most appropriate place qa_recalc_transition($state, 'dorecalcpoints_recalc'); break; case 'dorecalcpoints_recalc': $recalccount = 10; $userids = qa_db_users_get_for_recalc_points($next, $recalccount + 1); // get one extra so we know where to start from next $gotcount = count($userids); $recalccount = min($recalccount, $gotcount); // can't recalc more than we got if ($recalccount > 0) { $lastuserid = $userids[$recalccount - 1]; qa_db_users_recalc_points($next, $lastuserid); $done += $recalccount; } else { $lastuserid = $next; } // for truncation if ($gotcount > $recalccount) { // more left to do $next = $userids[$recalccount]; // start next round at first one not recalculated $continue = true; } else { qa_db_truncate_userpoints($lastuserid); qa_db_userpointscount_update(); // quick so just do it here qa_recalc_transition($state, 'dorecalcpoints_complete'); } break; case 'dorefillevents': qa_recalc_transition($state, 'dorefillevents_qcount'); break; case 'dorefillevents_qcount': qa_db_qcount_update(); qa_recalc_transition($state, 'dorefillevents_refill'); break; case 'dorefillevents_refill': $questionids = qa_db_qs_get_for_event_refilling($next, 1); if (count($questionids)) { require_once QA_INCLUDE_DIR . 'app/events.php'; require_once QA_INCLUDE_DIR . 'app/updates.php'; require_once QA_INCLUDE_DIR . 'util/sort.php'; $lastquestionid = max($questionids); foreach ($questionids as $questionid) { // Retrieve all posts relating to this question list($question, $childposts, $achildposts) = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $questionid), qa_db_full_child_posts_selectspec(null, $questionid), qa_db_full_a_child_posts_selectspec(null, $questionid)); // Merge all posts while preserving keys as postids $posts = array($questionid => $question); foreach ($childposts as $postid => $post) { $posts[$postid] = $post; } foreach ($achildposts as $postid => $post) { $posts[$postid] = $post; } // Creation and editing of each post foreach ($posts as $postid => $post) { $followonq = $post['basetype'] == 'Q' && $postid != $questionid; if ($followonq) { $updatetype = QA_UPDATE_FOLLOWS; } elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'Q') { $updatetype = QA_UPDATE_C_FOR_Q; } elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'A') { $updatetype = QA_UPDATE_C_FOR_A; } else { $updatetype = null; } qa_create_event_for_q_user($questionid, $postid, $updatetype, $post['userid'], @$posts[$post['parentid']]['userid'], $post['created']); if (isset($post['updated']) && !$followonq) { qa_create_event_for_q_user($questionid, $postid, $post['updatetype'], $post['lastuserid'], $post['userid'], $post['updated']); } } // Tags and categories of question qa_create_event_for_tags($question['tags'], $questionid, null, $question['userid'], $question['created']); qa_create_event_for_category($question['categoryid'], $questionid, null, $question['userid'], $question['created']); // Collect comment threads $parentidcomments = array(); foreach ($posts as $postid => $post) { if ($post['basetype'] == 'C') { $parentidcomments[$post['parentid']][$postid] = $post; } } // For each comment thread, notify all previous comment authors of each comment in the thread (could get slow) foreach ($parentidcomments as $parentid => $comments) { $keyuserids = array(); qa_sort_by($comments, 'created'); foreach ($comments as $comment) { foreach ($keyuserids as $keyuserid => $dummy) { if ($keyuserid != $comment['userid'] && $keyuserid != @$posts[$parentid]['userid']) { qa_db_event_create_not_entity($keyuserid, $questionid, $comment['postid'], QA_UPDATE_FOLLOWS, $comment['userid'], $comment['created']); } } if (isset($comment['userid'])) { $keyuserids[$comment['userid']] = true; } } } } $next = 1 + $lastquestionid; $done += count($questionids); $continue = true; } else { qa_recalc_transition($state, 'dorefillevents_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)) { require_once QA_INCLUDE_DIR . 'app/posts.php'; $postid = $posts[0]; qa_post_delete($postid); $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)) { require_once QA_INCLUDE_DIR . 'app/posts.php'; $postid = $posts[0]; qa_post_delete($postid); $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)) { require_once QA_INCLUDE_DIR . 'app/posts.php'; $postid = $posts[0]; qa_post_delete($postid); $next = 1 + $postid; $done++; $continue = true; } else { qa_recalc_transition($state, 'dodeletehidden_complete'); } break; case 'doblobstodisk': qa_recalc_transition($state, 'doblobstodisk_move'); break; case 'doblobstodisk_move': $blob = qa_db_get_next_blob_in_db($next); if (isset($blob)) { require_once QA_INCLUDE_DIR . 'app/blobs.php'; require_once QA_INCLUDE_DIR . 'db/blobs.php'; if (qa_write_blob_file($blob['blobid'], $blob['content'], $blob['format'])) { qa_db_blob_set_content($blob['blobid'], null); } $next = 1 + $blob['blobid']; $done++; $continue = true; } else { qa_recalc_transition($state, 'doblobstodisk_complete'); } break; case 'doblobstodb': qa_recalc_transition($state, 'doblobstodb_move'); break; case 'doblobstodb_move': $blob = qa_db_get_next_blob_on_disk($next); if (isset($blob)) { require_once QA_INCLUDE_DIR . 'app/blobs.php'; require_once QA_INCLUDE_DIR . 'db/blobs.php'; $content = qa_read_blob_file($blob['blobid'], $blob['format']); qa_db_blob_set_content($blob['blobid'], $content); qa_delete_blob_file($blob['blobid'], $blob['format']); $next = 1 + $blob['blobid']; $done++; $continue = true; } else { qa_recalc_transition($state, 'doblobstodb_complete'); } break; default: $state = ''; break; } if ($continue) { $state = $operation . "\t" . $length . "\t" . $next . "\t" . $done; } return $continue && $done < $length; }
GNU General Public License for more details. More about this license: http://www.question2answer.org/license.php */ require_once QA_INCLUDE_DIR . 'app/cookies.php'; require_once QA_INCLUDE_DIR . 'app/format.php'; require_once QA_INCLUDE_DIR . 'app/users.php'; require_once QA_INCLUDE_DIR . 'db/selects.php'; require_once QA_INCLUDE_DIR . 'pages/question-view.php'; require_once QA_INCLUDE_DIR . 'pages/question-submit.php'; // Load relevant information about this comment $commentid = qa_post_text('commentid'); $questionid = qa_post_text('questionid'); $parentid = qa_post_text('parentid'); $userid = qa_get_logged_in_userid(); list($comment, $question, $parent, $children) = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $commentid), qa_db_full_post_selectspec($userid, $questionid), qa_db_full_post_selectspec($userid, $parentid), qa_db_full_child_posts_selectspec($userid, $parentid)); // Check if there was an operation that succeeded if (@$comment['basetype'] == 'C' && @$question['basetype'] == 'Q' && (@$parent['basetype'] == 'Q' || @$parent['basetype'] == 'A')) { $comment = $comment + qa_page_q_post_rules($comment, $parent, $children, null); // array union if (qa_page_q_single_click_c($comment, $question, $parent, $error)) { $comment = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $commentid)); // If so, page content to be updated via Ajax echo "QA_AJAX_RESPONSE\n1"; // If the comment was not deleted... if (isset($comment)) { $parent = $parent + qa_page_q_post_rules($parent, $questionid == $parentid ? null : $question, null, $children); // in theory we should retrieve the parent's siblings for the above, but they're not going to be relevant $comment = $comment + qa_page_q_post_rules($comment, $parent, $children, null); $usershtml = qa_userids_handles_html(array($comment), true); $c_view = qa_page_q_comment_view($question, $parent, $comment, $usershtml, false);
require_once QA_INCLUDE_DIR . 'qa-app-users.php'; require_once QA_INCLUDE_DIR . 'qa-app-limits.php'; // First check whether the person has permission to do this if (!qa_user_permit_error('permit_post_a', QA_LIMIT_ANSWERS)) { require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-app-captcha.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-app-post-create.php'; require_once QA_INCLUDE_DIR . 'qa-app-cookies.php'; require_once QA_INCLUDE_DIR . 'qa-page-question-view.php'; require_once QA_INCLUDE_DIR . 'qa-page-question-submit.php'; // Load relevant information about this question and check it exists $usecaptcha = qa_user_use_captcha(); $questionid = qa_post_text('a_questionid'); $userid = qa_get_logged_in_userid(); list($question, $childposts) = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $questionid), qa_db_full_child_posts_selectspec($userid, $questionid)); if (@$question['basetype'] == 'Q' && !isset($question['closedbyid'])) { $answers = qa_page_q_load_as($question, $childposts); // Try to create the new answer $answerid = qa_page_q_add_a_submit($question, $answers, $usecaptcha, $in, $errors); $countanswers = $question['acount'] + 1; if (isset($answerid)) { // If successful, page content will be updated via Ajax $answer = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $answerid)); $question = $question + qa_page_q_post_rules($question, null, null, $childposts); // array union $answer = $answer + qa_page_q_post_rules($answer, $question, $answers, null); $usershtml = qa_userids_handles_html(array($answer), true); $a_view = qa_page_q_answer_view($question, $answer, false, $usershtml, false); $themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-answer', null, null); echo "QA_AJAX_RESPONSE\n1\n";
function qa_comment_set_status($oldcomment, $status, $userid, $handle, $cookieid, $question, $parent) { require_once QA_INCLUDE_DIR . 'qa-app-format.php'; if (!isset($parent)) { $parent = $question; } // for backwards compatibility with old answer parameter $washidden = $oldcomment['type'] == 'C_HIDDEN'; $wasqueued = $oldcomment['type'] == 'C_QUEUED'; $wasrequeued = $wasqueued && isset($oldcomment['updated']); qa_post_unindex($oldcomment['postid']); $setupdated = false; $event = null; if ($status == QA_POST_STATUS_QUEUED) { $newtype = 'C_QUEUED'; if (!$wasqueued) { $event = 'c_requeue'; } // same event whether it was hidden or shown before } elseif ($status == QA_POST_STATUS_HIDDEN) { $newtype = 'C_HIDDEN'; if (!$washidden) { $event = $wasqueued ? 'c_reject' : 'c_hide'; if (!$wasqueued) { $setupdated = true; } } } elseif ($status == QA_POST_STATUS_NORMAL) { $newtype = 'C'; if ($wasqueued) { $event = 'c_approve'; } elseif ($washidden) { $event = 'c_reshow'; $setupdated = true; } } else { qa_fatal_error('Unknown status in qa_comment_set_status(): ' . $status); } qa_db_post_set_type($oldcomment['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($oldcomment['postid'], null); } else { qa_db_post_set_created($oldcomment['postid'], null); } } qa_db_ccount_update(); qa_db_points_update_ifuser($oldcomment['userid'], array('cposts')); if ($wasqueued || $status == QA_POST_STATUS_QUEUED) { qa_db_queuedcount_update(); } if ($oldcomment['flagcount']) { qa_db_flaggedcount_update(); } if ($question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A') && $status == QA_POST_STATUS_NORMAL) { // only index if none of the things it depends on are hidden or queued qa_post_index($oldcomment['postid'], 'C', $question['postid'], $oldcomment['parentid'], null, $oldcomment['content'], $oldcomment['format'], qa_viewer_text($oldcomment['content'], $oldcomment['format']), null, $oldcomment['categoryid']); } $eventparams = array('postid' => $oldcomment['postid'], 'parentid' => $oldcomment['parentid'], 'parenttype' => $parent['basetype'], 'parent' => $parent, 'questionid' => $question['postid'], 'question' => $question, 'content' => $oldcomment['content'], 'format' => $oldcomment['format'], 'text' => qa_viewer_text($oldcomment['content'], $oldcomment['format']), 'categoryid' => $oldcomment['categoryid'], 'name' => $oldcomment['name']); if (isset($event)) { qa_report_event($event, $userid, $handle, $cookieid, $eventparams + array('oldcomment' => $oldcomment)); } if ($wasqueued && $status == QA_POST_STATUS_NORMAL && !$wasrequeued) { require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-util-string.php'; $commentsfollows = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $oldcomment['parentid'])); $thread = array(); foreach ($commentsfollows as $comment) { if ($comment['type'] == 'C' && $comment['parentid'] == $parent['postid']) { $thread[] = $comment; } } qa_report_event('c_post', $oldcomment['userid'], $oldcomment['handle'], $oldcomment['cookieid'], $eventparams + array('thread' => $thread, 'notify' => isset($oldcomment['notify']), 'email' => qa_email_validate($oldcomment['notify']) ? $oldcomment['notify'] : null, 'delayed' => $oldcomment['created'])); } }
header('Location: ../'); exit; } require_once QA_INCLUDE_DIR . 'app/cookies.php'; require_once QA_INCLUDE_DIR . 'app/format.php'; require_once QA_INCLUDE_DIR . 'db/selects.php'; require_once QA_INCLUDE_DIR . 'util/sort.php'; require_once QA_INCLUDE_DIR . 'util/string.php'; require_once QA_INCLUDE_DIR . 'app/captcha.php'; require_once QA_INCLUDE_DIR . 'pages/question-view.php'; require_once QA_INCLUDE_DIR . 'app/updates.php'; $questionid = qa_request_part(0); $userid = qa_get_logged_in_userid(); $cookieid = qa_cookie_get(); // Get information about this question list($question, $childposts, $achildposts, $parentquestion, $closepost, $extravalue, $categories, $favorite) = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $questionid), qa_db_full_child_posts_selectspec($userid, $questionid), qa_db_full_a_child_posts_selectspec($userid, $questionid), qa_db_post_parent_q_selectspec($questionid), qa_db_post_close_post_selectspec($questionid), qa_db_post_meta_selectspec($questionid, 'qa_q_extra'), qa_db_category_nav_selectspec($questionid, true, true, true), isset($userid) ? qa_db_is_favorite_selectspec($userid, QA_ENTITY_QUESTION, $questionid) : null); if ($question['basetype'] != 'Q') { // don't allow direct viewing of other types of post $question = null; } if (isset($question)) { $question['extra'] = $extravalue; $answers = qa_page_q_load_as($question, $childposts); $commentsfollows = qa_page_q_load_c_follows($question, $childposts, $achildposts); $question = $question + qa_page_q_post_rules($question, null, null, $childposts); // array union if ($question['selchildid'] && @$answers[$question['selchildid']]['type'] != 'A') { $question['selchildid'] = null; } // if selected answer is hidden or somehow not there, consider it not selected foreach ($answers as $key => $answer) {
function qa_post_get_answer_commentsfollows($answerid) { $commentsfollows = array(); $childposts = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $answerid)); foreach ($childposts as $postid => $post) { if ($post['basetype'] == 'Q' || $post['basetype'] == 'C') { $commentsfollows[$postid] = $post; } } return $commentsfollows; }
function do_select($data, $question) { $questionid = (int) @$data['action_data']['question_id']; $answerid = (int) @$data['action_id']; if ($questionid === null) { return false; } $userid = qa_get_logged_in_userid(); require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; require_once QA_INCLUDE_DIR . 'qa-page-question-view.php'; $qchildposts = qa_db_select_with_pending(qa_db_full_child_posts_selectspec($userid, $questionid)); $question = $question + qa_page_q_post_rules($question, null, null, $qchildposts); // array union if (isset($data['action_data']['select']) && $question['aselectable'] && (!isset($answerid) || !isset($question['selchildid']) && !qa_opt('do_close_on_select'))) { // allowed to select qa_post_set_selchildid($questionid, $answerid, $userid); return true; } else { if (!isset($data['action_data']['select']) && $question['aselectable'] && isset($answerid) && (int) $question['selchildid'] == $answerid) { // allowed to unselect qa_post_set_selchildid($questionid, null, $userid); return true; } } return false; }
function ra_ajax_add_answer() { // Load relevant information about this question $questionid = qa_post_text('a_questionid'); $userid = qa_get_logged_in_userid(); list($question, $childposts) = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $questionid), qa_db_full_child_posts_selectspec($userid, $questionid)); // Check if the question exists, is not closed, and whether the user has permission to do this if (@$question['basetype'] == 'Q' && !isset($question['closedbyid']) && !qa_user_post_permit_error('permit_post_a', $question, QA_LIMIT_ANSWERS)) { require_once QA_INCLUDE_DIR . 'qa-app-captcha.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-app-post-create.php'; require_once QA_INCLUDE_DIR . 'qa-app-cookies.php'; require_once QA_INCLUDE_DIR . 'qa-page-question-view.php'; require_once QA_INCLUDE_DIR . 'qa-page-question-submit.php'; // Try to create the new answer $usecaptcha = qa_user_use_captcha(qa_user_level_for_post($question)); $answers = qa_page_q_load_as($question, $childposts); $answerid = qa_page_q_add_a_submit($question, $answers, false, $in, $errors); if ($answerid) { return true; } } die; }
list($question, $parent, $children) = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $questionid), qa_db_full_post_selectspec($userid, $parentid), qa_db_full_child_posts_selectspec($userid, $parentid)); // Check if the question and parent exist, and whether the user has permission to do this if (@$question['basetype'] == 'Q' && (@$parent['basetype'] == 'Q' || @$parent['basetype'] == 'A') && !qa_user_post_permit_error('permit_post_c', $parent, QA_LIMIT_COMMENTS)) { require_once QA_INCLUDE_DIR . 'app/captcha.php'; require_once QA_INCLUDE_DIR . 'app/format.php'; require_once QA_INCLUDE_DIR . 'app/post-create.php'; require_once QA_INCLUDE_DIR . 'app/cookies.php'; require_once QA_INCLUDE_DIR . 'pages/question-view.php'; require_once QA_INCLUDE_DIR . 'pages/question-submit.php'; require_once QA_INCLUDE_DIR . 'util/sort.php'; // Try to create the new comment $usecaptcha = qa_user_use_captcha(qa_user_level_for_post($question)); $commentid = qa_page_q_add_c_submit($question, $parent, $children, $usecaptcha, $in, $errors); // If successful, page content will be updated via Ajax if (isset($commentid)) { $children = qa_db_select_with_pending(qa_db_full_child_posts_selectspec($userid, $parentid)); $parent = $parent + qa_page_q_post_rules($parent, $questionid == $parentid ? null : $question, null, $children); // in theory we should retrieve the parent's siblings for the above, but they're not going to be relevant foreach ($children as $key => $child) { $children[$key] = $child + qa_page_q_post_rules($child, $parent, $children, null); } $usershtml = qa_userids_handles_html($children, true); qa_sort_by($children, 'created'); $c_list = qa_page_q_comment_follow_list($question, $parent, $children, true, $usershtml, false, null); $themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-comments', null, null); echo "QA_AJAX_RESPONSE\n1\n"; // Send back the ID of the new comment echo qa_anchor('C', $commentid) . "\n"; // Send back the HTML $themeclass->c_list_items($c_list['cs']); return;
function qa_page_q_load_q() { global $qa_login_userid, $questionid, $question, $parentquestion, $answers, $commentsfollows, $relatedcount, $relatedquestions, $question, $categories; list($question, $childposts, $achildposts, $parentquestion, $relatedquestions, $categories) = qa_db_select_with_pending(qa_db_full_post_selectspec($qa_login_userid, $questionid), qa_db_full_child_posts_selectspec($qa_login_userid, $questionid), qa_db_full_a_child_posts_selectspec($qa_login_userid, $questionid), qa_db_post_parent_q_selectspec($questionid), qa_db_related_qs_selectspec($qa_login_userid, $questionid), qa_db_category_nav_selectspec($questionid, true, true)); if ($question['basetype'] != 'Q') { // don't allow direct viewing of other types of post $question = null; } $answers = array(); $commentsfollows = array(); foreach ($childposts as $postid => $post) { switch ($post['type']) { case 'Q': // never show follow-on Qs which have been hidden, even to admins // never show follow-on Qs which have been hidden, even to admins case 'C': case 'C_HIDDEN': $commentsfollows[$postid] = $post; break; case 'A': case 'A_HIDDEN': $answers[$postid] = $post; break; } } foreach ($achildposts as $postid => $post) { switch ($post['type']) { case 'Q': case 'Q_HIDDEN': case 'C': case 'C_HIDDEN': $commentsfollows[$postid] = $post; break; } } if (isset($question)) { $relatedcount = qa_opt('do_related_qs') ? 1 + qa_opt('page_size_related_qs') : 0; $relatedquestions = array_slice($relatedquestions, 0, $relatedcount); // includes question itself at this point qa_page_q_post_rules($question); if ($question['selchildid'] && @$answers[$question['selchildid']]['type'] != 'A') { $question['selchildid'] = null; } // if selected answer is hidden or somehow not there, consider it not selected foreach ($answers as $key => $answer) { $question['deleteable'] = false; qa_page_q_post_rules($answers[$key]); if ($answers[$key]['isbyuser'] && !qa_opt('allow_multi_answers')) { $question['answerbutton'] = false; } $answers[$key]['isselected'] = $answer['postid'] == $question['selchildid']; } foreach ($commentsfollows as $key => $commentfollow) { if ($commentfollow['parentid'] == $questionid) { $question['deleteable'] = false; } if (isset($answers[$commentfollow['parentid']])) { $answers[$commentfollow['parentid']]['deleteable'] = false; } qa_page_q_post_rules($commentsfollows[$key]); } } }
function qa_recalc_perform_step(&$state) { $continue = false; @(list($operation, $length, $next, $done) = explode(',', $state)); switch ($operation) { case 'doreindexcontent': qa_recalc_transition($state, 'doreindexcontent_pagereindex'); break; case 'doreindexcontent_pagereindex': $pages = qa_db_pages_get_for_reindexing($next, 10); if (count($pages)) { require_once QA_INCLUDE_DIR . 'qa-app-format.php'; $lastpageid = max(array_keys($pages)); foreach ($pages as $pageid => $page) { if (!($page['flags'] & QA_PAGE_FLAGS_EXTERNAL)) { $searchmodules = qa_load_modules_with('search', 'unindex_page'); foreach ($searchmodules as $searchmodule) { $searchmodule->unindex_page($pageid); } $searchmodules = qa_load_modules_with('search', 'index_page'); if (count($searchmodules)) { $indextext = qa_viewer_text($page['content'], 'html'); foreach ($searchmodules as $searchmodule) { $searchmodule->index_page($pageid, $page['tags'], $page['heading'], $page['content'], 'html', $indextext); } } } } $next = 1 + $lastpageid; $done += count($pages); $continue = true; } else { qa_recalc_transition($state, 'doreindexcontent_postcount'); } break; case 'doreindexcontent_postcount': qa_db_qcount_update(); qa_db_acount_update(); qa_db_ccount_update(); qa_recalc_transition($state, 'doreindexcontent_postreindex'); break; case 'doreindexcontent_postreindex': $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); qa_suspend_update_counts(); foreach ($posts as $postid => $post) { qa_post_unindex($postid); qa_post_index($postid, $post['type'], $post['questionid'], $post['parentid'], $post['title'], $post['content'], $post['format'], qa_viewer_text($post['content'], $post['format']), $post['tags'], $post['categoryid']); } $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_db_unselqcount_update(); qa_recalc_transition($state, 'dorecountposts_votecount'); break; case 'dorecountposts_votecount': $postids = qa_db_posts_get_for_recounting($next, 1000); if (count($postids)) { $lastpostid = max($postids); qa_db_posts_votes_recount($next, $lastpostid); $next = 1 + $lastpostid; $done += count($postids); $continue = true; } else { qa_recalc_transition($state, 'dorecountposts_acount'); } break; case 'dorecountposts_acount': $postids = qa_db_posts_get_for_recounting($next, 1000); if (count($postids)) { $lastpostid = max($postids); qa_db_posts_answers_recount($next, $lastpostid); $next = 1 + $lastpostid; $done += count($postids); $continue = true; } else { qa_db_unupaqcount_update(); 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 'dorefillevents': qa_recalc_transition($state, 'dorefillevents_qcount'); break; case 'dorefillevents_qcount': qa_db_qcount_update(); qa_recalc_transition($state, 'dorefillevents_refill'); break; case 'dorefillevents_refill': $questionids = qa_db_qs_get_for_event_refilling($next, 1); if (count($questionids)) { require_once QA_INCLUDE_DIR . 'qa-app-events.php'; require_once QA_INCLUDE_DIR . 'qa-app-updates.php'; require_once QA_INCLUDE_DIR . 'qa-util-sort.php'; $lastquestionid = max($questionids); foreach ($questionids as $questionid) { // Retrieve all posts relating to this question list($question, $childposts, $achildposts) = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $questionid), qa_db_full_child_posts_selectspec(null, $questionid), qa_db_full_a_child_posts_selectspec(null, $questionid)); // Merge all posts while preserving keys as postids $posts = array($questionid => $question); foreach ($childposts as $postid => $post) { $posts[$postid] = $post; } foreach ($achildposts as $postid => $post) { $posts[$postid] = $post; } // Creation and editing of each post foreach ($posts as $postid => $post) { $followonq = $post['basetype'] == 'Q' && $postid != $questionid; qa_create_event_for_q_user($questionid, $postid, $followonq ? QA_UPDATE_FOLLOWS : null, $post['userid'], @$posts[$post['parentid']]['userid'], $post['created']); if (isset($post['updated']) && !$followonq) { qa_create_event_for_q_user($questionid, $postid, $post['updatetype'], $post['lastuserid'], $post['userid'], $post['updated']); } } // Tags and categories of question qa_create_event_for_tags($question['tags'], $questionid, null, $question['userid'], $question['created']); qa_create_event_for_category($question['categoryid'], $questionid, null, $question['userid'], $question['created']); // Collect comment threads $parentidcomments = array(); foreach ($posts as $postid => $post) { if ($post['basetype'] == 'C') { $parentidcomments[$post['parentid']][$postid] = $post; } } // For each comment thread, notify all previous comment authors of each comment in the thread (could get slow) foreach ($parentidcomments as $parentid => $comments) { $keyuserids = array(); qa_sort_by($comments, 'created'); foreach ($comments as $comment) { foreach ($keyuserids as $keyuserid => $dummy) { if ($keyuserid != $comment['userid'] && $keyuserid != @$posts[$parentid]['userid']) { qa_db_event_create_not_entity($keyuserid, $questionid, $comment['postid'], null, $comment['userid'], $comment['created']); } } if (isset($comment['userid'])) { $keyuserids[$comment['userid']] = true; } } } } $next = 1 + $lastquestionid; $done += count($questionids); $continue = true; } else { qa_recalc_transition($state, 'dorefillevents_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)) { require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; $postid = $posts[0]; qa_post_delete($postid); $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)) { require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; $postid = $posts[0]; qa_post_delete($postid); $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)) { require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; $postid = $posts[0]; qa_post_delete($postid); $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; }
<?php require_once 'qa-include/qa-base.php'; require_once QA_INCLUDE_DIR . 'db/selects.php'; require_once QA_INCLUDE_DIR . 'app/q-list.php'; //require_once QA_INCLUDE_DIR.'app/users.php'; //$user = qa_get_logged_in_user(); //$userid=$user["userid"];//qa_get_logged_in_userid(); list($questions, $categories, $categoryid) = qa_db_select_with_pending(qa_db_qs_selectspec(null, 'hotness', 0, null, null, false, true), qa_db_category_nav_selectspec(null, false, false, true), null); foreach ($questions as $key => $question) { $questionid = $question["postid"]; $answers = array(); $childposts = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $questionid)); foreach ($childposts as $postid => $post) { if ($post['basetype'] == 'A') { $answers[$postid] = $post; } } $questions[$key]["answers"] = $answers; } $salida = []; foreach ($questions as $pregunta) { $salida[$pregunta["postid"]] = ['userid' => $pregunta["userid"], 'contenido' => substr($pregunta["title"] . ". " . strip_tags($pregunta["content"]), 0, 100)]; foreach ($pregunta["answers"] as $resp) { //$u = Medico::where('user_id','=',$resp["userid"])->first(); //if($u){ $salida[$pregunta["postid"]]["respuestas"][] = ["userid" => $resp["userid"], "contenido" => substr(strip_tags($resp["content"]), 0, 100)]; //} } } header('Content-Type: application/json');
function qa_comment_set_hidden($oldcomment, $hidden, $userid, $handle, $cookieid, $question, $parent) { require_once QA_INCLUDE_DIR . 'qa-app-format.php'; if (!isset($parent)) { $parent = $question; } // for backwards compatibility with old answer parameter $wasqueued = $oldcomment['type'] == 'C_QUEUED'; qa_post_unindex($oldcomment['postid']); $setupdated = $hidden || !$wasqueued; // don't record approval of a post as an update action... qa_db_post_set_type($oldcomment['postid'], $hidden ? 'C_HIDDEN' : 'C', $setupdated ? $userid : null, $setupdated ? qa_remote_ip_address() : null, QA_UPDATE_VISIBLE); if (!$setupdated) { // ... for approval of a post, set created time to now instead qa_db_post_set_created($oldcomment['postid'], null); } qa_db_points_update_ifuser($oldcomment['userid'], array('cposts')); qa_db_ccount_update(); if ($question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A') && !$hidden) { // only index if none of the things it depends on are hidden or queued qa_post_index($oldcomment['postid'], 'C', $question['postid'], $oldcomment['parentid'], null, $oldcomment['content'], $oldcomment['format'], qa_viewer_text($oldcomment['content'], $oldcomment['format']), null, $oldcomment['categoryid']); } qa_report_event($wasqueued ? $hidden ? 'c_reject' : 'c_approve' : ($hidden ? 'c_hide' : 'c_reshow'), $userid, $handle, $cookieid, array('postid' => $oldcomment['postid'], 'parentid' => $oldcomment['parentid'], 'oldcomment' => $oldcomment, 'parenttype' => $parent['basetype'], 'questionid' => $question['postid'])); if ($wasqueued && !$hidden) { require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-util-string.php'; $commentsfollows = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $oldcomment['parentid'])); $thread = array(); foreach ($commentsfollows as $comment) { if ($comment['type'] == 'C' && $comment['parentid'] == $parent['postid']) { $thread[] = $comment; } } qa_report_event('c_post', $oldcomment['userid'], $oldcomment['handle'], $oldcomment['cookieid'], array('postid' => $oldcomment['postid'], 'parentid' => $oldcomment['parentid'], 'parenttype' => $parent['basetype'], 'parent' => $parent, 'questionid' => $question['postid'], 'question' => $question, 'thread' => $thread, 'content' => $oldcomment['content'], 'format' => $oldcomment['format'], 'text' => qa_viewer_text($oldcomment['content'], $oldcomment['format']), 'categoryid' => $oldcomment['categoryid'], 'notify' => isset($oldcomment['notify']), 'email' => qa_email_validate($oldcomment['notify']) ? $oldcomment['notify'] : null, 'delayed' => $oldcomment['created'])); } }