true, ); $screens = get_post_types($args); //var_dump($screens); foreach ( $screens as $screen ) { add_meta_box( 'associatebox-for-amazon', __( 'AssociateBox' ), 'associatebox_meta_box_callback', $screen, 'normal', 'default' ); } } //Meta-Box function associatebox_meta_box_callback( $post ) { wp_nonce_field(basename(__FILE__), "meta-box-nonce"); ?>
Title for Widget on this Page:', 'associatebox-for-amazon' ); ?> "> '; echo _e( 'Show results in widget or under the content? ', 'associatebox-for-amazon' ); $placement=get_post_meta($post->ID, "associatebox_placement", true); if (empty($placement) OR $placement=="widget") { $checkbox22='checked="checked"'; } else { $checkbox11='checked="checked"'; } echo ' '; echo ' '; echo "
"; echo '
'; echo _e( 'Shuffle results? ', 'associatebox-for-amazon' ); $shuffle=get_post_meta($post->ID, "associatebox_shuffle", true); if (empty($shuffle) OR $shuffle=="no") { $checkbox2='checked="checked"'; } else { $checkbox1='checked="checked"'; } echo ' '; echo ' '; echo "
"; echo "
"; $host=get_post_meta($post->ID, "associatebox_host", true); //Standard-Locale if (empty($host)) { $host=get_option('associatebox_standardhost');; } echo _e( 'Amazon Server:', 'associatebox-for-amazon' ); $hostarray = array( "de"=>"amazon.de (DE)", "com"=>"amazon.com (US)", "co.uk"=>"amazon.co.uk (GB)", "fr"=>"amazon.fr (FR)", "es"=>"amazon.es (ES)", ); echo'"; echo "
"; ?>
No Amazon-Articles', 'associatebox-for-amazon' ); ?> value="empty">
Search for ASINs:', 'associatebox-for-amazon' ); ?> ID, "associatebox_art", true); if ($art=="asin") { $checked1="checked"; } ?> value="asin">
'; $value = get_post_meta( $post->ID, 'associatebox_asin', true ); echo ''; echo _e( 'Amount Articles shown:', 'associatebox-for-amazon' ); $associatebox_multiamount=get_post_meta( $post->ID, 'associatebox_multiamount', true ); if(empty($associatebox_multiamount)) { $associatebox_multiamount=1; } echo'"; ?>
Items in BrowseNode:', 'associatebox-for-amazon' ); ?> ID, "associatebox_art", true); if ($art=="browse") { $checked2="checked"; } ?> value="browse" >
ID, "associatebox_browsenode", true); ?>
 
