table_options = $wpdb->prefix . "amazonfeed_options"; $this->table_cache = $wpdb->prefix . "amazonfeed_cache"; // Load Options $this->options = get_option('amazonFeedOptions'); if(defined('AUTH_KEY')) $this->encKey = AUTH_KEY; else $this->encKey = ABSPATH . 'fwa CGkK-5{ao[XYn7hq7wLvDMN#^PSIZ)$19lPI+UpH51vD|gYe%9s)j#5E-.lu'; // Default REST Parameters (can be over-ridden) $this->params = array( 'Operation' => 'ItemSearch', 'SearchIndex' => 'Books', 'ResponseGroup' => 'Small,Images' ); // If we're ready to run live, activate the controls. if( isset($this->options['ServicePath']) AND isset($this->options['AWSAccessKeyId']) AND ( $this->options['AWSSecretAccessKeyId'] OR time() < 1250294400 ) AND isset($this->options['AssociateTag']) AND isset($this->options['DefaultTags']) AND isset($this->options['DefaultSearchField']) AND isset($this->options['MaxResults']) AND isset($this->options['Version']) AND function_exists('simplexml_load_string') ) { $this->live = true; } } function checkInstall($autoInstall = false) { // Plugin options are not installed, implying that the plugin itself has not yet been installed either. if(!$this->options['Version'] OR $this->options['Version'] < $this->version) { if($autoInstall) return($this->doInstall()); else { $this->admin_notices[] = 'AmazonFeed is almost ready. Please visit the management page (Tools > AmazonFeed) to complete the ' . 'installation process and enter your Amazon credentials.'; return(false); } } else return(true); } function unInstall() { global $wpdb; $sql = "DROP TABLE `" . $this->table_cache . "`;"; $wpdb->query($sql); delete_option('amazonFeedOptions'); } function doInstall() { global $wpdb; if(!function_exists('simplexml_load_string')) { $this->admin_alert("WARNING: AmazonFeed currently only works on servers running PHP v 5.x or higher."); return(false); } // Plugin options are not installed, implying that the plugin itself has not yet been installed either. if(!$this->options['Version']) { $this->admin_alert("Previous installation not found. Installing necessary tables now."); $sql = "CREATE TABLE IF NOT EXISTS `" . $this->table_cache . "` ( `keyword` varchar(255) NOT NULL, `timestamp` bigint(20) unsigned zerofill NOT NULL, `data` longblob NOT NULL, PRIMARY KEY (`keyword`) );"; $result = $wpdb->query($sql); if($result === false) { $this->admin_alert("Failed to create table."); return(false); } $this->options = array( 'Locale' => 'United States', 'LocaleTipTag' => 'usamazonfeed-20', 'ServicePath' => 'http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService', 'AWSAccessKeyId' => '', 'AssociateTag' => '', 'SearchFrom' => 'categories', 'DefaultTags' => '', 'ShowOnPosts' => true, 'ShowOnPages' => true, 'ShowOnHome' => true, 'ShowOnCategories' => true, 'ShowOnTags' => true, 'ShowOnSearch' => true, 'TitleText' => '

Related Reading:

