Ejemplo n.º 1
0
 /**
  * Additional methods in theme
  */
 public static function insert_answer($question_id, $content, $author = false, $answer_id = 0)
 {
     $instance = self::get_instance();
     global $current_user;
     if (!$current_user->ID) {
         return new WP_Error('logged_in_required', __('Login Required', ET_DOMAIN));
     }
     if ($author == false) {
         $author = $current_user->ID;
     }
     $question = get_post($question_id);
     $content = preg_replace('/\\[quote\\].*(<br\\s*\\/?>\\s*).*\\[\\/quote\\]/', '', $content);
     $data = array('post_title' => 'RE: ' . $question->post_title, 'post_content' => $content, 'post_parent' => $question_id, 'author' => $author, 'post_type' => 'answer', 'post_status' => ae_get_option('pending_answers') && !(current_user_can('manage_options') || qa_user_can('approve_answer')) ? 'pending' : 'publish', 'et_answer_parent' => $answer_id);
     $result = $instance->_insert($data);
     // if item is inserted successfully, update statistic
     if ($result) {
         //update user answers count
         $count = et_count_user_posts($current_user->ID, 'answer');
         update_user_meta($current_user->ID, 'et_answer_count', $count);
         //update user following questions
         $follow_questions = (array) get_user_meta($current_user->ID, 'qa_following_questions', true);
         if (!in_array($question_id, $follow_questions)) {
             array_push($follow_questions, $question_id);
         }
         $follow_questions = array_unique(array_filter($follow_questions));
         update_user_meta($current_user->ID, 'qa_following_questions', $follow_questions);
         // update question's update date
         update_post_meta($question_id, 'et_updated_date', current_time('mysql'));
         // update last update author
         update_post_meta($question_id, 'et_last_author', $author);
         // update answer_authors
         $answer_authors = get_post_meta($question_id, 'et_answer_authors', true);
         $answer_authors = is_array($answer_authors) ? $answer_authors : array();
         if (!in_array($author, $answer_authors)) {
             $answer_authors[] = $author;
             update_post_meta($question_id, 'et_answer_authors', $answer_authors);
         }
         // update answer author for answer
         if ($answer_id) {
             $answer_authors = get_post_meta($answer_id, 'et_answer_authors', true);
             $answer_authors = is_array($answer_authors) ? $answer_authors : array();
             if (!in_array($author, $answer_authors)) {
                 $answer_authors[] = $author;
                 update_post_meta($answer_id, 'et_answer_authors', $answer_authors);
             }
         }
         if ($answer_id == 0) {
             QA_Questions::count_comments($question->ID);
         } else {
             QA_Answers::count_comments($answer_id);
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
        </div><!-- END SELECT-CATEGORY -->
        <div id="question_content" class="row question-main-content question-item" data-id="<?php 
echo $post->ID;
?>
">
            <!-- Vote section -->
            <?php 
get_template_part('template/item', 'vote');
?>
            <!--// Vote section -->
            <div class="col-md-9 col-xs-9 q-right-content">

                <!-- admin control -->
                <ul class="post-controls">
                    <?php 
if ($current_user->ID == $qa_question->post_author || qa_user_can('edit_question')) {
    ?>
                    <li>
                        <a href="javascript:void(0)" data-toggle="tooltip" data-original-title="<?php 
    _e("Edit", ET_DOMAIN);
    ?>
" data-name="edit" class="post-edit action">
                            <i class="fa fa-pencil"></i>
                        </a>
                    </li>
                    <?php 
}
?>
                    <?php 
if (current_user_can('manage_options')) {
    ?>
Ejemplo n.º 3
0
$vote_up_class .= $object->voted_up ? 'active' : '';
$vote_up_class .= $object->voted_down ? 'disabled' : '';
$vote_down_class = 'action vote vote-down img-circle ';
$vote_down_class .= $object->voted_down ? 'active' : '';
$vote_down_class .= $object->voted_up ? 'disabled' : '';
/**
 * check privileges
 */
$privi = qa_get_privileges();
$vote_up_prover = '';
$vote_down_prover = '';
if (!qa_user_can('vote_up') && isset($privi->vote_up)) {
    $content = sprintf(__("You must have %d points to vote up.", ET_DOMAIN), $privi->vote_up);
    $vote_up_prover = 'data-container="body" data-toggle="popover" data-content="' . $content . '"';
}
if (!qa_user_can('vote_down') && isset($privi->vote_down)) {
    $content = sprintf(__("You must have %d points to vote down.", ET_DOMAIN), $privi->vote_down);
    $vote_down_prover = ' data-container="body" data-toggle="popover" data-content="' . $content . '"';
}
?>
<div class="col-md-2 col-xs-2 vote-block">
	<!-- vote group -->
    <ul>
        <!-- vote up -->
        <li title="<?php 
_e("This is useful.", ET_DOMAIN);
?>
">
        	<a <?php 
echo $vote_up_prover;
?>
Ejemplo n.º 4
0
function qa_comment_form($post, $type = 'question')
{
    global $current_user;
    /**
     * check privileges
     */
    $privi = qa_get_privileges();
    $comment_prover = '';
    if (!qa_user_can('add_comment') && isset($privi->add_comment)) {
        $content = sprintf(__("You must have %d points to add comment.", ET_DOMAIN), $privi->add_comment);
        $comment_prover = 'data-container="body" data-toggle="popover" data-content="' . $content . '"';
    }
    ?>
	<a <?php 
    echo $comment_prover;
    ?>
 class="add-comment" data-id="<?php 
    echo $post->ID;
    ?>
" href="javascript:void(0)"><?php 
    _e("Add Comment", ET_DOMAIN);
    ?>
</a>
    <div class="clearfix"></div>
    <form class="child-reply" method="POST">
        <input type="hidden" name="qa_nonce"        value="<?php 
    echo wp_create_nonce('insert_comment');
    ?>
" />
        <input type="hidden" name="comment_post_ID" value="<?php 
    echo $post->ID;
    ?>
" />
        <input type="hidden" name="comment_type"    value="<?php 
    echo $type;
    ?>
" />
        <input type="hidden" name="user_id"         value="<?php 
    echo $current_user->ID;
    ?>
" />
        <div id="editor_wrap_<?php 
    echo $post->ID;
    ?>
" class="child-answer-wrap collapse">
            <div class="wp-editor-container">
                <textarea name="post_content" id="insert_answer_<?php 
    echo $post->ID;
    ?>
"></textarea>
            </div>
            <div class="row submit-wrapper">
                <div class="col-md-3 col-xs-3">
                    <button id="submit_reply" class="btn-submit">
                        <?php 
    _e("Add comment", ET_DOMAIN);
    ?>
                    </button>
                </div>
                <div class="col-md-9 col-xs-9">
                    <a href="javascript:void(0)" class="hide-comment"><?php 
    _e("Cancel", ET_DOMAIN);
    ?>
</a>
                </div>
            </div>
        </div>
    </form><!-- END SUBMIT FORM COMMENT -->

<?php 
}
Ejemplo n.º 5
0
function qa_comment_vote($id, $comment)
{
    global $user_ID;
    /**
     * get site qa badge point system
     */
    $point = qa_get_badge_point();
    /**
     * get comment post
     */
    $post = get_post($comment->comment_post_ID);
    /**
     * user can not vote for him self
     */
    if ($user_ID == $post->post_author) {
        return false;
    }
    // $change_log = QA_Log::get_instance();
    switch ($comment->comment_type) {
        case 'vote_up':
            /*
             * return false if user can not vote up
             */
            if (!qa_user_can('vote_up')) {
                return false;
            }
            if ($post->post_type == 'answer') {
                $vote_up_point = $point->a_vote_up;
            } else {
                $vote_up_point = $point->q_vote_up;
            }
            /**
             * save point to comment, keep it to restore point to user if  the vote be undo
             */
            update_comment_meta($comment->comment_ID, 'qa_point', $vote_up_point);
            /**
             * updte user point
             */
            qa_update_user_point($post->post_author, $vote_up_point);
            /**
             * do action qa point vote up
             * @param $post the post be voted
             * @param $vote_up_point
             */
            do_action('qa_point_vote_up', $post, $vote_up_point);
            break;
        case 'vote_down':
            // return false if user can not vote down
            if (!qa_user_can('vote_down')) {
                return false;
            }
            if ($post->post_type == 'answer') {
                $vote_down_point = $point->a_vote_down;
            } else {
                $vote_down_point = $point->q_vote_down;
            }
            /**
             * save point to comment, keep it to restore point to user if  the vote be undo
             */
            update_comment_meta($comment->comment_ID, 'qa_point', $vote_down_point);
            /**
             * updte user point
             */
            qa_update_user_point($post->post_author, $vote_down_point);
            /**
             * update point to current user when he/she vote down a question/answer
             */
            qa_update_user_point($user_ID, $point->vote_down);
            /**
             * do action qa point vote down
             * @param $post the post be voted
             * @param $vote_down_point
             */
            do_action('qa_point_vote_down', $post, $vote_down_point);
            break;
    }
}
Ejemplo n.º 6
0
        <?php 
//answer status is pending & current user is admin
if ($qa_answer->post_status == "pending" && (current_user_can('manage_options') || qa_user_can('approve_answer'))) {
    ?>
        <li>
            <a href="javascript:void(0);" data-toggle="tooltip" data-original-title="<?php 
    _e("Approve", ET_DOMAIN);
    ?>
" data-name="approve" class="post-edit action">
                <i class="fa fa-check"></i>
            </a>
        </li>
        <?php 
}
// user can control option or have qa cap edit question/answer
if ($current_user->ID == $qa_answer->post_author || current_user_can('manage_options') || qa_user_can('edit_answer')) {
    ?>
        <li>
            <a href="javascript:void(0);" data-toggle="tooltip" data-original-title="<?php 
    _e("Edit", ET_DOMAIN);
    ?>
" data-name="edit" class="post-edit action">
                <i class="fa fa-pencil"></i>
            </a>
        </li>
        <?php 
}
?>
        <?php 
if ($current_user->ID == $qa_answer->post_author || current_user_can('manage_options')) {
    ?>
Ejemplo n.º 7
0
 public function update_post()
 {
     try {
         global $current_user;
         if (!isset($_POST['do_action'])) {
             throw new Exception(__("Invalid action", ET_DOMAIN));
         }
         if (isset($_POST['content']['post_title']) && $_POST['content']['post_title'] != strip_tags($_POST['content']['post_title'])) {
             throw new Exception(__("Post title should not contain any HTML Tag.", ET_DOMAIN));
         }
         $action = $_POST['do_action'];
         switch ($action) {
             case 'vote_down':
                 if (!qa_user_can('vote_down')) {
                     throw new Exception(__("You don't have enough point to vote up.", ET_DOMAIN));
                 }
             case 'vote_up':
                 if (!qa_user_can('vote_up')) {
                     throw new Exception(__("You don't have enough point to vote down.", ET_DOMAIN));
                 }
                 QA_Questions::vote($_POST['ID'], $action);
                 $post = QA_Questions::convert(get_post($_POST['ID']));
                 $resp = array('success' => true, 'data' => $post);
                 break;
             case 'accept-answer':
             case 'un-accept-answer':
                 $question = get_post($_POST['post_parent']);
                 $answerID = $action == "accept-answer" ? $_POST['ID'] : 0;
                 if ($current_user->ID != $question->post_author) {
                     throw new Exception(__("Only question author can mark answered.", ET_DOMAIN));
                     return false;
                 }
                 QA_Questions::mark_answer($_POST['post_parent'], $answerID);
                 do_action('qa_accept_answer', $answerID, $action);
                 $resp = array('success' => true);
                 break;
             case 'saveComment':
                 $data = array();
                 $data['comment_ID'] = $_POST['comment_ID'];
                 $data['comment_content'] = $_POST['comment_content'];
                 $success = QA_Comments::update($data);
                 $comment = QA_Comments::convert(get_comment($_POST['comment_ID']));
                 $resp = array('success' => true, 'data' => $comment);
                 break;
             case 'savePost':
                 $data = array();
                 $data['ID'] = $_POST['ID'];
                 $data['post_content'] = $_POST['post_content'];
                 $data['post_author'] = $_POST['post_author'];
                 $success = QA_Answers::update($data);
                 $post = QA_Answers::convert(get_post($_POST['ID']));
                 if ($success && !is_wp_error($success)) {
                     $resp = array('success' => true, 'data' => $post);
                 } else {
                     $resp = array('success' => false, 'data' => $post, 'msg' => $success->get_error_message());
                 }
                 break;
             case 'saveQuestion':
                 $data = $_POST['content'];
                 $data['ID'] = $_POST['ID'];
                 $data['qa_tag'] = isset($data['tags']) ? $data['tags'] : array();
                 $data['post_author'] = $_POST['post_author'];
                 unset($data['tags']);
                 $success = QA_Questions::update($data);
                 $post = QA_Questions::convert(get_post($_POST['ID']));
                 if ($success && !is_wp_error($success)) {
                     $resp = array('success' => true, 'data' => $post, 'msg' => __('Question has been saved successfully.', ET_DOMAIN), 'redirect' => get_permalink($_POST['ID']));
                 } else {
                     $resp = array('success' => false, 'data' => $post, 'msg' => $success->get_error_message());
                 }
                 break;
             case 'approve':
                 $id = $_POST['ID'];
                 $success = QA_Questions::change_status($id, "publish");
                 $post = QA_Questions::convert(get_post($id));
                 $point = qa_get_badge_point();
                 //store question id to data for send mail
                 QA_Engine::qa_questions_new_answer($id);
                 if ($success && !is_wp_error($success)) {
                     if ($post->post_type == "question") {
                         //add points to user
                         if (!empty($point->create_question)) {
                             qa_update_user_point($post->post_author, $point->create_question);
                         }
                         // set transient for new question
                         set_transient('qa_notify_' . mt_rand(100000, 999999), array('title' => __('New Question', ET_DOMAIN), 'content' => __("There's a new post, why don't you give a look at", ET_DOMAIN) . ' <a href ="' . get_permalink($id) . '">' . get_the_title($id) . '</a>', 'type' => 'update', 'user' => md5($current_user->user_login)), 20);
                         $resp = array('success' => true, 'data' => $post, 'msg' => __("You've just successfully approved a question.", ET_DOMAIN), 'redirect' => get_permalink($id));
                     } else {
                         if ($post->post_type == "answer") {
                             //add point to user
                             if (!empty($point->post_answer)) {
                                 qa_update_user_point($post->post_author, $point->post_answer);
                             }
                             $resp = array('success' => true, 'data' => $post, 'msg' => __("You've just successfully approved an answer.", ET_DOMAIN), 'redirect' => get_permalink($id));
                         }
                     }
                 } else {
                     $resp = array('success' => false, 'data' => $post, 'msg' => $success->get_error_message());
                 }
                 break;
             case 'follow':
             case 'unfollow':
                 if (!$current_user->ID) {
                     throw new Exception(__('Login required', ET_DOMAIN));
                 }
                 $result = QA_Questions::toggle_follow($_POST['ID'], $current_user->ID);
                 if (!is_array($result)) {
                     throw new Exception(__('Error occurred', ET_DOMAIN));
                 }
                 if (in_array($current_user->ID, $result)) {
                     $msg = __('You have started following this question.', ET_DOMAIN);
                 } else {
                     $msg = __('You have stopped following this question.', ET_DOMAIN);
                 }
                 $resp = array('success' => true, 'msg' => $msg, 'data' => array('isFollow' => in_array($current_user->ID, $result), 'following' => $result));
                 break;
             case 'report':
                 $id = $_POST['ID'];
                 if (!isset($_POST) || !$id) {
                     throw new Exception(__("Invalid post", ET_DOMAIN));
                 } else {
                     $fl = $this->report($id, $_POST['data']['message']);
                     if ($fl) {
                         $resp = array('success' => true, 'msg' => __("You have reported successfully", ET_DOMAIN));
                     } else {
                         $resp = array('success' => false, 'msg' => __("Error when reported!", ET_DOMAIN));
                     }
                 }
                 break;
             default:
                 throw new Exception(__("Invalid action", ET_DOMAIN));
                 break;
         }
     } catch (Exception $e) {
         $resp = array('success' => false, 'msg' => $e->getMessage());
     }
     return $resp;
 }
Ejemplo n.º 8
0
        </div><!-- END SELECT-CATEGORY -->
        <div id="question_content" class="row question-main-content question-item" data-id="<?php 
echo $post->ID;
?>
">
            <!-- Vote section -->
            <?php 
get_template_part('template/item', 'vote');
?>
            <!--// Vote section -->
            <div class="col-md-9 col-xs-9 q-right-content">

                <!-- admin control -->
                <ul class="post-controls">
                    <?php 
if (qa_user_can('edit_question')) {
    ?>
                    <li>
                        <a href="javascript:void(0)" data-name="edit" class="post-edit action">
                            <i class="fa fa-pencil"></i>
                        </a>
                    </li>
                    <?php 
}
?>
                    <?php 
if (current_user_can('manage_options')) {
    ?>
                    <li>
                        <a href="javascript:void(0)" data-name="delete" class="post-delete action" >
                            <i class="fa fa-trash-o"></i>