Version Description
Download this release
Release Info
Developer | amazonlinkbuilder |
Plugin | Amazon Associates Link Builder |
Version | 1.3.4 |
Comparing to | |
See all releases |
Code changes from version 1.3.2 to 1.3.4
- aalb_config.php +5 -2
- admin/aalb_admin.php +26 -8
- admin/js/aalb_admin.js +58 -15
- admin/sidebar/partials/aalb_about.php +1 -1
- admin/sidebar/partials/aalb_credentials.php +1 -1
- admin/sidebar/partials/aalb_templates.php +1 -1
- amazon-associates-link-builder.php +1 -1
- includes/aalb_manager.php +3 -1
- includes/aalb_template_engine.php +0 -2
- lib/php/Paapi/aalb_paapi_helper.php +0 -2
- lib/php/aalb_tracking_api_helper.php +6 -1
- lib/php/aalb_xml_helper.php +10 -14
- readme.txt +13 -6
- shortcode/aalb_shortcode.php +12 -157
- shortcode/aalb_shortcode_helper.php +176 -0
- shortcode/aalb_shortcode_loader.php +37 -8
- shortcode/aalb_shortcode_text.php +102 -0
- template/ProductLink.css +0 -0
- template/ProductLink.mustache +7 -0
aalb_config.php
CHANGED
@@ -13,7 +13,7 @@ and limitations under the License.
|
|
13 |
*/
|
14 |
|
15 |
//version
|
16 |
-
define('AALB_PLUGIN_CURRENT_VERSION','1.3.
|
17 |
|
18 |
//paths
|
19 |
define('AALB_PLUGIN_DIR', plugin_dir_path( __FILE__ ));
|
@@ -35,10 +35,13 @@ define('AALB_TRACKING_API_HELPER_PHP', AALB_PLUGIN_DIR .'lib/php/aalb_tracking_a
|
|
35 |
|
36 |
//Shortcode
|
37 |
define('AALB_SHORTCODE_PHP', AALB_PLUGIN_DIR .'shortcode/aalb_shortcode.php');
|
|
|
38 |
define('AALB_SHORTCODE_LOADER', AALB_PLUGIN_DIR . 'shortcode/aalb_shortcode_loader.php');
|
|
|
39 |
|
40 |
//Shortcodes supported
|
41 |
define('AALB_SHORTCODE_AMAZON_LINK', 'amazon_link');
|
|
|
42 |
|
43 |
//Admin
|
44 |
define('AALB_SIDEBAR_PHP', AALB_PLUGIN_DIR .'admin/sidebar/aalb_sidebar.php');
|
@@ -132,7 +135,7 @@ define('AALB_ADMIN_ICON', AALB_SECURE_HOSTNAME . AALB_ADMIN_ICON_LOCATION);
|
|
132 |
//Search result items. Paapi returns 10 items by default.
|
133 |
define('AALB_MAX_SEARCH_RESULT_ITEMS', 9);
|
134 |
//List of Default Amazon Template names
|
135 |
-
define('AALB_AMAZON_TEMPLATE_NAMES', 'ProductCarousel,ProductGrid,ProductAd,PriceLink');
|
136 |
|
137 |
//Database keys
|
138 |
define('AALB_TEMPLATE_NAMES', 'aalb_template_names');
|
13 |
*/
|
14 |
|
15 |
//version
|
16 |
+
define('AALB_PLUGIN_CURRENT_VERSION','1.3.4');
|
17 |
|
18 |
//paths
|
19 |
define('AALB_PLUGIN_DIR', plugin_dir_path( __FILE__ ));
|
35 |
|
36 |
//Shortcode
|
37 |
define('AALB_SHORTCODE_PHP', AALB_PLUGIN_DIR .'shortcode/aalb_shortcode.php');
|
38 |
+
define('AALB_SHORTCODE_TEXT_PHP', AALB_PLUGIN_DIR .'shortcode/aalb_shortcode_text.php');
|
39 |
define('AALB_SHORTCODE_LOADER', AALB_PLUGIN_DIR . 'shortcode/aalb_shortcode_loader.php');
|
40 |
+
define('AALB_SHORTCODE_HELPER', AALB_PLUGIN_DIR . 'shortcode/aalb_shortcode_helper.php');
|
41 |
|
42 |
//Shortcodes supported
|
43 |
define('AALB_SHORTCODE_AMAZON_LINK', 'amazon_link');
|
44 |
+
define('AALB_SHORTCODE_AMAZON_TEXT', 'amazon_textlink');
|
45 |
|
46 |
//Admin
|
47 |
define('AALB_SIDEBAR_PHP', AALB_PLUGIN_DIR .'admin/sidebar/aalb_sidebar.php');
|
135 |
//Search result items. Paapi returns 10 items by default.
|
136 |
define('AALB_MAX_SEARCH_RESULT_ITEMS', 9);
|
137 |
//List of Default Amazon Template names
|
138 |
+
define('AALB_AMAZON_TEMPLATE_NAMES', 'ProductCarousel,ProductGrid,ProductAd,PriceLink,ProductLink');
|
139 |
|
140 |
//Database keys
|
141 |
define('AALB_TEMPLATE_NAMES', 'aalb_template_names');
|
admin/aalb_admin.php
CHANGED
@@ -96,7 +96,8 @@ class Aalb_Admin {
|
|
96 |
'ajax_url' => admin_url('admin-ajax.php'),
|
97 |
'action' => 'get_item_search_result',
|
98 |
'item_search_nonce' => wp_create_nonce('aalb-item-search-nonce'),
|
99 |
-
'AALB_SHORTCODE_AMAZON_LINK' => AALB_SHORTCODE_AMAZON_LINK
|
|
|
100 |
);
|
101 |
}
|
102 |
|
@@ -107,6 +108,10 @@ class Aalb_Admin {
|
|
107 |
* @since 1.3
|
108 |
*/
|
109 |
public function handle_plugin_update() {
|
|
|
|
|
|
|
|
|
110 |
global $wp_filesystem;
|
111 |
$this->helper->aalb_initialize_wp_filesystem_api();
|
112 |
$this->helper->refresh_template_list();
|
@@ -197,13 +202,26 @@ class Aalb_Admin {
|
|
197 |
public function get_custom_template_content() {
|
198 |
global $wp_filesystem;
|
199 |
$this->helper->aalb_initialize_wp_filesystem_api();
|
200 |
-
$
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
wp_die();
|
208 |
}
|
209 |
}
|
96 |
'ajax_url' => admin_url('admin-ajax.php'),
|
97 |
'action' => 'get_item_search_result',
|
98 |
'item_search_nonce' => wp_create_nonce('aalb-item-search-nonce'),
|
99 |
+
'AALB_SHORTCODE_AMAZON_LINK' => AALB_SHORTCODE_AMAZON_LINK,
|
100 |
+
'AALB_SHORTCODE_AMAZON_TEXT' => AALB_SHORTCODE_AMAZON_TEXT
|
101 |
);
|
102 |
}
|
103 |
|
108 |
* @since 1.3
|
109 |
*/
|
110 |
public function handle_plugin_update() {
|
111 |
+
//Clear all transients for price changes to reflect
|
112 |
+
$this->helper->clear_cache_for_substring('');
|
113 |
+
$this->helper->clear_expired_transients();
|
114 |
+
|
115 |
global $wp_filesystem;
|
116 |
$this->helper->aalb_initialize_wp_filesystem_api();
|
117 |
$this->helper->refresh_template_list();
|
202 |
public function get_custom_template_content() {
|
203 |
global $wp_filesystem;
|
204 |
$this->helper->aalb_initialize_wp_filesystem_api();
|
205 |
+
$base_path = $this->helper->get_template_upload_directory();
|
206 |
+
if(current_user_can('edit_posts')) {
|
207 |
+
$css_file = $_POST['css'];
|
208 |
+
$real_css_file = realpath($css_file);
|
209 |
+
$mustache_file = $_POST['mustache'];
|
210 |
+
$real_mustache_file = realpath($mustache_file);
|
211 |
+
if ($real_css_file === false || $real_mustache_file === false || strpos($real_css_file, $base_path) !== 0 || strpos($real_mustache_file, $base_path) !== 0) {
|
212 |
+
//If base path is not a prefix of the realpath, this means that a directry traversal was attempted
|
213 |
+
die('Not authorised to make request template content or Directory Traversal Attempted.');
|
214 |
+
} else {
|
215 |
+
//No vulnerability. Get file contents.
|
216 |
+
$css_file_content = $wp_filesystem->get_contents($css_file);
|
217 |
+
$mustache_file_content = $wp_filesystem->get_contents($mustache_file);
|
218 |
+
|
219 |
+
$response = array("css" => $css_file_content, "mustache" => $mustache_file_content);
|
220 |
+
echo json_encode($response);
|
221 |
+
}
|
222 |
+
} else {
|
223 |
+
die('Not authorised to make request');
|
224 |
+
}
|
225 |
wp_die();
|
226 |
}
|
227 |
}
|
admin/js/aalb_admin.js
CHANGED
@@ -14,7 +14,8 @@ 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 |
|
19 |
jQuery(document).ready(function() {
|
20 |
// http://stackoverflow.com/questions/5557641/how-can-i-reset-div-to-its-original-state-after-it-has-been-modified-by-java
|
@@ -84,8 +85,20 @@ function aalb_remove_selected_item(element) {
|
|
84 |
function aalb_admin_show_create_shortcode_popup() {
|
85 |
// http://stackoverflow.com/questions/5557641/how-can-i-reset-div-to-its-original-state-after-it-has-been-modified-by-java
|
86 |
jQuery("#aalb-admin-popup-content").html(jQuery("#aalb-admin-popup-content").data('old-state'));
|
|
|
87 |
var keywords = jQuery("#aalb-admin-input-search").val();
|
88 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
// Showing the TB and resetting the width - http://wordpress.stackexchange.com/questions/114107/thickbox-width-cant-be-changed-in-admin
|
90 |
tb_show('Add Amazon Associates Link Builder Shortcode', '#TB_inline?inlineId=aalb-admin-popup-container',false);
|
91 |
resize_thickbox();
|
@@ -93,9 +106,8 @@ function aalb_admin_show_create_shortcode_popup() {
|
|
93 |
// Getting the ItemSearch results
|
94 |
aalb_admin_get_item_search_items(jQuery("#aalb-admin-input-search").val());
|
95 |
jQuery("#aalb-admin-popup-input-search").attr('value',keywords);
|
96 |
-
|
97 |
} else {
|
98 |
-
alert("Please enter the keywords");
|
99 |
jQuery("#aalb-admin-input-search").focus();
|
100 |
}
|
101 |
|
@@ -179,10 +191,22 @@ function aalb_admin_get_item_search_items(keywords) {
|
|
179 |
});
|
180 |
jQuery("#aalb-add-shortcode-button").unbind().click(function(){
|
181 |
var selectedAsins=aalb_get_selected_asins();
|
|
|
182 |
if(selectedAsins){
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
alert("Please select atleast one product for display");
|
187 |
}
|
188 |
});
|
@@ -195,12 +219,12 @@ function aalb_admin_get_item_search_items(keywords) {
|
|
195 |
*/
|
196 |
function aalb_add_shortcode(shortcodeName) {
|
197 |
var shortcodeJson;
|
|
|
|
|
|
|
|
|
|
|
198 |
if(shortcodeName == AALB_SHORTCODE_AMAZON_LINK) {
|
199 |
-
var selectedAsins=aalb_get_selected_asins();
|
200 |
-
var selectedTemplate=aalb_get_selected_template();
|
201 |
-
var selectedStore=aalb_get_selected_store();
|
202 |
-
var selectedMarketplace=aalb_get_selected_marketplace_abbreviation();
|
203 |
-
|
204 |
shortcodeJson = {
|
205 |
"name" : AALB_SHORTCODE_AMAZON_LINK,
|
206 |
"params" : {
|
@@ -210,12 +234,22 @@ function aalb_add_shortcode(shortcodeName) {
|
|
210 |
"marketplace" : selectedMarketplace,
|
211 |
}
|
212 |
};
|
213 |
-
|
214 |
-
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
console.log("Invalid Shortcode provided!");
|
217 |
return;
|
218 |
}
|
|
|
219 |
}
|
220 |
|
221 |
/**
|
@@ -334,3 +368,12 @@ function aalb_get_selected_marketplace_abbreviation() {
|
|
334 |
}
|
335 |
return selectedMarketplace;
|
336 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
20 |
jQuery(document).ready(function() {
|
21 |
// http://stackoverflow.com/questions/5557641/how-can-i-reset-div-to-its-original-state-after-it-has-been-modified-by-java
|
85 |
function aalb_admin_show_create_shortcode_popup() {
|
86 |
// http://stackoverflow.com/questions/5557641/how-can-i-reset-div-to-its-original-state-after-it-has-been-modified-by-java
|
87 |
jQuery("#aalb-admin-popup-content").html(jQuery("#aalb-admin-popup-content").data('old-state'));
|
88 |
+
var selected = aalb_get_selected_text_from_editor();
|
89 |
var keywords = jQuery("#aalb-admin-input-search").val();
|
90 |
+
if (selected) {
|
91 |
+
tb_show('Add Amazon Associates Link Builder Shortcode', '#TB_inline?inlineId=aalb-admin-popup-container',false);
|
92 |
+
resize_thickbox();
|
93 |
+
|
94 |
+
//Setting Search field with selected value.
|
95 |
+
jQuery("#aalb-admin-input-search").attr('value',selected);
|
96 |
+
// Getting the ItemSearch results
|
97 |
+
aalb_admin_get_item_search_items(jQuery("#aalb-admin-input-search").val());
|
98 |
+
jQuery("#aalb-admin-popup-input-search").attr('value',selected);
|
99 |
+
//Chose ProductLink template By Default when some text is selected.
|
100 |
+
jQuery("#aalb_template_names_list").val('ProductLink');
|
101 |
+
} else if (keywords) {
|
102 |
// Showing the TB and resetting the width - http://wordpress.stackexchange.com/questions/114107/thickbox-width-cant-be-changed-in-admin
|
103 |
tb_show('Add Amazon Associates Link Builder Shortcode', '#TB_inline?inlineId=aalb-admin-popup-container',false);
|
104 |
resize_thickbox();
|
106 |
// Getting the ItemSearch results
|
107 |
aalb_admin_get_item_search_items(jQuery("#aalb-admin-input-search").val());
|
108 |
jQuery("#aalb-admin-popup-input-search").attr('value',keywords);
|
|
|
109 |
} else {
|
110 |
+
alert("Please enter the keywords or select some text from the editor.");
|
111 |
jQuery("#aalb-admin-input-search").focus();
|
112 |
}
|
113 |
|
191 |
});
|
192 |
jQuery("#aalb-add-shortcode-button").unbind().click(function(){
|
193 |
var selectedAsins=aalb_get_selected_asins();
|
194 |
+
var selected = aalb_get_selected_text_from_editor();
|
195 |
if(selectedAsins){
|
196 |
+
if(selected) {
|
197 |
+
/* If there was some text selected in the wordpress post editor. Implies amazon_textlink */
|
198 |
+
var selectedAsinsLength = selectedAsins.split(",").length;
|
199 |
+
if(selectedAsinsLength > 1) {
|
200 |
+
alert("Failed to create Text Link shortcode. Editor has some text selected. Only one item can be selected while adding text links");
|
201 |
+
} else {
|
202 |
+
jQuery("#aalb-add-shortcode-alert").fadeTo("fast",1);
|
203 |
+
aalb_add_shortcode(AALB_SHORTCODE_AMAZON_TEXT);
|
204 |
+
}
|
205 |
+
} else {
|
206 |
+
jQuery("#aalb-add-shortcode-alert").fadeTo("fast",1);
|
207 |
+
aalb_add_shortcode(AALB_SHORTCODE_AMAZON_LINK);
|
208 |
+
}
|
209 |
+
} else {
|
210 |
alert("Please select atleast one product for display");
|
211 |
}
|
212 |
});
|
219 |
*/
|
220 |
function aalb_add_shortcode(shortcodeName) {
|
221 |
var shortcodeJson;
|
222 |
+
var selectedAsins=aalb_get_selected_asins();
|
223 |
+
var selectedTemplate=aalb_get_selected_template();
|
224 |
+
var selectedStore=aalb_get_selected_store();
|
225 |
+
var selectedMarketplace=aalb_get_selected_marketplace_abbreviation();
|
226 |
+
|
227 |
if(shortcodeName == AALB_SHORTCODE_AMAZON_LINK) {
|
|
|
|
|
|
|
|
|
|
|
228 |
shortcodeJson = {
|
229 |
"name" : AALB_SHORTCODE_AMAZON_LINK,
|
230 |
"params" : {
|
234 |
"marketplace" : selectedMarketplace,
|
235 |
}
|
236 |
};
|
237 |
+
} else if (shortcodeName == AALB_SHORTCODE_AMAZON_TEXT) {
|
238 |
+
shortcodeJson = {
|
239 |
+
"name" : AALB_SHORTCODE_AMAZON_TEXT,
|
240 |
+
"params" : {
|
241 |
+
"asin" : selectedAsins,
|
242 |
+
"text" : aalb_get_selected_text_from_editor(),
|
243 |
+
"template" : selectedTemplate,
|
244 |
+
"store" : selectedStore,
|
245 |
+
"marketplace" : selectedMarketplace,
|
246 |
+
}
|
247 |
+
};
|
248 |
+
} else {
|
249 |
console.log("Invalid Shortcode provided!");
|
250 |
return;
|
251 |
}
|
252 |
+
aalb_get_link_id(shortcodeJson);
|
253 |
}
|
254 |
|
255 |
/**
|
368 |
}
|
369 |
return selectedMarketplace;
|
370 |
}
|
371 |
+
|
372 |
+
/**
|
373 |
+
* Get selected text from the editor.
|
374 |
+
*
|
375 |
+
* @return String Selected text from the wordpress post editor.
|
376 |
+
*/
|
377 |
+
function aalb_get_selected_text_from_editor() {
|
378 |
+
return tinyMCE.activeEditor.selection.getContent({format : "text"});
|
379 |
+
}
|
admin/sidebar/partials/aalb_about.php
CHANGED
@@ -27,7 +27,7 @@ include 'aalb_admin_ui_common.php'; ?>
|
|
27 |
<b>Note</b>
|
28 |
<ul>
|
29 |
<li>
|
30 |
-
You must review and accept the Amazon Associates Link Builder
|
31 |
</li>
|
32 |
<li>
|
33 |
The plugin is currently in beta form. We intend to regularly add new features and enhancements throughout the beta period and beyond, and welcome your feedback and input.
|
27 |
<b>Note</b>
|
28 |
<ul>
|
29 |
<li>
|
30 |
+
You must review and accept the Amazon Associates Link Builder <a href="https://s3.amazonaws.com/aalb-public-resources/documents/AssociatesLinkBuilder-ConditionsOfUse-2017-01-17.pdf" target="_blank">Conditions of Use</a>.
|
31 |
</li>
|
32 |
<li>
|
33 |
The plugin is currently in beta form. We intend to regularly add new features and enhancements throughout the beta period and beyond, and welcome your feedback and input.
|
admin/sidebar/partials/aalb_credentials.php
CHANGED
@@ -106,7 +106,7 @@ wp_localize_script('aalb_credentials_js', 'wp_opt', array('plugin_url' => AALB_P
|
|
106 |
<input id="aalb-terms-checkbox" type="checkbox" name="demo-checkbox" value="1" />
|
107 |
</th>
|
108 |
<td style="vertical-align:middle;">
|
109 |
-
Check here to indicate that you have read and agree to the Amazon Associates Link Builder
|
110 |
</td>
|
111 |
</tr>
|
112 |
</table>
|
106 |
<input id="aalb-terms-checkbox" type="checkbox" name="demo-checkbox" value="1" />
|
107 |
</th>
|
108 |
<td style="vertical-align:middle;">
|
109 |
+
Check here to indicate that you have read and agree to the Amazon Associates Link Builder <a href="https://s3.amazonaws.com/aalb-public-resources/documents/AssociatesLinkBuilder-ConditionsOfUse-2017-01-17.pdf" target="_blank">Conditions of Use</a>.
|
110 |
</td>
|
111 |
</tr>
|
112 |
</table>
|
admin/sidebar/partials/aalb_templates.php
CHANGED
@@ -203,7 +203,7 @@ wp_localize_script('aalb_template_js', 'wp_opt', array('ajax_url' => admin_url('
|
|
203 |
<?php
|
204 |
foreach ($aalb_template_names as $aalb_template) {
|
205 |
?>
|
206 |
-
<option value="<?=$aalb_template?>" <?php $saveFailed===false ? selected($aalb_template, $aalb_template_name) : selected($aalb_template, "") ?>><?=$aalb_template?></option>
|
207 |
<?php
|
208 |
}
|
209 |
?>
|
203 |
<?php
|
204 |
foreach ($aalb_template_names as $aalb_template) {
|
205 |
?>
|
206 |
+
<option value="<?=$aalb_template?>" <?php $saveFailed===false ? selected($aalb_template, (isset($aalb_template_name))?$aalb_template_name:'') : selected($aalb_template, "") ?>><?=$aalb_template?></option>
|
207 |
<?php
|
208 |
}
|
209 |
?>
|
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.3.
|
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.3.4
|
11 |
Author: Amazon Associates Program
|
12 |
Author URI: https://affiliate-program.amazon.com/
|
13 |
License: GPLv2
|
includes/aalb_manager.php
CHANGED
@@ -62,8 +62,10 @@ class Aalb_Manager {
|
|
62 |
* @since 1.0.0
|
63 |
*/
|
64 |
private function register_shortcode_hooks() {
|
65 |
-
$aalb_shortcode = $this->shortcode_loader->
|
|
|
66 |
$this->hook_loader->add_action('wp_enqueue_scripts', $aalb_shortcode, 'enqueue_styles');
|
|
|
67 |
}
|
68 |
|
69 |
/**
|
62 |
* @since 1.0.0
|
63 |
*/
|
64 |
private function register_shortcode_hooks() {
|
65 |
+
$aalb_shortcode = $this->shortcode_loader->get_amazon_link_shortcode();
|
66 |
+
$aalb_shortcode_text = $this->shortcode_loader->get_amazon_textlink_shortcode();
|
67 |
$this->hook_loader->add_action('wp_enqueue_scripts', $aalb_shortcode, 'enqueue_styles');
|
68 |
+
$this->hook_loader->add_action('wp_enqueue_scripts', $aalb_shortcode_text, 'enqueue_styles');
|
69 |
}
|
70 |
|
71 |
/**
|
includes/aalb_template_engine.php
CHANGED
@@ -54,8 +54,6 @@ class Aalb_Template_Engine {
|
|
54 |
$xml = $this->parse($products);
|
55 |
$items = $this->get_items($xml);
|
56 |
|
57 |
-
//Add Click URL Prefix to required hyperlinks
|
58 |
-
$items = $this->xml_helper->prefix_click_URL($items);
|
59 |
//Add custom nodes to the XML
|
60 |
$custom_items = $this->xml_helper->add_custom_nodes($items, $marketplace);
|
61 |
|
54 |
$xml = $this->parse($products);
|
55 |
$items = $this->get_items($xml);
|
56 |
|
|
|
|
|
57 |
//Add custom nodes to the XML
|
58 |
$custom_items = $this->xml_helper->add_custom_nodes($items, $marketplace);
|
59 |
|
lib/php/Paapi/aalb_paapi_helper.php
CHANGED
@@ -76,7 +76,6 @@ class Aalb_Paapi_Helper {
|
|
76 |
"ItemId" => "$asin",
|
77 |
"IdType" => "ASIN",
|
78 |
"ResponseGroup" => "Images,ItemAttributes,OfferFull",
|
79 |
-
"Condition" => "New",
|
80 |
"AssociateTag" => "$tracking_id",
|
81 |
);
|
82 |
$url = $this->aws_signed_url ($params,$marketplace);
|
@@ -97,7 +96,6 @@ class Aalb_Paapi_Helper {
|
|
97 |
"SearchIndex" => "All",
|
98 |
"Keywords" => "$search_keywords",
|
99 |
"ResponseGroup" => "Images,ItemAttributes,Offers",
|
100 |
-
"Condition" => "New",
|
101 |
"AssociateTag" => "$tracking_id",
|
102 |
);
|
103 |
$url = $this->aws_signed_url ($params, $marketplace);
|
76 |
"ItemId" => "$asin",
|
77 |
"IdType" => "ASIN",
|
78 |
"ResponseGroup" => "Images,ItemAttributes,OfferFull",
|
|
|
79 |
"AssociateTag" => "$tracking_id",
|
80 |
);
|
81 |
$url = $this->aws_signed_url ($params,$marketplace);
|
96 |
"SearchIndex" => "All",
|
97 |
"Keywords" => "$search_keywords",
|
98 |
"ResponseGroup" => "Images,ItemAttributes,Offers",
|
|
|
99 |
"AssociateTag" => "$tracking_id",
|
100 |
);
|
101 |
$url = $this->aws_signed_url ($params, $marketplace);
|
lib/php/aalb_tracking_api_helper.php
CHANGED
@@ -74,6 +74,7 @@ class Aalb_Tracking_Api_Helper {
|
|
74 |
|
75 |
/**
|
76 |
* Returns the response of the impressions API for a given link-id
|
|
|
77 |
*
|
78 |
* @since 1.0.0
|
79 |
* @param string $link_id Link ID for which impression parameters are required
|
@@ -95,6 +96,7 @@ class Aalb_Tracking_Api_Helper {
|
|
95 |
|
96 |
/**
|
97 |
* Returns the click URL by parsing the recieved getImpressions API Response
|
|
|
98 |
*
|
99 |
* @since 1.0.0
|
100 |
* @param json string $impression_params JSON Response from the get impressions API for a link-id
|
@@ -107,6 +109,7 @@ class Aalb_Tracking_Api_Helper {
|
|
107 |
|
108 |
/**
|
109 |
* Echoes an invisible img with src=pixel-url to fire the pixels
|
|
|
110 |
*
|
111 |
* @since 1.0.0
|
112 |
* @param json string $impression_params JSON Response from the get impressions API for a link-id
|
@@ -114,7 +117,9 @@ class Aalb_Tracking_Api_Helper {
|
|
114 |
public function insert_pixel($impression_params) {
|
115 |
$body = json_decode($impression_params,true);
|
116 |
$pixel_url = $body["pixel-url"];
|
117 |
-
|
|
|
|
|
118 |
}
|
119 |
}
|
120 |
|
74 |
|
75 |
/**
|
76 |
* Returns the response of the impressions API for a given link-id
|
77 |
+
* TODO: Not used post v1.4. Impression tracking plugged out for re-vamping purposes.
|
78 |
*
|
79 |
* @since 1.0.0
|
80 |
* @param string $link_id Link ID for which impression parameters are required
|
96 |
|
97 |
/**
|
98 |
* Returns the click URL by parsing the recieved getImpressions API Response
|
99 |
+
* TODO: Not used post v1.4. Impression Tracking plugged out for re-vamping purposes.
|
100 |
*
|
101 |
* @since 1.0.0
|
102 |
* @param json string $impression_params JSON Response from the get impressions API for a link-id
|
109 |
|
110 |
/**
|
111 |
* Echoes an invisible img with src=pixel-url to fire the pixels
|
112 |
+
* TODO: Not used post v1.4. Impression Tracking plugged out for re-vamping purposes.
|
113 |
*
|
114 |
* @since 1.0.0
|
115 |
* @param json string $impression_params JSON Response from the get impressions API for a link-id
|
117 |
public function insert_pixel($impression_params) {
|
118 |
$body = json_decode($impression_params,true);
|
119 |
$pixel_url = $body["pixel-url"];
|
120 |
+
if(!is_amp_endpoint()) {
|
121 |
+
echo '<img src="' . $pixel_url . '" style="display:none"></img>';
|
122 |
+
}
|
123 |
}
|
124 |
}
|
125 |
|
lib/php/aalb_xml_helper.php
CHANGED
@@ -172,21 +172,16 @@ class Aalb_Xml_Helper {
|
|
172 |
//If Sale Price is returned
|
173 |
$aalb_node->CurrentPrice = $sale_price;
|
174 |
$aalb_node->CurrentPriceValue = $sale_price_amount;
|
175 |
-
$aalb_node->
|
176 |
-
|
|
|
|
|
177 |
} else {
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
$aalb_node->
|
182 |
-
|
183 |
-
$aalb_node->CurrentPrice = $price;
|
184 |
-
$aalb_node->CurrentPriceValue = $price_amount;
|
185 |
-
//Add StrikePrice node only if there is a difference with CurrentPrice amount
|
186 |
-
if((int)$list_price_amount > (int)$price_amount) {
|
187 |
-
$aalb_node->StrikePrice = $list_price;
|
188 |
-
$aalb_node->StrikePriceValue = $list_price_amount;
|
189 |
-
}
|
190 |
}
|
191 |
}
|
192 |
return $aalb_node;
|
@@ -230,6 +225,7 @@ class Aalb_Xml_Helper {
|
|
230 |
|
231 |
/**
|
232 |
* Adds Click URL Prefix to requierd hyperlinks
|
|
|
233 |
*
|
234 |
* @since 1.0.0
|
235 |
* @param SimpleXMLElement $items Well formed XML String
|
172 |
//If Sale Price is returned
|
173 |
$aalb_node->CurrentPrice = $sale_price;
|
174 |
$aalb_node->CurrentPriceValue = $sale_price_amount;
|
175 |
+
if ((int)$aalb_node->SavingPercent > 1) {
|
176 |
+
$aalb_node->StrikePrice = $price;
|
177 |
+
$aalb_node->StrikePriceValue = $price_amount;
|
178 |
+
}
|
179 |
} else {
|
180 |
+
$aalb_node->CurrentPrice = $price;
|
181 |
+
$aalb_node->CurrentPriceValue = $price_amount;
|
182 |
+
if ((int)$aalb_node->SavingPercent > 1) {
|
183 |
+
$aalb_node->StrikePrice = $list_price;
|
184 |
+
$aalb_node->StrikePriceValue = $list_price_amount;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
}
|
186 |
}
|
187 |
return $aalb_node;
|
225 |
|
226 |
/**
|
227 |
* Adds Click URL Prefix to requierd hyperlinks
|
228 |
+
* TODO: Not used post v1.4. Impression Tracking plugged out for re-vamping purposes.
|
229 |
*
|
230 |
* @since 1.0.0
|
231 |
* @param SimpleXMLElement $items Well formed XML String
|
readme.txt
CHANGED
@@ -17,7 +17,7 @@ The Amazon Associates Program is one of the original affiliate marketing program
|
|
17 |
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.
|
18 |
|
19 |
= Note =
|
20 |
-
* You must review and accept the Amazon Associates Link Builder Conditions of Use
|
21 |
* The plugin is currently in beta form. We intend to regularly add new features and enhancements throughout the beta period and beyond, and welcome your feedback and input.
|
22 |
|
23 |
== Installation ==
|
@@ -88,7 +88,14 @@ You can search products using keywords in any supported country, but you have to
|
|
88 |
|
89 |
== Changelog ==
|
90 |
|
91 |
-
= 1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
* If you are coming from any version other than v1.3 and are using custom templates, be sure to backup your custom templates before updating the plugin by following [these instructions](https://s3.amazonaws.com/aalb-public-resources/documents/AssociatesLinkBuilder-Guide-HowToBackupCustomTemplates.pdf). If you have not created any custom template or if you are coming from v1.3, you can simply update the plugin using the update now link.
|
93 |
* Fix: Problems with rendering ads when using custom templates.
|
94 |
|
@@ -114,11 +121,11 @@ You can search products using keywords in any supported country, but you have to
|
|
114 |
|
115 |
== Upgrade Notice ==
|
116 |
|
|
|
|
|
|
|
117 |
= 1.3.2 =
|
118 |
This update fixes the issue with improper rendering of ads using custom templates. If you are coming from v1.3, you don't need to take a backup of your templates before updating to v1.3.2.
|
119 |
|
120 |
= 1.3 =
|
121 |
-
This update includes a few minor fixes. In particular, you will no longer need to back up your custom templates when updating the plugin in future.
|
122 |
-
|
123 |
-
= 1.2 =
|
124 |
-
You will no longer get PHP syntax issues while activating the plugin. Take a backup of your custom templates before updating the plugin.
|
17 |
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.
|
18 |
|
19 |
= Note =
|
20 |
+
* You must review and accept the Amazon Associates Link Builder [Conditions of Use](https://s3.amazonaws.com/aalb-public-resources/documents/AssociatesLinkBuilder-ConditionsOfUse-2017-01-17.pdf).
|
21 |
* The plugin is currently in beta form. We intend to regularly add new features and enhancements throughout the beta period and beyond, and welcome your feedback and input.
|
22 |
|
23 |
== Installation ==
|
88 |
|
89 |
== Changelog ==
|
90 |
|
91 |
+
= 1.4 - January 17, 2017 =
|
92 |
+
* Conditions of Use have been updated with a worldwide version. Please review the updated [Conditions of Use](https://s3.amazonaws.com/aalb-public-resources/documents/AssociatesLinkBuilder-ConditionsOfUse-2017-01-17.pdf) for the terms which are applicable to your use.
|
93 |
+
* Enhancement: Now, you can create text links to Amazon products using amazon_textlink short code. Check [reference guide](https://s3.amazonaws.com/aalb-public-resources/documents/AssociatesLinkBuilder-Guide-HowToCreateTextLinks.pdf) for more details.
|
94 |
+
* Fix: Display Amazon [buy box](https://www.amazon.com/gp/help/customer/display.html?nodeId=200401830) price.
|
95 |
+
* General improvements to reduce the loading time of the links/ ad units created via the plugin.
|
96 |
+
* Updated [plugin user guide](https://s3.amazonaws.com/aalb-public-resources/documents/AssociatesLinkBuilder-UserGuide.pdf).
|
97 |
+
|
98 |
+
= 1.3.2 - December 30, 2016 =
|
99 |
* If you are coming from any version other than v1.3 and are using custom templates, be sure to backup your custom templates before updating the plugin by following [these instructions](https://s3.amazonaws.com/aalb-public-resources/documents/AssociatesLinkBuilder-Guide-HowToBackupCustomTemplates.pdf). If you have not created any custom template or if you are coming from v1.3, you can simply update the plugin using the update now link.
|
100 |
* Fix: Problems with rendering ads when using custom templates.
|
101 |
|
121 |
|
122 |
== Upgrade Notice ==
|
123 |
|
124 |
+
= 1.4 =
|
125 |
+
This update includes general performance improvements, and support for text links.
|
126 |
+
|
127 |
= 1.3.2 =
|
128 |
This update fixes the issue with improper rendering of ads using custom templates. If you are coming from v1.3, you don't need to take a backup of your templates before updating to v1.3.2.
|
129 |
|
130 |
= 1.3 =
|
131 |
+
This update includes a few minor fixes. In particular, you will no longer need to back up your custom templates when updating the plugin in future.
|
|
|
|
|
|
shortcode/aalb_shortcode.php
CHANGED
@@ -13,7 +13,7 @@ and limitations under the License.
|
|
13 |
*/
|
14 |
|
15 |
/**
|
16 |
-
* Fired when a shortcode is there in the post page.
|
17 |
*
|
18 |
* Gets the product information by making a Paapi request and renders the HTML
|
19 |
*
|
@@ -27,17 +27,15 @@ class Aalb_Shortcode {
|
|
27 |
protected $paapi_helper;
|
28 |
protected $template_engine;
|
29 |
protected $helper;
|
30 |
-
protected $config_loader;
|
31 |
-
protected $validation_helper;
|
32 |
protected $tracking_api_helper;
|
|
|
33 |
|
34 |
public function __construct() {
|
35 |
$this->template_engine = new Aalb_Template_Engine();
|
36 |
$this->paapi_helper = new Aalb_Paapi_Helper();
|
37 |
$this->helper = new Aalb_Helper();
|
38 |
-
$this->config_loader = new Aalb_Config_Loader();
|
39 |
-
$this->validation_helper = new Aalb_Validation_Helper();
|
40 |
$this->tracking_api_helper = new Aalb_Tracking_Api_Helper();
|
|
|
41 |
}
|
42 |
|
43 |
/**
|
@@ -49,21 +47,6 @@ class Aalb_Shortcode {
|
|
49 |
wp_enqueue_style('aalb_basics_css', AALB_BASICS_CSS );
|
50 |
}
|
51 |
|
52 |
-
/**
|
53 |
-
* Add CSS for the template
|
54 |
-
*
|
55 |
-
* @since 1.0.0
|
56 |
-
*/
|
57 |
-
public function enqueue_template_styles($template_name) {
|
58 |
-
$aalb_default_templates = explode(",", AALB_AMAZON_TEMPLATE_NAMES);
|
59 |
-
if(in_array($template_name, $aalb_default_templates)) {
|
60 |
-
wp_enqueue_style('aalb_template' . $template_name . '_css', AALB_TEMPLATE_URL . $template_name . '.css' );
|
61 |
-
} else {
|
62 |
-
$aalb_template_upload_url = $this->helper->get_template_upload_directory_url();
|
63 |
-
wp_enqueue_style('aalb_template' . $template_name . '_css', $aalb_template_upload_url . $template_name . '.css' );
|
64 |
-
}
|
65 |
-
}
|
66 |
-
|
67 |
/**
|
68 |
* The function responsible for rendering the shortcode.
|
69 |
* Makes a GET request and calls the render_xml to render the response.
|
@@ -76,28 +59,24 @@ class Aalb_Shortcode {
|
|
76 |
try {
|
77 |
$shortcode_attributes = $this->get_shortcode_attributes($atts);
|
78 |
|
79 |
-
$validated_link_id = $this->get_validated_link_id($shortcode_attributes['link_id']);
|
80 |
-
$validated_marketplace = $this->get_validated_marketplace($shortcode_attributes['marketplace']);
|
81 |
-
$validated_asins = $this->get_validated_asins($shortcode_attributes['asins']);
|
82 |
-
$validated_template = $this->get_validated_template($shortcode_attributes['template']);
|
83 |
-
$validated_store_id = $this->get_validated_store_id($shortcode_attributes['store']);
|
84 |
|
85 |
-
$marketplace = $this->get_marketplace_endpoint($validated_marketplace);
|
86 |
$url = $this->paapi_helper->get_item_lookup_url($validated_asins, $marketplace, $validated_store_id);
|
87 |
-
$asins = $this->format_asins($validated_asins);
|
88 |
$products_key = $this->helper->build_products_cache_key($asins, $marketplace, $validated_store_id);
|
89 |
$products_template_key = $this->helper->build_template_cache_key($asins, $marketplace, $validated_store_id, $validated_template );
|
90 |
|
91 |
-
$
|
92 |
-
$click_url = $this->tracking_api_helper->get_click_url($impression_params);
|
93 |
-
$this->tracking_api_helper->insert_pixel($impression_params);
|
94 |
-
$this->enqueue_template_styles($validated_template);
|
95 |
|
96 |
-
return str_replace(array('[[
|
97 |
} catch (Exception $e) {
|
98 |
error_log($this->paapi_helper->get_error_message($e->getMessage()));
|
99 |
}
|
100 |
-
|
101 |
}
|
102 |
|
103 |
/**
|
@@ -117,130 +96,6 @@ class Aalb_Shortcode {
|
|
117 |
),$atts);
|
118 |
return $shortcode_attributes;
|
119 |
}
|
120 |
-
|
121 |
-
/**
|
122 |
-
* Format comma separated asins into hypen separated asins for building key.
|
123 |
-
* Checks for more spaces and trims it.
|
124 |
-
*
|
125 |
-
* @since 1.0.0
|
126 |
-
* @param string $asins Comma separated asins.
|
127 |
-
* @return string Hyphen separated asins.
|
128 |
-
*/
|
129 |
-
private function format_asins($asins) {
|
130 |
-
return preg_replace('/[ ,]+/', '-', trim($asins));
|
131 |
-
}
|
132 |
-
|
133 |
-
/**
|
134 |
-
* Get marketplace endpoint for marketplace abbreviation
|
135 |
-
*
|
136 |
-
* @since 1.0.0
|
137 |
-
* @param string $marketplace_abbr Marketplace Abbreviation from shortcode
|
138 |
-
* @return string $marketplace_endpoint Marketplace endpoint
|
139 |
-
*/
|
140 |
-
public function get_marketplace_endpoint($marketplace_abbr) {
|
141 |
-
$marketplace_endpoint = "";
|
142 |
-
$aalb_marketplace_names = $this->config_loader->fetch_marketplaces();
|
143 |
-
$marketplace_endpoint = array_search($marketplace_abbr, $aalb_marketplace_names);
|
144 |
-
return $marketplace_endpoint;
|
145 |
-
}
|
146 |
-
|
147 |
-
/**
|
148 |
-
* Get validated link-id
|
149 |
-
* Checks if the link id we got from the api is valid or not and returns
|
150 |
-
* validated link-id. In case of invalid marketplace, it returns empty string.
|
151 |
-
*
|
152 |
-
* @since 1.0.0
|
153 |
-
* @param string $marketplace Marketplace from shortcode
|
154 |
-
* @return string $validated_template Validated marketplace
|
155 |
-
*/
|
156 |
-
public function get_validated_link_id($link_id) {
|
157 |
-
$validated_link_id = $link_id;
|
158 |
-
if(!$this->validation_helper->validate_link_id($link_id)) {
|
159 |
-
//If the link id is not valid, return empty string
|
160 |
-
$validated_link_id = '';
|
161 |
-
}
|
162 |
-
return $validated_link_id;
|
163 |
-
}
|
164 |
-
|
165 |
-
/**
|
166 |
-
* Get validated marketplace.
|
167 |
-
* Checks if a marketplace abbreviation from shortcode is valid and returns
|
168 |
-
* validated marketplace. In case of invalid marketplace, it returns default marketplace.
|
169 |
-
*
|
170 |
-
* @since 1.0.0
|
171 |
-
* @param string $marketplace Marketplace from shortcode
|
172 |
-
* @return string $validated_template Validated marketplace
|
173 |
-
*/
|
174 |
-
public function get_validated_marketplace($marketplace) {
|
175 |
-
//Changing case of the marketplace to upper. Ensures case insensitivity
|
176 |
-
$validated_marketplace = strtoupper($marketplace);
|
177 |
-
if(!$this->validation_helper->validate_marketplace($marketplace)) {
|
178 |
-
//If the marketplace is not valid, return default marketplace
|
179 |
-
$validated_marketplace = get_option(AALB_DEFAULT_MARKETPLACE);
|
180 |
-
}
|
181 |
-
return $validated_marketplace;
|
182 |
-
}
|
183 |
-
|
184 |
-
/**
|
185 |
-
* Get validated asin list
|
186 |
-
* Drops invalid asin from the list
|
187 |
-
*
|
188 |
-
* @since 1.0.0
|
189 |
-
* @param string $asins List of asins from shortcode
|
190 |
-
* @return string List of validated asins
|
191 |
-
*/
|
192 |
-
public function get_validated_asins($asins) {
|
193 |
-
//Creates array of asins in the shortcode
|
194 |
-
$asins_array = explode(',', $asins);
|
195 |
-
foreach ($asins_array as $asin) {
|
196 |
-
if (!$this->validation_helper->validate_asin($asin)) {
|
197 |
-
//Drop Invalid ASIN out of list of asins
|
198 |
-
$asins_array = array_diff($asins_array, array($asin));
|
199 |
-
//Show error message regarding incorrect asin in preview mode only
|
200 |
-
$this->helper->show_error_in_preview("The ASIN: '" . $asin . "' is invalid.");
|
201 |
-
}
|
202 |
-
}
|
203 |
-
return implode(',',$asins_array);
|
204 |
-
}
|
205 |
-
|
206 |
-
/**
|
207 |
-
* Get validated template.
|
208 |
-
* Checks if a template is valid, returns default template otherwise
|
209 |
-
*
|
210 |
-
* @since 1.0.0
|
211 |
-
* @param string $template Template name from shortcode
|
212 |
-
* @return string $validated_template Validated template name
|
213 |
-
*/
|
214 |
-
public function get_validated_template($template) {
|
215 |
-
$validated_template = $template;
|
216 |
-
if (!$this->validation_helper->validate_template_name($template)) {
|
217 |
-
//Return Default template in case of invalid template name
|
218 |
-
$validated_template = get_option(AALB_DEFAULT_TEMPLATE);
|
219 |
-
//Show error message regarding incorrect asin in preview mode only
|
220 |
-
$this->helper->show_error_in_preview("The template: '" . $template . "' is invalid. Using default template '" . $validated_template . "'.");
|
221 |
-
}
|
222 |
-
return $validated_template;
|
223 |
-
}
|
224 |
-
|
225 |
-
/**
|
226 |
-
* Get validated store id.
|
227 |
-
* Checks if a store id is valid, returns default store id otherwise
|
228 |
-
*
|
229 |
-
* @since 1.0.0
|
230 |
-
* @param string $store_id Store ID from shortcode
|
231 |
-
* @return string $validated_store_id Validated Store ID
|
232 |
-
*/
|
233 |
-
public function get_validated_store_id($store_id) {
|
234 |
-
$validated_store_id = $store_id;
|
235 |
-
if (!$this->validation_helper->validate_store_id($store_id)) {
|
236 |
-
//Return Default store id in case of invalid store id
|
237 |
-
$validated_store_id = get_option(AALB_DEFAULT_STORE_ID,AALB_DEFAULT_STORE_ID_NAME);
|
238 |
-
//Show error message regarding incorrect asin in preview mode only
|
239 |
-
$this->helper->show_error_in_preview("The Associate tag '" . $store_id . "' is not present in the list of valid tags. Associate tag has been updated to '" . $validated_store_id . "'. Please check your Associate tag selection or contact the administrator to add a new tag.");
|
240 |
-
}
|
241 |
-
return $validated_store_id;
|
242 |
-
}
|
243 |
-
|
244 |
}
|
245 |
|
246 |
?>
|
13 |
*/
|
14 |
|
15 |
/**
|
16 |
+
* Fired when a amazon_link shortcode is there in the post page.
|
17 |
*
|
18 |
* Gets the product information by making a Paapi request and renders the HTML
|
19 |
*
|
27 |
protected $paapi_helper;
|
28 |
protected $template_engine;
|
29 |
protected $helper;
|
|
|
|
|
30 |
protected $tracking_api_helper;
|
31 |
+
protected $shortcode_helper;
|
32 |
|
33 |
public function __construct() {
|
34 |
$this->template_engine = new Aalb_Template_Engine();
|
35 |
$this->paapi_helper = new Aalb_Paapi_Helper();
|
36 |
$this->helper = new Aalb_Helper();
|
|
|
|
|
37 |
$this->tracking_api_helper = new Aalb_Tracking_Api_Helper();
|
38 |
+
$this->shortcode_helper = new Aalb_Shortcode_Helper();
|
39 |
}
|
40 |
|
41 |
/**
|
47 |
wp_enqueue_style('aalb_basics_css', AALB_BASICS_CSS );
|
48 |
}
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
/**
|
51 |
* The function responsible for rendering the shortcode.
|
52 |
* Makes a GET request and calls the render_xml to render the response.
|
59 |
try {
|
60 |
$shortcode_attributes = $this->get_shortcode_attributes($atts);
|
61 |
|
62 |
+
$validated_link_id = $this->shortcode_helper->get_validated_link_id($shortcode_attributes['link_id']);
|
63 |
+
$validated_marketplace = $this->shortcode_helper->get_validated_marketplace($shortcode_attributes['marketplace']);
|
64 |
+
$validated_asins = $this->shortcode_helper->get_validated_asins($shortcode_attributes['asins']);
|
65 |
+
$validated_template = $this->shortcode_helper->get_validated_template($shortcode_attributes['template']);
|
66 |
+
$validated_store_id = $this->shortcode_helper->get_validated_store_id($shortcode_attributes['store']);
|
67 |
|
68 |
+
$marketplace = $this->shortcode_helper->get_marketplace_endpoint($validated_marketplace);
|
69 |
$url = $this->paapi_helper->get_item_lookup_url($validated_asins, $marketplace, $validated_store_id);
|
70 |
+
$asins = $this->shortcode_helper->format_asins($validated_asins);
|
71 |
$products_key = $this->helper->build_products_cache_key($asins, $marketplace, $validated_store_id);
|
72 |
$products_template_key = $this->helper->build_template_cache_key($asins, $marketplace, $validated_store_id, $validated_template );
|
73 |
|
74 |
+
$this->shortcode_helper->enqueue_template_styles($validated_template);
|
|
|
|
|
|
|
75 |
|
76 |
+
return str_replace(array('[[UNIQUE_ID]]'), array(str_replace('.','-',$products_template_key)), $this->template_engine->render($products_template_key, $products_key, $validated_template, $url, $validated_marketplace));
|
77 |
} catch (Exception $e) {
|
78 |
error_log($this->paapi_helper->get_error_message($e->getMessage()));
|
79 |
}
|
|
|
80 |
}
|
81 |
|
82 |
/**
|
96 |
),$atts);
|
97 |
return $shortcode_attributes;
|
98 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
}
|
100 |
|
101 |
?>
|
shortcode/aalb_shortcode_helper.php
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
Copyright 2016-2016 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 AALB shortcodes.
|
17 |
+
*
|
18 |
+
* Contains helper functions used while rendering shortcodes
|
19 |
+
*
|
20 |
+
* @since 1.4
|
21 |
+
* @package AmazonAssociatesLinkBuilder
|
22 |
+
* @subpackage AmazonAssociatesLinkBuilder/shortcode
|
23 |
+
*/
|
24 |
+
|
25 |
+
class Aalb_Shortcode_Helper {
|
26 |
+
|
27 |
+
protected $helper;
|
28 |
+
protected $config_loader;
|
29 |
+
protected $validation_helper;
|
30 |
+
|
31 |
+
public function __construct() {
|
32 |
+
$this->helper = new Aalb_Helper();
|
33 |
+
$this->config_loader = new Aalb_Config_Loader();
|
34 |
+
$this->validation_helper = new Aalb_Validation_Helper();
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Add CSS for the template
|
39 |
+
*
|
40 |
+
* @since 1.0.0
|
41 |
+
*/
|
42 |
+
public function enqueue_template_styles($template_name) {
|
43 |
+
$aalb_default_templates = explode(",", AALB_AMAZON_TEMPLATE_NAMES);
|
44 |
+
if(in_array($template_name, $aalb_default_templates)) {
|
45 |
+
wp_enqueue_style('aalb_template' . $template_name . '_css', AALB_TEMPLATE_URL . $template_name . '.css' );
|
46 |
+
} else {
|
47 |
+
$aalb_template_upload_url = $this->helper->get_template_upload_directory_url();
|
48 |
+
wp_enqueue_style('aalb_template' . $template_name . '_css', $aalb_template_upload_url . $template_name . '.css' );
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Format comma separated asins into hypen separated asins for building key.
|
54 |
+
* Checks for more spaces and trims it.
|
55 |
+
*
|
56 |
+
* @since 1.0.0
|
57 |
+
* @param string $asins Comma separated asins.
|
58 |
+
* @return string Hyphen separated asins.
|
59 |
+
*/
|
60 |
+
public function format_asins($asins) {
|
61 |
+
return preg_replace('/[ ,]+/', '-', trim($asins));
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Get marketplace endpoint for marketplace abbreviation
|
66 |
+
*
|
67 |
+
* @since 1.0.0
|
68 |
+
* @param string $marketplace_abbr Marketplace Abbreviation from shortcode
|
69 |
+
* @return string $marketplace_endpoint Marketplace endpoint
|
70 |
+
*/
|
71 |
+
public function get_marketplace_endpoint($marketplace_abbr) {
|
72 |
+
$marketplace_endpoint = "";
|
73 |
+
$aalb_marketplace_names = $this->config_loader->fetch_marketplaces();
|
74 |
+
$marketplace_endpoint = array_search($marketplace_abbr, $aalb_marketplace_names);
|
75 |
+
return $marketplace_endpoint;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Get validated link-id
|
80 |
+
* Checks if the link id we got from the api is valid or not and returns
|
81 |
+
* validated link-id. In case of invalid marketplace, it returns empty string.
|
82 |
+
*
|
83 |
+
* @since 1.0.0
|
84 |
+
* @param string $marketplace Marketplace from shortcode
|
85 |
+
* @return string $validated_template Validated marketplace
|
86 |
+
*/
|
87 |
+
public function get_validated_link_id($link_id) {
|
88 |
+
$validated_link_id = $link_id;
|
89 |
+
if(!$this->validation_helper->validate_link_id($link_id)) {
|
90 |
+
//If the link id is not valid, return empty string
|
91 |
+
$validated_link_id = '';
|
92 |
+
}
|
93 |
+
return $validated_link_id;
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Get validated marketplace.
|
98 |
+
* Checks if a marketplace abbreviation from shortcode is valid and returns
|
99 |
+
* validated marketplace. In case of invalid marketplace, it returns default marketplace.
|
100 |
+
*
|
101 |
+
* @since 1.0.0
|
102 |
+
* @param string $marketplace Marketplace from shortcode
|
103 |
+
* @return string $validated_template Validated marketplace
|
104 |
+
*/
|
105 |
+
public function get_validated_marketplace($marketplace) {
|
106 |
+
//Changing case of the marketplace to upper. Ensures case insensitivity
|
107 |
+
$validated_marketplace = strtoupper($marketplace);
|
108 |
+
if(!$this->validation_helper->validate_marketplace($marketplace)) {
|
109 |
+
//If the marketplace is not valid, return default marketplace
|
110 |
+
$validated_marketplace = get_option(AALB_DEFAULT_MARKETPLACE);
|
111 |
+
}
|
112 |
+
return $validated_marketplace;
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Get validated asin list
|
117 |
+
* Drops invalid asin from the list
|
118 |
+
*
|
119 |
+
* @since 1.0.0
|
120 |
+
* @param string $asins List of asins from shortcode
|
121 |
+
* @return string List of validated asins
|
122 |
+
*/
|
123 |
+
public function get_validated_asins($asins) {
|
124 |
+
//Creates array of asins in the shortcode
|
125 |
+
$asins_array = explode(',', $asins);
|
126 |
+
foreach ($asins_array as $asin) {
|
127 |
+
if (!$this->validation_helper->validate_asin($asin)) {
|
128 |
+
//Drop Invalid ASIN out of list of asins
|
129 |
+
$asins_array = array_diff($asins_array, array($asin));
|
130 |
+
//Show error message regarding incorrect asin in preview mode only
|
131 |
+
$this->helper->show_error_in_preview("The ASIN: '" . $asin . "' is invalid.");
|
132 |
+
}
|
133 |
+
}
|
134 |
+
return implode(',',$asins_array);
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Get validated template.
|
139 |
+
* Checks if a template is valid, returns default template otherwise
|
140 |
+
*
|
141 |
+
* @since 1.0.0
|
142 |
+
* @param string $template Template name from shortcode
|
143 |
+
* @return string $validated_template Validated template name
|
144 |
+
*/
|
145 |
+
public function get_validated_template($template) {
|
146 |
+
$validated_template = $template;
|
147 |
+
if (!$this->validation_helper->validate_template_name($template)) {
|
148 |
+
//Return Default template in case of invalid template name
|
149 |
+
$validated_template = get_option(AALB_DEFAULT_TEMPLATE);
|
150 |
+
//Show error message regarding incorrect asin in preview mode only
|
151 |
+
$this->helper->show_error_in_preview("The template: '" . $template . "' is invalid. Using default template '" . $validated_template . "'.");
|
152 |
+
}
|
153 |
+
return $validated_template;
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Get validated store id.
|
158 |
+
* Checks if a store id is valid, returns default store id otherwise
|
159 |
+
*
|
160 |
+
* @since 1.0.0
|
161 |
+
* @param string $store_id Store ID from shortcode
|
162 |
+
* @return string $validated_store_id Validated Store ID
|
163 |
+
*/
|
164 |
+
public function get_validated_store_id($store_id) {
|
165 |
+
$validated_store_id = $store_id;
|
166 |
+
if (!$this->validation_helper->validate_store_id($store_id)) {
|
167 |
+
//Return Default store id in case of invalid store id
|
168 |
+
$validated_store_id = get_option(AALB_DEFAULT_STORE_ID,AALB_DEFAULT_STORE_ID_NAME);
|
169 |
+
//Show error message regarding incorrect asin in preview mode only
|
170 |
+
$this->helper->show_error_in_preview("The Associate tag '" . $store_id . "' is not present in the list of valid tags. Associate tag has been updated to '" . $validated_store_id . "'. Please check your Associate tag selection or contact the administrator to add a new tag.");
|
171 |
+
}
|
172 |
+
return $validated_store_id;
|
173 |
+
}
|
174 |
+
}
|
175 |
+
|
176 |
+
?>
|
shortcode/aalb_shortcode_loader.php
CHANGED
@@ -23,7 +23,8 @@ and limitations under the License.
|
|
23 |
*/
|
24 |
class Aalb_Shortcode_Loader {
|
25 |
|
26 |
-
public $
|
|
|
27 |
|
28 |
/**
|
29 |
* Create only a single instance of the Aalb Shortcode.
|
@@ -32,11 +33,25 @@ class Aalb_Shortcode_Loader {
|
|
32 |
* @since 1.0.0
|
33 |
* @return Aalb_Shortcode The instance of Aalb_Shortcode.
|
34 |
*/
|
35 |
-
public function
|
36 |
-
if(is_null($this->
|
37 |
return new Aalb_Shortcode();
|
38 |
}
|
39 |
-
return $this->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
|
42 |
/**
|
@@ -45,7 +60,8 @@ class Aalb_Shortcode_Loader {
|
|
45 |
* @since 1.0.0
|
46 |
*/
|
47 |
public function add_shortcode() {
|
48 |
-
add_shortcode(AALB_SHORTCODE_AMAZON_LINK, array($this, '
|
|
|
49 |
}
|
50 |
|
51 |
/**
|
@@ -55,18 +71,31 @@ class Aalb_Shortcode_Loader {
|
|
55 |
*/
|
56 |
public function remove_shortcode() {
|
57 |
remove_shortcode(AALB_SHORTCODE_AMAZON_LINK);
|
|
|
58 |
}
|
59 |
|
60 |
/**
|
61 |
-
* Callback function for rendering shortcode
|
62 |
*
|
63 |
*
|
64 |
* @since 1.0.0
|
65 |
* @param array $atts Shortcode attributes and values.
|
66 |
* @return HTML HTML for displaying the templates.
|
67 |
*/
|
68 |
-
public function
|
69 |
-
return $this->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
}
|
71 |
|
72 |
}
|
23 |
*/
|
24 |
class Aalb_Shortcode_Loader {
|
25 |
|
26 |
+
public $shortcode_link = null;
|
27 |
+
public $shortcode_textlink = null;
|
28 |
|
29 |
/**
|
30 |
* Create only a single instance of the Aalb Shortcode.
|
33 |
* @since 1.0.0
|
34 |
* @return Aalb_Shortcode The instance of Aalb_Shortcode.
|
35 |
*/
|
36 |
+
public function get_amazon_link_shortcode() {
|
37 |
+
if(is_null($this->shortcode_link)) {
|
38 |
return new Aalb_Shortcode();
|
39 |
}
|
40 |
+
return $this->shortcode_link;
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Create only a single instance of the Aalb TextLink Shortcode.
|
45 |
+
* No need to create an instance for rendering each shortcode.
|
46 |
+
*
|
47 |
+
* @since 1.4
|
48 |
+
* @return Aalb_Shortcode_Text The instance of Aalb_Shortcode_Text.
|
49 |
+
*/
|
50 |
+
public function get_amazon_textlink_shortcode() {
|
51 |
+
if(is_null($this->shortcode_textlink)) {
|
52 |
+
return new Aalb_Shortcode_Text();
|
53 |
+
}
|
54 |
+
return $this->shortcode_textlink;
|
55 |
}
|
56 |
|
57 |
/**
|
60 |
* @since 1.0.0
|
61 |
*/
|
62 |
public function add_shortcode() {
|
63 |
+
add_shortcode(AALB_SHORTCODE_AMAZON_LINK, array($this, 'amazon_link_shortcode_callback'));
|
64 |
+
add_shortcode(AALB_SHORTCODE_AMAZON_TEXT, array($this, 'amazon_textlink_shortcode_callback'));
|
65 |
}
|
66 |
|
67 |
/**
|
71 |
*/
|
72 |
public function remove_shortcode() {
|
73 |
remove_shortcode(AALB_SHORTCODE_AMAZON_LINK);
|
74 |
+
remove_shortcode(AALB_SHORTCODE_AMAZON_TEXT);
|
75 |
}
|
76 |
|
77 |
/**
|
78 |
+
* Callback function for rendering amazon_link shortcode
|
79 |
*
|
80 |
*
|
81 |
* @since 1.0.0
|
82 |
* @param array $atts Shortcode attributes and values.
|
83 |
* @return HTML HTML for displaying the templates.
|
84 |
*/
|
85 |
+
public function amazon_link_shortcode_callback($atts) {
|
86 |
+
return $this->get_amazon_link_shortcode()->render($atts);
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Callback function for rendering amazon_textlink shortcode
|
91 |
+
*
|
92 |
+
*
|
93 |
+
* @since 1.4
|
94 |
+
* @param array $atts Shortcode attributes and values.
|
95 |
+
* @return HTML HTML for displaying the templates.
|
96 |
+
*/
|
97 |
+
public function amazon_textlink_shortcode_callback($atts) {
|
98 |
+
return $this->get_amazon_textlink_shortcode()->render($atts);
|
99 |
}
|
100 |
|
101 |
}
|
shortcode/aalb_shortcode_text.php
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
Copyright 2016-2016 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 |
+
* Fired when a amazon_textlink is there in the post page.
|
17 |
+
*
|
18 |
+
* Gets the product information by making a Paapi request and renders the HTML
|
19 |
+
*
|
20 |
+
* @since 1.4
|
21 |
+
* @package AmazonAssociatesLinkBuilder
|
22 |
+
* @subpackage AmazonAssociatesLinkBuilder/shortcode
|
23 |
+
*/
|
24 |
+
|
25 |
+
class Aalb_Shortcode_Text {
|
26 |
+
|
27 |
+
protected $paapi_helper;
|
28 |
+
protected $template_engine;
|
29 |
+
protected $helper;
|
30 |
+
protected $tracking_api_helper;
|
31 |
+
protected $shortcode_helper;
|
32 |
+
|
33 |
+
public function __construct() {
|
34 |
+
$this->template_engine = new Aalb_Template_Engine();
|
35 |
+
$this->paapi_helper = new Aalb_Paapi_Helper();
|
36 |
+
$this->helper = new Aalb_Helper();
|
37 |
+
$this->tracking_api_helper = new Aalb_Tracking_Api_Helper();
|
38 |
+
$this->shortcode_helper = new Aalb_Shortcode_Helper();
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Add basic styles
|
43 |
+
*
|
44 |
+
* @since 1.4
|
45 |
+
*/
|
46 |
+
public function enqueue_styles() {
|
47 |
+
wp_enqueue_style('aalb_basics_css', AALB_BASICS_CSS );
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* The function responsible for rendering the shortcode.
|
52 |
+
* Makes a GET request and calls the render_xml to render the response.
|
53 |
+
*
|
54 |
+
* @since 1.4
|
55 |
+
* @param array $atts Shortcode attribute and values.
|
56 |
+
* @return HTML Rendered html to display.
|
57 |
+
*/
|
58 |
+
public function render($atts) {
|
59 |
+
try {
|
60 |
+
$shortcode_attributes = $this->get_shortcode_attributes($atts);
|
61 |
+
|
62 |
+
$validated_link_id = $this->shortcode_helper->get_validated_link_id($shortcode_attributes['link_id']);
|
63 |
+
$validated_marketplace = $this->shortcode_helper->get_validated_marketplace($shortcode_attributes['marketplace']);
|
64 |
+
$validated_asins = $this->shortcode_helper->get_validated_asins($shortcode_attributes['asin']);
|
65 |
+
$validated_template = $this->shortcode_helper->get_validated_template($shortcode_attributes['template']);
|
66 |
+
$validated_store_id = $this->shortcode_helper->get_validated_store_id($shortcode_attributes['store']);
|
67 |
+
$link_text = $shortcode_attributes['text'];
|
68 |
+
|
69 |
+
$marketplace = $this->shortcode_helper->get_marketplace_endpoint($validated_marketplace);
|
70 |
+
$url = $this->paapi_helper->get_item_lookup_url($validated_asins, $marketplace, $validated_store_id);
|
71 |
+
$asins = $this->shortcode_helper->format_asins($validated_asins);
|
72 |
+
$products_key = $this->helper->build_products_cache_key($asins, $marketplace, $validated_store_id);
|
73 |
+
$products_template_key = $this->helper->build_template_cache_key($asins, $marketplace, $validated_store_id, $validated_template );
|
74 |
+
|
75 |
+
$this->shortcode_helper->enqueue_template_styles($validated_template);
|
76 |
+
return str_replace(array('[[UNIQUE_ID]]', '[[Amazon_Link_Text]]'), array(str_replace('.','-',$products_template_key), $link_text), $this->template_engine->render($products_template_key, $products_key, $validated_template, $url, $validated_marketplace));
|
77 |
+
} catch (Exception $e) {
|
78 |
+
error_log($this->paapi_helper->get_error_message($e->getMessage()));
|
79 |
+
}
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Returns default shortcode attributes if not mentioned
|
84 |
+
*
|
85 |
+
* @since 1.4
|
86 |
+
* @param array $atts Shortcode attributes.
|
87 |
+
* @return array Default shortcode attributes if not mentioned.
|
88 |
+
*/
|
89 |
+
private function get_shortcode_attributes($atts) {
|
90 |
+
$shortcode_attributes=shortcode_atts(array(
|
91 |
+
'asin' => null,
|
92 |
+
'marketplace' => get_option(AALB_DEFAULT_MARKETPLACE),
|
93 |
+
'store' => get_option(AALB_DEFAULT_STORE_ID),
|
94 |
+
'template' => get_option(AALB_DEFAULT_TEMPLATE),
|
95 |
+
'link_id' => null,
|
96 |
+
'text' => null
|
97 |
+
),$atts);
|
98 |
+
return $shortcode_attributes;
|
99 |
+
}
|
100 |
+
}
|
101 |
+
|
102 |
+
?>
|
template/ProductLink.css
ADDED
File without changes
|
template/ProductLink.mustache
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{{#Items}}
|
2 |
+
{{#Item}}
|
3 |
+
{{#aalb}}
|
4 |
+
<a href="{{DetailPageURL}}" target="_blank" rel="nofollow">[[Amazon_Link_Text]]</a> <!--Individual attributes are provided as variable tags as {{[[attribute]]}}. Check documentation for list of supported variable tags.-->
|
5 |
+
{{/aalb}}
|
6 |
+
{{/Item}}
|
7 |
+
{{/Items}}
|