示例#1
0
 public function init_theme()
 {
     global $wp_rewrite;
     // post type
     QA_Questions::init();
     QA_Answers::init();
     QA_Member::init();
     if (ae_get_option('twitter_login', false)) {
         new ET_TwitterAuth();
     }
     if (ae_get_option('facebook_login', false)) {
         new ET_FaceAuth();
     }
     if (ae_get_option('gplus_login', false)) {
         new ET_GoogleAuth();
     }
     /**
      * new class QA_PackAction to control all action do with user badge
      */
     $qa_pack = new QA_PackAction();
     // register footer menu
     register_nav_menus(array('et_header' => __('Menu display on Header', ET_DOMAIN), 'et_left' => __('Menu display on Left Sidebar', ET_DOMAIN)));
     //sidebars
     register_sidebar(array('name' => __('Left Sidebar', ET_DOMAIN), 'id' => 'qa-left-sidebar', 'description' => __("Display widgets in left sidebar", ET_DOMAIN)));
     register_sidebar(array('name' => __('Right Sidebar', ET_DOMAIN), 'id' => 'qa-right-sidebar', 'description' => __("Display widgets in right sidebar", ET_DOMAIN)));
     //header sidebars
     register_sidebar(array('name' => __('Header Sidebar', ET_DOMAIN), 'id' => 'qa-header-sidebar', 'description' => __("Display widgets in header sidebar", ET_DOMAIN)));
     //blog sidebars
     register_sidebar(array('name' => __('Blog\'s Left Sidebar', ET_DOMAIN), 'id' => 'qa-blog-left-sidebar', 'description' => __("Display widgets in blog's left sidebar", ET_DOMAIN)));
     register_sidebar(array('name' => __('Blog\'s Right Sidebar', ET_DOMAIN), 'id' => 'qa-blog-right-sidebar', 'description' => __("Display widgets in blog's right sidebar", ET_DOMAIN)));
     add_theme_support('automatic-feed-links');
     $author_slug = apply_filters('qa_member_slug', 'member');
     // change slug name
     $wp_rewrite->author_base = $author_slug;
     /**
      * create post type report
      */
     $args = array('labels' => array('name' => __('Reports', ET_DOMAIN), 'singular_name' => __('Report', ET_DOMAIN), 'add_new' => __('Add New', ET_DOMAIN), 'add_new_item' => __('Add New Report', ET_DOMAIN), 'edit_item' => __('Edit Report', ET_DOMAIN), 'new_item' => __('New Report', ET_DOMAIN), 'all_items' => __('All Reports', ET_DOMAIN), 'view_item' => __('View Report', ET_DOMAIN), 'search_items' => __('Search Reports', ET_DOMAIN), 'not_found' => __('No Reports found', ET_DOMAIN), 'not_found_in_trash' => __('No Reports found in Trash', ET_DOMAIN), 'parent_item_colon' => '', 'menu_name' => __('Reports', ET_DOMAIN)), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array('slug' => 'report'), 'capability_type' => 'post', 'has_archive' => 'reports', 'hierarchical' => false, 'menu_position' => null, 'supports' => array('title', 'editor', 'author'), 'taxonomies' => array('report-taxonomy'));
     register_post_type('report', $args);
     $tax_labels = array('name' => _x('Reports taxonomy', ET_DOMAIN), 'singular_name' => _x('Report taxonomys', ET_DOMAIN), 'search_items' => __('Search Reports', ET_DOMAIN), 'popular_items' => __('Popular Reports', ET_DOMAIN), 'all_items' => __('All Reports', ET_DOMAIN), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __('Edit Report', ET_DOMAIN), 'update_item' => __('Update Report', ET_DOMAIN), 'add_new_item' => __('Add New Report', ET_DOMAIN), 'new_item_name' => __('New Report Name', ET_DOMAIN), 'separate_items_with_commas' => __('Separate Reports with commas', ET_DOMAIN), 'add_or_remove_items' => __('Add or remove Reports', ET_DOMAIN), 'choose_from_most_used' => __('Choose from the most used Reports', ET_DOMAIN), 'not_found' => __('No Reports found.', ET_DOMAIN), 'menu_name' => __('Reports taxonomy', ET_DOMAIN));
     $tax_args = array('hierarchical' => true, 'labels' => $tax_labels, 'show_ui' => true, 'show_admin_column' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'rewrite' => array('slug' => 'Report-taxonomy'));
     register_taxonomy('report-taxonomy', 'report', $tax_args);
 }
