public function process_ask_form() { if (!is_user_logged_in()) { return false; } if (isset($_POST['is_question']) && isset($_POST['submitted']) && isset($_POST['ask_form']) && wp_verify_nonce($_POST['ask_form'], 'post_nonce')) { $fields = $this->get_question_fields_to_process(); if (!ap_user_can_ask()) { return; } $validate = $this->validate_question_form(); if ($validate['has_error']) { if ($_POST['action'] == 'ap_submit_question') { $result = array('action' => 'validation_falied', 'message' => __('Question not submitted, please check the form fields.', 'ap'), 'error' => $validate); return json_encode($result); } return; } do_action('process_ask_form'); $user_id = get_current_user_id(); $status = 'publish'; if (ap_opt('moderate_new_question') == 'pending' || ap_opt('moderate_new_question') == 'point' && ap_get_points($user_id) < ap_opt('mod_question_point')) { $status = 'moderate'; } $question_array = array('post_title' => $fields['post_title'], 'post_author' => $user_id, 'post_content' => wp_kses($fields['post_content'], ap_form_allowed_tags()), 'post_type' => 'question', 'post_status' => $status); $post_id = wp_insert_post($question_array); if ($post_id) { // Update Custom Meta if (isset($fields['category'])) { wp_set_post_terms($post_id, $fields['category'], 'question_category'); } if (isset($fields['tags'])) { wp_set_post_terms($post_id, $fields['tags'], 'question_tags'); } update_post_meta($post_id, ANSPRESS_VOTE_META, '0'); update_post_meta($post_id, ANSPRESS_FAV_META, '0'); update_post_meta($post_id, ANSPRESS_CLOSE_META, '0'); update_post_meta($post_id, ANSPRESS_FLAG_META, '0'); update_post_meta($post_id, ANSPRESS_VIEW_META, '0'); update_post_meta($post_id, ANSPRESS_UPDATED_META, current_time('mysql')); update_post_meta($post_id, ANSPRESS_SELECTED_META, false); //ap_add_history($user_id, $post_id, 'asked'); ap_add_parti($post_id, $user_id, 'question'); //update answer count update_post_meta($post_id, ANSPRESS_ANS_META, '0'); do_action('ap_after_inserting_question', $post_id); ap_do_event('new_question', $post_id, $user_id); if ($_POST['action'] == 'ap_submit_question') { $result = apply_filters('ap_ajax_question_submit_result', array('action' => 'new_question', 'message' => __('Question submitted successfully', 'ap'), 'redirect_to' => get_permalink($post_id))); return json_encode($result); } else { // Redirect wp_redirect(get_permalink($post_id)); exit; } } } }
function ap_user_can_create_tag() { if (is_super_admin() || current_user_can('ap_new_tag') && ap_get_points() >= ap_opt('min_point_new_tag')) { return true; } return false; }
public function edit_answer($question) { global $ap_errors, $validate; // return if user do not have permission to edit this answer if (!ap_user_can_edit_ans($this->fields['edit_post_id'])) { $this->result = ap_ajax_responce('no_permission'); return; } $answer = get_post($this->fields['edit_post_id']); $status = 'publish'; if (ap_opt('edit_answer_status') == 'moderate' || ap_opt('edit_answer_status') == 'point' && ap_get_points(get_current_user_id()) < ap_opt('new_answer_status')) { $status = 'moderate'; } if (isset($this->fields['is_private']) && $this->fields['is_private']) { $status = 'private_post'; } $answer_array = array('ID' => $this->fields['edit_post_id'], 'post_author' => $answer->post_author, 'post_content' => apply_filters('ap_form_contents_filter', $this->fields['description']), 'post_status' => $status); $answer_array = apply_filters('ap_pre_update_answer', $answer_array); $post_id = wp_update_post($answer_array); if ($post_id) { if ($this->is_ajax) { $this->result = array('action' => 'answer_edited', 'message' => 'answer_updated', 'do' => array('redirect' => get_permalink($answer->post_parent))); } $this->redirect = get_permalink($post_id); } $this->process_image_uploads($post_id, $answer->post_author); }
"><b data-view="ap-followers"><?php echo ap_get_current_user_meta('followers'); ?> </b><span><?php _e('Followers', 'ap'); ?> </span></a></li> <li><a href="<?php echo ap_user_link($f->ID, 'following'); ?> "><b data-view="ap-following"><?php echo ap_get_current_user_meta('following'); ?> </b><span><?php _e('Following', 'ap'); ?> </span></a></li> <li><a href="<?php echo ap_user_link($f->ID, 'points'); ?> "><b data-view="ap-points"><?php echo ap_get_points($f->ID, true); ?> </b><span><?php _e('Points', 'ap'); ?> </span></a></li> </ul> </div> </div>
</span></a></li> <li><a href="<?php echo ap_user_link($userid, 'following'); ?> "><b data-view="ap-following"><?php echo ap_get_current_user_meta('following'); ?> </b><span><?php _e('Following', 'ap'); ?> </span></a></li> <li><a href="<?php echo ap_user_link($userid, 'points'); ?> "><b data-view="ap-points"><?php echo ap_get_points($userid, true); ?> </b><span><?php _e('Points', 'ap'); ?> </span></a></li> </ul> </div> </div> </div> <?php } ?> <div class="ap-profile-lr"> <div class="ap-profile-nav clearfix"> <?php
function ap_set_points($type, $uid, $points, $data) { $points = apply_filters('ap_set_points', $points, $type, $uid, $data); $difference = $points - ap_get_points($uid); ap_update_points($uid, $points); ap_point_log($type, $uid, $difference, $data); }
public function ap_ask_form_bottom() { if (!is_super_admin() && ap_opt('captcha_answer') && ap_current_page_is() == 'question') { ?> <?php if (ap_opt('enable_captcha_skip') && ap_get_points() < ap_opt('captcha_skip_rpoints')) { ?> <div class="form-group"> <div id="recaptcha"><?php ap_recaptch_html(); ?> </div> </div> <?php } elseif (!ap_opt('enable_captcha_skip')) { ?> <div class="form-group"> <div id="recaptcha"><?php ap_recaptch_html(); ?> </div> </div> <?php } ?> <?php } elseif (!is_super_admin() && ap_opt('captcha_ask') && ap_current_page_is() == 'ask') { ?> <?php if (ap_opt('enable_captcha_skip') && ap_get_points() < ap_opt('captcha_skip_rpoints')) { ?> <div class="form-group"> <div id="recaptcha"><?php ap_recaptch_html(); ?> </div> </div> <?php } elseif (!ap_opt('enable_captcha_skip')) { ?> <div class="form-group"> <div id="recaptcha"><?php ap_recaptch_html(); ?> </div> </div> <?php } ?> <?php } }
public function process_ask_form() { if (!is_user_logged_in() && !ap_allow_anonymous()) { return false; } if (isset($_POST['is_question']) && isset($_POST['submitted']) && isset($_POST['ask_form']) && wp_verify_nonce($_POST['ask_form'], 'post_nonce')) { $fields = $this->get_question_fields_to_process(); if (!ap_user_can_ask() && ap_opt('allow_anonymous')) { return; } $validate = $this->validate_question_form(); if ($validate['has_error']) { if ($_POST['action'] == 'ap_submit_question') { $result = array('action' => 'validation_falied', 'message' => __('Question not submitted, please check the form fields.', 'ap'), 'error' => $validate); return json_encode($result); } return; } do_action('process_ask_form'); $user_id = get_current_user_id(); $status = 'publish'; if (ap_opt('moderate_new_question') == 'pending' || ap_opt('moderate_new_question') == 'point' && ap_get_points($user_id) < ap_opt('mod_question_point')) { $status = 'moderate'; } if (isset($fields['private_question']) && $fields['private_question']) { $status = 'private_question'; } $question_array = array('post_title' => $fields['post_title'], 'post_author' => $user_id, 'post_content' => wp_kses($fields['post_content'], ap_form_allowed_tags()), 'post_type' => 'question', 'post_status' => $status); if (isset($fields['parent_id'])) { $question_array['post_parent'] = (int) $fields['parent_id']; } $post_id = wp_insert_post($question_array); if ($post_id) { // Update Custom Meta if (isset($fields['category'])) { wp_set_post_terms($post_id, $fields['category'], 'question_category'); } if (isset($fields['tags'])) { wp_set_post_terms($post_id, $fields['tags'], 'question_tags'); } if (ap_opt('allow_anonymous') && isset($fields['name'])) { update_post_meta($post_id, 'anonymous_name', $fields['name']); } if ($_POST['action'] == 'ap_submit_question') { $result = apply_filters('ap_ajax_question_submit_result', array('action' => 'new_question', 'message' => __('Question submitted successfully', 'ap'), 'redirect_to' => get_permalink($post_id))); return json_encode($result); } else { // Redirect wp_redirect(get_permalink($post_id)); exit; } } } }