function relevanssi_do_excerpt($t_post, $query) { global $post; $old_global_post = NULL; if ($post != NULL) { $old_global_post = $post; } $post = $t_post; $remove_stopwords = false; $terms = relevanssi_tokenize($query, $remove_stopwords, -1, false); // These shortcodes cause problems with Relevanssi excerpts remove_shortcode('layerslider'); $content = apply_filters('relevanssi_pre_excerpt_content', $post->post_content, $post, $query); $content = apply_filters('the_content', $content); $content = apply_filters('relevanssi_excerpt_content', $content, $post, $query); $content = relevanssi_strip_invisibles($content); // removes <script>, <embed> &c with content $content = preg_replace('/(<\\/[^>]+?>)(<[^>\\/][^>]*?>)/', '$1 $2', $content); // add spaces between tags to avoid getting words stuck together $content = strip_tags($content, get_option('relevanssi_excerpt_allowable_tags', '')); // this removes the tags, but leaves the content $content = preg_replace("/\n\r|\r\n|\n|\r/", " ", $content); // $content = trim(preg_replace("/\s\s+/", " ", $content)); $excerpt_data = relevanssi_create_excerpt($content, $terms, $query); if (get_option("relevanssi_index_comments") != 'none') { $comment_content = relevanssi_get_comments($post->ID); $comment_excerpts = relevanssi_create_excerpt($comment_content, $terms, $query); if ($comment_excerpts[1] > $excerpt_data[1]) { $excerpt_data = $comment_excerpts; } } if (get_option("relevanssi_index_excerpt") != 'none') { $excerpt_content = $post->post_excerpt; $excerpt_excerpts = relevanssi_create_excerpt($excerpt_content, $terms, $query); if ($excerpt_excerpts[1] > $excerpt_data[1]) { $excerpt_data = $excerpt_excerpts; } } $start = $excerpt_data[2]; $excerpt = $excerpt_data[0]; $excerpt = trim($excerpt); $excerpt = apply_filters('relevanssi_excerpt', $excerpt); $ellipsis = apply_filters('relevanssi_ellipsis', '...'); $highlight = get_option('relevanssi_highlight'); if ("none" != $highlight) { if (!is_admin()) { $excerpt = relevanssi_highlight_terms($excerpt, $query); } } if (!$start && !empty($excerpt)) { $excerpt = $ellipsis . $excerpt; // do not add three dots to the beginning of the post } if (!empty($excerpt)) { $excerpt = $excerpt . $ellipsis; } if (relevanssi_s2member_level($post->ID) == 1) { $excerpt = $post->post_excerpt; } if ($old_global_post != NULL) { $post = $old_global_post; } return $excerpt; }
function relevanssi_index_doc($indexpost, $remove_first = false, $custom_fields = false) { global $wpdb, $relevanssi_table, $post; $post = $indexpost; // END modified by renaissancehack if (!is_object($post)) { // BEGIN modified by renaissancehack // modified query to get child records that inherit their post_status get_option('relevanssi_index_attachments') == 'on' ? $attachments = '' : $attachments = "AND post.post_type!='attachment'"; $post = $wpdb->get_row("SELECT *,parent.post_status FROM $wpdb->posts parent, $wpdb->posts post WHERE (parent.post_status='publish' OR parent.post_status='private') AND post.ID=$post AND ( (post.post_status='inherit' AND post.post_parent=parent.ID) OR (parent.ID=post.ID) ) AND post.post_type!='nav_menu_item' AND post.post_type!='revision' $attachments"); // END modified by renaissancehack if (!$post) { // the post isn't public return; } } $index_type = get_option('relevanssi_index_type'); $custom_types = explode(",", get_option('relevanssi_custom_types')); $index_this_post = false; switch ($index_type) { case 'posts': if ("post" == $post->post_type) $index_this_post = true; if (in_array($post->post_type, $custom_types)) $index_this_post = true; break; case 'pages': if ("page" == $post->post_type) $index_this_post = true; if (in_array($post->post_type, $custom_types)) $index_this_post = true; break; case 'public'; if (function_exists('get_post_types')) { $public_types = get_post_types(array('exclude_from_search' => false)); if (in_array($post->post_type, $public_types)) $index_this_post = true; } else { $index_this_post = true; } break; case 'both': $index_this_post = true; break; } if ($remove_first) { // we are updating a post, so remove the old stuff first relevanssi_remove_doc($post->ID); } // This needs to be here, after the call to relevanssi_remove_doc(), because otherwise // a post that's in the index but shouldn't be there won't get removed. A remote chance, // I mean who ever flips exclude_from_search between true and false once it's set, but // I'd like to cover all bases. if (!$index_this_post) return; $n = 0; $titles = relevanssi_tokenize($post->post_title); //Added by OdditY - INDEX COMMENTS of the POST -> if ("none" != get_option("relevanssi_index_comments")) { $pcoms = relevanssi_get_comments($post->ID); if( $pcoms != "" ){ $pcoms = relevanssi_strip_invisibles($pcoms); $pcoms = strip_tags($pcoms); $pcoms = relevanssi_tokenize($pcoms); if (count($pcoms) > 0) { foreach ($pcoms as $pcom => $count) { if (strlen($pcom) < 2) continue; $n++; $wpdb->query("INSERT INTO $relevanssi_table (doc, term, tf, title) VALUES ($post->ID, '$pcom', $count, 3)"); } } } } //Added by OdditY END <- $taxonomies = array(); //Added by OdditY - INDEX TAGs of the POST -> if ("on" == get_option("relevanssi_include_tags")) { array_push($taxonomies, "post_tag"); } // Added by OdditY END <- $custom_taxos = get_option("relevanssi_custom_taxonomies"); if ("" != $custom_taxos) { $cts = explode(",", $custom_taxos); foreach ($cts as $taxon) { $taxon = trim($taxon); array_push($taxonomies, $taxon); } } // Then process all taxonomies, if any. foreach ($taxonomies as $taxonomy) { $n += index_taxonomy_terms($post, $taxonomy); } // index categories if ("on" == get_option("relevanssi_include_cats")) { $post_categories = get_the_category($post->ID); if (is_array($post_categories)) { foreach ($post_categories as $p_cat) { $cat_name = apply_filters("single_cat_title", $p_cat->cat_name); $cat_tokens = relevanssi_tokenize($cat_name); foreach ($cat_tokens as $pcat => $count) { if (strlen($pcat) < 2) continue; $n++; $wpdb->query("INSERT INTO $relevanssi_table (doc, term, tf, title) VALUES ($post->ID, '$pcat', $count, 4)"); } } } } // index author if ("on" == get_option("relevanssi_index_author")) { $auth = $post->post_author; $display_name = $wpdb->get_var("SELECT display_name FROM $wpdb->users WHERE ID=$auth"); $wpdb->query("INSERT INTO $relevanssi_table (doc, term, tf, title) VALUES ($post->ID, '$display_name', 1, 5)"); } if ($custom_fields) { foreach ($custom_fields as $field) { $values = get_post_meta($post->ID, $field, false); if ("" == $values) continue; foreach ($values as $value) { // Custom field values are simply tacked to the end of the post content $post->post_content .= ' ' . $value; } } } if (isset($post->post_excerpt) && ("on" == get_option("relevanssi_index_excerpt") || "attachment" == $post->post_type)) { // include excerpt for attachments which use post_excerpt for captions - modified by renaissancehack $post->post_content .= ' ' . $post->post_excerpt; } $contents = relevanssi_strip_invisibles($post->post_content); if ('on' == get_option('relevanssi_expand_shortcodes')) { if (function_exists("do_shortcode")) { $contents = do_shortcode($contents); } } else { if (function_exists("strip_shortcodes")) { // WP 2.5 doesn't have the function $contents = strip_shortcodes($contents); } } $contents = strip_tags($contents); $contents = relevanssi_tokenize($contents); if (count($titles) > 0) { foreach ($titles as $title => $count) { if (strlen($title) < 2) continue; $n++; $wpdb->query("INSERT INTO $relevanssi_table (doc, term, tf, title) VALUES ($post->ID, '$title', $count, 1)"); // a slightly clumsy way to handle titles, I'll try to come up with something better } } if (count($contents) > 0) { foreach ($contents as $content => $count) { if (strlen($content) < 2) continue; $n++; $wpdb->query("INSERT INTO $relevanssi_table (doc, term, tf, title) VALUES ($post->ID, '$content', $count, 0)"); } } return $n; }
function relevanssi_index_doc($indexpost, $remove_first = false, $custom_fields = false, $bypassglobalpost = false) { global $wpdb, $post, $relevanssi_variables; $relevanssi_table = $relevanssi_variables['relevanssi_table']; $post_was_null = false; $previous_post = NULL; // Check if this is a Jetpack Contact Form entry if (isset($_REQUEST['contact-form-id'])) { return; } if ($bypassglobalpost) { // if $bypassglobalpost is set, relevanssi_index_doc() will index the post object or post // ID as specified in $indexpost isset($post) ? $previous_post = $post : ($post_was_null = true); is_object($indexpost) ? $post = $indexpost : ($post = get_post($indexpost)); } else { // Quick edit has an array in the global $post, so fetch the post ID for the post to edit. if (is_array($post)) { $post = get_post($post['ID']); } if (empty($post)) { // No $post set, so we need to use $indexpost, if it's a post object $post_was_null = true; if (is_object($indexpost)) { $post = $indexpost; } else { $post = get_post($indexpost); } } else { // $post was set, let's grab the previous value in case we need it $previous_post = $post; } } if ($post == NULL) { // At this point we should have something in $post; if not, quit. if ($post_was_null) { $post = null; } if ($previous_post) { $post = $previous_post; } return; } // Finally fetch the post again by ID. Complicated, yes, but unless we do this, we might end // up indexing the post before the updates come in. $post = get_post($post->ID); if (function_exists('relevanssi_hide_post')) { if (relevanssi_hide_post($post->ID)) { if ($post_was_null) { $post = null; } if ($previous_post) { $post = $previous_post; } return; } } $index_this_post = false; $post->indexing_content = true; $index_types = get_option('relevanssi_index_post_types'); if (!is_array($index_types)) { $index_types = array(); } if (in_array($post->post_type, $index_types)) { $index_this_post = true; } if (true == apply_filters('relevanssi_do_not_index', false, $post->ID)) { // filter says no $index_this_post = false; } if ($remove_first) { // we are updating a post, so remove the old stuff first relevanssi_remove_doc($post->ID, true); if (function_exists('relevanssi_remove_item')) { relevanssi_remove_item($post->ID, 'post'); } } // This needs to be here, after the call to relevanssi_remove_doc(), because otherwise // a post that's in the index but shouldn't be there won't get removed. if (!$index_this_post) { if ($post_was_null) { $post = null; } if ($previous_post) { $post = $previous_post; } return; } $n = 0; $post = apply_filters('relevanssi_post_to_index', $post); $min_word_length = get_option('relevanssi_min_word_length', 3); $insert_data = array(); //Added by OdditY - INDEX COMMENTS of the POST -> if ("none" != get_option("relevanssi_index_comments")) { $pcoms = relevanssi_get_comments($post->ID); if ($pcoms != "") { $pcoms = relevanssi_strip_invisibles($pcoms); $pcoms = preg_replace('/<[a-zA-Z\\/][^>]*>/', ' ', $pcoms); $pcoms = strip_tags($pcoms); $pcoms = relevanssi_tokenize($pcoms, true, $min_word_length); if (count($pcoms) > 0) { foreach ($pcoms as $pcom => $count) { $n++; $insert_data[$pcom]['comment'] = $count; } } } } //Added by OdditY END <- $taxonomies = get_option("relevanssi_index_taxonomies_list"); // Then process all taxonomies, if any. foreach ($taxonomies as $taxonomy) { $insert_data = relevanssi_index_taxonomy_terms($post, $taxonomy, $insert_data); } // index author if ("on" == get_option("relevanssi_index_author")) { $auth = $post->post_author; $display_name = $wpdb->get_var("SELECT display_name FROM {$wpdb->users} WHERE ID={$auth}"); $names = relevanssi_tokenize($display_name, false, $min_word_length); foreach ($names as $name => $count) { isset($insert_data[$name]['author']) ? $insert_data[$name]['author'] += $count : ($insert_data[$name]['author'] = $count); } } if ($custom_fields) { $remove_underscore_fields = false; if ($custom_fields == 'all') { $custom_fields = get_post_custom_keys($post->ID); } if ($custom_fields == 'visible') { $custom_fields = get_post_custom_keys($post->ID); $remove_underscore_fields = true; } $custom_fields = apply_filters('relevanssi_index_custom_fields', $custom_fields); if (is_array($custom_fields)) { foreach ($custom_fields as $field) { if ($remove_underscore_fields) { if (substr($field, 0, 1) == '_') { continue; } } $values = get_post_meta($post->ID, $field, false); if ("" == $values) { continue; } foreach ($values as $value) { $value_tokens = relevanssi_tokenize($value, true, $min_word_length); foreach ($value_tokens as $token => $count) { isset($insert_data[$token]['customfield']) ? $insert_data[$token]['customfield'] += $count : ($insert_data[$token]['customfield'] = $count); if (function_exists('relevanssi_customfield_detail')) { $insert_data = relevanssi_customfield_detail($insert_data, $token, $count, $field); } } } } } } if (isset($post->post_excerpt) && ("on" == get_option("relevanssi_index_excerpt") || "attachment" == $post->post_type)) { // include excerpt for attachments which use post_excerpt for captions - modified by renaissancehack $excerpt_tokens = relevanssi_tokenize($post->post_excerpt, true, $min_word_length); foreach ($excerpt_tokens as $token => $count) { isset($insert_data[$token]['excerpt']) ? $insert_data[$token]['excerpt'] += $count : ($insert_data[$token]['excerpt'] = $count); } } if (function_exists('relevanssi_index_mysql_columns')) { $insert_data = relevanssi_index_mysql_columns($insert_data, $post->ID); } $index_titles = true; if (apply_filters('relevanssi_index_titles', $index_titles)) { $filtered_title = apply_filters('relevanssi_post_title_before_tokenize', $post->post_title, $post); $titles = relevanssi_tokenize(apply_filters('the_title', $filtered_title)); if (count($titles) > 0) { foreach ($titles as $title => $count) { $n++; isset($insert_data[$title]['title']) ? $insert_data[$title]['title'] += $count : ($insert_data[$title]['title'] = $count); } } } $index_content = true; if (apply_filters('relevanssi_index_content', $index_content)) { remove_shortcode('noindex'); add_shortcode('noindex', 'relevanssi_noindex_shortcode_indexing'); $contents = apply_filters('relevanssi_post_content', $post->post_content, $post); // Allow user to add extra content for Relevanssi to index // Thanks to Alexander Gieg $additional_content = trim(apply_filters('relevanssi_content_to_index', '', $post)); if ('' != $additional_content) { $contents .= ' ' . $additional_content; } if ('on' == get_option('relevanssi_expand_shortcodes')) { if (function_exists("do_shortcode")) { // WP Table Reloaded support if (defined('WP_TABLE_RELOADED_ABSPATH')) { include_once WP_TABLE_RELOADED_ABSPATH . 'controllers/controller-frontend.php'; $My_WP_Table_Reloaded = new WP_Table_Reloaded_Controller_Frontend(); } // TablePress support if (defined('TABLEPRESS_ABSPATH')) { $My_TablePress_Controller = TablePress::load_controller('frontend'); $My_TablePress_Controller->init_shortcodes(); } $disable_shortcodes = get_option('relevanssi_disable_shortcodes'); $shortcodes = explode(',', $disable_shortcodes); foreach ($shortcodes as $shortcode) { remove_shortcode(trim($shortcode)); } remove_shortcode('contact-form'); // Jetpack Contact Form causes an error message remove_shortcode('starrater'); // GD Star Rating rater shortcode causes problems remove_shortcode('responsive-flipbook'); // Responsive Flipbook causes problems remove_shortcode('avatar_upload'); // WP User Avatar is incompatible remove_shortcode('product_categories'); // A problematic WooCommerce shortcode remove_shortcode('recent_products'); // A problematic WooCommerce shortcode remove_shortcode('php'); // PHP Code for Posts $post_before_shortcode = $post; $contents = do_shortcode($contents); $post = $post_before_shortcode; if (defined('TABLEPRESS_ABSPATH')) { unset($My_TablePress_Controller); } if (defined('WP_TABLE_RELOADED_ABSPATH')) { unset($My_WP_Table_Reloaded); } } } else { if (function_exists("strip_shortcodes")) { // WP 2.5 doesn't have the function $contents = strip_shortcodes($contents); } } remove_shortcode('noindex'); add_shortcode('noindex', 'relevanssi_noindex_shortcode'); $contents = relevanssi_strip_invisibles($contents); if (function_exists('relevanssi_process_internal_links')) { $contents = relevanssi_process_internal_links($contents, $post->ID); } $contents = preg_replace('/<[a-zA-Z\\/][^>]*>/', ' ', $contents); $contents = strip_tags($contents); if (function_exists('wp_encode_emoji')) { $contents = wp_encode_emoji($contents); } $contents = apply_filters('relevanssi_post_content_before_tokenize', $contents, $post); $contents = relevanssi_tokenize($contents, true, $min_word_length); if (count($contents) > 0) { foreach ($contents as $content => $count) { $n++; isset($insert_data[$content]['content']) ? $insert_data[$content]['content'] += $count : ($insert_data[$content]['content'] = $count); } } } $type = 'post'; if ($post->post_type == 'attachment') { $type = 'attachment'; } $insert_data = apply_filters('relevanssi_indexing_data', $insert_data, $post); $values = array(); foreach ($insert_data as $term => $data) { $content = 0; $title = 0; $comment = 0; $tag = 0; $link = 0; $author = 0; $category = 0; $excerpt = 0; $taxonomy = 0; $customfield = 0; $taxonomy_detail = ''; $customfield_detail = ''; $mysqlcolumn = 0; extract($data); $term = trim($term); $value = $wpdb->prepare("(%d, %s, REVERSE(%s), %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %s, %s, %s, %d)", $post->ID, $term, $term, $content, $title, $comment, $tag, $link, $author, $category, $excerpt, $taxonomy, $customfield, $type, $taxonomy_detail, $customfield_detail, $mysqlcolumn); array_push($values, $value); } $values = apply_filters('relevanssi_indexing_values', $values, $post); if (!empty($values)) { $values = implode(', ', $values); $query = "INSERT IGNORE INTO {$relevanssi_table} (doc, term, term_reverse, content, title, comment, tag, link, author, category, excerpt, taxonomy, customfield, type, taxonomy_detail, customfield_detail, mysqlcolumn)\n\t\t\tVALUES {$values}"; $wpdb->query($query); } if ($post_was_null) { $post = null; } if ($previous_post) { $post = $previous_post; } return $n; }
function relevanssi_index_doc($indexpost, $remove_first = false, $custom_fields = false, $bypassglobalpost = false) { global $wpdb, $relevanssi_table, $post; $post_was_null = false; $previous_post = NULL; if ($bypassglobalpost) { // if $bypassglobalpost is set, relevanssi_index_doc() will index the post object or post // ID as specified in $indexpost isset($post) ? $previous_post = $post : ($post_was_null = true); is_object($indexpost) ? $post = $indexpost : ($post = get_post($indexpost)); } else { // Quick edit has an array in the global $post, so fetch the post ID for the post to edit. if (is_array($post)) { $post = $post['ID']; } if (!isset($post)) { // No $post set, so we need to use $indexpost, if it's a post object $post_was_null = true; if (is_object($indexpost)) { $post = $indexpost; } } else { // $post was set, let's grab the previous value in case we need it $previous_post = $post; } // At this point we should have something in $post; if not, quit. if ($post == NULL) { if ($post_was_null) { $post = null; } if ($previous_post) { $post = $previous_post; } return; } is_object($post) ? $ID = $post->ID : ($ID = $post); } // Finally fetch the post again by ID. Complicated, yes, but unless we do this, we might end // up indexing the post before the updates come in. $post = get_post($ID); $index_type = get_option('relevanssi_index_type'); $custom_types = explode(",", get_option('relevanssi_custom_types')); $index_this_post = false; switch ($index_type) { case 'posts': if ("post" == $post->post_type) { $index_this_post = true; } if (in_array($post->post_type, $custom_types)) { $index_this_post = true; } break; case 'pages': if ("page" == $post->post_type) { $index_this_post = true; } if (in_array($post->post_type, $custom_types)) { $index_this_post = true; } break; case 'public': if (function_exists('get_post_types')) { $pt_1 = get_post_types(array('exclude_from_search' => '0')); $pt_2 = get_post_types(array('exclude_from_search' => false)); $public_types = array_merge($pt_1, $pt_2); if (in_array($post->post_type, $public_types)) { $index_this_post = true; } } else { $index_this_post = true; } break; case 'custom': if (in_array($post->post_type, $custom_types)) { $index_this_post = true; } break; case 'both': $index_this_post = true; break; } if ($post->post_type == 'attachment') { get_option('relevanssi_index_attachments') == 'on' ? $index_this_post = true : ($index_this_post = false); } if ($remove_first) { // we are updating a post, so remove the old stuff first relevanssi_remove_doc($post->ID); relevanssi_purge_excerpt_cache($post->ID); } // This needs to be here, after the call to relevanssi_remove_doc(), because otherwise // a post that's in the index but shouldn't be there won't get removed. A remote chance, // I mean who ever flips exclude_from_search between true and false once it's set, but // I'd like to cover all bases. if (!$index_this_post) { if ($post_was_null) { $post = null; } if ($previous_post) { $post = $previous_post; } return; } $n = 0; $min_word_length = get_option('relevanssi_min_word_length', 3); $titles = relevanssi_tokenize($post->post_title); //Added by OdditY - INDEX COMMENTS of the POST -> if ("none" != get_option("relevanssi_index_comments")) { $pcoms = relevanssi_get_comments($post->ID); if ($pcoms != "") { $pcoms = relevanssi_strip_invisibles($pcoms); $pcoms = strip_tags($pcoms); $pcoms = relevanssi_tokenize($pcoms); if (count($pcoms) > 0) { foreach ($pcoms as $pcom => $count) { if (strlen($pcom) < $min_word_length) { continue; } $n++; $wpdb->query("INSERT INTO {$relevanssi_table} (doc, term, tf, title)\n\t\t\t\t\tVALUES ({$post->ID}, '{$pcom}', {$count}, 3)"); } } } } //Added by OdditY END <- $taxonomies = array(); //Added by OdditY - INDEX TAGs of the POST -> if ("on" == get_option("relevanssi_include_tags")) { array_push($taxonomies, "post_tag"); } // Added by OdditY END <- $custom_taxos = get_option("relevanssi_custom_taxonomies"); if ("" != $custom_taxos) { $cts = explode(",", $custom_taxos); foreach ($cts as $taxon) { $taxon = trim($taxon); array_push($taxonomies, $taxon); } } // Then process all taxonomies, if any. foreach ($taxonomies as $taxonomy) { $n += index_taxonomy_terms($post, $taxonomy); } // index categories if ("on" == get_option("relevanssi_include_cats")) { $post_categories = get_the_category($post->ID); if (is_array($post_categories)) { foreach ($post_categories as $p_cat) { $cat_name = apply_filters("single_cat_title", $p_cat->cat_name); $cat_tokens = relevanssi_tokenize($cat_name); foreach ($cat_tokens as $pcat => $count) { if (strlen($pcat) < $min_word_length) { continue; } $n++; $wpdb->query("INSERT INTO {$relevanssi_table} (doc, term, tf, title)\n\t\t\t\t\tVALUES ({$post->ID}, '{$pcat}', {$count}, 4)"); } } } } // index author if ("on" == get_option("relevanssi_index_author")) { $auth = $post->post_author; $display_name = $wpdb->get_var("SELECT display_name FROM {$wpdb->users} WHERE ID={$auth}"); $names = relevanssi_tokenize($display_name, false); $names = apply_filters('relevanssi_index_author', $names, $post); $names = apply_filters('relevanssi_index_author-', $names, $post); foreach ($names as $name => $count) { $wpdb->query("INSERT INTO {$relevanssi_table} (doc, term, tf, title)\n\t\t\t\tVALUES ({$post->ID}, '{$name}', {$count}, 5)"); } } if ($custom_fields) { foreach ($custom_fields as $field) { $values = get_post_meta($post->ID, $field, false); if ("" == $values) { continue; } foreach ($values as $value) { // Custom field values are simply tacked to the end of the post content $post->post_content .= ' ' . (is_array($value) ? implode(' ', $value) : $value); } } } if (isset($post->post_excerpt) && ("on" == get_option("relevanssi_index_excerpt") || "attachment" == $post->post_type)) { // include excerpt for attachments which use post_excerpt for captions - modified by renaissancehack $post->post_content .= ' ' . $post->post_excerpt; } $contents = $post->post_content; $contents = apply_filters('relevanssi_index_content', $contents, $post); $contents = apply_filters('relevanssi_index_content-' . $post->post_type, $contents, $post); if ('on' == get_option('relevanssi_expand_shortcodes')) { if (function_exists("do_shortcode")) { $contents = do_shortcode($contents); } } else { if (function_exists("strip_shortcodes")) { // WP 2.5 doesn't have the function $contents = strip_shortcodes($contents); } } $contents = relevanssi_strip_invisibles($contents); $contents = strip_tags($contents); $contents = relevanssi_tokenize($contents); if (count($titles) > 0) { foreach ($titles as $title => $count) { if (strlen($title) < $min_word_length) { continue; } $n++; $wpdb->query("INSERT INTO {$relevanssi_table} (doc, term, tf, title)\n\t\t\tVALUES ({$post->ID}, '{$title}', {$count}, 1)"); // a slightly clumsy way to handle titles, I'll try to come up with something better } } if (count($contents) > 0) { foreach ($contents as $content => $count) { if (strlen($content) < $min_word_length) { continue; } $n++; $wpdb->query("INSERT INTO {$relevanssi_table} (doc, term, tf, title)\n\t\t\tVALUES ({$post->ID}, '{$content}', {$count}, 0)"); } } // Restore the global $post to whatever it was. if ($post_was_null) { $post = null; } if ($previous_post) { $post = $previous_post; } return $n; }