Index: tumblr-importer.php
===================================================================
--- tumblr-importer.php	(revision 626363)
+++ tumblr-importer.php	(working copy)
@@ -49,7 +49,6 @@
 	function __construct() {
 		add_action( 'tumblr_importer_metadata', array( $this, 'tumblr_importer_metadata' ) );
 		add_filter( 'tumblr_importer_format_post', array( $this, 'filter_format_post' ) );
-		add_filter( 'tumblr_importer_get_consumer_key', array( $this, 'get_consumer_key' ) );
 		add_filter( 'wp_insert_post_empty_content', array( $this, 'filter_allow_empty_content' ), 10, 2 );
 		parent::__construct();
 	}
@@ -60,16 +59,15 @@
 			$this->restart();
 			
 		if ( !isset($this->error) ) $this->error = null;
+	
+		$this->set_tumblr_keys();	
 		
-		$this->consumerkey = defined ('TUMBLR_CONSUMER_KEY') ? TUMBLR_CONSUMER_KEY : ( !empty($_POST['consumerkey']) ? $_POST['consumerkey'] : $this->consumerkey );
-		$this->secretkey = defined ('TUMBLR_SECRET_KEY') ? TUMBLR_SECRET_KEY : ( !empty($_POST['secretkey']) ? $_POST['secretkey'] : $this->secretkey );
-		
 		// if we have access tokens, verify that they work
 		if ( !empty( $this->access_tokens ) ) {
 			// TODO
 		} else if ( isset( $_GET['oauth_verifier'] ) ) {
 			$this->check_permissions();
-		} else if ( !empty( $this->consumerkey ) && !empty( $this->secretkey ) ) {
+		} else if ( !empty( $this->consumer_key ) && !empty( $this->secret_key ) ) {
 			$this->check_credentials();
 		}
 		if ( isset( $_POST['blogurl'] ) ) {
@@ -123,12 +121,12 @@
 		<form action='?import=tumblr' method='post'>
 			<table class="form-table">
 				<tr>
-					<th scope="row"><label for='consumerkey'><?php _e('OAuth Consumer Key:','tumblr-importer'); ?></label></label></th>
-					<td><input type='text' class="regular-text" name='consumerkey' value='<?php if (isset($this->consumerkey)) echo esc_attr($this->consumerkey); ?>' /></td>
+					<th scope="row"><label for='consumer_key'><?php _e('OAuth Consumer Key:','tumblr-importer'); ?></label></label></th>
+					<td><input type='text' class="regular-text" name='consumer_key' value='<?php if (isset($this->consumer_key)) echo esc_attr($this->consumer_key); ?>' /></td>
 				</tr>
 				<tr>
-					<th scope="row"><label for='secretkey'><?php _e('Secret Key:','tumblr-importer'); ?></label></label></th>
-					<td><input type='text' class="regular-text" name='secretkey' value='<?php if (isset($this->secretkey)) echo esc_attr($this->secretkey); ?>' /></td>
+					<th scope="row"><label for='secret_key'><?php _e('Secret Key:','tumblr-importer'); ?></label></label></th>
+					<td><input type='text' class="regular-text" name='secret_key' value='<?php if (isset($this->secret_key)) echo esc_attr($this->secret_key); ?>' /></td>
 				</tr>
 			</table>
 			<p class='submit'>
@@ -172,7 +170,7 @@
 		// get the access_tokens
 		$url = 'http://www.tumblr.com/oauth/access_token';
 		
-		$params = array('oauth_consumer_key' => $this->consumerkey,
+		$params = array('oauth_consumer_key' => $this->consumer_key,
 				"oauth_nonce" => time().rand(),
 				"oauth_timestamp" => time(),
 				"oauth_token" => $this->request_tokens['oauth_token'],
@@ -181,7 +179,7 @@
 				"oauth_version" => "1.0",
 				);
 
-		$params['oauth_signature'] = $this->oauth_signature(array($this->secretkey,$this->request_tokens['oauth_token_secret']), 'GET', $url, $params);
+		$params['oauth_signature'] = $this->oauth_signature(array($this->secret_key,$this->request_tokens['oauth_token_secret']), 'GET', $url, $params);
 
 		$url = add_query_arg( array_map('urlencode', $params), $url);
 		$response = wp_remote_get( $url );		
@@ -670,20 +668,20 @@
 	 *
 	 */
 	 function oauth_get_request_token() {
-		if ( empty($this->consumerkey) || empty ($this->secretkey) )
+		if ( empty($this->consumer_key) || empty ($this->secret_key) )
 			return false;
 	 	
 	 	$url = 'http://www.tumblr.com/oauth/request_token';
 	 
 	 	$params = array('oauth_callback' => urlencode( self_admin_url('admin.php?import=tumblr') ),
-	 			'oauth_consumer_key' => $this->consumerkey,
+	 			'oauth_consumer_key' => $this->consumer_key,
 	 			"oauth_version" => "1.0",
 	 			"oauth_nonce" => time(),
 	 			"oauth_timestamp" => time(),
 	 			"oauth_signature_method" => "HMAC-SHA1",
 	 			);
 	 	
-	 	$params['oauth_signature'] = $this->oauth_signature(array($this->secretkey,''), 'POST', $url, $params);
+	 	$params['oauth_signature'] = $this->oauth_signature(array($this->secret_key,''), 'POST', $url, $params);
 	 	
 	 	$response = wp_remote_post( $url, array('body' => $params));
 	 	
@@ -730,8 +728,23 @@
 		return $this->blogs;
 	}
 
-	function get_consumer_key() {
-		return $this->consumerkey;
+	function set_tumblr_keys() {
+		global $wp_version;
+
+		$keys = get_site_transient( 'tumblr_consumer_key' );
+		if ( ! $keys ) {
+                	//$url = 'http://api.wordpress.org/core/importers/1.0/';
+                	$url = 'http://oddbird.org/tumblr/';
+                	$options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url() );
+                	$keys = maybe_unserialize( wp_remote_retrieve_body( wp_remote_get( $url, $options ) ) );
+
+			if ( is_array( $keys ) )
+				set_site_transient( 'tumblr_consumer_key', $keys, 1 * DAY_IN_SECONDS );
+			else
+				return false;
+		}
+		$this->consumer_key = $keys['consumer_key'];
+		$this->secret_key = $keys['secret_key'];
 	}
 
 	/**
@@ -754,7 +767,7 @@
 			$params = array(
 				'offset'  => $start,
 				'limit'   => $count,
-				'api_key' => apply_filters( 'tumblr_importer_get_consumer_key', '' ),
+				'api_key' => $this->consumer_key,
 			);
 			$url = add_query_arg( $params, $url );
 		}
@@ -978,7 +991,7 @@
 		if ( empty( $this->access_tokens ) ) 
 			return false;
 	
-		$params = array('oauth_consumer_key' => $this->get_consumer_key(),
+		$params = array('oauth_consumer_key' => $this->consumer_key,
 				"oauth_nonce" => time(),
 				"oauth_timestamp" => time(),
 				"oauth_token" => $this->access_tokens['oauth_token'],
@@ -986,7 +999,7 @@
 				"oauth_version" => "1.0",
 				);
 
-		$params['oauth_signature'] = $this->oauth_signature(array($this->secretkey,$this->access_tokens['oauth_token_secret']), 'GET', $url, $params);
+		$params['oauth_signature'] = $this->oauth_signature(array($this->secret_key,$this->access_tokens['oauth_token_secret']), 'GET', $url, $params);
 
 		$url = add_query_arg( array_map('urlencode', $params), $url);
 