示例#2
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;
 }
<?php

global $post;
$answer = QA_Answers::convert($post);
$question = QA_Questions::convert(get_post($answer->post_parent));
$et_post_date = et_the_time(strtotime($answer->post_date));
$badge_points = qa_get_badge_point();
$category = !empty($question->question_category[0]) ? $question->question_category[0]->name : __('No Category', ET_DOMAIN);
$category_link = !empty($question->question_category[0]) ? get_term_link($question->question_category[0]->term_id, 'question_category') : '#';
?>
<li <?php 
post_class('answer-item question-item pending-question');
?>
 data-id="<?php 
echo $post->ID;
?>
">
    <div class="col-md-8 q-left-content">
        <div class="q-ltop-content title-answer-style">
            <a href="<?php 
echo get_permalink($question->ID);
?>
" class="question-title">
                <?php 
the_title();
?>
            </a>
        </div>
        <div class="q-lbtm-content">
            <div class="question-cat">
                <span class="author-avatar">
示例#4
0
/**
*
* TEMPLATE LOOP FOR ANSWERS
* @param array $answers
* @author ThaiNT
* @since 1.0
*
**/
function qa_answers_loop()
{
    global $post, $wp_rewrite, $current_user, $qa_question;
    $question_ID = $post->ID;
    $answersData = array();
    $commentsData = array();
    $question = QA_Questions::convert(get_post($question_ID));
    $qa_question = $question;
    $paged = get_query_var('page') ? get_query_var('page') : 1;
    $reply_args = array('post_type' => 'answer', 'post_parent' => $post->ID, 'paged' => $paged);
    //show pending answer if current user is admin
    if (is_user_logged_in() && (qa_user_can('approve_answer') || current_user_can('manage_options'))) {
        $reply_args['post_status'] = array('publish', 'pending');
    }
    if (isset($_GET['sort']) && $_GET['sort'] == "oldest") {
        $reply_args['order'] = 'ASC';
    } else {
        add_filter("posts_join", array("QA_Front", "_post_vote_join"));
        add_filter("posts_orderby", array("QA_Front", "_post_vote_orderby"));
    }
    $replyQuery = new WP_Query($reply_args);
    ?>
	<!-- ANSWERS LOOP -->
	<div id="answers_main_list">
		<?php 
    if ($replyQuery->have_posts()) {
        while ($replyQuery->have_posts()) {
            $replyQuery->the_post();
            global $post, $qa_answer, $qa_answer_comments;
            $qa_answer = QA_Answers::convert($post);
            $answersData[] = $qa_answer;
            $qa_answer_comments = get_comments(array('post_id' => $qa_answer->ID, 'parent' => 0, 'status' => 'approve', 'post_status' => 'publish', 'order' => 'ASC', 'type' => 'answer'));
            $commentsData = array_merge($commentsData, $qa_answer_comments);
            ?>
			<div class="row question-main-content question-item answer-item" id="<?php 
            echo $qa_answer->ID;
            ?>
">
			    <?php 
            get_template_part('template/item', 'answer');
            ?>
			</div><!-- END REPLY-ITEM -->
			<?php 
        }
    }
    wp_reset_query();
    ?>
	</div>
	<!-- ANSWERS LOOP -->
	<div class="row paginations <?php 
    echo $replyQuery->max_num_pages > 1 ? '' : 'collapse';
    ?>
">
	    <div class="col-md-12">
	        <?php 
    echo paginate_links(array('base' => get_permalink($question_ID) . '%#%', 'format' => $wp_rewrite->using_permalinks() ? 'page/%#%' : '?paged=%#%', 'current' => max(1, $paged), 'total' => $replyQuery->max_num_pages, 'mid_size' => 1, 'prev_text' => '<', 'next_text' => '>', 'type' => 'list'));
    ?>
	    </div>
	</div><!-- END PAGINATIONS -->
	<script type="text/javascript">
		<?php 
    $parent_comments = get_comments(array('post_id' => $question_ID, 'parent' => 0, 'status' => 'approve', 'post_status' => 'publish', 'order' => 'ASC', 'type' => 'question'));
    $commentsData = !empty($commentsData) ? $commentsData : array();
    ?>
		var answersData  = <?php 
    echo defined('JSON_HEX_QUOT') ? json_encode($answersData, JSON_HEX_QUOT) : json_encode($answersData);
    ?>
;
		var commentsData = <?php 
    echo defined('JSON_HEX_QUOT') ? json_encode(array_merge($parent_comments, $commentsData), JSON_HEX_QUOT) : json_encode(array_merge($parent_comments, $commentsData));
    ?>
;
	</script>
<?php 
}
示例#5
0
function qa_mark_answer_point($question_id, $answer_id)
{
    $answer = get_post($answer_id);
    if ($answer) {
        // answer is valid
        global $user_ID;
        if ($user_ID != $answer->post_author) {
            /**
             * get site qa badge point system
             */
            $point = qa_get_badge_point();
            /**
             * update use point by answer accepted point
             */
            qa_update_user_point($answer->post_author, $point->a_accepted);
            QA_Answers::update_field($answer_id, 'et_best_answer_point', $point->a_accepted);
            /**
             * do action qa point answer mark answered
             * @param $answer the answer be mark
             * @param $point
             */
            do_action('qa_point_answer_marked', $answer, $point->a_accepted);
        }
    }
}
if (is_user_logged_in() && current_user_can('manage_options')) {
    $reply_args['post_status'] = array('publish', 'pending');
}
if (isset($_GET['sort']) && $_GET['sort'] == "oldest") {
    $reply_args['order'] = 'ASC';
} else {
    add_filter("posts_join", array("QA_Front", "_post_vote_join"));
    add_filter("posts_orderby", array("QA_Front", "_post_vote_orderby"));
}
$replyQuery = new WP_Query($reply_args);
$answersData = array();
global $post;
if ($replyQuery->have_posts()) {
    while ($replyQuery->have_posts()) {
        $replyQuery->the_post();
        $answersData[] = QA_Answers::convert($post);
        get_template_part('mobile/template/item', 'answer');
    }
}
wp_reset_query();
?>
    </div>
    <div class="clearfix" style="height:20px;"></div>
    <!-- CONTENT ANSWERS LOOP / END -->
    <!-- PAGINATIONS ANSWER -->
    <section class="list-pagination-wrapper">
        <?php 
