options page or all sales credit will go to the plugin creator by default.
Author: Don Fischer
Author URI: http://www.fischercreativemedia.com/
Version: 1.6
Version info:
1.6 -
1.5 - Remove hook to the_excerpt because it could cause problems in themes that only want to show text. (9/17/2009)
1.4 - Added menthod to restore default CSS if needed - by deleting all CSS in options panel and saving - default css will re-appear in box. (9/16/2009)
1.3 - Added new feature to be able to adjust or add your own styles. (9/16/2009)
1.2 - Fix to image call procedure to help with "no image available" issue. (9/15/2009)
1.1 - Minor Fixes/Spelling Error corrections & code cleanup to prep for WordPress hosting of Plugin. (9/14/2009)
1.0 - Plugin Release (9/12/2009)
Copyright (C) 2009 Donald J. Fischer
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
// Warnings Quickfix
if(get_option('apipp_hide_warnings_quickfix')==true){
ini_set("display_errors", 0); //turns off error display
}
// Includes
require_once("sha256.inc.php"); //required for php4
require_once("aws_signed_request.php"); //major workhorse for plugin
require_once("amazon-product-in-a-post-tools.php"); //edit box for plugin
require_once("amazon-product-in-a-post-options.php"); //admin options for plugin
//upgrade check. Lets me add/change the default style etc to fix/add new items during updrages.
$thisstyleversion=get_option('apipp_product_styles_default_version');
if($thisstyleversion!="1.6"){
update_option("apipp_product_styles_default",$thedefaultapippstyle);
update_option("apipp_product_styles_default_version","1.6");
update_option("apipp_amazon_notavailable_message","This item is may not be available in your area. Please click the image or title of product to check pricing & availability."); //default message
update_option("apipp_amazon_hiddenprice_message","Price Not Listed"); //default message - done
update_option("apipp_hook_content","1"); //default is yes - done
update_option("apipp_hook_excerpt","0"); //default is no - done
update_option('apipp_open_new_window',"0"); //newoption added at 1.6 - done
}
// Variables
global $public_key;
global $private_key;
global $aws_partner_id;
global $aws_eatra_pages;
global $aws_plugin_version;
global $aws_partner_locale;
global $thedefaultapippstyle;
global $amazonhiddenmsg;
global $amazonerrormsg;
global $apipphookexcerpt;
global $apipphookcontent;
global $apippopennewwindow;
global $apippnewwindowhtml;
session_start();
if(!isset($_SESSION['Amazon-PIPP-Cart-HMAC'])) $_SESSION['Amazon-PIPP-Cart-HMAC'] = '';
if(!isset($_SESSION['Amazon-PIPP-Cart-Encoded-HMAC'])) $_SESSION['Amazon-PIPP-Cart-Encoded-HMAC']='';
if(!isset($_SESSION['Amazon-PIPP-Cart-ID'])) $_SESSION['Amazon-PIPP-Cart-ID']='';
$public_key = get_option('awsplugin_amazon_publickey'); //Developer Public AWS Key
$private_key = get_option('awsplugin_amazon_secretkey'); //Developer Secret AWS Key
$aws_partner_id = get_option('apipp_amazon_associateid'); //Amazon Partner ID
$aws_partner_locale = get_option('apipp_amazon_locale'); //Amazon Locale
$awsPageRequest = 1;
$aws_plugin_version = "1.0";
$amazonhiddenmsg = get_option('apipp_amazon_hiddenprice_message'); //Amazon Hidden Price Message
$amazonerrormsg = get_option('apipp_amazon_notavailable_message'); //Amazon Error No Product Message
$apipphookexcerpt = get_option('apipp_hook_excerpt'); //Hook the excerpt?
$apipphookcontent = get_option('apipp_hook_content'); //Hook the content?
$apippopennewwindow = get_option('apipp_open_new_window'); //open in new window?
$aws_eatra_pages = '"ItemPage"=>"'.$awspagequery.'",';
$thereapippstyles = get_option("apipp_product_styles_default");
$apippnewwindowhtml ='';
if($apippopennewwindow==true){
$apippnewwindowhtml=' target="amazonwin" ';
}
if($amazonerrormsg==''){
$amazonerrormsg='Product Unavailable.';
}
if($amazonhiddenmsg==''){
$amazonhiddenmsg='Visit Amazon for Price.';
}
if($aws_partner_locale==''){
update_option('apipp_amazon_locale','com'); //set default to US
$aws_partner_locale='com';
}
if($aws_partner_id==''){
$aws_partner_id = "wolvid-20"; //Amazon Partner ID - if one is not set up, we will use Plugin Creator's ID - so be sure to set one up!!
}
if($public_key==''){
$public_key = "AKIAIR3UXPU7Y7GQQPAQ"; //Developer Public AWS Key
}
if($private_key==''){
$private_key = "oKUKoxCKgsmN1pmNbBYYi6DT9vMJfNMdt3Q1VUfJ"; //Developer Secret AWS Key
}
if(isset($_GET['awspage'])){ //future item for search results
if(is_numeric($_GET['awspage'])){
$awspagequery = (int)$wpdb->escape($_GET['awspage']);
}
}
if($awspagequery>1){ //future item for search results
$awsPageRequest = $awspagequery;
}
if(trim(get_option("apipp_product_styles")) == ''){ //reset to default styles if user deletes styles in admin
update_option("apipp_product_styles",$thedefaultapippstyle);
}
// Filters & Hooks
add_filter('the_content', 'aws_prodinpost_filter_content', 10); //hook content - we will filter the override after
add_filter('the_excerpt', 'aws_prodinpost_filter_excerpt', 10); //hook excerpt - we will filter the override after
add_action('wp_head','aws_prodinpost_addhead',10); //add styles to hesd
add_action('admin_head','aws_prodinpost_addadminhead',10); //add admin styles to admin head
//add_action('wp','aws_prodinpost_cartsetup', 1, 2); //Future Item
// Functions
//Single Product API Call - Returns One Product Data
function getSingleAmazonProduct($asin='',$extratext=''){
global $public_key, $private_key, $aws_partner_id,$aws_partner_locale,$amazonhiddenmsg,$amazonerrormsg,$apippopennewwindow,$apippnewwindowhtml;
if ($asin!=''){
$ASIN = $asin; //valid ASIN
$errors='';
//Main 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!=''){
$hiddenerrors = "<"."!-- HIDDEN AMAZON PRODUCT IN A POST ERROR: ". $errors ."-->";
if($extratext!=''){return $hiddenerrors.$extratext;}
return $hiddenerrors;
}else{
$result = FormatASINResult($pxml);
$returnval = '
'."\n";
if(isset($result["ReleaseDate"])){
if(strtotime($result["ReleaseDate"]) > strtotime(date("Y-m-d",time()))){
$returnval .= ' This title will be released on '.date("F j, Y", strtotime($result["ReleaseDate"])).'.'."\n";
}else{
$returnval .= ' Released '.date("F j, Y", strtotime($result["ReleaseDate"])).'.'."\n";
}
}
$returnval .= '