Exemplo n.º 1
0
function dwqa_read_comment_permission_apply($comments, $post_id)
{
    if (('dwqa-question' == get_post_type($post_id) || 'dwqa-answer' == get_post_type($post_id)) && !dwqa_current_user_can('read_comment')) {
        return array();
    }
    return $comments;
}
 public function submit_question_form_shortcode()
 {
     global $dwqa_sript_vars, $script_version, $dwqa_template_compat;
     ob_start();
     $dwqa_template_compat->remove_all_filters('the_content');
     echo '<div class="dwqa-container" >';
     if (dwqa_current_user_can('post_question')) {
         dwqa_load_template('question', 'submit-form');
     } else {
         echo '<p class="alert alert-error">' . __('You do not have permission to submit question.', 'dwqa') . '</p>';
     }
     echo '</div>';
     $html = ob_get_contents();
     $dwqa_template_compat->restore_all_filters('the_content');
     ob_end_clean();
     wp_enqueue_script('dwqa-submit-question', DWQA_URI . 'inc/templates/default/assets/js/dwqa-submit-question.js', array('jquery'), $script_version, true);
     wp_localize_script('dwqa-submit-question', 'dwqa', $dwqa_sript_vars);
     return $this->sanitize_output($html);
 }
Exemplo n.º 3
0
/**
 * Return number of answer for a question
 * @param  int $question_id Question ID ( if null get ID of current post )
 * @return int      Number of answer
 */
function dwqa_question_answers_count($question_id = null)
{
    global $wpdb;
    if (!$question_id) {
        global $post;
        $question_id = $post->ID;
    }
    $answer_count = get_transient('dwqa_answer_count_for_' . $question_id);
    if (false === $answer_count) {
        $sql = "SELECT COUNT( DISTINCT `P`.ID ) FROM {$wpdb->postmeta} PM JOIN {$wpdb->posts} P ON `PM`.post_id = `P`.ID WHERE `PM`.meta_key = '_question' AND meta_value = {$question_id} AND `P`.post_type = 'dwqa-answer' AND `P`.post_status = 'publish'";
        $sql .= " AND ( `P`.post_status = 'publish' ";
        if (dwqa_current_user_can('edit_question', $question_id)) {
            $sql .= " OR `P`.post_status = 'private'";
        }
        $sql .= " )";
        $answer_count = $wpdb->get_var($sql);
        set_transient('dwqa_answer_count_for_' . $question_id, $answer_count, 15 * 60);
    }
    return $answer_count;
}
Exemplo n.º 4
0
    public function ajax_create_update_question_editor()
    {
        if (!isset($_POST['question'])) {
            return false;
        }
        extract($_POST);
        ob_start();
        ?>
		<form action="<?php 
        echo admin_url('admin-ajax.php?action=dwqa-update-question');
        ?>
" method="post">
			<?php 
        wp_nonce_field('_dwqa_update_question');
        ?>

			<?php 
        if ('draft' == get_post_status($question) && dwqa_current_user_can('edit_question')) {
            ?>
			<input type="hidden" name="dwqa-action-draft" value="true" >
			<?php 
        }
        ?>
 
			<input type="hidden" name="dwqa-action" value="update-question" >
			<input type="hidden" name="question" value="<?php 
        echo $question;
        ?>
">
			<?php 
        $question = get_post($question);
        ?>
			<input type="text" style="width:100%" name="dwqa-question-title" id="dwqa-question-title" value="<?php 
        echo $question->post_title;
        ?>
">
			<?php 
        $question_content = apply_filters('dwqa_prepare_edit_question_content', $question->post_content);
        add_filter('dwqa_prepare_edit_question_content', 'wpautop');
        dwqa_init_tinymce_editor(array('content' => $question_content, 'textarea_name' => 'dwqa-question-content', 'wpautop' => false));
        ?>
			<p class="dwqa-question-form-btn">
				<input type="submit" name="submit-question" class="dwqa-btn dwqa-btn-default" value="<?php 
        _e('Update', 'dwqa');
        ?>
">
				<a type="button" class="question-edit-cancel dwqa-btn dwqa-btn-link" ><?php 
        _e('Cancel', 'dwqa');
        ?>
</a>
				<?php 
        if ('draft' == get_post_status($question) && current_user_can('manage_options')) {
            ?>
				<input type="submit" name="submit-question" class="btn btn-primary btn-small" value="<?php 
            _e('Publish', 'dwqa');
            ?>
">
				<?php 
        }
        ?>
			</p>
		</form>
		<?php 
        $editor = ob_get_contents();
        ob_end_clean();
        wp_send_json_success(array('editor' => $editor));
    }
Exemplo n.º 5
0
 public function posts_where_filter_default($where)
 {
     global $current_user;
     $manager = 0;
     if (dwqa_current_user_can('edit_question')) {
         $manager = 1;
     }
     $where .= " AND if ( post_status = 'private', if ( {$manager} = 1, 1, if ( post_author = {$current_user->ID}, 1, 0 ) ), 1 ) = 1";
     $where .= " AND if ( post_status = 'pending', if ( {$manager} = 1, 1, if ( post_author = {$current_user->ID}, 1, 0 ) ), 1 ) = 1";
     return $where;
 }