echo paginate_links(array('base' => get_permalink($question->ID) . '%#%', 'format' => $wp_rewrite->using_permalinks() ? 'page/%#%' : '?paged=%#%', 'current' => max(1, $paged), 'mid_size' => 1, 'total' => $replyQuery->max_num_pages, 'prev_text' => '<', 'next_text' => '>', 'type' => 'list'));
?>
         
    </section>
示例#7
0
 public function delete()
 {
     try {
         if (empty($_POST['ID']) && empty($_POST['comment_ID'])) {
             throw new Exception(__('Error occurred', ET_DOMAIN));
         }
         if (isset($_POST['do_action']) && $_POST['do_action'] == "deleteComment") {
             $msg = __("Comment deleted successfully!", ET_DOMAIN);
             $post = get_comment($_POST['ID']);
             wp_delete_comment($_POST['comment_ID']);
         } else {
             if (isset($_POST['post_type']) && $_POST['post_type'] == "answer") {
                 $msg = __("Answer deleted successfully!", ET_DOMAIN);
                 $post = get_post($_POST['ID']);
                 QA_Answers::delete($_POST['ID']);
             } else {
                 $msg = __("Question deleted successfully!", ET_DOMAIN);
                 $post = get_post($_POST['ID']);
                 QA_Questions::delete($_POST['ID']);
             }
         }
         $resp = array('success' => true, 'msg' => $msg, 'redirect' => get_post_type_archive_link('question'), 'data' => $post);
     } catch (Exception $e) {
         $resp = array('success' => false, 'msg' => $e->getMessage());
     }
     return $resp;
 }