'GET',
'timeout' => 20
)
);
if( is_wp_error( $response ) || !isset($response['body']) ) {
return false;
}else{
return $response['body'];
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// Generate Image Content ////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function photo_retrieval($id, $tumblr_options){
$defaults = $this->option_defaults();
$tumblr_uid = apply_filters( $this->hook, empty($tumblr_options['tumblr_user_id']) ? 'uid' : $tumblr_options['tumblr_user_id'], $tumblr_options );
$tumblr_uid = @ereg_replace('[[:cntrl:]]', '', $tumblr_uid ); // remove ASCII's control characters
$tumblr_custom_url = apply_filters( $this->hook, empty($tumblr_options['tumblr_custom_url']) ? 'groupid' : $tumblr_options['tumblr_custom_url'], $tumblr_options );
$tumblr_custom_url = @ereg_replace('[[:cntrl:]]', '', $tumblr_custom_url ); // remove ASCII's control characters
$tumblr_custom_url_safe = str_replace( array(".","\'","/"),'',$tumblr_custom_url);
$key = 'tumblr-'.$this->vers.'-'.$tumblr_options['tumblr_source'].'-'.$tumblr_uid.'-'.$tumblr_custom_url_safe.'-'.$tumblr_options['tumblr_photo_number'].'-'.$tumblr_options['tumblr_display_link'].'-'.$tumblr_options['tumblr_photo_size'];
$disablecache = $this->get_option( 'cache_disable' );
if ( !$disablecache ) {
if( $this->cacheExists($key) ) {
$results = $this->getCache($key);
$results = @unserialize($results);
if( count($results) ){
$results['hidden'] .= '';
return $results;
}
}
}
$message = '';
$hidden = '';
$continue = false;
$feed_found = false;
$linkurl = array();
$photocap = array();
$photourl = array();
// Determine image size id
$size_id = 2;
switch ($tumblr_options['tumblr_photo_size']) {
case 75:
$size_id = 5;
break;
case 100:
$size_id = 4;
break;
case 250:
$size_id = 3;
break;
case 400:
$size_id = 2;
break;
case 500:
$size_id = 1;
break;
}
// Retrieve content using wp_remote_get and JSON
if ( function_exists('json_decode') ) {
// @ is shut-up operator
// For reference: http://www.tumblr.com/services/feeds/
$repeats = floor($tumblr_options['tumblr_photo_number']/20);
switch ($tumblr_options['tumblr_source']) {
case 'user':
$tumblr_uid = apply_filters( $this->hook, empty($tumblr_options['tumblr_user_id']) ? '' : $tumblr_options['tumblr_user_id'], $tumblr_options );
$tumblr_uid = str_replace(array('/',' '),'',$tumblr_uid);
$tumblr_uid = str_replace('http:','',$tumblr_uid );
$tumblr_uid = str_replace('.tumblr.com','',$tumblr_uid);
$request = 'http://api.tumblr.com/v2/blog/'.$tumblr_uid.'.tumblr.com/posts?api_key=GhKB8A19ZFhO3rWpBhjKfJUistNDgQwIYu6tHlzzg4pPT3WZwH';
break;
case 'custom':
$tumblr_uid = apply_filters( $this->hook, empty($tumblr_options['tumblr_custom_url']) ? '' : $tumblr_options['tumblr_custom_url'], $tumblr_options );
$tumblr_uid = str_replace(array('/',' '),'',$tumblr_uid);
$tumblr_uid = str_replace('http:','',$tumblr_uid );
$request = 'http://api.tumblr.com/v2/blog/'.$tumblr_uid.'/posts?api_key=GhKB8A19ZFhO3rWpBhjKfJUistNDgQwIYu6tHlzzg4pPT3WZwH';
break;
}
$result = $this->fetch_tumblr_feed($request);
$_tumblr_json = array();
if( $result ){ $_tumblr_json = @json_decode( $result ); }
if( empty($_tumblr_json) || 200 != $_tumblr_json->meta->status ){
$hidden .= '';
$continue = false;
}else{
for($loop=0;$loop<=$repeats;$loop++){
$response = $_tumblr_json->response;
$response_blog = $response->blog;
$title = $response_blog->title;
$link = $response_blog->url;
$found = $response_blog->posts;
$content = $response->posts;
$i = $loop*20;
foreach($content as $post){
if( $i<$tumblr_options['tumblr_photo_number'] ){
$post_url = $post->post_url;
$post_cap = $post->caption;
if( $post_url && count($post->photos) ){
foreach( $post->photos as $photo ){
if( $i<$tumblr_options['tumblr_photo_number'] ){
$sizes = $photo->alt_sizes;
$linkurl[$i] = $post_url;
$photocap[$i] = ''; //$post_cap;
$photourl[$i] = $sizes[$size_id]->url;
$originalurl[$i] = $sizes[1]->url;
$photourl[$i] = $sizes[0]->url;
foreach( $sizes as $currentsize ){
if( $currentsize->width >= $tumblr_options['tumblr_photo_size'] && $currentsize->url ){
$photourl[$i] = $currentsize->url;
}
}
$i++;
}
}
}
}else{
break;
}
}
// Try another request
if($loop<$repeats){
$next_request = $request.'&offset='.(($loop+1)*20);
$result = $this->fetch_tumblr_feed($next_request);
$_tumblr_json = array();
if( $result ){ $_tumblr_json = @json_decode( $result ); }
if(empty($_tumblr_json) || 200 != $_tumblr_json->meta->status ){
$hidden .= '';
$loop = $repeats;
}
}
}
if(!empty($linkurl) && !empty($photourl)){
if( $tumblr_options['tumblr_display_link'] ) {
$user_link = '
';
}
// If content successfully fetched, generate output...
$continue = true;
$hidden .= '';
}else{
$hidden .= '';
$continue = false;
$feed_found = true;
}
}
}
///////////////////////////////////////////////////
/// If nothing found, try using xml and rss_200 ///
///////////////////////////////////////////////////
if ( $continue == false && function_exists('simplexml_load_file') ) {
// Determine image size id
$size_id = 2;
switch ($tumblr_options['tumblr_photo_size']) {
case 75:
$size_id = 5;
break;
case 100:
$size_id = 4;
break;
case 250:
$size_id = 3;
break;
case 400:
$size_id = 2;
break;
case 500:
$size_id = 1;
break;
}
$repeats = floor($tumblr_options['tumblr_photo_number']/20);
switch ($tumblr_options['tumblr_source']) {
case 'user':
$tumblr_uid = apply_filters( $this->hook, empty($tumblr_options['tumblr_user_id']) ? '' : $tumblr_options['tumblr_user_id'], $tumblr_options );
$tumblr_uid = str_replace(array('/',' '),'',$tumblr_uid);
$tumblr_uid = str_replace('http:','',$tumblr_uid );
$tumblr_uid = str_replace('.tumblr.com','',$tumblr_uid);
$request = 'http://' . $tumblr_uid . '.tumblr.com/api/read?number=' .$tumblr_options['tumblr_photo_number']. '&type=photo';
break;
case 'custom':
$tumblr_uid = apply_filters( $this->hook, empty($tumblr_options['tumblr_custom_url']) ? '' : $tumblr_options['tumblr_custom_url'], $tumblr_options );
$tumblr_uid = str_replace(array('/',' '),'',$tumblr_uid);
$tumblr_uid = str_replace('http:','',$tumblr_uid );
$request = 'http://' . $tumblr_uid . '/api/read?number=' .$tumblr_options['tumblr_photo_number']. '&type=photo';
break;
}
// XML doesn't seem to care if "www" is present or not
$_tumblr_request = @urlencode( $request ); // just for compatibility
$_tumblr_xml = @simplexml_load_file( $_tumblr_request); // @ is shut-up operator
if($_tumblr_xml===false){
$hidden .= '';
$continue = false;
}else{
$s = 0; // simple counter
for($loop=0;$loop<=$repeats;$loop++){
if( $_tumblr_xml && $_tumblr_xml->posts[0]) {
foreach( $_tumblr_xml->posts[0]->post as $p ) {
if( $s<$tumblr_options['tumblr_photo_number'] ){
// list of link urls
$linkurl[$s] = (string) $p['url'];
// list of photo urls
$photourl[$s] = (string) $p->{"photo-url"}[$size_id];
$originalurl[$s] = (string) $p->{"photo-url"}[1];
$photocap[$s] = (string) $p["slug"];
$s++;
}else{
break;
}
}
}
// Try another request
if($loop<$repeats){
$next_request = $request.'&start='.(($loop+1)*20);
$_tumblr_request = @urlencode( $next_request ); // just for compatibility
$_tumblr_xml = @simplexml_load_file( $_tumblr_request); // @ is shut-up operator
if($_tumblr_xml===false){
$hidden .= '';
$loop = $repeats;
}
}
}
if(!empty($linkurl) && !empty($photourl)){
// If set, generate tumblr link
if( $tumblr_options['display-link'] ) {
$user_link = '';
}
// If content successfully fetched, generate output...
$continue = true;
$hidden .= '';
}else{
$hidden .= '';
$continue = false;
}
}
}
////////////////////////////////////////////////////////
//// If still nothing found, try using RSS ///
////////////////////////////////////////////////////////
if( $continue == false ) {
// RSS may actually be safest approach since it does not require PHP server extensions,
// but I had to build my own method for parsing SimplePie Object so I will keep it as the last option.
if(!function_exists(APTFTbyTAP_specialarraysearch)){
function APTFTbyTAP_specialarraysearch($array, $find){
foreach ($array as $key=>$value){
if( is_string($key) && $key==$find){
return $value;
}
elseif(is_array($value)){
$results = APTFTbyTAP_specialarraysearch($value, $find);
}
elseif(is_object($value)){
$sub = $array->$key;
$results = APTFTbyTAP_specialarraysearch($sub, $find);
}
// If found, return
if(!empty($results)){return $results;}
}
return $results;
}
}
switch ($tumblr_options['tumblr_source']) {
case 'user':
$tumblr_uid = apply_filters( $this->hook, empty($tumblr_options['tumblr_user_id']) ? '' : $tumblr_options['tumblr_user_id'], $tumblr_options );
$tumblr_uid = str_replace(array('/',' '),'',$tumblr_uid);
$tumblr_uid = str_replace('http:','',$tumblr_uid );
$tumblr_uid = str_replace('.tumblr.com','',$tumblr_uid);
$request = 'http://' . $tumblr_uid . '.tumblr.com/rss';
break;
case 'custom':
$tumblr_uid = apply_filters( $this->hook, empty($tumblr_options['tumblr_custom_url']) ? '' : $tumblr_options['tumblr_custom_url'], $tumblr_options );
$tumblr_uid = str_replace(array('/',' '),'',$tumblr_uid);
$tumblr_uid = str_replace('http:','',$tumblr_uid );
$request = 'http://' . $tumblr_uid . '/rss';
break;
}
include_once(ABSPATH . WPINC . '/feed.php');
if( !function_exists('return_noCache') ){
function return_noCache( $seconds ){
// change the default feed cache recreation period to 30 seconds
return 30;
}
}
add_filter( 'wp_feed_cache_transient_lifetime' , 'return_noCache' );
$rss = @fetch_feed( $request );
remove_filter( 'wp_feed_cache_transient_lifetime' , 'return_noCache' );
if (!is_wp_error( $rss ) && $rss != NULL ){ // Check that the object is created correctly
// Bulldoze through the feed to find the items
$results = array();
$title = @APTFTbyTAP_specialarraysearch($rss,'title');
$title = $title['0']['data'];
$link = @APTFTbyTAP_specialarraysearch($rss,'link');
$link = $link['0']['data'];
$rss_data = @APTFTbyTAP_specialarraysearch($rss,'item');
$s = 0; // simple counter
if ($rss_data != NULL ){ // Check again
foreach ( $rss_data as $item ) {
if( $s<$tumblr_options['tumblr_photo_number'] ){
$linkurl[$s] = $item['child']['']['link']['0']['data'];
$content = $item['child']['']['description']['0']['data'];
if($content){
// For Reference: regex references and http://php.net/manual/en/function.preg-match.php
// Using the RSS feed will require some manipulation to get the image url from tumblr;
// preg_replace is bad at skipping lines so we'll start with preg_match
// i sets letters in upper or lower case, s sets . to anything
@preg_match("/';
$user_link .='';
$user_link .= $title;
$user_link .= '';
}
// If content successfully fetched, generate output...
$continue = true;
$hidden .= '';
}else{
$hidden .= '';
$continue = false;
$feed_found = true;
}
}
else{
$hidden .= '';
$continue = false;
}
}
///////////////////////////////////////////////////////////////////////
//// If STILL!!! nothing found, report that Tumblr ID must be wrong ///
///////////////////////////////////////////////////////////////////////
if( false == $continue ) {
if($feed_found ){
$message .= '- Tumblr feed was successfully retrieved, but no photos found.';
}else{
$message .= '- Tumblr feed not found. Please recheck your ID.';
}
}
$results = array('continue'=>$continue,'message'=>$message,'hidden'=>$hidden,'user_link'=>$user_link,'image_captions'=>$photocap,'image_urls'=>$photourl,'image_perms'=>$linkurl,'image_originals'=>$originalurl);
if( true == $continue && !$disablecache ){
$cache_results = $results;
if(!is_serialized( $cache_results )) { $cache_results = maybe_serialize( $cache_results ); }
$this->putCache($key, $cache_results);
$cachetime = $this->get_option( 'cache_time' );
if( $cachetime && is_numeric($cachetime) ){
$this->setExpiryInterval( $cachetime*60*60 );
}
}
return $results;
}
/**
* Function for printing vertical style
*
* @ Since 0.0.1
*/
function display_vertical($id, $options, $source_results){
$linkurl = $source_results['image_perms'];
$photocap = $source_results['image_captions'];
$photourl = $source_results['image_urls'];
$userlink = $source_results['user_link'];
$originalurl = $source_results['image_originals'];
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// Check Content /////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if($options['tumblr_photo_number'] != count($linkurl)){$options['tumblr_photo_number']=count($linkurl);}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////// Begin the Content /////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$output .= '';
// Align photos
$output .= '
';
$output .= $by_link;
}
// Close vertical-parent
$output .= '
';
if($userlink){
$output .= ''.$userlink.'
'; // Only breakline if floating
}
// Close container
$output .= '';
$output .= '';
$highlight = $this->get_option("general_highlight_color");
$highlight = ($highlight?$highlight:'#64a2d8');
if( $options['style_shadow'] || $options['style_border'] || $options['style_highlight'] ){
$output .= '';
}
if( $options['tumblr_image_link_option'] == "fancybox" ){
$output .= '';
}
return $output;
}
/**
* Function for printing cascade style
*
* @ Since 0.0.1
*/
function display_cascade($id, $options, $source_results){
$linkurl = $source_results['image_perms'];
$photocap = $source_results['image_captions'];
$photourl = $source_results['image_urls'];
$userlink = $source_results['user_link'];
$originalurl = $source_results['image_originals'];
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// Check Content /////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if($options['tumblr_photo_number'] != count($linkurl)){$options['tumblr_photo_number']= count($linkurl);}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////// Begin the Content /////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$output .= '';
// Align photos
$output .= '
';
$shadow = ($options['style_shadow']?'AlpinePhotoTiles-img-shadow':'AlpinePhotoTiles-img-noshadow');
$border = ($options['style_border']?'AlpinePhotoTiles-img-border':'AlpinePhotoTiles-img-noborder');
$curves = ($options['style_curve_corners']?'AlpinePhotoTiles-img-corners':'AlpinePhotoTiles-img-nocorners');
$highlight = ($options['style_highlight']?'AlpinePhotoTiles-img-highlight':'AlpinePhotoTiles-img-nohighlight');
for($col = 0; $col<$options['style_column_number'];$col++){
$output .= '
';
$output .= '
';
$output .= $by_link;
}
// Close cascade-parent
$output .= '
';
$output .= '
';
if($userlink){
if($options['widget_alignment'] == 'center'){ // Optional: Set text alignment (left/right) or center
$output .= '
';
}
else{
$output .= '
'.$userlink.''; // Only breakline if floating
}
}
// Close container
$output .= '
';
$output .= '
';
$highlight = $this->get_option("general_highlight_color");
$highlight = ($highlight?$highlight:'#64a2d8');
if( $options['style_shadow'] || $options['style_border'] || $options['style_highlight'] ){
$output .= '';
}
if( $options['tumblr_image_link_option'] == "fancybox" ){
$output .= '';
}
return $output;
}
/**
* Function for printing and initializing JS styles
*
* @ Since 0.0.1
*/
function display_hidden($id, $options, $source_results){
$linkurl = $source_results['image_perms'];
$photocap = $source_results['image_captions'];
$photourl = $source_results['image_urls'];
$userlink = $source_results['user_link'];
$originalurl = $source_results['image_originals'];
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// Check Content /////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if($options['tumblr_photo_number'] != count($linkurl)){$options['tumblr_photo_number']=count($linkurl);}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////// Begin the Content /////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$output .= '
';
// Align photos
$output .= '
';
$output .= '
';
if( !$options['widget_disable_credit_link'] ){
$by_link = '
';
$output .= $by_link;
}
// Close vertical-parent
$output .= '
';
if($userlink){
if($options['widget_alignment'] == 'center'){ // Optional: Set text alignment (left/right) or center
$output .= '
';
}
else{
$output .= '
'.$userlink.''; // Only breakline if floating
}
}
// Close container
$output .= '
';
$disable = $this->get_option("general_loader");
$highlight = $this->get_option("general_highlight_color");
$highlight = ($highlight?$highlight:'#64a2d8');
$output .= '';
return $output;
}
}
?>