/** * * TEMPLATE LOOP FOR COMMENTS * @param array $comments * @author ThaiNT * @since 1.0 * **/ function qa_comments_loop($child) { global $qa_comment; $qa_comment = QA_Comments::convert($child); if (et_load_mobile()) { get_template_part('mobile/template/item', 'comment'); } else { get_template_part('template/item', 'comment'); } }
/** * * TEMPLATE LOOP FOR MOBILE COMMENTS * @param array $comments * @author ThaiNT * @since 1.0 * **/ function qa_mobile_comments_loop($child) { global $qa_comment; $qa_comment = QA_Comments::convert($child); get_template_part('mobile/template/item', 'comment'); }
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; }