/** * 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; $question = QA_Questions::convert($post); $et_post_date = et_the_time(strtotime($question->post_date)); $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('question-item pending-question'); ?> data-id="<?php echo $post->ID; ?> "> <div class="col-md-8 col-xs-8 q-left-content"> <div class="q-ltop-content"> <a href="<?php the_permalink(); ?> " class="question-title"> <?php the_title(); ?> </a> </div> <div class="q-lbtm-content"> <div class="question-excerpt"> <?php the_excerpt(); ?>
<?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">
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); }
<?php $paged = get_query_var('paged') ? get_query_var('paged') : 1; $type = isset($_GET['type']) ? $_GET['type'] : 'question'; $args = array('post_type' => $type, 'paged' => $paged, 'author' => $user->ID); //show pending question if current is author if ($current_user->ID == $user->ID) { $args['post_status'] = array('publish', 'pending'); } //tab following questions if (isset($_GET['type']) && $_GET['type'] == "following") { $follow_questions = array_filter((array) get_user_meta($user->ID, 'qa_following_questions', true)); $args['post_type'] = $type = "question"; $args['post__in'] = !empty($follow_questions) ? $follow_questions : array(0); unset($args['author']); } $query = QA_Questions::get_questions($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); get_template_part('mobile/template/' . $type, 'loop'); } } else { echo '<li class="no-questions">'; echo '<h2>' . __('There are no questions yet.', ET_DOMAIN) . '</h2>'; echo '</li>'; } wp_reset_query(); ?> </ul> </div> </div>
/** * * 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 }
</section> <!-- MIDDLE BAR / END --> <!-- LIST QUESTION --> <section class="list-question-wrapper"> <div class="container"> <div class="row"> <div class="col-md-12"> <ul class="list-question"> <?php if (get_query_var('page')) { $paged = get_query_var('page') ? get_query_var('page') : 1; } else { $paged = get_query_var('paged') ? get_query_var('paged') : 1; } $query = QA_Questions::get_questions(array('post_type' => 'question', 'paged' => $paged)); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); get_template_part('mobile/template/question', 'loop'); } } wp_reset_query(); ?> </ul> </div> </div> </div> </section> <!-- LIST QUESTION / END --> <section class="list-pagination-wrapper">
/** * AJAX search questions by keyword (next version) * */ public function search_questions() { try { $query = QA_Questions::search($_POST['content']); $data = array(); foreach ($query->posts as $post) { $question = QA_Questions::convert($post); $question->et_avatar = QA_Member::get_avatar_urls($post->post_author, 30); $question->permalink = get_permalink($post->ID); $data[] = $question; } $resp = array('success' => true, 'msg' => '', 'data' => array('questions' => $data, 'total' => $query->found_posts, 'count' => $query->post_count, 'pages' => $query->max_num_pages, 'search_link' => qa_search_link($_POST['content']['s']), 'search_term' => $_POST['content']['s'], 'test' => $query)); } catch (Exception $e) { $resp = array('success' => false, 'msg' => $e->getMessage()); } wp_send_json($resp); }
<?php global $post, $wp_rewrite, $current_user, $qa_question, $qa_answer; the_post(); $answer = QA_Questions::convert($post); $question = QA_Questions::convert(get_post($post->post_parent)); $et_post_date = et_the_time(strtotime($question->post_date)); $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') : '#'; /** * global qa_question */ $qa_question = $question; $qa_answer = $answer; get_header(); $parent_comments = get_comments(array('post_id' => $question->ID, 'parent' => 0, 'status' => 'approve', 'post_status' => 'publish', 'order' => 'ASC', 'type' => 'question')); $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($parent_comments, $qa_answer_comments); ?> <?php get_sidebar('left'); ?> <div class="col-md-8 main-content single-content"> <div class="row select-category single-head"> <div class="col-md-2 col-xs-2"> <span class="back"> <i class="fa fa-angle-double-left"></i> <a href="<?php echo home_url(); ?> "><?php _e("Home", ET_DOMAIN);