esc_html__( 'Books','associatebox-for-amazon' ), "DVD" => esc_html__( 'DVD','associatebox-for-amazon' ), "Music" => esc_html__( 'Music','associatebox-for-amazon' ), "VideoGames" => esc_html__( 'VideoGames','associatebox-for-amazon' ), "Electronics" => esc_html__( 'Electronics','associatebox-for-amazon' ), "Automotive" => esc_html__( 'Automotive','associatebox-for-amazon' ), "Baby" => esc_html__( 'Baby','associatebox-for-amazon' ), "Tools" => esc_html__( 'Tools','associatebox-for-amazon' ), "PCHardware" => esc_html__( 'PcHardware','associatebox-for-amazon' ), "HealthPersonalCare" => esc_html__( 'HealthPersonalCare','associatebox-for-amazon' ), "Kitchen" => esc_html__( 'Kitchen','associatebox-for-amazon' ), "Software" => esc_html__( 'Software','associatebox-for-amazon' ), "Toys" => esc_html__( 'Toys','associatebox-for-amazon' ), "Beauty" => esc_html__( 'Beauty','associatebox-for-amazon' ), "MP3Downloads" => esc_html__( 'MP3Downloads','associatebox-for-amazon' ), "MusicalInstruments" => esc_html__( 'MusicalInstruments','associatebox-for-amazon' ), "Classical" => esc_html__( 'Classical','associatebox-for-amazon' ), "Grocery" => esc_html__( 'Grocery','associatebox-for-amazon' ), "Watches" => esc_html__( 'Watches','associatebox-for-amazon' ), "Magazines" => esc_html__( 'Magazines','associatebox-for-amazon' ), "Shoes" => esc_html__( 'Shoes','associatebox-for-amazon' ), "HomeGarden" => esc_html__( 'HomeGarden','associatebox-for-amazon' ), "GiftCards" => esc_html__( 'GiftCards','associatebox-for-amazon' ), "PetSupplies" => esc_html__( 'PetSupplies','associatebox-for-amazon' ), "Photo" => esc_html__( 'Photo','associatebox-for-amazon' ), "Appliances" => esc_html__( 'Appliances','associatebox-for-amazon' ), "Apparel" => esc_html__( 'Apparel','associatebox-for-amazon' ), "Lighting" => esc_html__( 'Lighting','associatebox-for-amazon' ), "ForeignBooks" => esc_html__( 'ForeignBooks','associatebox-for-amazon' ), "Pantry" => esc_html__( 'Pantry','associatebox-for-amazon' ), "MobileApps" => esc_html__( 'MobileApps','associatebox-for-amazon' ), "OfficeProducts" => esc_html__( 'OfficeProducts','associatebox-for-amazon' ), "KindleStore" => esc_html__( 'KindleStore','associatebox-for-amazon' ), "Luggage" => esc_html__( 'Luggage','associatebox-for-amazon' ), "Jewelry" => esc_html__( 'Jewelry','associatebox-for-amazon' ), "Industrial" => esc_html__( 'Industrial','associatebox-for-amazon' ), ); //var_dump($indexarray); $searchindex=get_post_meta($post->ID, "associatebox_mysearchindex", true); echo _e( 'SearchIndex: ', 'associatebox-for-amazon' ); echo '"; $associatebox_multiamount2=get_post_meta( $post->ID, 'associatebox_multiamount2', true ); if(empty($associatebox_multiamount2)) { $associatebox_multiamount2=1; } echo '
'; echo _e( 'Amount Articles shown:', 'associatebox-for-amazon' ); echo'
"; $checked3=""; $art=get_post_meta($post->ID, "associatebox_art", true); if ($art=="keyword") { $checked3="checked"; } ?>
Search for Keyword:', 'associatebox-for-amazon' ); ?> value="keyword" >
  ID, "associatebox_keyword", true); ?>
esc_html__( 'All','associatebox-for-amazon' ), "Books" => esc_html__( 'Books','associatebox-for-amazon' ), "DVD" => esc_html__( 'DVD','associatebox-for-amazon' ), "Music" => esc_html__( 'Music','associatebox-for-amazon' ), "VideoGames" => esc_html__( 'VideoGames','associatebox-for-amazon' ), "Electronics" => esc_html__( 'Electronics','associatebox-for-amazon' ), "Automotive" => esc_html__( 'Automotive','associatebox-for-amazon' ), "Baby" => esc_html__( 'Baby','associatebox-for-amazon' ), "Tools" => esc_html__( 'Tools','associatebox-for-amazon' ), "PCHardware" => esc_html__( 'PcHardware','associatebox-for-amazon' ), "HealthPersonalCare" => esc_html__( 'HealthPersonalCare','associatebox-for-amazon' ), "Kitchen" => esc_html__( 'Kitchen','associatebox-for-amazon' ), "Software" => esc_html__( 'Software','associatebox-for-amazon' ), "Toys" => esc_html__( 'Toys','associatebox-for-amazon' ), "Beauty" => esc_html__( 'Beauty','associatebox-for-amazon' ), "MP3Downloads" => esc_html__( 'MP3Downloads','associatebox-for-amazon' ), "MusicalInstruments" => esc_html__( 'MusicalInstruments','associatebox-for-amazon' ), "Classical" => esc_html__( 'Classical','associatebox-for-amazon' ), "Grocery" => esc_html__( 'Grocery','associatebox-for-amazon' ), "Watches" => esc_html__( 'Watches','associatebox-for-amazon' ), "Magazines" => esc_html__( 'Magazines','associatebox-for-amazon' ), "Shoes" => esc_html__( 'Shoes','associatebox-for-amazon' ), "HomeGarden" => esc_html__( 'HomeGarden','associatebox-for-amazon' ), "GiftCards" => esc_html__( 'GiftCards','associatebox-for-amazon' ), "PetSupplies" => esc_html__( 'PetSupplies','associatebox-for-amazon' ), "Photo" => esc_html__( 'Photo','associatebox-for-amazon' ), "Appliances" => esc_html__( 'Appliances','associatebox-for-amazon' ), "Apparel" => esc_html__( 'Apparel','associatebox-for-amazon' ), "Lighting" => esc_html__( 'Lighting','associatebox-for-amazon' ), "ForeignBooks" => esc_html__( 'ForeignBooks','associatebox-for-amazon' ), "Pantry" => esc_html__( 'Pantry','associatebox-for-amazon' ), "MobileApps" => esc_html__( 'MobileApps','associatebox-for-amazon' ), "OfficeProducts" => esc_html__( 'OfficeProducts','associatebox-for-amazon' ), "KindleStore" => esc_html__( 'KindleStore','associatebox-for-amazon' ), "Luggage" => esc_html__( 'Luggage','associatebox-for-amazon' ), "Jewelry" => esc_html__( 'Jewelry','associatebox-for-amazon' ), "Industrial" => esc_html__( 'Industrial','associatebox-for-amazon' ), ); $searchindex2=get_post_meta($post->ID, "associatebox_mysearchindex2", true); echo _e( 'SearchIndex: ', 'associatebox-for-amazon' ); echo '"; echo '
'; echo _e( 'Amount Articles shown:', 'associatebox-for-amazon' ); $associatebox_multiamount3=get_post_meta( $post->ID, 'associatebox_multiamount3', true ); //echo "AMOUNT3 ".$associatebox_multiamount3; if(empty($associatebox_multiamount3)) { //echo "LEER"; $associatebox_multiamount3=1; } echo'
"; ?>
ID, "associatebox_art", true); if ($art=="similarity") { $checked4="checked"; } ?>
Search for Similarity:', 'associatebox-for-amazon' ); ?> value="similarity" >
ID, "associatebox_asinsim", true); ?>
 