', 'DefaultSearchField'=> 'Keywords', 'MaxResults' => 5, 'ShowText' => true, 'ShowImages' => true, 'CacheExpiry' => 60*24, 'AllowTip' => true, 'StyleSheet' => 'style.css', 'Version' => $this->version ); update_option('amazonFeedOptions', $this->options); } elseif($this->options['Version'] < $this->version) { $this->admin_alert("Plugin files version do not match installed version. Running upgrade scripts now."); if($this->options['Version'] < '1.1') { $this->options['Version'] = '1.1'; $this->options['ShowOnPosts'] = true; $this->options['ShowOnPages'] = true; $this->options['ShowOnHome'] = true; $this->options['ShowOnCategories'] = true; $this->options['ShowOnTags'] = true; $this->options['ShowOnSearch'] = true; update_option('amazonFeedOptions', $this->options); $this->admin_alert("Plugin upgraded to v. 1.1 This version allows you to limit display of products on various categories of blog pages. Some CSS tweaks were also added."); } if($this->options['Version'] < '1.2') { $this->options['Version'] = '1.2'; $this->options['Locale'] = 'United States'; $this->options['LocaleTipTag'] = 'usamazonfeed-20'; update_option('amazonFeedOptions', $this->options); $this->admin_alert("Plugin upgraded to v. 1.2 This version allows you to select the locale from where you wish your products to be selected. Please be aware that in order to collect referral rewards, your associate account must be registered in the same locale as you are using to pull products from."); } if($this->options['Version'] < '1.3') { /* * Bug fixes * Limit hits to amazon * Select Search index to be displayed * Clear cache button * Pretty icon for notices */ $this->options['Version'] = '1.3'; if(!$this->options['SearchIndex']) $this->options['SearchIndex'] = $this->params['SearchIndex']; update_option('amazonFeedOptions', $this->options); $this->admin_alert("Plugin upgraded to v. 1.3 -- Tired of promoting just books? This version gives you access to promote many different types of products from Amazon. Simply check off the products you would like to promote in the Items to Feature field below."); } if($this->options['Version'] < '1.4') { /* * Updates to Amazon security and authentication protocol. */ $this->options['Version'] = '1.4'; update_option('amazonFeedOptions', $this->options); $this->admin_alert("Plugin upgraded to v. 1.4 -- Updated to support new Amazon security protocols. You will need to enter your AWS Secret Access Key in the appropriate field below."); } if($this->options['Version'] < '1.5') { /* * Minor bug fixes and tweaks. */ $this->options['Version'] = '1.5'; update_option('amazonFeedOptions', $this->options); $this->admin_alert("Plugin upgraded to v. 1.5 -- Minor bug fixes and tweaks to support a wider range of Amazon keys."); } if($this->options['Version'] < '1.6') { /* * Minor bug fixes and tweaks. */ $this->options['Version'] = '1.6'; $this->options['StyleSheet'] = 'style.css'; $this->options['ShowText'] = true; update_option('amazonFeedOptions', $this->options); $this->admin_alert("Plugin upgraded to v. 1.6
" . "Minor bug fixes when zero results are returned.
" . "Better admin screen organization.
" . "Upgraded admin security.
" . "Allowed display of only images or only text.
" . "Allowed for custom stylesheets.

" . "NOTE: If products are not showing on your blog, you may need to clear the built-in product cache."); } return(true); } } // Function to show notices using the built-in wp controls when appropriate. function wp_admin_notices() { foreach($this->admin_notices as $msg) { $this->admin_alert($msg); $this->log_error($msg); } } // Allow showing an alert to the user when necessary. function admin_alert($msg = '', $log = true) { if($msg) echo "

$msg

"; if($log) $this->log_error($msg); } // Allow limited logging of errors. function log_error($msg = '') { if(!is_array($this->options['error_log'])) $this->options['error_log'] = array(); array_unshift($this->options['error_log'], date('F j, Y, g:i a ') . $msg); if(count($this->options['error_log']) > 50) { array_pop($this->options['error_log']); } update_option('amazonFeedOptions', $this->options); } function debug($msg = '', $vDumpMode = false) { if($this->debug_mode == true) { echo "
"; 
			if($vDumpMode)
				var_dump($msg);
			else
				print_r($msg); 
			echo "
