コード例 #1
0
ファイル: anspress-form.php プロジェクト: jessor/anspress
 public function process_answer_form()
 {
     if (!is_user_logged_in()) {
         return false;
     }
     if (isset($_POST['is_answer']) && isset($_POST['submitted']) && isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'post_nonce_' . $_POST['form_question_id'])) {
         $fields = $this->get_answer_fields_to_process();
         $validate = $this->validate_ans_form();
         if ($validate['has_error']) {
             if ($_POST['action'] == 'ap_submit_answer') {
                 $result = array('action' => 'validation_falied', 'message' => __('Answer not submitted, please check the form fields.', 'ap'), 'error' => $validate);
                 return json_encode($result);
             }
             return;
         }
         if (!isset($fields['question_id']) && !is_int($fields['question_id']) && 'question' !== get_post_type($fields['question_id'])) {
             return;
         }
         $question = get_post($fields['question_id']);
         if (!ap_user_can_answer($question->ID)) {
             return;
         }
         do_action('process_answer_form');
         $logged_in = false;
         $user_id = get_current_user_id();
         $ans_array = array('post_author' => $user_id, 'post_content' => wp_kses($fields['post_content'], ap_form_allowed_tags()), 'post_type' => 'answer', 'post_status' => 'publish', 'post_parent' => $question->ID);
         $post_id = wp_insert_post($ans_array);
         if ($post_id) {
             // set default value for meta
             update_post_meta($post_id, ANSPRESS_VOTE_META, '0');
             // set updated meta for sorting purpose
             update_post_meta($question->ID, ANSPRESS_UPDATED_META, current_time('mysql'));
             ap_add_parti($question->ID, $user_id, 'answer');
             // get existing answer count
             $current_ans = ap_count_ans($question->ID);
             //update answer count
             update_post_meta($question->ID, ANSPRESS_ANS_META, $current_ans);
             update_post_meta($post_id, ANSPRESS_BEST_META, 0);
             // redirect if just logged in
             if ($logged_in && $_POST['action'] != 'ap_submit_answer') {
                 wp_redirect(get_permalink($question->ID));
                 exit;
             }
             $result = array();
             if ($_POST['action'] == 'ap_submit_answer') {
                 if ($current_ans == 1) {
                     global $post;
                     $post = $question;
                     setup_postdata($post);
                 } else {
                     global $post;
                     $post = get_post($post_id);
                     setup_postdata($post);
                 }
                 ob_start();
                 if ($current_ans == 1) {
                     ap_answers_list($post->ID, 'voted');
                 } else {
                     include ap_get_theme_location('answer.php');
                 }
                 $html = ob_get_clean();
                 $count_label = sprintf(_n('1 Answer', '%d Answers', $current_ans, 'ap'), $current_ans);
                 $result = apply_filters('ap_ajax_answer_submit_result', array('postid' => $post_id, 'action' => 'new_answer', 'div_id' => '#answer_' . get_the_ID(), 'count' => $current_ans, 'count_label' => $count_label, 'can_answer' => ap_user_can_answer($post->ID), 'html' => $html, 'message' => __('Answer submitted successfully!', 'ap')));
                 if ($logged_in) {
                     $result['redirect_to'] = get_permalink($post->ID);
                 }
             }
             do_action('ap_after_inserting_answer', $post_id);
             ap_do_event('new_answer', $post_id, $user_id, $question->ID, $result);
             if ($_POST['action'] == 'ap_submit_answer') {
                 return json_encode($result);
             }
         }
     } elseif ($_POST['action'] == 'ap_submit_answer') {
         $result = array('postid' => $post_id, 'action' => false, 'message' => __('Please try again, answer submission failed!', 'ap'));
         return json_encode($result);
     }
 }
コード例 #2
0
ファイル: question.php プロジェクト: coollog/theboola
        printf(__('<span>Active</span><strong><time class="updated" itemprop="dateUpdated" datetime="%s">%s Ago</time></strong>', 'ap'), mysql2date('c', ap_last_active(get_question_id())), ap_human_time(mysql2date('U', ap_last_active(get_question_id()))));
        ?>
										</li>
									</ul>
								</div>																
							</div>
							<?php 
        comments_template();
        ?>
						</div>						
					</div>		
				</div>
				
				<?php 
        if (ap_have_ans(get_the_ID())) {
            ap_answers_list(get_the_ID(), 'voted');
        }
        ?>
					
				<?php 
        if (ap_user_can_answer(get_question_id())) {
            include ap_get_theme_location('answer-form.php');
        }
        ?>

		</div>
		</div>
		<div class="ap-question-right">
			<div class="ap-question-right-inner">
				<?php 
        ap_question_side_tab(get_question_id());