logger = new \AMZNPP\HeyPublisher\Log('amznpp-widget.log');
$control_ops = array( 'id_base' => 'amznpp','width'=>$this->admin_width );
$widget_ops = array('description' => __('Display Amazon products related to your POST in the side-bar.','amznpp'));
$this->options = get_option(AMZNPP_PLUGIN_OPTTIONS)[options];
parent::__construct('amznpp', __('Amazon Post Purchase','amznpp'), $widget_ops,$control_ops );
}
/** @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);
$tag = $this->options[tag];
if (!$tag) { return false; } // no defined ASIN tag - that's weird
$asin = get_post_meta($post->ID,$tag,true);
// safety checks and biz rule checks
$this->logger->debug("ASIN = '{$asin}'");
// Logic:
$asin = $this->should_widget_display($asin);
if (!$asin) { return false; }
// If we made it this far, show the block
$title = apply_filters('widget_title', $instance['title']);
$aff_id = $this->options[aff_id];
$aff_cc = $this->options[aff_cc];
$widget_content = $this->getSingleAmazonProduct($asin,$aff_id,$aff_cc,$title);
if ($widget_content) {
// start the output
echo $before_widget;
if ( $title ) { echo $before_title . $title . $after_title; }
echo $widget_content;
echo $after_widget;
}
return;
}
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
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']);
?>
title_spec; ?> will be replaced with author/artist's 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
);
$this->logger->debug("getSingleAmazonProduct()");
$this->logger->debug(sprintf("=> ASIN: : %s",print_r($ASIN,1)));
$this->logger->debug(sprintf("=> parnter locale: : %s",print_r($aws_partner_locale,1)));
$this->logger->debug(sprintf("PXML : %s",print_r($pxml,1)));
if (!$pxml) {
return false;
}
if(isset($pxml["ItemLookupResponse"]["Items"]["Request"]["Errors"]["Error"]["Message"])){
$errors = $pxml["ItemLookupResponse"]["Items"]["Request"]["Errors"]["Error"]["Message"];
return false;
}
// get our result data formatted into a meaningful hash
// TODO: Move this FormatASINResult to AmazonPostPurchase class
$result = FormatASINResult($pxml);
$this->logger->debug(sprintf("FormatASINResult : %s",print_r($result,1)));
// build up our HTML
// Test for a large image - if we have it, provide a link
$largeimage = false;
if($result['LargeImage']!=''){
$largeimage = <<< EOF