/** * Output the HTML for the alternate indexer * * @since 2.5 */ function alternate_indexer_view() { if (!current_user_can($this->settings_cap)) { wp_die(__('Invalid request', 'searchwp')); } $progress = searchwp_get_option('progress'); $form_action_url_params = array('page' => $this->textDomain); $form_action_url = add_query_arg($form_action_url_params, admin_url('options-general.php')); ?> <?php if (isset($_REQUEST['swpnonce'])) { ?> <div class="wrap"> <h3><?php _e('SearchWP Alternate Indexer', 'searchwp'); ?> </h3> <?php $nonce = wp_create_nonce('searchwp_alternate_indexer'); ?> <p><?php _e('Current progress:', 'searchwp'); ?> <?php echo esc_html($progress); ?> %</p> <p class="descripttion"><?php _e('If the percentage is not increasing it <strong>does not necessarily mean</strong> there is a problem. SearchWP takes multiple passes when indexing, please allow adequate time for the indexer to run.', 'searchwp'); ?> </p> <?php if (absint($progress) < 100) { ?> <p> <?php _e('Triggering next index chunk, please wait...', 'searchwp'); ?> <span class="spinner is-active" style="display:inline-block;float:none;position:relative;top:-4px;"></span> </p> <script type="text/javascript"> jQuery(document).ready(function($){ // noinspection JSUnresolvedVariable ajaxurl $.post(ajaxurl, { action: 'searchwp_alternate_indexer_trigger', nonce: '<?php echo esc_js($nonce); ?> ', swpnonce: '<?php echo esc_js($_REQUEST['swpnonce']); ?> ' }, function (res) { if (res.hash) { document.location.href = '<?php echo esc_url($form_action_url); ?> &swpnonce=' + res.hash; } else { document.location.href = '<?php echo esc_url($form_action_url); ?> '; } }, 'json'); }); </script> <?php } else { ?> <p><strong><?php _e('Index built!', 'searchwp'); ?> </strong></p> <script type="text/javascript"> document.location.href = '<?php echo esc_url($form_action_url); ?> '; </script> <?php } ?> </div> <?php } else { ?> <?php $indexer = new SearchWPIndexer(); $total = intval($indexer->count_total_posts()); $indexed = intval($indexer->indexed_count()); $num_remaining_posts_to_index = absint($total - $indexed); // if there are no more posts to index, we don't need to output any UI to trigger the index if (empty($num_remaining_posts_to_index)) { return; } $hash = sprintf('%.22F', microtime(true)); // inspired by $doing_wp_cron update_option('searchwp_transient', $hash); ?> <h3><?php _e('SearchWP Alternate Indexer', 'searchwp'); ?> </h3> <p><?php echo sprintf(__('There are <strong>%d</strong> entries left to index. <strong>YOU MUST LEAVE THIS BROWSER WINDOW OPEN</strong> during indexing.', 'searchwp'), absint($num_remaining_posts_to_index)); ?> </p> <p class="description"><?php _e('This action builds the initial index and only needs to be run once.', 'searchwp'); ?> </p> <form method="get" action="<?php echo esc_url($form_action_url); ?> "> <input type="hidden" name="page" value="searchwp" /> <input type="hidden" name="swpnonce" value="<?php echo esc_attr($hash); ?> " /> <p style="padding-bottom:2em;"> <button class="button button-primary" type="submit" name="submit"><?php esc_attr_e('Build Initial Index', 'searchwp'); ?> </button> </p> </form> <?php } ?> <?php }