Beispiel #1
0
/**
 * Flag button html.
 *
 * @return string
 *
 * @since 0.9
 */
function ap_flag_btn_html($echo = false)
{
    if (!is_user_logged_in()) {
        return;
    }
    global $post;
    $flagged = ap_is_user_flagged();
    $total_flag = ap_post_flag_count();
    $nonce = wp_create_nonce('flag_' . $post->ID);
    $title = !$flagged ? __('Flag this post', 'ap') : __('You have flagged this post', 'ap');
    $output = '<a id="flag_' . $post->ID . '" data-query="ap_ajax_action=flag_post&post_id=' . $post->ID . '&__nonce=' . $nonce . '" data-action="ap_subscribe" class="flag-btn' . (!$flagged ? ' can-flagged' : '') . '" href="#" title="' . $title . '">' . __('Flag ', 'ap') . '<span class="ap-data-view ap-view-count-' . $total_flag . '" data-view="' . $post->ID . '_flag_count">' . $total_flag . '</span></a>';
    if ($echo) {
        echo $output;
    } else {
        return $output;
    }
}
Beispiel #2
0
 /**
  * Ajax callback to process post flag button
  * @since 2.0.0
  */
 public function flag_post()
 {
     $post_id = (int) $_POST['args'][0];
     if (!ap_verify_nonce('flag_' . $post_id) || !is_user_logged_in()) {
         $this->something_wrong();
     }
     $userid = get_current_user_id();
     $is_flagged = ap_is_user_flagged($post_id);
     if ($is_flagged) {
         $this->send(array('message' => 'already_flagged'));
     } else {
         ap_add_flag($userid, $post_id);
         $count = ap_post_flag_count($post_id);
         // Update post meta.
         update_post_meta($post_id, ANSPRESS_FLAG_META, $count);
         $this->send(array('message' => 'flagged', 'action' => 'flagged', 'view' => array($post_id . '_flag_count' => $count), 'count' => $count));
     }
     $this->something_wrong();
 }
Beispiel #3
0
do_action('ap_before_admin_page_title');
?>
	<h2><?php 
_e('Post flag', 'ap');
?>
</h2>

	<div class="ap-admin-container">
		<div class="ap-flag-post-content">
			<h1><?php 
the_title();
?>
</h1>
			<div class="ap-admin-sub">
				<span><?php 
printf(__('Total <b>%d flag</b>', 'ap'), ap_post_flag_count());
?>
</span>
				<span> | <a href="<?php 
echo get_edit_post_link(get_the_ID());
?>
"><?php 
_e('Edit post', 'ap');
?>
</a></span>
				<span> | <a href="<?php 
echo get_delete_post_link(get_the_ID());
?>
"><?php 
_e('Trash post', 'ap');
?>
Beispiel #4
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>';
     }
 }
Beispiel #5
0
 /**
  * Flag a post as inappropriate
  * @return void
  * @since 2.0.0-alpha2
  */
 public function flag_post()
 {
     $post_id = (int) $_POST['post_id'];
     if (!wp_verify_nonce($_POST['__nonce'], 'flag_' . $post_id) && is_user_logged_in()) {
         ap_send_json(ap_ajax_responce('something_wrong'));
         return;
     }
     $userid = get_current_user_id();
     $is_flagged = ap_is_user_flagged($post_id);
     if ($is_flagged) {
         ap_send_json(ap_ajax_responce(array('message' => 'already_flagged')));
         echo json_encode(array('action' => false, 'message' => __('You already flagged this post', 'ap')));
     } else {
         ap_add_flag($userid, $post_id);
         $count = ap_post_flag_count($post_id);
         //update post meta
         update_post_meta($post_id, ANSPRESS_FLAG_META, $count);
         ap_send_json(ap_ajax_responce(array('message' => 'flagged', 'action' => 'flagged', 'view' => array($post_id . '_flag_count' => $count), 'count' => $count)));
     }
     die;
 }
Beispiel #6
0
 public function ap_submit_flag_note()
 {
     $args = explode('-', sanitize_text_field($_POST['args']));
     $note_id = sanitize_text_field($_POST['note_id']);
     $other_note = sanitize_text_field($_POST['other_note']);
     if (wp_verify_nonce($args[1], 'flag_submit_' . $args[0])) {
         global $wpdb;
         $userid = get_current_user_id();
         $is_flagged = ap_is_user_flagged($args[0]);
         if ($is_flagged) {
             // if already then return
             echo json_encode(array('action' => false, 'message' => __('You already flagged this post', 'ap')));
         } else {
             if ($note_id != 'other') {
                 $row = ap_add_flag($userid, $args[0], $note_id);
             } else {
                 $row = ap_add_flag($userid, $args[0], NULL, $other_note);
             }
             $counts = ap_post_flag_count($args[0]);
             //update post meta
             update_post_meta($args[0], ANSPRESS_FLAG_META, $counts);
             echo json_encode(array('row' => $row, 'action' => 'flagged', 'text' => __('Flag', 'ap') . ' (' . $counts . ')', 'title' => __('You have flagged this post', 'ap'), 'message' => __('This post is notified to moderator. Thank you for helping us', 'ap')));
         }
     } else {
         echo '0' . __('Please try again', 'ap');
     }
     die;
 }
Beispiel #7
0
do_action('ap_before_admin_page_title');
?>
	<h2><?php 
_e('Post flag', 'anspress-question-answer');
?>
</h2>

    <div class="ap-admin-container">
        <div class="ap-flag-post-content">
			<h1><?php 
the_title();
?>
</h1>
            <div class="ap-admin-sub">
				<span><?php 
printf(__('Total <b>%d flag</b>', 'anspress-question-answer'), ap_post_flag_count());
?>
</span>
				<span> | <a href="<?php 
echo get_edit_post_link(get_the_ID());
?>
"><?php 
_e('Edit post', 'anspress-question-answer');
?>
</a></span>
				<span> | <a href="<?php 
echo get_delete_post_link(get_the_ID());
?>
"><?php 
_e('Trash post', 'anspress-question-answer');
?>