/**
  * Query the required server
  * passes all parameters to the appropriate function based on the server name
  * This allows for extensible server/core based query functions.
  * TODO allow for similar theme/output function
  */
 function query($qry, $offset, $count, $fq, $sortby, $order, $server = 'master')
 {
     //NOTICE: does this needs to be cached to stop the db being hit to grab the options everytime search is being done.
     $plugin_s4wp_settings = solr_options();
     $solr = get_solr();
     return $this->master_query($solr, $qry, $offset, $count, $fq, $sortby, $order, $plugin_s4wp_settings);
 }
 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();
 }
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    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 
 /**
  * Checks for 'facet' as WP_Query variable or query string and sets it up for a filter query.
  * @return array
  */
 function parse_facets($query)
 {
     $facets = $query->get('facet');
     if (!$facets) {
         $facets = filter_input(INPUT_GET, 'facet', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY);
     }
     if (!$facets) {
         return array();
     }
     $return = array();
     foreach ($facets as $facet_name => $facet_arr) {
         $fq = array();
         foreach ($facet_arr as $facet) {
             $fq[] = '"' . htmlspecialchars($facet) . '"';
         }
         $return[] = $facet_name . ':(' . implode(' OR ', $fq) . ')';
     }
     $plugin_s4wp_settings = solr_options();
     $default_operator = isset($plugin_s4wp_settings['s4wp_default_operator']) ? $plugin_s4wp_settings['s4wp_default_operator'] : 'OR';
     return implode(' ' . $default_operator . ' ', $return);
 }
 function __change_option($key, $value)
 {
     $solr_options = solr_options();
     $solr_options[$key] = $value;
     update_option('plugin_s4wp_settings', $solr_options);
 }
 /**
  * Determine if a facet should be visible based on options set on admin page.
  *
  * @param string $facet Facet name
  *
  * @return bool
  */
 function show_facet($facet)
 {
     if (0 < strpos($facet, 'taxonomy')) {
         $facet = 'taxonomy';
     }
     if (0 < strpos($facet, 'author')) {
         $facet = 'author';
     }
     if ('post_type' === $facet) {
         $facet = 'type';
     }
     if (0 < strpos($facet, '_str')) {
         $facet = 'custom_fields';
     }
     $key = 's4wp_facet_on_' . $facet;
     $solr_options = solr_options();
     if (array_key_exists($key, $solr_options) && false != $solr_options[$key]) {
         return true;
     }
     return false;
 }
 /**
  * Generates HTML form fields based upon array of arguments sent (field, filter, type, choices).
  *
  * @param array $args
  */
 function render_field($args)
 {
     $field_name = $args['field'];
     $s4wp_settings = solr_options();
     $value = $this->render_value($s4wp_settings[$field_name], $args['filter']);
     switch ($args['type']) {
         case 'input':
             echo '<input type="text" name="plugin_s4wp_settings[' . esc_attr($field_name) . ']" value="' . esc_attr($value) . '"/>';
             echo PHP_EOL;
             //XSS ok
             break;
         case 'checkbox':
             echo '<input type="checkbox" name="plugin_s4wp_settings[' . esc_attr($field_name) . ']" value="1" ' . checked($value, 1, false) . '/>';
             echo PHP_EOL;
             //XSS ok
             break;
         case 'radio':
             if (!isset($args['choices']) || !is_array($args['choices'])) {
                 return;
             }
             if (empty($value)) {
                 $value = $args['choices'][0];
             }
             foreach ($args['choices'] as $choice) {
                 echo esc_html($choice) . ' ';
                 echo '<input type="radio" name="plugin_s4wp_settings[' . esc_attr($field_name) . ']" value="' . esc_attr($choice) . '" ' . checked($value, $choice, false) . '/>';
                 echo PHP_EOL;
                 //XSS ok
             }
             break;
         case 'select':
             if (!isset($args['choices']) || !is_array($args['choices'])) {
                 return;
             }
             if (empty($value)) {
                 $value = $args['choices'][0];
             }
             echo '<select name="plugin_s4wp_settings[' . esc_attr($field_name) . ']">';
             echo PHP_EOL;
             //XSS ok
             foreach ($args['choices'] as $choice) {
                 echo '<option value="' . esc_attr($value) . '" ' . selected($value, $choice, false) . '>' . esc_attr($choice) . '</option>';
                 echo PHP_EOL;
                 //XSS ok
             }
             echo '</select>';
             echo PHP_EOL;
             //XSS ok
             break;
     }
 }