] {Optional, default=ALL} * search="" [] {Optional} * asin="" [] {Optional} * isbn="" [] {Optional} * size="" [16,24,32,48 (px)] {Optional, default=16} * label="" [] {Optional} * display="" [IMAGE|TEXT|BOTH] {Optional, default=IMAGE} * nofollow="" [true|false] [Optional, default=true] * ] * * Examples: * [marbl type="amazon" region="UK,US,CA" search="Intel NUC" size="16"] * [marbl type="amazon" region="UK,US,CA" asin="B01N6SRT4H"] * [marbl type="amazon" region="UK,CA" isbn="0593077180" size="48"] * [marbl type="amazon" region="ALL" search="Intel NUC"] // If there is a registered Amazon Associates ID / Country Code (or is 'null'), create a link for it in the output * [marbl type="amazon" search="Intel NUC"] // Same as above, without the explicit all * [marbl type="amazon" asin="B01N6SRT4H" label="buy now on Amazon" display=TEXT] // Write buy 'now on Amazon' as the trigger for the drop menu with no icon * [marbl type="amazon" region="UK,CA,ES" isbn="0593077180"] // Assuming that ES doesn't have a Associates ID and isn't set to null in the Associates ID, this will force ES to display as a link * [marbl type="amazon" region="MX,FR,UK,IN" isbn="0593077180"] // Writes them out in the order MX,FR,UK,IN */ class Marbl { protected $pluginPath; protected $pluginUrl; public static $Version = '0.9.23'; public function __construct() { // Set plugin Path $this->pluginPath = dirname(__FILE__); // Set plugin URL $this->pluginUrl = rtrim(plugin_dir_url(__FILE__), '/');//plugins_url() . '/marbl'; // Register shortcode hook add_shortcode('marbl', array($this, 'create_Link') ); // Register Admin Settings add_action('admin_init', array($this, 'marbl_register_settings') ); // Register Admin UI Settings Page add_action('admin_menu', array($this, 'marbl_link_register_options_page') ); // Register required JavaScript & CSS add_action('wp_enqueue_scripts', array($this, 'marblLink_scriptsStyles') ); } public function shortcode() { } public function create_Link( $atts ) { // Set Attribute Default Values (if not provided) $a = shortcode_atts( array( 'type' => 'amazon', // Values: amazon,ebay 'regions' => 'ALL', // All 'search' => '', // All 'asin' => '', // Amazon 'isbn' => '', // Amazon 'item' => '', // eBay: link to specific item 'store' => '', // eBay: Link to a specific eBay store front 'size' => '16', // All 'label' => '', // All 'display' => 'IMAGE', // All 'campaign' => '' // eBay: Track into a specific campaign ID ), $atts ); switch (strtolower($a['type'])) { case 'amazon': if (get_option('marbl_amazon_enabled')) { return $this->createLink_amazon($a['regions'], $a['label'], $a['search'], $a['asin'], $a['isbn'], $a['size'], $a['display']); } else { return; } break; case 'ebay': if (get_option('marbl_ebay_enabled')) { return $this->createLink_ebay($a['regions'], $a['label'], $a['search'], $a['item'], $a['store'], $a['size'], $a['display'], $a['campaign']); } else { return; } break; default: return; break; } } private function getCountryCodes($strType) { if ($strType === 'amazon') { return ['AE', 'AU', 'BE', 'BR', 'CA', 'CN', 'DE', 'ES', 'FR', 'IN', 'IT', 'JP', 'MX', 'NL', 'PL', 'SA', 'SE', 'SG', 'UK', 'US']; } elseif ($strType === 'ebay') { return ['AT', 'AU', 'BE', 'CA', 'CH', 'DE', 'ES', 'FR', 'GB', 'IE', 'IT', 'NL', 'PL', 'US']; } } private function getCountryName($strCountryCode) { switch ($strCountryCode) { case 'AE': return 'United Arab Emirates'; case 'AT': return 'Austria'; case 'AU': return 'Australia'; case 'BE': return 'Belgium'; case 'BR': return 'Brazil'; case 'CA': return 'Canada'; case 'CH': return 'Switzerland'; case 'CN': return 'China'; case 'DE': return 'Germany'; case 'ES': return 'Spain'; case 'FR': return 'France'; case 'GB': return 'United Kingdom'; case 'IE': return 'Ireland'; case 'IN': return 'India'; case 'IT': return 'Italy'; case 'JP': return 'Japan'; case 'MX': return 'Mexico'; case 'NL': return 'Netherlands'; case 'PL': return 'Poland'; case 'SA': return 'Saudi Arabia'; case 'SE': return 'Sweden'; case 'SG': return 'Singapore'; case 'UK': return 'United Kingdom'; case 'US': return 'United States'; } } /** * Create Amazon Link */ private function createLink_amazon($strRegions, $strLabel, $strFreetext, $strAsin, $strIsbn, $strSize, $strDisplay) { if (!isset($strFreetext) || !isset($strAsin) || !isset($strIsbn)) { //die return 'You must provide a either an ASIN, ISBN or a Search String'; //die(); } else { $strRegions = trim(str_replace(' ', '', $strRegions)); $strLabel = str_replace('&quot;', '"', $strLabel); // Search for quotation marks " coming in (double escaped) from Wordpress's sanitisation and restore to " $strLabel = trim($strLabel); // Make safe to paste into JavaScript $strFreetext = str_replace('&quot;', '"', $strFreetext); $strFreetext = trim($strFreetext); $strAsin = trim($strAsin); $strIsbn = trim($strIsbn); $iSize = sprintf("%d", $strSize); // Numeric or 0 switch (strtoupper($strDisplay)) { case 'IMAGE': $strDisplay = 1; // Image Only break; case 'TEXT': $strDisplay = 2; // Text Only break; case 'BOTH': $strDisplay = 3; // Both Text and Image break; default: $strDisplay = 1; // Image Only break; } //filter_var($strDisplay, FILTER_VALIDATE_BOOLEAN) switch ($iSize) { case 16: $strSize = 16; break; case 24: $strSize = 24; break; case 32: $strSize = 32; break; case 48: $strSize = 48; break; default: $strSize = 16; break; } $arrCountryCodes = $this->getCountryCodes('amazon'); $strAssociateIds = ''; for ($i = 0; $i < count($arrCountryCodes); $i++) { if (get_option('marbl_amazon_link_associate_id_' . strtolower($arrCountryCodes[$i])) != '') { $strAssociateIds .= 'marblAmazon.addAssociateId(\'' . esc_js(strtoupper($arrCountryCodes[$i])) .'\', \'' . esc_js(get_option('marbl_amazon_link_associate_id_' . (strtolower($arrCountryCodes[$i])))) . '\');'; } } if (get_option('marbl_general_custom_resources_path') != null) { $strAssetsPath = esc_url(get_option('marbl_general_custom_resources_path')); } else { $strAssetsPath = esc_url(plugin_dir_url( __FILE__ )); } $strDisclaimerCfg = ''; if (get_option('marbl_amazon_show_disclaimer')) { $strDisclaimerCfg = 'marblAmazon.DisclaimerPosition = marblAmazon.' . ((get_option('marbl_amazon_disclaimer_position') === 'TOP') ? 'TOP' : 'BOTTOM') . ';'; $strDisclaimerCfg .= 'marblAmazon.DisclaimerText = \'' . esc_js(get_option('marbl_amazon_disclaimer')) . '\';'; } return ''; } } /** * Create eBay EPN Link */ private function createLink_eBay($strRegions, $strLabel, $strFreetext, $strItemId, $strStoreId, $strSize, $strDisplay, $strCampaign) { if (!isset($strFreetext) || !isset($strItemId) || !isset($strStoreId)) { //die return 'You must provide a either an Item Number, Store Link ID or a Search String'; //die(); } else { $strRegions = trim(str_replace(' ', '', $strRegions)); $strLabel = str_replace('&quot;', '"', $strLabel); // Search for quotation marks " coming in (double escaped) from Wordpress's sanitisation and restore to " $strLabel = trim($strLabel); // Make safe to paste into JavaScript $strFreetext = str_replace('&quot;', '"', $strFreetext); $strFreetext = trim($strFreetext); $strItemId = trim($strItemId); $strStoreId = trim($strStoreId); $iSize = sprintf("%d", $strSize); // Numeric or 0 switch (strtoupper($strDisplay)) { case 'IMAGE': $strDisplay = 1; // Image Only break; case 'TEXT': $strDisplay = 2; // Text Only break; case 'BOTH': $strDisplay = 3; // Both Text and Image break; default: $strDisplay = 1; // Image Only break; } //filter_var($strDisplay, FILTER_VALIDATE_BOOLEAN) switch ($iSize) { case 16: $strSize = 16; break; case 24: $strSize = 24; break; case 32: $strSize = 32; break; case 48: $strSize = 48; break; default: $strSize = 16; break; } // If there is a custom Campaign ID, use it, else fall back to the default one. if (isset($strCampaign) && ($strCampaign != '')) { $strCampaignId = 'marblEbay.CampaignId = \'' . esc_js($strCampaign) . '\';'; } else { $strCampaignId = 'marblEbay.CampaignId = \'' . get_option('marbl_ebay_default_campaign_id') . '\';'; } $arrCountryCodes = $this->getCountryCodes('ebay'); $strPermittedRegions = ''; foreach($arrCountryCodes as $strCountryCode) { if (get_option('marbl_ebay_region_' . strtolower($strCountryCode) . '_enabled')) { $strPermittedRegions .= 'marblEbay.addRegion(\'' . esc_js(strtoupper($strCountryCode)) .'\');'; } } if (get_option('marbl_general_custom_resources_path') != null) { $strAssetsPath = esc_url(get_option('marbl_general_custom_resources_path')); } else { $strAssetsPath = esc_url(plugin_dir_url( __FILE__ )); } $strDisclaimerCfg = ''; if (get_option('marbl_ebay_show_disclaimer')) { $strDisclaimerCfg = 'marblEbay.DisclaimerPosition = marblEbay.' . ((get_option('marbl_general_link_show_flags')) ? 'TOP' : 'BOTTOM') . ';'; $strDisclaimerCfg .= 'marblEbay.DisclaimerText = \'' . esc_js(get_option('marbl_ebay_disclaimer')) . '\';'; } return ''; // Note: String parameters are not wrapped in " " because json_encode appends this itself } } /** * Include CSS and JS content. */ function marblLink_scriptsStyles() { if (get_option('marbl_general_include_default_css')) { wp_register_style( 'marbl-css', plugin_dir_url( __FILE__ ) . 'css/main.css', NULL, self::$Version ); wp_enqueue_style( 'marbl-css' ); } wp_enqueue_script( 'marbl-js', plugin_dir_url( __FILE__ ) . 'js/Marbl.js', NULL, self::$Version, array( 'in_footer' => false, ) ); } // add_action( 'wp_enqueue_scripts', 'marblLink_scriptsStyles' ); /** * Register Admin Settings Parms */ function marbl_register_settings() { // General add_option( 'marbl_general_link_open_new_window', true); register_setting( 'marbl_general_options_group', 'marbl_general_link_open_new_window', array($this, 'marbl_validate_boolean') ); // Parm 2 is a string callback function ref where the value is sanitised add_option( 'marbl_general_link_show_flags', true); register_setting( 'marbl_general_options_group', 'marbl_general_link_show_flags', array($this, 'marbl_validate_boolean') ); add_option( 'marbl_general_link_link_nofollow', true); register_setting( 'marbl_general_options_group', 'marbl_general_link_link_nofollow', array($this, 'marbl_validate_boolean') ); add_option( 'marbl_general_include_default_css', true); register_setting( 'marbl_general_options_group', 'marbl_general_include_default_css', array($this, 'marbl_validate_boolean') ); add_option( 'marbl_general_custom_resources_path', null); register_setting( 'marbl_general_options_group', 'marbl_general_custom_resources_path', array($this, 'marbl_settings_general_resources_path_validate') ); // Amazon add_option( 'marbl_amazon_enabled', false); register_setting( 'marbl_amazon_link_options_group', 'marbl_amazon_enabled', array($this, 'marbl_validate_boolean') ); add_option( 'marbl_amazon_show_disclaimer', false); register_setting( 'marbl_amazon_link_options_group', 'marbl_amazon_show_disclaimer', array($this, 'marbl_validate_boolean') ); add_option( 'marbl_amazon_disclaimer_position', false); register_setting( 'marbl_amazon_link_options_group', 'marbl_amazon_disclaimer_position', array($this, 'marbl_validate_string') ); add_option( 'marbl_amazon_disclaimer', false); register_setting( 'marbl_amazon_link_options_group', 'marbl_amazon_disclaimer', array($this, 'marbl_validate_string') ); $arrCountryCodes = $this->getCountryCodes('amazon'); for ($i = 0; $i < count($arrCountryCodes); $i++) { add_option( 'marbl_amazon_link_associate_id_' . strtolower($arrCountryCodes[$i]), ''); register_setting( 'marbl_amazon_link_options_group', 'marbl_amazon_link_associate_id_' . strtolower($arrCountryCodes[$i]), array($this, 'marbl_amazon_link_associate_id_validate') ); } // eBay add_option( 'marbl_ebay_enabled', false); register_setting( 'marbl_ebay_link_options_group', 'marbl_ebay_enabled', array($this, 'marbl_validate_boolean') ); add_option( 'marbl_ebay_default_campaign_id', ''); register_setting( 'marbl_ebay_link_options_group', 'marbl_ebay_default_campaign_id', array($this, 'marbl_ebay_campaign_id_validate') ); add_option( 'marbl_ebay_show_disclaimer', false); register_setting( 'marbl_ebay_link_options_group', 'marbl_ebay_show_disclaimer', array($this, 'marbl_validate_boolean') ); add_option( 'marbl_ebay_disclaimer_position', false); register_setting( 'marbl_ebay_link_options_group', 'marbl_ebay_disclaimer_position', array($this, 'marbl_validate_string') ); add_option( 'marbl_ebay_disclaimer', false); register_setting( 'marbl_ebay_link_options_group', 'marbl_ebay_disclaimer', array($this, 'marbl_validate_string') ); $arrCountryCodes = $this->getCountryCodes('ebay'); foreach($arrCountryCodes as $iVectorId => $strCountryCode) { add_option( 'marbl_ebay_region_' . strtolower($strCountryCode) . '_enabled', true); register_setting( 'marbl_ebay_link_options_group', 'marbl_ebay_region_' . strtolower($strCountryCode) . '_enabled', array($this, 'marbl_validate_boolean') ); } } // add_action( 'admin_init', 'marbl_register_settings' ); /* Settings Sanitisation and Validation */ //https://codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data public function marbl_settings_general_resources_path_validate($strInput) { $strInput = trim($strInput); if (strlen($strInput) == 0) { return null; } else { if (substr($strInput, -1) != '/') { $strInput .= '/'; } return esc_url($strInput); } } public function marbl_amazon_link_associate_id_validate($strInput) { return esc_attr($strInput); } public function marbl_ebay_campaign_id_validate($strInput) { $strInput = trim($strInput); if (!is_numeric($strInput)) { return null; } if (strlen($strInput) > 10) { return substr($strInput, 0, 10); } else { return $strInput; } } public function marbl_validate_boolean($strInput) { $iVal = intval($strInput); if ($iVal === 0 || $iVal === null) { return false; } else { return true; } } public function marbl_validate_string($strInput) { return htmlentities($strInput); } /** * Register Admin Settings Page */ function marbl_link_register_options_page() { // Page TTL Nav Link Name Capability Menu Slug Callback Function add_options_page('Marbl Links', 'Marbl Links for Amazon & eBay', 'manage_options', 'marbl_link', array($this, 'marbl_link_options_page')); } // add_action('admin_menu', 'marbl_link_register_options_page'); function marbl_link_options_page() { //content on page goes here ?>

Multi-region Affiliate & Referral Buyers Link (Marbl)

Multi-region Affiliate & Referral Buyers Link creates a user-selectable drop list of your Amazon Affiliate store and eBay Partner Network accounts, allowing the user to select their preferred region.

Marbl does not use IP geo-location, third party services and is strong on protecting your and your users privacy.

  • General Settings
  • Amazon Settings
  • eBay Settings
If you found this free plugin useful, please show your support via
Donate with ko-fi.com

General Settings

These settings control the functionality of the Marbl plugin.

Behaviour

Styling

{Optional} This should be the root path containing ./css/main.css and ./images/<custom_image_files>
It can be a relative path (/static/marbl/) or an absolute path (http://www.mysite.com/static/marbl/)
See the Marbl documentation for more information on how to use custom styles and images.