.
*/
// Variables
define( 'APIAP_PLUGIN_VER', '3.8.0' );
define( 'APIAP_DBASE_VER', '3.7.0' );
define( 'APIAP_PUB_KEY', get_option( 'apipp_amazon_publickey', '' ) );
define( 'APIAP_SECRET_KEY', get_option( 'apipp_amazon_secretkey', '' ) );
define( 'APIAP_ASSOC_ID', get_option( 'apipp_amazon_associateid', '' ) );//Amazon Partner ID
define( 'APIAP_LOCALE', get_option( 'apipp_amazon_locale', 'com' ) ); // default to Amazon.com
global $thedefaultapippstyle;
global $amazonhiddenmsg;
global $amazonerrormsg;
global $apipphookexcerpt;
global $apipphookcontent;
global $apippopennewwindow;
global $apippnewwindowhtml;
global $encodemode;
global $awspagequery;
global $debuggingAPPIP;
register_activation_hook(__FILE__,'appip_install');
register_deactivation_hook(__FILE__,'appip_deinstall');
// MISC Settings, etc.
//if(get_option('apipp_amazon_use_lightbox', 'notset') == 'notset'){ update_option('apipp_amazon_use_lightbox','true');}
$debuggingAPPIP = false;
$appipitemnumber = 0;
$awspagequery = '';
$awsPageRequest = 1;
$amazonhiddenmsg = get_option( 'apipp_amazon_hiddenprice_message', __( 'Visit Amazon for Price.', 'amazon-product-in-a-post-plugin' )); //Amazon Hidden Price Message
$amazonerrormsg = get_option( 'apipp_amazon_notavailable_message',__( 'Product Unavailable.', 'amazon-product-in-a-post-plugin' ) ); //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', true ); //open in new window?
$thereapippstyles = get_option( "apipp_product_styles_default" );
$apippnewwindowhtml = (bool) $apippopennewwindow === true ? ' target="amazonwin" ' : '';
$apip_getmethod = get_option( 'apipp_API_call_method' );
$encodemode = get_option( 'appip_encodemode', 'UTF-8' ); //UTF-8 will be default
//Encode Mode
if( get_option( 'appip_encodemode', '' ) == '' ){
update_option( 'appip_encodemode', 'UTF-8' ); //set default to UTF-8
$encodemode = "UTF-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 = array(), $encstrict = false ){
return $etext;
}
}
if(!function_exists('mb_detect_order')){
function mb_detect_order(){
return array('ASCII','ISO-8859-1','UTF-8');
}
}
// Change encoding if needed via GET - use :
// http://yoursite.com/?resetenc=[encode mode] i.e., http://yoursite.com/?resetenc=UTF-8 or http://yoursite.com/?resetenc=ISO-8859-1, etc.
// This will be the mode you want the text OUTPUT as. Note - You MUST be logged in and have 'manage_options' (administrator) capabilities.
if( isset( $_GET['resetenc'] ) && ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || can_set_debug() ){
$validEncModes = apply_filters('amazon-product-valid-enc-modes', array('ISO-8859-1','ASCII','ISO-8859-2','ISO-8859-3','ISO-8859-4','ISO-8859-5','ISO-8859-6','ISO-8859-7','ISO-8859-8','ISO-8859-9','ISO-8859-10','ISO-8859-15','ISO-2022-JP','ISO-2022-JP-2','ISO-2022-KR','UTF-8','UTF-16'));
if( in_array( strtoupper( $_GET[ 'resetenc' ] ), $validEncModes ) ){
update_option( 'appip_encodemode', strtoupper( esc_attr( $_GET['resetenc'] ) ) );
$encodemode = strtoupper( esc_attr($_GET['resetenc'] ) );
}
}
if(trim(get_option("apipp_product_styles",'')) == '') //reset to default styles if user deletes styles in admin
update_option("apipp_product_styles",$thedefaultapippstyle);
if(trim(get_option("apipp_amazon_debugkey",'')) == ''){ //generate debug key
$randomkey = md5( uniqid( get_bloginfo( 'url' ) . time(), true ) );
update_option( "apipp_amazon_debugkey", $randomkey );
}
// Filters & Hooks
//add_action('wp','aws_prodinpost_cartsetup', 1, 2); //Future Item
add_filter( 'the_content', 'aws_prodinpost_filter_content_test', 1); //hook content - we will filter the override after
add_filter( 'the_excerpt', 'aws_prodinpost_filter_excerpt_test', 1); //hook excerpt - we will filter the override after
add_filter( 'get_the_excerpt', 'aws_prodinpost_filter_get_excerpt', 1);
add_filter( 'amazon-hide-binding-in-title', function($val, $binding = ''){
// override this with a later priority than 1 if you want to turn off for certain bindings.
/* example for turning off for a specific binding:
if(strtolower($binding) == 'kitchen')
return true;
*/
if( (bool) get_option('apipp_hide_binding', false) === true)
return true;
}, 1, 2);
add_filter( 'plugin_row_meta', function( $links, $file ){
if ( $file == plugin_basename(__FILE__) ){
//$links[] = 'Getting Started';
$links[] = '[]Shortcode Usage';
$links[] = 'FAQs';
$links[] = 'Donate';
}
return $links;
}, 10, 2 );
add_action( 'plugin_action_links_' . plugin_basename(__FILE__), function($links){
$new_links = array();
$new_links[] = 'Getting Started';
return array_merge($links,$new_links );
});
// Warnings Quickfix
if( (bool) get_option( 'apipp_hide_warnings_quickfix', false ) === true ){
if(!(defined('WP_DEBUG') && WP_DEBUG))//do nothing if WP_DEBUG is on - warnings and notices should show in debug mode no matter what. Fixed 3.7.1
ini_set("display_errors", 0); //turns off error display
}
// Includes
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-activation.php"); //Install and Uninstall hooks
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-functions.php"); //Functions
if (version_compare(phpversion(), '5.4.0', '<='))
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-sha256.inc.php"); //3.8.0+ only require if PHP version is less than 5.4.0
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-get-product.php"); //main product function
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-aws-signed-request.php"); //major workhorse for plugin
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-aws-signed-request-test.php"); //class for testing the request.
//require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-translations.php"); //translations for plugin - REMOVED 3.7
//require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-styles-product.php"); //styles for plugin - REMOVED 3.6.0
//require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-shortcodes.php"); //shortcodes for plugin - REMOVED 3.7.1
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-shortcode-class.php"); //shortcode class for plugin
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-shortcode-amazon-elements.php"); //amazon-element shortcodes for plugin
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-shortcode-amazon-products.php"); //amazonproducr shortcodes for plugin
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-shortcode-search.php"); //search shortcodes for plugin
add_action('plugins_loaded', function(){
// we need to make sure this loads late enough so the plugin takes priority (may change later if needed)
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-shortcode-grid.php"); //grid shortcodes for plugin (add-on plugin overrides this). ADDED 3.7.1
}, 11);
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-featured-image.php"); //Featured Image Function for URL based Amazon Featured images.
if(is_admin()){
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-tools.php"); //edit box for plugin
require_once( plugin_dir_path( __FILE__ )."/inc/amazon-product-in-a-post-options.php"); //admin options for plugin
require_once( plugin_dir_path( __FILE__ ).'/inc/amazon-product-in-a-post-add-tmce.php' ); //editor Button Funcitonality
require_once( plugin_dir_path( __FILE__ ).'/inc/amazon-product-in-a-post-debug.php' ); //debug functionality for plugin
}
if(version_compare(APIAP_PLUGIN_VER, get_option("apipp_product_upgraded_version", '0.0.0'), '>' )){
//add other items needed.
update_option("apipp_amazon_use_lightbox", 'true');
update_option("apipp_product_upgraded_version", APIAP_PLUGIN_VER);
}
if ( is_admin() && !( defined('DOING_AJAX') && DOING_AJAX )){
//upgrade check. Lets me add/change the default style etc to fix/add new items during updrages.
if(get_option("apipp_product_styles_default",'') == ''){
update_option( "apipp_product_styles_default", $thedefaultapippstyle);
}
$thisstyleversion = get_option( 'apipp_product_styles_default_version', '0' );
if($thisstyleversion != "2.1"){
update_option("apipp_product_styles_default_version", "2.1");
//add the new element style to their custom ones - so at least it has the default functionality. They can change it after if they like
$apipp_product_styles_cust_temp = get_option("apipp_product_styles",'');
//$apipp_product_styles_cust_temp = $apipp_product_styles_cust_temp;
if($apipp_product_styles_cust_temp != ''){
update_option("apipp_product_styles",'/*version 2.1 Modified*/'."\n".$apipp_product_styles_cust_temp."\n.amazon-elements-wrapper,.amazon-element-wrapper{clear: both;}");
}
if( get_option("apipp_amazon_notavailable_message",'') == ''){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
if( get_option("apipp_amazon_hiddenprice_message",'') == ''){update_option("apipp_amazon_hiddenprice_message","Price Not Listed");} //default message - done
if( get_option("apipp_hook_content",'') == ''){update_option("apipp_hook_content","1");} //default is yes - done
if( get_option("apipp_hook_excerpt",'') == ''){update_option("apipp_hook_excerpt","0");} //default is no - done
if( get_option("apipp_open_new_window",'') == ''){update_option('apipp_open_new_window',"0");} //default is no - newoption added at 1.6 - done
}
}
function can_set_debug(){
global $debuggingAPPIP;
if( $debuggingAPPIP )
return true;
return false;
}
function appip_admin_scripts($hook) {
wp_enqueue_style( 'amazon-plugin-admin-styles',plugins_url('/css/amazon-admin.css',__FILE__),null,'15-07-12');
if ( $hook == "amazon-product_page_appip-layout-styles" ) {
//wp_enqueue_script('jquery');
//wp_enqueue_script('jquery-ui-core');
//wp_enqueue_script('jquery-ui-sortable');
}elseif("amazon-product_page_apipp-cache-page" == $hook || $hook == "post.php" || $hook == "post-new.php" || $hook == "edit.php"){
wp_enqueue_script('amazon-plugin-admin',plugins_url('/js/amazon-admin.js',__FILE__),array('jquery-ui-tooltip'),'15-07-12');
wp_localize_script('amazon-plugin-admin','appipData',array( 'ajaxURL' => admin_url('admin-ajax.php'), 'appip_nonce' => wp_create_nonce( 'appip_cache_delete_nonce_ji9osdjfkjl' ), 'confirmDel' => __('Are you sure you want to delete this cache?', 'amazon-product-in-a-post-plugin'),'noCacheMsg' => __('no cached products at this time', 'amazon-product-in-a-post-plugin'), 'deleteMsgErr' => __('there was an error - the cache could not be deleted', 'amazon-product-in-a-post-plugin') ) );
}elseif( "amazon-product_page_apipp_plugin_admin" == $hook || "amazon-product_page_apipp_plugin-shortcode" == $hook){
add_thickbox();
wp_enqueue_style( 'plugin-install' );
wp_enqueue_script('amazon-plugin-admin-options',plugins_url('/js/amazon-admin-options.js',__FILE__),array('jquery'),'16-09-20');
wp_enqueue_script('amazon-plugin-admin',plugins_url('/js/amazon-admin.js',__FILE__),array('jquery-ui-tooltip'),'15-07-12');
}elseif( "amazon-product_page_apipp-add-new" == $hook ){
wp_enqueue_style( 'plugin-install' );
wp_enqueue_script('amazon-plugin-admin',plugins_url('/js/amazon-admin.js',__FILE__),array('jquery'),'15-07-12');
//wp_localize_script('amazon-plugin-admin','appipData',array( 'ajaxURL' => admin_url('admin-ajax.php'), 'appip_nonce' => wp_create_nonce( 'appip_cache_delete_nonce_ji9osdjfkjl' ), 'confirmDel' => __('Are you sure you want to delete this cache?', 'amazon-product-in-a-post-plugin'),'noCacheMsg' => __('no cached products at this time', 'amazon-product-in-a-post-plugin'), 'deleteMsgErr' => __('there was an error - the cache could not be deleted', 'amazon-product-in-a-post-plugin') ) );
add_thickbox();
}
}
add_action( 'admin_enqueue_scripts', 'appip_admin_scripts' );