Example #1
0
function load_tablepress_in_the_admin()
{
    if (is_admin() && defined('DOING_AJAX') && DOING_AJAX) {
        TablePress::load_controller('frontend');
        // работает на дефолтной теме
        // TablePress::$controller = TablePress::load_controller( 'admin_ajax' );
    }
}
 /**
  * Generates the content tokens and puts them into the tokens array
  *
  * @param object $the_post the post object
  * @param array $tokens tokens array
  *
  * @return int keywords count
  */
 private function tokenizeContent($the_post, &$tokens)
 {
     $args = $this->args;
     $content = $the_post->post_content;
     if ($args['extract_shortcodes']) {
         // WP Table Reloaded support
         if (defined('WP_TABLE_RELOADED_ABSPATH')) {
             include_once WP_TABLE_RELOADED_ABSPATH . 'controllers/controller-frontend.php';
             $wpt_reloaded = new WP_Table_Reloaded_Controller_Frontend();
         }
         // TablePress support
         if (defined('TABLEPRESS_ABSPATH')) {
             $tp_controller = TablePress::load_controller('frontend');
             $tp_controller->init_shortcodes();
         }
         // Remove user defined shortcodes
         $shortcodes = explode(',', $args['exclude_shortcodes']);
         foreach ($shortcodes as $shortcode) {
             remove_shortcode(trim($shortcode));
             add_shortcode(trim($shortcode), array($this, 'return_empty_string'));
         }
         // Remove some shortcodes
         remove_shortcode('wpdreams_ajaxsearchpro');
         add_shortcode('wpdreams_ajaxsearchpro', array($this, 'return_empty_string'));
         remove_shortcode('wpdreams_ajaxsearchpro_results');
         add_shortcode('wpdreams_ajaxsearchpro_results', array($this, 'return_empty_string'));
         remove_shortcode('wpdreams_asp_settings');
         add_shortcode('wpdreams_asp_settings', array($this, 'return_empty_string'));
         remove_shortcode('contact-form');
         add_shortcode('contact-form', array($this, 'return_empty_string'));
         remove_shortcode('starrater');
         add_shortcode('starrater', array($this, 'return_empty_string'));
         remove_shortcode('responsive-flipbook');
         add_shortcode('responsive-flipbook', array($this, 'return_empty_string'));
         remove_shortcode('avatar_upload');
         add_shortcode('avatar_upload', array($this, 'return_empty_string'));
         remove_shortcode('product_categories');
         add_shortcode('product_categories', array($this, 'return_empty_string'));
         remove_shortcode('recent_products');
         add_shortcode('recent_products', array($this, 'return_empty_string'));
         $content = do_shortcode($content);
         // WP 4.2 emoji strip
         if (function_exists('wp_encode_emoji')) {
             $content = wp_encode_emoji($content);
         }
         if (defined('TABLEPRESS_ABSPATH')) {
             unset($tp_controller);
         }
         if (defined('WP_TABLE_RELOADED_ABSPATH')) {
             unset($wpt_reloaded);
         }
     }
     // Strip the remaining shortcodes
     $content = strip_shortcodes($content);
     $content = preg_replace('/<[a-zA-Z\\/][^>]*>/', ' ', $content);
     $content = strip_tags($content);
     $filtered_content = apply_filters('asp_post_content_before_tokenize', $content);
     if ($filtered_content == "") {
         return 0;
     }
     $content_keywords = $this->tokenize($filtered_content);
     foreach ($content_keywords as $keyword) {
         $this->insertToken($tokens, $keyword[0], $keyword[1], 'content');
     }
     return count($content_keywords);
 }
Example #3
0
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;
}