Exemplo n.º 6
0
function dwqa_siteinfo_guest_fields()
{
    if (!is_user_logged_in() && dwqa_current_user_can('post_question')) {
        ?>
	<div class="user-name">
		<label for="user-email" title="<?php 
        _e('Enter your name.', 'dwqa_site_info');
        ?>
"><?php 
        _e('Your name *', 'dwqa');
        ?>
</label> 
		<input type="text" name="_dwqa_anonymous_name" id="_dwqa_anonymous_name" class="large-text" placeholder="<?php 
        _e('Your name', 'dwqa_site_info');
        ?>
" required> 
	</div>
	<?php 
    }
}
Exemplo n.º 7
0
        ?>
						<li class="dwqa-comment-edit-link" data-edit="0" data-comment-edit-nonce="<?php 
        echo wp_create_nonce('_dwqa_action_comment_edit_nonce');
        ?>
" data-comment-id="<?php 
        echo $comment->comment_ID;
        ?>
" ><a href="#"><i class="fa fa-pencil"></i> <?php 
        _e('Edit', 'dwqa');
        ?>
</a></li>
						<?php 
    }
    ?>
						<?php 
    if (dwqa_current_user_can('delete_comment') || $current_user->ID == $comment->user_id) {
        ?>
						<li class="comment-delete-link" data-comment-type="<?php 
        echo $post->post_type == 'dwqa-question' ? 'question' : 'answer';
        ?>
" data-comment-id="<?php 
        echo $comment->comment_ID;
        ?>
" data-comment-delete-nonce="<?php 
        echo wp_create_nonce('_dwqa_action_comment_delete_nonce');
        ?>
" ><a href="#"><i class="fa fa-trash-o"></i> <?php 
        _e('Delete', 'dwqa');
        ?>
</a></li>
						<?php 
Exemplo n.º 8
0
    public function ajax_create_update_question_editor()
    {
        if (!isset($_POST['question'])) {
            return false;
        }
        extract($_POST);
        ob_start();
        ?>
		<form action="<?php 
        echo admin_url('admin-ajax.php?action=dwqa-update-question');
        ?>
" method="post">
			<?php 
        wp_nonce_field('_dwqa_update_question');
        ?>

			<?php 
        if ('draft' == get_post_status($question) && dwqa_current_user_can('edit_question')) {
            ?>
			<input type="hidden" name="dwqa-action-draft" value="true" >
			<?php 
        }
        ?>
 
			<input type="hidden" name="dwqa-action" value="update-question" >
			<input type="hidden" name="question" value="<?php 
        echo $question;
        ?>
">
			<?php 
        $question = get_post($question);
        ?>
			<input type="text" style="width:100%" name="dwqa-question-title" id="dwqa-question-title" value="<?php 
        echo $question->post_title;
        ?>
">
			<?php 
        $question_content = apply_filters('dwqa_prepare_edit_question_content', $question->post_content);
        dwqa_init_tinymce_editor(array('content' => $question_content, 'textarea_name' => 'dwqa-question-content', 'wpautop' => false));
        ?>
			<script type="text/javascript">
				var id = 'dwqa-custom-content-editor';
				var settings = tinyMCEPreInit.mceInit['dwqa-answer-question-editor'];

                    settings.elements = id;
                    settings.body_class = id + ' post-type-dwqa-question';
                    settings.editor_selector = id; // deprecated in TinyMCE 4.x
                    settings.selector = '#' + id;
                    //init tinymce
                    if( tinyMCE.get(id) ) {
                        tinymce.remove('#'+id);   
                    }
                    tinyMCE.init(settings);
			</script>
			<p class="dwqa-question-form-btn">
				<input type="submit" name="submit-question" class="dwqa-btn dwqa-btn-default" value="<?php 
        _e('Update', 'dwqa');
        ?>
">
				<a type="button" class="question-edit-cancel dwqa-btn dwqa-btn-link" ><?php 
        _e('Cancel', 'dwqa');
        ?>
</a>
				<?php 
        if ('draft' == get_post_status($question) && current_user_can('manage_options')) {
            ?>
				<input type="submit" name="submit-question" class="btn btn-primary btn-small" value="<?php 
            _e('Publish', 'dwqa');
            ?>
">
				<?php 
        }
        ?>
			</p>
		</form>
		<?php 
        $editor = apply_filters('dwqa_question_edit_content_editor', ob_get_contents(), $_POST);
        ob_end_clean();
        wp_send_json_success(array('editor' => $editor));
    }
	</p>
	<p>
		<label for="question-tag"><?php 
_e('Tag', 'dwqa');
?>
</label>
		<?php 
$tags = isset($_POST['question-tag']) ? $_POST['question-tag'] : '';
?>
		<input type="text" class="" name="question-tag" value="<?php 
echo $tags;
?>
" >
	</p>
	<?php 
if (dwqa_current_user_can('post_question') && !is_user_logged_in()) {
    ?>
	<p>
		<label for="_dwqa_anonymous_email"><?php 
    _e('Your Email', 'dwqa');
    ?>
</label>
		<?php 
    $email = isset($_POST['_dwqa_anonymous_email']) ? $_POST['_dwqa_anonymous_email'] : '';
    ?>
		<input type="email" class="" name="_dwqa_anonymous_email" value="<?php 
    echo $email;
    ?>
" >
	</p>
	<p>
Exemplo n.º 10
0
    ?>
</span>
	</div>
	<?php 
}
?>

	<?php 
if (have_comments()) {
    ?>
	<ol class="dwqa-comment-list">
	<?php 
    wp_list_comments(array('style' => 'ol', 'callback' => 'dwqa_question_comment_callback'));
    ?>
	</ol>
	<?php 
}
?>

	<?php 
if (!dwqa_is_closed(get_the_ID()) && dwqa_current_user_can('post_comment')) {
    ?>
		<?php 
    global $current_user;
    $args = array('comment_field' => (is_user_logged_in() ? get_avatar($current_user->ID, 32) : '') . '<textarea id="comment" name="comment" aria-required="true" placeholder="' . __('Write a reply...', 'dwqa') . '"></textarea>', 'comment_notes_before' => '', 'logged_in_as' => '', 'comment_notes_after' => '', 'id_form' => 'comment_form_' . get_the_ID());
    ?>
		<?php 
    dwqa_comment_form($args);
    ?>
	<?php 
}
		<span class="dwqa-question-actions"><?php 
dwqa_question_button_action();
?>
</span>
	</div>
	<div class="dwqa-question-content"><?php 
the_content();
?>
</div>
	<footer class="dwqa-question-footer">
		<div class="dwqa-question-meta">
			<?php 
echo get_the_term_list(get_the_ID(), 'dwqa-question_tag', '<span class="dwqa-question-tag">' . __('Question Tags: ', 'dwqa'), ', ', '</span>');
?>
			<?php 
if (dwqa_current_user_can('edit_question', get_the_ID())) {
    ?>
			<span class="dwqa-question-status">
				<?php 
    _e('This question is:', 'dwqa');
    ?>
				<select id="dwqa-question-status" data-nonce="<?php 
    echo wp_create_nonce('_dwqa_update_privacy_nonce');
    ?>
" data-post="<?php 
    the_ID();
    ?>
">
					<optgroup label="Status">
						<option <?php 
    selected(dwqa_question_status(), 'open');
Exemplo n.º 12
0
 public function load_template($name, $extend = false, $include = true)
 {
     $check = true;
     if ($extend) {
         $name .= '-' . $extend;
     }
     if ($name == 'submit-question-form' && is_user_logged_in() && !dwqa_current_user_can('post_question')) {
         echo '<div class="alert">' . __('You do not have permission to submit a question', 'dwqa') . '</div>';
         return false;
     }
     $template = get_stylesheet_directory() . '/dwqa-templates/' . $name . '.php';
     if (!file_exists($template)) {
         $template = DWQA_DIR . 'templates/' . $this->active . '/' . $name . '.php';
     }
     $template = apply_filters('dwqa-load-template', $template, $name);
     if (!$template) {
         return false;
     }
     if (!$include) {
         return $template;
     }
     include $template;
 }
Exemplo n.º 13
0
        public function single_question()
        {
            global $post, $current_user;
            $post_id = get_the_ID();
            ?>
        <div class="dwqa-single-question">
            <!-- dwqa-status-private -->
            <article id="question-<?php 
            echo $post_id;
            ?>
" <?php 
            post_class('dwqa-question');
            ?>
>
                <header class="dwqa-header">
                    <h1 class="dwqa-title"><?php 
            the_title();
            ?>
</h1>
                    <div class="dwqa-meta">
                        <span class="dwqa-vote" data-type="question" data-nonce="<?php 
            echo wp_create_nonce('_dwqa_question_vote_nonce');
            ?>
" data-question="<?php 
            echo $post_id;
            ?>
" >
                            <a class="dwqa-vote-dwqa-btn dwqa-vote-up" data-vote="up" href="#"  title="<?php 
            _e('Vote Up', 'dwqa');
            ?>
"><?php 
            _e('Vote Up', 'dwqa');
            ?>
</a>
                            <div class="dwqa-vote-count"><?php 
            $point = dwqa_vote_count();
            echo $point > 0 ? '+' . $point : $point;
            ?>
</div>
                            <a class="dwqa-vote-dwqa-btn dwqa-vote-down" data-vote="down" href="#"  title="<?php 
            _e('Vote Down', 'dwqa');
            ?>
"><?php 
            _e('Vote Down', 'dwqa');
            ?>
</a>
                        </span>

                        <?php 
            if (is_user_logged_in()) {
                ?>
                        <span data-post="<?php 
                echo $post_id;
                ?>
" data-nonce="<?php 
                echo wp_create_nonce('_dwqa_follow_question');
                ?>
" class="dwqa-favourite <?php 
                echo dwqa_is_followed($post_id) ? 'active' : '';
                ?>
" title="<?php 
                echo dwqa_is_followed($post_id) ? __('Unfollow This Question', 'dwqa') : __('Follow This Question', 'dwqa');
                ?>
"><!-- add class 'active' -->
                            <i class="fa fa-star"></i>
                        </span>
                        <?php 
            }
            ?>
                    </div>
                </header>
                <div class="dwqa-content">
                    <?php 
            the_content();
            ?>
                </div>
                <?php 
            $tags = get_the_term_list($post_id, 'dwqa-question_tag', '<span class="dwqa-tag">', '</span><span class="dwqa-tag">', '</span>');
            if (!empty($tags)) {
                ?>
                <div class="dwqa-tags"><?php 
                echo $tags;
                ?>
</div>
                <?php 
            }
            ?>
  <!-- Question Tags -->

                <footer class="dwqa-footer">
                    <div class="dwqa-author">
                        <?php 
            echo get_avatar($post->post_author, 32, false);
            ?>
                        <span class="author">
                            <?php 
            printf('<a href="%1$s" title="%2$s %3$s">%3$s</a>', get_author_posts_url(get_the_author_meta('ID')), __('Posts by', 'dwqa'), get_the_author_meta('display_name'));
            ?>
                        </span><!-- Author Info -->
                        <span class="dwqa-date">
                            <?php 
            printf('<a href="%s" title="%s #%d">%s %s</a>', get_permalink(), __('Link to', 'dwqa'), $post_id, __('asked', 'dwqa'), get_the_date());
            ?>
                        </span> <!-- Question Date -->
                        
                        
                        <div data-post="<?php 
            echo $post_id;
            ?>
" data-nonce="<?php 
            echo wp_create_nonce('_dwqa_update_privacy_nonce');
            ?>
" data-type="question" class="dwqa-privacy">
                            <input type="hidden" name="privacy" value="<?php 
            get_post_status();
            ?>
">
                            <span class="dwqa-current-privacy"> <?php 
            echo 'private' == get_post_status() ? '<i class="fa fa-lock"></i> ' . __('Private', 'dwqa') : '<i class="fa fa-globe"></i> ' . __('Public', 'dwqa');
            ?>
</span>
                            <?php 
            if (dwqa_current_user_can('edit_question') || dwqa_current_user_can('edit_answer') || $post->post_author == $current_user->ID) {
                ?>
                            <span class="dwqa-change-privacy">
                                <div class="dwqa-btn-group">
                                    <button type="button" class="dropdown-toggle" ><i class="fa fa-caret-down"></i></button>
                                    <div class="dwqa-dropdown-menu">
                                        <div class="dwqa-dropdown-caret">
                                            <span class="dwqa-caret-outer"></span>
                                            <span class="dwqa-caret-inner"></span>
                                        </div>
                                        <ul role="menu">
                                            <li title="<?php 
                _e('Everyone can see', 'dwqa');
                ?>
" data-privacy="publish" <?php 
                echo 'publish' == get_post_status() ? 'class="current"' : '';
                ?>
><a href="#"><i class="fa fa-globe"></i> <?php 
                _e('Public', 'dwqa');
                ?>
</a></li>
                                            <li title="<?php 
                _e('Only Author and Administrator can see', 'dwqa');
                ?>
" data-privacy="private" <?php 
                echo 'private' == get_post_status() ? 'class="current"' : '';
                ?>
><a href="#" ><i class="fa fa-lock"></i> <?php 
                _e('Private', 'dwqa');
                ?>
</a></li>
                                        </ul>
                                    </div>
                                </div>
                            </span>
                            <?php 
            }
            ?>
                        </div><!-- post status -->
                    </div>
                    <?php 
            $categories = wp_get_post_terms($post_id, 'dwqa-question_category');
            if (!empty($categories)) {
                $cat = $categories[0];
                ?>
                    <div class="dwqa-category">
                        <span class="dwqa-category-title"><?php 
                _e('Category', 'dwqa');
                ?>
</span>
                        <a class="dwqa-category-name" href="<?php 
                echo get_term_link($cat);
                ?>
" title="<?php 
                _e('All questions from', 'dwqa');
                ?>
 <?php 
                echo $cat->name;
                ?>
"><?php 
                echo $cat->name;
                ?>
</a>
                    </div>
                    <?php 
            }
            ?>
 <!-- Question Categories -->

                    <?php 
            $meta = get_post_meta($post_id, '_dwqa_status', true);
            if (!$meta) {
                $meta = 'open';
            }
            ?>
                    <div class="dwqa-current-status">
                        <span class="dwqa-status-title"><?php 
            _e('Status', 'dwqa');
            ?>
</span>
                        <span class="dwqa-status-name"><?php 
            echo $meta;
            ?>
</span>
                        <?php 
            if (dwqa_current_user_can('edit_question') || dwqa_current_user_can('edit_answer') || $current_user->ID == $post->post_author) {
                ?>
                        <span class="dwqa-change-status">
                            <div class="dwqa-btn-group">
                                <button type="button" class="dropdown-toggle" ><i class="fa fa-caret-down"></i></button>
                                <div class="dwqa-dropdown-menu" data-nonce="<?php 
                echo wp_create_nonce('_dwqa_update_question_status_nonce');
                ?>
" data-question="<?php 
                the_ID();
                ?>
" >
                                    <div class="dwqa-dropdown-caret">
                                        <span class="dwqa-caret-outer"></span>
                                        <span class="dwqa-caret-inner"></span>
                                    </div>
                                    <ul role="menu" data-nonce="<?php 
                echo wp_create_nonce('_dwqa_update_question_status_nonce');
                ?>
" data-question="<?php 
                the_ID();
                ?>
">
                                        <?php 
                if ('resolved' == $meta || 'pending' == $meta || 'closed' == $meta) {
                    ?>
                                            <li class="dwqa-re-open" data-status="re-open">
                                                <a href="#"><i class="fa fa-reply"></i> <?php 
                    _e('Re-Open', 'dwqa');
                    ?>
</a>
                                            </li>
                                        <?php 
                }
                ?>
                                        <?php 
                if ('closed' != $meta) {
                    ?>
                                            <li class="dwqa-closed" data-status="closed">
                                                <a href="#"><i class="fa fa-lock"></i> <?php 
                    _e('Closed', 'dwqa');
                    ?>
</a>
                                            </li>
                                        <?php 
                }
                ?>
                                        <?php 
                if ('pending' != $meta && 'closed' != $meta && current_user_can('edit_posts', $post_id)) {
                    ?>
                                            <li class="dwqa-pending"  data-status="pending">
                                                <a href="#"><i class="fa fa-question-circle"></i> <?php 
                    _e('Pending', 'dwqa');
                    ?>
</a>
                                            </li>
                                        <?php 
                }
                ?>
                                        <?php 
                if ('resolved' != $meta && 'closed' != $meta) {
                    ?>
                                            <li class="dwqa-resolved" data-status="resolved">
                                                <a href="#"><i class="fa fa-check-circle-o"></i> <?php 
                    _e('Resolved', 'dwqa');
                    ?>
</a>
                                            </li>
                                        <?php 
                }
                ?>
                                    </ul>
                                </div>
                            </div>
                        </span>
                        <?php 
            }
            ?>
 <!-- Change Question Status -->
                    </div>
                </footer>
                <div class="dwqa-comments">
                    <?php 
            comments_template();
            ?>
                </div>
            </article><!-- end question -->

            <div id="dwqa-answers">
                <?php 
            dwqa_load_template('answers');
            ?>
            </div><!-- end dwqa-add-answers -->
        </div><!-- end dwqa-single-question -->
    <?php 
        }
	<form name="dwqa-answer-form" id="dwqa-answer-form" method="post">
		<?php 
dwqa_print_notices();
?>
		<?php 
$content = isset($_POST['answer-content']) ? $_POST['answer-content'] : '';
?>
		<?php 
dwqa_init_tinymce_editor(array('content' => $content, 'textarea_name' => 'answer-content', 'id' => 'dwqa-answer-content'));
?>
		<?php 
dwqa_load_template('captcha', 'form');
?>

		<?php 
if (dwqa_current_user_can('post_answer') && !is_user_logged_in()) {
    ?>
		<p>
			<label for="user-email"><?php 
    _e('Your Email', 'dwqa');
    ?>
</label>
			<?php 
    $email = isset($_POST['user-email']) ? $_POST['user-email'] : '';
    ?>
			<input type="email" class="" name="user-email" value="<?php 
    echo $email;
    ?>
" >
		</p>
		<?php 
Exemplo n.º 15
0
 function remove_answer()
 {
     if (!isset($_POST['wpnonce']) || !wp_verify_nonce(esc_html($_POST['wpnonce']), '_dwqa_action_remove_answer_nonce') || !is_user_logged_in()) {
         wp_send_json_error(array('message' => __('Are you cheating huh?', 'dwqa')));
     }
     if (isset($_POST['answer_id'])) {
         $answer_id = intval($_POST['answer_id']);
     } else {
         wp_send_json_error(array('message' => __('Missing answer ID', 'dwqa')));
     }
     global $current_user;
     $answer_author = get_post_field('post_author', $answer_id);
     if (!(dwqa_current_user_can('delete_answer') || is_user_logged_in() && $answer_author == $current_user->ID)) {
         wp_send_json_error(array('message' => __('You do not have permission to edit this post', 'dwqa')));
     }
     if (get_post_type($answer_id) != 'dwqa-answer') {
         wp_send_json_error(array('message' => __('This post is not an answer', 'dwqa')));
     }
     $question_id = get_post_meta($answer_id, '_question', true);
     do_action('dwqa_delete_answer', $answer_id, $question_id);
     wp_delete_post($answer_id);
     wp_send_json_success(array('question' => $question_id, 'answer' => $answer_id));
 }
Exemplo n.º 16
0
            ?>
				<?php 
        }
        ?>
			<?php 
    }
    ?>
			<?php 
    wp_reset_postdata();
    ?>
		<?php 
    do_action('dwqa_after_answers_list');
    ?>
	</div>
	<?php 
}
?>
	<?php 
