Exemple #1
0
 public function load_ajax_commentform()
 {
     if (!ap_user_can_comment()) {
         _e('No Permission', 'ap');
         die;
     }
     $args = explode('-', sanitize_text_field($_REQUEST['args']));
     $action = get_post_type($args[0]) . '-' . $args[0];
     if (wp_verify_nonce($args[1], $action)) {
         $comment_args = array('title_reply' => '', 'logged_in_as' => '', 'comment_field' => '<div class="ap-comment-ta"><textarea name="comment" rows="3" aria-required="true" class="form-control autogrow" placeholder="' . __('Respond to the post.', 'ap') . '"></textarea></div><input type="hidden" name="ap_comment_form" value="true"/>', 'comment_notes_after' => '');
         $current_user = get_userdata(get_current_user_id());
         echo '<div class="comment-form-c clearfix">';
         echo '<div class="ap-content-inner">';
         comment_form($comment_args, $args[0]);
         echo '</div>';
         echo '</div>';
     }
     die;
 }
Exemple #2
0
 public function comment_form()
 {
     if (empty($_POST['comment'])) {
         $this->result = ap_ajax_responce('comment_content_empty');
         return;
     }
     if (!isset($_REQUEST['comment_ID'])) {
         // Do security check
         if (!ap_user_can_comment() || !isset($_POST['__nonce']) || !wp_verify_nonce($_POST['__nonce'], 'comment_' . (int) $_POST['comment_post_ID'])) {
             $this->result = ap_ajax_responce('no_permission');
             return;
         }
     } else {
         if (!ap_user_can_edit_comment((int) $_REQUEST['comment_ID']) || !wp_verify_nonce($_REQUEST['__nonce'], 'comment_' . (int) $_REQUEST['comment_ID'])) {
             $this->result = ap_ajax_responce('no_permission');
             return;
         }
     }
     $comment_post_ID = (int) $_POST['comment_post_ID'];
     $post = get_post($comment_post_ID);
     if (!$post || empty($post->post_status)) {
         return;
     }
     if (in_array($post->post_status, array('draft', 'pending', 'trash'))) {
         $this->result = ap_ajax_responce('draft_comment_not_allowed');
         return;
     }
     if (isset($_POST['comment_ID'])) {
         $comment_id = (int) $_POST['comment_ID'];
         $updated = wp_update_comment(array('comment_ID' => $comment_id, 'comment_content' => trim($_POST['comment'])));
         if ($updated) {
             $comment = get_comment($comment_id);
             ob_start();
             comment_text($comment_id);
             $html = ob_get_clean();
             $this->result = ap_ajax_responce(array('action' => 'edit_comment', 'comment_ID' => $comment->comment_ID, 'comment_post_ID' => $comment->comment_post_ID, 'comment_content' => $comment->comment_content, 'html' => $html, 'message' => 'comment_edit_success'));
         }
         return;
     } else {
         $user = wp_get_current_user();
         if ($user->exists()) {
             $user_ID = $user->ID;
             $comment_author = wp_slash($user->display_name);
             $comment_author_email = wp_slash($user->user_email);
             $comment_author_url = wp_slash($user->user_url);
             $comment_content = trim($_POST['comment']);
             $comment_type = 'anspress';
         } else {
             $this->result = ap_ajax_responce('no_permission');
             return;
         }
         $comment_parent = 0;
         if (isset($_POST['comment_ID'])) {
             $comment_parent = absint($_POST['comment_ID']);
         }
         $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
         // Automatically approve parent comment.
         if (!empty($_POST['approve_parent'])) {
             $parent = get_comment($comment_parent);
             if ($parent && $parent->comment_approved === '0' && $parent->comment_post_ID == $comment_post_ID) {
                 if (wp_set_comment_status($parent->comment_ID, 'approve')) {
                     $comment_auto_approved = true;
                 }
             }
         }
         $comment_id = wp_new_comment($commentdata);
         if ($comment_id > 0) {
             $comment = get_comment($comment_id);
             do_action('ap_after_new_comment', $comment);
             ob_start();
             ap_comment($comment);
             $html = ob_get_clean();
             $count = get_comment_count($comment->comment_post_ID);
             $this->result = ap_ajax_responce(array('action' => 'new_comment', 'status' => true, 'comment_ID' => $comment->comment_ID, 'comment_post_ID' => $comment->comment_post_ID, 'comment_content' => $comment->comment_content, 'html' => $html, 'message' => 'comment_success', 'view' => array('comments_count_' . $comment->comment_post_ID => '(' . $count['approved'] . ')', 'comment_count_label_' . $comment->comment_post_ID => sprintf(_n('One comment', '%d comments', $count['approved'], 'ap'), $count['approved']))));
         } else {
             $this->result = ap_ajax_responce('something_wrong');
         }
     }
 }
