/**
  * AJAX Callback
  *
  */
 function options_load()
 {
     check_ajax_referer('solr_security', 'security');
     $method = filter_input(INPUT_POST, 'method', FILTER_SANITIZE_STRING);
     if ($method === "load") {
         $type = filter_input(INPUT_POST, 'type', FILTER_SANITIZE_STRING);
         $prev = filter_input(INPUT_POST, 'prev', FILTER_SANITIZE_STRING);
         if (isset($type)) {
             SolrPower_Sync::get_instance()->load_all_posts($prev, $type);
             die;
         }
     }
     die;
 }
        if ($end) {
            printf("{\"type\": \"" . $post_type . "\", \"last\": \"%s\", \"end\": true, \"percent\": \"%.2f\"}", $last, 100);
        } else {
            printf("{\"type\": \"" . $post_type . "\", \"last\": \"%s\", \"end\": false, \"percent\": \"%.2f\"}", $last, $percent);
        }
    }
    function format_date($thedate)
    {
        $datere = '/(\\d{4}-\\d{2}-\\d{2})\\s(\\d{2}:\\d{2}:\\d{2})/';
        $replstr = '${1}T${2}Z';
        return preg_replace($datere, $replstr, $thedate);
    }
    // copies config settings from the main blog
    // to all of the other blogs
    function copy_config_to_all_blogs()
    {
        global $wpdb;
        $blogs = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs} WHERE spam = 0 AND deleted = 0");
        $plugin_s4wp_settings = solr_options();
        foreach ($blogs as $blog) {
            switch_to_blog($blog->blog_id);
            wp_cache_flush();
            syslog(LOG_INFO, "pushing config to {$blog->blog_id}");
            SolrPower_Options::get_instance()->update_option($plugin_s4wp_settings);
        }
        wp_cache_flush();
        restore_current_blog();
    }
}
SolrPower_Sync::get_instance();
示例#3
0
 /**
  * Setup for every test.
  */
 function setUp()
 {
     parent::setUp();
     // Delete the entire index.
     SolrPower_Sync::get_instance()->delete_all();
 }
 /**
  * Test to see if a two facets can be selected with the AND operator.
  * Should yield zero results.
  * @group 37
  */
 function test_multi_facet_and()
 {
     $this->__change_option('s4wp_default_operator', 'AND');
     $this->__change_option('s4wp_facet_on_custom_fields', array('my_field'));
     $this->__change_option('s4wp_index_custom_fields', array('my_field'));
     $cat_id_one = wp_create_category('new_cat');
     $cat_id_two = wp_create_category('smelly_cat');
     $p_id = $this->__create_test_post();
     update_post_meta($p_id, 'my_field', 'my_value');
     wp_set_object_terms($p_id, $cat_id_one, 'category', true);
     $p_id_two = $this->__create_test_post();
     wp_set_object_terms($p_id_two, $cat_id_two, 'category', true);
     SolrPower_Sync::get_instance()->load_all_posts(0, 'post', 100, false);
     $query = $this->__facet_query(array('facet' => array('my_field_str' => array('my_value'), 'categories' => array('smelly_cat^^'))));
     // This should return zero results because the result cannot contain both the custom field and the category.
     $this->assertEquals(0, $query->post_count);
     $this->assertEquals(0, $query->found_posts);
     wp_delete_category($cat_id_one);
     wp_delete_category($cat_id_two);
 }
示例#5
0
 /**
  * Tests to see if Solr indexes all posts.
  * @group 43
  * @link https://github.com/pantheon-systems/solr-power/issues/43
  */
 function test_index_all_posts()
 {
     // Create 20 posts:
     $this->__create_multiple(20);
     // Delete index.
     SolrPower_Sync::get_instance()->delete_all();
     // Index all posts:
     SolrPower_Sync::get_instance()->load_all_posts(0, 'post', 100, false);
     $search = $this->__run_test_query('post');
     if (is_null($search)) {
         $this->assertTrue(false);
     }
     $search = $search->getData();
     $search = $search['response'];
     // We should have 20 results.
     $this->assertEquals(absint($search['numFound']), 20);
 }
示例#6
0
            _e('All Indexed Pages Deleted!<br />' . esc_html($output), 'solr4wp');
            ?>
</strong></p></div>
<?php 
        } else {
            if (isset($_POST['s4wp_optimize']) and $_POST['s4wp_optimize']) {
                SolrPower_Api::get_instance()->optimize();
                ?>
    <div id="message" class="updated fade"><p><strong><?php 
                _e('Index Optimized!', 'solr4wp');
                ?>
</strong></p></div>
<?php 
            } else {
                if (isset($_POST['s4wp_init_blogs']) and $_POST['s4wp_init_blogs']) {
                    SolrPower_Sync::get_instance()->copy_config_to_all_blogs();
                } else {
                    if (isset($_POST['s4wp_query']) && $_POST['solrQuery']) {
                        $qry = filter_input(INPUT_POST, 'solrQuery', FILTER_SANITIZE_STRING);
                        $offset = null;
                        $count = null;
                        $fq = null;
                        $sortby = null;
                        $order = null;
                        $results = SolrPower_Api::get_instance()->query($qry, $offset, $count, $fq, $sortby, $order);
                        if (isset($results)) {
                            $plugin_s4wp_settings = solr_options();
                            $output_info = $plugin_s4wp_settings['s4wp_output_info'];
                            $data = $results->getData();
                            $response = $data['response'];
                            $header = $data['responseHeader'];
 /**
  * Checks to see if any actions were taken on the settings page.
  */
 function check_for_actions()
 {
     if (!isset($_POST['action']) || !current_user_can('manage_options')) {
         return;
     }
     $action = sanitize_text_field($_POST['action']);
     switch ($action) {
         case 'update':
             if (!$this->check_nonce('solr_update')) {
                 return;
             }
             $this->save_options();
             break;
         case 'ping':
             if (!$this->check_nonce('solr_ping')) {
                 return;
             }
             if (SolrPower_Api::get_instance()->ping_server()) {
                 $this->msg = __('Ping Success!', 'solr-for-wordpress-on-pantheon');
             } else {
                 $this->msg = __('Ping Failed!', 'solr-for-wordpress-on-pantheon');
             }
             break;
         case 'init_blogs':
             if (!$this->check_nonce('solr_init_blogs')) {
                 return;
             }
             SolrPower_Sync::get_instance()->copy_config_to_all_blogs();
             $this->msg = __('Configuration has been copied to all blogs!', 'solr-for-wordpress-on-pantheon');
             break;
         case 'optimize':
             if (!$this->check_nonce('solr_optimize')) {
                 return;
             }
             SolrPower_Api::get_instance()->optimize();
             $this->msg = __('Index Optimized!', 'solr-for-wordpress-on-pantheon');
             break;
         case 'delete_all':
             if (!$this->check_nonce('solr_delete_all')) {
                 return;
             }
             SolrPower_Sync::get_instance()->delete_all();
             $this->msg = __('All Indexed Pages Deleted!', 'solr-for-wordpress-on-pantheon');
             break;
         case 'repost_schema':
             if (!$this->check_nonce('solr_repost_schema')) {
                 return;
             }
             SolrPower_Sync::get_instance()->delete_all();
             $output = SolrPower_Api::get_instance()->submit_schema();
             $this->msg = __('All Indexed Pages Deleted!<br />' . esc_html($output), 'solr-for-wordpress-on-pantheon');
             break;
         case 'run_query':
             if (!$this->check_nonce('solr_run_query')) {
                 return;
             }
             $this->run_query();
             break;
     }
 }