Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( ! class_exists( 'oxoScriptsClass' ) )
- {
- add_action( 'init', array( 'oxoScriptsClass', 'init' ) );
- /**
- * Loads all styles and scripts
- */
- class oxoScriptsClass
- {
- /**
- * The Class Object
- */
- static private $class = NULL;
- static $nearby_nonce_val = 'neary-nonce-val';
- /**
- * Handler for the action 'init'. Instantiates this class.
- *
- * @return void
- */
- public static function init()
- {
- if ( null === self::$class )
- self::$class = new self;
- return self::$class;
- }
- /**
- * Construct
- *
- * @return void
- */
- public function __construct()
- {
- // Custom function
- if ( is_login() )
- return;
- add_action( 'wp_enqueue_scripts', array( &$this, 'switch_jquery_google_cdn' ), 20 );
- add_action( 'wp_enqueue_scripts', array( &$this, 'load_jquery' ), 20 );
- # >>>> AJAX
- add_action( 'wp_enqueue_scripts', array( &$this, 'ajax_search' ), 30 );
- // Ajax Callbacks
- add_action( 'wp_ajax_nopriv_nearby_locations', array( &$this, 'nearby_locations_cb' ) );
- add_action( 'wp_ajax_nearby_locations', array( &$this, 'nearby_locations_cb' ) );
- # <<<<
- // DEV & DEBUG
- if ( $this->debug AND current_user_can( 'manage_options' ) )
- add_action( 'shutdown', array( &$this, '_dev' ) );
- }
- /**
- * Load jQuery from Google CDN
- * Fallback is WP core
- *
- * @since 0.3
- * @return void
- */
- public function switch_jquery_google_cdn()
- {
- global $wp_scripts;
- $http = is_ssl() ? 'https' : 'http';
- $ver = wp_script_is( 'jquery', 'registered' ) ? $wp_scripts->registered['jquery']->ver : '1';
- $min = defined( SCRIPT_DEBUG ) && SCRIPT_DEBUG ? '' : '.min';
- $src = "{$http}://ajax.googleapis.com/ajax/libs/jquery/{$ver}/jquery{$min}.js";
- wp_deregister_script( 'jquery' );
- wp_register_script( 'jquery', $src, array(), null, true );
- }
- /**
- * Enqueue jQuery
- *
- * @since 0.3
- * @return void
- */
- public function load_jquery()
- {
- wp_enqueue_script( 'jquery' );
- }
- /**
- * Registers & enqueues ajax script related stuff
- * For public search
- *
- * @since 0.3
- *
- * @return void
- */
- public function ajax_search()
- {
- wp_register_script( 'json2', false, array(), false, true );
- $url = get_stylesheet_directory_uri().'/lib/search/js';
- $deps = array( 'jquery', 'jquery-form', 'json2' );
- wp_register_script( 'nearby-locations-script', "{$url}/nearby_location.js", $deps, false, true );
- wp_enqueue_script( 'json2' );
- // Ajax: Location
- wp_enqueue_script( 'nearby-locations-script' );
- wp_localize_script(
- 'nearby-locations-script'
- ,'nearby_locations_object'
- ,array(
- 'ajaxurl' => admin_url( 'admin-ajax.php' )
- ,'nearby_nonce' => wp_create_nonce( self :: $nearby_nonce_val )
- ,'action' => 'nearby_locations'
- ,'type' => null
- ,'distance' => null
- ,'entry' => null
- )
- );
- # DEBUG:
- # echo '<pre>'; print_r( $GLOBALS['wp_filter'][ "wp_ajax_nopriv_nearby-parties" ] ); echo '</pre>';
- }
- /**
- * Ajax cb fn for
- *
- * @since 0.4
- *
- * @return string json result
- */
- public function nearby_locations_cb()
- {
- # check_ajax_referer( 'neary-nonce-val', 'nearby_nonce' );
- echo '<h1>NEARBY LOCATIONS CALLBACK FUNCTION</h1>';
- var_dump( $_REQUEST );
- var_dump( $_POST );
- var_dump( $_GET );
- $data = $_REQUEST;
- $package = json_encode( array(
- 'data' => 'FOO'
- ,'bla' => $_POST
- ,'data'=> $data
- ) );
- $response = "{$_GET['callback']} ( {$package} )";
- header( "Content-Type: application/json" );
- echo $response;
- exit;
- }
- } // END Class oxoThemeStylesScripts
- } // endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement