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.9
Version info:
1.9 - Fix to undefined function error - causing problems - sorry for the trouble everyone. (12/28/2009)
1.8 - Added Fix for users without encoding functions in PHP4 to be able to use. This may have caused some problems with users on 1.7. (12/21/2009)
Added Options for Language selection. (12/21/2009)
Added French Language and buttons (special thanks to Henri Sequeira for translations). (12/21/2009)
Added Lightbox type effect for "View Larger Image" function.(12/22/2009)
Modified Style Call to use a more WP friendly method to not rely on a "guess" as to where the core WP files are located. (12/22/2009)
Fixed Open in new window functionality - was not working 100% of the time. (12/22/2009)
1.7 - Add Curl option for users that cant use file_get_contents() for some reason or another. (12/1/2009)
Added Show on Single Page Only option to Options Page.(11/30/2009)
Added a way to change encoding display of prices from API if funny characters are showing.(12/1/2009)
1.6 - Added Options to let admin choose if they want to "Hook" into the_excerpt and the_content hooks in Main Options with override on each post/page.(10/3/2009)
Added Open in a New Window Option (for Amazon button) in Main Options with override on each page/post.(10/3/2009)
Added "Show Only on Single Page" option to individual post/page options.(10/4/2009)
Added Shortcode functionality to allow addition of unlimited products in the post/page content.(10/4/2009)
Added "Quick Fix - Hide Warnings" option in Main Options. Adds ini_set("display_errors", 0) to code to help some admins hide any Warnings if their PHP settings are set to show them.(10/3/2009)
Fixed Array Merge Warning when item is not an array.(10/3/2009)
Fixed "This Items not available in your locale" message as to when it acatually displays and spelling.(10/3/2009)
Added Options to let admin add their own Error Messages for Item Not available and Amazon Hidden Price notificaton.(10/3/2009)
Updated Default CSS styles to include in Stock and Out of Stock classes and made adjustments to other improper styles. (10/3/2009)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 .
*/
//error_reporting(E_ALL);
//ini_set("display_errors", 0);
// Warnings Quickfix
if(get_option('apipp_hide_warnings_quickfix')==true){
ini_set("display_errors", 0); //turns off error display
}
// 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;
global $encodemode; //1.7 new
global $appip_text_lgimage;
global $appip_text_listprice;
global $appip_text_newfrom;
global $appip_text_usedfrom;
global $appip_text_instock;
global $appip_text_outofstock;
global $appip_text_author;
global $appip_text_starring;
global $appip_text_director;
global $appip_text_reldate;
global $appip_text_preorder;
global $appip_text_releasedon;
global $appip_text_notavalarea;
global $buyamzonbutton;
global $addestrabuybutton;
global $awspagequery;
global $apip_language;
// Includes
require_once("inc/sha256.inc.php"); //required for php4
require_once("inc/aws_signed_request.php"); //major workhorse for plugin
require_once("inc/amazon-product-in-a-post-tools.php"); //edit box for plugin
require_once("inc/amazon-product-in-a-post-options.php"); //admin options for plugin
require_once("inc/amazon-product-in-a-post-translations.php"); //translations for plugin
require_once("inc/amazon-product-in-a-post-styles-product.php"); //styles 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
}
//added in 1.7 to allow those that could not use file_get_contents() to use Curl instead.
if(get_option('awsplugin_amazon_usefilegetcontents')==''){update_option('awsplugin_amazon_usefilegetcontents','1');}
if(get_option('awsplugin_amazon_usecurl')==''){update_option('awsplugin_amazon_usecurl','0');}
//if(get_option('apipp_API_call_method')==''){update_option('apipp_API_call_method','0');}
if(get_option('apipp_API_call_method')=='' && get_option('awsplugin_amazon_usecurl')=='0'){
update_option('apipp_API_call_method','0');}
elseif(get_option('apipp_API_call_method')=='' && get_option('awsplugin_amazon_usecurl')!='1'){
update_option('apipp_API_call_method','1');
}
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']='';
$awspagequery = '';
$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 - moved to translations file
$awsPageRequest = 1;
$aws_plugin_version = "1.8";
$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 = '';
$aws_eatra_pages = '"ItemPage"=>"'.$awspagequery.'",';
$thereapippstyles = get_option("apipp_product_styles_default");
$apippnewwindowhtml = '';
$apip_getmethod = get_option('apipp_API_call_method');
$apip_usefileget = '0';
$apip_usecurlget = '0';
$encodemode = get_option('appip_encodemode'); //1.7 added - UTF-8 will be default\
// 1.7 api get method defaults/check
if($apip_getmethod=='0'){
$apip_usefileget = '1';
}
if($apip_getmethod=='1'){
$apip_usecurlget = '1';
}
if($apip_getmethod==''){
$apip_usefileget = '1'; //set default if not set
}
//1.7 Encode Mode
if(get_option('appip_encodemode')==''){
update_option('appip_encodemode','UTF-8'); //set default to UTF-8
$encodemode="UTF-8";
}
//1.8 backward compat.
if(!function_exists('mb_convert_encoding')){
function mb_convert_encoding($etext='', $encodemode='', $encis=''){
return $etext;
}
}
if(!function_exists('mb_detect_encoding')){
function mb_detect_encoding($etext='', $encodemode=''){
return $etext;
}
}
// 1.7 - change encoding if needed via GET
// use http://yoursite.com/?resetenc=UTF-8 or http://yoursite.com/?resetenc=ISO-8859-1
// this will be the mode you wat the text OUTPUT as.
if(isset($_GET['resetenc'])){
if($_GET['resetenc']=='ISO-8859-1' || $_GET['resetenc']=='UTF-8'){
update_option('appip_encodemode',$_GET['resetenc']);
$encodemode = $_GET['resetenc'];
}
}
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 head
add_action('wp','add_appip_jquery'); //enqueue scripts
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='',$extrabutton=0){
global $public_key, $private_key, $aws_partner_id,$aws_partner_locale,$amazonhiddenmsg,$amazonerrormsg,$apippopennewwindow,$apippnewwindowhtml;
global $appip_text_lgimage;
global $appip_text_listprice;
global $appip_text_newfrom;
global $appip_text_usedfrom;
global $appip_text_instock;
global $appip_text_outofstock;
global $appip_text_author;
global $appip_text_starring;
global $appip_text_director;
global $appip_text_reldate;
global $appip_text_preorder;
global $appip_text_releasedon;
global $appip_text_notavalarea;
global $buyamzonbutton;
global $addestrabuybutton;
global $encodemode;
global $post;
//$apippOpenNewWindow = get_post_meta($post->ID,'amazon-product-newwindow',true);
//if($apippOpenNewWindow!='3'){$apippnewwindowhtml=' target="amazonwin" ';}
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 = '