Exemple #3
0
/**
 * Post actions buttons
 * @return 	string
 * @param  array $disable
 * @return void
 * @since 	2.0
 */
function ap_post_actions_buttons($disable = array())
{
    global $post;
    if (!$post->post_type == 'question' || !$post->post_type == 'answer') {
        return;
    }
    $actions = array();
    /**
     * Select answer button
     * @var string
     */
    if ($post->post_type == 'answer') {
        $actions['select_answer'] = ap_select_answer_btn_html($post->ID);
    }
    /**
     * Comment button
     */
    if (ap_user_can_comment()) {
        $actions['comment'] = ap_comment_btn_html();
    }
    $actions['status'] = ap_post_change_status_btn_html($post->ID);
    /**
     * edit question link
     */
    if (ap_user_can_edit_question($post->ID) && $post->post_type == 'question') {
        $actions['dropdown']['edit_question'] = ap_edit_post_link_html();
    }
    if (ap_user_can_edit_ans($post->ID) && $post->post_type == 'answer') {
        $actions['dropdown']['edit_answer'] = ap_edit_post_link_html();
    }
    if (is_user_logged_in()) {
        $actions['dropdown']['flag'] = ap_flag_btn_html();
    }
    if (is_super_admin() && $post->post_type == 'question') {
        $actions['dropdown']['featured'] = ap_featured_post_btn();
    }
    if (ap_user_can_delete($post->ID) && $post->post_status != 'trash') {
        $actions['dropdown']['delete'] = ap_post_delete_btn_html();
    }
    if (ap_user_can_delete($post->ID)) {
        $actions['dropdown']['permanent_delete'] = ap_post_permanent_delete_btn_html();
    }
    /**
     * FILTER: ap_post_actions_buttons
     * For filtering post actions buttons
     * @var 	string
     * @since 	2.0
     */
    $actions = apply_filters('ap_post_actions_buttons', $actions);
    if (!empty($actions) && count($actions) > 0) {
        echo '<ul id="ap_post_actions_' . $post->ID . '" class="ap-q-actions ap-ul-inline clearfix">';
        foreach ($actions as $k => $action) {
            if (!empty($action) && $k != 'dropdown' && !in_array($k, $disable)) {
                echo '<li class="ap-post-action ap-action-' . $k . '">' . $action . '</li>';
            }
        }
        if (!empty($actions['dropdown'])) {
            echo '<li class="ap-post-action dropdown">';
            echo '<div id="ap_post_action_' . $post->ID . '" class="ap-dropdown">';
            echo '<a class="apicon-ellipsis more-actions ap-tip ap-dropdown-toggle" title="' . __('More action', 'ap') . '" href="#"></a>';
            echo '<ul class="ap-dropdown-menu">';
            foreach ($actions['dropdown'] as $sk => $sub) {
                echo '<li class="ap-post-action ap-action-' . $sk . '">' . $sub . '</li>';
            }
            echo '</ul>';
            echo '</div>';
            echo '</li>';
        }
        echo '</ul>';
    }
}
Exemple #4
0
/**
 * Load comment form button.
 *
 * @param bool $echo
 *
 * @return string
 *
 * @since 0.1
 */
function ap_comment_btn_html($echo = false)
{
    if (ap_user_can_comment()) {
        global $post;
        if ($post->post_type == 'question' && ap_opt('disable_comments_on_question')) {
            return;
        }
        if ($post->post_type == 'answer' && ap_opt('disable_comments_on_answer')) {
            return;
        }
        $nonce = wp_create_nonce('comment_form_nonce');
        $comment_count = get_comments_number(get_the_ID());
        $output = '<a href="#comments-' . get_the_ID() . '" class="comment-btn ap-tip" data-action="load_comment_form" data-query="ap_ajax_action=load_comment_form&post=' . get_the_ID() . '&__nonce=' . $nonce . '" title="' . __('Comments', 'ap') . '">' . __('Comment', 'ap') . '<span class="ap-data-view ap-view-count-' . $comment_count . '" data-view="comments_count_' . get_the_ID() . '">(' . $comment_count . ')</span></a>';
        if ($echo) {
            echo $output;
        } else {
            return $output;
        }
    }
}