if (dwqa_current_user_can('post_answer') && !dwqa_is_closed(get_the_ID())) {
    ?>
		<?php 
    dwqa_load_template('answer', 'submit-form');
    ?>
	<?php 
}
?>
	<?php 
do_action('dwqa_after_answers');
?>
</div>
Exemplo n.º 17
0
 public function delete_question()
 {
     $valid_ajax = check_ajax_referer('_dwqa_delete_question', 'nonce', false);
     $nonce = isset($_POST['nonce']) ? esc_html($_POST['nonce']) : false;
     if (!$valid_ajax || !wp_verify_nonce($nonce, '_dwqa_delete_question') || !is_user_logged_in()) {
         wp_send_json_error(array('message' => __('Hello, Are you cheating huh?', 'dwqa')));
     }
     if (!isset($_POST['question'])) {
         wp_send_json_error(array('message' => __('Question is not valid', 'dwqa')));
     }
     $question = get_post(sanitize_text_field($_POST['question']));
     global $current_user;
     if (dwqa_current_user_can('delete_question', $question->ID)) {
         //Get all answers that is tired with this question
         do_action('before_delete_post', $question->ID);
         $delete = wp_delete_post($question->ID);
         if ($delete) {
             global $dwqa_options;
             do_action('dwqa_delete_question', $question->ID);
             wp_send_json_success(array('question_archive_url' => get_permalink($dwqa_options['pages']['archive-question'])));
         } else {
             wp_send_json_error(array('question' => $question->ID, 'message' => __('Delete Action was failed', 'dwqa')));
         }
     } else {
         wp_send_json_error(array('message' => __('You do not have permission to delete this question', 'dwqa')));
     }
 }
	

