function settings_license_nag()
    {
        $nag = $this->implement_nag(array('name' => 'license', 'nonce' => 'searchwpnagnnonce'));
        $searchwp = SWP();
        $notices = searchwp_get_setting('notices');
        $initial_notified = is_array($notices) && in_array('initial', $notices) ? true : false;
        if (false == $initial_notified && !empty($searchwp->license) && (isset($searchwp->status) && 'valid' !== $searchwp->status) && !$nag['dismissed'] && apply_filters('searchwp_initial_license_nag', true)) {
            ?>
			<div id="setting-error-settings_updated" class="updated settings-error swp-license-nag">
				<p><?php 
            _e('In order to receive updates and support, you must have an active license.', 'searchwp');
            ?>
 <a href="<?php 
            echo esc_url(add_query_arg(array('page' => 'searchwp', 'tab' => 'license'), admin_url('options.php')));
            ?>
"><?php 
            _e('Manage License', 'searchwp');
            ?>
</a> <a href="<?php 
            echo esc_url(SEARCHWP_EDD_STORE_URL);
            ?>
"><?php 
            _e('Purchase License', 'searchwp');
            ?>
</a> <a href="<?php 
            echo esc_url($nag['dismissal_link']);
            ?>
"><?php 
            _e('Dismiss', 'searchwp');
            ?>
</a></p>
			</div>
		<?php 
        }
    }
