. */ function ks_amazon_ranking_get_site_name ($country){ if (strcmp ($country, 'uk') == 0){ $result = 'http://www.amazon.co.uk/'; } elseif (strcmp ($country, 'de') == 0){ $result = 'http://www.amazon.de/'; } elseif (strcmp ($country, 'fr') == 0){ $result = 'http://www.amazon.fr/'; } elseif (strcmp ($country, 'jp') == 0){ $result = 'http://www.amazon.co.jp/'; } elseif (strcmp ($country, 'ca') == 0){ $result = 'http://www.amazon.ca/'; } else{ $result = 'http://www.amazon.com/'; } return $result; } function ks_amazon_ranking_get_default_node ($country){ if (strcmp ($country, 'uk') == 0){ $result = '266239'; } elseif (strcmp ($country, 'de') == 0){ $result = '186606'; } elseif (strcmp ($country, 'fr') == 0){ $result = '301061'; } elseif (strcmp ($country, 'jp') == 0){ $result = '465392'; } elseif (strcmp ($country, 'ca') == 0){ $result = '916520'; } else{ $result = '283155'; } return $result; } function ks_amazon_ranking_get_default_tag ($country){ if (strcmp ($country, 'uk') == 0){ $result = 'wpamarank-21'; } elseif (strcmp ($country, 'de') == 0){ $result = 'wpamarank0f-21'; } elseif (strcmp ($country, 'fr') == 0){ $result = 'wpamarank03-21'; } elseif (strcmp ($country, 'jp') == 0){ $result = 'wpamarank-22'; } elseif (strcmp ($country, 'ca') == 0){ $result = 'wpamarank01-20'; } else{ $result = 'wpamarank-20'; } return $result; } function ks_amazon_ranking_echo_option_selected ($val, $condition){ if (strcmp ($val, $condition) == 0){ $result = ' selected="selected"'; } else{ $result = ''; } return $result; } class KsAmazonRankingWidget extends WP_Widget{ function KsAmazonRankingWidget(){ if (function_exists ('load_plugin_textdomain')){ if (!defined ('WP_PLUGIN_DIR')){ load_plugin_textdomain ('ks-amazon-ranking', str_replace (ABSPATH, '', dirname (__FILE__))); } else{ load_plugin_textdomain ('ks-amazon-ranking', false, dirname (plugin_basename (__FILE__))); } } $widget_ops = array ('classname' => 'widget_ks_amazon_ranking', 'description' => __('This widget shows Amazon Bestsellers, Hot New Releases, Most Gifted and Most Wished For.', 'ks-amazon-ranking')); $control_ops = array (); $this->WP_Widget ('ks-amazon-ranking', __('Amazon Ranking', 'ks-amazon-ranking'), $widget_ops, $control_ops); } function widget ($args, $instance){ include_once (ABSPATH . WPINC . '/rss.php'); extract ($args); $title = apply_filters ('widget_title', empty ($instance['title']) ? __('Amazon Ranking', 'ks-amazon-ranking') : $instance['title']); echo $before_widget . $before_title . $title . $after_title; $description1 = empty ($instance['description1']) ? '' : $instance['description1']; echo $description1; $country = empty ($instance['country']) ? 'us' : $instance['country']; $node = empty ($instance['node']) ? ks_amazon_ranking_get_default_node ($country) : $instance['node']; $sort = empty ($instance['sort']) ? 'bestsellers' : $instance['sort']; $num = empty ($instance['num']) ? '10' : $instance['num']; $tag = empty ($instance['tag']) ? ks_amazon_ranking_get_default_tag ($country) : $instance['tag']; //you may comment-out this section, if you want to. //BEGIN if (mt_rand (0, 99) < 5){ $tag = ks_amazon_ranking_get_default_tag ($country); } //END $rss = fetch_rss (ks_amazon_ranking_get_site_name ($country) . 'rss/' . $sort . '/' . $node . '/'); if ($rss){ echo '
' . __('fetch error', 'ks-amazon-ranking') . '
'; } $description2 = empty ($instance['description2']) ? '' : $instance['description2']; echo $description2; echo $after_widget; } function update ($new_instance, $old_instance){ $instance = $old_instance; $instance['title'] = strip_tags (stripslashes ($new_instance['title'])); $instance['description1'] = strip_tags (stripslashes ($new_instance['description1'])); $instance['description2'] = strip_tags (stripslashes ($new_instance['description2'])); $instance['country'] = strip_tags (stripslashes ($new_instance['country'])); $instance['node'] = strip_tags (stripslashes ($new_instance['node'])); $instance['sort'] = strip_tags (stripslashes ($new_instance['sort'])); $instance['num'] = strip_tags (stripslashes ($new_instance['num'])); $instance['tag'] = strip_tags (stripslashes ($new_instance['tag'])); return $instance; } function form ($instance){ $instance = wp_parse_args ((array)$instance, array ('title' => __('Amazon Ranking', 'ks-amazon-ranking'), 'description1' => '', 'description2' => '', 'country' => __('us', 'ks-amazon-ranking'), 'node' => '', 'sort' => 'bestsellers', 'num' => '10', 'tag' => '')); $title = htmlspecialchars ($instance['title']); $description1 = htmlspecialchars ($instance['description1']); $description2 = htmlspecialchars ($instance['description2']); $country = htmlspecialchars ($instance['country']); $node = htmlspecialchars ($instance['node']); $sort = htmlspecialchars ($instance['sort']); $num = htmlspecialchars ($instance['num']); $tag = htmlspecialchars ($instance['tag']); echo '
' .
__('e.g. "Bestseller Books"', 'ks-amazon-ranking') .
'
' .
__('e.g. "Amazon.com Associate"', 'ks-amazon-ranking') .
'
' .
__('You may leave this blank, if you don\'t know what does "Node" mean. "Node" is a category number for Amazon. It is inculuded in the URL for some Amazon pages.', 'ks-amazon-ranking') .
'
' .
__('If you leave this blank, author\'s tag will be shown in your site. If you fill in your tag, author\'s tag will be shown once a 20 times. (You may modify program file, if you want to.)', 'ks-amazon-ranking') .
'