$this->admin_width)); } /** @see WP_Widget::widget */ function widget($args, $instance) { global $post; // This widget does NOT execute on the homepage if (is_home()) { return false; } // outputs the content of the widget extract($args); $asin_tag = apply_filters('widget_asin_tag', $instance['asin_tag']); $asin = get_post_meta($post->ID,$asin_tag,true); if (!$asin) { return false; } // we don't execute if the page does not have an asin // get the remainder of the vars $title = apply_filters('widget_title', $instance['title']); $affiliate = apply_filters('widget_affiliate', $instance['affiliate']); $widget_content = $this->getSingleAmazonProduct($asin,$affiliate,$title); // start the output echo $before_widget; if ( $title ) { echo $before_title . $title . $after_title; } echo $widget_content; echo $after_widget; } /** @see WP_Widget::update */ function update($new_instance, $old_instance) { if (!$new_instance['affiliate']) { $new_instance['affiliate'] = $this->affiliate; } if (!$new_instance['asin_tag']) { $new_instance['asin_tag'] = $this->asin_tag; } if (!$new_instance['title']) { $new_instance['title'] = sprintf($this->title,$this->title_spec); } return $new_instance; } // outputs the options form on admin /** @see WP_Widget::form */ function form($instance) { $title = esc_attr($instance['title']); $affiliate = esc_attr($instance['affiliate']); $asin_tag = esc_attr($instance['asin_tag']); ?>


* If not set, will default to our Affiliate ID


* Same as post's Custom Field Name

public_key; $private_key = $this->private_key; if (!$asin) { return false; } $ASIN = $asin; //valid ASIN $errors=''; // Amazon API Call $pxml = aws_signed_request($aws_partner_locale, array( "Operation"=>"ItemLookup", "ItemId"=>"$ASIN", "ResponseGroup"=>"ItemAttributes,Images,Offers", "IdType"=>"ASIN", "AssociateTag"=>"$aws_partner_id"), $public_key, $private_key); //print_r($pxml); if(isset($pxml["ItemLookupResponse"]["Items"]["Request"]["Errors"]["Error"]["Message"])){ $errors=$pxml["ItemLookupResponse"]["Items"]["Request"]["Errors"]["Error"]["Message"]; } if($errors!=''){ // for now - errors are turned off and widget will not display return false; } // get our result data formatted into a meaningful hash $result = FormatASINResult($pxml); // build up our HTML // Test for a large image - if we have it, provide a link $largeimage = false; if($result['LargeImage']!=''){ $largeimage = <<< EOF
See larger image
EOF; } // Test for byline - set it appropriately $byline = false; if(isset($result["Author"])){ $byline .= "
By {$result['Author']}
"; } if(isset($result["Director"])){ $byline .= "
Directed by {$result['Director']}
"; } if(isset($result["Actors"])){ $byline .= "
Starring: {$result['Actors']}
"; } if(isset($result["Rating"])){ $byline .= "
Rating: {$result['Rating']}
"; } // Hidden price if($result["ListPrice"]!='0') { $list_price = $result["ListPrice"]; } else { $list_price = $a_hidden_msg; } // lowest price $lowest_new_price = false; if (isset($result["LowestNewPrice"])){ if($result["LowestNewPrice"]=='Too low to display'){ $newPrice = 'Check Amazon For Pricing'; } else{ $newPrice = $result["LowestNewPrice"]; } if($result["TotalNew"]>0){ $instock = " In Stock"; } else { $instock = " Out of Stock"; } $lowest_new_price = "New From:{$newPrice}{$instock}"; } // check for used prices $lowest_used_price = false; if(isset($result["LowestUsedPrice"])){ if($result["TotalUsed"]>0){ $lowest_used_price = "Used From:{$result["LowestUsedPrice"]} In Stock"; } } // test for special key in the title $spec = $this->title_spec; if (preg_match("/$this->title_spec/", $title)) { if (isset($result['Author']) && FALSE != $result['Author']) { $title = preg_replace("/$this->title_spec/",$result['Author'],$title); } elseif (isset($result['Director']) && FALSE != $result['Director']) { $title = preg_replace("/$this->title_spec/",$result['Director'],$title); } elseif (isset($result['Publisher']) && FALSE != $result['Publisher']) { $title = preg_replace("/$this->title_spec/",$result['Publisher'],$title); } elseif (isset($result['ProductGroup']) && FALSE != $result['ProductGroup']) { $title = preg_replace("/$this->title_spec/",$result['ProductGroup'],$title); } else { # if we can't format it properly, don't push special chars to the screen $title = ''; } } $plugin_dir = get_bloginfo('url') . '/' . PLUGINDIR . '/amazon-post-purchase'; // the whole kit-n-kaboodle $returnval = <<< EOF
{$this->awsImageGrabber($result['MediumImage'],'amazon-image')} {$largeimage}

{$result["Title"]}

{$byline}
{$result['Binding']}
Released {$result['PublicationDate']}
By {$result['Publisher']}
{$lowest_new_price} {$lowest_used_price}
List Price:{$list_price}
EOF; return $returnval; } //Amazon Product Image from ASIN function - Returns HTML Image Code function awsImageGrabber($imgurl, $class=""){ $base_url0 = '<'.'img src="'; $base_url = $imgurl; $base_url1 = '"'; $base_url1 = $base_url1.' class="amazon-image '.$class.'"'; $base_url1 = $base_url1.' rel="image-'.$asin.'" />'; if($base_url!=''){ return $base_url0.$base_url.$base_url1; }else{ $base_url = get_bloginfo('url').'/'.PLUGINDIR.'/amazon-product-in-a-post-plugin/images/noimage.jpg'; return $base_url0.$base_url.$base_url1; } } //Amazon Product Image from ASIN function - Returns URL only function awsImageGrabberURL($asin, $size="M"){ $base_url = 'http://images.amazon.com/images/P/'.$asin.'.03.'; if (strcasecmp($size, 'S') == 0){ $base_url .= 'THUMBZZZ'; } else if (strcasecmp($size, 'L') == 0){ $base_url .= 'LZZZZZZZ'; } else{ $base_url .= 'MZZZZZZZ'; } $base_url .= '.jpg'; return $base_url; } } // end class // register_widget('AmazonPostPurchase'); // register FooWidget widget add_action('widgets_init', create_function('', 'return register_widget("AmazonPostPurchase");')); ?>