amzn_assoc_ad_type = "link_enhancement_widget";
amzn_assoc_tracking_id = "' . $tracking_id . '";
amzn_assoc_linkid = "' . $link_id . '";
amzn_assoc_placement = "";
amzn_assoc_marketplace = "amazon";
amzn_assoc_region = "' . $region . '";
';
}
}
function aws_prodinpost_filter_get_excerpt( $text ) {
global $appip_running_excerpt;
$appip_running_excerpt = true;
return $text;
}
add_filter( 'amazon_product_post_cache', function ( $cache_in_sec ) {
if ( $cache_in_sec == '' || ( int )$cache_in_sec == 0 )
return 3600;
return $cache_in_sec;
}, -1 );
if ( !function_exists( 'aws_prodinpost_filter_content_test' ) ) {
function aws_prodinpost_filter_content_test( $text ) {
global $post, $apipphookcontent, $apipphookexcerpt;
global $appip_running_excerpt;
$ActiveProdPostAWS = get_post_meta( $post->ID, 'amazon-product-isactive', true );
$singleProdPostAWS = get_post_meta( $post->ID, 'amazon-product-single-asin', true );
$AWSPostLoc = get_post_meta( $post->ID, 'amazon-product-content-location', true );
$apippContentHookOverride = get_post_meta( $post->ID, 'amazon-product-content-hook-override', true );
$apippExcerptHookOverride = get_post_meta( $post->ID, 'amazon-product-excerpt-hook-override', true );
$apippShowSingularonly = get_post_meta( $post->ID, 'amazon-product-singular-only', true );
$showDesc = get_post_meta( $post->ID, 'amazon-product-amazon-desc', true );
$showGallery = get_post_meta( $post->ID, 'amazon-product-show-gallery', true );
$showFeatures = get_post_meta( $post->ID, 'amazon-product-show-features', true );
$newWindow = get_post_meta( $post->ID, 'amazon-product-newwindow', true );
$showList = get_post_meta( $post->ID, 'amazon-product-show-list-price', true );
$showUsed = get_post_meta( $post->ID, 'amazon-product-show-used-price', true );
$showSaved = get_post_meta( $post->ID, 'amazon-product-show-saved-amt', true );
$showTimestamp = get_post_meta( $post->ID, 'amazon-product-timestamp', true );
$newTitle = get_post_meta( $post->ID, 'amazon-product-new-title', true );
$useCartURL = get_post_meta( $post->ID, 'amazon-product-use-cartURL', true ) == '1' ? true : false;
$newWindow = $newWindow == '2' ? 1 : 0;
$manualArray = array(
'desc' => $showDesc,
'listprice' => $showList,
'features' => $showFeatures,
'used_price' => $showUsed,
'saved_amt' => $showSaved,
'timestamp' => $showTimestamp,
'gallery' => $showGallery,
'replace_title' => $newTitle,
'usecarturl' => $useCartURL,
'newwindow' => $newWindow
);
/*
* Strip Excerpt Shortcodes:
* this strips the shortcodes out of the excerpt in the event
* that there is not excerpt and one is created using the content.
* otherwise you get nonsense text from removed HTML in product.
*/
$stripShortcodes = false;
if ( $appip_running_excerpt == true ) {
if ( ( ( bool )$apipphookexcerpt && $apippExcerptHookOverride != '3' ) )
$stripShortcodes = true;
}
/* END Strip Excerpt Shortcodes */
$scode_attrs = array( 'amazon-element', 'amazon-elements', 'amazonproducts', 'amazonproduct', 'AMAZONPRODUCTS', 'AMAZONPRODUCT' );
$pattern = get_shortcode_regex();
$allASIN = $singleProdPostAWS != '' ? explode( ',', str_replace( ', ', ',', $singleProdPostAWS ) ) : array();
$grASIN = array();
foreach ( $scode_attrs as $scode ) {
if ( has_shortcode( $text, $scode ) ) {
if ( preg_match_all( '/' . $pattern . '/s', $text, $matches ) && array_key_exists( 2, $matches ) && in_array( $scode, $matches[ 2 ] ) ) {
foreach ( $matches[ 3 ] as $a ) {
//$attrs = shortcode_parse_atts( $a );
//if ( isset( $attrs[ 'asin' ] ) ) {
//$temp = explode( ',', $attrs[ 'asin' ] );
//foreach ( $temp as $tempval ) {
//array_push( $allASIN, $tempval );
//}
//}
$attrs = shortcode_parse_atts( $a );
if ( isset( $attrs[ 'partner_id' ] ) && $attrs[ 'partner_id' ] !== APIAP_ASSOC_ID ) {
//echo '
aws_prodinpost_filter_content_test - dont cache - different partner ID
';
// dont cache - different partner ID
// todo- add cache ahead for these circumstances
} elseif ( isset( $attrs[ 'locale' ] ) && $attrs[ 'locale' ] !== APIAP_LOCALE ) {
//echo 'aws_prodinpost_filter_content_test - dont cache - different locale
';
// dont cache - different locale
// todo- add cache ahead for these circumstances
} elseif ( isset( $attrs[ 'asin' ] ) && $attrs[ 'asin' ] !== '' ) {
$temp = explode( ',', $attrs[ 'asin' ] );
foreach ( $temp as $tempval ) {
if ( !in_array( $tempval, $allASIN ) )
$allASIN[] = $tempval;
}
} elseif ( 'amazon' == $scode && isset( $attrs[ 'template' ] ) && ( isset( $attrs[ 1 ] ) && strpos( $attrs[ 1 ], 'asin=' ) !== false ) ) {
//this is a special amazon code from old "Amazon Links" users
$temp = explode( 'asin=', $attrs[ 1 ] );
if ( isset( $temp[ 1 ] ) ) {
if ( !in_array( $temp[ 1 ], $allASIN ) )
$allASIN[] = $temp[ 1 ];
}
}
}
}
}
}
if ( !empty( $allASIN ) ) {
foreach ( $allASIN as $asinl ) {
$grASIN[] = $asinl;
}
}
if ( !empty( $grASIN ) ) {
$params = array( 'ItemId' => implode( ',', $grASIN ), 'CacheOnly' => true, "RequestBy" => 'cache-only' );
amazon_plugin_aws_signed_request( '', $params );
}
$doshort = false;
foreach ( $scode_attrs as $scode ) {
if ( has_shortcode( $text, $scode ) ) {
if ( preg_match_all( '/' . $pattern . '/s', $text, $matches ) && array_key_exists( 2, $matches ) && in_array( $scode, $matches[ 2 ] ) ) {
if ( ( $apippShowSingularonly == '1' && !is_singular() ) || $stripShortcodes ) {
foreach ( $matches[ 0 ] as $scs )
$text = str_replace( $scs, '', $text );
} else {
$doshort = true;
}
}
}
}
if ( $stripShortcodes )
return $text;
if ( $doshort )
$text = do_shortcode( $text );
if ( $apippShowSingularonly == '1' ) {
if ( is_singular() && ( ( $apipphookcontent == true && $apippContentHookOverride != '3' ) || $apippContentHookOverride == '' || $apipphookcontent == '' ) ) { //if options say to show it, show it
if ( $singleProdPostAWS != '' && $ActiveProdPostAWS != '' ) {
if ( $AWSPostLoc == '2' ) {
//Post Content is the description
$theproduct = getSingleAmazonProduct( $singleProdPostAWS, $text, 0, $manualArray );
} elseif ( $AWSPostLoc == '3' ) {
//Post Content before product
$theproduct = $text . '
' . getSingleAmazonProduct( $singleProdPostAWS, '', 0, $manualArray );
} else {
//Post Content after product - default
$theproduct = getSingleAmazonProduct( $singleProdPostAWS, '', 0, $manualArray ) . '
' . $text;
}
return $theproduct;
} else {
return $text;
}
}
} else {
if ( ( $apipphookcontent == true && $apippContentHookOverride != '3' ) || $apippContentHookOverride == '' || $apipphookcontent == '' ) { //if options say to show it, show it
if ( $singleProdPostAWS != '' && $ActiveProdPostAWS != '' ) {
if ( $AWSPostLoc == '2' ) {
//Post Content is the description
$theproduct = getSingleAmazonProduct( $singleProdPostAWS, $text, 0, $manualArray );
} elseif ( $AWSPostLoc == '3' ) {
//Post Content before product
$theproduct = $text . '
' . getSingleAmazonProduct( $singleProdPostAWS, '', 0, $manualArray );
} else {
//Post Content after product - default
$theproduct = getSingleAmazonProduct( $singleProdPostAWS, '', 0, $manualArray ) . '
' . $text;
}
return $theproduct;
} else {
return $text;
}
}
}
return $text;
}
}
if ( !function_exists( 'aws_prodinpost_filter_excerpt_test' ) ) {
function aws_prodinpost_filter_excerpt_test( $text ) {
global $post, $apipphookexcerpt;
$ActiveProdPostAWS = get_post_meta( $post->ID, 'amazon-product-isactive', true );
$singleProdPostAWS = get_post_meta( $post->ID, 'amazon-product-single-asin', true );
$AWSPostLoc = get_post_meta( $post->ID, 'amazon-product-content-location', true );
$apippExcerptHookOverride = get_post_meta( $post->ID, 'amazon-product-excerpt-hook-override', true );
$apippShowSingularonly = get_option( 'appip_show_single_only' ) == '1' ? '1' : '0';
$apippShowSingularonly2 = get_post_meta( $post->ID, 'amazon-product-singular-only', true );
$showDesc = get_post_meta( $post->ID, 'amazon-product-amazon-desc', true );
$showGallery = get_post_meta( $post->ID, 'amazon-product-show-gallery', true );
$showFeatures = get_post_meta( $post->ID, 'amazon-product-show-features', true );
$showList = get_post_meta( $post->ID, 'amazon-product-show-list-price', true );
$showUsed = get_post_meta( $post->ID, 'amazon-product-show-used-price', true );
$showSaved = get_post_meta( $post->ID, 'amazon-product-show-saved-amt', true );
$showTimestamp = get_post_meta( $post->ID, 'amazon-product-timestamp', true );
$useCartURL = get_post_meta( $post->ID, 'amazon-product-use-cartURL', true ) == '1' ? true : false;
$newTitle = get_post_meta( $post->ID, 'amazon-product-new-title', true );
$manualArray = array(
'desc' => $showDesc,
'listprice' => $showList,
'features' => $showFeatures,
'used_price' => $showUsed,
'saved_amt' => $showSaved,
'timestamp' => $showTimestamp,
'gallery' => $showGallery,
'usecarturl' => $useCartURL,
'replace_title' => $newTitle
);
$apippShowSingularonly = $apippShowSingularonly2 == '1' ? '1' : $apippShowSingularonly;
$scode_attrs = array( 'amazon-element', 'amazon-elements', 'amazonproducts', 'amazonproduct', 'AMAZONPRODUCTS', 'AMAZONPRODUCT' );
$pattern = get_shortcode_regex();
$ASINs_Set = $singleProdPostAWS;
$allASIN = $singleProdPostAWS != '' ? explode( ',', str_replace( ', ', ',', $singleProdPostAWS ) ) : array();
$grASIN = array();
if ( ( ( bool )$apipphookexcerpt && $apippExcerptHookOverride != '3' ) ) { //if options say to show it, show it
foreach ( $scode_attrs as $scode ) {
if ( has_shortcode( $text, $scode ) ) {
if ( preg_match_all( '/' . $pattern . '/s', $text, $matches ) && array_key_exists( 2, $matches ) && in_array( $scode, $matches[ 2 ] ) ) {
foreach ( $matches[ 3 ] as $a ) {
$attrs = shortcode_parse_atts( $a );
if ( isset( $attrs[ 'partner_id' ] ) && $attrs[ 'partner_id' ] !== APIAP_ASSOC_ID ) {
//echo 'aws_prodinpost_filter_excerpt_test - dont cache - different partner ID
';
// dont cache - different partner ID
// todo- add cache ahead for these circumstances
} elseif ( isset( $attrs[ 'locale' ] ) && $attrs[ 'locale' ] !== APIAP_LOCALE ) {
//echo 'aws_prodinpost_filter_excerpt_test - dont cache - different locale
';
// dont cache - different locale
// todo- add cache ahead for these circumstances
} elseif ( isset( $attrs[ 'asin' ] ) && $attrs[ 'asin' ] !== '' ) {
$temp = explode( ',', $attrs[ 'asin' ] );
foreach ( $temp as $tempval ) {
if ( !in_array( $tempval, $allASIN ) )
$allASIN[] = $tempval;
}
} elseif ( 'amazon' == $scode && isset( $attrs[ 'template' ] ) && ( isset( $attrs[ 1 ] ) && strpos( $attrs[ 1 ], 'asin=' ) !== false ) ) {
//this is a special amazon code from old "Amazon Links" users
if ( isset( $temp[ 1 ] ) ) {
$temp = explode( 'asin=', $attrs[ 1 ] );
if ( !in_array( $temp[ 1 ], $allASIN ) )
$allASIN[] = $temp[ 1 ];
}
}
}
}
}
}
if ( !empty( $allASIN ) ) {
foreach ( $allASIN as $asinl ) {
$grASIN[ $asinl ] = $asinl;
}
}
if ( !empty( $grASIN ) ) {
$params = array( 'ItemId' => implode( ',', $grASIN ), 'CacheOnly' => true, "RequestBy" => 'cache-only' );
amazon_plugin_aws_signed_request( '', $params );
}
//replace short tag here. Handle a bit different than content so they get stripped if they don't want to hook excerpt we don't want to show the [AMAZON-PRODUCT=XXXXXXXX] tag in the excerpt text!
$doshort = false;
foreach ( $scode_attrs as $scode ) {
if ( has_shortcode( $text, $scode ) ) {
if ( preg_match_all( '/' . $pattern . '/s', $text, $matches ) && array_key_exists( 2, $matches ) && in_array( $scode, $matches[ 2 ] ) ) {
if ( $apippShowSingularonly == '1' && !is_singular() ) {
foreach ( $matches[ 0 ] as $scs )
$text = str_replace( $scs, '', $text );
} else {
$doshort = true;
}
}
}
}
if ( $doshort )
$text = do_shortcode( $text );
if ( $apippShowSingularonly == '1' ) {
if ( is_singular() && ( $singleProdPostAWS != '' && $ActiveProdPostAWS != '' ) ) {
if ( $AWSPostLoc == '2' ) {
$theproduct = getSingleAmazonProduct( $singleProdPostAWS, $text, 0, $manualArray );
} elseif ( $AWSPostLoc == '3' ) {
$theproduct = $text . '
' . getSingleAmazonProduct( $singleProdPostAWS, '', 0, $manualArray );
} else {
$theproduct = getSingleAmazonProduct( $singleProdPostAWS, '', 0, $manualArray ) . '
' . $text;
}
return $theproduct;
} else {
return $text;
}
} else {
if ( $singleProdPostAWS != '' && $ActiveProdPostAWS != '' ) {
if ( $AWSPostLoc == '2' ) {
$theproduct = getSingleAmazonProduct( $singleProdPostAWS, $text, 0, $manualArray );
} elseif ( $AWSPostLoc == '3' ) {
$theproduct = $text . '
' . getSingleAmazonProduct( $singleProdPostAWS, '', 0, $manualArray );
} else {
$theproduct = getSingleAmazonProduct( $singleProdPostAWS, '', 0, $manualArray ) . '
' . $text;
}
return $theproduct;
} else {
return $text;
}
}
} else {
foreach ( $scode_attrs as $scode ) {
if ( has_shortcode( $text, $scode ) ) {
if ( preg_match_all( '/' . $pattern . '/s', $text, $matches ) && array_key_exists( 2, $matches ) && in_array( $scode, $matches[ 2 ] ) ) {
foreach ( $matches[ 0 ] as $scs )
$text = str_replace( $scs, '', $text ); //take the darn thing out!
}
}
}
}
return $text;
}
}
add_filter( 'amz_get_fileds_to_cache', function ( $arr ) {
$arr[] = 'itemasin';
$arr[] = 'amazon-product-single-asin';
return $arr;
} );
function amazon_plugin_postlist_detect_and_cache_ASINs( $posts ) {
$cache_ahead = get_option( 'apipp_amazon_cache_ahead', '0' );
if ( !empty( $posts ) && $cache_ahead ) {
$scode_attrs = array( 'amazon-element', 'amazon-elements', 'amazonproducts', 'amazonproduct', 'AMAZONPRODUCTS', 'AMAZONPRODUCT', 'amazon-product-search', 'amazon-grid' );
$pattern = get_shortcode_regex();
$allASIN = array();
$grASIN = array();
foreach ( $posts as $apposts ) {
$mActv = get_post_meta( $apposts->ID, 'amazon-product-isactive', true );
$mASIN = get_post_meta( $apposts->ID, 'amazon-product-single-asin', true );
if ( $mActv == '1' && $mASIN != '' ) {
$newASN = explode( ',', str_replace( ', ', ',', $mASIN ) );
if ( is_array( $newASN ) && !empty( $newASN ) ) {
foreach ( $newASN as $Aval ) {
$allASIN[] = $Aval;
}
}
}
$other_fields = apply_filters( 'amz_get_fileds_to_cache', array() );
if ( !empty( $other_fields ) ) {
foreach ( $other_fields as $k => $v ) {
if ( function_exists( 'get_field' ) ) {
$meta_val = get_field( $v, $apposts->ID, true );
} else {
//regular meta key
$meta_val = get_post_meta( $apposts->ID, '_' . $v, true );
}
if ( $meta_val != '' ) {
$newASN = explode( ',', trim( str_replace( ', ', ',', $meta_val ) ) );
if ( is_array( $newASN ) && !empty( $newASN ) ) {
foreach ( $newASN as $Aval ) {
$allASIN[] = $Aval;
}
}
}
}
}
//get scodes
foreach ( $scode_attrs as $scode ) {
if ( AmazonProduct_ShortcodeClass::appip_has_shortcode( $apposts->post_content, $scode ) ) {
if ( preg_match_all( '/' . $pattern . '/s', $apposts->post_content, $matches ) && array_key_exists( 2, $matches ) && in_array( $scode, $matches[ 2 ] ) ) {
foreach ( $matches[ 3 ] as $a ) {
$attrs = shortcode_parse_atts( $a );
if ( isset( $attrs[ 'partner_id' ] ) && $attrs[ 'partner_id' ] !== APIAP_ASSOC_ID ) {
// dont cache - different partner ID
// todo- add cache ahead for these circumstances
} elseif ( isset( $attrs[ 'locale' ] ) && $attrs[ 'locale' ] !== APIAP_LOCALE ) {
// dont cache - different locale
// todo- add cache ahead for these circumstances
} elseif ( isset( $attrs[ 'asin' ] ) && $attrs[ 'asin' ] !== '' ) {
$temp = explode( ',', $attrs[ 'asin' ] );
foreach ( $temp as $tempval ) {
if ( !in_array( $tempval, $allASIN ) )
$allASIN[] = $tempval;
}
} elseif ( 'amazon' == $scode && isset( $attrs[ 'template' ] ) && ( isset( $attrs[ 1 ] ) && strpos( $attrs[ 1 ], 'asin=' ) !== false ) ) {
//this is a special amazon code from old "Amazon Links" users
if ( isset( $temp[ 1 ] ) ) {
$temp = explode( 'asin=', $attrs[ 1 ] );
if ( !in_array( $temp[ 1 ], $allASIN ) )
$allASIN[] = $temp[ 1 ];
}
}
}
}
}
}
}
if ( !empty( $allASIN ) ) {
foreach ( $allASIN as $asinl ) {
$grASIN[ $asinl ] = $asinl;
}
}
if ( !empty( $grASIN ) ) {
//cache all the ones on the page if possible.
$params = array( 'ItemId' => $grASIN, 'CacheOnly' => true, "RequestBy" => 'cache-only-loop-start' );
amazon_plugin_aws_signed_request( '', $params );
}
}
return $posts;
}
//updated to production 4.0.0
add_filter( 'the_posts', 'amazon_plugin_postlist_detect_and_cache_ASINs' );
function maybe_convert_encoding( $text ) {
$encmode_temp = mb_detect_encoding( "aeiou�", mb_detect_order() );
$encodemode = get_bloginfo( 'charset' );
if ( $encmode_temp != $encodemode ) {
return mb_convert_encoding( $text, $encodemode, $encmode_temp );
}
return $text;
}
function appip_product_array_processed_add_variants( $resultarr, $newWin = '' ) {
$resultArrNew = array();
if ( !( is_array( $resultarr ) && !empty( $resultarr ) ) )
return $resultArrNew;
foreach ( $resultarr as $key => $val ) {
if ( isset( $val[ 'Offers_TotalOffers' ] ) && $val[ 'Offers_TotalOffers' ] == '0' ) {
$varLowPrice = isset( $val[ 'VariationSummary_LowestSalePrice_FormattedPrice' ] ) ? $val[ 'VariationSummary_LowestSalePrice_FormattedPrice' ] : ( isset( $val[ 'VariationSummary_LowestPrice_FormattedPrice' ] ) ? $val[ 'VariationSummary_LowestPrice_FormattedPrice' ] : '' );
$varHiPrice = isset( $val[ 'VariationSummary_HighestPrice_FormattedPrice' ] ) ? $val[ 'VariationSummary_HighestPrice_FormattedPrice' ] : '';
$varTotalNum = isset( $val[ 'Variations_TotalVariations' ] ) ? ( int )$val[ 'Variations_TotalVariations' ] : 0;
$hasMainList = isset( $val[ 'ItemAttributes_ListPrice_FormattedPrice' ] ) ? 1 : 0;
if ( $hasMainList == 1 ) {
$val[ 'ListPrice' ] = isset( $val[ 'ItemAttributes_ListPrice_FormattedPrice' ] ) ? $val[ 'ItemAttributes_ListPrice_FormattedPrice' ] : '';
}
if ( $varTotalNum > 0 ) {
if ( $varTotalNum == 1 ) {
//Set Main Image as first variant Image if product does not have Image
$val[ 'MediumImage' ] = isset( $val[ 'LargeImage_URL' ] ) && $val[ 'LargeImage_URL' ] != '' ? $val[ 'LargeImage_URL' ] : ( isset( $val[ 'Variations_Item_LargeImage_URL' ] ) ? $val[ 'Variations_Item_LargeImage_URL' ] : '' );
$val[ 'LargeImage' ] = isset( $val[ 'LargeImage_URL' ] ) && $val[ 'LargeImage_URL' ] != '' ? $val[ 'LargeImage_URL' ] : ( isset( $val[ 'Variations_Item_LargeImage_URL' ] ) ? $val[ 'Variations_Item_LargeImage_URL' ] : '' );;
} else {
//Set Main Image as first variant Image if product does not have Image
$val[ 'MediumImage' ] = isset( $val[ 'LargeImage_URL' ] ) && $val[ 'LargeImage_URL' ] != '' ? $val[ 'LargeImage_URL' ] : ( isset( $val[ 'Variations_Item_0_LargeImage_URL' ] ) ? $val[ 'Variations_Item_0_LargeImage_URL' ] : '' );
$val[ 'LargeImage' ] = isset( $val[ 'LargeImage_URL' ] ) && $val[ 'LargeImage_URL' ] != '' ? $val[ 'LargeImage_URL' ] : ( isset( $val[ 'Variations_Item_0_LargeImage_URL' ] ) ? $val[ 'Variations_Item_0_LargeImage_URL' ] : '' );;
}
//Set New price for "from X to Y"
if ( $varLowPrice != '' && $varHiPrice != '' ) {
$val[ 'LowestNewPrice' ] = $varLowPrice . ' – ' . $varHiPrice;
}
//Set Total New
$val[ "TotalNew" ] = 1; //needs to be at least one to not show "Out of Stock".
$val[ "PriceHidden" ] = 0;
$val[ "HideStockMsg" ] = 1;
//List Varients
$vartype = isset( $val[ 'Variations_VariationDimensions_VariationDimension' ] ) ? $val[ 'Variations_VariationDimensions_VariationDimension' ] : '';
if ( $vartype != '' ) {
$val[ 'VariantHTML' ] = '' . __( 'Variations:', 'amazon-product-in-a-post-plugin' ) . ' (' . $vartype . '):';
} else {
$val[ 'VariantHTML' ] = '
' . __( 'Variations:', 'amazon-product-in-a-post-plugin' ) . ':';
}
$target = $newWin == '' ? '' : $newWin;
$ImageSetsArray = array();
if ( $varTotalNum == 1 ) {
$varASIN = isset( $val[ 'Variations_Item_ASIN' ] ) ? $val[ 'Variations_Item_ASIN' ] : '';
if ( $hasMainList == 0 && isset( $val[ 'Variations_Item_ItemAttributes_ListPrice_FormattedPrice' ] ) ) {
$val[ 'ListPrice' ] = $val[ 'Variations_Item_ItemAttributes_ListPrice_FormattedPrice' ];
}
//for image sets
for ( $y = 0; $y < 10; $y++ ) {
if ( isset( $val[ 'Variations_Item_ImageSets_ImageSet_' . $y . '_LargeImage_URL' ] ) && isset( $val[ 'Variations_Item_ImageSets_ImageSet_' . $y . '_SmallImage_URL' ] ) ) {
$lgImg = $val[ 'Variations_Item_ImageSets_ImageSet_' . $y . '_LargeImage_URL' ];
$swImg = $val[ 'Variations_Item_ImageSets_ImageSet_' . $y . '_SmallImage_URL' ];
if ( $lgImg != '' && $swImg != '' ) {
$ImageSetsArray[] = '
!['.(apply_filters('appip_alt_text_gallery_img','Img - '.$val[ 'ASIN' ],$val[ 'ASIN' ])).'](' . $swImg . ')
' . "\n";
}
} else {
if ( $y > 9 ) {
break 1;
}
}
}
$varT = isset( $val[ 'Variations_Item_VariationAttributes_VariationAttribute_Value' ] ) ? $val[ 'Variations_Item_VariationAttributes_VariationAttribute_Value' ] : '';
$varC = isset( $val[ 'Variations_Item_Offers_Offer_OfferAttributes_Condition' ] ) ? $val[ 'Variations_Item_Offers_Offer_OfferAttributes_Condition' ] : '';
$varD = isset( $val[ 'Variations_Item_Offers_Offer_OfferListing_SalePrice_CurrencyCode' ] ) ? get_appipCurrCode( $val[ 'Variations_Item_Offers_Offer_OfferListing_SalePrice_CurrencyCode' ] ) : ( isset( $val[ 'Variations_Item_Offers_Offer_OfferListing_Price_CurrencyCode' ] ) ? get_appipCurrCode( $val[ 'Variations_Item_Offers_Offer_OfferListing_Price_CurrencyCode' ] ) : '' );
$varP = isset( $val[ 'Variations_Item_Offers_Offer_OfferListing_SalePrice_FormattedPrice' ] ) ? $val[ 'Variations_Item_Offers_Offer_OfferListing_SalePrice_FormattedPrice' ] : ( isset( $val[ 'Variations_Item_Offers_Offer_OfferListing_Price_FormattedPrice' ] ) ? $val[ 'Variations_Item_Offers_Offer_OfferListing_Price_FormattedPrice' ] : '' );
$linkStart = $varASIN != '' ? '
': '';
$linkEnd = $linkStart != '' ? '' : '';
$varL = $linkStart != '' ? ( $linkStart . $varT . $linkEnd ) : $varT;
$photo = isset( $val[ 'Variations_Item_SmallImage_URL' ] ) ? $linkStart . '

' . $linkEnd: '';
if ( $varT != '' && $varC != '' && $varP != '' ) {
$val[ 'VariantHTML' ] .= '
' . $photo . '' . $varL . ' — ' . $varC . ' ' . __( 'from', 'amazon-product-in-a-post-plugin' ) . ' ' . $varP . $varD . '
' . "\n";
}
$val[ 'VariantHTML' ] .= '
';
//Make Image Set from the first image for each varient
if ( !empty( $ImageSetsArray ) ) {
if ( count( $ImageSetsArray ) > 10 )
$ImageSetsArray = array_slice( $ImageSetsArray, 0, 10 );
$val[ 'AddlImages' ] = implode( "\n", $ImageSetsArray );
}
} else {
for ( $x = 0; $x <= ( $varTotalNum - 1 ); $x++ ) {
$varASIN = isset( $val[ 'Variations_Item_' . $x . '_ASIN' ] ) ? $val[ 'Variations_Item_' . $x . '_ASIN' ] : '';
if ( $x == 0 && $hasMainList == 0 && isset( $val[ 'Variations_Item_' . $x . '_ItemAttributes_ListPrice_FormattedPrice' ] ) ) {
$val[ 'ListPrice' ] = $val[ 'Variations_Item_' . $x . '_ItemAttributes_ListPrice_FormattedPrice' ];
}
//for image sets
for ( $y = 0; $y < 10; $y++ ) {
if ( isset( $val[ 'Variations_Item_' . $x . '_ImageSets_ImageSet_' . $y . '_LargeImage_URL' ] ) && isset( $val[ 'Variations_Item_' . $x . '_ImageSets_ImageSet_' . $y . '_SmallImage_URL' ] ) ) {
$lgImg = $val[ 'Variations_Item_' . $x . '_ImageSets_ImageSet_' . $y . '_LargeImage_URL' ];
$swImg = $val[ 'Variations_Item_' . $x . '_ImageSets_ImageSet_' . $y . '_SmallImage_URL' ];
if ( $lgImg != '' && $swImg != '' ) {
$ImageSetsArray[] = '
!['.(apply_filters('appip_alt_text_gallery_img','Img - '.$val[ 'ASIN' ],$val[ 'ASIN' ])).'](' . $swImg . ')
' . "\n";
}
} else {
if ( $y > 9 ) {
break 1;
}
}
}
$varT = isset( $val[ 'Variations_Item_' . $x . '_VariationAttributes_VariationAttribute_Value' ] ) ? $val[ 'Variations_Item_' . $x . '_VariationAttributes_VariationAttribute_Value' ] : '';
$varC = isset( $val[ 'Variations_Item_' . $x . '_Offers_Offer_OfferAttributes_Condition' ] ) ? $val[ 'Variations_Item_' . $x . '_Offers_Offer_OfferAttributes_Condition' ] : '';
$varD = isset( $val[ 'Variations_Item_' . $x . '_Offers_Offer_OfferListing_SalePrice_CurrencyCode' ] ) ? get_appipCurrCode( $val[ 'Variations_Item_' . $x . '_Offers_Offer_OfferListing_SalePrice_CurrencyCode' ] ) : ( isset( $val[ 'Variations_Item_' . $x . '_Offers_Offer_OfferListing_Price_CurrencyCode' ] ) ? get_appipCurrCode( $val[ 'Variations_Item_' . $x . '_Offers_Offer_OfferListing_Price_CurrencyCode' ] ) : '' );
$varP = isset( $val[ 'Variations_Item_' . $x . '_Offers_Offer_OfferListing_SalePrice_FormattedPrice' ] ) ? $val[ 'Variations_Item_' . $x . '_Offers_Offer_OfferListing_SalePrice_FormattedPrice' ] : ( isset( $val[ 'Variations_Item_' . $x . '_Offers_Offer_OfferListing_Price_FormattedPrice' ] ) ? $val[ 'Variations_Item_' . $x . '_Offers_Offer_OfferListing_Price_FormattedPrice' ] : '' );
$linkStart = $varASIN != '' ? '
': '';
$linkEnd = $linkStart != '' ? '' : '';
$varL = $linkStart != '' ? ( $linkStart . $varT . $linkEnd ) : $varT;
$photo = isset( $val[ 'Variations_Item_' . $x . '_SmallImage_URL' ] ) ? $linkStart . '

' . $linkEnd: '';
if ( $varT != '' && $varC != '' && $varP != '' ) {
$val[ 'VariantHTML' ] .= '
' . $photo . '' . $varL . ' — ' . $varC . ' ' . __( 'from', 'amazon-product-in-a-post-plugin' ) . ' ' . $varP . $varD . '
' . "\n";
}
}
$val[ 'VariantHTML' ] .= '
';
//Make Image Set from the first image for each varient
if ( !empty( $ImageSetsArray ) ) {
if ( count( $ImageSetsArray ) > 10 )
$ImageSetsArray = array_slice( $ImageSetsArray, 0, 10 );
$val[ 'AddlImages' ] = implode( "\n", $ImageSetsArray );
}
}
}
}
$resultArrNew[] = $val;
}
return $resultArrNew;
}
add_filter( 'appip_product_array_processed', 'appip_product_array_processed_add_variants', 10, 2 );
if ( !function_exists( 'awsImageGrabber' ) ) {
//Amazon Product Image from ASIN function - Returns HTML Image Code
function awsImageGrabber( $imgurl, $class = "" ) {
if ( $imgurl != '' ) {
return '
';
} else {
return '
';
}
}
}
/*
To filter labels:
add_filter('appip_text_newfrom', '_clear_appip_text');
function _clear_appip_text($val=''){
return 'Your Text Label Here';
}
*/
if ( !function_exists( 'checkSSLImages_tag' ) ) {
function checkSSLImages_tag( $img_URL, $class = '', $ASIN = '') {
if ( amazon_check_SSL_on() )
return '
';
return '
';
}
}
if ( !function_exists( 'checkSSLImages_url' ) ) {
function checkSSLImages_url( $img_URL ) {
if ( amazon_check_SSL_on() )
return plugin_aws_prodinpost_filter_text( $img_URL );
return $img_URL;
}
}
if ( !function_exists( 'awsImageGrabberURL' ) ) {
//Amazon Product Image from ASIN function - Returns URL only
function awsImageGrabberURL( $asin, $size = "M" ) {
$usSSL = amazon_check_SSL_on();
if ( $usSSL ) {
//http://images.amazon.com/images/P/B004RMK4BC.01._AA300_SCLZZZZZZZ_.jpg
$base_url = 'https://images-na.ssl-images-amazon.com/images/P/' . $asin . '.01.';
} else {
$base_url = 'http://images.amazon.com/images/P/' . $asin . '.01.';
}
if ( strcasecmp( $size, 'S' ) == 0 ) {
$base_url .= '_AA200_SCLZZZZZZZ_';
} else if ( strcasecmp( $size, 'L' ) == 0 ) {
$base_url .= '_AA450_SCSCRM_';
} else if ( strcasecmp( $size, 'H' ) == 0 ) { //huge
$base_url .= '_SCRM_';
} else if ( strcasecmp( $size, 'P' ) == 0 ) { //pop
$base_url .= '_AA800_SCRM_';
} else {
$base_url .= '_AA300_SCLZZZZZZZ_';
}
$base_url .= '.jpg';
return $base_url;
}
}
function amazon_check_SSL_on() {
$check = false;
if ( ( bool )get_option( 'apipp_ssl_images', false ) === true || strpos( get_bloginfo( 'url' ), 'https://' ) !== false ) {
$check = true;
}
return apply_filters( 'appip_use_ssl_images', $check );
}
function plugin_aws_prodinpost_filter_text( $content ) {
return str_replace( array( 'http://ecx.images-amazon', 'https://ecx.images-amazon' ), array( 'https://images-na.ssl-images-amazon', 'https://images-na.ssl-images-amazon' ), $content );
}
//add_filter('the_content', 'plugin_aws_prodinpost_filter_text', 20);
//add_filter('the_excerpt', 'plugin_aws_prodinpost_filter_text', 20);
//add_filter('widget_text', 'plugin_aws_prodinpost_filter_text', 20);
if ( !function_exists( 'awsImageURLModify' ) ) {
//Amazon Product Image from ASIN function - Returns URL only
function awsImageURLModify( $imgurl, $size = "P" ) {
//http://ecx.images-amazon.com/images/I/
$usSSL = amazon_check_SSL_on();
if ( $usSSL )
$imgurl = str_replace( 'http://ecx.images-amazon.com/', 'https://images-na.ssl-images-amazon.com/', $imgurl );
$base_url = str_replace( '.jpg', '.', $imgurl );
if ( strcasecmp( $size, 'S' ) == 0 ) {
$base_url .= '_SY200_';
} else if ( strcasecmp( $size, 'L' ) == 0 ) {
$base_url .= '_SY450_';
} else if ( strcasecmp( $size, 'H' ) == 0 ) { //huge
$base_url .= '_SY1200_';
} else if ( strcasecmp( $size, 'P' ) == 0 ) { //pop
$base_url .= '_SY800_';
} else {
$base_url .= '_SY300_';
}
$base_url .= '.jpg';
return $base_url;
}
}
function appip_delete_cache_ajax() {
check_ajax_referer( 'appip_cache_delete_nonce_ji9osdjfkjl', 'appip_nonce', true );
if ( !isset( $_POST[ 'appip-cache-id' ] ) || !current_user_can( 'manage_options' ) ) {
echo 'error';
exit;
}
// removed direct use of post value.
$cacheid = isset( $_POST[ 'appip-cache-id' ] ) && ( int )$_POST[ 'appip-cache-id' ] != 0 ? ( int )$_POST[ 'appip-cache-id' ] : 0;
global $wpdb;
if ( $cacheid == 0 ) {
$tempswe = $wpdb->query( "DELETE FROM {$wpdb->prefix}amazoncache;" );
} else {
$tempswe = $wpdb->query( "DELETE FROM {$wpdb->prefix}amazoncache WHERE Cache_id ='{$cacheid}' LIMIT 1;" );
}
if ( $tempswe ) {
echo 'deleted';
} else {
echo 'error';
}
exit;
}
add_action( 'wp_ajax_appip-cache-del', 'appip_delete_cache_ajax' );
/**
* Delete All product Cache Files.
* Delete all cache files on options update, so nothing is cached with old variables.
*
* @since 3.6.2
* @global $wpdb
* @param string $reason allowed value is 'option-update'
*/
function amazon_product_delete_all_cache( $reason = '' ) {
if ( $reason == 'option-update' ) {
global $wpdb;
$tempswe = $wpdb->query( "DELETE FROM {$wpdb->prefix}amazoncache;" );
}
}
/**
* Enqueue styles for plugin.
* Replaces previous function aws_prodinpost_addhead().
*
* @since 3.5.3
*
* @return none.
*/
function appip_addhead_new_ajax() {
if ( file_exists( get_stylesheet_directory() . '/appip-styles.css' ) ) {
wp_enqueue_style( 'appip-theme-styles', get_stylesheet_directory_uri() . '/appip-styles.css', array(), null );
} elseif ( file_exists( get_stylesheet_directory() . '/css/appip-styles.css' ) ) {
wp_enqueue_style( 'appip-theme-styles', get_stylesheet_directory_uri() . '/css/appip-styles.css', array(), null );
} else {
wp_enqueue_style( 'amazon-default-styles', plugins_url( 'css/amazon-default-plugin-styles.css', dirname( __FILE__ ) ), array(), filemtime( dirname( plugin_dir_path( __FILE__ ) ) . '/css/amazon-default-plugin-styles.css' ) );
}
// for adding in extra user styles after all the styles are loaded.
$usemine = get_option( 'apipp_product_styles_mine', false );
$uselightbox = ( bool )get_option( 'apipp_amazon_use_lightbox', false ) === true ? true : false;
if ( $uselightbox ) {
wp_enqueue_style( 'appip-amazon-lightbox', plugins_url( 'css/amazon-lightbox.css', dirname( __FILE__ ) ), array('amazon-grid-shortcode'), filemtime( dirname( plugin_dir_path( __FILE__ ) ) . '/css/amazon-lightbox.css' ) );
wp_enqueue_script( 'appip-amazon-lightbox', plugins_url( 'js/amazon-lightbox.js', dirname( __FILE__ ) ), array( 'jquery' ), filemtime( dirname( plugin_dir_path( __FILE__ ) ) . '/js/amazon-lightbox.js' ) );
}
if($usemine ) {
$data = wp_kses( get_option( 'apipp_product_styles', '' ), array( "\'", '\"' ) );
if($uselightbox) // enqueue after lightbox if loaded - so styles can be overriden
wp_add_inline_style( 'appip-amazon-lightbox', $data );
else
wp_add_inline_style( 'amazon-grid-shortcode', $data );
}
}
add_action( 'wp_enqueue_scripts', 'appip_addhead_new_ajax', 101 );
function amazon_product_check_in_cache( $items ) {
global $amazonCache, $cacheClean;
if ( is_array( $cacheClean ) && !empty( $cacheClean ) ) {
$cachedASINs = $cacheClean;
} else {
$completeCache = $amazonCache->get_amazon_plugin_cache( 'product' );
$cachedASINs = array();
if ( is_array( $completeCache ) && !empty( $completeCache ) ) {
foreach ( $completeCache as $resultkey => $resultvalue ) {
$tempURL = explode( ":", $resultvalue->URL );
$tempASINs = isset($tempURL[ 1 ]) ? explode( ',', $tempURL[ 1 ] ) : array();
if ( isset($tempURL[ 1 ]) && !empty( $tempURL[ 1 ] ) )
$cachedASINs = array_unique( array_merge( $cachedASINs, $tempASINs ) );
}
}
}
$final = true;
if ( is_array( $items ) ) {
foreach ( $items as $k => $item ) {
if ( in_array( $item, $cachedASINs ) )
$final = false;
}
return $final;
} else {
if ( in_array( $items, $cachedASINs ) )
return true;
}
return false;
}
function amazon_appip_register_button( $buttons ) {
array_push( $buttons, "|", "amazon_products" );
return $buttons;
}
function amazon_appip_add_plugin( $plugin_array ) {
$plugin_array[ 'amazon_products' ] = plugins_url( '/js/wysiwyg/amazon_editor.js', dirname( __FILE__ ) );
return $plugin_array;
}
function amazon_appip_editor_button() {
if ( is_admin() ) {
if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
return;
}
if ( get_user_option( 'rich_editing' ) == 'true' ) {
add_filter( 'mce_external_plugins', 'amazon_appip_add_plugin' );
add_filter( 'mce_buttons', 'amazon_appip_register_button' );
}
}
}
class amazonAPPIP_ButtonURLFix2016 {
public function __construct() {
add_action( 'admin_menu', array( $this, 'apipp_plugin_menu' ), 11 );
/* uploaded button overeride */
add_filter( 'appip_amazon_button_url', array( $this, 'change_the_button' ), 10, 1 );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );
add_action( 'init', array( $this, 'appip_parse' ) );
/* Main Override to fix new Buttons - This can be overridden if a button is uploaded */
add_filter( 'appip_amazon_button_url', array( $this, 'button_url_for_locale' ), 5, 3 );
}
public function apipp_plugin_menu() {
add_submenu_page( 'apipp-main-menu', __( "Button Settings", 'amazon-product-in-a-post-plugin' ), __( 'Button Settings', 'amazon-product-in-a-post-plugin' ), 'manage_options', 'apipp_plugin-button-url', array( $this, 'apipp_options_button_url_page' ) );
}
public function change_the_button( $url ) {
$button_URL = get_option( 'amazon-button-image', '' );
if ( $button_URL != '' )
return $button_URL;
return $url;
}
public function admin_enqueue( $hook ) {
if ( strpos($hook, 'page_apipp_plugin-button-url') !== false ) {
wp_enqueue_media();
//wp_enqueue_style( 'wp-color-picker');
wp_enqueue_script( 'appip_admin_buttons', plugin_dir_url( dirname( __FILE__ ) ) . 'js/amazon-button-admin.js', array( 'media-upload' ) );
}
}
public function button_url_for_locale( $url = '', $button = '', $locale = '' ) {
$button = 'new-buyamzon-button-' . $locale . '.png';
$newurl = plugins_url( '/images/' . $button, dirname( __FILE__ ) );
return $newurl;
}
public function appip_parse() {
if ( is_admin() && isset( $_POST[ 'amazon-button-image' ] ) && $_POST[ 'amazon-button-image' ] !== '' ) {
check_admin_referer( 'appip_admin_button_url', 'security' );
update_option( 'amazon-button-image', esc_url_raw( $_POST[ 'amazon-button-image' ] ) );
wp_redirect( admin_url( 'admin.php?page=apipp_plugin-button-url' ), 301 );
exit;
} elseif ( is_admin() && isset( $_POST[ 'amazon-button-image' ] ) && $_POST[ 'amazon-button-image' ] === '' ) {
check_admin_referer( 'appip_admin_button_url', 'security' );
update_option( 'amazon-button-image', '' );
wp_redirect( admin_url( 'admin.php?page=apipp_plugin-button-url' ), 301 );
exit;
}
}
public function apipp_options_button_url_page() {
$button = esc_url_raw( get_option( 'amazon-button-image', '' ) );
$buttonImg = '';
if ( $button != '' ) {
$buttonImg = '' . __( 'Current Button Image:', 'amazon-product-in-a-post-plugin' ) . '

';
} else {
$buttonImg = '';
}
$radmore_text = _x('Read More','Button text','amazon-product-in-a-post-plugin');
$buyfrom_text= _x('Buy from Amazon','Button text - Locale will be appended to this text. i.e., Buy From Amazon.com','amazon-product-in-a-post-plugin').'.'.APIAP_LOCALE;
add_thickbox();
echo '';
echo '
' . __( 'Amazon Button Settings', 'amazon-product-in-a-post-plugin' ) . '
';
echo '
';
echo '
' . __( 'Set New Default button to use with all Amazon products. Clear the upload field and save blank to delete button.', 'amazon-product-in-a-post-plugin' ) . '
';
echo '
' . __( 'Other Button Options', 'amazon-product-in-a-post-plugin' ) . '
';
echo '
';
echo '
';
}
}
new amazonAPPIP_ButtonURLFix2016();
function amazon_product_get_new_button_array( $locale ){
$btn_arr = array(
"read-more" => array('color'=> '', 'text' => 'Read More' ),
"read-more-red" => array('color'=> '--red', 'text' => 'Read More' ),
"read-more-blue" => array('color'=> '--blue', 'text' => 'Read More' ),
"read-more-green" => array('color'=> '--green', 'text' => 'Read More' ),
"buy-from" => array('color'=> '','text' => 'Buy from Amazon' .'.'. $locale ),
"buy-from-red" => array('color'=> '--red','text' => 'Buy from Amazon' .'.'. $locale ),
"buy-from-blue" => array('color'=> '--blue','text' => 'Buy from Amazon' .'.'. $locale ),
"buy-from-green" => array('color'=> '--green','text' => 'Buy from Amazon' .'.'. $locale ),
"read-more-rounded" => array('color'=> '', 'text' => 'Read More'),
"read-more-red-rounded" => array('color'=> '--red', 'text' => 'Read More'),
"read-more-blue-rounded" => array('color'=> '--blue', 'text' => 'Read More' ),
"read-more-green-rounded" => array('color'=> '--green', 'text' => 'Read More' ),
"buy-from-rounded" => array('color'=> '', 'text' => 'Buy from Amazon' .'.'. $locale ),
"buy-from-red-rounded" => array('color'=> '--red', 'text' => 'Buy from Amazon' .'.'. $locale ),
"buy-from-blue-rounded" => array('color'=> '--blue', 'text' => 'Buy from Amazon' .'.'. $locale ),
"buy-from-green-rounded" => array('color'=> '--green', 'text' => 'Buy from Amazon' .'.'. $locale )
);
$btn_arr = apply_filters('amazon-add-new-button-array',$btn_arr,$locale);
return $btn_arr;
}