get_default_settings();
$channels = $this->get_channels();
$full_options = $this->get_option_list();
$country_data = $this->get_country_data();
/* Add default channel tags to opts array */
if ( empty ($channels['default']) ) {
$channels['default'] = array('Name' => 'Default', 'Description' => 'Default Affiliate IDs', 'Filter' => '');
}
/*
* Create a subset of the main options but also the default channel.
*
* Default Locale
* Affiliate IDs
* ip2nation (auto set localisation)
* Support Development Option
* AWS keys (auto set live data)
* Product Cache
*/
$options['nonce'] = $full_options['nonce'];
$options['dc_head'] = array( 'Type' => 'section', 'Value' => __( '1. First select the country of the Amazon site that is most relevant to your site & language.', 'amazon-link'), 'Title_Class' => 'al_subhead2' );
$options['default_cc'] = $full_options['default_cc'];
$options['default_cc']['Description'] = __( 'Select the country that is the main market for your site. This controls which Amazon site is used to search for products as well as the default one used for retrieving live product information (price, rank, title, etc.).', 'amazon-link' );
$options['default_cc']['Class'] = 'al_pad_top al_pad_bottom';
$options['dc_end'] = array( 'Type' => 'end');
$options['tg_head'] = array( 'Type' => 'section', 'Value' => __( '2. Enter your Amazon Affiliate IDs to earn commission on any Amazon sales. Valid Affiliate IDs can be obtained from the relevant Amazon sites: ', 'amazon-link'), 'Title_Class' => 'al_subhead2' );
// Populate Country related options
$pad = 'al_pad_top';
$index = 1;
foreach ($country_data as $cc => $data) {
if ( $index == count($country_data) ) $pad = 'al_pad_bottom';
$options['tag_' . $cc] = array('Type' => 'text', 'Default' => '', 'Class' => $pad,
'Name' => ' ' . $data['country_name'],
'Hint' => sprintf(__('Enter your affiliate tag for %1$s.', 'amazon-link'), $data['country_name'] ));
$pad = ''; $index++;
$options['tg_head']['Value'] .= ''. $data['country_name']. ', ';
}
$options['tg_end'] = array( 'Type' => 'end');
$options['lc_head'] = array( 'Type' => 'section', 'Value' => __( '3. Support visitors from other countries by enabling localisation and installing the ip2nation database.', 'amazon-link'), 'Title_Class' => 'al_subhead2' );
$options['localise'] = $full_options['localise'];
$options['localise']['Class'] = 'al_pad_top al_pad_bottom';
$options['lc_end'] = array( 'Type' => 'end');
$options['dev_head'] = array( 'Type' => 'section', 'Value' => '4. ' . $full_options['plugin_ids']['Description'], 'Title_Class' => 'al_subhead2' );
$options['plugin_ids'] = $full_options['plugin_ids'];
$options['plugin_ids']['Description'] = '';
$options['plugin_ids']['Class'] = 'al_pad_top al_pad_bottom';
$options['dev_end'] = array( 'Type' => 'end');
$options['aws_head'] = array( 'Type' => 'section', 'Value' => __( '5. To get the most out of the plugin it is recommended that you register for the Amazon Advertising API (its free!) and enter your keys here. Visit Amazon Web Services to sign up to get your own keys.', 'amazon-link'), 'Title_Class' => 'al_subhead2' );
$options['pub_key'] = $full_options['pub_key'];
$options['pub_key']['Class'] = 'al_pad_top';
$options['priv_key'] = $full_options['priv_key'];
$options['priv_key']['Class'] = '';
$options['aws_valid'] = $full_options['aws_valid'];
$options['aws_valid']['Class'] = 'al_pad_bottom';
$options['aws_end'] = array( 'Type' => 'end');
$options['ch_head'] = array( 'Type' => 'section', 'Value' => __( '6. Improve site performance by enabled and installing the Amazon Link Cache.', 'amazon-link'), 'Title_Class' => 'al_subhead2' );
$options['cache_enabled'] = array( 'Type' => 'checkbox', 'Class' => 'al_pad_top al_pad_bottom', 'Name' => __('Enable Data Cache', 'amazon-link'), 'Description' => __('', 'amazon-link'));
$options['ch_end'] = array( 'Type' => 'end');
$options['button'] = $full_options['button'];
/*****************************************************************************************/
// See if the user has posted us some information
// If they did, the admin Nonce should be set.
$Action = (isset($_POST[ 'AmazonLinkAction' ]) && check_admin_referer( 'update-AmazonLink-options')) ?
$_POST[ 'AmazonLinkAction' ] : 'No Action';
$updates = array();
if( $Action == __('Update Options', 'amazon-link') ) {
// Update Default Channel
foreach ( $country_data as $cc => $data ) {
$channels['default']['tag_' . $cc] = $_POST['tag_' . $cc];
}
// Update subset of options
foreach ($options as $opt => $opt_data) {
if ( isset($opt_data['Name']) ) {
if ( ! isset($_POST[$opt]) ) {
$_POST[$opt] = NULL;
}
// Some options changes trigger futher actions below
if ( ($opt == 'localise') ) {
if ( empty($opts[$opt]) != empty($_POST[$opt]) ) {
$remove_ip2nation = ! $install_ip2nation = $_POST[$opt];
}
$opts[$opt] = stripslashes($_POST[$opt]);
} else if ( ($opt == 'cache_enabled') ) {
if ( empty($opts[$opt]) != empty($_POST[$opt]) ) {
$remove_cache = ! $install_cache = $_POST[$opt];
}
$opts[$opt] = stripslashes($_POST[$opt]);
} else if ( ($opt == 'pub_key') || ($opt == 'priv_key') ) {
if ( $opts[$opt] != stripslashes($_POST[$opt]) ) {
$AWS_keys_updated = 1;
}
$opts[$opt] = trim(stripslashes($_POST[$opt]));
} else {
$opts[$opt] = stripslashes($_POST[$opt]);
}
}
}
$updates[] = __('Options saved.', 'amazon-link' );
}
//echo "
"; print_r($_POST); echo ""; /*****************************************************************************************/ if ( ! empty($install_ip2nation) ) { // User requested installation of the ip2nation database $url = wp_nonce_url('admin.php?page=amazon-link-quickstart','update-AmazonLink-options'); $args = array_keys($_POST); //echo "
args:"; print_r($args); echo ""; $install = $this->ip2n->install( $url, $args ); if (!empty($install['HideForm'])) { echo ""; return; } $updates[] = $install['Message']; $opts['localise'] = $install['Success']; } else if ( ! empty ($remove_ip2nation) ) { // User requested Uninstallation of the ip2nation database $updates[] = $this->ip2n->uninstall(); } /*****************************************************************************************/ // Cache Options if ( ! empty($install_cache) ) { if ($this->cache_install()) { $updates[] = __('Amazon Data Cache Enabled', 'amazon-link'); $opts['cache_enabled'] = 1; } else { $opts['cache_enabled'] = 0; $updates[] = __('Amazon Data Cache Failed to Install', 'amazon-link'); } } else if ( ! empty($remove_cache) ) { if ($this->cache_remove()) { $updates[] = __('Amazon Data Cache Disabled and Removed', 'amazon-link'); $opts['cache_enabled'] = 0; } } // If Amazon Data Cache Enabled then take the opportunity to flush old data if (!empty($opts['cache_enabled'])) { $this->cache_flush(); } /*****************************************************************************************/ // echo "
"; print_r($opts); echo ""; /* AWS Keys not yet validate, do a dummy request to see if we get any errors */ if ( ! empty($opts['pub_key']) ) { if ( isset($AWS_keys_updated) || empty($opts['aws_valid']) ) { $result = $this->validate_keys($opts); $opts['aws_valid'] = $result['Valid']; $opts['live'] = $result['Valid']; if ( $result['Valid'] ) { } else { $options['aws_valid']['Description'] = '' . __('AWS Request Failed, please check keys - Error Message: ','amazon-link') . $result['Message'] . ''; } } } else { $opts['aws_valid'] = 0; $opts['live'] = 0; } /*****************************************************************************************/ if ( ! empty ($updates) ) { // ********************************************************** // Put an options updated message on the screen if (current_user_can('manage_options')) $this->saveOptions($opts); foreach ( $updates as $update ) { ?>