public static function report($question_id) { global $current_user; // required logged in if (!$current_user->ID) { return false; } // get reports list $reports = QA_Questions::get_field($question_id, 'et_reports'); // if (!is_array($reports)) { $reports = array(); } if (!in_array($current_user->ID, $reports)) { $reports[] = $current_user->ID; } QA_Questions::update_field($question_id, 'et_reports', $reports); return true; }
public function handle_posts() { global $current_user; /** * * - PREVENT USERS ACCESS TO PENDING PAGE EXCEPT ADMIN * - * - @package QAEngine * - @version 1.0 * **/ if (is_page_template('page-pending.php') && !current_user_can('manage_options')) { wp_redirect(home_url()); exit; } /** * * - PREVENT USERS ACCESS TO CONTENT PAGE IF OPTION IS ACTIVE * - * - @package QAEngine * - @version 1.0 * **/ if (ae_get_option("login_view_content")) { //var_dump(!is_page_template( 'page-intro.php' ) && !is_user_logged_in()); if (!is_page() && !is_singular('post') && !is_user_logged_in()) { wp_redirect(et_get_page_link('intro')); exit; } } /** * * - REDIRECT USERS TO QUESTIONS LIST PAGE IF ALREADY LOGGED IN * - * - @package QAEngine * - @version 1.0 * **/ if (is_page_template('page-intro.php')) { if (is_user_logged_in()) { wp_redirect(get_post_type_archive_link('question')); exit; } } /** * * - REDIRECT TO SEARCH PAGE * - * - @package QAEngine * - @version 1.0 * **/ if (isset($_REQUEST['keyword'])) { $keyword = str_replace('.php', ' php', $_REQUEST['keyword']); $link = qa_search_link(esc_attr($keyword)); wp_redirect($link); exit; } /** * * - COUNT QUESTION VIEW * - * - @package QAEngine * - @version 1.0 * **/ if (is_singular('question')) { global $post, $user_ID; if (ae_get_option("login_view_content") && get_user_meta($user_ID, 'register_status', true) == "unconfirm") { wp_redirect(add_query_arg(array('confirm' => 0), home_url())); exit; } if ($post->post_status == 'publish') { $views = (int) QA_Questions::get_field($post->ID, 'et_view_count'); $key = "et_post_" . $post->ID . "_viewed"; if (!isset($_COOKIE[$key]) || $_COOKIE[$key] != 'on') { QA_Questions::update_field($post->ID, 'et_view_count', $views + 1); setcookie($key, 'on', time() + 3600, "/"); } } } /** * * - INSERT A QUESTION * - @param string $post_title * - @param string $post_content * - @param string $question_category * - @package QAEngine * - @version 1.0 * **/ if (isset($_POST['qa_nonce']) && wp_verify_nonce($_POST['qa_nonce'], 'insert_question')) { global $current_user; $cats = array('qa_tag' => $_POST['tags'], 'question_category' => $_POST['question_category']); $result = QA_Questions::insert_question($_POST['post_title'], $_POST['post_content'], $cats); do_action('qa_insert_question', $result); if (!is_wp_error($result)) { wp_redirect(get_permalink($result)); exit; } } /** * * - INSERT A COMMENT TO QUESTION * - @param int $post_id * - @param array $author_data * - @param array $comment_data * - @package QAEngine * - @version 1.0 * **/ if (isset($_POST['qa_nonce']) && wp_verify_nonce($_POST['qa_nonce'], 'insert_comment')) { global $current_user; $result = QA_Comments::insert(array('comment_post_ID' => $_POST['comment_post_ID'], 'comment_content' => $_POST['post_content'])); do_action('qa_insert_comment', $result); if (!is_wp_error($result)) { wp_redirect(et_get_last_page($_POST['comment_post_ID'])); exit; } } /** * Confirm User */ if (isset($_GET['act']) && $_GET['act'] == "confirm" && $_GET['key']) { $user = get_users(array('meta_key' => 'key_confirm', 'meta_value' => $_GET['key'])); global $qa_confirm; $qa_confirm = update_user_meta($user[0]->ID, 'register_status', ''); $user_email = $user[0]->user_email; $message = ae_get_option('confirmed_mail_template'); $message = et_filter_authentication_placeholder($message, $user[0]->ID); $subject = __("Congratulations! Your account has been confirmed successfully.", ET_DOMAIN); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: " . get_option('blogname') . " < " . ae_get_option('send_mail_from', '*****@*****.**') . "> \r\n"; if ($qa_confirm && $user_email) { wp_mail($user_email, $subject, $message, $headers); } } }