<?php 
if (!dwqa_current_user_can('read_question')) {
    ?>
<div class="alert"><?php 
    _e('You do not have permission to view questions', 'dwqa');
    ?>
</div>
<?php 
}
?>
<p class="not-found">
 	<?php 
_e('Sorry, but nothing matched your filter.', 'dwqa');
?>
    <?php 
if (is_user_logged_in()) {
    ?>
        <?php 
    dwqa_get_ask_question_link();
    ?>
    <?php 
} else {
    ?>
    	<?php 
    $register_link = wp_register('', '', false);
    printf('%s <a href="%s">%s</a> %s %s', __('Please', 'dwqa'), wp_login_url(get_post_type_archive_link('dwqa-question')), __('Login', 'dwqa'), !empty($register_link) && $register_link ? __(' or', 'dwqa') . ' ' . $register_link : '', __(' to submit question.', 'dwqa'));
    wp_login_form();
    ?>
    <?php 
Exemplo n.º 19
0
// Answer Page Naving
if ($answers->max_num_pages > 1) {
    $question_url = get_permalink($question_id);
    echo '<h3 class="dwqa-answers-page-navigation-head">' . sprintf(__('Answer page %d', 'dwqa'), $ans_cur_page) . '</h3>';
    echo '<ul class="dwqa-answers-page-navigation">';
    for ($i = 1; $i <= $answers->max_num_pages; $i++) {
        echo '<li class="' . ($ans_cur_page == $i ? 'active' : '') . '"><a href="' . esc_url(add_query_arg('ans-page', $i, $question_url)) . '">' . $i . '</a></li>';
    }
    echo '</ul>';
}
//Create answer form
if (dwqa_is_closed($question_id)) {
    echo '<p class="alert">' . __('This question is now closed', 'dwqa') . '</p>';
    return false;
}
if (dwqa_current_user_can('post_answer')) {
    dwqa_load_template('answer', 'submit-form');
} else {
    ?>
	<?php 
    if (is_user_logged_in()) {
        ?>
		<div class="alert"><?php 
        _e('You do not have permission to submit answer.', 'dwqa');
        ?>
</div>
	<?php 
    } else {
        ?>
	<h3 class="dwqa-title">
		<?php 
 public function prepare_archive_posts()
 {
     global $wpdb, $wp_query, $dwqa_general_settings;
     if (is_user_logged_in()) {
         $post_status = "'publish', 'private', 'pending'";
     } else {
         $post_status = "'publish'";
     }
     $query = "SELECT * FROM {$this->table} WHERE 1=1 AND post_status IN ( {$post_status} )";
     //Permisson
     if (is_user_logged_in() && !dwqa_current_user_can('edit_question')) {
         global $current_user;
         $query .= " AND IF( post_author = {$current_user->ID}, 1, IF( post_status = 'private', 0, 1 ) ) = 1";
     }
     $sticky_questions = get_option('dwqa_sticky_questions');
     if (is_array($sticky_questions)) {
         $sticky_questions = implode(',', $sticky_questions);
     }
     if ($sticky_questions) {
         $query .= " AND ID NOT IN ( {$sticky_questions} )";
     }
     if (is_tax('dwqa-question_category')) {
         $category = get_query_var('dwqa-question_category');
         $term = get_term_by('slug', $category, 'dwqa-question_category');
         $query .= " AND question_categories REGEXP '^{$term->term_id},|,{$term->term_id},|,{$term->term_id}\$|^{$term->term_id}\$' ";
     }
     if (is_tax('dwqa-question_tag')) {
         $tag = get_query_var('dwqa-question_tag');
         $term = get_term_by('slug', $tag, 'dwqa-question_tag');
         if ($term) {
             $query .= " AND question_tags REGEXP '^{$term->term_id},|,{$term->term_id},|,{$term->term_id}\$|^{$term->term_id}\$' ";
         }
     }
     $posts_per_page = isset($dwqa_general_settings['posts-per-page']) ? $dwqa_general_settings['posts-per-page'] : 5;
     $paged = get_query_var('paged');
     $offset = $paged ? ($paged - 1) * $posts_per_page : 0;
     $query .= " ORDER BY last_activity_date DESC LIMIT {$offset}, {$posts_per_page}";
     $questions = $wpdb->get_results($query);
     $this->temp = array('posts' => $wp_query->posts, 'post_count' => $wp_query->post_count);
     $wp_query->posts = $questions;
     $wp_query->post_count = count($questions);
     rewind_posts();
 }
Exemplo n.º 21
0
		<div class="dwqa-comment-actions">
			<?php 
if (dwqa_current_user_can('edit_comment')) {
    ?>
				<a href="<?php 
    echo esc_url(add_query_arg(array('comment_edit' => $comment->comment_ID)));
    ?>
"><?php 
    _e('Edit', 'dwqa');
    ?>
</a>
			<?php 
}
?>
			<?php 
if (dwqa_current_user_can('delete_comment')) {
    ?>
				<a class="dwqa-delete-comment" href="<?php 
    echo wp_nonce_url(add_query_arg(array('action' => 'dwqa-action-delete-comment', 'comment_id' => $comment->comment_ID), admin_url('admin-ajax.php')), '_dwqa_delete_comment');
    ?>
"><?php 
    _e('Delete', 'dwqa');
    ?>
</a>
			<?php 
}
?>
		</div>
	</div>
	<?php 
comment_text();
Exemplo n.º 22
0
}
?>

				<div data-post="<?php 
echo $answer_id;
?>
" data-nonce="<?php 
echo wp_create_nonce('_dwqa_update_privacy_nonce');
?>
" data-type="answer" class="dwqa-privacy">
				<input type="hidden" name="privacy" value="<?php 
get_post_status();
?>
">
				<?php 
if (get_post_status() != 'draft' && is_user_logged_in() && (dwqa_current_user_can('edit_answer') || $answer->post_author == $current_user->ID || $current_user->ID == $question->post_author)) {
    ?>
					<span class="dwqa-change-privacy">
						<div class="dwqa-btn-group">
							<button type="button" class="dropdown-toggle" ><span><?php 
    echo 'private' == get_post_status() ? '<i class="fa fa-lock"></i> ' . __('Private', 'dwqa') : '<i class="fa fa-globe"></i> ' . __('Public', 'dwqa');
    ?>
</span> <i class="fa fa-caret-down"></i></button>
							<div class="dwqa-dropdown-menu">
								<div class="dwqa-dropdown-caret">
									<span class="dwqa-caret-outer"></span>
									<span class="dwqa-caret-inner"></span>
								</div>
								<ul role="menu">
									<li title="<?php 
    _e('Everyone can see', 'dwqa');
function dwqa_question_meta_button($post_id = false)
{
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    ?>
	<div class="dwqa-meta">
		<div class="dwqa-vote" data-type="question" data-nonce="<?php 
    echo wp_create_nonce('_dwqa_question_vote_nonce');
    ?>
" data-question="<?php 
    echo $post_id;
    ?>
" >
			<a class="dwqa-vote-dwqa-btn dwqa-vote-up" data-vote="up" href="#"  title="<?php 
    _e('Vote Up', 'dwqa');
    ?>
"><?php 
    _e('Vote Up', 'dwqa');
    ?>
</a>
			<div class="dwqa-vote-count"><?php 
    $point = dwqa_vote_count();
    echo $point > 0 ? '+' . $point : $point;
    ?>
</div>
			<a class="dwqa-vote-dwqa-btn dwqa-vote-down" data-vote="down" href="#"  title="<?php 
    _e('Vote Down', 'dwqa');
    ?>
"><?php 
    _e('Vote Down', 'dwqa');
    ?>
</a>
		</div>
		
		<?php 
    dwqa_question_status_button($post_id);
    ?>

		<?php 
    dwqa_question_privacy_button($post_id);
    ?>

		<?php 
    $categories = wp_get_post_terms($post_id, 'dwqa-question_category');
    ?>
		<?php 
    if (!empty($categories)) {
        ?>
			<?php 
        $cat = $categories[0];
        ?>
		<div class="dwqa-category">
			<a class="dwqa-category-name" href="<?php 
        echo get_term_link($cat);
        ?>
" title="<?php 
        _e('All questions from', 'dwqa');
        ?>
 <?php 
        echo $cat->name;
        ?>
"><i class="fa fa-folder-open"></i> <?php 
        echo $cat->name;
        ?>
</a>
		</div>
		<?php 
    }
    ?>
 <!-- Question Categories -->

		<?php 
    dwqa_question_action_buttons($post_id);
    ?>

		<?php 
    if (is_user_logged_in()) {
        ?>
		<span data-post="<?php 
        echo $post_id;
        ?>
" data-nonce="<?php 
        echo wp_create_nonce('_dwqa_follow_question');
        ?>
" class="dwqa-favourite <?php 
        echo dwqa_is_followed($post_id) ? 'active' : '';
        ?>
" title="<?php 
        echo dwqa_is_followed($post_id) ? __('Unfollow This Question', 'dwqa') : __('Follow This Question', 'dwqa');
        ?>
"><!-- add class 'active' -->
			<span class="dwpa_follow"><?php 
        _e('follow', 'dwqa');
        ?>
</span>
			<span class="dwpa_following"><?php 
        _e('following', 'dwqa');
        ?>
</span>
			<span class="dwpa_unfollow"><?php 
        _e('unfollow', 'dwqa');
        ?>
</span>
		</span>
		<?php 
    }
    ?>

		<?php 
    if (dwqa_current_user_can('edit_question')) {
        ?>
		<span  data-post="<?php 
        echo $post_id;
        ?>
" data-nonce="<?php 
        echo wp_create_nonce('_dwqa_stick_question');
        ?>
" class="dwqa-stick-question <?php 
        echo dwqa_is_sticky($post_id) ? 'active' : '';
        ?>
" title="<?php 
        echo dwqa_is_sticky($post_id) ? __('Unpin this Question from the top', 'dwqa') : __('Pin this Question to top', 'dwqa');
        ?>
"><i class="fa fa-bookmark"></i></span>
		<?php 
    }
    ?>
	</div>
	<?php 
}
Exemplo n.º 24
0
 public function load_template($name, $extend = false, $include = true)
 {
     $check = true;
     if ($extend) {
         $name .= '-' . $extend;
     }
     if ($name == 'question-submit-form' && !dwqa_current_user_can('post_question')) {
         echo '<div class="alert">' . __('You do not have permission to submit a question', 'dwqa') . '</div>';
         return false;
     }
     $template = get_stylesheet_directory() . '/dwqa-templates/' . $name . '.php';
     if (!file_exists($template)) {
         $template = DWQA_DIR . 'templates/' . $name . '.php';
     }
     $template = apply_filters('dwqa-load-template', $template, $name);
     if (!file_exists($template)) {
         _doing_it_wrong(__FUNCTION__, sprintf("<strong>%s</strong> does not exists in <code>%s</code>.", $name, $template), '1.4.0');
         return false;
     }
     if (!$include) {
         return $template;
     }
     include $template;
 }
Exemplo n.º 25
0
 public function insert_question($args)
 {
     if (is_user_logged_in()) {
         $user_id = get_current_user_id();
     } elseif (dwqa_current_user_can('post_question')) {
         $user_id = 0;
     } else {
         return false;
     }
     $args = wp_parse_args($args, array('comment_status' => 'open', 'post_author' => $user_id, 'post_content' => '', 'post_status' => 'pending', 'post_title' => '', 'post_type' => 'dwqa-question'));
     $new_question = wp_insert_post($args, true);
     if (!is_wp_error($new_question)) {
         if (isset($args['tax_input'])) {
             foreach ($args['tax_input'] as $taxonomy => $tags) {
                 wp_set_post_terms($new_question, $tags, $taxonomy);
             }
         }
         update_post_meta($new_question, '_dwqa_status', 'open');
         update_post_meta($new_question, '_dwqa_views', 0);
         update_post_meta($new_question, '_dwqa_votes', 0);
         update_post_meta($new_question, '_dwqa_answers_count', 0);
         add_post_meta($new_question, '_dwqa_followers', $user_id);
         $date = get_post_field('post_date', $new_question);
         // dwqa_log_last_activity_on_question( $new_question, 'Create question', $date );
         //Call action when add question successfull
         do_action('dwqa_add_question', $new_question, $user_id);
     }
     return $new_question;
 }
Exemplo n.º 26
0
function dwqa_comment_action_add()
{
    global $current_user;
    if (!dwqa_current_user_can('post_comment')) {
        wp_send_json_error(array('message' => __('You can\'t post comment', 'dwqa')));
    }
    $args = array('comment_post_ID' => $_POST['comment_post_ID'], 'comment_content' => $_POST['content'], 'comment_parent' => $_POST['comment_parent']);
    if (is_user_logged_in()) {
        $args['user_id'] = $current_user->ID;
        $args['comment_author'] = $current_user->display_name;
    } else {
        if (!isset($_POST['email']) || !$_POST['email']) {
            wp_send_json_error(array('message' => __('Missing email infomation', 'dwqa')));
        }
        if (!isset($_POST['name']) || !$_POST['name']) {
            wp_send_json_error(array('message' => __('Missing name infomation', 'dwqa')));
        }
        $args['comment_author'] = isset($_POST['name']) ? $_POST['name'] : 'anonymous';
        $args['comment_author_email'] = $_POST['email'];
        $args['comment_author_url'] = isset($_POST['url']) ? $_POST['url'] : '';
        $args['user_id'] = -1;
    }
    $comment_id = wp_insert_comment($args);
    global $comment;
    $comment = get_comment($comment_id);
    ob_start();
    $args = array('walker' => null, 'max_depth' => '', 'style' => 'ol', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '');
    dwqa_question_comment_callback($comment, $args, 0);
    echo '</li>';
    $comment_html = ob_get_contents();
    ob_end_clean();
    do_action('dwqa_add_comment', $comment_id, $_POST['clientId']);
    wp_send_json_success(array('html' => $comment_html));
}
Exemplo n.º 27
0
 public function update_status()
 {
     if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field($_POST['nonce']), '_dwqa_update_question_status_nonce')) {
     }
     if (!isset($_POST['question'])) {
         wp_die(0);
     }
     if (!isset($_POST['status']) || !in_array(sanitize_text_field($_POST['status']), array('open', 're-open', 'resolved', 'closed', 'pending'))) {
         wp_die(0);
     }
     global $current_user;
     $question_id = intval($_POST['question']);
     $question = get_post($question_id);
     if (dwqa_current_user_can('edit_question') || $current_user->ID == $question->post_author) {
         $status = sanitize_text_field($_POST['status']);
         update_post_meta($question_id, '_dwqa_status', $status);
         if ($status == 'resolved') {
             update_post_meta($question_id, '_dwqa_resolved_time', time());
         }
     } else {
         wp_send_json_error(array('message' => __('You do not have permission to edit question status', 'dwqa')));
     }
 }
        $meta = get_post_meta($post_id, '_dwqa_status', true);
        if (!$meta) {
            $meta = 'open';
        }
        ?>
                        <div class="dwqa-current-status">
                            <span class="dwqa-status-title"><?php 
        _e('Status', 'dwqa');
        ?>
</span>
                            <span class="dwqa-status-name"><?php 
        echo $meta;
        ?>
</span>
                            <?php 
        if (dwqa_current_user_can('edit_question') || dwqa_current_user_can('edit_answer') || $current_user->ID == $post->post_author) {
            ?>
                            <span class="dwqa-change-status">
                                <div class="dwqa-btn-group">
                                    <button type="button" class="dropdown-toggle" ><i class="fa fa-caret-down"></i></button>
                                    <div class="dwqa-dropdown-menu" data-nonce="<?php 
            echo wp_create_nonce('_dwqa_update_question_status_nonce');
            ?>
" data-question="<?php 
            the_ID();
            ?>
" >
                                        <div class="dwqa-dropdown-caret">
                                            <span class="dwqa-caret-outer"></span>
                                            <span class="dwqa-caret-inner"></span>
                                        </div>
							<a href="#"><?php 
_e('Resolved', 'dwqa');
?>
</a>
						</li>
						<li class="<?php 
echo $selected == 'closed' ? 'active' : '';
?>
 status-closed" data-type="closed">
							<a href="#"><?php 
_e('Closed', 'dwqa');
?>
</a>
						</li>
						<?php 
if (dwqa_current_user_can('edit_question')) {
    ?>
						<li class="<?php 
    echo $selected == 'overdue' ? 'active' : '';
    ?>
 status-overdue" data-type="overdue"><a href="#"><?php 
    _e('Overdue', 'dwqa');
    ?>
</a></li>
						<li class="<?php 
    echo $selected == 'pending-review' ? 'active' : '';
    ?>
 status-pending-review" data-type="pending-review"><a href="#"><?php 
    _e('Queue', 'dwqa');
    ?>
</a></li>
Exemplo n.º 30
0
 /**
  * Update question status when have new answer
  */
 public function dwqa_auto_change_question_status($answer_id)
 {
     if (!is_wp_error($answer_id)) {
         $question_id = get_post_meta($answer_id, '_question', true);
         $answer = get_post($answer_id);
         if ($question_id && $answer->post_author) {
             $question_status = get_post_meta($question_id, '_dwqa_status', true);
             if (dwqa_current_user_can('edit_question')) {
                 update_post_meta($question_id, '_dwqa_status', 'answered');
             } else {
                 if ($question_status == 'resolved' || $question_status == 'answered') {
                     update_post_meta($question_id, '_dwqa_status', 're-open');
                 }
             }
         }
     }
 }