Esempio n. 2
0
 function wakeUpIndexer()
 {
     $running = searchwp_get_setting('running');
     if ($running) {
         echo 'Indexer thought it was running. ';
         searchwp_set_setting('running', false);
         searchwp_set_setting('total', null, 'stats');
         searchwp_set_setting('remaining', null, 'stats');
         searchwp_set_setting('done', null, 'stats');
         searchwp_set_setting('last_activity', null, 'stats');
     }
     $this->triggerIndex();
     echo 'Woken up.';
 }
 /**
  * Upgrade routines
  *
  * @since 1.0
  */
 private function upgrade()
 {
     global $wpdb, $searchwp;
     if (version_compare($this->last_version, '1.3.1', '<')) {
         // clean up misuse of cron schedule
         wp_clear_scheduled_hook('swp_cron_indexer');
     }
     if (version_compare($this->last_version, '1.6.7', '<')) {
         // truncate logs table
         $prefix = $wpdb->prefix . SEARCHWP_DBPREFIX;
         $tableName = $prefix . 'log';
         $wpdb->query("TRUNCATE TABLE {$tableName}");
     }
     if (version_compare($this->last_version, '1.8', '<')) {
         // fix a possible issue with settings storage resulting in MySQL errors after update
         $settings = get_option(SEARCHWP_PREFIX . 'settings');
         if (is_array($settings)) {
             // make sure additional array keys are present and defined
             foreach ($settings['engines'] as $engine_key => $engine_setting) {
                 foreach ($settings['engines'][$engine_key] as $post_type => $post_type_settings) {
                     if (is_array($settings['engines'][$engine_key][$post_type]) && isset($settings['engines'][$engine_key][$post_type]['options']) && !is_array($settings['engines'][$engine_key][$post_type]['options'])) {
                         $settings['engines'][$engine_key][$post_type]['options'] = array('exclude' => false, 'attribute_to' => false, 'stem' => false);
                     }
                 }
             }
         }
         searchwp_update_option('settings', $settings);
     }
     // index cleanup and optimization
     if (version_compare($this->last_version, '1.9', '<')) {
         $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'termindex'", ARRAY_N);
         if (!empty($index_exists)) {
             $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_terms DROP INDEX termindex;");
         }
         $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'stemindex'", ARRAY_N);
         if (!empty($index_exists)) {
             $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_terms DROP INDEX stemindex;");
         }
         $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'id'", ARRAY_N);
         if (!empty($index_exists)) {
             $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_terms DROP INDEX id;");
         }
         $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_index` WHERE Key_name = 'id'", ARRAY_N);
         if (!empty($index_exists)) {
             $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_index DROP INDEX id;");
         }
         $wpdb->query("CREATE INDEX termindex ON {$wpdb->prefix}swp_terms(term(2));");
         $wpdb->query("CREATE INDEX stemindex ON {$wpdb->prefix}swp_terms(stem(2));");
     }
     // consolidate settings into one database record
     if (version_compare($this->last_version, '1.9.1', '<')) {
         $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'termindex'", ARRAY_N);
         if (empty($index_exists)) {
             $wpdb->query("CREATE INDEX termindex ON {$wpdb->prefix}swp_terms(term(2));");
         }
         $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'stemindex'", ARRAY_N);
         if (empty($index_exists)) {
             $wpdb->query("CREATE INDEX stemindex ON {$wpdb->prefix}swp_terms(term(2));");
         }
         $old_settings = searchwp_get_option('settings');
         $engines = isset($old_settings['engines']) ? $old_settings['engines'] : array();
         // clear out the old settings because we're using the same key
         searchwp_delete_option('settings');
         // in with the new
         searchwp_generate_settings($engines);
         // delete the old options
         searchwp_delete_option('activated');
         searchwp_delete_option('license_nag');
         searchwp_delete_option('dismissed');
         searchwp_delete_option('ignored_queries');
         searchwp_delete_option('indexer_nag');
         searchwp_delete_option('valid_db_environment');
         searchwp_delete_option('running');
         searchwp_delete_option('total');
         searchwp_delete_option('remaining');
         searchwp_delete_option('done');
         searchwp_delete_option('in_process');
         searchwp_delete_option('initial');
         searchwp_delete_option('initial_notified');
         searchwp_delete_option('purgeQueue');
         searchwp_delete_option('processingPurgeQueue');
         searchwp_delete_option('mysql_version_nag');
         searchwp_delete_option('remote');
         searchwp_delete_option('remote_meta');
         searchwp_delete_option('paused');
         searchwp_delete_option('nuke_on_delete');
         searchwp_delete_option('indexnonce');
     }
     if (version_compare($this->last_version, '1.9.2.2', '<')) {
         searchwp_add_option('progress', -1);
     }
     if (version_compare($this->last_version, '1.9.4', '<')) {
         // clean up a potential useless settings save
         $live_settings = searchwp_get_option('settings');
         $update_settings_record = false;
         if (is_array($live_settings)) {
             foreach ($live_settings as $live_setting_key => $live_setting_value) {
                 // none of our keys should be numeric (specifically going after a rogue 'running' setting that
                 // may have been inadvertently set in 1.9.2, we just don't want it in there at all
                 if (is_numeric($live_setting_key)) {
                     unset($live_settings[$live_setting_key]);
                     $update_settings_record = true;
                 }
                 // also update 'nuke_on_delete' to be a boolean if necessary
                 if ('nuke_on_delete' === $live_setting_key) {
                     $live_settings['nuke_on_delete'] = empty($live_setting_value) ? false : true;
                     $update_settings_record = true;
                 }
             }
         }
         if ($update_settings_record) {
             // save the cleaned up settings array
             searchwp_update_option('settings', $live_settings);
             $searchwp->settings = $live_settings;
         }
     }
     if (version_compare($this->last_version, '1.9.5', '<')) {
         // move indexer-specific settings to their own record as they're being constantly updated
         $live_settings = searchwp_get_option('settings');
         $indexer_settings = array();
         // whether the initial index has been built
         if (isset($live_settings['initial_index_built'])) {
             $indexer_settings['initial_index_built'] = (bool) $live_settings['initial_index_built'];
             unset($live_settings['initial_index_built']);
         } else {
             $indexer_settings['initial_index_built'] = false;
         }
         // all of the stats
         if (isset($live_settings['stats'])) {
             $indexer_settings['stats'] = $live_settings['stats'];
             unset($live_settings['stats']);
         } else {
             $indexer_settings['stats'] = array();
         }
         // whether the indexer is running
         if (isset($live_settings['running'])) {
             $indexer_settings['running'] = (bool) $live_settings['running'];
             unset($live_settings['running']);
         } else {
             $indexer_settings['running'] = false;
         }
         // whether the indexer is paused (disabled)
         if (isset($live_settings['paused'])) {
             $indexer_settings['paused'] = (bool) $live_settings['paused'];
             unset($live_settings['paused']);
         } else {
             $indexer_settings['paused'] = false;
         }
         // whether the indexer is processing the purge queue
         if (isset($live_settings['processing_purge_queue'])) {
             $indexer_settings['processing_purge_queue'] = (bool) $live_settings['processing_purge_queue'];
             unset($live_settings['processing_purge_queue']);
         } else {
             $indexer_settings['processing_purge_queue'] = false;
         }
         // the purge queue will be moved to it's own option to avoid conflict
         if (isset($live_settings['purge_queue'])) {
             searchwp_add_option('purge_queue', $live_settings['purge_queue']);
             unset($live_settings['purge_queue']);
         }
         searchwp_update_option('settings', $live_settings);
         searchwp_add_option('indexer', $indexer_settings);
     }
     if (version_compare($this->last_version, '1.9.6', '<')) {
         // wake up the indexer if necessary
         $running = searchwp_get_setting('running');
         if (empty($running)) {
             searchwp_set_setting('running', false);
         }
     }
     // make ignored queries for search stats per-user
     if (version_compare($this->last_version, '2.0.2', '<')) {
         $user_id = get_current_user_id();
         if ($user_id) {
             $ignored_queries = searchwp_get_setting('ignored_queries');
             update_user_meta($user_id, SEARCHWP_PREFIX . 'ignored_queries', $ignored_queries);
         }
     }
     // add 'busy' option
     if (version_compare($this->last_version, '2.1.5', '<')) {
         searchwp_add_option('busy', false);
         searchwp_add_option('doing_delta', false);
     }
     // force a wakeup
     if (version_compare($this->last_version, '2.2.1', '<')) {
         if (function_exists('searchwp_wake_up_indexer')) {
             searchwp_wake_up_indexer();
         }
     }
     // add new 'waiting' flag, prep for possible new custom endpoint, clear out redundant post meta
     if (version_compare($this->last_version, '2.3', '<')) {
         searchwp_add_option('waiting', false);
         searchwp_set_setting('endpoint', '');
         // now using last_index instead of indexed, we don't need separate records
         $wpdb->delete($wpdb->prefix . 'postmeta', array('meta_key' => '_' . SEARCHWP_PREFIX . 'indexed'));
     }
     if (version_compare($this->last_version, '2.4.5', '<')) {
         // implement our settings backup
         $live_settings = searchwp_get_option('settings');
         $settings_backups = array();
         $settings_backups[current_time('timestamp')] = $live_settings;
         searchwp_add_option('settings_backup', $settings_backups);
         // there was a bug triggered by a custom post type name of 'label' that caused issues
         // so we need to update all of the supplemental engine label keys to searchwp_engine_label
         // which will not trigger the issue because it is 21 characters in length and WordPress
         // requires post type names to be 20 characters or less
         if (isset($live_settings['engines'])) {
             foreach ($live_settings['engines'] as $live_settings_engine_key => $live_settings_engine_values) {
                 if (isset($live_settings_engine_values['label'])) {
                     $engine_label = $live_settings_engine_values['label'];
                     unset($live_settings['engines'][$live_settings_engine_key]['label']);
                     $live_settings['engines'][$live_settings_engine_key]['searchwp_engine_label'] = $engine_label;
                 }
             }
         }
         searchwp_update_option('settings', $live_settings);
     }
     /**
      * The upgrade routine for 2.5.7 was designed to implement support for utf8mb4 as per WordPress 4.2, it even
      * used the same code to do so. Unfortunately the index key changes and charset changes can take a very (very)
      * long time depending on the power of the server and the size of the database tables. Unfortunately SearchWP's
      * tables are quite large, and the update routine took *way* too long on some test machines. While the update
      * was running, performance on the front end was erratic at best, primarily because the table updates caused
      * MySQL to utilize ~100% CPU, thus preventing other traffic from reaching the server. As a result, existing
      * installations of SearchWP will not be converted to utf8mb4, only fresh installations. The indexer and search
      * algorithm will actively strip out problematic characters (e.g. emoji) if the tables are not prepared for them.
      *
     
     if ( version_compare( $this->last_version, '2.5.7', '<' ) ) {
     
     	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     
     	SWP()->indexer_pause();
     
     	// utf8mb4 index length limit is 191 @link https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/
     	$wpdb->query( "ALTER TABLE {$wpdb->prefix}swp_cf DROP INDEX metakey, ADD INDEX metakey(metakey(191));" );
     	$wpdb->query( "ALTER TABLE {$wpdb->prefix}swp_log DROP INDEX queryindex, ADD INDEX queryindex(query(191));" );
     	$wpdb->query( "ALTER TABLE {$wpdb->prefix}swp_log DROP INDEX engineindex, ADD INDEX engineindex(engine(191));" );
     
     	// loop through tables and upgrade them to utf8mb4
     	$tables = array(
     		$wpdb->prefix . 'swp_cf',
     		$wpdb->prefix . 'swp_index',
     		$wpdb->prefix . 'swp_log',
     		$wpdb->prefix . 'swp_tax',
     		$wpdb->prefix . 'swp_terms',
     	);
     
     	$successful = true;
     
     	foreach ( $tables as $table ) {
     
     		// WordPress 4.2 added maybe_convert_table_to_utf8mb4() but
     		// we don't necessarily have access to it (e.g. user is running <4.2)
     		// but we also don't want to have to keep track of what WP version
     		// is in play and have to continually compare that to whether this
     		// upgrade routine has run so the function has been copied verbatim
     		// for use here because utf8mb4 is fully backwards compatible so we're
     		// going for the full upgrade by using a copy of that function
     
     		$result = searchwp_maybe_convert_table_to_utf8mb4( $table );
     		if ( ( is_wp_error( $result ) || false === $result ) ) {
     			// there was a problem
     			$successful = false;
     		}
     	}
     
     	if ( ! $successful ) {
     		// there was a problem with the utf8mb4 upgrade but that doesn't necessarily
     		// mean there is a show-stopping issue, just that the table is still utf8
     		// so log that the upgrade failed and indicate it in System Info
     		searchwp_add_option( 'utf8mb4_upgrade_failed', true );
     	}
     
     	SWP()->indexer_unpause();
     }
     */
 }
Esempio n. 4
0
 function swp_dismiss_filter_conflict()
 {
     // verify the request
     if (isset($_REQUEST['swphash']) && isset($_REQUEST['swpnonce']) && isset($_REQUEST['swpfilter'])) {
         if (wp_verify_nonce($_REQUEST['swpnonce'], 'swpconflict_' . $_REQUEST['swpfilter'])) {
             // grab our existing dismissals and make sure our array key is set up
             $existing_dismissals = searchwp_get_setting('dismissed');
             if (!is_array($existing_dismissals)) {
                 $existing_dismissals = array();
             }
             if (!isset($existing_dismissals['filter_conflicts'])) {
                 $existing_dismissals['filter_conflicts'] = array();
             }
             // add this dismissal to the list and save it
             $existing_dismissals['filter_conflicts'][] = sanitize_text_field($_REQUEST['swphash']);
             $existing_dismissals['filter_conflicts'] = array_unique($existing_dismissals['filter_conflicts']);
             searchwp_set_setting('dismissed', $existing_dismissals);
         }
     }
     die;
 }
<?php

if ( ! defined( 'ABSPATH' ) ) {
	die();
}

$parent = SWP();

$parent->define_keys();
$lazy_settings = apply_filters( 'searchwp_lazy_settings', false );

// progress of indexer
$remainingPostsToIndex = searchwp_get_setting( 'remaining', 'stats' );
$progress = searchwp_get_option( 'progress' );
if ( ! $parent->is_using_alternate_indexer() && ( ! is_bool( $remainingPostsToIndex ) || ( is_numeric( $progress ) && $progress > 0 && $progress < 100 ) ) ) {
	$remainingPostsToIndex = absint( $remainingPostsToIndex );
	?>
	<div class="updated settings-error swp-in-progress<?php if ( 0 === $remainingPostsToIndex ) : ?> swp-in-progress-done<?php endif; ?>">
		<div class="swp-progress-wrapper">
			<p class="swp-label"><?php _e( 'Indexing is', 'searchwp' ); ?>
				<span><?php _e( 'almost', 'searchwp' ); ?></span> <?php _e( 'complete', 'searchwp' ); ?>
				<a class="swp-tooltip" href="#swp-tooltip-progress">?</a></p>

			<div class="swp-tooltip-content" id="swp-tooltip-progress">
				<?php _e( 'This process is running in the background. You can leave this page and the index will continue to be built until completion.', 'searchwp' ); ?>
			</div>
			<div class="swp-progress-track">
				<div class="swp-progress-bar"></div>
			</div>
			<p class="description"><?php echo sprintf( __( 'The indexer has been <strong>temporarily scaled back</strong> to reduce server load. This is monitored automatically. <a href="%s">More information &raquo;</a>', 'searchwp' ), 'http://searchwp.com/?p=11818' ); ?></p>
		</div>
    /**
     * Callback for plugin activation, outputs admin notice
     *
     * @since 1.0
     */
    function activation()
    {
        if (false == searchwp_get_setting('activated')) {
            searchwp_set_setting('activated', 1);
            // reset the counts
            if (class_exists('SearchWPIndexer')) {
                $indexer = new SearchWPIndexer();
                $indexer->update_running_counts();
            }
            ?>
			<div class="updated">
				<p><?php 
            echo sprintf(__('SearchWP has been activated and the index is now being built. <a href="%s">View progress and settings</a>', 'searchwp'), esc_url(admin_url('options-general.php?page=searchwp')));
            ?>
</p>
			</div>
			<?php 
            // trigger the initial indexing
            do_action('searchwp_log', 'Request index (activation)');
            $this->trigger_index();
        }
    }
Esempio n. 7
0
 /**
  * Checks the stored in-process post IDs and existing index to ensure a rogue parallel indexer is not running
  *
  * @since 1.9
  */
 function check_for_parallel_indexer()
 {
     global $wpdb;
     if (is_array($this->unindexedPosts) && count($this->unindexedPosts)) {
         // prevent parallel indexers
         $ids_to_index = array();
         foreach ($this->unindexedPosts as $unindexed_post) {
             $ids_to_index[] = (int) $unindexed_post->ID;
         }
         reset($this->unindexedPosts);
         // check what's in process *right now*
         $in_process = searchwp_get_setting('in_process', 'stats');
         if (is_array($in_process)) {
             $in_process = array_intersect($ids_to_index, $in_process);
         }
         // check the index too
         $ids_to_index_sql = implode(',', $ids_to_index);
         $index_table = $wpdb->prefix . SEARCHWP_DBPREFIX . 'index';
         $ids_to_index_sql = "SELECT post_id  FROM {$index_table} WHERE post_id IN ({$ids_to_index_sql}) GROUP BY post_id LIMIT 100";
         $already_indexed = $wpdb->get_col($ids_to_index_sql);
         $already_indexed = array_map('absint', $already_indexed);
         // if it's in the index, force the indexed flag
         if (is_array($already_indexed) && !empty($already_indexed)) {
             foreach ($already_indexed as $already_indexed_key => $already_indexed_id) {
                 do_action('searchwp_log', (int) $already_indexed_id . ' is already in the index');
                 // if we're not dealing with a term queue, mark this post as indexed
                 if (!get_post_meta((int) $already_indexed_id, '_' . SEARCHWP_PREFIX . 'terms', true)) {
                     update_post_meta((int) $already_indexed_id, '_' . SEARCHWP_PREFIX . 'indexed', true);
                 } else {
                     // this is a term chunk update, not a conflict
                     unset($already_indexed[$already_indexed_key]);
                 }
             }
         }
         // combine the two results so we have one collection of conflicts
         $conflicts = is_array($in_process) ? array_values(array_merge((array) $in_process, (array) $already_indexed)) : (array) $already_indexed;
         if (!empty($conflicts)) {
             do_action('searchwp_log', 'Parallel indexer detected when attempting to index: ' . implode(', ', $conflicts));
             die;
         }
         searchwp_set_setting('in_process', $ids_to_index, 'stats');
     }
 }
 function searchwp_check_for_stalled_indexer($threshold = 180)
 {
     $last_activity = searchwp_get_setting('last_activity', 'stats');
     $running = searchwp_get_setting('running');
     $doing_delta = searchwp_get_option('doing_delta');
     $busy = searchwp_get_option('busy');
     if (!is_null($last_activity) && false !== $last_activity) {
         if (current_time('timestamp') > $last_activity + absint($threshold) && ($running || $doing_delta || $busy)) {
             // stalled
             do_action('searchwp_log', '---------- Indexer has stalled, jumpstarting');
             searchwp_wake_up_indexer();
         }
     } else {
         // prior to version 2.2.2 the last activity was set to false once indexing was done
         // so if that timestamp is false but there is still a purge queue, we're going to
         // wake up the indexer by force
         $purge_queue = searchwp_get_option('purge_queue');
         if (!empty($purge_queue)) {
             searchwp_wake_up_indexer();
         } else {
             if (current_time('timestamp') > $last_activity + absint($threshold) && ($running || $doing_delta || $busy)) {
                 // stalled
                 do_action('searchwp_log', '---------- Indexer has stalled [alt], jumpstarting');
                 searchwp_wake_up_indexer();
             }
         }
     }
 }
    /**
     * Detect whether other plugins are using the hooks SearchWP absolutely depends on as they're likely to cause interference
     */
    function conflicts()
    {
        // allow developers to disable potential conflict notices if they want
        $maybe_debugging = apply_filters('searchwp_debug', false);
        $show_conflict_notices = apply_filters('searchwp_show_conflict_notices', $maybe_debugging);
        if (!class_exists('SearchWP_Conflicts')) {
            return;
        }
        $conflicts = new SearchWP_Conflicts();
        // whether the JavaScript for these notices has been output
        $javascript_deployed = false;
        // output a notification if there are potential query_posts or WP_Query conflicts in search.php
        if ($conflicts->search_template && apply_filters('searchwp_show_conflict_notices', true)) {
            if (!empty($conflicts->search_template_conflicts)) {
                add_action('admin_footer', array($this, 'filter_conflict_javascript'));
                $javascript_deployed = true;
                ?>
				<div class="updated">
					<p><?php 
                _e('SearchWP has detected a <strong>theme conflict</strong> with the active theme.', 'searchwp');
                ?>
 <a class="swp-conflict-toggle swp-theme-conflict-show" href="#searchwp-conflict-theme"><?php 
                _e('More info &raquo;', 'searchwp');
                ?>
</a></p>
					<div id="searchwp-conflict-theme" style="background:#fafafa;border:1px solid #eaeaea;padding:0.6em 1.2em;border-radius:2px;margin-bottom:1em;display:none;">
						<p><?php 
                _e("In order for SearchWP to display it's results, occurrences of <code>new WP_Query</code> and <code>query_posts()</code> must be removed from your search results template.", 'searchwp');
                ?>
</p>
						<p>
							<strong><?php 
                _e('File location', 'searchwp');
                ?>
:</strong>
							<code><?php 
                echo esc_html($conflicts->search_template);
                ?>
</code>
						</p>
						<?php 
                foreach ($conflicts->search_template_conflicts as $line_number => $conflicts) {
                    ?>
							<?php 
                    $conflicts = array_map('esc_html', $conflicts);
                    ?>
							<p>
								<strong><?php 
                    _e('Line', 'searchwp');
                    ?>
: <?php 
                    echo absint($line_number);
                    ?>
</strong>
								<code><?php 
                    echo implode('</code>, <code>', $conflicts);
                    ?>
</code>
							</p>
						<?php 
                }
                ?>
						<p><?php 
                _e('Please ensure the offending lines are removed from the theme template to avoid conflicts with SearchWP. When removed, this notice will disappear. You may also dismiss this message using', 'searchwp');
                ?>
</p>
						<p class="description"><?php 
                _e("You may dismiss this (and all like this) message by adding <code>add_filter( 'searchwp_show_conflict_notices', '__return_false' );</code> to your theme's <code>functions.php</code>.", 'searchwp');
                ?>
</p>
					</div>
				</div>
			<?php 
            }
        }
        // output a notification if there are potential action/filter conflicts
        $show_filter_notices = apply_filters('searchwp_show_filter_conflict_notices', false);
        if ($show_filter_notices && $show_conflict_notices && !empty($conflicts->filter_conflicts)) {
            foreach ($conflicts->filter_conflicts as $filter_name => $potential_conflict) {
                $show_conflict = true;
                // user may have already dismissed this conflict so let's check
                $existing_dismissals = searchwp_get_setting('dismissed');
                // dismissals are stored as hashes of the hooks as they were when the dismissal was enabled
                $conflict_hash = md5(json_encode($potential_conflict));
                $conflict_nonce = wp_create_nonce('swpconflict_' . $filter_name);
                // check to see if this particular filter conflict was already dismissed
                if (is_array($existing_dismissals)) {
                    if (isset($existing_dismissals['filter_conflicts']) && is_array($existing_dismissals['filter_conflicts'])) {
                        if (in_array($conflict_hash, $existing_dismissals['filter_conflicts'])) {
                            $show_conflict = false;
                        }
                    }
                }
                if ($show_conflict) {
                    // dump out the JavaScript that allows dismissals
                    if (!$javascript_deployed) {
                        add_action('admin_footer', array($this, 'filter_conflict_javascript'));
                        $javascript_deployed = true;
                    }
                    ?>
					<div class="updated">
						<p><?php 
                    echo sprintf(__('SearchWP has detected a <strong>potential (<em>not guaranteed</em>)</strong> action/filter conflict with <code>%s</code> caused by an active plugin or the active theme.', 'searchwp'), esc_html($filter_name));
                    ?>
 <a class="swp-conflict-toggle swp-filter-conflict-show" href="#searchwp-conflict-<?php 
                    echo esc_attr($filter_name);
                    ?>
"><?php 
                    _e('More info &raquo;', 'searchwp');
                    ?>
</a></p>
						<div id="searchwp-conflict-<?php 
                    echo esc_attr($filter_name);
                    ?>
" style="background:#fafafa;border:1px solid #eaeaea;padding:0.6em 1.2em;border-radius:2px;margin-bottom:1em;display:none;">
							<p><?php 
                    _e('<strong>This is simply a <em>preliminary</em> detection of a <em>possible</em> conflict.</strong> Many times these detections can be <strong>safely dismissed</strong>', 'searchwp');
                    ?>
</p>
							<p><?php 
                    _e('<em>If (and only if) you are experiencing issues</em> with search results not changing or not appearing, the following Hooks (put in place by other plugins or your active theme) <em>may be</em> contributing to the problem:', 'searchwp');
                    ?>
</p>
							<ol>
								<?php 
                    foreach ($potential_conflict as $conflict) {
                        ?>
									<?php 
                        // if it was class based we'll break out the class
                        if (strpos($conflict, '::')) {
                            $conflict = explode('::', $conflict);
                            $conflict = '<code>' . esc_html($conflict[1]) . '</code> ' . __('(method) in', 'searchwp') . ' <code>' . esc_html($conflict[0]) . '</code>' . __(' (class)', 'searchwp');
                        } else {
                            $conflict = '<code>' . esc_html($conflict) . '</code> ' . __('(function)', 'searchwp');
                        }
                        ?>
									<li><?php 
                        echo $conflict;
                        ?>
</li>
								<?php 
                    }
                    ?>
							</ol>
							<?php 
                    $filter_resolution_url = '#';
                    if (is_array($conflicts->filter_checklist) && array_key_exists($filter_name, $conflicts->filter_checklist)) {
                        $filter_resolution_url = esc_url($conflicts->filter_checklist[$filter_name]);
                    }
                    ?>
							<p><?php 
                    echo sprintf(__('<strong>If you believe there to be a conflict (e.g. search results not showing up):</strong> use this information you can determine how to best disable this interference. For more information please see <a href="%s">this Knowledge Base article</a>.', 'searchwp'), esc_url($filter_resolution_url));
                    ?>
</p>
							<p><a class="button swp-dismiss-conflict" href="#" data-hash="<?php 
                    echo esc_attr($conflict_hash);
                    ?>
" data-nonce="<?php 
                    echo esc_attr($conflict_nonce);
                    ?>
" data-filter="<?php 
                    echo esc_attr($filter_name);
                    ?>
"><?php 
                    _e('Dismiss this message', 'searchwp');
                    ?>
</a></p>
						</div>
					</div>
				<?php 
                }
            }
        }
    }
Esempio n. 10
0
 /**
  * Upgrade routines
  *
  * @since 1.0
  */
 private function upgrade()
 {
     global $wpdb, $searchwp;
     if (version_compare($this->last_version, '1.3.1', '<')) {
         // clean up misuse of cron schedule
         wp_clear_scheduled_hook('swp_cron_indexer');
     }
     if (version_compare($this->last_version, '1.6.7', '<')) {
         // truncate logs table
         $prefix = $wpdb->prefix . SEARCHWP_DBPREFIX;
         $tableName = $prefix . 'log';
         $wpdb->query("TRUNCATE TABLE {$tableName}");
     }
     if (version_compare($this->last_version, '1.8', '<')) {
         // fix a possible issue with settings storage resulting in MySQL errors after update
         $settings = get_option(SEARCHWP_PREFIX . 'settings');
         if (is_array($settings)) {
             // make sure additional array keys are present and defined
             foreach ($settings['engines'] as $engine_key => $engine_setting) {
                 foreach ($settings['engines'][$engine_key] as $post_type => $post_type_settings) {
                     if (is_array($settings['engines'][$engine_key][$post_type]) && !is_array($settings['engines'][$engine_key][$post_type]['options'])) {
                         $settings['engines'][$engine_key][$post_type]['options'] = array('exclude' => false, 'attribute_to' => false, 'stem' => false);
                     }
                 }
             }
         }
         searchwp_update_option('settings', $settings);
     }
     // index cleanup and optimization
     if (version_compare($this->last_version, '1.9', '<')) {
         $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'termindex'", ARRAY_N);
         if (!empty($index_exists)) {
             $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_terms DROP INDEX termindex;");
         }
         $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'stemindex'", ARRAY_N);
         if (!empty($index_exists)) {
             $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_terms DROP INDEX stemindex;");
         }
         $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'id'", ARRAY_N);
         if (!empty($index_exists)) {
             $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_terms DROP INDEX id;");
         }
         $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_index` WHERE Key_name = 'id'", ARRAY_N);
         if (!empty($index_exists)) {
             $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_index DROP INDEX id;");
         }
         $wpdb->query("CREATE INDEX termindex ON {$wpdb->prefix}swp_terms(term(2));");
         $wpdb->query("CREATE INDEX stemindex ON {$wpdb->prefix}swp_terms(stem(2));");
     }
     // consolidate settings into one database record
     if (version_compare($this->last_version, '1.9.1', '<')) {
         $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'termindex'", ARRAY_N);
         if (empty($index_exists)) {
             $wpdb->query("CREATE INDEX termindex ON {$wpdb->prefix}swp_terms(term(2));");
         }
         $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'stemindex'", ARRAY_N);
         if (empty($index_exists)) {
             $wpdb->query("CREATE INDEX stemindex ON {$wpdb->prefix}swp_terms(term(2));");
         }
         $old_settings = searchwp_get_option('settings');
         $engines = isset($old_settings['engines']) ? $old_settings['engines'] : array();
         // clear out the old settings because we're using the same key
         searchwp_delete_option('settings');
         // in with the new
         searchwp_generate_settings($engines);
         // delete the old options
         searchwp_delete_option('activated');
         searchwp_delete_option('license_nag');
         searchwp_delete_option('dismissed');
         searchwp_delete_option('ignored_queries');
         searchwp_delete_option('indexer_nag');
         searchwp_delete_option('valid_db_environment');
         searchwp_delete_option('running');
         searchwp_delete_option('total');
         searchwp_delete_option('remaining');
         searchwp_delete_option('done');
         searchwp_delete_option('in_process');
         searchwp_delete_option('initial');
         searchwp_delete_option('initial_notified');
         searchwp_delete_option('purgeQueue');
         searchwp_delete_option('processingPurgeQueue');
         searchwp_delete_option('mysql_version_nag');
         searchwp_delete_option('remote');
         searchwp_delete_option('remote_meta');
         searchwp_delete_option('paused');
         searchwp_delete_option('nuke_on_delete');
         searchwp_delete_option('indexnonce');
     }
     if (version_compare($this->last_version, '1.9.2.2', '<')) {
         searchwp_add_option('progress', -1);
     }
     if (version_compare($this->last_version, '1.9.4', '<')) {
         // clean up a potential useless settings save
         $live_settings = searchwp_get_option('settings');
         $update_settings_record = false;
         if (is_array($live_settings)) {
             foreach ($live_settings as $live_setting_key => $live_setting_value) {
                 // none of our keys should be numeric (specifically going after a rogue 'running' setting that
                 // may have been inadvertently set in 1.9.2, we just don't want it in there at all
                 if (is_numeric($live_setting_key)) {
                     unset($live_settings[$live_setting_key]);
                     $update_settings_record = true;
                 }
                 // also update 'nuke_on_delete' to be a boolean if necessary
                 if ('nuke_on_delete' === $live_setting_key) {
                     $live_settings['nuke_on_delete'] = empty($live_setting_value) ? false : true;
                     $update_settings_record = true;
                 }
             }
         }
         if ($update_settings_record) {
             // save the cleaned up settings array
             searchwp_update_option('settings', $live_settings);
             $searchwp->settings = $live_settings;
         }
     }
     if (version_compare($this->last_version, '1.9.5', '<')) {
         // move indexer-specific settings to their own record as they're being constantly updated
         $live_settings = searchwp_get_option('settings');
         $indexer_settings = array();
         // whether the initial index has been built
         if (isset($live_settings['initial_index_built'])) {
             $indexer_settings['initial_index_built'] = (bool) $live_settings['initial_index_built'];
             unset($live_settings['initial_index_built']);
         } else {
             $indexer_settings['initial_index_built'] = false;
         }
         // all of the stats
         if (isset($live_settings['stats'])) {
             $indexer_settings['stats'] = $live_settings['stats'];
             unset($live_settings['stats']);
         } else {
             $indexer_settings['stats'] = array();
         }
         // whether the indexer is running
         if (isset($live_settings['running'])) {
             $indexer_settings['running'] = (bool) $live_settings['running'];
             unset($live_settings['running']);
         } else {
             $indexer_settings['running'] = false;
         }
         // whether the indexer is paused (disabled)
         if (isset($live_settings['paused'])) {
             $indexer_settings['paused'] = (bool) $live_settings['paused'];
             unset($live_settings['paused']);
         } else {
             $indexer_settings['paused'] = false;
         }
         // whether the indexer is processing the purge queue
         if (isset($live_settings['processing_purge_queue'])) {
             $indexer_settings['processing_purge_queue'] = (bool) $live_settings['processing_purge_queue'];
             unset($live_settings['processing_purge_queue']);
         } else {
             $indexer_settings['processing_purge_queue'] = false;
         }
         // the purge queue will be moved to it's own option to avoid conflict
         if (isset($live_settings['purge_queue'])) {
             searchwp_add_option('purge_queue', $live_settings['purge_queue']);
             unset($live_settings['purge_queue']);
         }
         searchwp_update_option('settings', $live_settings);
         searchwp_add_option('indexer', $indexer_settings);
     }
     if (version_compare($this->last_version, '1.9.6', '<')) {
         // wake up the indexer if necessary
         $running = searchwp_get_setting('running');
         if (empty($running)) {
             searchwp_set_setting('running', false);
         }
     }
     // make ignored queries for search stats per-user
     if (version_compare($this->last_version, '2.0.2', '<')) {
         $user_id = get_current_user_id();
         if ($user_id) {
             $ignored_queries = searchwp_get_setting('ignored_queries');
             update_user_meta($user_id, SEARCHWP_PREFIX . 'ignored_queries', $ignored_queries);
         }
     }
     // add 'busy' option
     if (version_compare($this->last_version, '2.1.5', '<')) {
         searchwp_add_option('busy', false);
         searchwp_add_option('doing_delta', false);
     }
     // force a wakeup
     if (version_compare($this->last_version, '2.2.1', '<')) {
         if (function_exists('searchwp_wake_up_indexer')) {
             searchwp_wake_up_indexer();
         }
     }
 }
	/**
	 * Callback if user chose to restore conflict notices
	 */
	function conflict_notices_reset() {
		if ( ! $this->is_valid_action_request( 'conflict_notices_reset' ) ) {
			return;
		}

		$existing_dismissals = searchwp_get_setting( 'dismissed' );
		$existing_dismissals['filter_conflicts'] = array();
		searchwp_set_setting( 'dismissed', $existing_dismissals );
	}
    /**
     * Main (engines) settings view
     */
    function render_view_engine()
    {
        // output a notice for the initial index being built
        $notices = searchwp_get_setting('notices');
        $initial_notified = is_array($notices) && in_array('initial', $notices) ? true : false;
        if (searchwp_get_setting('initial_index_built') && !$initial_notified) {
            ?>
			<div class="updated">
				<p><?php 
            _e('Initial index has been built, the progress bar will be hidden until it is needed again.', 'searchwp');
            ?>
</p>
			</div>
			<?php 
            if (is_array($notices)) {
                $notices[] = 'initial';
            } else {
                $notices = array('initial');
            }
            searchwp_set_setting('notices', $notices);
            ?>
		<?php 
        }
        include dirname(__FILE__) . '/view-settings-engines.php';
    }