Skip to content

Commit

Permalink
Twitter Profile Image Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jptksc committed Aug 9, 2013
1 parent d971077 commit 4fe4a22
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ templates/typographic/
templates/cards/

plugins/switcher.php

cache/*.png
cache/*.jpeg
5 changes: 5 additions & 0 deletions cache/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

// Nothing to see here.

?>
28 changes: 26 additions & 2 deletions dropplets/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,37 @@ function count_premium_templates($type = 'all') {
define('IS_HOME', $is_home);

/*-----------------------------------------------------------------------------------*/
/* Get Twitter Profile Image (This Needs to be Cached)
/* Get Profile Image (This Needs to be Cached)
/*-----------------------------------------------------------------------------------*/

function get_twitter_profile_img($username, $size = '') {
$api_call = 'https://twitter.com/users/'.$username.'.json';
$results = json_decode(file_get_contents($api_call));
return str_replace('_normal', $size, $results->profile_image_url);
$image_url = str_replace('_normal', $size, $results->profile_image_url);

// Replace with your cache directory.
$image_path = './cache/';

// Get the name of the file.
$exploded_image_url = explode("/",$image_url);
$image_filename = end($exploded_image_url);
$exploded_image_filename = explode(".",$image_filename);
$extension = end($exploded_image_filename);

// Make sure its an image.
if($extension=="gif"||$extension=="jpg"||$extension=="jpeg"||$extension=="png"){

// Get the remote image.
$image_to_fetch = file_get_contents($image_url);

// Save it.
$local_image_file = fopen($image_path.$image_filename, 'w+');
chmod($image_path.$image_filename,0755);
fwrite($local_image_file, $image_to_fetch);
fclose($local_image_file);
}

return $image_path.$image_filename;
}

/*-----------------------------------------------------------------------------------*/
Expand Down

0 comments on commit 4fe4a22

Please sign in to comment.