示例#1
0
 /**
  * Show similar questions when asking a question.
  *
  * @since 2.0.1
  */
 public function suggest_similar_questions()
 {
     if (empty($_POST['value']) || !ap_verify_default_nonce() && !current_user_can('manage_options')) {
         wp_die('false');
     }
     $keyword = sanitize_text_field(wp_unslash($_POST['value']));
     $is_admin = (bool) $_POST['is_admin'];
     $questions = get_posts(array('post_type' => 'question', 'showposts' => 10, 's' => $keyword));
     if ($questions) {
         $items = '<div class="ap-similar-questions-head">';
         $items .= '<h3>' . ap_icon('check', true) . sprintf(__('%d similar questions found', 'anspress-question-answer'), count($questions)) . '</h3>';
         $items .= '<p>' . __('We\'ve found similar questions that have already been asked, click to read them.', 'anspress-question-answer') . '</p>';
         $items .= '</div>';
         $items .= '<div class="ap-similar-questions">';
         foreach ($questions as $p) {
             $count = ap_count_answer_meta($p->ID);
             $p->post_title = ap_highlight_words($p->post_title, $keyword);
             if ($is_admin) {
                 $items .= '<div class="ap-q-suggestion-item clearfix"><a class="select-question-button button button-primary button-small" href="' . add_query_arg(array('post_type' => 'answer', 'post_parent' => $p->ID), admin_url('post-new.php')) . '">' . __('Select', 'anspress-question-answer') . '</a><span class="question-title">' . $p->post_title . '</span><span class="acount">' . sprintf(_n('1 Answer', '%d Answers', $count, 'anspress-question-answer'), $count) . '</span></div>';
             } else {
                 $items .= '<a class="ap-sqitem clearfix" target="_blank" href="' . get_permalink($p->ID) . '"><span class="acount">' . sprintf(_n('1 Answer', '%d Answers', $count, 'anspress-question-answer'), $count) . '</span><span class="ap-title">' . $p->post_title . '</span></a>';
             }
         }
         $items .= '</div>';
         $result = array('status' => true, 'html' => $items);
     } else {
         $result = array('status' => false, 'message' => __('No related questions found', 'anspress-question-answer'));
     }
     $this->send($result);
 }
示例#2
0
 /**
  * Show similar questions when asking a question
  * @return void
  * @since 2.0.1
  */
 public function suggest_similar_questions()
 {
     if (empty($_POST['value'])) {
         return;
     }
     $keyword = sanitize_text_field($_POST['value']);
     $questions = get_posts(array('post_type' => 'question', 'showposts' => 10, 's' => $keyword));
     if ($questions) {
         $items = '<div class="ap-similar-questions-head">';
         $items .= '<h3>' . ap_icon('check', true) . sprintf(__('%d similar questions found', 'ap'), count($questions)) . '</h3>';
         $items .= '<p>' . __('We found similar questions that have already been asked, click to read them. Avoid creating duplicate questions, it will be deleted.') . '</p>';
         $items .= '</div>';
         $items .= '<div class="ap-similar-questions">';
         foreach ($questions as $p) {
             $count = ap_count_answer_meta($p->ID);
             $p->post_title = ap_highlight_words($p->post_title, $keyword);
             if (!isset($_POST['is_admin'])) {
                 $items .= '<a class="ap-sqitem clearfix" href="' . get_permalink($p->ID) . '"><span class="acount">' . sprintf(_n('1 Answer', '%d Answers', $count, 'ap'), $count) . '</span><span class="ap-title">' . $p->post_title . '</span></a>';
             } else {
                 $items .= '<div class="ap-q-suggestion-item clearfix"><a class="select-question-button button button-primary button-small" href="' . add_query_arg(array('post_type' => 'answer', 'post_parent' => $p->ID), admin_url('post-new.php')) . '">' . __('Select', 'ap') . '</a><span class="question-title">' . $p->post_title . '</span><span class="acount">' . sprintf(_n('1 Answer', '%d Answers', $count, 'ap'), $count) . '</span></div>';
             }
         }
         $items .= '</div>';
         $result = array('status' => true, 'html' => $items);
     } else {
         $result = array('status' => false, 'message' => __('No related questions found', 'ap'));
     }
     ap_send_json($result);
 }
示例#3
0
 /**
  * Add answer-seleted class in post_class
  * @param  array $classes Post class attribute.
  * @return array
  * @since 2.0.1
  */
 public function question_answer_post_class($classes)
 {
     global $post;
     if ('question' == $post->post_type) {
         if (ap_question_best_answer_selected($post->ID)) {
             $classes[] = 'answer-selected';
         }
         if (ap_is_featured_question($post->ID)) {
             $classes[] = 'featured-question';
         }
         $classes[] = 'answer-count-' . ap_count_answer_meta();
     } elseif ('answer' == $post->post_type) {
         if (ap_answer_is_best($post->ID)) {
             $classes[] = 'best-answer';
         }
     }
     return $classes;
 }
示例#4
0
    public function question_meta_box_content($post)
    {
        $ans_count = ap_count_answer_meta($post->ID);
        $vote_count = get_post_meta($post->ID, ANSPRESS_VOTE_META, true);
        ?>
			<ul>
				<li> <?php 
        printf(_n('<strong>1</strong> Answer', '<strong>%d</strong> Answers', $ans_count, 'ap'), $ans_count);
        ?>
 </li>
				<li> <?php 
        printf(_n('<strong>1</strong> Vote', '<strong>%d</strong> Votes', $vote_count, 'ap'), $vote_count);
        ?>
 </li>
			</ul>
		<?php 
    }
