function AddCategoryToPost($params, $category) { require_once QA_INCLUDE_DIR . 'qa-db-post-update.php'; $postid = $params['postid']; $result = qa_db_read_one_assoc(qa_db_query_sub('SELECT categoryid,parentid,tags,title,content,qcount,position,backpath FROM ^categories WHERE title=$', $category), true); if (empty($result)) { //create category $tags = str_replace(' ', '-', $category); $catID = $this->CreatCategory($category, $tags); qa_db_post_set_category($postid, $catID, null, null); qa_db_posts_calc_category_path($postid); $path = qa_db_post_get_category_path($postid); qa_db_category_path_qcount_update($path); } else { // update category $oldpath = qa_db_post_get_category_path($postid); $tags = $result['tags']; $catID = $result['categoryid']; qa_db_post_set_category($postid, $catID, null, null); qa_db_posts_calc_category_path($postid); $path = qa_db_post_get_category_path($postid); qa_db_category_path_qcount_update($oldpath); qa_db_category_path_qcount_update($path); } }
function qa_update_counts_for_q($postid) { if (isset($postid)) { // post might no longer exist qa_db_category_path_qcount_update(qa_db_post_get_category_path($postid)); } qa_db_qcount_update(); qa_db_unaqcount_update(); qa_db_unselqcount_update(); qa_db_unupaqcount_update(); }
function qa_question_create($followanswer, $userid, $handle, $cookieid, $title, $content, $format, $text, $tagstring, $notify, $email, $categoryid = null, $extravalue = null, $queued = false) { require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; $postid = qa_db_post_create($queued ? 'Q_QUEUED' : 'Q', @$followanswer['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), $title, $content, $format, $tagstring, qa_combine_notify_email($userid, $notify, $email), $categoryid); if (isset($extravalue)) { require_once QA_INCLUDE_DIR . 'qa-db-metas.php'; qa_db_postmeta_set($postid, 'qa_q_extra', $extravalue); } qa_db_posts_calc_category_path($postid); qa_db_hotness_update($postid); if (!$queued) { qa_db_category_path_qcount_update(qa_db_post_get_category_path($postid)); qa_post_index($postid, 'Q', $postid, @$followanswer['postid'], $title, $content, $format, $text, $tagstring, $categoryid); qa_db_points_update_ifuser($userid, 'qposts'); qa_db_qcount_update(); qa_db_unaqcount_update(); qa_db_unselqcount_update(); qa_db_unupaqcount_update(); } qa_report_event($queued ? 'q_queue' : 'q_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => @$followanswer['postid'], 'parent' => $followanswer, 'title' => $title, 'content' => $content, 'format' => $format, 'text' => $text, 'tags' => $tagstring, 'categoryid' => $categoryid, 'extra' => $extravalue, 'notify' => $notify, 'email' => $email)); return $postid; }
function qa_question_delete($oldquestion, $userid, $handle, $cookieid, $oldclosepost = null) { require_once QA_INCLUDE_DIR . 'qa-db-votes.php'; if ($oldquestion['type'] != 'Q_HIDDEN') { qa_fatal_error('Tried to delete a non-hidden question'); } if (isset($oldclosepost) && $oldclosepost['parentid'] == $oldquestion['postid']) { qa_db_post_set_closed($oldquestion['postid'], null); // for foreign key constraint qa_post_unindex($oldclosepost['postid']); qa_db_post_delete($oldclosepost['postid']); } $useridvotes = qa_db_uservote_post_get($oldquestion['postid']); $oldpath = qa_db_post_get_category_path($oldquestion['postid']); qa_post_unindex($oldquestion['postid']); qa_db_post_delete($oldquestion['postid']); // also deletes any related voteds due to foreign key cascading qa_update_counts_for_q(null); qa_db_category_path_qcount_update($oldpath); // don't do inside qa_update_counts_for_q() since post no longer exists qa_db_points_update_ifuser($oldquestion['userid'], array('qposts', 'aselects', 'qvoteds', 'upvoteds', 'downvoteds')); foreach ($useridvotes as $voteruserid => $vote) { qa_db_points_update_ifuser($voteruserid, $vote > 0 ? 'qupvotes' : 'qdownvotes'); } // could do this in one query like in qa_db_users_recalc_points() but this will do for now - unlikely to be many votes qa_report_event('q_delete', $userid, $handle, $cookieid, array('postid' => $oldquestion['postid'], 'oldquestion' => $oldquestion)); }
function qa_question_delete($oldquestion, $userid, $handle, $cookieid) { require_once QA_INCLUDE_DIR . 'qa-db-votes.php'; if (!$oldquestion['hidden']) { qa_fatal_error('Tried to delete a non-hidden question'); } $useridvotes = qa_db_uservote_post_get($oldquestion['postid']); $oldpath = qa_db_post_get_category_path($oldquestion['postid']); qa_post_unindex($oldquestion['postid']); qa_db_post_delete($oldquestion['postid']); // also deletes any related voteds due to cascading qa_db_category_path_qcount_update($oldpath); qa_db_points_update_ifuser($oldquestion['userid'], array('qposts', 'aselects', 'qvoteds', 'upvoteds', 'downvoteds')); foreach ($useridvotes as $voteruserid => $vote) { qa_db_points_update_ifuser($voteruserid, $vote > 0 ? 'qupvotes' : 'qdownvotes'); } // could do this in one query like in qa_db_users_recalc_points() but this will do for now - unlikely to be many votes qa_db_qcount_update(); qa_db_unaqcount_update(); qa_report_event('q_delete', $userid, $handle, $cookieid, array('postid' => $oldquestion['postid'])); }
function qa_question_create($followanswer, $userid, $handle, $cookieid, $title, $content, $format, $text, $tagstring, $notify, $email, $categoryid = null) { require_once QA_INCLUDE_DIR . 'qa-app-options.php'; require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'mp-db-users.php'; require_once QA_INCLUDE_DIR . 'mp-app-users.php'; $postid = qa_db_post_create('Q', @$followanswer['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), $title, $content, $format, $tagstring, qa_combine_notify_email($userid, $notify, $email), $categoryid); qa_db_posts_calc_category_path($postid); qa_db_category_path_qcount_update(qa_db_post_get_category_path($postid)); qa_post_index($postid, 'Q', $postid, $title, $text, $tagstring); qa_db_hotness_update($postid); qa_db_points_update_ifuser($userid, 'qposts'); qa_db_qcount_update(); qa_db_unaqcount_update(); if (isset($followanswer['notify']) && !qa_post_is_by_user($followanswer, $userid, $cookieid)) { require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-util-string.php'; $blockwordspreg = qa_get_block_words_preg(); $sendtitle = qa_block_words_replace($title, $blockwordspreg); $sendtext = qa_viewer_text($followanswer['content'], $followanswer['format'], array('blockwordspreg' => $blockwordspreg)); qa_send_notification($followanswer['userid'], $followanswer['notify'], @$followanswer['handle'], qa_lang('emails/a_followed_subject'), qa_lang('emails/a_followed_body'), array('^q_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => $sendtitle, '^a_content' => $sendtext, '^url' => qa_path(qa_q_request($postid, $sendtitle), null, qa_opt('site_url')))); } if (qa_opt('notify_admin_q_post')) { qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/q_posted_subject'), qa_lang('emails/q_posted_body'), array('^q_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => $title, '^q_content' => $text, '^url' => qa_path(qa_q_request($postid, $title), null, qa_opt('site_url')))); } // notify all members of the category about the new post // 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_QUESTIONS)) { // for each member, send notification qa_send_notification($recipient['userid'], null, null, qa_lang('emails/q_posted_with_category_subject'), qa_lang('emails/q_posted_body'), array('^q_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => $title, '^q_content' => $text, '^url' => qa_path(qa_q_request($postid, $title), null, qa_opt('site_url')), '^category_title' => $currentcategory['title'])); } } qa_report_event('q_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => @$followanswer['postid'], 'title' => $title, 'content' => $content, 'format' => $format, 'text' => $text, 'tags' => $tagstring, 'categoryid' => $categoryid, 'notify' => $notify, 'email' => $email)); return $postid; }