"; } } function getpath($path, $username = false, $password = false) { $this->debug("Using built-in function to load data. Slower, but should work."); // Test URL and ensure that it is valid. if(false !== $username AND false !== $password) $match = "^([a-z]{2,10})\://" . $username . "\:" . $password . "([a-z0-9\.\-]+)/?([^\?]*)(.*)$"; else $match = "^([a-z]{2,10})\://([a-z0-9\.\-]+)(/?[^\?]*)(.*)$"; // Return false if the path does not look like a url. if(!eregi($match, $path, $regs)) { return(false); } else { list($path, $protocol, $hostname, $request, $query) = $regs; // Determine port protocol. switch(strtoupper($protocol)) { case "HTTPS": $port = 443; break; case "FTP": $port = 21; break; default: $port = 80; break; } } // Load url data $fp = fsockopen($hostname, $port, $errno, $errstr, 10); if (!$fp) { echo "$errstr ($errno)
\n"; return(false); } else { $out = "GET " . $request . $query . " HTTP/1.0\r\n"; $out .= "Host: $hostname\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); unset($data); while (!feof($fp)) { $data .= fgets($fp); } fclose($fp); $data_start = strpos($data, "\r\n\r\n"); $header = substr($data, 0, $data_start); $body = substr($data, $data_start + 4, strlen($data)); $regs = ""; if(eregi("[\r\n]+Location\: *([^\r\n]+)", $header, $regs) AND eregi("HTTP/[0-9]*\.[0-9]*[ ]*3[0-9]{2}", $header)) { $location = $regs[1]; return($this->getpath($location)); } else { return($body); } } } // Main data loader. function request_data($new_params = array()) { // Only run a request from Amazon once per page load in order to comply with amazon regs. if($this->done_request == true) { $this->debug("Do not run request for '" . implode(",", $new_params) . "' in order to comply " . "with Amazon speed limit regulations"); $this->log_error("Do not run request for '" . implode(",", $new_params) . "' in order to comply " . "with Amazon speed limit regulations"); return(false); } if($this->options['SearchIndex']) $this->params['SearchIndex'] = $this->options['SearchIndex']; // Update the options with anything passed on the function. $params = array_merge($this->params, $new_params); // Create the request # $request = $this->options['ServicePath'] # . "&AWSAccessKeyId=" . $this->options['AWSAccessKeyId'] # . "&AssociateTag=" . $this->options['AssociateTag']; // Determine region based on predefined service path. if(eregi('ecs\.amazonaws\.([^/]+)/', $this->options['ServicePath'], $regs)) { $region = $regs[1]; } $pubKey = $this->options['AWSAccessKeyId']; $priKey = $this->options['AWSSecretAccessKeyId']; $request['AssociateTag'] = $this->options['AssociateTag']; // Iterate through the parameters adding to the request. foreach($params as $key=>$param) { if($param != "") { # $request .= "&" . $key . "=" . $param; $request[$key] = $param; } } $xml_data = $this->aws_signed_request($region, $request, $pubKey, $priKey); $this->done_request = true; if($xml_data) return($xml_data); } // Load related reading either from database table, or from Amazon.com function load($keyword) { global $wpdb; $keyword = addslashes($keyword); $sql = "SELECT * FROM " . $this->table_cache . " WHERE `keyword` = '" . $keyword . "' LIMIT 0,1"; $data = $wpdb->get_row($sql, ARRAY_A); if($data !== false AND $data['keyword'] != "") { $data['keyword'] = stripslashes($data['keyword']); $data['data'] = stripslashes($data['data']); return($data); } } // Save related reading to cache when necessary function save($keyword, $xml) { global $wpdb; $keyword = trim(addslashes($keyword)); $data = trim(addslashes($xml)); $timestamp = time() + ($this->options['CacheExpiry']*60); $sql = "SELECT * FROM " . $this->table_cache . " WHERE `keyword` = '" . $keyword . "' LIMIT 0,1"; $existing_data = $wpdb->get_row($sql, ARRAY_A); if($existing_data['keyword'] != "") $sql = "UPDATE " . $this->table_cache . " SET `timestamp` = '$timestamp', `data` = '$data' WHERE `keyword` = '" . $keyword . "' LIMIT 1;"; else $sql = "INSERT INTO " . $this->table_cache . " (`keyword`, `timestamp`, `data`) VALUES ('$keyword', '$timestamp', '$data');"; $results = $wpdb->query($sql); return; } // Specific search functions function search($search_keywords, $searchResults=false, $searchField=false, $searchIndex=false) { global $wpdb; $this->debug("Searching For: '$search_keywords'"); if($searchResults == false) $searchResults = $this->options['MaxResults']; if($searchField == false) $searchField = $this->options['DefaultSearchField']; if($searchIndex == false) $searchIndex = $this->params['SearchIndex']; $keywords = explode(",", $search_keywords); $tmp_items = array(); foreach($keywords as $word) { if(trim($word) != "") { $data = $this->load(trim($word)); if($data['data'] != "" AND $data['timestamp'] > time()) { $this->debug("Loading from memory for keyword: '$word'."); $xml_data = $data['data']; $memCached = true; } else { $new_params = array( $searchField => urlencode(trim($word)) ); $this->debug("Sending request to amazon for keyword: '$word'."); $this->log_error("Sending request to amazon for keyword: '$word'."); $this->debug($new_params); $xml_data = $this->request_data($new_params); if($xml_data) { $this->save($word, $xml_data); } $memCached = false; } if($xml_data) { $xml = simplexml_load_string($xml_data); # $this->debug($xml); if(isset($xml)) { $items = $xml->Items->Item; if(count($items) > 0) { $counter = 0; foreach($xml->Items->Item as $item) { $tmp_items[] = $item; } } elseif(isset($xml->Items->Request->Errors)) { if(!$memCached) { $this->log_error('Error returned from Amazon.'); $this->log_error($xml->Items->Request->Errors->Error->Message); } } else { $this->log_error('No results or errors were returned for word:' . $word); } } else $this->log_error('Unable to properly load XML string.'); } } } if(!$tmp_items) { $this->debug('No items found related to the keyword(s): ' . $search_keywords); return(false); } $items = array(); $counter = 0; while($counter++ < count($tmp_items)*2) { $rand = rand(0, count($tmp_items)-1); $tmp_item = $tmp_items[$rand]; $id = $tmp_item->ASIN; if(!$items["$id"]) $items["$id"] = $tmp_item; if(count($items) >= $searchResults) break; } return($items); } function display($keywords, $echo = true) { $items = $this->search($keywords); $numBooks = count($items); $this->debug("Number of Items: $numBooks"); #$this->debug($numBooks, true); #$this->debug($items, true); if($numBooks == 0 AND $keywords != $this->options['DefaultTags']) { $this->debug("No items found. Searching with default tags: '" . $this->options['DefaultTags'] . "'"); $items = $this->search($this->options['DefaultTags']); $numBooks = count($items); $this->debug("Number of Items: $numBooks"); #$this->debug($numBooks, true); #$this->debug($items, true); } if($numBooks > 0) { // Allow for tipping the author, if enabled if($this->options['AllowTip'] == true) { // If there is only one result, show the author's link 50% of the time. if($numBooks == 1) $tip_random_number = rand(1, 2); else $tip_random_number = rand(1, $numBooks); } $result = "
" . stripslashes($this->options['TitleText']) . "\n"; $counter = 0; if(is_array($items)) foreach($items as $item) { $result .= "
"; $counter++; $image = $item->SmallImage->URL; $title = $item->ItemAttributes->Title; $link = urldecode($item->DetailPageURL); $link_target = $this->options['LinkTarget']; // Do the tip if($this->options['AllowTip'] == true AND $counter == $tip_random_number) { $link = str_replace($this->options['AssociateTag'], $this->options['LocaleTipTag'], $link); } if($this->options['ShowImages'] == true AND trim($image) != "") $image_html = ""; else $image_html = ""; if($this->options['ShowText'] == true AND trim($title) != "") $title_html = "$title"; else $title_html = ""; $result .= "" . $image_html . $title_html . "\n"; $result .= "
"; } $result .= "
"; } if($echo) echo $result; else return($result); } function wp_head() { if(!isset($this->options['StyleSheet'])) $this->options['StyleSheet'] = 'style.css'; if(file_exists($this->basePath . '/css/' . $this->options['StyleSheet'])) { $csspath = $this->urlPath . '/css/' . $this->options['StyleSheet']; ?> options['Version'] > '1.0') { // Check to ensure we're allowed to show on this page. if(is_single() AND !$this->options['ShowOnPosts']) return($content); if(is_page() AND !$this->options['ShowOnPages']) return($content); if((is_home()) AND !$this->options['ShowOnHome']) return($content); if(is_category() AND !$this->options['ShowOnCategories']) return($content); if(is_tag() AND !$this->options['ShowOnTags']) return($content); if(is_search() AND !$this->options['ShowOnSearch']) return($content); if(function_exists('is_front_page')) if((is_front_page()) AND !$this->options['ShowOnHome']) return($content); } // If the page has had the plugin disabled, just return the content. if( get_post_meta($post->ID, '_amazonfeed_disabled', true) == "true" ) return($content); // Check to see if we have custom keywords for the page. $custom_keywords = get_post_meta($post->ID, '_amazonfeed_keywords', true); if(!$custom_keywords) { if($this->options['SearchFrom'] == "categories") $tags = get_the_category(); else $tags = get_the_tags(); if(count($tags) == 0 OR $tags == "") { $keywords = $this->options['DefaultTags']; } else { foreach($tags as $tag) $search_string[] = $tag->name; $keywords = implode(', ', $search_string); } } else $keywords = $custom_keywords; $result = $this->display($keywords, false); $content = "$content\n$result"; return($content); } function wp_admin_init() { global $wp_version; // Add admin management pages add_management_page('Amazon Feed Management', 'AmazonFeed', 7, __FILE__, array(&$this, 'wp_admin_options')); // Check to see if the plugin has been installed yet. $this->checkInstall(false); if(function_exists('wp_enqueue_script')) { wp_enqueue_script('jQuery'); } } function wp_admin_options() { if ( function_exists('current_user_can') && !current_user_can('manage_options') ) die(__('Access Denied')); // Check Installation $this->checkInstall(true); // Show and process different pages based on the page selected. switch($_GET['amazonFeedAdminPage']) { case 'error_log': $this->wp_admin_errors(); break; default: $this->wp_admin_screen(); break; } } // Main / Default admin management screen. To be split up into multiple pages in the future. function wp_admin_screen() { // Load StyleSheet List $styles_folder = $this->basePath . '/css'; $d = dir($styles_folder); while (false !== ($entry = $d->read())) { if(is_file($this->basePath . '/css/' . $entry)) { $stylesheets[] = trim($entry); } } $d->close(); // Save admin options if posted. if($_POST) { $post_errors = false; // Clear the cache database if locale has changed. if($_POST['Locale'] != $this->options['Locale']) { $_POST['ClearCacheNowv'] = 'yes'; $this->admin_alert("Locale change detected."); switch($_POST['Locale']) { case "Canada": $this->options['Locale'] = 'Canada'; $this->options['ServicePath'] = 'http://ecs.amazonaws.ca/onca/xml?Service=AWSECommerceService'; $this->options['LocaleTipTag'] = 'caamazonfeed-20'; break; case "United Kingdom": $this->options['Locale'] = 'United Kingdom'; $this->options['ServicePath'] = 'http://ecs.amazonaws.co.uk/onca/xml?Service=AWSECommerceService'; $this->options['LocaleTipTag'] = 'ukamazonfeed-21'; break; case "United States": default: $this->options['Locale'] = 'United States'; $this->options['ServicePath'] = 'http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService'; $this->options['LocaleTipTag'] = 'usamazonfeed-20'; break; } } if(eregi("^.+$", $_POST['AWSAccessKeyId'])) $this->options['AWSAccessKeyId'] = trim($_POST['AWSAccessKeyId']); else { $this->admin_alert("The AWS Access Key you entered was improperly formatted."); $post_errors = true; } if($_POST['AWSSecretAccessKeyId'] != '************************') { if(eregi("^.+$", $_POST['AWSSecretAccessKeyId'])) $this->options['AWSSecretAccessKeyId'] = $this->encrypt(trim($_POST['AWSSecretAccessKeyId'])); else { $this->admin_alert("The AWS Secret Access Key you entered was improperly formatted."); $post_errors = true; } } if(eregi("^.+$", $_POST['AssociateTag'])) $this->options['AssociateTag'] = trim($_POST['AssociateTag']); else { $this->admin_alert("The Associate Tag you entered was improperly formatted."); $post_errors = true; } if(eregi("^[a-z]+$", $_POST['SearchFrom']) AND $_POST['SearchFrom'] == 'tags') $this->options['SearchFrom'] = 'tags'; else { $this->options['SearchFrom'] = 'categories'; } if(eregi("^[a-z0-9\-]+$", $_POST['ShowOnPosts']) AND $_POST['ShowOnPosts'] == 'yes') $this->options['ShowOnPosts'] = true; else { $this->options['ShowOnPosts'] = false; } if(eregi("^[a-z0-9\-]+$", $_POST['ShowOnPages']) AND $_POST['ShowOnPages'] == 'yes') $this->options['ShowOnPages'] = true; else { $this->options['ShowOnPages'] = false; } if(eregi("^[a-z0-9\-]+$", $_POST['ShowOnHome']) AND $_POST['ShowOnHome'] == 'yes') $this->options['ShowOnHome'] = true; else { $this->options['ShowOnHome'] = false; } if(eregi("^[a-z0-9\-]+$", $_POST['ShowOnCategories']) AND $_POST['ShowOnCategories'] == 'yes') $this->options['ShowOnCategories'] = true; else { $this->options['ShowOnCategories'] = false; } if(eregi("^[a-z0-9\-]+$", $_POST['ShowOnTags']) AND $_POST['ShowOnTags'] == 'yes') $this->options['ShowOnTags'] = true; else { $this->options['ShowOnTags'] = false; } if(eregi("^[a-z0-9\-]+$", $_POST['ShowOnSearch']) AND $_POST['ShowOnSearch'] == 'yes') $this->options['ShowOnSearch'] = true; else { $this->options['ShowOnSearch'] = false; } switch($_POST['SearchIndex']) { case "Music": $this->options['SearchIndex'] = 'Music'; break; case "Video": $this->options['SearchIndex'] = 'Video'; break; case "Electronics": $this->options['SearchIndex'] = 'Electronics'; break; case "Software": $this->options['SearchIndex'] = 'Software'; break; case "Blended": $this->options['SearchIndex'] = 'Blended'; break; case "All": $this->options['SearchIndex'] = 'All'; break; case "Books": default: $this->options['SearchIndex'] = 'Books'; break; } if(eregi("^.*$", $_POST['DefaultTags'])) $this->options['DefaultTags'] = $_POST['DefaultTags']; else { $this->admin_alert("The Default Tags you entered was improperly formatted."); $post_errors = true; } if(eregi("^.*$", $_POST['TitleText'])) $this->options['TitleText'] = $_POST['TitleText']; else { $this->admin_alert("The Title Text you entered was improperly formatted."); $post_errors = true; } if(eregi("^[0-9]+$", $_POST['MaxResults']) AND $_POST['MaxResults'] >= 0 AND $_POST['MaxResults'] <= 25) $this->options['MaxResults'] = $_POST['MaxResults']; else { $this->admin_alert("The Max Results must only be a number between 0 and 25."); $post_errors = true; } if($_POST['ShowImages'] == 'yes') $this->options['ShowImages'] = true; else { $this->options['ShowImages'] = false; } if($_POST['ShowText'] == 'yes') $this->options['ShowText'] = true; else { $this->options['ShowText'] = false; } if($_POST['LinkTarget'] == '_blank') $this->options['LinkTarget'] = '_blank'; else { $this->options['LinkTarget'] = ''; } if($_POST['StyleSheet']) { if(!is_file($this->basePath . '/css/' . $_POST['StyleSheet'])) { $post_errors = true; $this->admin_alert("The stylesheet you selected doesn't seem to exist."); } elseif(preg_match('|^[a-z0-9_\.\-]$|i', $_POST['StyleSheet'])) { $post_errors = true; $this->admin_alert("The stylesheet you selected is invalid."); } else $this->options['StyleSheet'] = $_POST['StyleSheet']; } if(eregi("^[0-9]+$", $_POST['CacheExpiry']) AND $_POST['CacheExpiry'] >= 1 AND $_POST['CacheExpiry'] <= 43200) $this->options['CacheExpiry'] = $_POST['CacheExpiry']; else { $this->admin_alert("The Cache Expiry Minutes must only be a number between 15 and 43200 (30 days)."); $post_errors = true; } if(eregi("^[a-z0-9\-]+$", $_POST['ClearCacheNow']) AND $_POST['ClearCacheNow'] == 'yes') { $sql = "TRUNCATE " . $this->table_cache; global $wpdb; $wpdb->query($sql); $this->admin_alert("The database cache has been cleared of all items."); } if(eregi("^[a-z0-9\-]+$", $_POST['AllowTip']) AND $_POST['AllowTip'] == 'yes') { if($this->options['AllowTip'] == false) $this->admin_alert("Thank you for your generosity."); $this->options['AllowTip'] = true; } else { $this->options['AllowTip'] = false; } if(!$post_errors) { // Save current options update_option('amazonFeedOptions', $this->options); $this->admin_alert("Options saved!"); } } if(!$this->options['AWSSecretAccessKeyId'] AND time() < 1250294400) { $this->admin_alert("ALERT: Your AWS Secret Access Key will be required for this plugin to continue working after Aug. 15, 2009 due to recent changes with the Amazon system."); } // Show default admin page include($this->basePath . "/html/admin.php"); } // Special error reporting screen. function wp_admin_errors() { $homePath = $_SERVER['REQUEST_URI']; if(eregi('^(.+)&amazonFeedAdminPage=error_log$', $homePath, $regs)) $homePath = $regs[1]; // Show default admin page include($this->basePath . "/html/error_log.php"); } function add_custom_box() { if( function_exists( 'add_meta_box' )) { add_meta_box( 'amazonfeed_sectionid', 'Amazon Products Feed', array(&$this, 'inner_custom_box'), 'post', 'advanced' ); add_meta_box( 'amazonfeed_sectionid', 'Amazon Products Feed', array(&$this, 'inner_custom_box'), 'page', 'advanced' ); } else { add_action('dbx_post_advanced', array(&$this, 'old_custom_box') ); add_action('dbx_page_advanced', array(&$this, 'old_custom_box') ); } } function inner_custom_box() { global $post; ?>