示例#5
0
/**
 * Count all answers excluding best answer.
 *
 * @return int
 */
function ap_count_other_answer($question_id = false)
{
    if (!$question_id) {
        $question_id = get_question_id();
    }
    $count = ap_count_answer_meta($question_id);
    if (ap_question_best_answer_selected($question_id)) {
        return (int) ($count - 1);
    }
    return (int) $count;
}
示例#6
0
/**
 * Return active question answer count
 * @return integer
 * @since 2.1
 */
function ap_question_get_the_answer_count()
{
    return ap_count_answer_meta(ap_question_get_the_ID());
}
示例#7
0
 public function custom_columns_value($column)
 {
     global $post;
     if (!($post->post_type != 'question' || $post->post_type != 'answer')) {
         return $column;
     }
     if ('asker' == $column || 'answerer' == $column) {
         echo get_avatar(get_the_author_meta('user_email'), 40);
     } elseif ('status' == $column) {
         echo '<span class="post-status">';
         if ('private_post' == $post->post_status) {
             echo __('Private', 'ap');
         } elseif ('closed' == $post->post_status) {
             echo __('Closed', 'ap');
         } elseif ('moderate' == $post->post_status) {
             echo __('Moderate', 'ap');
         } elseif ('private' == $post->post_status) {
             echo __('Private', 'ap');
         } elseif ('darft' == $post->post_status) {
             echo __('Draft', 'ap');
         } elseif ('pending' == $post->post_status) {
             echo __('Pending', 'ap');
         } elseif ('trash' == $post->post_status) {
             echo __('Trash', 'ap');
         } else {
             echo __('Open', 'ap');
         }
         echo '</span>';
     } elseif ('question_category' == $column && taxonomy_exists('question_category')) {
         $category = get_the_terms($post->ID, 'question_category');
         if (!empty($category)) {
             $out = array();
             foreach ($category as $cat) {
                 $out[] = edit_term_link($cat->name, '', '', $cat, false);
             }
             echo join(', ', $out);
         } else {
             _e('--');
         }
     } elseif ('question_tag' == $column && taxonomy_exists('question_tag')) {
         $terms = get_the_terms($post->ID, 'question_tag');
         if (!empty($terms)) {
             $out = array();
             foreach ($terms as $term) {
                 $out[] = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post_type' => $post->post_type, 'question_tag' => $term->slug), 'edit.php')), esc_html(sanitize_term_field('name', $term->name, $term->term_id, 'question_tag', 'display')));
             }
             echo join(', ', $out);
         } else {
             _e('--', 'ap');
         }
     } elseif ('answers' == $column) {
         $a_count = ap_count_answer_meta();
         /* If terms were found. */
         if (!empty($a_count)) {
             echo '<a class="ans-count" title="' . $a_count . __('answers', 'ap') . '" href="' . esc_url(add_query_arg(array('post_type' => 'answer', 'post_parent' => $post->ID), 'edit.php')) . '">' . $a_count . '</a>';
         } else {
             echo '<a class="ans-count" title="0' . __('answers', 'ap') . '">0</a>';
         }
     } elseif ('parent_question' == $column) {
         echo '<a class="parent_question" href="' . esc_url(add_query_arg(array('post' => $post->post_parent, 'action' => 'edit'), 'post.php')) . '"><strong>' . get_the_title($post->post_parent) . '</strong></a>';
     } elseif ('vote' == $column) {
         $vote = get_post_meta($post->ID, ANSPRESS_VOTE_META, true);
         echo '<span class="vote-count' . ($vote ? ' zero' : '') . '">' . $vote . '</span>';
     } elseif ('flag' == $column) {
         $total_flag = ap_post_flag_count();
         echo '<span class="flag-count' . ($total_flag ? ' flagged' : '') . '">' . $total_flag . '</span>';
     }
 }
示例#8
0
    public function question_meta_box_content($post)
    {
        $ans_count = ap_count_answer_meta($post->ID);
        $vote_count = get_post_meta($post->ID, ANSPRESS_VOTE_META, true);
        ?>
            <ul class="ap-meta-list">
            	<?php 
        if ('answer' == $post->post_type) {
            ?>
					<li>
						<i class="apicon-answer"></i>
						<?php 
            printf(_n('<strong>1</strong> Answer', '<strong>%d</strong> Answers', $ans_count, 'anspress-question-answer'), $ans_count);
            ?>
						<a href="#" class="add-answer"><?php 
            _e('Add an answer', 'anspress-question-answer');
            ?>
</a>
					</li>
				<?php 
        }
        ?>
				
				<li>
					<i class="apicon-thumb-up"></i>
					<?php 
        printf(_n('<strong>1</strong> Vote', '<strong>%d</strong> Votes', $vote_count, 'anspress-question-answer'), $vote_count);
        ?>
					
					<a id="ap-vote-down" href="#" class="vote button button-small"><?php 
        _e('-', 'anspress-question-answer');
        ?>
</a>
					<a id="ap-vote-up" href="#" class="vote button button-small"><?php 
        _e('+', 'anspress-question-answer');
        ?>
</a>
				</li>
				<li><?php 
        $this->flag_meta_box($post);
        ?>
 </li>
            </ul>
		<?php 
    }