'; echo _e( 'Amount Articles shown:', 'associatebox-for-amazon' ); echo'
"; ?> ID; // If there are no errors, then we'll exit the function if ( ! ( $errors = get_transient( 'settings_errors' ) ) ) { return; } // Otherwise, build the list of errors that exist in the settings errores $message = '

'; // Write them out to the screen echo $message; // Clear and the transient and unhook any other notices so we don't see duplicate messages delete_transient( 'settings_errors' ); remove_action( 'admin_notices', '_location_admin_notices' ); } function associatebox_save_custom_meta_box($post_id, $post, $update) { global $post; if(isset($_POST["associatebox_title"])) { $meta_box_text_value = sanitize_text_field($_POST["associatebox_title"]); update_post_meta($post_id, "associatebox_title", esc_html($_POST["associatebox_title"])); } $id=$post->ID; $art=$_POST['associatebox_art']; $asins=$_POST['associatebox_asin']; $browsenode=$_POST['associatebox_browsenode']; $thekeyword=$_POST['associatebox_keyword']; $asinsim=$_POST['associatebox_asinsim']; if ($art=="asin" && empty($asins)) { $message = __( "You forgot to set an ASIN with 'Search for ASINs'. Mode was set to 'No Amazon-Articles' therefore.", "associatebox-for-amazon" ); add_settings_error( 'MissingASIN.', 'MissingASIN.', $message, 'error' ); set_transient( 'settings_errors', get_settings_errors(), 30 ); update_post_meta($id, "associatebox_art", "empty"); return $post_id; } else if ($art=="browse" && empty($browsenode)) { $message = __( "You forgot to set a BrowseId with 'Items in BrowseNode'. Mode was set to 'No Amazon-Articles' therefore.", "associatebox-for-amazon" ); add_settings_error( 'MissingASIN.', 'MissingASIN.', $message, 'error' ); set_transient( 'settings_errors', get_settings_errors(), 30 ); update_post_meta($id, "associatebox_art", "empty"); return $post_id; } else if ($art=="keyword" && empty($thekeyword)) { $message = __( "You forgot to set a Keyword with 'Search for Keyword'. Mode was set to 'No Amazon-Articles' therefore.", "associatebox-for-amazon" ); add_settings_error( 'MissingASIN.', 'MissingASIN.', $message, 'error' ); set_transient( 'settings_errors', get_settings_errors(), 30 ); update_post_meta($id, "associatebox_art", "empty"); return $post_id; } else if ($art=="similarity" && empty($asinsim)) { $message = __( "You forgot to set an ASIN with 'Search for Similarity'. Mode was set to 'No Amazon-Articles' therefore.", "associatebox-for-amazon" ); add_settings_error( 'MissingASIN.', 'MissingASIN.', $message, 'error' ); set_transient( 'settings_errors', get_settings_errors(), 30 ); update_post_meta($id, "associatebox_art", "empty"); return $post_id; } if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-box-nonce"], basename(__FILE__))) return $post_id; if(!current_user_can("edit_post", $post_id)) return $post_id; if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE) return $post_id; if(isset($_POST["associatebox_placement"])) { $placement_box_text_value = sanitize_text_field($_POST["associatebox_placement"]); update_post_meta($post_id, "associatebox_placement", esc_html($placement_box_text_value)); } if(isset($_POST["associatebox_title"])) { $meta_box_text_value = sanitize_text_field($_POST["associatebox_title"]); update_post_meta($post_id, "associatebox_title", esc_html($meta_box_text_value)); } if(isset($_POST["associatebox_shuffle"])) { $shuffle = sanitize_text_field($_POST["associatebox_shuffle"]); update_post_meta($post_id, "associatebox_shuffle", $shuffle); } if(isset($_POST["associatebox_host"])) { $host_text_value = sanitize_text_field($_POST["associatebox_host"]); update_post_meta($post_id, "associatebox_host", $host_text_value); } if($_POST["associatebox_art"]=="empty") { //DMS $art_value = sanitize_text_field($_POST["associatebox_art"]); update_post_meta($post_id, "associatebox_art", $art_value); } else if ($_POST["associatebox_art"]=="asin") { update_post_meta($post_id, "associatebox_art", "asin"); $asin_value = sanitize_text_field($_POST["associatebox_asin"]); update_post_meta($post_id, "associatebox_asin", esc_html(esc_textarea($asin_value))); if(isset($_POST["associatebox_multiamount"])) { $amount_value = sanitize_text_field($_POST["associatebox_multiamount"]); update_post_meta($post_id, "associatebox_multiamount", $amount_value); } } else if ($_POST["associatebox_art"]=="browse") { update_post_meta($post_id, "associatebox_art", "browse"); if(isset($_POST["associatebox_browsenode"])) { $browsenode= sanitize_text_field($_POST["associatebox_browsenode"]); update_post_meta($post_id, "associatebox_browsenode", esc_html($browsenode)); } if(isset($_POST["associatebox_searchindex"])) { $mysearchindex = sanitize_text_field($_POST["associatebox_searchindex"]); update_post_meta($post_id, "associatebox_mysearchindex", $mysearchindex); } if(isset($_POST["associatebox_multiamount2"])) { $amount_value2 = sanitize_text_field($_POST["associatebox_multiamount2"]); update_post_meta($post_id, "associatebox_multiamount2", $amount_value2); } } else if ($_POST["associatebox_art"]=="keyword") { update_post_meta($post_id, "associatebox_art", "keyword"); if(isset($_POST["associatebox_keyword"])) { $thekeyword= sanitize_text_field($_POST["associatebox_keyword"]); update_post_meta($post_id, "associatebox_keyword", esc_html($thekeyword)); } if(isset($_POST["associatebox_searchindex2"])) { $mysearchindex2 = sanitize_text_field($_POST["associatebox_searchindex2"]); update_post_meta($post_id, "associatebox_mysearchindex2", $mysearchindex2); if(isset($_POST["associatebox_multiamount3"])) { $amount_value3 = sanitize_text_field($_POST["associatebox_multiamount3"]); update_post_meta($post_id, "associatebox_multiamount3", $amount_value3); } } } else if ($_POST["associatebox_art"]=="similarity") { update_post_meta($post_id, "associatebox_art", "similarity"); if(isset($_POST["associatebox_asinsim"])) { $asinsim = sanitize_text_field($_POST["associatebox_asinsim"]); update_post_meta($post_id, "associatebox_asinsim", esc_html($asinsim)); } if(isset($_POST["associatebox_multiamount4"])) { $amount_value4 = sanitize_text_field($_POST["associatebox_multiamount4"]); update_post_meta($post_id, "associatebox_multiamount4", $amount_value4); } } } function associatebox_page_create() { $page_title = 'associatebox'; $menu_title = 'AssociateBox'; $capability = 'edit_posts'; $menu_slug = 'associatebox'; $function = 'associatebox_page_display'; $icon_url = ''; $position = 24; add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); } function associatebox_page_display() { echo "

"."AssociateBox"."

"; if (isset($_POST['deletecache'])) { $dir = plugin_dir_path( __FILE__ )."cache/"; $handle=opendir($dir); while($data=readdir($handle)) { if(!is_dir($data) && $data!="." && $data!="..") { unlink($dir.$data); } } echo _e( 'Data deleted.', 'associatebox-for-amazon' ); } if (isset($_POST['associatebox_standardhost'])) { $standardhost = sanitize_text_field($_POST['associatebox_standardhost']); update_option('associatebox_standardhost', $standardhost); } $standardhost= get_option('standardhost', esc_html__( 'Standardhost','associatebox-for-amazon' )); if (isset($_POST['associatebox_access_key'])) { $accesskey = sanitize_text_field($_POST['associatebox_access_key']); $accesskey = esc_html($accesskey); update_option('associatebox_access_key', $accesskey); } $accesskey = get_option('associatebox_access_key', esc_html__( 'Amazon Access Key','associatebox-for-amazon' )); if (isset($_POST['associatebox_sec_access_key'])) { $secret_key = sanitize_text_field($_POST['associatebox_sec_access_key']); $secret_key = esc_html($secret_key); update_option('associatebox_sec_access_key', $secret_key); } $secret_key = get_option('associatebox_sec_access_key', esc_html__( 'Secret Amazon Access Key','associatebox-for-amazon' )); if (isset($_POST['associatebox_partner_id'])) { $partnerid=sanitize_text_field($_POST['associatebox_partner_id']); $partnerid = esc_html($partnerid); update_option('associatebox_partner_id', $partnerid); } $partnerid = get_option('associatebox_partner_id', esc_html__( 'Partner-ID','Your Partner ID' )); if (isset($_POST['associatebox_partner_iduk'])) { $partneriduk=sanitize_text_field($_POST['associatebox_partner_iduk']); $partneriduk=esc_html($partneriduk); update_option('associatebox_partner_iduk', $partneriduk); } $partneriduk = get_option('associatebox_partner_iduk', esc_html__( 'Partner-ID UK','associatebox-for-amazon' )); if (isset($_POST['associatebox_partner_idus'])) { $partneridus=sanitize_text_field($_POST['associatebox_partner_idus']); $partneridus=esc_html($partneridus); update_option('associatebox_partner_idus', $partneridus); } $partneridus = get_option('associatebox_partner_idus', esc_html__( 'Partner-ID US','associatebox-for-amazon' )); if (isset($_POST['associatebox_partner_idfr'])) { $partneridfr=sanitize_text_field($_POST['associatebox_partner_idfr']); $partneridfr=esc_html($partneridfr); update_option('associatebox_partner_idfr', $partneridfr); } $partneridfr = get_option('associatebox_partner_idfr', esc_html__( 'Partner-ID FR','associatebox-for-amazon' )); if (isset($_POST['associatebox_partner_ides'])) { $partnerides=sanitize_text_field($_POST['associatebox_partner_ides']); $partnerides=esc_html($partnerides); update_option('associatebox_partner_ides', $partnerides); } $partnerides = get_option('associatebox_partner_ides', esc_html__( 'Partner-ID ES','associatebox-for-amazon' )); ?>
"; $standardhost=get_option('associatebox_standardhost'); //Standard-Locale if (empty($standardhost)) { $standardhost="de"; } echo _e( 'Amazon Standard-Server:', 'associatebox-for-amazon' ); $hostarraystandard = array( "de"=>"amazon.de (DE)", "com"=>"amazon.com (US)", "co.uk"=>"amazon.co.uk (GB)", "fr"=>"amazon.fr (FR)", "es"=>"amazon.es (ES)", ); echo'"; echo ""; ?>
0) { $size=foldersize($cachedir); $sizeumgerechnet=human_filesize($size); } if ($num_files==0) { echo __("No files in cache.",'associatebox-for-amazon'); } else if($num_files==1) { echo $num_files.__(" File in Cache ","associatebox-for-amazon")."(".$sizeumgerechnet.")."; } else { echo $num_files.__(" Files in Cache ","associatebox-for-amazon")."(".$sizeumgerechnet.")."; } ?>
"." && $t<>"..") { $currentFile = $cleanPath . $t; if (is_dir($currentFile)) { $size = foldersize($currentFile); $total_size += $size; } else { $size = filesize($currentFile); $total_size += $size; } } } return $total_size; } function human_filesize($bytes, $decimals = 2) { $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); $factor = floor((strlen($bytes) - 1) / 3); return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor]; } // Widget ausschalten, wenn keine ASINS vorhanden function associatebox_my_disable_widget( $sidebars_widgets ) { global $wp_query; if( is_object( $wp_query ) ) { $page_id=$wp_query->get_queried_object_id(); } else { global $post; $page_id=$post->ID; } $asins=get_post_meta( $page_id, 'associatebox_asin', true ); $art=get_post_meta($page_id, "associatebox_art", true); $browseid=get_post_meta($page_id, "associatebox_art", true); $keyword=get_post_meta($page_id, "associatebox_keyword", true); $placement=get_post_meta($page_id, "associatebox_placement", true); if ($sidebars_widgets) { foreach( $sidebars_widgets as $widget_area => $widget_list ){ foreach( $widget_list as $pos => $widget_id ){ $pos2 = strpos($widget_id, "associatebox"); if($pos2===false) { } else { if ($placement=="under") { unset( $sidebars_widgets[$widget_area][$pos] ); } else { if (!$art) { unset( $sidebars_widgets[$widget_area][$pos] ); } else { if ($art=="empty") { unset( $sidebars_widgets[$widget_area][$pos] ); } if ($art=="asin") { if(empty($asins) OR !$asins) { unset( $sidebars_widgets[$widget_area][$pos] ); } } else if ($art=="browse") { if(empty($browseid) OR !$browseid) { unset( $sidebars_widgets[$widget_area][$pos] ); } } else if ($art=="keyword") { if(empty($keyword) OR !$keyword) { unset( $sidebars_widgets[$widget_area][$pos] ); } } } } } } } } return $sidebars_widgets; } function aws_query($extraparams,$path,$host='de',$arrayback) { $private_key = get_option('associatebox_sec_access_key'); if ($host=="de") { $partnerid=get_option('associatebox_partner_id'); } else if ($host=="co.uk") { $partnerid=get_option('associatebox_partner_iduk'); } else if ($host=="com") { $partnerid=get_option('associatebox_partner_idus'); } else if ($host=="fr") { $partnerid=get_option('associatebox_partner_idfr'); } else if ($host=="es") { $partnerid=get_option('associatebox_partner_ides');; } //echo $host."
"; $method = "GET"; $host = "webservices.amazon.".$host; $uri = "/onca/xml"; $params = array( "AssociateTag" => $partnerid, "Service" => "AWSECommerceService", "AWSAccessKeyId" => get_option('associatebox_access_key'), "Timestamp" => gmdate("Y-m-d\TH:i:s\Z"), "SignatureMethod" => "HmacSHA256", "SignatureVersion" => "2", "Version" => "2013-08-01", ); //echo "PARTNER_ID ".$params["AssociateTag"]; foreach ($extraparams as $param => $value) { $params[$param] = $value; } ksort($params); // sort the parameters // 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 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, $private_key, TRUE)); // encode the signature for the request $signature = str_replace('%7E', '~', rawurlencode($signature)); // Put the signature into the parameters $params["Signature"] = $signature; uksort($params, "strnatcasecmp"); // TODO: the timestamp colons get urlencoded by http_build_query // and then need to be urldecoded to keep AWS happy. Spaces // get reencoded as %20, as the + encoding doesn't work with // AWS $query = urldecode(http_build_query($params)); $query = str_replace(' ', '%20', $query); $string_to_send = "https://" . $host . $uri . "?" . $query; //echo "
XML
"; $dir = plugin_dir_path( __FILE__ ); if ($params['Operation']=="ItemLookup" && $params['ItemId']) { $cachedatei = $dir."cache/".$params['Operation']."_"."ASINSearch"."_".str_replace(",","-",$params['ItemId'])."_".$host.".xml"; } else if ($params['Operation']=="ItemSearch" && $params[ 'SearchIndex'] && $params['BrowseNode']) { $cachedatei = $dir."cache/"."BrowseNode_".$params['Operation']."_".$params['SearchIndex']."_".str_replace(",","-",$params['BrowseNode'])."_".$host.".xml"; } else if ($params['Keywords']) { $cachedatei=$dir."cache/"."Keywords_".$params['Operation']."_".$params['Keywords']."_".$params['SearchIndex']."_".$host.".xml"; } else if ($params['Operation']=="SimilarityLookup") { $cachedatei=$dir."cache/".$params['Operation']."_".$params['ItemId']."_".$host.".xml"; } $cachezeit = time()-3600; if (file_exists($cachedatei)){ if (filemtime($cachedatei)<$cachezeit){ $daten = @file_get_contents($string_to_send); @file_put_contents($cachedatei, $daten); } else { $daten = @file_get_contents($cachedatei); } } else { $daten = @file_get_contents($string_to_send); @file_put_contents($cachedatei, $daten); } $response = simplexml_load_string($daten); if ($response) { if ($arrayback=="yes") { $response2 = json_decode(json_encode((array) $response), 1); $response = array($response->getName() => $response2); } } return $response; } function associatebox_append($content) { global $wp_query; $page_object = get_queried_object(); $page_id = get_queried_object_id(); $placement=get_post_meta($page_id, "associatebox_placement", true); if ($placement=="under") { $art=get_post_meta($page_id, "associatebox_art", true); if ($art=="empty") { return; } $host=get_post_meta($page_id, "associatebox_host", true); if (empty($host)) { $host="de"; } if ($host=="de") { $partnerid=get_option('associatebox_partner_id'); } else if ($host=="co.uk") { $partnerid=get_option('associatebox_partner_iduk'); } else if ($host=="com") { $partnerid=get_option('associatebox_partner_idus'); } else if ($host=="fr") { $partnerid=get_option('associatebox_partner_idfr'); } else if ($host=="es") { $partnerid=get_option('associatebox_partner_ides');; } wp_enqueue_style( 'associatebox', plugins_url()."/associatebox-for-amazon/css/associatebox.css" ); $custom_title=get_post_meta($page_id, "associatebox_title", true); $output.='
'.$custom_title.'
'; $output.='
'; //----------------------------------------------------------------------------------------------------------------- if ($art=="keyword") { $multi3=get_post_meta( $page_id, 'associatebox_multiamount3', true ); $keyword=get_post_meta($page_id, "associatebox_keyword", true); $searchindex2=get_post_meta($page_id, "associatebox_mysearchindex2", true); $params=array( "Operation" => "ItemSearch", "Keywords" => $keyword, "SearchIndex" => $searchindex2, "ResponseGroup" => "Medium" ); $response=aws_query($params,ABSPATH,$host,"yes"); //var_dump($response); if (!$response) { $output.= '
'.__('ERROR','associatebox-for-amazon').'
'; $output.= '
'.__('Please check your keys for the Amazon Product API.','associatebox-for-amazon').'
'; return; } if ($response[ItemSearchResponse][Items][Request][Errors]) { //FEHLER? $output.= '
'.$response[ItemSearchResponse][Items][Request][Errors][Error][Code].'
'; $output.= '
'.$response[ItemSearchResponse][Items][Request][Errors][Error][Message].'
'; } //FEHLER else { $anzahl=count($response[ItemSearchResponse][Items][Item]); $multi3=get_post_meta( $page_id, 'associatebox_multiamount3', true ); if ($anzahl<$multi3) { //MULTI 3 $multi3=$anzahl; } $shuffle=get_post_meta($page_id, "associatebox_shuffle", true); //$output.= "SHUFFLE" .$shuffle; if ($shuffle=="shuffle") { shuffle($response[ItemSearchResponse][Items][Item]); } for($count = 0; $count < $multi3; $count++) { $item=$response[ItemSearchResponse][Items][Item][$count]; if ($count==$multi3-1) { $last="last"; } else { $last=""; } $width=100/$multi3; $item=$response[ItemSearchResponse][Items][Item][$count]; $output.= '
'; $output.= ''; $output.= '
'; $output.= '
Cover
'; $output.= "
"; } } } else if ($art=="browse") { //BROWSE $browseid=get_post_meta($page_id, "associatebox_browsenode", true); $searchindex=get_post_meta($page_id, "associatebox_mysearchindex", true); $params=array( "Operation" => "ItemSearch", "BrowseNode" => $browseid, "SearchIndex" => $searchindex, "ResponseGroup" => "Medium" ); $response=aws_query($params,ABSPATH,$host,"yes"); //var_dump($response); if (!$response) { $output.= '
'.__('ERROR','associatebox-for-amazon').'
'; $output.= '
'.__('Please check your keys for the Amazon Product API.','associatebox-for-amazon').'
'; return; } $multi2=get_post_meta( $page_id, 'associatebox_multiamount2', true ); //var_dump($response[ItemSearchResponse][Items][Request][Errors]); if ($response[ItemSearchResponse][Items][Request][Errors]) { //FEHLER? $output.= '
'.$response[ItemSearchResponse][Items][Request][Errors][Error][Code].'
'; $output.= '
'.$response[ItemSearchResponse][Items][Request][Errors][Error][Message].'
'; } else { $anzahl=count($response[ItemSearchResponse][Items][Item]); $multi2=get_post_meta( $page_id, 'associatebox_multiamount2', true ); if ($anzahl<$multi2) { //MULTI 2 $multi2=$anzahl; } $shuffle=get_post_meta($page_id, "associatebox_shuffle", true); if ($shuffle=="shuffle") { shuffle($response[ItemSearchResponse][Items][Item]); } for($count = 0; $count < $multi2; $count++) { if ($count==$multi2-1) { $last="last"; } else { $last=""; } $width=100/$multi2; $item=$response[ItemSearchResponse][Items][Item][$count]; $output.= '
'; $output.= ''; $output.= '
'; $output.= '
Cover
'; $output.= "
"; } } //FEHLER ODER NICHT? ENDE BROWSE } else if ($art=="similarity") { //SIM $asinsim=get_post_meta($page_id, "associatebox_asinsim", true); $params = array( 'Operation' => 'SimilarityLookup', 'ItemId' => $asinsim, 'ResponseGroup' => 'Medium' ); $response=aws_query($params,ABSPATH,$host,"yes"); if (!$response) { $output.= '
'.__('ERROR','associatebox-for-amazon').'
'; $output.= '
'.__('Please check your keys for the Amazon Product API.','associatebox-for-amazon').'
'; return; } //var_dump($response[SimilarityLookupResponse]); if ($response[SimilarityLookupResponse][Items][Request][Errors]) { $output.= '
'.$response[SimilarityLookupResponse][Items][Request][Errors][Error][Code].'
'; $output.= '
'.$response[SimilarityLookupResponse][Items][Request][Errors][Error][Message].'
'; } else { //ANZAHL $anzahl=count($response[SimilarityLookupResponse][Items][Item]); //$output.= "ANZAHL ".$anzahl; $multi4=get_post_meta( $page_id, 'associatebox_multiamount4', true ); if ($anzahl<$multi4) { //MULTI 4 $multi4=$anzahl; } $shuffle=get_post_meta($page_id, "associatebox_shuffle", true); if ($shuffle=="shuffle") { shuffle($response[SimilarityLookupResponse][Items][Item]); } for($count = 0; $count < $multi4; $count++) { $item=$response[SimilarityLookupResponse][Items][Item][$count]; if ($count==$multi4-1) { $last="last"; } else { $last=""; } $width=100/$multi4; $output.= '
'; $output.= ''; $output.= '
'; $output.= '
Cover
'; $output.= "
"; } } //ANZAHL } //SIM elseif ($art=="asin") { //ASINS $asins=get_post_meta( $page_id, 'associatebox_asin', true ); //echo $asins; $asins=explode(",",$asins); $shuffle=get_post_meta($page_id, "associatebox_shuffle", true); //echo $shuffle; if ($shuffle=="shuffle") { shuffle($asins); } //echo $asins; $multi=get_post_meta( $page_id, 'associatebox_multiamount', true ); if ($multi>sizeof($asins)) { $multi=sizeof($asins); } $asins = array_slice($asins, 0, $multi); $asins=implode(",",$asins); $params=array( 'Operation' => 'ItemLookup', 'ItemId' => $asins, 'ResponseGroup' => 'Medium' ); $response=aws_query($params,ABSPATH,$host,"no"); if (!$response) { $output.= '
'.__('ERROR','associatebox-for-amazon').'
'; $output.= '
'.__('Please check your keys for the Amazon Product API.','associatebox-for-amazon').'
'; return; } if ($response->Items->Request->Errors->Error) { $output.= '
'.$response->Items->Request->Errors->Error->Code.'
'; $output.= '
'.$response->Items->Request->Errors->Error->Message.'
'; } else { $max=count($response->Items->Item); //$output.= $max."
"; $counter=1; $output.='
'; foreach ($response->Items->Item as $item) { //$output.= $counter; if ($counter==$max) { $last="last"; } else { $last=""; } $width=100/$max; $output.='
'; $output.=''; $output.= '
Cover
'; $output.='
'; /* $output.= '
'; $output.= '
'; $output.= '
Cover
'; */ $counter++; } $output.="
"; } } //----------------------------------------------------------------------------------------------------------------- $output.="
"; $content=$content.$output; } return $content; } ?>