/** * Search and score comments * * @param string original search term * @param array all separated words from the search term * @param array all quoted parts from the search term * @param number max possible score */ function search_and_score_comments($search_term, $keywords, $quoted_parts) { global $DB, $Blog; // Search between comments $search_CommentList = new CommentList2($Blog, '', 'CommentCache', 'search_comment'); $search_CommentList->set_filters(array('keywords' => $search_term, 'phrase' => 'OR', 'order_by' => 'date', 'order' => 'DESC', 'comments' => 1000)); $search_CommentList->query_init(); $search_query = 'SELECT comment_ID, post_title, comment_content, comment_date, IFNULL(comment_author, user_login) as author' . $search_CommentList->CommentQuery->get_from() . ' LEFT JOIN T_items__item ON comment_item_ID = post_ID' . ' LEFT JOIN T_users ON post_creator_user_ID = user_ID' . $search_CommentList->CommentQuery->get_where() . $search_CommentList->CommentQuery->get_group_by() . $search_CommentList->CommentQuery->get_order_by() . $search_CommentList->CommentQuery->get_limit(); $query_result = $DB->get_results($search_query, OBJECT, 'Search comments query'); $search_result = array(); foreach ($query_result as $row) { $scores_map = array(); $scores_map['item_title'] = score_text($row->post_title, $search_term, $keywords, $quoted_parts); $scores_map['content'] = score_text($row->comment_content, $search_term, $keywords, $quoted_parts); if (!empty($row->author) && !empty($search_term) && strpos($row->author, $search_term) !== false) { $scores_map['author_name'] = 5; } $scores_map['creation_date'] = score_date($row->comment_date); $final_score = $scores_map['item_title']['score'] + $scores_map['content']['score'] + (isset($scores_map['author_name']) ? $scores_map['author_name'] : 0) + $scores_map['creation_date']; $search_result[] = array('type' => 'comment', 'score' => $final_score, 'ID' => $row->comment_ID, 'scores_map' => $scores_map); } return $search_result; }
/* * List of comments to display: */ $CommentList = new CommentList2($Blog, NULL, 'CommentCache', $comments_list_param_prefix, $tab3); // Filter list: $CommentList->set_default_filters(array('statuses' => get_visibility_statuses('keys', array('redirected', 'trash')), 'order' => 'DESC')); $CommentList->load_from_Request(); /** * Mass delete comments */ param('mass_type', 'string', ''); if ($action == 'mass_delete' && !empty($mass_type)) { // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('comment'); // Init the comment list query, but don't execute it $CommentList->query_init(); // Set sql query to get deletable comment ids $deletable_comments_query = 'SELECT DISTINCT ' . $CommentList->Cache->dbIDname . ' ' . $CommentList->CommentQuery->get_from() . $CommentList->CommentQuery->get_where(); // Set an action param to display a correct template $process_action = $action; unset($_POST['actionArray']); set_param('action', 'list'); // Try to obtain some serious time to do some serious processing (15 minutes) set_max_execution_time(10000); } break; default: debug_die('unhandled action 2'); } /* * Page navigation: