&text=] --> inserts link to amazon item [amazon cat=&last=] --> inserts table of random items Layout: amazon_container - Encloses whole wishlist. amazon_prod - Encloses each list item. amazon_img_container - Encloses the item thumbnail (link+img) amazon_pic - Class of the item thumbnail IMG element amazon_text_container - Encloses the item description (Title paragraphs+link + Details paragraphs) amazon_details - Encloses the item details part of the description amazon_price - Spans the item's formatted price. */ /******************************************************************************************************* To serve a page containing amazon links the plugin performs the following: * Queue the Amazon javascript and styles * Search through the content and widget text for Amazon links, for each one: * Parse arguments (get_options_list(>cached), get_country_data (>cached), get_options(>cached)) * Make Links: * get_templates (>cached) * for each ASIN: * (if live) perform itemLookup * parse results: * Get local Info:  * get channel   * get country [ip2n lookup >cached]  * get country data  * return country specific data * For each ASIN: * Check for local images * Make links * 5:  * get URL (get local info)  * get local info * Fill in template * If 'multinational' link found when doing the above then:   * Return all channels and user channels(>cached), create the javascript for the multinational popup. *******************************************************************************************************/ define (TIMING, False); require_once('include/displayForm.php'); //require_once('include/translate.php'); if (!class_exists('AmazonWishlist_ip2nation')) include_once ( 'include/ip2nation.php'); if (!class_exists('AmazonLinkSearch')) include_once ( 'include/amazonSearch.php'); if (!class_exists('AmazonWishlist_For_WordPress')) { class AmazonWishlist_For_WordPress { /*****************************************************************************************/ /// Settings: /*****************************************************************************************/ // String to insert into Posts to indicate where to insert the amazon items var $TagHead = '[amazon'; var $TagTail = ']'; var $cache_table = 'amazon_link_cache'; var $option_version= 6; var $plugin_version= '3.0.3'; var $optionName = 'AmazonLinkOptions'; var $user_options = 'amazonlinkoptions'; var $templatesName = 'AmazonLinkTemplates'; var $channels_name = 'AmazonLinkChannels'; var $settings_slug = 'amazon-link-options'; var $extras_slug = 'amazon-link-extras'; var $plugin_home = 'http://www.houseindorset.co.uk/plugins/amazon-link/'; var $multi_id = 0; var $scripts_done = False; var $tags = array(); /*****************************************************************************************/ // Constructor for the Plugin function AmazonWishlist_For_WordPress() { $this->__construct(); } function __construct() { $this->URLRoot = plugins_url("", __FILE__); $this->base_name = plugin_basename( __FILE__ ); $this->plugin_dir = dirname( $this->base_name ); $this->form = new AmazonWishlist_Options; $this->ip2n = new AmazonWishlist_ip2nation; $this->search = new AmazonLinkSearch; // Frontend & Backend Related register_activation_hook(__FILE__, array($this, 'activate')); // To perform options installation add_action('init', array($this, 'init')); // Load i18n and initialise translatable vars add_filter('the_content', array($this, 'content_filter'),15); // Process the content add_filter('widget_text', array($this, 'widget_filter'), 16 ); // Filter widget text (after the content?) // Backend only add_filter('plugin_row_meta', array($this, 'registerPluginLinks'),10,2); // Add extra links to plugins page add_action('admin_menu', array($this, 'admin_menu')); // Add options page and page/post edit hooks add_action('show_user_profile', array($this, 'show_user_options') ); // Display User Options add_action('edit_user_profile', array($this, 'show_user_options') ); // Display User Options add_action('personal_options_update', array($this, 'update_user_options')); // Update User Options add_action('edit_user_profile_update', array($this, 'update_user_options'));// Update User Options } /*****************************************************************************************/ // Functions for the above hooks // On activation of plugin - used to create default settings function activate() { $Opts = $this->getOptions(); $this->saveOptions($Opts); } function upgrade_settings($Opts) { include('include/upgradeSettings.php'); } // On wordpress initialisation - load text domain and register styles & scripts function init() { /* load localisation */ load_plugin_textdomain('amazon-link', $this->plugin_dir . '/i18n', $this->plugin_dir . '/i18n'); // Initialise dependent classes $this->search->init($this); $this->form->init($this); $this->ip2n->init($this); // Register our styles and scripts $script = plugins_url("amazon.js", __FILE__); $edit_script = plugins_url("postedit.js", __FILE__); $admin_script = plugins_url("include/amazon-admin.js", __FILE__); // Allow the user to override our default styles. if (file_exists(dirname (__FILE__).'/user_styles.css')) { $stylesheet = plugins_url("user_styles.css", __FILE__); } else { $stylesheet = plugins_url("Amazon.css", __FILE__); } wp_register_style('amazon-link-style', $stylesheet, false, $this->plugin_version); wp_register_script('amazon-link-script', $script, false, $this->plugin_version); wp_register_script('amazon-link-edit-script', $edit_script, array('jquery', 'amazon-link-search'), $this->plugin_version); wp_register_script('amazon-link-admin-script', $admin_script, false, $this->plugin_version); add_action('wp_enqueue_scripts', array($this, 'amazon_styles')); // Add base stylesheet do_action('amazon_link_init', $this->getOptions()); } // If in admin section then register options page and required styles & metaboxes function admin_menu() { // Add plugin options page, with load hook to bring in meta boxes and scripts and styles $this->opts_page = add_options_page( __('Manage Amazon Link Options', 'amazon-link'), __('Amazon Link', 'amazon-link'), 'manage_options', $this->settings_slug, array($this, 'show_options_page')); add_action('load-'.$this->opts_page, array(&$this, 'load_options_page')); add_action( "admin_print_styles-" . $this->opts_page, array($this,'amazon_admin_styles') ); add_action( "admin_print_scripts-" . $this->opts_page, array($this,'amazon_admin_scripts') ); // Add plugin extras page, with load hook to bring in meta boxes and scripts and styles $this->extras_page = add_plugins_page( __('Manage Amazon Link Extras', 'amazon-link'), __('Amazon Link Extras', 'amazon-link'), 'activate_plugins', $this->extras_slug, array($this, 'show_extras_page')); add_action('load-'.$this->extras_page, array(&$this, 'load_extras_page')); add_action( "admin_print_styles-" . $this->extras_page, array($this,'amazon_admin_styles') ); add_action( "admin_print_scripts-" . $this->extras_page, array($this,'amazon_admin_scripts') ); // Add support for Post edit metabox, this requires our styles and post edit AJAX scripts. $post_types = get_post_types(); foreach ( $post_types as $post_type ) { add_meta_box('amazonLinkID', 'Add Amazon Link', array($this,'insertForm'), $post_type, 'normal'); } add_action( "admin_print_scripts-post.php", array($this,'edit_scripts') ); add_action( "admin_print_scripts-post-new.php", array($this,'edit_scripts') ); add_action( "admin_print_styles-post-new.php", array($this,'amazon_admin_styles') ); add_action( "admin_print_styles-post.php", array($this,'amazon_admin_styles') ); } function admin_help($contextual_help, $page, $screen) { if ($page== $this->opts_page ) { $contextual_help = __('Use this page to set up the global settings, provide Affiliate tags for each country locale, configure your AWS keys and select and edit any Templates you might require.','amazon-link'); } return $contextual_help; } // Hooks required to bring up options page with meta boxes: function load_options_page() { $screen = get_current_screen(); add_filter('screen_layout_columns', array(&$this, 'adminColumns'), 10, 2); wp_enqueue_script('common'); wp_enqueue_script('wp-lists'); wp_enqueue_script('postbox'); add_meta_box( 'alOptions', __( 'Options', 'amazon-link' ), array (&$this, 'show_options' ), $this->opts_page, 'normal', 'core' ); add_meta_box( 'alChannels', __( 'Amazon Tracking ID Channels', 'amazon-link' ), array (&$this, 'show_channels' ), $this->opts_page, 'normal', 'core' ); add_meta_box( 'alInfo', __( 'About', 'amazon-link' ), array (&$this, 'show_info' ), $this->opts_page, 'side', 'core' ); add_meta_box( 'alTemplateHelp', __( 'Template Help', 'amazon-link' ), array (&$this, 'displayTemplateHelp' ), $this->opts_page, 'side', 'low' ); add_meta_box( 'alTemplates', __( 'Templates', 'amazon-link' ), array (&$this, 'show_templates' ), $this->opts_page, 'advanced', 'core' ); add_meta_box( 'alManageTemplates', __( 'Default Templates', 'amazon-link' ), array (&$this, 'show_default_templates' ), $this->opts_page, 'advanced', 'low' ); if ( $screen->id != $this->opts_page) return; // Add Contextual Help $screen->add_help_tab( array( 'id' => 'amazon-options-tab', 'title' => __('Options', 'amazon-link'), 'content' => '

