Amazon Associates Link Builder - Version 1.4.12

Version Description

Tracking IDs are associated with marketplaces in the revamped settings page and add shortcode popup.

Download this release

Release Info

Developer amazonlinkbuilder
Plugin Icon 128x128 Amazon Associates Link Builder
Version 1.4.12
Comparing to
See all releases

Code changes from version 1.4.11 to 1.4.12

aalb_config.php CHANGED
@@ -13,7 +13,10 @@ and limitations under the License.
13
  */
14
 
15
  //version
16
- define( 'AALB_PLUGIN_CURRENT_VERSION', '1.4.11' );
 
 
 
17
 
18
  //PHP version compatible for AALB plugin
19
  define( 'AALB_PLUGIN_MINIMUM_SUPPORTED_PHP_VERSION', '5.3.0' );
@@ -63,6 +66,7 @@ define( 'AALB_INCLUDES_DIR', AALB_PLUGIN_DIR . 'includes/' );
63
  define( 'AALB_PAAPI_DIR', AALB_PLUGIN_DIR . 'lib/php/Paapi/' );
64
  define( 'AALB_SHORTCODE_DIR', AALB_PLUGIN_DIR . 'shortcode/' );
65
  define( 'AALB_LIBRARY_DIR', AALB_PLUGIN_DIR . 'lib/php/' );
 
66
 
67
  //Includes
68
  define( 'AALB_ACTIVATOR_PHP', AALB_PLUGIN_DIR . 'includes/aalb_activator.php' );
@@ -156,6 +160,7 @@ define( 'AALB_AWS_ACCESS_KEY', 'aalb_aws_access_key' );
156
  define( 'AALB_AWS_SECRET_KEY', 'aalb_aws_secret_key' );
157
  define( 'AALB_CRED_CONFIG_GROUP', 'aalb_cred_config_group' );
158
  define( 'AALB_STORE_ID_NAMES', 'aalb_store_id_names' );
 
159
  define( 'AALB_SHOW_HTTP_WARNING_ONCE', 'aalb_show_http_warning_once' );
160
  define( 'AALB_PLUGIN_VERSION', 'aalb_plugin_version' );
161
  define( 'AALB_NO_REFERRER_DISABLED', 'aalb_no_referrer_disabled' );
