예제 #1
0
 /**
  * Process answer form
  */
 public function process_answer_form()
 {
     global $ap_errors, $validate;
     if (ap_show_captcha_to_user() && !$this->check_recaptcha()) {
         $this->result = array('form' => $_POST['ap_form_action'], 'message' => 'captcha_error', 'errors' => array('captcha' => __('Bot verification failed.', 'ap')));
         return;
     }
     $question = get_post((int) $_POST['form_question_id']);
     $args = array('description' => array('sanitize' => array('remove_more', 'encode_pre_code', 'wp_kses'), 'validate' => array('required' => true, 'length_check' => ap_opt('minimum_question_length'))), 'is_private' => array('sanitize' => array('only_boolean')), 'name' => array('sanitize' => array('strip_tags', 'sanitize_text_field')), 'form_question_id' => array('sanitize' => array('only_int')), 'edit_post_id' => array('sanitize' => array('only_int')));
     /**
      * FILTER: ap_answer_fields_validation
      * Filter can be used to modify answer form fields.
      * @var void
      * @since 2.0.1
      */
     $args = apply_filters('ap_answer_fields_validation', $args);
     $validate = new AnsPress_Validation($args);
     $ap_errors = $validate->get_errors();
     // if error in form then return
     if ($validate->have_error()) {
         $this->result = array('form' => $_POST['ap_form_action'], 'message_type' => 'error', 'message' => __('Check missing fields and then re-submit.', 'ap'), 'errors' => $ap_errors);
         return;
     }
     $fields = $validate->get_sanitized_fields();
     $this->fields = $fields;
     if (!empty($fields['edit_post_id'])) {
         $this->edit_answer($question);
         return;
     }
     // Do security check, if fails then return
     if (!ap_user_can_answer($question->ID) || !isset($_POST['__nonce']) || !wp_verify_nonce($_POST['__nonce'], 'nonce_answer_' . $question->ID)) {
         $this->result = ap_ajax_responce('no_permission');
         return;
     }
     $user_id = get_current_user_id();
     $status = 'publish';
     if (ap_opt('new_answer_status') == 'moderate' || ap_opt('new_answer_status') == 'point' && ap_get_points($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('post_title' => $question->post_title, 'post_author' => $user_id, 'post_content' => apply_filters('ap_form_contents_filter', $fields['description']), 'post_parent' => $question->ID, 'post_type' => 'answer', 'post_status' => $status, 'comment_status' => 'open');
     /**
      * FILTER: ap_pre_insert_answer
      * Can be used to modify args before inserting answer
      * @var array
      * @since 2.0.1
      */
     $answer_array = apply_filters('ap_pre_insert_answer', $answer_array);
     $post_id = wp_insert_post($answer_array);
     if ($post_id) {
         // get existing answer count
         $current_ans = ap_count_published_answers($question->ID);
         if (!is_user_logged_in() && ap_opt('allow_anonymous') && isset($fields['name'])) {
             update_post_meta($post_id, 'anonymous_name', $fields['name']);
         }
         if ($this->is_ajax) {
             if ($current_ans == 1) {
                 global $post;
                 $post = $question;
                 setup_postdata($post);
             } else {
                 global $post;
                 $post = get_post($post_id);
                 setup_postdata($post);
             }
             ob_start();
             global $answers;
             if ($current_ans == 1) {
                 $answers = ap_get_answers(array('question_id' => $question->ID));
                 ap_get_template_part('answers');
             } else {
                 $answers = ap_get_answers(array('p' => $post_id));
                 while (ap_have_answers()) {
                     ap_the_answer();
                     ap_get_template_part('answer');
                 }
             }
             $html = ob_get_clean();
             $count_label = sprintf(_n('1 Answer', '%d Answers', $current_ans, 'ap'), $current_ans);
             $result = array('postid' => $post_id, 'action' => 'new_answer', 'div_id' => '#answer_' . get_the_ID(), 'can_answer' => ap_user_can_answer($post->ID), 'html' => $html, 'message' => 'answer_submitted', 'do' => 'clearForm', 'view' => array('answer_count' => $current_ans, 'answer_count_label' => $count_label));
             $this->result = $result;
         }
     }
     $this->process_image_uploads($post_id, $user_id);
 }
예제 #2
0
	</div><!-- close .ap-about-block -->

	<div class="ap-about-block top-answers">
		<h3><?php 
echo ap_icon('answer', true);
?>
 <?php 
_e('Top Answers', 'ap');
?>
</h3>
		<div class="ap-about-block-c">
			<?php 
ap_get_answers(array('author' => ap_get_displayed_user_id(), 'showposts' => 5, 'sortby' => 'voted'));
?>
			<?php 
if (ap_have_answers()) {
    ?>
				<?php 
    while (ap_answers()) {
        ap_the_answer();
        ?>
					<?php 
        ap_get_template_part('user/list-answer');
        ?>
				<?php 
    }
    ?>
				<div class="ap-user-posts-footer">
					<?php 
    printf(__('More answers by %s', 'ap'), ap_user_get_the_display_name());
    ?>
예제 #3
0
<?php

/**
 * Best answer content
 * 	
 * @author Rahul Aryan <*****@*****.**>
 * @link http://anspress.io/anspress
 * @since 0.1
 *
 * @package AnsPress
 */
/**
 * Show best answer
 */
if (ap_have_answers()) {
    echo '<div id="ap-best-answer">';
    echo '<h3 class="ap-answers-label"><span>' . __('Best answer', 'anspress-question-answer') . '</span></h3>';
    while (ap_have_answers()) {
        ap_the_answer();
        include ap_get_theme_location('answer.php');
    }
    echo '</div>';
}
예제 #4
0
    /**
     * Render Meta Box content.
     */
    public function answers_meta_box_content()
    {
        global $answers;
        $answers = ap_get_answers(array('question_id' => get_the_ID()));
        if (ap_have_answers()) {
            while (ap_have_answers()) {
                ap_the_answer();
                ?>
            <div id="answer_<?php 
                the_ID();
                ?>
" data-id="<?php 
                the_ID();
                ?>
" class="ap-ansm clearfix">
                <div class="author">
					<a class="ap-ansm-avatar" href="<?php 
                ap_answer_the_author_link();
                ?>
"<?php 
                ap_hover_card_attributes(ap_answer_get_author_id());
                ?>
>
						<?php 
                ap_answer_the_author_avatar();
                ?>
					</a>
					<strong class="ap-ansm-name"><?php 
                echo ap_user_display_name(ap_answer_get_author_id());
                ?>
</strong>
                </div>

                <div class="ap-ansm-inner">
                    
                    <div class="ap-ansm-meta">
						<?php 
                ap_answer_the_active_time();
                ?>
					</div>
					
					<div class="ap-ansm-content"><?php 
                the_content();
                ?>
</div>
					
					<div class="answer-actions">

						<span><a href="<?php 
                echo get_edit_post_link(get_the_ID());
                ?>
"><?php 
                _e('Edit', 'ap');
                ?>
</a></span>
						<span class="delete vim-d vim-destructive"> | <a href="<?php 
                echo get_delete_post_link(get_the_ID());
                ?>
"><?php 
                _e('Trash', 'ap');
                ?>
</a></span>
					</div>

				</div>
			</div>
			<?php 
            }
        } else {
            ?>
            <div class="inside">
				<a href="#addanswerbtn" class="button"><?php 
            _e('Add answer', 'ap');
            ?>
</a>
				<?php 
            _e('No answers yet', 'ap');
            ?>
            </div>
            
			<?php 
        }
        wp_reset_postdata();
    }