예제 #1
0
파일: core.php 프로젝트: kalushta/darom
/**
 * Register items to index, post types, taxonomies, and custom fields
 *
 * @return void
 */
function cp_register_search_index_items()
{
    if (!current_theme_supports('app-search-index') || isset($_GET['firstrun'])) {
        return;
    }
    // Ad listings
    $listing_custom_fields = array_merge(cp_custom_search_fields(), array('cp_sys_ad_conf_id'));
    $listing_index_args = array('meta_keys' => $listing_custom_fields, 'taxonomies' => array(APP_TAX_CAT, APP_TAX_TAG));
    APP_Search_Index::register(APP_POST_TYPE, $listing_index_args);
    // Blog posts
    $post_index_args = array('taxonomies' => array('category', 'post_tag'));
    APP_Search_Index::register('post', $post_index_args);
    // Pages
    APP_Search_Index::register('page');
}
예제 #2
0
    function admin_print_footer_scripts()
    {
        global $wpdb;
        ?>

<script type="text/javascript">
jQuery(document).ready(function($) {
	if ( $("form input[name^='search_index']").length ) {
		$('form p.submit').html('');
	}
});
</script>

<?php 
        if (!empty($_POST['search_index']['update_index'])) {
            $total_listings = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_content_filtered = '' AND post_type IN ('" . implode("', '", APP_Search_Index::get_registered_post_types()) . "')");
            $speed = isset($_POST['search_index']['speed']) ? $_POST['search_index']['speed'] : 'slow';
            $speed = self::get_index_speed($speed);
            ?>

<script type="text/javascript">
	jQuery(document).ready(function($){
		var si_total = <?php 
            echo $total_listings;
            ?>
;
		var si_speed = <?php 
            echo $speed;
            ?>
;
		var si_count = 1;
		var si_percent = 0;
		var si_nonce = "<?php 
            echo wp_create_nonce('build-index');
            ?>
";
		var si_timestart = new Date().getTime();
		var si_continue = true;

		// Create the progress bar
		$("#search-index-progress-bar").progressbar();
		$("#search-index-progress-bar-percent").html( "0%" );

		// Called after each indexing. Updates the progress bar.
		function appthemes_search_index_update_status( success, data ) {
			si_percent = ( si_count / si_total ) * 100;
			if ( si_percent > 100 ) {
				si_percent = 100;
			}
			$("#search-index-progress-bar").progressbar( "value", si_percent );
			$("#search-index-progress-bar-percent").html( Math.round( si_percent ) + "%" );
			si_count = si_count + si_speed;

			if ( ! success || data.completed == true ) {
				si_continue = false;
			}
		}

		// Called when all posts have been processed.
		function appthemes_search_index_finish( data ) {
			$("#search-index-message").html( data.message );
		}

		// Generate search index via AJAX
		function appthemes_search_index_process() {
			$.ajax({
				type: 'POST',
				url: ajaxurl,
				dataType: "json",
				data: {
					action: "build-search-index",
					speed: si_speed,
					nonce: si_nonce
				},
				success: function( data ) {
					if ( data.success == true ) {
						appthemes_search_index_update_status( true, data );
					} else {
						appthemes_search_index_update_status( false, data );
					}

					if ( si_continue ) {
						setTimeout( appthemes_search_index_process, 1000 );
					} else {
						appthemes_search_index_finish( data );
					}
				},
				error: function( data ) {
					appthemes_search_index_update_status( false, data );

					if ( si_continue ) {
						appthemes_search_index_process();
					} else {
						appthemes_search_index_finish( data );
					}
				}
			});
		}

		appthemes_search_index_process();
	});
</script>

<?php 
        }
    }
예제 #3
0
function appthemes_update_search_index($post, $return_updated_post = true)
{
    return APP_Search_Index::update_search_index($post, $return_updated_post);
}