_db_table = $wpdb->prefix . "amz_servers"; $this->_pluginURL = get_option('siteurl') . '/wp-content/plugins/amazon-search'; $this->_ip2Nation = new AMZ_ip2nation; } function getSearch() { if (!isset($this->_search)) { require_once( 'amz-searchBox.php' ); $this->_search = new AMZ_Search; } return $this->_search; } function isCURLinstalled() { return function_exists( 'curl_init' ); } function addHeaderCode() { echo '' . "\n"; // check for CSS file specific to this theme $template = get_option('template'); if ( $template !== "default" ) { $theme_css = getcwd() . '/wp-content/plugins/amazon-search/css/' . $template . '.css'; if ( is_readable( $theme_css ) ) echo '' . "\n"; } } function db_install() { global $wpdb; $table_name = $this->_db_table; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { $sql = "CREATE TABLE {$table_name} ( id enum('com','ca','uk','fr','de','jp') NOT NULL default 'com', server enum('amazon.com','amazon.ca','amazon.co.uk','amazon.fr','amazon.de','amazon.co.jp') NOT NULL default 'amazon.com', assoc_server enum('affiliate-program.amazon.com','associates.amazon.ca','affiliate-program.amazon.co.uk','partenaires.amazon.fr','partnernet.amazon.de','affiliate.amazon.co.jp') NOT NULL default 'affiliate-program.amazon.com', default_tag enum('imol-20','imol0a-20','imol-21','imol08-21','imol05-21','imol-22') NOT NULL default 'imol-20', user_tag varchar(32) default NULL, PRIMARY KEY (id), UNIQUE KEY server (server) ) PACK_KEYS=1 "; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); $_DATA[] = "INSERT IGNORE INTO {$table_name} VALUES ('com', 'amazon.com', 'affiliate-program.amazon.com', 'imol-20', '')"; $_DATA[] = "INSERT IGNORE INTO {$table_name} VALUES ('ca', 'amazon.ca', 'associates.amazon.ca', 'imol0a-20', '')"; $_DATA[] = "INSERT IGNORE INTO {$table_name} VALUES ('uk', 'amazon.co.uk', 'affiliate-program.amazon.co.uk', 'imol-21', '')"; $_DATA[] = "INSERT IGNORE INTO {$table_name} VALUES ('fr', 'amazon.fr', 'partenaires.amazon.fr', 'imol08-21', '')"; $_DATA[] = "INSERT IGNORE INTO {$table_name} VALUES ('de', 'amazon.de', 'partnernet.amazon.de', 'imol05-21', '')"; $_DATA[] = "INSERT IGNORE INTO {$table_name} VALUES ('jp', 'amazon.co.jp', 'affiliate.amazon.co.jp', 'imol-22', '')"; foreach ($_DATA as $insert) { $results = $wpdb->query( $insert ); } add_option("AMZ_db_version", $this->_version); } } function getAdminOptions() { $adminOptions = array( 'contribute' => '4', 'default_category' => 'Blended', 'default_search' => 'WordPress', 'default_server' => 'com', 'image_size' => 'Medium', 'search_count' => '0', 'xsl' => $this->_pluginURL . '/xsl/wp-amz-search.xsl', 'use_text_links' => true, 'use_ip2nation' => true, 'use_searching' => true, 'use_tinymce' => true, ); $savedOptions = get_option($this->_adminOptionsName); $dirty = false; if (!empty($savedOptions)) { foreach ($savedOptions as $key => $option) { if ( $adminOptions[$key] != $option ) { $dirty = true; $adminOptions[$key] = $option; } } } if ( $dirty ) update_option($this->_adminOptionsName, $adminOptions); if ( !$this->isCURLinstalled() ) $adminOptions['use_searching'] = false; return $adminOptions; } function getServerInfo( $serverID ) { global $wpdb; $_AMZ_PREFS = $this->getAdminOptions(); // Get the server info $sql = 'SELECT * FROM ' . $this->_db_table . ' WHERE id="' . $serverID .'"'; $server_info = $wpdb->get_row($sql, ARRAY_A); if ( $server_info['user_tag'] == NULL ) { $server_info['user_tag'] = $server_info['default_tag']; } else if ( $_AMZ_PREFS['contribute'] > 0 ) { $_AMZ_PREFS['search_count'] += 1; if ( $_AMZ_PREFS['search_count'] >= $_AMZ_PREFS['contribute'] ) { $server_info['user_tag'] = $server_info['default_tag']; $_AMZ_PREFS['search_count'] = 0; } // Update the search count update_option($this->_adminOptionsName, $_AMZ_PREFS); } return $server_info; } function printAdminPage() { global $wpdb; $display = ''; $_AMZ_PREFS = $this->getAdminOptions(); // Check for and save updated prefs if ( isset( $_POST['Save'] ) ) { check_admin_referer('amz_search-admin_options'); $new_prefs = $_POST['new_prefs']; // workaround for HTML being braindead - it only passes checkboxes which are 'on' $_AMZ_PREFS['use_text_links'] = false; $_AMZ_PREFS['use_ip2nation'] = false; $_AMZ_PREFS['use_searching'] = false; $_AMZ_PREFS['use_tinymce'] = false; foreach ( $new_prefs as $pref => $value ) { if (isset($new_prefs[$pref])) { $_AMZ_PREFS[$pref] = $new_prefs[$pref]; } } if ( !$this->isCURLinstalled() ) $_AMZ_PREFS['use_searching'] = false; update_option($this->_adminOptionsName, $_AMZ_PREFS); $results = $wpdb->get_results('SELECT * FROM ' . $this->_db_table, ARRAY_A); foreach ($results as $server_info) { $associate_id = trim( $_POST['usertag'][$server_info['id']] ); $sql = 'UPDATE ' . $this->_db_table . " SET user_tag='$associate_id' WHERE id='{$server_info['id']}'"; $wpdb->query($sql); } $display .= '
Settings Updated.