ID, '_amazonfeed_disabled', true) == 'true' ) echo "checked"; ?> /> Disabled

Amazon Products Feed

inner_custom_box(); ?>
"ItemLookup", "ItemId"=>"B000X9FLKM", "ResponseGroup"=>"Small") $public_key - your "Access Key ID" $private_key - your "Secret Access Key" */ // some paramters $method = "GET"; $host = "ecs.amazonaws.".$region; $uri = "/onca/xml"; // additional parameters $params["Service"] = "AWSECommerceService"; $params["AWSAccessKeyId"] = $public_key; // GMT timestamp $params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z"); // API version $params["Version"] = "2009-03-31"; // sort the parameters ksort($params); // create the canonicalized query $canonicalized_query = array(); foreach ($params as $param=>$value) { $param = str_replace("%7E", "~", rawurlencode($param)); $value = str_replace("%7E", "~", rawurlencode($value)); $canonicalized_query[] = $param."=".$value; } $canonicalized_query = implode("&", $canonicalized_query); // create request if($private_key) { // create the string to sign $string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query; // calculate HMAC with SHA256 and base64-encoding $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $this->decrypt($private_key), True)); // encode the signature for the request $signature = str_replace("%7E", "~", rawurlencode($signature)); $request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature; } else $request = "http://".$host.$uri."?".$canonicalized_query; // do request if(function_exists('file_get_contents')) $response = @file_get_contents($request); else $response = @$this->getpath($request); $this->done_request = true; if ($response === False) { return False; } else { return($response); } } function encrypt($ptext) { $key = $this->encKey; $ptext = trim($ptext); if($ptext == "") return(base64_encode($ptext)); srand((double) microtime() * 1000000); //for sake of MCRYPT_RAND $key = md5($key); //to improve variance /* Open module, and create IV */ $td = mcrypt_module_open('rijndael-128', '','cbc', ''); $key = substr($key, 0, mcrypt_enc_get_key_size($td)); $iv_size = mcrypt_enc_get_iv_size($td); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); /* Initialize encryption handle */ if (mcrypt_generic_init($td, $key, $iv) != -1) { /* Encrypt data */ $c_t = mcrypt_generic($td, $ptext); mcrypt_generic_deinit($td); mcrypt_module_close($td); $c_t = $iv.$c_t; // we are including iv (fixed size) in the encrypted message return base64_encode($c_t); } //end if } function decrypt($etext) { $key = $this->encKey; $etext = base64_decode($etext); if($etext == "") return($etext); $key = md5($key); //to improve variance /* Open module, and create IV */ $td = mcrypt_module_open('rijndael-128', '','cbc', ''); $key = substr($key, 0, mcrypt_enc_get_key_size($td)); $iv_size = mcrypt_enc_get_iv_size($td); $iv = substr($etext,0,$iv_size); // extract iv $etext = substr($etext,$iv_size); /* Initialize encryption handle */ if (mcrypt_generic_init($td, $key, $iv) != -1) { /* Encrypt data */ $c_t = mdecrypt_generic($td, $etext); mcrypt_generic_deinit($td); mcrypt_module_close($td); return trim($c_t); } //end if } } ?>