@@ -280,6 +285,11 @@ define( 'AALB_PAAPI_SIGN_UP_URL', 'http://docs.aws.amazon.com/AWSECommerceServic
280
  define( 'AALB_MANAGE_PAAPI_US_ACCOUNT_URL', 'https://affiliate-program.amazon.com/gp/advertising/api/detail/your-account.html' );
281
  define( 'AALB_PAAPI_EFFICIENCY_GUIDELINES_URL', 'http://docs.aws.amazon.com/AWSECommerceService/latest/DG/TroubleshootingApplications.html#efficiency-guidelines' );
282
 
 
 
 
283
  define( 'AALB_NEW_PAGE_TARGET', "_blank" );
284
 
 
 
285
  ?>
13
  */
14
 
15
  //version
16
+ define( 'AALB_PLUGIN_CURRENT_VERSION', '1.4.12' );
17
+
18
+ //Version no. with multi locale settings page
19
+ define( 'AALB_MULTI_LOCALE_SETTINGS_PLUGIN_VERSION', '1.4.12' );
20
 
21
  //PHP version compatible for AALB plugin
22
  define( 'AALB_PLUGIN_MINIMUM_SUPPORTED_PHP_VERSION', '5.3.0' );
66
  define( 'AALB_PAAPI_DIR', AALB_PLUGIN_DIR . 'lib/php/Paapi/' );
67
  define( 'AALB_SHORTCODE_DIR', AALB_PLUGIN_DIR . 'shortcode/' );
68
  define( 'AALB_LIBRARY_DIR', AALB_PLUGIN_DIR . 'lib/php/' );
69
+ define( 'AALB_SIDEBAR_HELPER_DIR', AALB_PLUGIN_DIR . 'admin/sidebar/partials/helper/' );
70
 
71
  //Includes
72
  define( 'AALB_ACTIVATOR_PHP', AALB_PLUGIN_DIR . 'includes/aalb_activator.php' );
160
  define( 'AALB_AWS_SECRET_KEY', 'aalb_aws_secret_key' );
161
  define( 'AALB_CRED_CONFIG_GROUP', 'aalb_cred_config_group' );
162
  define( 'AALB_STORE_ID_NAMES', 'aalb_store_id_names' );
163
+ define( 'AALB_STORE_IDS', 'aalb_store_ids' );
164
  define( 'AALB_SHOW_HTTP_WARNING_ONCE', 'aalb_show_http_warning_once' );
165
  define( 'AALB_PLUGIN_VERSION', 'aalb_plugin_version' );
166
  define( 'AALB_NO_REFERRER_DISABLED', 'aalb_no_referrer_disabled' );
285
  define( 'AALB_MANAGE_PAAPI_US_ACCOUNT_URL', 'https://affiliate-program.amazon.com/gp/advertising/api/detail/your-account.html' );
286
  define( 'AALB_PAAPI_EFFICIENCY_GUIDELINES_URL', 'http://docs.aws.amazon.com/AWSECommerceService/latest/DG/TroubleshootingApplications.html#efficiency-guidelines' );
287
 
288
+ //Plugin specific URLS
289
+ define( 'AALB_SETTINGS_PAGE_URL', admin_url( 'admin.php?page=associates-link-builder-settings' ) );
290
+
291
  define( 'AALB_NEW_PAGE_TARGET', "_blank" );
292
 
293
+ define( 'AALB_NEWLINE_SEPARATOR', "\r\n" );
294
+
295
  ?>
admin/aalb_admin.php CHANGED
@@ -29,6 +29,8 @@ class Aalb_Admin {
29
  private $tracking_api_helper;
30
  private $helper;
31
  private $compatibility_helper;
 
 
32
 
33
  public function __construct() {
34
  $this->compatibility_helper = new Aalb_Compatibility_Helper();
@@ -36,16 +38,29 @@ class Aalb_Admin {
36
  $this->remote_loader = new Aalb_Remote_Loader();
37
  $this->tracking_api_helper = new Aalb_Tracking_Api_Helper();
38
  $this->helper = new Aalb_Helper();
 
 
39
  }
40
 
41
  /**
42
- * Checks whether PA-API Credentials are set
43
  *
44
  * @since 1.4.5
45
  * @return boolean true if PA-API credentials are set
46
  */
47
- public function aalb_is_paapi_credentials_set() {
48
- return !( get_option( AALB_AWS_ACCESS_KEY ) == '' or get_option( AALB_AWS_SECRET_KEY ) == '' );
 
 
 
 
 
 
 
 
 
 
 
49
  }
50
 
51
  /**
@@ -85,16 +100,19 @@ class Aalb_Admin {
85
  */
86
  private function get_paapi_pref() {
87
  return array(
88
- 'max_search_result_items' => AALB_MAX_SEARCH_RESULT_ITEMS,
89
- 'store_id' => get_option( AALB_DEFAULT_STORE_ID ),
90
- 'marketplace' => get_option( AALB_DEFAULT_MARKETPLACE ),
91
- 'ajax_url' => admin_url( 'admin-ajax.php' ),
92
- 'action' => 'get_item_search_result',
93
- 'item_search_nonce' => wp_create_nonce( 'aalb-item-search-nonce' ),
94
- 'AALB_SHORTCODE_AMAZON_LINK' => AALB_SHORTCODE_AMAZON_LINK,
95
- 'AALB_SHORTCODE_AMAZON_TEXT' => AALB_SHORTCODE_AMAZON_TEXT,
96
- 'IS_PAAPI_CREDENTIALS_SET' => $this->aalb_is_paapi_credentials_set(),
97
- 'WORDPRESS_REQUEST_TIMEOUT' => AALB_WORDPRESS_REQUEST_TIMEOUT
 
 
 
98
  );
99
  }
100
 
@@ -107,13 +125,31 @@ class Aalb_Admin {
107
  */
108
  private function get_aalb_strings() {
109
  return array(
110
- "template_asin_error" => esc_html__( "Only one product can be selected for this template", 'amazon-associates-link-builder' ),
111
- "no_asin_selected_error" => esc_html__( "Please select at least one product for display", 'amazon-associates-link-builder' ),
112
- "empty_product_search_bar" => esc_html__( "Please Enter a Product Name ", 'amazon-associates-link-builder' ),
113
- "short_code_create_failure" => esc_html__( "Failed to create Text Link shortcode. Editor has some text selected. Only one item can be selected while adding text links", 'amazon-associates-link-builder' ),
114
  /* translators: %s: Email-id of the support */
115
- "paapi_request_timeout_error" => sprintf( esc_html__( "Request timed out. Try again after some time. Please check your network and firewall settings. If the error still persists, write to us at %s.", 'amazon-associates-link-builder' ), AALB_SUPPORT_EMAIL_ID ),
116
- "add_aalb_shortcode" => esc_html__( "Add Amazon Associates Link Builder Shortcode", 'amazon-associates-link-builder' )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  );
118
  }
119
 
@@ -135,7 +171,7 @@ class Aalb_Admin {
135
  * @since 1.3
136
  */
137
  public function handle_plugin_update() {
138
- if( $this->compatibility_helper->is_plugin_compatible() ) {
139
  //Clear all transients for price changes to reflect
140
  $this->helper->clear_cache_for_substring( '' );
141
  $this->helper->clear_expired_transients();
@@ -143,6 +179,7 @@ class Aalb_Admin {
143
  global $wp_filesystem;
144
  $this->helper->aalb_initialize_wp_filesystem_api();
145
  $this->helper->refresh_template_list();
 
146
  update_option( AALB_PLUGIN_VERSION, AALB_PLUGIN_CURRENT_VERSION );
147
  } else {
148
  $this->compatibility_helper->aalb_deactivate();
@@ -201,7 +238,7 @@ class Aalb_Admin {
201
 
202
  //Only allow users who can edit post to make the request.
203
  if ( current_user_can( 'edit_posts' ) ) {
204
- $url = $this->paapi_helper->get_item_search_url( $_GET['keywords'], $_GET['marketplace'], $_GET['store_id'] );
205
  try {
206
  echo $this->remote_loader->load( $url );
207
  } catch ( Exception $e ) {
29
  private $tracking_api_helper;
30
  private $helper;
31
  private $compatibility_helper;
32
+ private $aalb_migration_helper;
33
+ private $config_loader;
34
 
35
  public function __construct() {
36
  $this->compatibility_helper = new Aalb_Compatibility_Helper();
38
  $this->remote_loader = new Aalb_Remote_Loader();
39
  $this->tracking_api_helper = new Aalb_Tracking_Api_Helper();
40
  $this->helper = new Aalb_Helper();
41
+ $this->aalb_migration_helper = new Aalb_Settings_Page_Migration_Helper();
42
+ $this->config_loader = new Aalb_Config_Loader();
43
  }
44
 
45
  /**
46
+ * Checks if PA-API Credentials are not set
47
  *
48
  * @since 1.4.5
49
  * @return boolean true if PA-API credentials are set
50
  */
51
+ public function is_paapi_credentials_not_set() {
52
+ return ( get_option( AALB_AWS_ACCESS_KEY ) == '' or get_option( AALB_AWS_SECRET_KEY ) == '' );
53
+ }
54
+
55
+ /**
56
+ * Checks if store-ids credentials are not set
57
+ *
58
+ * @since 1.4.12
59
+ *
60
+ * @return boolean true if store-id credentials are set
61
+ */
62
+ public function is_store_id_credentials_not_set() {
63
+ return ( get_option( AALB_STORE_IDS ) == '' );
64
  }
65
 
66
  /**
100
  */
101
  private function get_paapi_pref() {
102
  return array(
103
+ 'max_search_result_items' => AALB_MAX_SEARCH_RESULT_ITEMS,
104
+ 'default_marketplace' => get_option( AALB_DEFAULT_MARKETPLACE ),
105
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
106
+ 'action' => 'get_item_search_result',
107
+ 'item_search_nonce' => wp_create_nonce( 'aalb-item-search-nonce' ),
108
+ 'AALB_SHORTCODE_AMAZON_LINK' => AALB_SHORTCODE_AMAZON_LINK,
109
+ 'AALB_SHORTCODE_AMAZON_TEXT' => AALB_SHORTCODE_AMAZON_TEXT,
110
+ 'IS_PAAPI_CREDENTIALS_NOT_SET' => $this->is_paapi_credentials_not_set(),
111
+ 'IS_STORE_ID_CREDENTIALS_NOT_SET' => $this->is_store_id_credentials_not_set(),
112
+ 'WORDPRESS_REQUEST_TIMEOUT' => AALB_WORDPRESS_REQUEST_TIMEOUT,
113
+ 'templates_list' => json_encode( get_option( AALB_TEMPLATE_NAMES ) ),
114
+ 'default_template' => get_option( AALB_DEFAULT_TEMPLATE, AALB_DEFAULT_TEMPLATE_NAME ),
115
+ 'marketplace_store_id_map' => get_option( AALB_STORE_IDS )
116
  );
117
  }
118
 
125
  */
126
  private function get_aalb_strings() {
127
  return array(
128
+ "template_asin_error" => esc_html__( "Only one product can be selected for this template", 'amazon-associates-link-builder' ),
129
+ "no_asin_selected_error" => esc_html__( "Please select at least one product for display", 'amazon-associates-link-builder' ),
130
+ "empty_product_search_bar" => esc_html__( "Please Enter a Product Name ", 'amazon-associates-link-builder' ),
131
+ "short_code_create_failure" => esc_html__( "Failed to create Text Link shortcode. Editor has some text selected. Only one item can be selected while adding text links", 'amazon-associates-link-builder' ),
132
  /* translators: %s: Email-id of the support */
133
+ "paapi_request_timeout_error" => sprintf( esc_html__( "Request timed out. Try again after some time. Please check your network and firewall settings. If the error still persists, write to us at %s.", 'amazon-associates-link-builder' ), AALB_SUPPORT_EMAIL_ID ),
134
+ "add_aalb_shortcode" => esc_html__( "Add Amazon Associates Link Builder Shortcode", 'amazon-associates-link-builder' ),
135
+ /* translators: %s: URL of settings page */
136
+ "paapi_credentials_not_set" => sprintf( __( "Please configure your PA-API credentials in the <a href=%s>Settings Page</a> to use the Link Builder features.", 'amazon-associates-link-builder' ), AALB_SETTINGS_PAGE_URL ),
137
+ /* translators: %s: URL of settings page */
138
+ "store_id_credentials_not_set" => sprintf( __( "Please configure your Store-Id credentials in the <a href=%s>Settings Page</a> to use the Link Builder features.", 'amazon-associates-link-builder' ), AALB_SETTINGS_PAGE_URL ),
139
+ "ad_template_label" => esc_html__( "Ad Template", 'amazon-associates-link-builder' ),
140
+ "searchbox_placeholder" => esc_html__( "Enter keyword(s)", 'amazon-associates-link-builder' ),
141
+ "search_button_label" => esc_html__( "Search", 'amazon-associates-link-builder' ),
142
+ "associate_id_label" => esc_html__( "Tracking IDs", 'amazon-associates-link-builder' ),
143
+ "marketplace_label" => esc_html__( "Marketplace", 'amazon-associates-link-builder' ),
144
+ "text_shown_during_search" => esc_html__( "Searching relevant products from Amazon", 'amazon-associates-link-builder' ),
145
+ "click_to_select_products_label" => esc_html__( "Click to select product(s) to advertise", 'amazon-associates-link-builder' ),
146
+ "check_more_on_amazon_text" => esc_html__( "Check more search results on Amazon", 'amazon-associates-link-builder' ),
147
+ "selected_products_list_label" => esc_html__( "List of Selected Products", 'amazon-associates-link-builder' ),
148
+ "text_shown_during_shortcode_creation" => esc_html__( "Creating shortcode. Please wait....", 'amazon-associates-link-builder' ),
149
+ "add_shortcode_button_label" => esc_html__( "Add Shortcode", 'amazon-associates-link-builder' ),
150
+ "templates_help_content" => esc_html__( "To configure templates, go to Associates Link Builder plugin's Templates page", 'amazon-associates-link-builder' ),
151
+ "marketplace_help_content" => esc_html__( "To configure marketplaces, go to Associates Link Builder plugin's Settings page", 'amazon-associates-link-builder' ),
152
+ "tracking_id_help_content" => esc_html__( "To configure tracking ids, go to Associates Link Builder plugin's Settings page", 'amazon-associates-link-builder' )
153
  );
154
  }
155
 
171
  * @since 1.3
172
  */
173
  public function handle_plugin_update() {
174
+ if ( $this->compatibility_helper->is_plugin_compatible() ) {
175
  //Clear all transients for price changes to reflect
176
  $this->helper->clear_cache_for_substring( '' );
177
  $this->helper->clear_expired_transients();
179
  global $wp_filesystem;
180
  $this->helper->aalb_initialize_wp_filesystem_api();
181
  $this->helper->refresh_template_list();
182
+ $this->aalb_migration_helper->run_migration_logic();
183
  update_option( AALB_PLUGIN_VERSION, AALB_PLUGIN_CURRENT_VERSION );
184
  } else {
185
  $this->compatibility_helper->aalb_deactivate();
238
 
239
  //Only allow users who can edit post to make the request.
240
  if ( current_user_can( 'edit_posts' ) ) {
241
+ $url = $this->paapi_helper->get_item_search_url( $_GET['keywords'], array_search( $_GET['marketplace'], $this->config_loader->fetch_marketplaces() ), $_GET['store_id'] );
242
  try {
243
  echo $this->remote_loader->load( $url );
244
  } catch ( Exception $e ) {
admin/css/aalb_admin.css CHANGED
@@ -464,7 +464,7 @@ input.aalb-admin-input-search:disabled {
464
  font-size: 12px;
465
  }
466
 
467
- .aalb-admin-searchbox-tooltip-disabled {
468
  display: none;
469
  }
470
 
@@ -473,3 +473,7 @@ input.aalb-admin-input-search:disabled {
473
  color: #0073aa !important;
474
  font-weight: bold;
475
  }
 
 
 
 
464
  font-size: 12px;
465
  }
466
 
467
+ .aalb-admin-hide-display {
468
  display: none;
469
  }
470
 
473
  color: #0073aa !important;
474
  font-weight: bold;
475
  }
476
+
477
+ .aalb-info-icon::before {
478
+ margin-left: 5px;
479
+ }
admin/css/aalb_credentials.css CHANGED
@@ -19,11 +19,11 @@ td.aalb-settings-input-column {
19
  }
20
 
21
  .aalb-settings-input-field {
22
- width:90%;
23
  }
24
 
25
- .aalb-settings-no-referrer-text{
26
- font-size:110%;
27
  }
28
 
29
  .aalb-settings-fieldset {
@@ -31,8 +31,8 @@ td.aalb-settings-input-column {
31
  background: #ffffff;
32
  }
33
 
34
- .aalb-settings-table {
35
- border:none !important;
36
  }
37
 
38
  .aalb-settings-legend {
@@ -41,11 +41,33 @@ td.aalb-settings-input-column {
41
 
42
  td.aalb-settings-terms-column {
43
  vertical-align: middle;
44
- width:85%;
45
  }
46
 
47
  div.aalb-terms-conditions {
48
  margin-top: 20px;
49
  margin-bottom: -10px;
50
  font-size: 110%;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
19
  }
20
 
21
  .aalb-settings-input-field {
22
+ width: 90%;
23
  }
24
 
25
+ .aalb-settings-no-referrer-text {
26
+ font-size: 110%;
27
  }
28
 
29
  .aalb-settings-fieldset {
31
  background: #ffffff;
32
  }
33
 
34
+ #aalb-credentials-form .aalb-settings-table {
35
+ border: none;
36
  }
37
 
38
  .aalb-settings-legend {
41
 
42
  td.aalb-settings-terms-column {
43
  vertical-align: middle;
44
+ width: 85%;
45
  }
46
 
47
  div.aalb-terms-conditions {
48
  margin-top: 20px;
49
  margin-bottom: -10px;
50
  font-size: 110%;
51
+ }
52
+
53
+ #aalb-add-new-marketplace {
54
+ font-size: 110%;
55
+ font-weight: bold;
56
+ text-decoration: underline;
57
+ }
58
+
59
+ a.aalb-remove-marketplace {
60
+ text-decoration: underline;
61
+ }
62
+
63
+ .aalb-default-marketplace a {
64
+ text-decoration: underline;
65
+ }
66
+
67
+ .aalb-store-ids-column {
68
+ width: 50%;
69
+ }
70
+
71
+ #aalb-remove-marketplace-confirmation-container {
72
+ display: none;
73
  }
admin/js/aalb_admin.js CHANGED
@@ -10,13 +10,22 @@
10
  and limitations under the License.
11
  */
12
 
 
 
 
 
 
 
 
 
13
  var template;
14
  var TB_WIDTH, TB_HEIGHT;
15
  var tb_remove;
16
  var link_id = "";
17
  var AALB_SHORTCODE_AMAZON_LINK = api_pref.AALB_SHORTCODE_AMAZON_LINK; //constant value from server side is reused here
18
  var AALB_SHORTCODE_AMAZON_TEXT = api_pref.AALB_SHORTCODE_AMAZON_TEXT;
19
- var IS_PAAPI_CREDENTIALS_SET = api_pref.IS_PAAPI_CREDENTIALS_SET;
 
20
  //object used as map to check duplicate asin selected by admin
21
  var asin_map = {};
22
  var SINGLE_ASIN_TEMPLATE = {
@@ -25,12 +34,39 @@ var SINGLE_ASIN_TEMPLATE = {
25
  ProductLink: 'true'
26
  };
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  jQuery( document ).ready( function() {
 
29
  // http://stackoverflow.com/questions/5557641/how-can-i-reset-div-to-its-original-state-after-it-has-been-modified-by-java
30
  jQuery( "#aalb-admin-popup-content" ).data( 'old-state', jQuery( "#aalb-admin-popup-content" ).html() );
31
 
32
  //Load the search result template
33
- var aalb_hbs_admin_items_search_source = jQuery( "#aalb-hbs-admin-items-search" ).html();
34
  if( aalb_hbs_admin_items_search_source != null ) {
35
  template = Handlebars.compile( aalb_hbs_admin_items_search_source );
36
  }
@@ -73,11 +109,40 @@ jQuery( document ).ready( function() {
73
  }
74
  } );
75
 
76
- if(!IS_PAAPI_CREDENTIALS_SET){
77
- aalb_disable_editor_search();
 
 
 
 
 
 
 
 
 
 
 
 
78
  }
79
  } );
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  /**
82
  * Resizing thickbox on change in window dimensions
83
  * Setting a max width and height of 1280x800 px for readability and to lessen distortion
@@ -185,8 +250,6 @@ function aalb_admin_popup_search_items() {
185
  * @param String keywords Items to search for.
186
  */
187
  function aalb_admin_get_item_search_items( keywords ) {
188
- marketplace = aalb_get_selected_marketplace();
189
- marketplace = marketplace ? marketplace : api_pref.marketplace;
190
  jQuery.ajax({
191
  url: api_pref.ajax_url,
192
  type: 'GET',
@@ -194,8 +257,8 @@ function aalb_admin_get_item_search_items( keywords ) {
194
  "action": api_pref.action,
195
  "item_search_nonce": api_pref.item_search_nonce,
196
  "keywords": keywords,
197
- "marketplace": marketplace,
198
- "store_id": api_pref.store_id
199
  },
200
  success: function( xml ) {
201
  var items_xml = jQuery( xml ).find( "Item" );
@@ -230,7 +293,8 @@ function aalb_admin_get_item_search_items( keywords ) {
230
  var productImage = jQuery( this ).find( "img" ).attr( "src" );
231
  var productTitle = jQuery( this ).find( "div.aalb-admin-item-search-items-item-title" ).text();
232
  var productPrice = jQuery( this ).find( "div.aalb-admin-item-search-items-item-price" ).text();
233
-
 
234
  var selectedAsinHTML = '<div class="aalb-selected-item" onclick="aalb_remove_asin(this)"';
235
  selectedAsinHTML += ' data-asin="' + data_asin + '">';
236
  selectedAsinHTML += '<div class="aalb-selected-item-img-wrap"><span class="aalb-selected-item-close">&times;</span>';
@@ -295,7 +359,7 @@ function aalb_add_shortcode( shortcodeName ) {
295
  var selectedAsins = aalb_get_selected_asins();
296
  var selectedTemplate = aalb_get_selected_template();
297
  var selectedStore = aalb_get_selected_store();
298
- var selectedMarketplace = aalb_get_selected_marketplace_abbreviation();
299
 
300
  if ( shortcodeName == AALB_SHORTCODE_AMAZON_LINK ) {
301
  shortcodeJson = {
@@ -425,26 +489,7 @@ function aalb_get_selected_store() {
425
  * @return String Selected Marketplace to search the product
426
  */
427
  function aalb_get_selected_marketplace() {
428
- var selectedMarketplace = "";
429
- var $selectedMarketplace = jQuery( "#aalb_marketplace_names_list option:selected" );
430
- if ( $selectedMarketplace.length > 0 ) {
431
- selectedMarketplace = $selectedMarketplace.val();
432
- }
433
- return selectedMarketplace;
434
- }
435
-
436
- /**
437
- * Get the selected marketplace abbreviation
438
- *
439
- * @return String Selected Marketplace abbreviation for the shortcode
440
- */
441
- function aalb_get_selected_marketplace_abbreviation() {
442
- var selectedMarketplace = "";
443
- var $selectedMarketplace = jQuery( "#aalb_marketplace_names_list option:selected" );
444
- if ( $selectedMarketplace.length > 0 ) {
445
- selectedMarketplace = $selectedMarketplace.text();
446
- }
447
- return selectedMarketplace;
448
  }
449
 
450
  /**
@@ -519,12 +564,18 @@ function aalb_reset_add_short_button_and_error_warnings() {
519
  }
520
 
521
  /**
522
- * To disable editor search for AALB plugin
 
 
 
 
 
523
  **/
524
- function aalb_disable_editor_search() {
525
- jQuery(".aalb-admin-button-create-amazon-shortcode").addClass('aalb-admin-button-create-amazon-shortcode-disabled');
526
  jQuery( ".aalb-admin-input-search" ).prop( 'disabled', true );
527
- var aalb_admin_searchbox_tooltip = jQuery('.aalb-admin-searchbox-tooltip-disabled');
528
- aalb_admin_searchbox_tooltip.addClass('aalb-admin-searchbox-tooltip-text');
529
- aalb_admin_searchbox_tooltip.removeClass('aalb-admin-searchbox-tooltip-disabled');
 
530
  }
10
  and limitations under the License.
11
  */
12
 
13
+
14
+ /*
15
+ List of tasks to be done in this file for improving code quality and to ease development and reduce chances of bugs.
16
+ ToDo: Put everything under closure to avoid name conflicts(remove aalb prefix from methods & variables after this) and making internal functionality private
17
+ ToDO: The variables under documet.ready by default(without closures) can create conflicts with same named varaibles from other files like "old_tb_remove"
18
+ ToDO: Add mustache templating in the meta_box and remove html code from this js to separate business logic & html
19
+ */
20
+
21
  var template;
22
  var TB_WIDTH, TB_HEIGHT;
23
  var tb_remove;
24
  var link_id = "";
25
  var AALB_SHORTCODE_AMAZON_LINK = api_pref.AALB_SHORTCODE_AMAZON_LINK; //constant value from server side is reused here
26
  var AALB_SHORTCODE_AMAZON_TEXT = api_pref.AALB_SHORTCODE_AMAZON_TEXT;
27
+ var IS_PAAPI_CREDENTIALS_NOT_SET = api_pref.IS_PAAPI_CREDENTIALS_NOT_SET;
28
+ var IS_STORE_ID_CREDENTIALS_NOT_SET = api_pref.IS_STORE_ID_CREDENTIALS_NOT_SET;
29
  //object used as map to check duplicate asin selected by admin
30
  var asin_map = {};
31
  var SINGLE_ASIN_TEMPLATE = {
34
  ProductLink: 'true'
35
  };
36
 
37
+ var aalb_marketplace_store_id_mapping = jQuery.parseJSON( api_pref.marketplace_store_id_map );
38
+ var aalb_default_marketplace = api_pref.default_marketplace;
39
+ var aalb_default_store_id_list = aalb_marketplace_store_id_mapping ? aalb_marketplace_store_id_mapping[ aalb_default_marketplace ] : [];
40
+ var aalb_search_pop_up_context = {
41
+ "ad_template_label" : aalb_strings.ad_template_label,
42
+ "searchbox_placeholder" : aalb_strings.searchbox_placeholder,
43
+ "search_button_label" : aalb_strings.search_button_label,
44
+ "associate_id_label" : aalb_strings.associate_id_label,
45
+ "marketplace_label" : aalb_strings.marketplace_label,
46
+ "text_shown_during_search" : aalb_strings.text_shown_during_search,
47
+ "click_to_select_products_label" : aalb_strings.click_to_select_products_label,
48
+ "check_more_on_amazon_text" : aalb_strings.check_more_on_amazon_text,
49
+ "selected_products_list_label" : aalb_strings.selected_products_list_label,
50
+ "text_shown_during_shortcode_creation": aalb_strings.text_shown_during_shortcode_creation,
51
+ "add_shortcode_button_label" : aalb_strings.add_shortcode_button_label,
52
+ "templates_help_content" : aalb_strings.templates_help_content,
53
+ "marketplace_help_content" : aalb_strings.marketplace_help_content,
54
+ "tracking_id_help_content" : aalb_strings.tracking_id_help_content,
55
+ "templates_list" : jQuery.parseJSON( api_pref.templates_list ),
56
+ "default_template" : api_pref.default_template,
57
+ "marketplace_list" : aalb_marketplace_store_id_mapping ? Object.keys( aalb_marketplace_store_id_mapping ) : "",
58
+ "default_marketplace" : aalb_default_marketplace,
59
+ "default_store_id_list" : aalb_default_store_id_list,
60
+ "default_store_id" : aalb_default_store_id_list ? aalb_default_store_id_list[ 0 ] : ""
61
+ };
62
+
63
  jQuery( document ).ready( function() {
64
+ aalb_load_search_pop_up();
65
  // http://stackoverflow.com/questions/5557641/how-can-i-reset-div-to-its-original-state-after-it-has-been-modified-by-java
66
  jQuery( "#aalb-admin-popup-content" ).data( 'old-state', jQuery( "#aalb-admin-popup-content" ).html() );
67
 
68
  //Load the search result template
69
+ var aalb_hbs_admin_items_search_source = jQuery( "#aalb-hbs-admin-items-search" ).html();
70
  if( aalb_hbs_admin_items_search_source != null ) {
71
  template = Handlebars.compile( aalb_hbs_admin_items_search_source );
72
  }
109
  }
110
  } );
111
 
112
+ /**
113
+ * To fill the store-ids as per markeplace in Associate Id section on changing marketplace
114
+ **/
115
+ jQuery( '#aalb_marketplace_names_list' ).on( 'change', function() {
116
+ jQuery( '#aalb-admin-popup-store-id' ).empty();
117
+ jQuery.each( aalb_marketplace_store_id_mapping[ jQuery( this ).val() ], function( key, store_id ) {
118
+ jQuery( '#aalb-admin-popup-store-id' ).append( '<option>' + store_id + '</option>' );
119
+ } );
120
+ } );
121
+
122
+ if( IS_PAAPI_CREDENTIALS_NOT_SET ) {
123
+ aalb_disable_editor_search( aalb_strings.paapi_credentials_not_set );
124
+ } else if( IS_STORE_ID_CREDENTIALS_NOT_SET ) {
125
+ aalb_disable_editor_search( aalb_strings.store_id_credentials_not_set );
126
  }
127
  } );
128
 
129
+ /**
130
+ * Load search pop-up box
131
+ *
132
+ * @since 1.4.12
133
+ */
134
+ function aalb_load_search_pop_up() {
135
+ Handlebars.registerHelper( 'selected', function( current_option, selected_option ) {
136
+ return (current_option === selected_option) ? 'selected' : '';
137
+ } );
138
+ var aalb_search_pop_up_hbs = jQuery( "#aalb-search-pop-up-hbs" ).html();
139
+ if( aalb_search_pop_up_hbs != null ) {
140
+ var aalb_search_pop_up_template = Handlebars.compile( aalb_search_pop_up_hbs );
141
+ var aalb_search_pop_up_html = aalb_search_pop_up_template( aalb_search_pop_up_context );
142
+ jQuery( "#aalb-admin-popup-container" ).prepend( aalb_search_pop_up_html );
143
+ }
144
+ }
145
+
146
  /**
147
  * Resizing thickbox on change in window dimensions
148
  * Setting a max width and height of 1280x800 px for readability and to lessen distortion
250
  * @param String keywords Items to search for.
251
  */
252
  function aalb_admin_get_item_search_items( keywords ) {
 
 
253
  jQuery.ajax({
254
  url: api_pref.ajax_url,
255
  type: 'GET',
257
  "action": api_pref.action,
258
  "item_search_nonce": api_pref.item_search_nonce,
259
  "keywords": keywords,
260
+ "marketplace": aalb_get_selected_marketplace(),
261
+ "store_id": aalb_get_selected_store()
262
  },
263
  success: function( xml ) {
264
  var items_xml = jQuery( xml ).find( "Item" );
293
  var productImage = jQuery( this ).find( "img" ).attr( "src" );
294
  var productTitle = jQuery( this ).find( "div.aalb-admin-item-search-items-item-title" ).text();
295
  var productPrice = jQuery( this ).find( "div.aalb-admin-item-search-items-item-price" ).text();
296
+ //ToDO: 1. See if handlebars can be leveraged here like in credentials.js
297
+ //ToDO: 2. Remove inline event handler 'onClick'
298
  var selectedAsinHTML = '<div class="aalb-selected-item" onclick="aalb_remove_asin(this)"';
299
  selectedAsinHTML += ' data-asin="' + data_asin + '">';
300
  selectedAsinHTML += '<div class="aalb-selected-item-img-wrap"><span class="aalb-selected-item-close">&times;</span>';
359
  var selectedAsins = aalb_get_selected_asins();
360
  var selectedTemplate = aalb_get_selected_template();
361
  var selectedStore = aalb_get_selected_store();
362
+ var selectedMarketplace = aalb_get_selected_marketplace();
363
 
364
  if ( shortcodeName == AALB_SHORTCODE_AMAZON_LINK ) {
365
  shortcodeJson = {
489
  * @return String Selected Marketplace to search the product
490
  */
491
  function aalb_get_selected_marketplace() {
492
+ return jQuery( "#aalb_marketplace_names_list" ).val();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
493
  }
494
 
495
  /**
564
  }
565
 
566
  /**
567
+ * To disable editor search for AALB plugin along with message
568
+ *
569
+ * @param String error_msg Error message
570
+ *
571
+ * @since 1.4.12
572
+ *
573
  **/
574
+ function aalb_disable_editor_search( error_msg ) {
575
+ jQuery( ".aalb-admin-button-create-amazon-shortcode" ).addClass( 'aalb-admin-button-create-amazon-shortcode-disabled' );
576
  jQuery( ".aalb-admin-input-search" ).prop( 'disabled', true );
577
+ var aalb_admin_searchbox_tooltip = jQuery( '.aalb-admin-editor-tooltip' );
578
+ aalb_admin_searchbox_tooltip.html( error_msg );
579
+ aalb_admin_searchbox_tooltip.addClass( 'aalb-admin-searchbox-tooltip-text' );
580
+ aalb_admin_searchbox_tooltip.removeClass( 'aalb-admin-hide-display' );
581
  }
admin/partials/aalb_editor_search_box.php CHANGED
@@ -25,10 +25,7 @@ $aalb_admin->aalb_enqueue_scripts();
25
  -->
26
 
27
  <div class="aalb-admin-inline aalb-admin-searchbox">
28
- <span class="aalb-admin-searchbox-tooltip-disabled"><?php
29
- /* translators: %s: URL of settings page */
30
- printf( __( "Please configure your PA-API credentials in the <a href=%s>Settings Page</a> to use the Link Builder features.", 'amazon-associates-link-builder' ), $aalb_settings_page_url ); ?>
31
- </span>
32
  <img src=<?= AALB_ADMIN_ICON ?> class="aalb-admin-searchbox-amzlogo">
33
  <input type="text" class="aalb-admin-input-search"
34
  name="aalb-admin-input-search"
25
  -->
26
 
27
  <div class="aalb-admin-inline aalb-admin-searchbox">
28
+ <span class="aalb-admin-editor-tooltip aalb-admin-hide-display"></span>
 
 
 
29
  <img src=<?= AALB_ADMIN_ICON ?> class="aalb-admin-searchbox-amzlogo">
30
  <input type="text" class="aalb-admin-input-search"
31
  name="aalb-admin-input-search"
admin/partials/aalb_meta_box.php CHANGED
@@ -21,81 +21,116 @@ and limitations under the License.
21
  // HandleBar template
22
  include AALB_ADMIN_ITEM_SEARCH_ITEMS_PATH;
23
 
24
- $aalb_template_names = get_option( AALB_TEMPLATE_NAMES );
25
- $config_loader = new Aalb_Config_Loader();
26
- $aalb_marketplace_names = $config_loader->fetch_marketplaces();
27
- $helper = new Aalb_Helper();
28
- $aalb_store_id_names = $helper->get_store_ids_array();
29
  $aalb_admin = new Aalb_Admin();
30
  $aalb_admin->aalb_enqueue_styles();
31
  $aalb_admin->aalb_enqueue_scripts();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  ?>
33
- <!-- keeping css inline as css file does not load at plugin initialization -->
34
- <div id="aalb-admin-popup-container" style="display:none;">
35
- <div class="aalb-admin-searchbox aalb-admin-popup-options">
36
- <input type="text" id="aalb-admin-popup-input-search" name="aalb-admin-popup-input-search"
37
- placeholder="<?php esc_attr_e( "Enter keyword(s)", 'amazon-associates-link-builder' ) ?>" onkeypress='aalb_submit_event(event,"aalb-btn-primary",this)'/>
38
- <button class="aalb-btn aalb-btn-primary" id="aalb-admin-popup-search-button" type="button"
39
- onclick="aalb_admin_popup_search_items()" style="margin-top:1%"><?php esc_html_e( "Search", 'amazon-associates-link-builder' ) ?>
40
- </button>
41
- </div><!--end .aalb-admin-popup-options-->
42
- <!-- start: aalb-admin-popup-shortcode-options-->
43
- <div class="aalb-admin-popup-shortocde-wrapper">
44
- <div class="aalb-admin-popup-shortcode-options">
45
- <div class="aalb-admin-item-search-templates">
46
- <label><?php esc_html_e( "Ad Template", 'amazon-associates-link-builder' ) ?></label>
47
- <?php $aalb_default_template = get_option( AALB_DEFAULT_TEMPLATE, AALB_DEFAULT_TEMPLATE_NAME ); ?>
48
- <select id="aalb_template_names_list" name="aalb_template_names_list" >
49
- <?php foreach ( $aalb_template_names as $aalb_template_name ) { ?>
50
- <option value="<?= $aalb_template_name ?>" <?php selected( $aalb_default_template, $aalb_template_name ); ?>><?= $aalb_template_name ?></option>
51
- <?php } ?>
52
- </select>
53
- </div>
54
- <div class="aalb-admin-popup-store">
55
- <label><?php esc_html_e( "Associate ID", 'amazon-associates-link-builder' ) ?></label>
56
- <?php $aalb_default_store_id = get_option( AALB_DEFAULT_STORE_ID, AALB_DEFAULT_STORE_ID_NAME ); ?>
57
- <select id="aalb-admin-popup-store-id" name="aalb-admin-popup-store-id" >
58
- <?php foreach ( $aalb_store_id_names as $aalb_store_id ) { ?>
59
- <option value="<?= $aalb_store_id ?>" <?php selected( $aalb_default_store_id, $aalb_store_id ); ?>> <?= $aalb_store_id ?> </option>
60
- <?php } ?>
61
- </select>
62
- </div>
63
- <div class="aalb-admin-item-search-marketplaces">
64
- <label><?php esc_html_e( "Marketplace", 'amazon-associates-link-builder' ) ?></label>
65
- <?php $aalb_default_marketplace = get_option( AALB_DEFAULT_MARKETPLACE, AALB_DEFAULT_MARKETPLACE_NAME ); ?>
66
- <select id="aalb_marketplace_names_list" name="aalb_marketplace_names_list" >
67
- <?php foreach ( $aalb_marketplace_names as $aalb_marketplace => $aalb_marketplace_abbr ) { ?>
68
- <option value="<?= $aalb_marketplace ?>" <?php selected( $aalb_default_marketplace, $aalb_marketplace_abbr ); ?>><?= $aalb_marketplace_abbr ?></option>
69
- <?php } ?>
70
- </select>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  </div>
72
- </div>
73
- </div><!--end .aalb-admin-popup-shortcode-options-->
74
- <div id="aalb-admin-popup-content">
75
- <div class="aalb-admin-alert aalb-admin-alert-info aalb-admin-item-search-loading">
76
- <div class="aalb-admin-icon"><i class="fa fa-spinner fa-pulse"></i></div>
77
- <?php esc_html_e( "Searching relevant products from Amazon", 'amazon-associates-link-builder' ) ?>
78
- </div><!--end .aalb-admin-item-search-loading-->
79
- <div class="aalb-admin-item-search">
80
- <?php esc_html_e( "Click to select product(s) to advertise", 'amazon-associates-link-builder' ) ?>
81
- <div class="aalb-admin-item-search-items"></div>
82
- <a href="#" target="_blank" id="aalb-admin-popup-more-results" class="pull-right"><?php esc_html_e( "Check more search results on Amazon", 'amazon-associates-link-builder' ) ?></a>
83
- </div><!--end .aalb-admin-item-serch-->
84
- </div><!--end .aalb-admin-popup-content-->
85
- <div class="aalb-selected">
86
- <label><?php esc_html_e( "List of Selected Products", 'amazon-associates-link-builder' ) ?></label>
87
- </div>
88
 
89
- <div class="aalb-add-shortcode-button">
90
- <button class="aalb-btn aalb-btn-primary" id="aalb-add-shortcode-button" type="button"><?php esc_html_e( "Add Shortcode", 'amazon-associates-link-builder' ) ?></button>
91
- <div id="aalb-add-shortcode-alert">
92
- <div class="aalb-admin-icon"><i class="fa fa-spinner fa-pulse"></i></div>
93
- <?php esc_html_e( "Creating shortcode. Please wait....", 'amazon-associates-link-builder' ) ?>
94
- </div>
95
- <div id="aalb-add-asin-error">
96
- <div id="aalb-add-template-asin-error"></div>
97
- </div>
98
- </div><!--end .aalb-add-shortcode-button-->
99
- </div><!--end .aalb-admin-popup-container-->
 
100
  <?php
101
  ?>
21
  // HandleBar template
22
  include AALB_ADMIN_ITEM_SEARCH_ITEMS_PATH;
23
 
 
 
 
 
 
24
  $aalb_admin = new Aalb_Admin();
25
  $aalb_admin->aalb_enqueue_styles();
26
  $aalb_admin->aalb_enqueue_scripts();
27
+
28
+ /*
29
+ * Below is an example of context to be passed to the below template
30
+ *
31
+ {
32
+ "ad_template_label":"Ad Template",
33
+ "searchbox_placeholder":"Enter keyword(s)",
34
+ "search_button_label":"Search",
35
+ "associate_id_label":"Associate ID",
36
+ "marketplace_label":"Marketplace",
37
+ "text_shown_during_search":"Searching relevant products from Amazon",
38
+ "click_to_select_products_label":"Click to select product(s) to advertise",
39
+ "check_more_on_amazon_text":"Check more search results on Amazon",
40
+ "selected_products_list_label":"List of Selected Products",
41
+ "text_shown_during_shortcode_creation":"Creating shortcode. Please wait....",
42
+ "add_shortcode_button_label":"Add Shortcode",
43
+ "templates_list":[
44
+ "PriceLink",
45
+ "ProductAd",
46
+ "ProductCarousel",
47
+ "ProductGrid",
48
+ "ProductLink"
49
+ ],
50
+ "default_template":"ProductAd",
51
+ "marketplace_list":[
52
+ "IN",
53
+ "UK"
54
+ ],
55
+ "default_marketplace":"IN",
56
+ "default_store_id_list":[
57
+ "store-1",
58
+ "store-2"
59
+ ],
60
+ "default_store_id":"store-1"
61
+ }
62
+ */
63
+
64
  ?>
65
+ <!--ToDO: Remove inline & event binding & styling(except the one for aalb-admin-popup-container)-->
66
+ <!-- keeping css inline as css file does not load at plugin initialization -->
67
+ <div id="aalb-admin-popup-container" style="display:none;">
68
+ <script id="aalb-search-pop-up-hbs" type="text/x-handlebars-template">
69
+ <div class="aalb-admin-searchbox aalb-admin-popup-options">
70
+ <input type="text" id="aalb-admin-popup-input-search" name="aalb-admin-popup-input-search"
71
+ placeholder="{{searchbox_placeholder}}" onkeypress='aalb_submit_event(event,"aalb-btn-primary",this)' />
72
+ <button class="aalb-btn aalb-btn-primary" id="aalb-admin-popup-search-button" type="button"
73
+ onclick="aalb_admin_popup_search_items()" style="margin-top:1%">{{search_button_label}}
74
+ </button>
75
+ </div><!--end .aalb-admin-popup-options-->
76
+ <!-- start: aalb-admin-popup-shortcode-options-->
77
+ <div class="aalb-admin-popup-shortocde-wrapper">
78
+ <div class="aalb-admin-popup-shortcode-options">
79
+ <div class="aalb-admin-item-search-templates">
80
+ <label title="{{templates_help_content}}">{{ad_template_label}}<i class="fa fa-info-circle aalb-info-icon" aria-hidden="true"></i></label>
81
+ <select id="aalb_template_names_list" name="aalb_template_names_list">
82
+ {{#each templates_list}}
83
+ <option value="{{this}}" {{selected this ..
84
+ /default_template}} {{this}}>{{this}}</option>
85
+ {{/each}}
86
+ </select>
87
+ </div>
88
+ <div class="aalb-admin-item-search-marketplaces">
89
+ <label title="{{marketplace_help_content}}">{{marketplace_label}}<i class="fa fa-info-circle aalb-info-icon" aria-hidden="true"></i></label>
90
+ <select id="aalb_marketplace_names_list" name="aalb_marketplace_names_list">
91
+ {{#each marketplace_list}}
92
+ <option value="{{this}}" {{selected this ..
93
+ /default_marketplace}}>{{this}}</option>
94
+ {{/each}}
95
+ </select>
96
+ </div>
97
+ <div class="aalb-admin-popup-store">
98
+ <label title="{{tracking_id_help_content}}">{{associate_id_label}}<i class="fa fa-info-circle aalb-info-icon" aria-hidden="true"></i></label>
99
+ <select id="aalb-admin-popup-store-id" name="aalb-admin-popup-store-id">
100
+ {{#each default_store_id_list}}
101
+ <option value="{{this}}" {{selected this ..
102
+ /default_store_id}}>{{this}}</option>
103
+ {{/each}}
104
+ </select>
105
+ </div>
106
+ </div>
107
+ </div><!--end .aalb-admin-popup-shortcode-options-->
108
+ <div id="aalb-admin-popup-content">
109
+ <div class="aalb-admin-alert aalb-admin-alert-info aalb-admin-item-search-loading">
110
+ <div class="aalb-admin-icon"><i class="fa fa-spinner fa-pulse"></i></div>
111
+ {{text_shown_during_search}}
112
+ </div><!--end .aalb-admin-item-search-loading-->
113
+ <div class="aalb-admin-item-search">
114
+ {{click_to_select_products_label}}
115
+ <div class="aalb-admin-item-search-items"></div>
116
+ <a href="#" target="_blank" id="aalb-admin-popup-more-results" class="pull-right">{{check_more_on_amazon_text}}</a>
117
+ </div><!--end .aalb-admin-item-serch-->
118
+ </div><!--end .aalb-admin-popup-content-->
119
+ <div class="aalb-selected">
120
+ <label>{{selected_products_list_label}}</label>
121
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
+ <div class="aalb-add-shortcode-button">
124
+ <button class="aalb-btn aalb-btn-primary" id="aalb-add-shortcode-button" type="button">{{add_shortcode_button_label}}</button>
125
+ <div id="aalb-add-shortcode-alert">
126
+ <div class="aalb-admin-icon"><i class="fa fa-spinner fa-pulse"></i></div>
127
+ {{text_shown_during_shortcode_creation}}
128
+ </div>
129
+ <div id="aalb-add-asin-error">
130
+ <div id="aalb-add-template-asin-error"></div>
131
+ </div>
132
+ </div><!--end .aalb-add-shortcode-button-->
133
+ </script>
134
+ </div><!--end .aalb-admin-popup-container-->
135
  <?php
136
  ?>
admin/sidebar/aalb_sidebar.php CHANGED
@@ -52,6 +52,7 @@ class Aalb_Sidebar {
52
  register_setting( AALB_CRED_CONFIG_GROUP, AALB_DEFAULT_MARKETPLACE );
53
  register_setting( AALB_CRED_CONFIG_GROUP, AALB_DEFAULT_TEMPLATE );
54
  register_setting( AALB_CRED_CONFIG_GROUP, AALB_STORE_ID_NAMES );
 
55
  register_setting( AALB_CRED_CONFIG_GROUP, AALB_NO_REFERRER_DISABLED );
56
  }
57
 
52
  register_setting( AALB_CRED_CONFIG_GROUP, AALB_DEFAULT_MARKETPLACE );
53
  register_setting( AALB_CRED_CONFIG_GROUP, AALB_DEFAULT_TEMPLATE );
54
  register_setting( AALB_CRED_CONFIG_GROUP, AALB_STORE_ID_NAMES );
55
+ register_setting( AALB_CRED_CONFIG_GROUP, AALB_STORE_IDS );
56
  register_setting( AALB_CRED_CONFIG_GROUP, AALB_NO_REFERRER_DISABLED );
57
  }
58
 
admin/sidebar/js/aalb_credentials.js CHANGED
@@ -9,46 +9,408 @@
9
  either express or implied. See the License for the specific language governing permissions
10
  and limitations under the License.
11
  */
 
 
 
 
 
12
 
13
- /**
14
- * Update the Default Store ID dropdown onchange
15
- *
16
- * @param HTML DOM OBJECT element list of store IDs in "Store IDs" field
17
- */
18
- function aalb_credentials_store_ids_onchange( element ) {
19
- var aalb_store_ids = element.value;
20
- var aalb_store_ids_array = aalb_store_ids.trim().split( /[\n]+/ );
21
- //Selected Store ID
22
- var aalb_store_ids_selected = jQuery( '#aalb_default_store_id' ).val();
23
- var aalb_store_id_dropdown_html = "";
24
- for ( var i = 0; i < aalb_store_ids_array.length; i++ ) {
25
- if ( aalb_store_ids_array[ i ].length > 0 ) {
26
- aalb_store_ids_array[ i ] = aalb_store_ids_array[ i ].trim();
27
- aalb_store_id_dropdown_html += "<option value='" + aalb_store_ids_array[ i ] + "'>" + aalb_store_ids_array[ i ] + "</option>\n";
28
- } else {
29
- //Remove empty lines
30
- aalb_store_ids_array.splice( i, 1 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
 
 
 
 
 
32
  }
33
- jQuery( '#aalb_store_id_names' ).val( aalb_store_ids_array.join( "\r\n" ) );
34
- //Set the HTML of select dropdown with updated store ids
35
- jQuery( '#aalb_default_store_id' ).html( aalb_store_id_dropdown_html );
36
- //Select the previously selected option value if it exists in the new list
37
- if ( aalb_store_ids_selected.length > 0 && jQuery.inArray( aalb_store_ids_selected, aalb_store_ids_array ) > 0 ) {
38
- jQuery( '#aalb_default_store_id' ).val( aalb_store_ids_selected );
39
- } else {
40
- //If no value is selected, automatically selects first element.
41
- jQuery( "#aalb_default_store_id" ).val( jQuery( "#aalb_default_store_id option:first" ).val() );
42
- }
43
- }
44
- /**
45
- * OnClick Handler for aalb terms and conditions checkbox.
46
- *
47
- */
48
- jQuery( '#aalb-terms-checkbox' ).click( function() {
49
- if ( jQuery( this ).is( ':checked' ) ) {
50
- jQuery( "#submit" ).removeAttr( 'disabled' );
51
- } else {
52
- jQuery( '#submit' ).attr( 'disabled', 'disabled' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  }
54
- } );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  either express or implied. See the License for the specific language governing permissions
10
  and limitations under the License.
11
  */
12
+ //ToDo: Use something webpack(https://webpack.js.org/) to leverage use of ES6
13
+ var aalb_credentials_object = (function( $ ) {
14
+ var SELECT_MARKETPLACE_DROPDOWN_VALUE = "no-selection";
15
+ //ToDO: Pass this separator from backend to maintain consistency
16
+ var STORE_ID_SEPARATOR = ',';
17
 
18
+ //Contains the TableRowHTMLElement of the marketplace to be removed
19
+ var marketplace_row_to_remove = "";
20
+ var default_marketplace = aalb_cred_data.default_marketplace_value;
21
+ var marketplace_list = $.parseJSON( aalb_cred_data.marketplace_list );
22
+ var marketplace_row_context = {
23
+ "marketplace_list" : marketplace_list,
24
+ "set_as_default_marketplace_label": aalb_cred_strings.set_as_default_marketplace_label,
25
+ "remove_marketplace_label" : aalb_cred_strings.remove_marketplace_label,
26
+ "default_marketplace_label" : aalb_cred_strings.default_marketplace_label,
27
+ "select_marketplace_label" : aalb_cred_strings.select_marketplace_label,
28
+ "tracking_id_placeholder" : aalb_cred_strings.tracking_id_placeholder,
29
+ "default_marketplace_value" : aalb_cred_data.default_marketplace_value,
30
+ "marketplace" : "",
31
+ "tracking_ids" : ""
32
+ };
33
+
34
+ var store_ids_settings_context = {
35
+ "marketplace_row_context" : marketplace_row_context,
36
+ "store_ids_for_marketplaces" : get_marketplaces_to_store_id_json(),
37
+ "old_store_id_db_key" : aalb_cred_data.old_store_id_db_key,
38
+ "new_store_id_db_key" : aalb_cred_data.new_store_id_db_key,
39
+ "default_store_id_db_key" : aalb_cred_data.default_store_id_db_key,
40
+ "default_marketplace_db_key" : aalb_cred_data.default_marketplace_db_key,
41
+ "marketplace_settings_info_message": aalb_cred_strings.marketplace_settings_info_message,
42
+ "tracking_id_settings_info_message": aalb_cred_strings.tracking_id_settings_info_message,
43
+ "tracking_id_fieldset_label" : aalb_cred_strings.tracking_id_fieldset_label,
44
+ "add_a_marketplace_label" : aalb_cred_strings.add_a_marketplace_label
45
+ };
46
+ $( function() {
47
+ load_store_id_settings_section();
48
+
49
+ $( '#aalb-terms-checkbox' ).click( function() {
50
+ if( $( this ).is( ':checked' ) ) {
51
+ $( "#submit" ).removeAttr( 'disabled' );
52
+ } else {
53
+ $( '#submit' ).attr( 'disabled', 'disabled' );
54
+ }
55
+ } );
56
+
57
+ //Dynamic binding of "Remove marketplace" with click event using delegated event
58
+ $( '#aalb-store-ids-settings' ).on( 'click', '.aalb-remove-marketplace', function() {
59
+ marketplace_row_to_remove = $( this ).closest( '.aalb-marketplace-row' );
60
+ if( is_marketplace_row_removal_allowed( marketplace_row_to_remove.find( 'select' ).val() ) ) {
61
+ <!--ToDO: Below modal box size is overriden by the amp.js provided by "Accelerated mobile pages" plugin -->
62
+ tb_show( aalb_cred_strings.remove_marketplace_confirmation, '#TB_inline?width=350&height=85&inlineId=aalb-remove-marketplace-confirmation-container', false );
63
+ } else {
64
+ show_dismissable_error_message( aalb_cred_strings.remove_last_marketplace_error );
65
+ marketplace_row_to_remove = "";
66
+ }
67
+ } );
68
+
69
+ //Bind click event with positive confirmation to remove marketplace
70
+ $( '#aalb-remove-yes-button' ).on( 'click', function() {
71
+ var marketplace_being_removed = marketplace_row_to_remove.find( 'select' ).val();
72
+ marketplace_row_to_remove.remove();
73
+ marketplace_row_to_remove = "";
74
+ //Marketplace is removed first to handle case if the first row contains default marketplace
75
+ if( marketplace_being_removed === default_marketplace ) {
76
+ make_a_marketplace_default( $( '.aalb-marketplace-row:first' ).find( 'select' ).val() );
77
+ }
78
+ window.tb_remove();
79
+ } );
80
+
81
+ //Bind click event with negative confirmation to remove marketplace
82
+ $( '#aalb-remove-no-button' ).on( 'click', function() {
83
+ marketplace_row_to_remove = "";
84
+ window.tb_remove();
85
+ } );
86
+
87
+ //Dynamic binding of "Default marketplace" with click event using delegated event
88
+ $( '#aalb-store-ids-settings' ).on( 'click', '.aalb-default-marketplace a', function() {
89
+ var marketplace_clicked = $( this ).closest( '.aalb-marketplace-row' ).find( 'select' ).val();
90
+ //To handle if the marketplace clicked has not been still set by customer
91
+ if( marketplace_clicked !== null ) {
92
+ make_a_marketplace_default( marketplace_clicked );
93
+ }
94
+ } );
95
+
96
+ //Bind click event with "Add marketplace" anchor tag
97
+ $( '#aalb-add-new-marketplace' ).on( 'click', function() {
98
+ var locale_row_hbs = jQuery( "#aalb-marketplace-row-hbs" ).html();
99
+ if( locale_row_hbs != null ) {
100
+ var locale_row_template = Handlebars.compile( locale_row_hbs );
101
+ var locale_row_html = locale_row_template( marketplace_row_context );
102
+ $( ".aalb-add-new-marketplace" ).before( locale_row_html );
103
+ }
104
+ } );
105
+
106
+ //Bind click event with Dismiss notice button
107
+ $( '.aalb-settings-page' ).on( 'click', '.aalb-dismiss-notice', function() {
108
+ $( this ).closest( '.aalb-cred-error' ).remove();
109
+ } );
110
+
111
+ //Bind focus event with dropdown of marketplaces
112
+ $( "#aalb-store-ids-settings" ).on( 'focus', '.aalb-marketplace-row select', function() {
113
+ $( this ).data( 'prev-val', $( this ).val() );
114
+ } );
115
+
116
+ //Bind change event with dropdown of marketplaces
117
+ $( "#aalb-store-ids-settings" ).on( 'change', '.aalb-marketplace-row select', function() {
118
+ var prev_marketplace = $( this ).data( 'prev-val' );
119
+ var new_marketplace = $( this ).val();
120
+ if( is_marketplace_not_set_in_any_other_row( new_marketplace ) ) {
121
+ $( this ).val( new_marketplace );
122
+ var is_default_marketplace_row_not_present = $( '.aalb-marketplace-row select' ).filter( function( index, marketplace_dropdown ) {
123
+ return $( marketplace_dropdown ).val() === default_marketplace;
124
+ } ).length === 0;
125
+ if( prev_marketplace === default_marketplace || default_marketplace === "" || is_default_marketplace_row_not_present ) {
126
+ default_marketplace = new_marketplace;
127
+ if( prev_marketplace === null || is_default_marketplace_row_not_present ) {
128
+ var default_marketplace_column = $( this ).closest( '.aalb-marketplace-row' ).find( '.aalb-default-marketplace' );
129
+ default_marketplace_column.empty();
130
+ default_marketplace_column.append( '<span>' + aalb_cred_strings.default_marketplace_label + '</span>' );
131
+ }
132
+ }
133
+ } else {
134
+ //Null is returned for "Select Marketplace" as this option has been disabled
135
+ $( this ).val( prev_marketplace || SELECT_MARKETPLACE_DROPDOWN_VALUE );
136
+ show_dismissable_error_message( aalb_cred_strings.marketplace_exists_error );
137
+ }
138
+ $( this ).blur();
139
+ } );
140
+
141
+ //Sanitize store-id input on change
142
+ $( "#aalb-store-ids-settings" ).on( 'change', '.aalb-marketplace-row input', function() {
143
+ store_ids_list = $( this ).val().trim().split( STORE_ID_SEPARATOR );
144
+ //Removes empty store-id values from array
145
+ var sanitized_store_ids_list = store_ids_list.map( function( store_id ) {
146
+ return store_id.trim();
147
+ } ).filter( function( store_id ) {
148
+ return store_id != "";
149
+ } );
150
+ $( this ).val( sanitized_store_ids_list.join( STORE_ID_SEPARATOR ) );
151
+ } );
152
+
153
+ $( '#aalb-credentials-form' ).submit( function( event ) {
154
+ if( validate_tracking_ids() ) {
155
+ //Backward compatibility logic to be removed in future
156
+ backward_compatibility_logic();
157
+ set_marketplace_store_id_mapping();
158
+ $( '#' + aalb_cred_data.default_marketplace_db_key ).val( default_marketplace );
159
+ } else {
160
+ return false;
161
+ }
162
+ } );
163
+ } );
164
+
165
+ /**
166
+ * Checks if marketplace row removal is allowed
167
+ *
168
+ * @since 1.4.12
169
+ *
170
+ * @param String marketplace
171
+ * @boolean is_marketplace_row_removal_allowed
172
+ *
173
+ */
174
+ function is_marketplace_row_removal_allowed( marketplace ) {
175
+ //Not selected marketplace removal is allowed
176
+ if( marketplace === null ) {
177
+ return true;
178
  }
179
+ //Checks if there exist at least two dropdown with marketplace value set
180
+ return $( '.aalb-marketplace-row select' ).filter( function( index, marketplace_dropdown ) {
181
+ //Null is returned for "Select Marketplace" as this option has been disabled
182
+ return $( marketplace_dropdown ).val() !== null;
183
+ } ).length > 1;
184
  }
185
+
186
+ /**
187
+ * Loads the store-ids settings section using handlebars
188
+ *
189
+ * @since 1.4.12
190
+ *
191
+ */
192
+ function load_store_id_settings_section() {
193
+ var locale_row_partial = $( "#aalb-marketplace-row-hbs" ).html();
194
+ if( locale_row_partial != null ) {
195
+ //ToDO: below function of handlebars breaking flow on other pages so load this sciprt only if you are on settings page
196
+ Handlebars.registerPartial( "aalb-marketplace-row-hbs", $( "#aalb-marketplace-row-hbs" ).html() );
197
+ //https://stackoverflow.com/questions/8853396/logical-operator-in-a-handlebars-js-if-conditional
198
+ Handlebars.registerHelper( 'ifCond', function( v1, v2, options ) {
199
+ if( v1 === v2 ) {
200
+ return options.fn( this );
201
+ }
202
+ return options.inverse( this );
203
+ } );
204
+ var hbs_store_id_settings = jQuery( "#aalb-hbs-store-id-settings" ).html();
205
+ if( hbs_store_id_settings != null ) {
206
+ store_id_settings_template = Handlebars.compile( hbs_store_id_settings );
207
+ var store_id_setings_html = store_id_settings_template( store_ids_settings_context );
208
+ $( "#aalb-credentials-form" ).prepend( store_id_setings_html );
209
+ }
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Get the json for the marketplace-store id mapping to be passed in context
215
+ *
216
+ * @since 1.4.12
217
+ *
218
+ *
219
+ */
220
+ function get_marketplaces_to_store_id_json() {
221
+ var marketplace_store_id_obj = $.parseJSON( aalb_cred_data.new_store_ids );
222
+ var marketplace_store_id_array = [];
223
+ for( var marketplace in marketplace_store_id_obj ) {
224
+ marketplace_store_id_array.push( {
225
+ "marketplace" : marketplace,
226
+ "tracking_ids": marketplace_store_id_obj[ marketplace ].toString()
227
+ } );
228
+ }
229
+ return marketplace_store_id_array;
230
+ }
231
+
232
+ /**
233
+ * Checks if store-ids entry is valid for all marketplaces
234
+ *
235
+ * @since 1.4.12
236
+ *
237
+ * @return bool is_store_id_data_valid
238
+ */
239
+ function validate_tracking_ids() {
240
+ if( is_marketplace_not_set_in_any_dropdown() ) {
241
+ show_dismissable_error_message( aalb_cred_strings.marketplace_not_set_error );
242
+ return false;
243
+ } else if( is_store_id_not_entered_for_any_marketplace() ) {
244
+ show_dismissable_error_message( aalb_cred_strings.empty_store_id_error );
245
+ return false;
246
+ } else if( is_no_marketplace_row_added() ) {
247
+ show_dismissable_error_message( aalb_cred_strings.no_marketplace_row_error );
248
+ return false;
249
+ }
250
+ //Add more if validations like above if required
251
+ return true;
252
  }
253
+
254
+ /**
255
+ * Checks if store-ids entry for any marketplace is empty
256
+ *
257
+ * @since 1.4.12
258
+ *
259
+ * @return bool is_marketplace_field_empty
260
+ */
261
+ function is_store_id_not_entered_for_any_marketplace() {
262
+ return $( '.aalb-marketplace-row input' ).filter( function( index, store_id_input ) {
263
+ return $( store_id_input ).val() === '';
264
+ } ).length > 0;
265
+ }
266
+
267
+ /**
268
+ * Checks if user has not added any row for marketplace
269
+ *
270
+ * @since 1.4.12
271
+ *
272
+ * @return bool is no marketplace row present
273
+ */
274
+ function is_no_marketplace_row_added() {
275
+ return $( '.aalb-marketplace-row' ).length === 0;
276
+ }
277
+
278
+ /**
279
+ * Checks if any local dropdown is left unset for one or more rows
280
+ *
281
+ * @since 1.4.12
282
+ *
283
+ * @return bool is marketplace not set in any dropdown
284
+ */
285
+ function is_marketplace_not_set_in_any_dropdown() {
286
+ return $( '.aalb-marketplace-row select' ).filter( function( index, marketplace_dropdown ) {
287
+ //Null is returned for "Select Marketplace" as this option has been disabled
288
+ return $( marketplace_dropdown ).val() === null;
289
+ } ).length > 0;
290
+ }
291
+
292
+ /**
293
+ * Backward compatibility logic to prevent loss of store_ids in case someone switches to older version of plugin before 1.4.12
294
+ *
295
+ * To be deprecated in future
296
+ *
297
+ * @since 1.4.12
298
+ *
299
+ */
300
+ function backward_compatibility_logic() {
301
+ set_default_store_id();
302
+ set_old_store_ids_key();
303
+ }
304
+
305
+ /**
306
+ * Set the old store ids key
307
+ *
308
+ * @since 1.4.12
309
+ *
310
+ */
311
+ function set_old_store_ids_key() {
312
+ var store_id_list = [];
313
+ //Append store ids for all marketplaces
314
+ $( '.aalb-store-ids-for-marketplace' ).each( function() {
315
+ store_id_list = store_id_list.concat( $( this ).val().split( STORE_ID_SEPARATOR ) );
316
+ } );
317
+ //Old store_ids(before 1.4.12) were separated by "\r\n"
318
+ $( '#' + aalb_cred_data.old_store_id_db_key ).val( store_id_list.join( "\r\n" ) );
319
+ }
320
+
321
+ /**
322
+ * Sets default store id
323
+ *
324
+ * @since 1.4.12
325
+ *
326
+ */
327
+ function set_default_store_id() {
328
+ //Need to maintain the overall default_store_Id to keep the item_look_up api code backward compatible
329
+ var default_marketplace_row = get_row_containing_marketplace( default_marketplace );
330
+ if( default_marketplace_row.length > 0 ) {
331
+ var default_store_id = default_marketplace_row.find( 'input' ).val().split( STORE_ID_SEPARATOR )[ 0 ];
332
+ $( '#' + aalb_cred_data.default_store_id_db_key ).val( default_store_id );
333
+ }
334
+ }
335
+
336
+ /**
337
+ * Finds the row containing the marketplace and returns the jQuery Object for that
338
+ *
339
+ * @since 1.4.12
340
+ *
341
+ * @return HTMLTableRowElement
342
+ */
343
+ function get_row_containing_marketplace( marketplace ) {
344
+ return $( '.aalb-marketplace-row' ).filter( function( index, marketplace_row ) {
345
+ return $( marketplace_row ).find( 'select' ).val() === marketplace;
346
+ } );
347
+ }
348
+
349
+ /**
350
+ * Sets the marketplace and store id mapping in the hidden input field to be passed on form submission
351
+ *
352
+ * @since 1.4.12
353
+ *
354
+ */
355
+ function set_marketplace_store_id_mapping() {
356
+ var tracking_id_json = {};
357
+ $( '.aalb-marketplace-row' ).each( function() {
358
+ tracking_id_json[ $( this ).find( 'select' ).val() ] = $( this ).find( 'input' ).val().split( "," );
359
+ } );
360
+ $( '#' + aalb_cred_data.new_store_id_db_key ).val( JSON.stringify( tracking_id_json ) );
361
+ }
362
+
363
+ /**
364
+ * Shows the dismissible error messages
365
+ *
366
+ * @param String Error Message to display
367
+ *
368
+ * @since 1.4.12
369
+ *
370
+ */
371
+ function show_dismissable_error_message( error_msg ) {
372
+ $( '#aalb-credentials-form' ).before( '<div class="is-dismissible notice notice-error aalb-cred-error"><p>' + error_msg + '</p></div>' );
373
+ $( '.aalb-cred-error:last' ).find( 'p' ).after( '<button type="button" class= "aalb-dismiss-notice notice-dismiss"></button>' );
374
+ $( 'html,body' ).scrollTop( 0 );
375
+ }
376
+
377
+ /**
378
+ * Checks if value is already set in some other row
379
+ *
380
+ * @param String marketplace
381
+ *
382
+ * @return bool is marketplace not set in any other row
383
+ *
384
+ * @since 1.4.12
385
+ */
386
+ function is_marketplace_not_set_in_any_other_row( marketplace ) {
387
+ return $( '.aalb-marketplace-row select' ).filter( function( index, marketplace_dropdown ) {
388
+ return $( marketplace_dropdown ).val() === marketplace;
389
+ } ).length < 2;
390
+ }
391
+
392
+ /**
393
+ * Make a marketplace default
394
+ *
395
+ * @param String Default marketplace
396
+ *
397
+ * @since 1.4.12
398
+ *
399
+ */
400
+ function make_a_marketplace_default( new_default_marketplace ) {
401
+ $( '.aalb-marketplace-row' ).each( function() {
402
+ var marketplace = $( this ).find( 'select' ).val();
403
+ if( marketplace === default_marketplace ) {
404
+ var element = $( this ).find( '.aalb-default-marketplace' );
405
+ element.find( 'span' ).remove();
406
+ element.append( '<a href="#">' + aalb_cred_strings.set_as_default_marketplace_label + '</a>' );
407
+ } else if( marketplace === new_default_marketplace ) {
408
+ var element = $( this ).find( '.aalb-default-marketplace' );
409
+ element.find( 'a' ).remove();
410
+ element.append( '<span>' + aalb_cred_strings.default_marketplace_label + '</span>' );
411
+ }
412
+ } );
413
+ default_marketplace = new_default_marketplace;
414
+ }
415
+
416
+ })( jQuery );
admin/sidebar/partials/aalb_credentials.php CHANGED
@@ -13,77 +13,60 @@ and limitations under the License.
13
  */
14
 
15
  include 'aalb_admin_ui_common.php';
16
- $helper = new Aalb_Helper();
17
- $aalb_store_id_names = $helper->get_store_ids_array();
18
- wp_enqueue_script( 'jquery' );
19
- wp_enqueue_script( 'aalb_credentials_js', AALB_CREDENTIALS_JS, array( 'jquery' ), AALB_PLUGIN_CURRENT_VERSION );
20
- wp_localize_script( 'aalb_credentials_js', 'wp_opt', array( 'plugin_url' => AALB_PLUGIN_URL ) );
21
- wp_enqueue_style( 'aalb_credentials_css', AALB_CREDENTIALS_CSS, array(), AALB_PLUGIN_CURRENT_VERSION );
22
  ?>
 
 
23
 
24
- <div class="wrap">
 
 
 
 
 
 
 
 
 
 
 
25
  <h2><?php esc_html_e( "Settings for Associates Link Builder", 'amazon-associates-link-builder' ) ?></h2>
26
  <br>
27
- <form method="post" action="options.php">
28
  <?php settings_fields( AALB_CRED_CONFIG_GROUP );
29
  do_settings_sections( AALB_CRED_CONFIG_GROUP ); ?>
30
- <fieldset class="aalb-settings-fieldset">
31
- <legend class="aalb-settings-legend"> <?php esc_html_e( "Tracking Id(s)", 'amazon-associates-link-builder' ) ?> </legend>
32
- <table class ="widefat fixed aalb-settings-table">
33
- <tr>
34
- <th scope="row" class="aalb-settings-identifier"><?php esc_html_e( "Associate ID", 'amazon-associates-link-builder' ) ?></th>
35
- <td class="aalb-settings-input-column">
36
- <textarea type="text" id=<?php echo AALB_STORE_ID_NAMES ?> name=<?php echo AALB_STORE_ID_NAMES ?> class="aalb-settings-input-field"
37
- value="<?php echo esc_attr( get_option( AALB_STORE_ID_NAMES ) ); ?>"
38
- onchange="aalb_credentials_store_ids_onchange(this)"><?php echo esc_attr( get_option( AALB_STORE_ID_NAMES ) ); ?>
39
- </textarea>
40
- </td>
41
- <td><?php esc_html_e( "Associate ID is used to monitor traffic and sales from your links to Amazon. You can add one store id or tracking id per row. You are recommended to create a new tracking ID in your Amazon Associates account for using it as Associate ID in the plugin.", 'amazon-associates-link-builder' ) ?>
42
- </td>
43
- </tr>
44
- </table>
45
- </fieldset>
46
- <br>
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  <fieldset class="aalb-settings-fieldset">
49
  <legend class="aalb-settings-legend"><?php esc_html_e( "Site Wide Settings", 'amazon-associates-link-builder' ) ?></legend>
50
- <table class ="widefat fixed aalb-settings-table">
51
- <tr>
52
- <th scope="row" class="aalb-settings-identifier"><?php esc_html_e( "Default Associate ID", 'amazon-associates-link-builder' ) ?></th>
53
- <td class="aalb-settings-input-column">
54
- <?php $default_store_id = get_option( AALB_DEFAULT_STORE_ID, AALB_DEFAULT_STORE_ID_NAME ); ?>
55
- <select id=<?php echo AALB_DEFAULT_STORE_ID ?> name=<?php echo AALB_DEFAULT_STORE_ID ?> class="aalb-settings-input-field">
56
- <?php
57
- foreach ( $aalb_store_id_names as $store_id ) {
58
- echo '<option value="' . $store_id . '"';
59
- selected( $default_store_id, $store_id );
60
- echo '>' . $store_id . '</option>\n';
61
- }
62
- ?>
63
- </select>
64
- </td>
65
- <td><?php esc_html_e( "The Associate ID that will be used for tagging the affiliate links generated by the plugin if no tag is specified in the short code.", 'amazon-associates-link-builder' ) ?>
66
- </td>
67
- </tr>
68
- <tr>
69
- <th scope="row" class="aalb-settings-identifier"><?php esc_html_e( "Default Marketplace", 'amazon-associates-link-builder' ) ?></th>
70
- <td class="aalb-settings-input-column">
71
- <?php $default_marketplace = get_option( AALB_DEFAULT_MARKETPLACE, AALB_DEFAULT_MARKETPLACE_NAME ); ?>
72
- <select name=<?php echo AALB_DEFAULT_MARKETPLACE ?> class="aalb-settings-input-field">
73
- <?php
74
- $config_loader = new Aalb_Config_Loader();
75
- $aalb_marketplace_names = $config_loader->fetch_marketplaces();
76
- foreach ( $aalb_marketplace_names as $marketplace ) {
77
- echo '<option value="' . $marketplace . '"';
78
- selected( $default_marketplace, $marketplace );
79
- echo '>' . $marketplace . '</option>\n';
80
- }
81
- ?>
82
- </select>
83
- </td>
84
- <td><?php esc_html_e( "Set the default Amazon marketplace based on the Amazon website that is identified in your Associates Account (for instance, if you have signed up for Amazon.co.uk site, then your default marketplace selection should be UK).", 'amazon-associates-link-builder' ) ?>
85
- </td>
86
- </tr>
87
  <tr>
88
  <th scope="row" class="aalb-settings-identifier"><?php esc_html_e( "Default Template", 'amazon-associates-link-builder' ) ?></th>
89
  <td class="aalb-settings-input-column">
@@ -104,7 +87,8 @@ wp_enqueue_style( 'aalb_credentials_css', AALB_CREDENTIALS_CSS, array(), AALB_PL
104
  </tr>
105
  <tr>
106
  <td scope="row" colspan="2" class="aalb-settings-input-column">
107
- <input id=<?php echo AALB_NO_REFERRER_DISABLED ?> type="checkbox" name=<?php echo AALB_NO_REFERRER_DISABLED ?> value="true"<?php if (get_option( AALB_NO_REFERRER_DISABLED )) echo "checked='checked'"; ?> />
 
108
  <label class="aalb-settings-no-referrer-text" for="aalb_no_referrer_disabled">
109
  <?php /* translators: %s: rel="noreferrer" attribute */
110
  printf( esc_html__( "Remove %s for Amazon Affiliate Links from all posts", 'amazon-associates-link-builder' ), "rel=\"noreferrer\"" ); ?></label>
@@ -120,12 +104,12 @@ wp_enqueue_style( 'aalb_credentials_css', AALB_CREDENTIALS_CSS, array(), AALB_PL
120
 
121
  <fieldset class="aalb-settings-fieldset">
122
  <legend class="aalb-settings-legend"><?php esc_html_e( "PA-API Credentials", 'amazon-associates-link-builder' ) ?></legend>
123
- <table class ="widefat fixed aalb-settings-table">
124
  <tr>
125
  <th scope="row" class="aalb-settings-identifier"><?php esc_html_e( "Access Key ID", 'amazon-associates-link-builder' ) ?></th>
126
  <td class="aalb-settings-input-column">
127
  <input type="text" name=<?php echo AALB_AWS_ACCESS_KEY ?> class="aalb-settings-input-field"
128
- value="<?php echo esc_attr( openssl_decrypt( base64_decode( get_option( AALB_AWS_ACCESS_KEY ) ), AALB_ENCRYPTION_ALGORITHM, AALB_ENCRYPTION_KEY, 0, AALB_ENCRYPTION_IV ) ); ?>"/>
129
  </td>
130
  <td>
131
  <?php /* translators: 1: URL of Getting Started page 2: _blank */
@@ -140,8 +124,7 @@ wp_enqueue_style( 'aalb_credentials_css', AALB_CREDENTIALS_CSS, array(), AALB_PL
140
  }
141
  ?>
142
  <td class="aalb-settings-input-column"><input type="password" name=<?php echo AALB_AWS_SECRET_KEY ?>
143
- class="aalb-settings-input-field" value="<?php echo esc_attr( $secret_key ); ?>"
144
- autocomplete="off"/>
145
  </td>
146
  <td>
147
  <?php /* translators: 1: URL of managing PA-API acccount page 2: _blank */
@@ -152,12 +135,12 @@ wp_enqueue_style( 'aalb_credentials_css', AALB_CREDENTIALS_CSS, array(), AALB_PL
152
  </fieldset>
153
 
154
  <div class="aalb-terms-conditions">
155
- <input id="aalb-terms-checkbox" type="checkbox" name="demo-checkbox" value="1"/>
156
  <label for="aalb-terms-checkbox">
157
  <?php /* translators: 1: URL of Condition of Use page 2: _blank */
158
  printf( __( "Check here to indicate that you have read and agree to the Amazon Associates Link Builder <a href=%1s target=%2s>Conditions of Use</a>.", 'amazon-associates-link-builder' ), AALB_CONDITIONS_OF_USE_URL, AALB_NEW_PAGE_TARGET ) ?></label>
159
  </div>
160
  <?php $aalb_submit_button_text = esc_html__( "Save Changes", 'amazon-associates-link-builder' );
161
- submit_button( $aalb_submit_button_text, 'primary', 'submit', true, array( 'disabled' => 'disabled' ) ); ?>
162
  </form>
163
- </div>
13
  */
14
 
15
  include 'aalb_admin_ui_common.php';
16
+ include 'aalb_credentials_locale_row.php'
 
 
 
 
 
17
  ?>
18
+ <!-- ToDO: 1. Convert table to div. 2. Put complete code under handlebars as currently store-id settings loads 1 second after page load-->
19
+ <!-- ToDO: 3. Include JSHint 4. See how can we leverage any of the libraries from Angular,React or VueJS -->
20
 
21
+ <!--start: confirmation modal for Remove marketplace-->
22
+ <div id="aalb-remove-marketplace-confirmation-container">
23
+ <div><?php esc_html_e( "Are you sure you want to remove this marketplace?", 'amazon-associates-link-builder' ) ?></div>
24
+ <br />
25
+ <div>
26
+ <button id="aalb-remove-yes-button" class="aalb-btn aalb-btn-primary"><?php esc_html_e( "YES", 'amazon-associates-link-builder' ) ?></button>
27
+ <button id="aalb-remove-no-button" class="aalb-btn aalb-btn-primary"><?php esc_html_e( "NO", 'amazon-associates-link-builder' ) ?></button>
28
+ </div>
29
+ <input type="hidden" id="aalb-marketplace-to-remove" />
30
+ </div> <!--end: confirmation modal for Remove marketplace-->
31
+
32
+ <div class="wrap aalb-settings-page">
33
  <h2><?php esc_html_e( "Settings for Associates Link Builder", 'amazon-associates-link-builder' ) ?></h2>
34
  <br>
35
+ <form id="aalb-credentials-form" method="post" action="options.php">
36
  <?php settings_fields( AALB_CRED_CONFIG_GROUP );
37
  do_settings_sections( AALB_CRED_CONFIG_GROUP ); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
+ <script id="aalb-hbs-store-id-settings" type="text/x-handlebars-template">
40
+ <fieldset class="aalb-settings-fieldset">
41
+ <legend class="aalb-settings-legend"> {{tracking_id_fieldset_label}}</legend>
42
+ <table id="aalb-store-ids-settings" class="widefat aalb-settings-table">
43
+ <tr>
44
+ <td colspan="4">
45
+ {{marketplace_settings_info_message}}
46
+ <br>
47
+ {{tracking_id_settings_info_message}}
48
+ </td>
49
+ </tr>
50
+ {{#each store_ids_for_marketplaces}}
51
+ {{> aalb-marketplace-row-hbs ../marketplace_row_context marketplace=this.marketplace tracking_ids=this.tracking_ids }}
52
+ {{/each}}
53
+ <tr class="aalb-add-new-marketplace">
54
+ <td colspan="4">
55
+ <a href="#" id="aalb-add-new-marketplace">{{add_a_marketplace_label}}</a>
56
+ </td>
57
+ </tr>
58
+ </table>
59
+ <!--Below fields needs to saved on form submission but don't require any user action so hidden-->
60
+ <input type="hidden" id={{old_store_id_db_key}} name={{old_store_id_db_key}}>
61
+ <input type="hidden" id={{new_store_id_db_key}} name={{new_store_id_db_key}}>
62
+ <input type="hidden" id={{default_store_id_db_key}} name={{default_store_id_db_key}}>
63
+ <input type="hidden" id={{default_marketplace_db_key}} name={{default_marketplace_db_key}}>
64
+ </fieldset>
65
+ </script>
66
+ <br>
67
  <fieldset class="aalb-settings-fieldset">
68
  <legend class="aalb-settings-legend"><?php esc_html_e( "Site Wide Settings", 'amazon-associates-link-builder' ) ?></legend>
69
+ <table class="widefat fixed aalb-settings-table">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  <tr>
71
  <th scope="row" class="aalb-settings-identifier"><?php esc_html_e( "Default Template", 'amazon-associates-link-builder' ) ?></th>
72
  <td class="aalb-settings-input-column">
87
  </tr>
88
  <tr>
89
  <td scope="row" colspan="2" class="aalb-settings-input-column">
90
+ <input id=<?php echo AALB_NO_REFERRER_DISABLED ?> type="checkbox" name=<?php echo AALB_NO_REFERRER_DISABLED ?> value="true"<?php if ( get_option( AALB_NO_REFERRER_DISABLED ) )
91
+ echo "checked='checked'"; ?> />
92
  <label class="aalb-settings-no-referrer-text" for="aalb_no_referrer_disabled">
93
  <?php /* translators: %s: rel="noreferrer" attribute */
94
  printf( esc_html__( "Remove %s for Amazon Affiliate Links from all posts", 'amazon-associates-link-builder' ), "rel=\"noreferrer\"" ); ?></label>
104
 
105
  <fieldset class="aalb-settings-fieldset">
106
  <legend class="aalb-settings-legend"><?php esc_html_e( "PA-API Credentials", 'amazon-associates-link-builder' ) ?></legend>
107
+ <table class="widefat fixed aalb-settings-table">
108
  <tr>
109
  <th scope="row" class="aalb-settings-identifier"><?php esc_html_e( "Access Key ID", 'amazon-associates-link-builder' ) ?></th>
110
  <td class="aalb-settings-input-column">
111
  <input type="text" name=<?php echo AALB_AWS_ACCESS_KEY ?> class="aalb-settings-input-field"
112
+ value="<?php echo esc_attr( openssl_decrypt( base64_decode( get_option( AALB_AWS_ACCESS_KEY ) ), AALB_ENCRYPTION_ALGORITHM, AALB_ENCRYPTION_KEY, 0, AALB_ENCRYPTION_IV ) ); ?>" />
113
  </td>
114
  <td>
115
  <?php /* translators: 1: URL of Getting Started page 2: _blank */
124
  }
125
  ?>
126
  <td class="aalb-settings-input-column"><input type="password" name=<?php echo AALB_AWS_SECRET_KEY ?>
127
+ class="aalb-settings-input-field" value="<?php echo esc_attr( $secret_key ); ?>" autocomplete="off" />
 
128
  </td>
129
  <td>
130
  <?php /* translators: 1: URL of managing PA-API acccount page 2: _blank */
135
  </fieldset>
136
 
137
  <div class="aalb-terms-conditions">
138
+ <input id="aalb-terms-checkbox" type="checkbox" name="demo-checkbox" value="1" />
139
  <label for="aalb-terms-checkbox">
140
  <?php /* translators: 1: URL of Condition of Use page 2: _blank */
141
  printf( __( "Check here to indicate that you have read and agree to the Amazon Associates Link Builder <a href=%1s target=%2s>Conditions of Use</a>.", 'amazon-associates-link-builder' ), AALB_CONDITIONS_OF_USE_URL, AALB_NEW_PAGE_TARGET ) ?></label>
142
  </div>
143
  <?php $aalb_submit_button_text = esc_html__( "Save Changes", 'amazon-associates-link-builder' );
144
+ submit_button( $aalb_submit_button_text, 'primary', 'submit', true, array( 'disabled' => 'disabled' ) ); ?>
145
  </form>
146
+ </div>
admin/sidebar/partials/aalb_credentials_locale_row.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+
4
+ Licensed under the GNU General Public License as published by the Free Software Foundation,
5
+ Version 2.0 (the "License"). You may not use this file except in compliance with the License.
6
+ A copy of the License is located in the "license" file accompanying this file.
7
+
8
+ This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
9
+ either express or implied. See the License for the specific language governing permissions
10
+ and limitations under the License.
11
+ -->
12
+ <?php
13
+ /*
14
+ * Below is an example of context to be passed to this template
15
+ {
16
+ "marketplace_list":[
17
+ "IN",
18
+ "US",
19
+ "CN",
20
+ "UK"
21
+ ],
22
+ "set_as_default_marketplace_label":"Set As Default Marketplace",
23
+ "remove_marketplace_label":"Remove Marketplace",
24
+ "default_marketplace_label":"Default Marketplace",
25
+ "select_marketplace_label":"Select Marketplace",
26
+ "tracking_id_placeholder":"Enter Tracking Id(s)",
27
+ "default_marketplace_value":"IN",
28
+ "marketplace":"IN",
29
+ "tracking_ids":"store-1,store-2"
30
+ }
31
+ */
32
+ ?>
33
+
34
+ <script id="aalb-marketplace-row-hbs" type="text/x-handlebars-template">
35
+ <tr class="aalb-marketplace-row">
36
+ <th scope="row" class="aalb-settings-identifier">
37
+ <select class="aalb-dropdown-marketplace">
38
+ <option value="no-selection" disabled="disabled" selected="selected">{{select_marketplace_label}}</option>
39
+ {{#each marketplace_list}}
40
+ {{#ifCond this ../marketplace}}
41
+ <option value={{this}} selected>{{this}}</option>
42
+ {{else}}
43
+ <option value={{this}}>{{this}}</option>
44
+ {{/ifCond}}
45
+ {{/each}}
46
+ </select>
47
+ </th>
48
+ <td class="aalb-settings-input-column aalb-store-ids-column ">
49
+ <input type="text" class="aalb-settings-input-field aalb-store-ids-for-marketplace" value="{{tracking_ids}}" placeholder="{{tracking_id_placeholder}}">
50
+ </td>
51
+ <td><a href="#" class="aalb-remove-marketplace">{{remove_marketplace_label}}</a></td>
52
+ <td class="aalb-default-marketplace">
53
+ {{#ifCond marketplace default_marketplace_value}}
54
+ <span>{{default_marketplace_label}}</span>
55
+ {{else}}
56
+ <a href="#">{{set_as_default_marketplace_label}}</a>
57
+ {{/ifCond}}
58
+ </td>
59
+ </tr>
60
+ </script>
admin/sidebar/partials/helper/aalb_credentials_helper.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+
6
+ Licensed under the GNU General Public License as published by the Free Software Foundation,
7
+ Version 2.0 (the "License"). You may not use this file except in compliance with the License.
8
+ A copy of the License is located in the "license" file accompanying this file.
9
+
10
+ This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11
+ either express or implied. See the License for the specific language governing permissions
12
+ and limitations under the License.
13
+ */
14
+
15
+ /**
16
+ * Helper class for commonly used functions in the credentials page of plugin.
17
+ *
18
+ * @since 1.4.12
19
+ * @package AmazonAssociatesLinkBuilder
20
+ * @subpackage AmazonAssociatesLinkBuilder/admin/sidebar/partials/helper
21
+ */
22
+ class Aalb_Credentials_Helper {
23
+
24
+ /**
25
+ * Returns data to be localized in the script.
26
+ * Makes the variable values in PHP to be used in Javascript.
27
+ *
28
+ * @since 1.4.12
29
+ * @return array Data to be localized in the script
30
+ */
31
+ private function credentials_data() {
32
+ return array(
33
+ 'old_store_id_db_key' => AALB_STORE_ID_NAMES,
34
+ 'new_store_id_db_key' => AALB_STORE_IDS,
35
+ 'new_store_ids' => get_option( AALB_STORE_IDS ),
36
+ 'default_marketplace_db_key' => AALB_DEFAULT_MARKETPLACE,
37
+ 'default_marketplace_value' => get_option( AALB_DEFAULT_MARKETPLACE ),
38
+ 'marketplace_list' => $this->get_marketplace_list(),
39
+ 'default_store_id_db_key' => AALB_DEFAULT_STORE_ID
40
+
41
+ );
42
+ }
43
+
44
+ /**
45
+ * Returns constant strings to be used in aalb_credentials.js
46
+ * Makes the variable values in PHP to be used in Javascript.
47
+ *
48
+ * @since 1.4.12
49
+ * @return array Data to be localized in the script
50
+ */
51
+ private function credentials_strings() {
52
+ //ToDO: Make default marketplace and remove marketplace also as label and put all labels together
53
+ return array(
54
+ 'tracking_id_placeholder' => esc_html__( "Enter Tracking Id(s)", 'amazon-associates-link-builder' ),
55
+ 'remove_marketplace_label' => esc_html__( "Remove Marketplace", 'amazon-associates-link-builder' ),
56
+ 'select_marketplace_label' => esc_html__( "Select Marketplace", 'amazon-associates-link-builder' ),
57
+ 'default_marketplace_label' => esc_html__( "Default Marketplace", 'amazon-associates-link-builder' ),
58
+ 'set_as_default_marketplace_label' => esc_html__( "Set As Default Marketplace", 'amazon-associates-link-builder' ),
59
+ "tracking_id_fieldset_label" => esc_html__( "Tracking Id(s)", 'amazon-associates-link-builder' ),
60
+ "add_a_marketplace_label" => esc_html__( "Add a Marketplace", 'amazon-associates-link-builder' ),
61
+ 'remove_marketplace_confirmation' => esc_html__( "Remove Marketplace Confirmation", 'amazon-associates-link-builder' ),
62
+ "empty_store_id_error" => esc_html__( "ERROR: No store id has been entered for one or more marketplaces.", 'amazon-associates-link-builder' ),
63
+ "marketplace_exists_error" => esc_html__( "ERROR: A marketplace already exists with this value. Please set a new marketplace.", 'amazon-associates-link-builder' ),
64
+ "marketplace_not_set_error" => esc_html__( "ERROR: A marketplace is present that has not been set. Please set that first.", 'amazon-associates-link-builder' ),
65
+ "remove_last_marketplace_error" => esc_html__( "ERROR: You need to maintain at least one marketplace entry for tracking ids ", 'amazon-associates-link-builder' ),
66
+ "no_marketplace_row_error" => esc_html__( "ERROR: You need to add at least one marketplace entry for tracking ids ", 'amazon-associates-link-builder' ),
67
+ "marketplace_settings_info_message" => esc_html__( "Add a Marketplace that you want to create Amazon links to.", 'amazon-associates-link-builder' ),
68
+ "tracking_id_settings_info_message" => esc_html__( "For each marketplace you can add multiple tracking ids, separated by commas. The first tracking id will be considered as default tracking id for that marketplace.", 'amazon-associates-link-builder' )
69
+ );
70
+ }
71
+
72
+ /**
73
+ * Enqueue CSS classes
74
+ *
75
+ * @since 1.4.12
76
+ *
77
+ */
78
+ public function aalb_credentials_enqueue_style() {
79
+ wp_enqueue_style( 'thickbox' );
80
+ wp_enqueue_style( 'aalb_credentials_css', AALB_CREDENTIALS_CSS, array(), AALB_PLUGIN_CURRENT_VERSION );
81
+ }
82
+
83
+ /**
84
+ * Enqueue JS files
85
+ *
86
+ * @since 1.4.12
87
+ *
88
+ */
89
+ public function aalb_credentials_enqueue_script() {
90
+ wp_enqueue_script( 'jquery' );
91
+ wp_enqueue_script( 'thickbox' );
92
+ wp_enqueue_script( 'handlebars_js', HANDLEBARS_JS );
93
+ wp_enqueue_script( 'aalb_credentials_js', AALB_CREDENTIALS_JS, array( 'jquery', 'thickbox', 'handlebars_js' ), AALB_PLUGIN_CURRENT_VERSION );
94
+ wp_localize_script( 'aalb_credentials_js', 'aalb_cred_data', $this->credentials_data() );
95
+ wp_localize_script( 'aalb_credentials_js', 'aalb_cred_strings', $this->credentials_strings() );
96
+ }
97
+
98
+ /**
99
+ * Returns list of marketplaces
100
+ *
101
+ *
102
+ * @since 1.4.12
103
+ * @return array marketplaces list
104
+ */
105
+ private function get_marketplace_list() {
106
+ $config_loader = new Aalb_Config_Loader();
107
+ $aalb_marketplace_names = $config_loader->fetch_marketplaces();
108
+
109
+ return json_encode( array_values( $aalb_marketplace_names ) );
110
+ }
111
+ }
112
+
113
+ ?>
amazon-associates-link-builder.php CHANGED
@@ -7,7 +7,7 @@
7
  /*
8
  Plugin Name: Amazon Associates Link Builder
9
  Description: Amazon Associates Link Builder is the official free Amazon Associates Program plugin for WordPress. The plugin enables you to search for products in the Amazon catalog, access real-time price and availability information, and easily create links in your posts to products on Amazon.com. You will be able to generate text links, create custom ad units, or take advantage of out-of-the-box widgets that we’ve designed and included with the plugin.
10
- Version: 1.4.11
11
  Author: Amazon Associates Program
12
  Author URI: https://affiliate-program.amazon.com/
13
  License: GPLv2
7
  /*
8
  Plugin Name: Amazon Associates Link Builder
9
  Description: Amazon Associates Link Builder is the official free Amazon Associates Program plugin for WordPress. The plugin enables you to search for products in the Amazon catalog, access real-time price and availability information, and easily create links in your posts to products on Amazon.com. You will be able to generate text links, create custom ad units, or take advantage of out-of-the-box widgets that we’ve designed and included with the plugin.
10
+ Version: 1.4.12
11
  Author: Amazon Associates Program
12
  Author URI: https://affiliate-program.amazon.com/
13
  License: GPLv2
includes/aalb_activator.php CHANGED
@@ -55,6 +55,9 @@ class Aalb_Activator {
55
  if ( ! get_option( AALB_AWS_SECRET_KEY ) ) {
56
  update_option( AALB_AWS_SECRET_KEY, '' );
57
  }
 
 
 
58
  }
59
 
60
  /**
55
  if ( ! get_option( AALB_AWS_SECRET_KEY ) ) {
56
  update_option( AALB_AWS_SECRET_KEY, '' );
57
  }
58
+ if ( ! get_option( AALB_STORE_IDS ) ) {
59
+ update_option( AALB_STORE_IDS, '' );
60
+ }
61
  }
62
 
63
  /**
includes/aalb_autoloader.php CHANGED
@@ -52,6 +52,7 @@ class Aalb_Autoloader {
52
  new self( AALB_PAAPI_DIR );
53
  new self( AALB_SHORTCODE_DIR );
54
  new self( AALB_LIBRARY_DIR );
 
55
  }
56
 
57
  /**
52
  new self( AALB_PAAPI_DIR );
53
  new self( AALB_SHORTCODE_DIR );
54
  new self( AALB_LIBRARY_DIR );
55
+ new self( AALB_SIDEBAR_HELPER_DIR );
56
  }
57
 
58
  /**
includes/aalb_cache_loader.php CHANGED
@@ -80,7 +80,6 @@ class Aalb_Cache_Loader {
80
 
81
  $this->helper->clear_expired_transients_at_intervals();
82
  set_transient( $key, $info, AALB_CACHE_FOR_ASIN_RAWINFO_TTL );
83
-
84
  return $info;
85
  }
86
  }
80
 
81
  $this->helper->clear_expired_transients_at_intervals();
82
  set_transient( $key, $info, AALB_CACHE_FOR_ASIN_RAWINFO_TTL );
 
83
  return $info;
84
  }
85
  }
includes/aalb_manager.php CHANGED
@@ -33,6 +33,9 @@ class Aalb_Manager {
33
 
34
  //add the hooks for shortcode rendering.
35
  $this->register_shortcode_hooks();
 
 
 
36
  }
37
 
38
  /**
@@ -67,6 +70,17 @@ class Aalb_Manager {
67
  $this->hook_loader->add_action( 'wp_enqueue_scripts', $aalb_shortcode_text, 'enqueue_styles' );
68
  }
69
 
 
 
 
 
 
 
 
 
 
 
 
70
  /**
71
  * Execute all the wordpress hooks and shortcodes.
72
  *
33
 
34
  //add the hooks for shortcode rendering.
35
  $this->register_shortcode_hooks();
36
+
37
+ //Add the hooks for the rendering Settings page of plugin
38
+ $this->add_credentials_hooks();
39
  }
40
 
41
  /**
70
  $this->hook_loader->add_action( 'wp_enqueue_scripts', $aalb_shortcode_text, 'enqueue_styles' );
71
  }
72
 
73
+ /**
74
+ * Add the hooks for the rendering Settings page of the plugin
75
+ *
76
+ * @since 1.4.12
77
+ */
78
+ private function add_credentials_hooks() {
79
+ $credentials_helper = new Aalb_Credentials_Helper();
80
+ $this->hook_loader->add_action( 'admin_enqueue_scripts', $credentials_helper, 'aalb_credentials_enqueue_style' );
81
+ $this->hook_loader->add_action( 'admin_enqueue_scripts', $credentials_helper, 'aalb_credentials_enqueue_script' );
82
+ }
83
+
84
  /**
85
  * Execute all the wordpress hooks and shortcodes.
86
  *
includes/aalb_settings_page_migration_helper.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+
5
+ Licensed under the GNU General Public License as published by the Free Software Foundation,
6
+ Version 2.0 (the "License"). You may not use this file except in compliance with the License.
7
+ A copy of the License is located in the "license" file accompanying this file.
8
+
9
+ This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10
+ either express or implied. See the License for the specific language governing permissions
11
+ and limitations under the License.
12
+ */
13
+
14
+ /**
15
+ * Fired during the plugin activation
16
+ *
17
+ * Runs the migration logic to populate store-ids in default locale and also to handle backward compatibility
18
+ * after release of new Settings page version(1.4.12)
19
+ *
20
+ * Temporary class. Needs to be removed after few versions once wide variety of audience
21
+ * is on new Settings page version
22
+ *
23
+ * @since 1.4.12
24
+ * @package AmazonAssociatesLinkBuilder
25
+ * @subpackage AmazonAssociatesLinkBuilder/includes
26
+ */
27
+ class Aalb_Settings_Page_Migration_Helper {
28
+ /**
29
+ * Runs the migrations logic to new settings page
30
+ *
31
+ * @since 1.4.12
32
+ */
33
+ public function run_migration_logic() {
34
+ if ( version_compare( AALB_MULTI_LOCALE_SETTINGS_PLUGIN_VERSION, get_option( AALB_PLUGIN_VERSION ) ) ) {
35
+ delete_option( AALB_STORE_IDS );
36
+ $this->migrate_storeids();
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Populates store ids in default locale
42
+ *
43
+ * @since 1.4.12
44
+ */
45
+ private function migrate_storeids() {
46
+ $default_marketplace_name = get_option( AALB_DEFAULT_MARKETPLACE, AALB_DEFAULT_MARKETPLACE_NAME );
47
+ $store_id_list = get_option( AALB_STORE_ID_NAMES );
48
+ if ( $store_id_list ) {
49
+ $marketplace_store_id_mapping = array( $default_marketplace_name => explode( AALB_NEWLINE_SEPARATOR, $store_id_list ) );
50
+ update_option( AALB_STORE_IDS, json_encode( $marketplace_store_id_mapping ) );
51
+ }
52
+ }
53
+ }
54
+
55
+ ?>
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: amazonlinkbuilder
3
  Tags: Amazon, Affiliate, Associates, Amazon Associates, Amazon Associate, Product Advertising API, Amazon API, Amazon Link, Amazon Ad, Amazon Affiliate, eCommerce
4
  Requires at least: 3.0.1
5
- Tested up to: 4.8.1
6
- Stable tag: 1.4.11
7
  Requires PHP: 5.3.0
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -101,14 +101,18 @@ Amazon Product Advertising API credentials are not required to use the feature t
101
 
102
  == Changelog ==
103
 
 
 
 
 
104
  = 1.4.11 - October 16, 2017 =
105
  * Plugin is now available in Spanish, French and Italian languages.
106
 
107
- = 1.4.10 - Septmeber 13, 2017 =
108
  * Fix: Customize theme option is not working for few users after v1.4.8.
109
  * Fix: Page alignment distorted for some users after v1.4.9.
110
 
111
- = 1.4.9 - Septmeber 4, 2017 =
112
  * Putting strings under translation function for Internationalization.
113
  * Fix: Product Grid not aligned properly on iOS devices.
114
  * Fix: Product Ad breaks the text on the right side on few mobile devices.
@@ -189,6 +193,9 @@ Amazon Product Advertising API credentials are not required to use the feature t
189
 
190
  == Upgrade Notice ==
191
 
 
 
 
192
  = 1.4.11 =
193
  Plugin is now available in Spanish, French and Italian languages.
194
 
2
  Contributors: amazonlinkbuilder
3
  Tags: Amazon, Affiliate, Associates, Amazon Associates, Amazon Associate, Product Advertising API, Amazon API, Amazon Link, Amazon Ad, Amazon Affiliate, eCommerce
4
  Requires at least: 3.0.1
5
+ Tested up to: 4.8.2
6
+ Stable tag: 1.4.12
7
  Requires PHP: 5.3.0
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
101
 
102
  == Changelog ==
103
 
104
+ = 1.4.12 - October 31, 2017 =
105
+ * **Revamped Settings Page:** Tracking IDs are now associated with Marketplaces in the new settings page. If you are upgrading from a previous version of the plugin, all existing tracking ids have been associated with your default marketplace. Please review and configure available marketplaces and tracking ids from the revamped settings page.
106
+ * Add shortcode popup now respects available marketplaces and tracking id associations configured in the revamped settings page.
107
+
108
  = 1.4.11 - October 16, 2017 =
109
  * Plugin is now available in Spanish, French and Italian languages.
110
 
111
+ = 1.4.10 - September 13, 2017 =
112
  * Fix: Customize theme option is not working for few users after v1.4.8.
113
  * Fix: Page alignment distorted for some users after v1.4.9.
114
 
115
+ = 1.4.9 - September 4, 2017 =
116
  * Putting strings under translation function for Internationalization.
117
  * Fix: Product Grid not aligned properly on iOS devices.
118
  * Fix: Product Ad breaks the text on the right side on few mobile devices.
193
 
194
  == Upgrade Notice ==
195
 
196
+ = 1.4.12 =
197
+ Tracking IDs are associated with marketplaces in the revamped settings page and add shortcode popup.
198
+
199
  = 1.4.11 =
200
  Plugin is now available in Spanish, French and Italian languages.
201