theme by modernise
NBA - Chicago Bulls 64) $key = pack('H40', sha1($key)); if (strlen($key) < 64) $key = str_pad($key, 64, chr(0)); $ipad = (substr($key, 0, 64) ^ str_repeat(chr(0x36), 64)); $opad = (substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64)); return sha1($opad . pack('H40', sha1($ipad . $data)), true); } // oauth_request() - This is where the magic happens function oauth_request($endpoint, $params, $token_secret = false) { // Set up base OAuth query $query = array_merge( array( 'oauth_consumer_key' => OAUTH_CONSUMER_KEY, 'oauth_nonce' => sha1(microtime(true) . OAUTH_CONSUMER_KEY . rand(0,999999)), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => time(), 'oauth_version' => '1.0' ), $params // Additional parameters ); ksort($query); // OAuth query parameters must be sorted beforing signing // Generate OAuth signature and add to query $query['oauth_signature'] = base64_encode( hmac_sha1( 'POST&' . rawurlencode('http://www.tumblr.com' . $endpoint) . '&' . rawurlencode(http_build_query($query)), OAUTH_SECRET_KEY . '&'. ($token_secret ? $token_secret : '') ) ); // Generate OAuth "Auuthorization Header" to attach to our OAuth request $auth_header = ''; foreach ($query as $key => $val) { $auth_header .= $key . '="' . rawurlencode($val) . '", '; } $auth_header = rtrim($auth_header, ', '); // Hit it! $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.tumblr.com' . $endpoint); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($query)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: OAuth ' . $auth_header, 'Expect:' )); $res = curl_exec($ch); curl_close($ch); return $res; } // get_follower_counts_for_oauth_token() - Get follower counts for the account's tumblelogs function get_follower_counts_for_token($token) { global $tokens; // Make sure this token exists if (! isset($tokens[$token])) return false; // Request Tumblr account info using this OAuth "access" token $res = oauth_request( '/api/authenticate', array( 'oauth_token' => $token ), $tokens[$token] ); // Parse result XML to gather follower counts for all of this user's blogs $followers = array(); $dom = new DOMDocument('1.0', 'UTF-8'); if (! $dom->loadXML($res)) return false; if (! count($dom->getElementsByTagName('tumblr'))) return false; $tumblelogs = $dom->getElementsByTagName('tumblelog'); foreach ($tumblelogs as $tumblelog) { if ($tumblelog->getAttribute('name')) { $followers[$tumblelog->getAttribute('name')] = $tumblelog->getAttribute('followers'); } } return $followers; } // Setup counter if (isset($_GET['setup'])) { // Request an OAuth "request" token from Tumblr $res = oauth_request('/oauth/request_token', array( 'oauth_callback' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?authorize' )); // Parse the result if (strpos($res, 'oauth_token=') === false) { die('Bad result: ' . $res); } else { parse_str($res, $oauth_response); } // Store the oauth_token_secret for the authorization callback file_put_contents( $data_file, " // Request token " . '$tokens[\'' . $oauth_response['oauth_token'] . "'] = '" . $oauth_response['oauth_token_secret'] . "'; ", FILE_APPEND ); // Use the "request" token to request account access header( 'Location: http://www.tumblr.com/oauth/authorize?oauth_token=' . $oauth_response['oauth_token'] ); // Authorization callback } else if (isset($_GET['authorize'])) { // An OAuth token and verifier will be returned if the user clicked "Allow" if ( ! isset($_GET['oauth_token']) || ! isset($_GET['oauth_verifier']) ) { die('Authorization failed.'); } // Get the oauth_token_secret we saved for this token if (! isset($tokens[$_GET['oauth_token']])) die("Couldn't find token."); $res = oauth_request( '/oauth/access_token', array( 'oauth_token' => $_GET['oauth_token'], 'oauth_verifier' => $_GET['oauth_verifier'] ), $tokens[$_GET['oauth_token']] ); // Parse the result if (strpos($res, 'oauth_token=') === false) { die('Bad result: ' . $res); } else { parse_str($res, $oauth_response); } // Add the "access" token manually (for the rest of this request) $tokens[$oauth_response['oauth_token']] = $oauth_response['oauth_token_secret']; // Store the "access" token file_put_contents( $data_file, " // Access token " . '$tokens[\'' . $oauth_response['oauth_token'] . "'] = '" . $oauth_response['oauth_token_secret'] . "'; ", FILE_APPEND ); // Use the new "access" token to load this user's follower counts $follower_counts = get_follower_counts_for_token($oauth_response['oauth_token']); if (! $follower_counts) die('Problem loading follower counts.'); // Render counter } else if (isset($_GET['counter'])) { $cache_key = $_GET['counter'] . ' ' . date('Y-m-d A'); // See if we have this count cached if (isset($count_cache[$cache_key])) { $count = $count_cache[$cache_key]; } else { // Load the follower counts for this OAuth "access" token and // and format the result for this counter if ( ($follower_counts = get_follower_counts_for_token($_GET['token'])) && isset($follower_counts[$_GET['counter']]) ) { $count = number_format($follower_counts[$_GET['counter']]); $count .= $count == 1 ? ' follower' : ' followers'; // Cache this result file_put_contents( $data_file, " // Count cache " . '$count_cache[\'' . $cache_key . "'] = '" . $count . "'; ", FILE_APPEND ); } else { $count = 'error'; } } header( 'Location: http://chart.apis.google.com/chart?chst=d_simple_text_icon_left&chld=' . $count . '|14|FFF|glyphish_user|16|D4DDE4|2c4762' ); exit; // Download source } else if (isset($_GET['source'])) { // header('Content-type: text/plain'); highlight_string(strtr( file_get_contents($_SERVER['SCRIPT_FILENAME']), array(OAUTH_CONSUMER_KEY => '', OAUTH_SECRET_KEY => '') )); exit; } ?> Tumblr Counter
Tumblr Counter
Copy the code for your Tumblr Counter:
$count) { ?>
: Tumblr Counter', ENT_QUOTES ) ?>"/> Tumblr Counter|14|FFF|glyphish_user|16|D4DDE4|2c4762"/>
12,345 followers
Generate counter Download source code