Example #1
0
/**
*
* TEMPLATE FILTER QUESTIONS FOR MOBILE
* @author ThaiNT
* @since 1.0
*
**/
function qa_mobile_submit_questions_form()
{
    $privi = qa_get_privileges();
    ?>
	<section class="post-question-form-wrapper">
		<form id="submit_question" action="">
		<input type="hidden" id="qa_nonce" name="qa_nonce" value="<?php 
    echo wp_create_nonce('insert_question');
    ?>
">
		<input id="add_tag_text" type="hidden" value="<?php 
    printf(__("You must have %d points to add tag. Current, you have to select existed tags.", ET_DOMAIN), $privi->create_tag);
    ?>
" />
		<div class="container">
	        <div class="row">
	        	<div class="col-md-12">
	                	<div class="form-post">
	                		<input type="text" name="post_title" id="question_title" placeholder="<?php 
    _e("Your Question", ET_DOMAIN);
    ?>
">
	                    </div>
	                    <div class="form-post">
	                        <div class="select-categories-wrapper">
	                            <div class="select-categories">
	                                <select class="select-grey-bg" id="" name="question_category">
										<option value=""><?php 
    _e("Select Category", ET_DOMAIN);
    ?>
</option>
										<?php 
    $terms = get_terms('question_category', array('hide_empty' => 0));
    foreach ($terms as $term) {
        ?>
										<option value="<?php 
        echo $term->slug;
        ?>
"><?php 
        echo $term->name;
        ?>
</option>
										<?php 
    }
    ?>
	                                </select>
	                            </div>
	                        </div>
	                    </div>
	                    <div class="form-post">
	                    	<textarea name="post_content" id="" cols="30" rows="10" placeholder="<?php 
    _e("Your Description", ET_DOMAIN);
    ?>
"></textarea>
	                    </div>
	                    <div class="form-post">
	                    	<input  data-provide="typeahead" type="text" name="" id="question_tags" placeholder="<?php 
    _e('Tag(max 5 tags)', ET_DOMAIN);
    ?>
" />
	                    </div>
	                    <ul class="post-question-tags" id="tag_list"></ul>
	            </div>
	        </div>
	    </div>
	    <div class="group-btn-post">
	    	<div class="container">
	            <div class="row">
	                <div class="col-xs-5"><span class="text"><?php 
    _e("Ask a Question", ET_DOMAIN);
    ?>
</span></div>
	                <div class="col-xs-7 text-right">
	                	<button type="submit" class="submit-post-question"><?php 
    _e("Submit", ET_DOMAIN);
    ?>
</button>
	                    <a href="javascript:void(0)" class="cancel-post-question"><?php 
    _e("Cancel", ET_DOMAIN);
    ?>
</a>
	                </div>
	            </div>
	        </div>
	    </div>
		</form>
	</section>
	<?php 
}
Example #2
0
 /**
  * update_answer
  */
 public static function update($data)
 {
     global $current_user;
     if (isset($data['post_author']) && $current_user->ID != $data['post_author'] && !qa_user_can('edit_answer')) {
         // check user cap with edit answer
         /**
          * get site privileges
          */
         $privileges = qa_get_privileges();
         return new WP_Error('cannot_edit', sprintf(__("You must have %d points to edit answer.", ET_DOMAIN), $privileges->edit_answer));
     }
     $instance = self::get_instance();
     $result = $instance->_update($data);
     return $result;
 }
Example #3
0
<?php

/**
 * Template Name: Badges List Template
 * version 1.0
 * @author: enginethemes
 **/
get_header();
$badge_points = qa_get_badge_point();
$levels = qa_get_privileges();
?>
    <?php 
get_sidebar('left');
?>
    <div class="col-md-8 main-content">
        <div class="row select-category">
            <div class="col-md-12 current-category">
                <span><?php 
_e("Badges", ET_DOMAIN);
?>
</span>
            </div>          
        </div><!-- END SELECT-CATEGORY -->
        <div class="row points-system">
            <div class="col-md-12">
                <h3><?php 
_e("Points System", ET_DOMAIN);
?>
</h3>
                <p><?php 
_e("You earn reputation when people vote on your posts", ET_DOMAIN);
Example #4
0
global $post, $qa_answer, $qa_question, $current_user;
if ($post->post_type == 'question') {
    $object = $qa_question;
} else {
    $object = $qa_answer;
}
$vote_up_class = 'action vote vote-up img-circle ';
$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 -->
Example #5
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 
}
Example #6
0
/**
 * get all user qa caps base on user point
 * @return array 
*/
function qa_get_user_caps()
{
    global $user_ID;
    $cap = array();
    if ($user_ID) {
        $privileges = qa_get_privileges();
        $user_point = qa_get_user_point($user_ID);
        foreach ($privileges as $privi => $point) {
            if ($point > $user_point && !current_user_can('manage_options')) {
                continue;
            }
            $cap[$privi] = true;
        }
        if (current_user_can('manage_options')) {
            $cap['edit'] = true;
        }
    }
    return $cap;
}
Example #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 = QA_Questions::convert(get_post($_POST['post_parent']));
                 $answerID = $action == "accept-answer" ? $_POST['ID'] : 0;
                 // Get user point
                 $user = QA_Member::convert($current_user);
                 $user_point = $user->qa_point;
                 // Get badges
                 $levels = qa_get_privileges();
                 $approve_answer = $levels->approve_answer;
                 if ($question->et_best_answer == "0") {
                     if ($current_user->ID == $question->post_author || $user_point > $approve_answer) {
                         QA_Questions::mark_answer($_POST['post_parent'], $answerID);
                         do_action('qa_accept_answer', $answerID, $action);
                         $resp = array('success' => true);
                     } else {
                         throw new Exception(__("You don't have enough point to approve answer.", ET_DOMAIN));
                         return false;
                     }
                 } elseif ($question->et_best_answer != "0") {
                     if ($current_user->ID == $question->post_author) {
                         QA_Questions::mark_answer($_POST['post_parent'], $answerID);
                         do_action('qa_accept_answer', $answerID, $action);
                         $resp = array('success' => true);
                     } else {
                         throw new Exception(__("Only author has right to change the best answer.", ET_DOMAIN));
                         return false;
                     }
                 } else {
                     // throw new Exception(__("Only author has right to change the best answer.", ET_DOMAIN));
                     // return false;
                 }
                 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']);
                 do_action('qa_before_save_question', $data);
                 $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;
 }