associate_option_name ) ) { add_option( $this->associate_option_name, '' ); } if( !get_option( $this->country_option_name ) ) { add_option( $this->country_option_name, 'com' ); } } /** * Function called when the plugin is deactivated. It removes the option that is * used to hold your Amazon affiliate Id. */ function on_deactivate() { if( FALSE !== get_option( $this->associate_option_name ) ) { delete_option( $this->associate_option_name ); } } /** * When in the administrative section, perform these actions. */ function on_admin_menu() { // If we're on the write post or write page interface, add the Amazon Reloaded javascript if( strpos( $_SERVER['REQUEST_URI'], 'post-new.php' ) || strpos( $_SERVER['REQUEST_URI'], 'page-new.php' ) || strpos( $_SERVER['REQUEST_URI'], 'post.php' ) || strpos( $_SERVER['REQUEST_URI'], 'page.php' )) { wp_enqueue_script( 'amazon-reloaded', '/wp-content/plugins/amazon-reloaded-for-wordpress/js/amazon-reloaded.js', array( 'jquery' ) ); } // Add the plugin option page $plugin_page = add_submenu_page( 'plugins.php', 'WP-Amazon Reloaded', 'WP-Amazon Reloaded', 8, basename( __FILE__ ), array( &$this, 'plugin_page' ) ); // Add the javascript for the plugin page add_action( "admin_print_scripts-$plugin_page", array( &$this, 'plugin_print_scripts' ) ); // Add the meta box to the post and page interfaces. It is assigned a type of normal so it appears below the categories add_meta_box( 'Amazon Reloaded', 'Amazon Reloaded', array( &$this, 'meta_box_output' ), 'post', 'normal' ); add_meta_box( 'Amazon Reloaded', 'Amazon Reloaded', array( &$this, 'meta_box_output' ), 'page', 'normal' ); } /** * Runs in the header of the administrative panel. */ function on_admin_head() { echo ''; } /** * Produces the output for the WP Amazon Reloaded plugin page. * */ function plugin_page() { include( dirname( __FILE__ ) . '/pages/settings.php' ); } /** * Prints a script to the head for the plugins page. * */ function plugin_print_scripts() { } /** * Provides the output for the Amazon meta box. */ function meta_box_output() { ?>

country_option_name ); $request.="/onca/xml?Service=AWSECommerceService"; $request.="&AWSAccessKeyId=" . urlencode( KEY_ID ); $request.="&AssociateTag=" . urlencode( get_option( $this->associate_option_name ) ); $request.="&Version=2008-04-07"; $request.="&Operation=ItemSearch"; $request.="&SearchIndex=Blended"; $request.="&ContentType=text/html"; $request.="&Style=http://ohrnventures.com/WP-Amazon-Reloaded/WP-Amazon-Reloaded.xslt"; $request.="&ResponseGroup=Images,ItemAttributes"; $request.="&Keywords=" . urlencode( $_POST['keywords'] ); // We do a manual one-step redirect here if( function_exists( 'curl_init' ) ) { // Start the cURL session $session = curl_init( $request ); // Set some cURL options curl_setopt( $session, CURLOPT_HEADER, true ); curl_setopt( $session, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $session, CURLOPT_FOLLOWLOCATION, false ); // Execute the cURL request $redirect_response = curl_exec( $session ); // Grab the location URL from the initial response preg_match("/Location: (.*)/si", $redirect_response, $matches); // Closes the initial session curl_close( $session ); // Start the cURL session that will grab the actual results $redirected_session = curl_init( $matches[ 1 ] ); // Set some cURL options curl_setopt( $redirected_session , CURLOPT_HEADER, false ); curl_setopt( $redirected_session , CURLOPT_RETURNTRANSFER, true ); curl_setopt( $redirected_session , CURLOPT_FOLLOWLOCATION, false ); // Execute the cURL request $response = curl_exec( $redirected_session ); // Close the cURL connection curl_close( $redirected_session ); } else if ( ini_get( 'allow_url_fopen' ) ) { $response = file_get_contents( $request ); } else { // Echo an error message echo "

Your server does not have the cURL extension or allow remote opening of files. WP-Amazon Reloaded will not function.

"; exit; } echo $response; exit; } } } if( class_exists( 'Amazon_Reloaded' ) ) { $amazon_reloaded = new Amazon_Reloaded(); // Add Filters // Add Actions add_action( 'admin_menu', array( &$amazon_reloaded, 'on_admin_menu' ) ); add_action( 'wp_ajax_amazon_reloaded', array( &$amazon_reloaded, 'on_ajax_request' ) ); add_action( 'admin_head', array( &$amazon_reloaded, 'on_admin_head' ) ); // Activation/Deactivation register_activation_hook( __FILE__, array( &$amazon_reloaded, 'on_activate' ) ); register_deactivation_hook( __FILE__, array( &$amazon_reloaded, 'on_deactivate' ) ); } ?>