*/ require_once QA_INCLUDE_DIR . 'qa-app-users.php'; require_once QA_INCLUDE_DIR . 'qa-app-cookies.php'; require_once QA_INCLUDE_DIR . 'qa-app-votes.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-app-options.php'; require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; $postid = qa_post_text('postid'); $vote = qa_post_text('vote'); $code = qa_post_text('code'); $userid = qa_get_logged_in_userid(); $cookieid = qa_cookie_get(); if (!qa_check_form_security_code('vote', $code)) { $voteerror = qa_lang_html('misc/form_security_reload'); } else { $post = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid)); $voteerror = qa_vote_error_html($post, $vote, $userid, qa_request()); } if ($voteerror === false) { qa_vote_set($post, $userid, qa_get_logged_in_handle(), $cookieid, $vote); $post = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid)); $fields = qa_post_html_fields($post, $userid, $cookieid, array(), null, array('voteview' => qa_get_vote_view($post, true))); $themeclass = qa_load_theme_class(qa_get_site_theme(), 'voting', null, null); echo "QA_AJAX_RESPONSE\n1\n"; $themeclass->voting_inner_html($fields); } else { echo "QA_AJAX_RESPONSE\n0\n" . $voteerror; } /* Omit PHP closing tag to help avoid accidental output */
function do_vote($data, $post) { require_once QA_INCLUDE_DIR . 'qa-app-votes.php'; $postid = (int) @$data['action_id']; $info = @$data['action_data']; $vote = (int) @$info['vote']; $type = @$info['type']; $userid = qa_get_logged_in_userid(); $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); // create a new cookie if necessary if ($postid === null || $vote === null || $type === null) { return false; } $voteerror = qa_vote_error_html($post, $vote, $userid, ""); if ($voteerror === false) { // allowed qa_vote_set($post, $userid, qa_get_logged_in_handle(), $cookieid, $vote); return true; } return false; }
function qa_check_page_clicks() { if (qa_to_override(__FUNCTION__)) { $args = func_get_args(); return qa_call_override(__FUNCTION__, $args); } global $qa_page_error_html; if (qa_is_http_post()) { foreach ($_POST as $field => $value) { if (strpos($field, 'vote_') === 0) { // voting... @(list($dummy, $postid, $vote, $anchor) = explode('_', $field)); if (isset($postid) && isset($vote)) { if (!qa_check_form_security_code('vote', qa_post_text('code'))) { $qa_page_error_html = qa_lang_html('misc/form_security_again'); } else { require_once QA_INCLUDE_DIR . 'app/votes.php'; require_once QA_INCLUDE_DIR . 'db/selects.php'; $userid = qa_get_logged_in_userid(); $post = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid)); $qa_page_error_html = qa_vote_error_html($post, $vote, $userid, qa_request()); if (!$qa_page_error_html) { qa_vote_set($post, $userid, qa_get_logged_in_handle(), qa_cookie_get(), $vote); qa_redirect(qa_request(), $_GET, null, null, $anchor); } break; } } } elseif (strpos($field, 'favorite_') === 0) { // favorites... @(list($dummy, $entitytype, $entityid, $favorite) = explode('_', $field)); if (isset($entitytype) && isset($entityid) && isset($favorite)) { if (!qa_check_form_security_code('favorite-' . $entitytype . '-' . $entityid, qa_post_text('code'))) { $qa_page_error_html = qa_lang_html('misc/form_security_again'); } else { require_once QA_INCLUDE_DIR . 'app/favorites.php'; qa_user_favorite_set(qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), $entitytype, $entityid, $favorite); qa_redirect(qa_request(), $_GET); } } } elseif (strpos($field, 'notice_') === 0) { // notices... @(list($dummy, $noticeid) = explode('_', $field)); if (isset($noticeid)) { if (!qa_check_form_security_code('notice-' . $noticeid, qa_post_text('code'))) { $qa_page_error_html = qa_lang_html('misc/form_security_again'); } else { if ($noticeid == 'visitor') { setcookie('qa_noticed', 1, time() + 86400 * 3650, '/', QA_COOKIE_DOMAIN); } elseif ($noticeid == 'welcome') { require_once QA_INCLUDE_DIR . 'db/users.php'; qa_db_user_set_flag(qa_get_logged_in_userid(), QA_USER_FLAGS_WELCOME_NOTICE, false); } else { require_once QA_INCLUDE_DIR . 'db/notices.php'; qa_db_usernotice_delete(qa_get_logged_in_userid(), $noticeid); } qa_redirect(qa_request(), $_GET); } } } } } }
require_once QA_INCLUDE_DIR . 'qa-app-users.php'; require_once QA_INCLUDE_DIR . 'qa-app-cookies.php'; require_once QA_INCLUDE_DIR . 'qa-app-votes.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-app-options.php'; require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; function qa_ajax_vote_db_fail_handler() { echo "QA_AJAX_RESPONSE\n0\nA database error occurred."; exit; } qa_base_db_connect('qa_ajax_vote_db_fail_handler'); $postid = qa_post_text('postid'); $qa_login_userid = qa_get_logged_in_userid(); $qa_cookieid = qa_cookie_get(); $post = qa_db_select_with_pending(qa_db_full_post_selectspec($qa_login_userid, $postid)); $voteerror = qa_vote_error_html($post, $qa_login_userid, $qa_request); if ($voteerror === false) { qa_vote_set($post, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, qa_post_text('vote')); $post = qa_db_select_with_pending(qa_db_full_post_selectspec($qa_login_userid, $postid)); $fields = qa_post_html_fields($post, $qa_login_userid, $qa_cookieid, array(), null, array('voteview' => qa_opt('votes_separated') ? 'updown' : 'net')); $themeclass = qa_load_theme_class(qa_opt('site_theme'), 'voting', null, null); echo "QA_AJAX_RESPONSE\n1\n"; $themeclass->voting_inner_html($fields); } else { echo "QA_AJAX_RESPONSE\n0\n" . $voteerror; } qa_base_db_disconnect(); /* Omit PHP closing tag to help avoid accidental output */