' . __('Use this section to set up the global Display Options that change how links are displayed and their behaviour, to enable advance options like \'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') . '

' . '

' . __('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') . '

') ); $screen->add_help_tab( array( 'id' => 'amazon-channels-tab', 'title' => __('Channels', 'amazon-link'), 'content' => '

' . __('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') . '

') ); $screen->add_help_tab( array( 'id' => 'amazon-templates-tab', 'title' => __('Templates', 'amazon-link'), 'content' => '

' . __('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 % delimited keywords that are replaced by appropriate product information, see the \'Template Help\' section for a list of all valid keywords.','amazon-link') . '

') ); $screen->add_help_tab( array( 'id' => 'amazon-templates-help-tab', 'title' => __('Templates Keywords', 'amazon-link'), 'callback'=> array($this, 'displayTemplateHelp')) ); $screen->add_help_tab( array( 'id' => 'amazon-templates-default-tab', 'title' => __('Default Templates', 'amazon-link'), 'content'=> '

' . __('This section lists all the default templates included with the plugin, use it to re-install or your update your active templates.','amazon-link') . '

') ); $screen->set_help_sidebar('

'. __('For more information:', 'amazon-link'). '

' . '

' . __('Plugin Home Page','amazon-link') . '

' . '

' . __('Plugin FAQ','amazon-link') . '

' . '

' . __('Channels Help','amazon-link') . '

' . '

' . __('Template Help','amazon-link') . '

'); } // Hooks required to bring up extras page with meta boxes: function load_extras_page() { $screen = get_current_screen(); add_filter('screen_layout_columns', array(&$this, 'adminColumns'), 10, 2); wp_enqueue_script('common'); wp_enqueue_script('wp-lists'); wp_enqueue_script('postbox'); add_meta_box( 'alExtras', __( 'Extras', 'amazon-link' ), array (&$this, 'show_extras' ), $this->extras_page, 'normal', 'core' ); if ( $screen->id != $this->extras_page) return; // Add Contextual Help $screen->add_help_tab( array( 'id' => 'amazon-extras-tab', 'title' => __('Extras', 'amazon-link'), 'content' => '

' . __('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') . '

') ); $screen->add_help_tab( array( 'id' => 'amazon-filters-tab', 'title' => __('Filters', 'amazon-link'), 'content' => '

' . __('The plugin exposes three filters that can be accessed via the standard WordPress Filter API:','amazon-link') . '