&text=] --> inserts link to amazon item
[amazon cat= ' . __('Use this section to set up the global Display Options that change how links are displayed and their behaviour, to enable advance options like \' ' . __('Within this section you can also set up the Amazon Product Data Cache, select Enable to install the cache, Disable to remove it, and Flush to empty any cached data.','amazon-link') . ' ' . __('The status of the ip2nation database is displayed at the bottom of this section, with options to Install the database if it is not already installed or a new version is available on the ip2nation website.','amazon-link') . ' ' . __('Use this section to set up the global default Amazon Affiliate Tags, as well as create named Channels that can be used on the Amazon Affiliate Site to track the performance of different sections of your site. You can also set Affiliate tags in the WordPress User\'s Profile page, these will automatically be used on any post authored by that user','amazon-link') . ' ' . __('Use this section to edit, create and delete Templates used to create the Amazon Links on your site, the content is standard HTML with special ' . __('This section lists all the default templates included with the plugin, use it to re-install or your update your active templates.','amazon-link') . ' '. __('For more information:', 'amazon-link'). ' ' . __('Plugin Home Page','amazon-link') . ' ' . __('Plugin FAQ','amazon-link') . ' ' . __('Channels Help','amazon-link') . ' ' . __('Template Help','amazon-link') . ' ' . __('Use this page to manage plugins that add extra functionality to the main Amazon Link plugin. These plugins are either user provided or have been requested by users of the Amazon Link plugin, however although useful they may come with some performance or database impact. As such they are not built into the Amazon Link plugin by default.','amazon-link') . ' ' . __('The plugins use the filters and action hooks built into the main Amazon Link plugin to modify its behavior (see the next help section), any changes made on this page will cause the Amazon Link Cache to be emptied.','amazon-link') . ' ' . __('It is recommended that if you wish to modify the behaviour of Amazon Link plugin then create your own plugins (using the provided ones as a template), these will survive any upgrades to the main plugin.','amazon-link') . ' ' . __('The plugin exposes three filters that can be accessed via the standard WordPress Filter API:','amazon-link') .
'live data\', the Product search tool or \'Wishlist\' facility you must also configure your AWS keys in the Amazon Associate Information sub section.','amazon-link') . '% delimited keywords that are replaced by appropriate product information, see the \'Template Help\' section for a list of all valid keywords.','amazon-link') . '
' . __('It is also possible to add your own filters to process individual data items returned via Amazon by adding a \'Filter\' item using the \'amazon_link_keywords\' filter. See the \'Editorial Content\' plugin for an example of how to do this.','amazon-link') . '
' . '' . __('The plugin exposes one action hook that can be used via the standard WordPress Action API:','amazon-link') . '
'. ''. __('For more information:', 'amazon-link'). '
' . '' . __('Plugin Home Page','amazon-link') . '
' . '' . __('Plugin FAQ','amazon-link') . '
' . '' . __('Filters Help','amazon-link') . '
' . '' . __('Template Help','amazon-link') . '
'); } function adminColumns($columns, $screen) { if ($screen == $this->opts_page) { $columns[$this->opts_page] = 2; } return $columns; } function amazon_admin_styles() { wp_enqueue_style('amazon-link-style'); $this->form->enqueue_styles(); } function amazon_admin_scripts() { wp_enqueue_script('amazon-link-admin-script'); } function amazon_styles() { wp_enqueue_style('amazon-link-style'); } function edit_scripts() { wp_enqueue_script('amazon-link-edit-script'); } function generate_multi_script() { wp_print_scripts('amazon-link-script'); $Settings = $this->getSettings(); $country_data = $this->get_country_data(); $channels = $this->get_channels(True, True); $TARGET = $Settings['new_window'] ? 'target="_blank"' : ''; ?> base_name) { $links[] = '' . __('Settings','amazon-link') . ''; } return $links; } function create_popup (){ if (!$this->scripts_done) { $this->scripts_done = True; add_action('wp_print_footer_scripts', array($this, 'generate_multi_script')); return; } } /*****************************************************************************************/ /// Options & Templates Handling /*****************************************************************************************/ function get_keywords() { if (!isset($this->keywords)) { $this->keywords = array( 'link_open' => array( 'Description' => __('Create an Amazon link to a product with user defined content, of the form %LINK_OPEN%My Content%LINK_CLOSE%', 'amazon-link'), 'Link' => '1'), 'rlink_open' => array( 'Description' => __('Create an Amazon link to product reviews with user defined content, of the form %RLINK_OPEN%My Content%LINK_CLOSE%', 'amazon-link'), 'Link' => '1'), 'slink_open' => array( 'Description' => __('Create an Amazon link to a search page with user defined content, of the form %SLINK_OPEN%My Content%LINK_CLOSE%', 'amazon-link'), 'Link' => '1'), 'link_close' => array( 'Description' => __('Must follow a LINK_OPEN (translates to "").', 'amazon-link')), 'asin' => array( 'Description' => __('Item\'s unique ASIN', 'amazon-link'), 'Live' => '1', 'Group' => 'ItemAttributes', 'Default' => '0', 'Position' => array(array('ASIN'))), 'asins' => array( 'Description' => __('Comma seperated list of ASINs', 'amazon-link'), 'Default' => '0'), 'product' => array( 'Description' => __('Item\'s Product Group', 'amazon-link'), 'Live' => '1', 'Group' => 'ItemAttributes', 'Default' => '-', 'Position' => array(array('ItemAttributes','ProductGroup'))), 'title' => array( 'Description' => __('Item\'s Title', 'amazon-link'), 'Live' => '1', 'Group' => 'ItemAttributes', 'Position' => array(array('ItemAttributes','Title'))), 'artist' => array( 'Description' => __('Item\'s Author, Artist or Creator', 'amazon-link'), 'Live' => '1', 'Group' => 'ItemAttributes', 'Default' => '-', 'Position' => array(array('ItemAttributes','Artist'), array('ItemAttributes','Author'), array('ItemAttributes','Director'), array('ItemAttributes','Creator'), array('ItemAttributes','Brand'))), 'manufacturer' => array( 'Description' => __('Item\'s Manufacturer', 'amazon-link'), 'Live' => '1', 'Group' => 'ItemAttributes', 'Default' => '-', 'Position' => array(array('ItemAttributes','Manufacturer'), array('ItemAttributes','Brand'))), 'thumb' => array( 'Description' => __('URL to Thumbnail Image', 'amazon-link'), 'Live' => '1', 'Image' => '1', 'Group' => 'Images', 'Default' => 'http://images-eu.amazon.com/images/G/02/misc/no-img-lg-uk.gif', 'Position' => array(array('MediumImage','URL'))), 'image' => array( 'Description' => __('URL to Full size Image', 'amazon-link'), 'Live' => '1', 'Image' => '1', 'Group' => 'Images', 'Default' => 'http://images-eu.amazon.com/images/G/02/misc/no-img-lg-uk.gif', 'Position' => array(array('LargeImage','URL'), array('MediumImage','URL'))), 'image_class' => array( 'Description' => __('Class of Image as defined in settings', 'amazon-link')), 'url' => array( 'Description' => __('The URL returned from the Item Search (not localised!)', 'amazon-link'), 'Live' => '1', 'Group' => 'Small', 'Position' => array(array('DetailPageURL'))), 'rank' => array( 'Description' => __('Amazon Rank', 'amazon-link'), 'Live' => '1', 'Group' => 'SalesRank', 'Default' => '-', 'Position' => array(array('SalesRank'))), 'rating' => array( 'Description' => __('Numeric User Rating - (No longer Available)', 'amazon-link'), 'Live' => '1', 'Default' => '-', 'Position' => array(array('CustomerReviews','AverageRating'))), 'offer_price' => array( 'Description' => __('Best Offer Price of Item', 'amazon-link'), 'Live' => '1', 'Group' => 'Offers', 'Default' => '-', 'Position' => array(array('Offers','Offer','OfferListing','Price','FormattedPrice'), array('OfferSummary','LowestNewPrice','FormattedPrice'), array('OfferSummary','LowestUsedPrice','FormattedPrice'))), 'list_price' => array( 'Description' => __('List Price of Item', 'amazon-link'), 'Live' => '1', 'Group' => 'Offers', 'Default' => '-', 'Position' => array(array('ItemAttributes','ListPrice','FormattedPrice'))), 'price' => array( 'Description' => __('Price of Item (Combination of Offer then List Price)', 'amazon-link'), 'Live' => '1', 'Group' => 'Offers', 'Default' => '-', 'Position' => array(array('Offers','Offer','OfferListing','Price','FormattedPrice'), array('OfferSummary','LowestNewPrice','FormattedPrice'), array('OfferSummary','LowestUsedPrice','FormattedPrice'), array('ItemAttributes','ListPrice','FormattedPrice'))), 'text' => array( 'Description' => __('User Defined Text string', 'amazon-link'), 'User' => '1'), 'text1' => array( 'Description' => __('User Defined Text string', 'amazon-link'), 'User' => '1'), 'text2' => array( 'Description' => __('User Defined Text string', 'amazon-link'), 'User' => '1'), 'text3' => array( 'Description' => __('User Defined Text string', 'amazon-link'), 'User' => '1'), 'text4' => array( 'Description' => __('User Defined Text string', 'amazon-link'), 'User' => '1'), 'tag' => array( 'Description' => __('Localised Amazon Associate Tag', 'amazon-link')), 'cc' => array( 'Description' => __('Localised Country Code (us, uk, etc.)', 'amazon-link')), 'flag' => array( 'Description' => __('Localised Country Flag Image URL', 'amazon-link')), 'mplace' => array( 'Description' => __('Localised Amazon Marketplace Code (US, GB, etc.)', 'amazon-link')), 'mplace_id' => array( 'Description' => __('Localised Numeric Amazon Marketplace Code (2=uk, 8=fr, etc.)', 'amazon-link')), 'tld' => array( 'Description' => __('Localised Top Level Domain (.com, .co.uk, etc.)', 'amazon-link')), 'rcm' => array( 'Description' => __('Localised RCM site host domain (rcm.amazon.com, rcm-uk.amazon.co.uk, etc.)', 'amazon-link')), 'downloaded' => array( 'Description' => __('1 if Images are in the local Wordpress media library', 'amazon-link')), 'found' => array( 'Description' => __('1 if product was found doing a live data request (also 1 if live not enabled).', 'amazon-link')) ); $this->keywords = apply_filters('amazon_link_keywords', $this->keywords); } return $this->keywords; } function get_response_groups() { if (!isset($this->response_groups)) { $this->response_groups = array(); foreach ($this->get_keywords() as $key => $key_data) { if (isset($key_data['Group']) && !in_array($key_data['Group'],$this->response_groups)) $this->response_groups[] = $key_data['Group']; } $this->response_groups=implode(',',$this->response_groups); } return $this->response_groups; } function get_country_data() { if (!isset($this->country_data)) { /* Move Country Data construction here so we can localise the strings */ // Country specific aspects: // full name of country, // country flag image // market place of amazon site // tld of main amazon site // link to affiliate program site // Default tag if none set up $this->country_data = array('uk' => array('name' => __('United Kingdom', 'amazon-link'), 'lang' => 'en', 'flag' => $this->URLRoot. '/'. 'images/flag_uk.gif', 'market' => 'GB', 'm_id' => 2, 'tld' => 'co.uk', 'rcm' => 'rcm-uk.amazon.co.uk', 'site' => 'https://affiliate-program.amazon.co.uk', 'default_tag' => 'livpauls-21'), 'us' => array('name' => __('United States', 'amazon-link'), 'lang' => 'en', 'flag' => $this->URLRoot. '/'. 'images/flag_us.gif', 'market' => 'US', 'm_id' => 1, 'tld' => 'com', 'rcm' => 'rcm.amazon.com', 'site' => 'https://affiliate-program.amazon.com', 'default_tag' => 'lipawe-20'), 'de' => array('name' => __('Germany', 'amazon-link'), 'lang' => 'de', 'flag' => $this->URLRoot. '/'. 'images/flag_de.gif', 'market' => 'DE', 'm_id' => 3, 'tld' => 'de', 'rcm' => 'rcm-de.amazon.de', 'site' => 'https://partnernet.amazon.de', 'default_tag' => 'lipas03-21'), 'es' => array('name' => __('Spain', 'amazon-link'), 'lang' => 'es', 'flag' => $this->URLRoot. '/'. 'images/flag_es.gif', 'market' => 'ES', 'm_id' => 30, 'tld' => 'es', 'rcm' => 'rcm-es.amazon.es', 'site' => 'https://afiliados.amazon.es', 'default_tag' => 'livpauls0b-21'), 'fr' => array('name' => __('France', 'amazon-link'), 'lang' => 'fr', 'flag' => $this->URLRoot. '/'. 'images/flag_fr.gif', 'market' => 'FR', 'm_id' => 8, 'tld' => 'fr', 'rcm' => 'rcm-fr.amazon.fr', 'site' => 'https://partenaires.amazon.fr', 'default_tag' => 'lipas-21'), 'jp' => array('name' => __('Japan', 'amazon-link'), 'lang' => 'ja', 'flag' => $this->URLRoot. '/'. 'images/flag_jp.gif', 'market' => 'JP', 'm_id' => 9, 'tld' => 'jp', 'rcm' => 'rcm-jp.amazon.co.jp', 'site' => 'https://affiliate.amazon.co.jp', 'default_tag' => 'livpaul21-22'), 'it' => array('name' => __('Italy', 'amazon-link'), 'lang' => 'it', 'flag' => $this->URLRoot. '/'. 'images/flag_it.gif', 'market' => 'IT', 'm_id' => 29, 'tld' => 'it', 'rcm' => 'rcm-it.amazon.it', 'site' => 'https://programma-affiliazione.amazon.it', 'default_tag' => 'livpaul-21'), 'cn' => array('name' => __('China', 'amazon-link'), 'lang' => 'zh-CHS', 'flag' => $this->URLRoot. '/'. 'images/flag_cn.gif', 'market' => 'CN', 'm_id' => 28, 'rcm' => 'rcm-cn.amazon.cn', 'tld' => 'cn', 'site' => 'https://associates.amazon.cn', 'default_tag' => 'livpaul-23'), 'ca' => array('name' => __('Canada', 'amazon-link'), 'lang' => 'en', 'flag' => $this->URLRoot. '/'. 'images/flag_ca.gif', 'market' => 'CA', 'm_id' => 15, 'rcm' => 'rcm-ca.amazon.ca', 'tld' => 'ca', 'site' => 'https://associates.amazon.ca', 'default_tag' => 'lipas-20')); } return $this->country_data; } function get_default_templates() { if (!isset($this->default_templates)) { // Default templates include('include/defaultTemplates.php'); $this->default_templates= apply_filters('amazon_link_default_templates', $this->default_templates); } return $this->default_templates; } function get_option_list() { if (!isset($this->option_list)) { $this->option_list = array( /* Hidden Options - not saved in Settings */ 'nonce' => array ( 'Type' => 'nonce', 'Name' => 'update-AmazonLink-options' ), 'cat' => array ( 'Type' => 'hidden' ), 'last' => array ( 'Type' => 'hidden' ), 'template' => array( 'Type' => 'hidden' ), 'chan' => array( 'Type' => 'hidden' ), /* Options that change how the items are displayed */ 'hd1s' => array ( 'Type' => 'section', 'Value' => __('Display Options', 'amazon-link'), 'Section_Class' => 'al_subhead1'), 'text' => array( 'Name' => __('Link Text', 'amazon-link'), 'Description' => __('Default text to display if none specified', 'amazon-link'), 'Default' => 'www.amazon.co.uk', 'Type' => 'text', 'Size' => '40', 'Class' => 'al_border' ), 'image_class' => array ( 'Name' => __('Image Class', 'amazon-link'), 'Description' => __('Style Sheet Class of image thumbnails', 'amazon-link'), 'Default' => 'wishlist_image', 'Type' => 'text', 'Size' => '40', 'Class' => 'alternate al_border' ), 'wishlist_template' => array ( 'Default' => 'Wishlist', 'Name' => __('Wishlist Template', 'amazon-link') , 'Description' => __('Default template to use for the wishlist * AWS *', 'amazon-link'), 'Type' => 'selection', 'Class' => 'al_border' ), 'wishlist_items' => array ( 'Name' => __('Wishlist Length', 'amazon-link'), 'Description' => __('Maximum number of items to display in a wishlist (Amazon only returns a maximum of 5, for the \'Similar\' type of list) * AWS *', 'amazon-link'), 'Default' => 5, 'Type' => 'text', 'Class' => 'alternate al_border' ), 'wishlist_type' => array ( 'Name' => __('Wishlist Type', 'amazon-link'), 'Description' => __('Default type of wishlist to display, \'Similar\' shows items similar to the ones found, \'Random\' shows a random selection of the ones found * AWS *', 'amazon-link'), 'Default' => 'Similar', 'Options' => array('Similar', 'Random', 'Multi'), 'Type' => 'selection', 'Class' => 'al_border' ), /* Options that change the behaviour of the links */ 'multi_cc' => array('Name' => __('Multinational Link', 'amazon-link'), 'Description' => __('Insert links to all other Amazon sites after primary link.', 'amazon-link'), 'Default' => '1', 'Type' => 'checkbox', 'Class' => 'alternate al_border'), 'localise' => array('Name' => __('Localise Amazon Link', 'amazon-link'), 'Description' => __('Make the link point to the user\'s local Amazon website, (you must have ip2nation installed for this to work).', 'amazon-link'), 'Default' => '1', 'Type' => 'checkbox', 'Class' => 'al_border' ), 'global_over' => array('Name' => __('Global Defaults', 'amazon-link'), 'Description' => __('Default values in the shortcode "title=xxxx" affect all locales, if not set only override the default locale.', 'amazon-link'), 'Default' => '1', 'Type' => 'checkbox', 'Class' => 'alternate al_border' ), 'search_link' => array('Name' => __('Create Search Links', 'amazon-link'), 'Description' => __('Generate links to search for the items by "Author Title" for non local links, rather than direct links to the product by ASIN.', 'amazon-link'), 'Default' => '0', 'Type' => 'checkbox', 'Class' => 'al_border' ), 'search_text' => array( 'Name' => __('Default Search String', 'amazon-link'), 'Description' => __('Default items to search for with "Search Links", uses the same system as the Templates below.', 'amazon-link'), 'Default' => '%ARTIST% | %TITLE%', 'Type' => 'text', 'Size' => '40', 'Class' => 'alternate al_border' ), 'live' => array ( 'Name' => __('Live Data', 'amazon-link'), 'Description' => __('When creating Amazon links, use live data from the Amazon site, otherwise populate the shortcode with static information. * AWS *', 'amazon-link'), 'Default' => '1', 'Type' => 'checkbox', 'Class' => 'al_border' ), 'new_window' => array('Name' => __('New Window Link', 'amazon-link'), 'Description' => __('When link is clicked on, open it in a new browser window', 'amazon-link'), 'Default' => '0', 'Type' => 'checkbox', 'Class' => 'alternate' ), 'hd1e' => array ( 'Type' => 'end'), /* Options related to the Amazon backend */ 'hd2s' => array ( 'Type' => 'section', 'Value' => __('Amazon Associate Information','amazon-link'), 'Section_Class' => 'al_subhead1'), 'default_cc' => array( 'Name' => __('Default Country', 'amazon-link'), 'Hint' => __('The Amazon Affiliate Tags should be entered in the \'Channels\' section below', 'amazon-link'),'Description' => __('Which country\'s Amazon site to use by default', 'amazon-link'), 'Default' => 'uk', 'Type' => 'selection', 'Class' => 'al_border' ), 'aws_help' => array( 'Value' => __('AWS Access Keys', 'amazon-link'), 'Description' => __('The AWS Keys are required for some of the features of the plugin to work (The ones marked with AWS above), visit Amazon Web Services to sign up to get your own keys.', 'amazon-link'), 'Title_Class' => 'al_subheading', 'Id' => 'aws_notes', 'Default' => '', 'Type' => 'title', 'Class' => 'alternate al_border' ), 'pub_key' => array( 'Name' => __('AWS Public Key', 'amazon-link'), 'Description' => __('Access Key ID provided by your AWS Account, found under Security Credentials/Access Keys of your AWS account', 'amazon-link'), 'Default' => '', 'Type' => 'text', 'Size' => '40', 'Class' => 'alternate' ), 'priv_key' => array( 'Name' => __('AWS Private key', 'amazon-link'), 'Description' => __('Secret Access Key ID provided by your AWS Account.', 'amazon-link'), 'Default' => '', 'Type' => 'text', 'Size' => '40', 'Class' => '' ), 'aws_valid' => array ( 'Type' => 'checkbox', 'Read_Only' => 1, 'Name' => 'AWS Keys Validated', 'Default' => '0', 'Class' => 'al_border'), 'template_asins' => array( 'Name' => __('Template ASINs', 'amazon-link'), 'Description' => __('ASIN values to use when previewing the templates in the templates manager.', 'amazon-link'), 'Default' => '0893817449,0500410607,050054199X,0500286426,0893818755,050054333X,0500543178,0945506562', 'Type' => 'text', 'Size' => '40', 'Class' => 'al_border' ), 'debug' => array( 'Name' => __('Debug Output', 'amazon-link'), 'Description' => __('Adds hidden debug output to the page source to aid debugging. Do not enable on live sites.', 'amazon-link'), 'Default' => '0', 'Type' => 'checkbox', 'Size' => '40', 'Class' => 'al_border' ), 'hd2e' => array ( 'Type' => 'end'), 'hd3s' => array ( 'Type' => 'section', 'Value' => __('Amazon Data Cache','amazon-link'), 'Section_Class' => 'al_subhead1'), 'cache_age' => array ( 'Name' => __('Cache Data Age', 'amazon-link'), 'Description' => __('Max age in hours of the data held in the Amazon Link Cache', 'amazon-link'), 'Type' => 'text', 'Default' => '48', 'Class' => 'al_border'), 'cache_enabled' => array ( 'Type' => 'backend', 'Default' => '0'), 'cache_c' => array( 'Type' => 'buttons', 'Buttons' => array( __('Enable Cache', 'amazon-link' ) => array( 'Hint' => __('Install the sql database table to cache data retrieved from Amazon.', 'amazon-link'), 'Class' => 'button-secondary', 'Action' => 'AmazonLinkAction'), __('Disable Cache', 'amazon-link' ) => array( 'Hint' => __('Remove the Amazon Link cache database table.', 'amazon-link'),'Class' => 'button-secondary', 'Action' => 'AmazonLinkAction'), __('Flush Cache', 'amazon-link' ) => array( 'Hint' => __('Delete all data in the Amazon Link cache.', 'amazon-link'),'Class' => 'button-secondary', 'Action' => 'AmazonLinkAction'), )), 'hd3e' => array ( 'Type' => 'end') ); $country_data = $this->get_country_data(); // Populate Country related options foreach ($country_data as $cc => $data) { $this->option_list['default_cc']['Options'][$cc]['Name'] = $data['name']; } // Populate the hidden Template Keywords foreach ($this->get_keywords() as $keyword => $details) { if (!isset($this->option_list[$keyword])) $this->option_list[$keyword] = array( 'Type' => 'hidden' ); } $this->option_list = apply_filters('amazon_link_option_list', $this->option_list); $this->option_list['button'] = array( 'Type' => 'buttons', 'Buttons' => array( __('Update Options', 'amazon-link' ) => array( 'Class' => 'button-primary', 'Action' => 'AmazonLinkAction'))); } return $this->option_list; } function get_user_option_list() { $option_list = array( 'title' => array ( 'Type' => 'subhead', 'Value' => __('Amazon Link Affiliate IDs', 'amazon-link'), 'Description' => __('Valid affiliate IDs from all Amazon locales can be obtained from the relevant Amazon sites: ', 'amazon-link'), 'Class' => 'al_pad al_border'), ); $country_data = $this->get_country_data(); // Populate Country related options foreach ($country_data as $cc => $data) { $option_list ['tag_' . $cc] = array('Type' => 'text', 'Default' => '', 'Name' => 'On this page you can manage user provided or requested extra functionality for the Amazon Link plugin. These items are not part of the main Amazon Link plugin as they provide features that not every user wants and may have a negative impact on your site (e.g. reduced performance, extra database usage, etc.).
%' . strtoupper($keyword) . '%
'; } echo $text; } /*****************************************************************************************/ // Page/Post Edit Screen Widget function insertForm($post) { include('include/insertForm.php'); } /*****************************************************************************************/ /// Helper Functions /*****************************************************************************************/ function aws_signed_request($region, $params, $public_key, $private_key) { return include('include/awsRequest.php'); } function remove_parents ($array) { if (is_array($array)) { return $this->remove_parents($array[0]); } else { return $array; } } /*****************************************************************************************/ /// Do Amazon Link Constructs /*****************************************************************************************/ function showRecommendations ($categories='1', $last='30') { return include('include/showRecommendations.php'); } function get_local_info($settings = NULL) { if ($settings === NULL) $settings = $this->getSettings(); $channel = $this->get_channel($settings); $top_cc = $this->get_country($settings); $country_data = $this->get_country_data(); $info = array( 'flag' => $country_data[$top_cc]['flag'], 'cc' => $top_cc, 'rcm' => $country_data[$top_cc]['rcm'], 'mplace_id' => $country_data[$top_cc]['m_id'], 'mplace' => $country_data[$top_cc]['market'], 'tld' => $country_data[$top_cc]['tld'], 'tag' => $channel['tag_' . $top_cc], 'channel' => $channel['ID']); return $info; } function getURL($term, $tld, $tag) { $type = substr($term,0,1); $arg = substr($term,2); if ($type == 'A') $text='http://www.amazon.' . $tld . '/gp/product/'. $arg. '?ie=UTF8&linkCode=as2&camp=1634&creative=6738&tag=' . $tag .'&creativeASIN='. $arg; else if ($type == 'S') { $text='http://www.amazon.' . $tld . '/mn/search/?_encoding=UTF8&linkCode=ur2&camp=1634&creative=19450&tag=' . $tag. '&field-keywords=' . $arg; } else { $text='http://www.amazon.' . $tld . '/review/'. $arg. '?_encoding=UTF8&linkCode=ur2&camp=1634&creative=19450&tag=' . $tag. '&field-keywords=' . $arg; } return $text; } function grab($data, $keys, $default) { foreach ($keys as $location) { $result = $data; foreach ($location as $key) if (isset($result[$key])) {$result = $result[$key];} else {$result=NULL;break;} if (isset($result)) return $result; } if ($keys = '') return $data; // If no keys then return the whole item return $default; } function cached_query($request, $settings = NULL) { global $wpdb; $cache_table = $wpdb->prefix . $this->cache_table; if ($settings === NULL) $settings = $this->getSettings(); /* If not a request then must be a standard ASIN Lookup */ if (!is_array($request)) $asin = $request; if (TIMING) $time_start = microtime(true); $result = NULL; if ($settings['cache_enabled']) { // Check if asin is already in the cache $li = $this->get_local_info($settings); $cc = $li['cc']; if (!is_array($request)) { $sql = "SELECT xml FROM $cache_table WHERE asin LIKE '$asin' AND cc LIKE '$cc' AND updated >= DATE_SUB(NOW(),INTERVAL " . $settings['cache_age']. " HOUR)"; $result = $wpdb->get_row($sql, ARRAY_A); if ($result !== NULL) { $data[0] = unserialize($result['xml']); $data[0]['cached'] = 1; } } } //echo ""; print_r($data); echo ""; if (TIMING) {$time_taken = microtime(true)-$time_start;echo "";} if ($result === NULL) { if (TIMING) $time_start = microtime(true); // Create query to retrieve the an item if (!is_array($request)) { $request = array(); $request['Operation'] = 'ItemLookup'; $request['ItemId'] = $asin; $request['IdType'] = 'ASIN'; $request['ResponseGroup'] = $this->get_response_groups(); } else { $request['ResponseGroup'] = $this->get_response_groups(); } $pxml = $this->doQuery($request, $settings); if (TIMING) {$time_taken = microtime(true)-$time_start;echo "";} if (($pxml === False) || !isset($pxml['Items']['Item'])) { // Failed to return any results $data = array(array('ASIN' => $asin, 'found' => 0 )); $data['Error'] = (isset($pxml['Error']['Message'])? $pxml['Error']['Message'] : (isset($pxml['Items']['Request']['Errors']['Error']['Message']) ? $pxml['Items']['Request']['Errors']['Error']['Message'] : 'No Items Found')); return $data; } else { if (array_key_exists('ASIN', $pxml['Items']['Item'])) { // Returned a single result (not in an array) if (TIMING) $time_start = microtime(true); $items = array($pxml['Items']['Item']); } else { // Returned several results $items =$pxml['Items']['Item']; } $keywords = $this->get_keywords(); /* Extract useful information from the xml */ $data= array(); for ($index=0; $index < count($items); $index++ ) { $result = $items[$index]; foreach ($keywords as $keyword => $key_info) { if (isset($key_info['Live'])) { $key_data = $this->grab($result, $key_info['Position'], $key_info['Default']); if (isset($key_info['Filter'])) $key_data = apply_filters($key_info['Filter'], $key_data, $settings); $data[$index][$keyword] = $key_data; } } $data[$index]['asins'] = 0; $data[$index]['artist'] = $this->remove_parents($data[$index]['artist']); $data[$index]['type'] = 'Amazon'; $data[$index]['found'] = 1; /* Save each item to the cache if it is enabled */ if ($settings['cache_enabled']) { $sql = "DELETE FROM $cache_table WHERE asin LIKE '". $data[$index]['asin'] ."' AND cc LIKE '$cc'"; $wpdb->query($sql); $sql_data = array( 'asin' => $data[$index]['asin'], 'cc' => $cc, 'xml' => serialize($data[$index]), updated => current_time('mysql')); $wpdb->insert($cache_table, $sql_data); if (TIMING) {$time_taken = microtime(true)-$time_start;echo "";} } } } } return $data; } function doQuery($request, $Settings = NULL) { if ($Settings === NULL) $Settings = $this->getSettings(); else $this->Settings = $Settings; $li = $this->get_local_info($Settings); $tld = $li['tld']; if (!isset($request['AssociateTag'])) $request['AssociateTag'] = $li['tag']; return $this->aws_signed_request($tld, $request, $Settings['pub_key'], $Settings['priv_key']); } function make_link($asin, $object, $settings = NULL, $local_info = NULL, $search = NULL, $type = 'product') { if ($settings === NULL) $settings = $this->getSettings(); if ($local_info === NULL) $local_info = $this->get_local_info($settings); if ($search === NULL) $search = array('',''); if (!isset($settings['home_cc'])) $settings['home_cc'] = $settings['default_cc']; if ($settings['multi_cc']) { // Need to check all locales... $sep = '{'; $term =''; $countries = $this->get_country_data(); foreach ($countries as $country => $country_data) { if ($type == 'search' ) { $term .= $sep. $country .' : \'S-'. ($search[1]) .'\''; } else { if ($type == 'review') { $type = 'R-'; } else if ($type == 'product') { $type = 'A-'; } if (isset($asin[$country])) { $term .= $sep. $country .' : \''. $type. $asin[$country].'\''; } else if ($settings['search_link']) { $term .= $sep. $country .' : \'S-'. ($search[1]) .'\''; } else { $term .= $sep. $country .' : \''. $type. $asin[$settings['home_cc']].'\''; } } $sep = ','; } } $term .= '}'; if ($type == 'search' ) { $url_term = 'S-'. $search[0]; } else { if ($type == 'review') { $type = 'R-'; } else if ($type == 'product') { $type = 'A-'; } if (isset($asin[$local_info['cc']])) { // User Specified ASIN always use $url_term = $type . $asin[$local_info['cc']]; } else if ($settings['search_link'] && ($type == 'A-')) { $url_term = 'S-'.$search[0]; } else { $url_term = $type . $asin[$settings['home_cc']]; } } /* * Generate a localised/multinational link, wrapped around '$object' */ $TARGET = $settings['new_window'] ? 'target="_blank"' : ''; $URL = $this->getURL($url_term, $local_info['tld'], $local_info['tag']); if ($settings['multi_cc']) { $this->create_popup(); $text =''; $text .= $object. ''; $this->multi_id++; } else { $text='' . $object . ''; } return $text; } function make_links($asins, $link_text, $Settings = NULL) { global $post; if ($Settings === NULL) $Settings = $this->getSettings(); $local_info = $this->get_local_info($Settings); $output = ''; /* * If a template is specified and exists then populate it */ if (isset($Settings['template'])) { $template = strtolower($Settings['template']); $Templates = $this->getTemplates(); if (isset($Templates[$template])) { $Settings['template_content'] = $Templates[$template]['Content']; $Settings['template_type'] = $Templates[$template]['Type']; } } if (isset($Settings['template_content'])) { $details = array(); unset($Settings['asin']); if ($Settings['template_type'] == 'Multi') { /* Multi-product template collapse array back to a list, respecting country specific selection */ $sep = ''; $list=''; foreach ($asins as $i => $asin) { /* TODO: Check this! */ $list .= $sep .(is_array($asin) ? (isset($asin[$local_info['cc']]) ? $asin[$local_info['cc']] : $asin[$Settings['default_cc']]) : $asin); $sep=','; } $details[0] = $Settings; $details[0]['asins'][$local_info['cc']] = $list; } elseif ($Settings['template_type'] == 'No ASIN') { /* No asin provided so don't try and parse it */ $details[0] = $Settings; $details[0]['found'] = 1; } else { /* Usual case where user provides asin=X or asin=X,Y,Z */ for ($index=0; $index < count($asins); $index++ ) { if (count($asins) > 1) { $details[$index] = $Settings; $details[$index]['asin'] = $asins[$index]; $details[$index]['live'] = 1; } else { $details[$index] = $Settings; $details[$index]['asin'] = $asins[$index]; } } } if (!empty($details)) { foreach ($details as $item) { $output .= $this->search->parse_template($item); } } return $output; } foreach ($asins as $asin) { /* * This code required to maintain backward compatibility */ $object = stripslashes($link_text); // Do we need to display or link to an image ? if (!empty($Settings['image']) || !empty($Settings['thumb'])) { $media_ids = $this->search->find_attachments($asin); if (!is_wp_error($media_ids)) { $media_id = $media_ids[0]->ID; } if (!empty($Settings['thumb'])) { if (isset($media_id)) { $thumb = wp_get_attachment_thumb_url($media_id); } elseif (strlen($Settings['thumb']) > 4) { $thumb = $Settings['thumb']; } } if (!empty($Settings['image'])) { if (isset($media_id)) { $image = wp_get_attachment_url($media_id); } elseif (strlen($Settings['image']) > 4) { $image = $Settings['image']; } } } // If both thumb and image are specified then just insert the image if (isset($thumb) && isset($image)) { $object = '