/**
  * Grab instance of object.
  * @return SolrPower_Options
  */
 public static function get_instance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 function posts_request($request, $query)
 {
     if (!$query->is_search()) {
         return $request;
     }
     $solr_options = SolrPower_Options::get_instance()->get_option();
     $the_page = !$query->get('paged') ? 1 : $query->get('paged');
     $qry = $query->get('s');
     $offset = $query->get('posts_per_page') * ($the_page - 1);
     $count = $query->get('posts_per_page');
     $fq = $this->parse_facets($query);
     $sortby = isset($solr_options['s4wp_default_sort']) && !empty($solr_options['s4wp_default_sort']) ? $solr_options['s4wp_default_sort'] : 'score';
     $order = 'desc';
     $search = SolrPower_Api::get_instance()->query($qry, $offset, $count, $fq, $sortby, $order);
     if (is_null($search)) {
         return false;
     }
     $this->search = $search;
     if ($search->getFacetSet()) {
         $this->facets = $search->getFacetSet()->getFacets();
     }
     $search = $search->getData();
     $search_header = $search['responseHeader'];
     $search = $search['response'];
     $query->found_posts = $search['numFound'];
     $query->max_num_pages = ceil($search['numFound'] / $query->get('posts_per_page'));
     SolrPower_Api::get_instance()->add_log(array('Results Found' => $search['numFound'], 'Query Time' => $search_header['QTime'] . 'ms'));
     $posts = array();
     foreach ($search['docs'] as $post_array) {
         $post = new stdClass();
         foreach ($post_array as $key => $value) {
             if ('displaydate' == $key) {
                 $post->post_date = $value;
                 continue;
             }
             if ('displaymodified' == $key) {
                 $post->post_modified = $value;
                 continue;
             }
             if ('post_date' == $key || 'post_modified' == $key) {
                 continue;
             }
             if ('post_id' == $key) {
                 $post->ID = $value;
                 continue;
             }
             $post->{$key} = $value;
         }
         $post->solr = true;
         $posts[] = $post;
     }
     $this->found_posts[spl_object_hash($query)] = $posts;
     global $wpdb;
     return "SELECT * FROM {$wpdb->posts} WHERE 1=0";
 }
 /**
  * Setup for every test.
  */
 function setUp()
 {
     parent::setUp();
     // Delete the entire index.
     SolrPower_Sync::get_instance()->delete_all();
     // Setup options (if not already set)
     $solr_options = solr_options();
     if ($solr_options['s4wp_solr_initialized'] != 1) {
         $options = SolrPower_Options::get_instance()->initalize_options();
         update_option('plugin_s4wp_settings', $options);
     }
 }
 function activate()
 {
     // Check to see if we have  environment variables. If not, bail. If so, create the initial options.
     if ($errMessage = SolrPower::get_instance()->sanity_check()) {
         wp_die($errMessage);
     }
     // Don't try to send a schema if we're not on Pantheon servers.
     if (!defined('SOLR_PATH')) {
         $schemaSubmit = SolrPower_Api::get_instance()->submit_schema();
         if (strpos($schemaSubmit, 'Error')) {
             wp_die('Submitting the schema failed with the message ' . $errMessage);
         }
     }
     SolrPower_Options::get_instance()->initalize_options();
     return;
 }
Пример #5
0
 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();
 }
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
*/
// Load up options.
$s4wp_settings = solr_options();
// Display a message if one is set.
if (!is_null(SolrPower_Options::get_instance()->msg)) {
    ?>
	<div id="message" class="updated fade"><p>
			<strong><?php 
    echo wp_kses_post(SolrPower_Options::get_instance()->msg);
    ?>
</strong>
		</p></div>
	<?php 
}
?>

<div class="wrap">
	<h2><?php 
esc_html_e('Solr Power', 'solr-for-wordpress-on-pantheon');
?>
</h2>


	<h2 class="nav-tab-wrapper" id="solr-tabs">
Пример #7
0
                foreach ($s_value as $key => $v) {
                    //lets rename the array_keys
                    if (!$v['host']) {
                        unset($s_value[$key]);
                    }
                }
                break;
        }
        if (!is_array($value)) {
            $value = trim($value);
        }
        $value = stripslashes_deep($value);
        $s4wp_settings[$option] = $value;
    }
    //lets save our options array
    SolrPower_Options::get_instance()->update_option($s4wp_settings);
    //we need to make call for the options again
    //as we need them to come out in an a sanitised format
    //otherwise fields that need to run s4wp_filter_list2str will come up with nothin
    $s4wp_settings = solr_options();
    ?>
  <div id="message" class="updated fade"><p><strong><?php 
    _e('Success!', 'solr4wp');
    ?>
</strong></p></div>
  <?php 
}
# checks if we need to check the checkbox
function s4wp_checkCheckbox($fieldValue)
{
    if ($fieldValue == '1') {
 /**
  * Type adjustments for value.
  *
  * @param string $value Value saved in option.
  * @param string $filter Type change needed.
  *
  * @return string Filtered (or unfiltered) value.
  */
 private function render_value($value, $filter)
 {
     if (is_null($filter)) {
         return $value;
     }
     switch ($filter) {
         case 'list2str':
             return SolrPower_Options::get_instance()->filter_list2str($value);
             break;
         case 'bool':
             return absint($value);
             break;
     }
     return $value;
 }
 function solr_options()
 {
     return SolrPower_Options::get_instance()->get_option();
 }