$val ){ $return = $return."-".($val?$val:$key); } $return = @ereg_replace('[[:cntrl:]]', '', $return ); // remove ASCII's control characters $bad = array_merge( array_map('chr', range(0,31)), array("<",">",":",'"',"/","\\","|","?","*"," ",",","\'",".")); $return = str_replace($bad, "", $return); // Remove Windows filename prohibited characters return $return; } } /** * Alpine PhotoTile for Picasa: Photo Retrieval Function * The PHP for retrieving content from Picasa. * * @ Since 1.0.0 * @ Updated 1.2.2 */ function photo_retrieval(){ $picasa_options = $this->options; $defaults = $this->option_defaults(); $key_input = array( 'name' => 'picasa', 'info' => array( 'vers' => $this->vers, 'src' => $picasa_options['picasa_source'], 'uid' => $picasa_options['picasa_user_id'], 'alb' => $picasa_options['picasa_user_album'], 'key' => $picasa_options['picasa_keyword'], 'num' => $picasa_options['picasa_photo_number'], 'link' => $picasa_options['picasa_display_link'], 'text' => $picasa_options['picasa_display_link_text'], 'size' => $picasa_options['picasa_photo_size'] ) ); $key = $this->key_maker( $key_input ); $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(); $picasa_uid = apply_filters( $this->hook, empty($picasa_options['picasa_user_id']) ? '' : $picasa_options['picasa_user_id'], $picasa_options ); $picasa_uid = str_replace(array('/',' '),'',$picasa_uid); $picasa_uid = str_replace('http:','',$picasa_uid ); $picasa_uid = str_replace('.picasa.com','',$picasa_uid); $request = ""; switch ($picasa_options['picasa_source']) { case 'user_recent': $request = 'http://picasaweb.google.com/data/feed/api/user/'.$picasa_uid.'?kind=photo&alt=json&max-results='.$picasa_options['picasa_photo_number'].'&thumbsize='.$picasa_options['picasa_photo_size'].'u&imgmax=1024u'; break; case 'user_album': $picasa_album = apply_filters( $this->hook, empty($picasa_options['picasa_user_album']) ? '' : $picasa_options['picasa_user_album'], $picasa_options ); $request = 'http://picasaweb.google.com/data/feed/api/user/'.$picasa_uid.'/albumid/'.$picasa_album.'?kind=photo&alt=json&kind=photo&max-results='.$picasa_options['picasa_photo_number'].'&thumbsize='.$picasa_options['picasa_photo_size'].'u&imgmax=1024u'; break; case 'global_keyword': $picasa_keyword = apply_filters( $this->hook, empty($picasa_options['picasa_keyword']) ? '' : $picasa_options['picasa_keyword'], $picasa_options ); $request = 'http://picasaweb.google.com/data/feed/api/all?kind=photo&alt=json&q='.$picasa_keyword.'&max-results='.$picasa_options['picasa_photo_number'].'&thumbsize='.$picasa_options['picasa_photo_size'].'u&imgmax=1024u'; break; } /////////////////////////////////////////////////// /// Try using wp_remote_get and JSON /// /////////////////////////////////////////////////// if ( function_exists('json_decode') ) { $_picasa_json = array(); $response = wp_remote_get($request, array( 'method' => 'GET', 'timeout' => 20, 'sslverify' => apply_filters('https_local_ssl_verify', false) ) ); if( is_wp_error( $response ) || empty($response['body']) ) { $hidden .= ''; }else{ $_picasa_json = json_decode( $response['body'] ); } if( empty($_picasa_json) || empty($_picasa_json->feed) ){ $hidden .= ''; $continue = false; }else{ $content = $_picasa_json->feed->entry; $link = $_picasa_json->feed->link[1]->href; $s = 0; // simple counter if( count($content) ) { foreach( $content as $p ) { if( $s<$picasa_options['picasa_photo_number'] ){ $title = (array) $p->title; $photocap[$s] = (string) $title['$t']; $photocap[$s] = str_replace(array('.jpg', '.JPG'),'',$photocap[$s]); // list of link urls; $glink = $p->link; $linkurl[$s] = (string) $glink[1]->href; if( $glink[2]->href ){ $linkurl[$s] = (string) $glink[2]->href; } // list of photo urls $originalurl[$s] = (string) $p->content->src; $mg = 'media$group'; $mt = 'media$thumbnail'; $thumb = $p->$mg->$mt; $photourl[$s] = (string) $thumb[0]->url; if( empty($photourl[$s]) ){ $photourl[$s] = $originalurl[$s]; } $s++; }else{ break; } } } if(!empty($linkurl) && !empty($photourl)){ // If set, generate picasa link if( $picasa_options['picasa_display_link'] && !empty($picasa_options['picasa_display_link_text']) ) { $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(APTFPICAbyTAP_specialarraysearch)){ function APTFPICAbyTAP_specialarraysearch($array, $find){ foreach ($array as $key=>$value){ if( is_string($key) && $key==$find){ return $value; } elseif(is_array($value)){ $results = APTFPICAbyTAP_specialarraysearch($value, $find); } elseif(is_object($value)){ $sub = $array->$key; $results = APTFPICAbyTAP_specialarraysearch($sub, $find); } // If found, return if(!empty($results)){return $results;} } return $results; } } 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; } } $request = str_replace('alt=json','alt=rss',$request); 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 $data = @APTFPICAbyTAP_specialarraysearch($rss,'child'); $data = @APTFPICAbyTAP_specialarraysearch($data,'child'); $data = @APTFPICAbyTAP_specialarraysearch($data,'child'); $link = $data[null]['link'][0]['data']; $rss_data = $data[null]['item']; $s = 0; // simple counter if ( !empty($rss_data) ){ // Check again foreach ( $rss_data as $item ) { //print_r( $item ); if( $s<$picasa_options['picasa_photo_number'] ){ $photocap[$s] = $item['child']['']['title']['0']['data']; $photocap[$s] = str_replace(array('.jpg', '.JPG'),'',$photocap[$s]); $thumb = @APTFPICAbyTAP_specialarraysearch($item,'thumbnail'); $linkurl[$s] = $item['child']['']['link']['0']['data']; $originalurl[$s] = $item['child']['']['enclosure']['0']['attribs']['']['url']; $photourl[$s] = $originalurl[$s]; if( $thumb['0']['attribs']['']['url'] ){ $photourl[$s] = $thumb['0']['attribs']['']['url']; } $s++; } else{ break; } } } if(!empty($linkurl) && !empty($photourl)){ if( $picasa_options['picasa_display_link'] && !empty($picasa_options['picasa_display_link_text']) ) { $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 Picasa ID must be wrong /// /////////////////////////////////////////////////////////////////////// if( false == $continue ) { if($feed_found ){ $message .= '- Picasa feed was successfully retrieved, but no photos found.'; }else{ $message .= '- Picasa feed not found. Please recheck your ID and check that your account/album is set to public, not private.'; } } $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 ); } } $this->results = $results; } /** * Get Image Link * * @ Since 1.2.2 */ function get_link($i){ $link = $this->options['picasa_image_link_option']; $photocap = $this->results['image_captions'][$i]; $photourl = $this->results['image_urls'][$i]; $linkurl = $this->results['image_perms'][$i]; $url = $this->options['custom_link_url']; $originalurl = $this->results['image_originals'][$i]; if( 'original' == $link && !empty($photourl) ){ $this->out .= ''; return true; }elseif( ('picasa' == $link || '1' == $link)&& !empty($linkurl) ){ $this->out .= ''; return true; }elseif( 'link' == $link && !empty($url) ){ $this->out .= ''; return true; }elseif( 'fancybox' == $link && !empty($originalurl) ){ $this->out .= ''; return true; } return false; } /** * Update photo number count * * @ Since 1.2.2 */ function updateCount(){ if( $this->options['picasa_photo_number'] != count( $this->results['image_urls'] ) ){ $this->options['picasa_photo_number'] = count( $this->results['image_urls'] ); } } /** * Get Parent CSS * * @ Since 1.2.2 */ function get_parent_css(){ $opts = $this->options; $return = 'width:100%;max-width:'.$opts['widget_max_width'].'%;padding:0px;'; if( 'center' == $opts['widget_alignment'] ){ // Optional: Set text alignment (left/right) or center $return .= 'margin:0px auto;text-align:center;'; } elseif( 'right' == $opts['widget_alignment'] || 'left' == $opts['widget_alignment'] ){ // Optional: Set text alignment (left/right) or center $return .= 'float:' . $opts['widget_alignment'] . ';text-align:' . $opts['widget_alignment'] . ';'; } else{ $return .= 'margin:0px auto;text-align:center;'; } return $return; } /** * Add Image Function * * @ Since 1.2.2 * ** Possible change: place original image as 'alt' and load image as needed */ function add_image($i,$css=""){ $this->out .= '