function fts_twitter_func($atts) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; $fts_functions = new feed_them_social_functions(); if (is_plugin_active('feed-them-premium/feed-them-premium.php')) { include WP_CONTENT_DIR . '/plugins/feed-them-premium/feeds/twitter/twitter-feed.php'; } else { extract(shortcode_atts(array('twitter_name' => '', 'twitter_height' => '', 'description_image' => ''), $atts)); $tweets_count = '5'; } ob_start(); $numTweets = $tweets_count; $name = $twitter_name; $excludeReplies = true; $data_cache = WP_CONTENT_DIR . '/plugins/feed-them-social/feeds/twitter/cache/twitter_data_cache-' . $name . '-num' . $numTweets . '.cache'; //Check Cache if (file_exists($data_cache) && !filesize($data_cache) == 0 && filemtime($data_cache) > time() - 1800 && false !== strpos($data_cache, '-num' . $numTweets . '')) { $fetchedTweets = $fts_functions->fts_get_feed_cache($data_cache); $cache_used = true; } else { include WP_CONTENT_DIR . '/plugins/feed-them-social/feeds/twitter/twitteroauth/twitteroauth.php'; $fts_twitter_custom_consumer_key = get_option('fts_twitter_custom_consumer_key'); $fts_twitter_custom_consumer_secret = get_option('fts_twitter_custom_consumer_secret'); $fts_twitter_custom_access_token = get_option('fts_twitter_custom_access_token'); $fts_twitter_custom_access_token_secret = get_option('fts_twitter_custom_access_token_secret'); //Use custom api info if (!empty($fts_twitter_custom_consumer_key) && !empty($fts_twitter_custom_consumer_secret) && !empty($fts_twitter_custom_access_token) && !empty($fts_twitter_custom_access_token_secret)) { $connection = new TwitterOAuthFTS($fts_twitter_custom_consumer_key, $fts_twitter_custom_consumer_secret, $fts_twitter_custom_access_token, $fts_twitter_custom_access_token_secret); } else { $connection = new TwitterOAuthFTS('dOIIcGrhWgooKquMWWXg', 'qzAE4t4xXbsDyGIcJxabUz3n6fgqWlg8N02B6zM', '1184502104-Cjef1xpCPwPobP5X8bvgOTbwblsmeGGsmkBzwdB', 'd789TWA8uwwfBDjkU0iJNPDz1UenRPTeJXbmZZ4xjY'); } // If excluding replies, we need to fetch more than requested as the // total is fetched first, and then replies removed. $totalToFetch = $excludeReplies ? max(50, $numTweets * 3) : $numTweets; $fetchedTweets = $connection->get('statuses/user_timeline', array('screen_name' => $name, 'count' => $totalToFetch, 'exclude_replies' => $excludeReplies, 'images' => $description_image)); } //END ELSE //Error Check if (isset($fetchedTweets->errors)) { $error_check = '<div>Oops, Somethings wrong. ' . $fetchedTweets->errors[0]->message . '.</div>'; if ($fetchedTweets->errors[0]->code == 32) { $error_check .= ' Please check that you have entered your Twitter API token information correctly.'; } if ($fetchedTweets->errors[0]->code == 34) { $error_check .= ' Please check the Twitter Username you have entered is correct.'; } } elseif (empty($fetchedTweets) && !isset($fetchedTweets->errors)) { $error_check = '<div>This account has no tweets. Please Tweet to see this feed.</div>'; } //Does Cache folder exists? If not make it! //IS RATE LIMIT REACHED? if (isset($fetchedTweets->errors)) { echo '<pre>'; print_r($fetchedTweets->errors); echo '</pre>'; } // Did the fetch fail? if (isset($error_check)) { echo $error_check; } else { if (!empty($fetchedTweets)) { //Cache It if (!isset($cache_used)) { $fts_functions->fts_create_feed_cache($data_cache, $fetchedTweets); } // Fetch succeeded. // Now update the array to store just what we need. // (Done here instead of PHP doing this for every page load) $limitToDisplay = min($numTweets, count($fetchedTweets)); for ($i = 0; $i < $limitToDisplay; $i++) { $tweet = $fetchedTweets[$i]; // Core info. $name = isset($tweet->user->name) ? $tweet->user->name : ""; $screen_name = isset($tweet->user->screen_name) ? $tweet->user->screen_name : ""; $protocol = isset($_SERVER["HTTPS"]) ? 'https://' : 'http://'; $not_protocol = !isset($_SERVER["HTTPS"]) ? 'https://' : 'http://'; $permalink = $protocol . 'twitter.com/' . $screen_name . '/status/' . $tweet->id_str; $user_permalink = $protocol . 'twitter.com/#!/' . $screen_name; //Is Media Set if (isset($tweet->entities->media[0]->media_url)) { $media_url = $tweet->entities->media[0]->media_url; $media_url = str_replace($not_protocol, $protocol, $media_url); } else { $media_url = ''; } // leaving this for another update, trying to get videos, and I know this ain't right! $url = $tweet->entities->media[0]->expanded_url; /* Alternative image sizes method: http://dev.twitter.com/doc/get/users/profile_image/:screen_name */ $image = isset($tweet->user->profile_image_url) ? $tweet->user->profile_image_url : ""; $image = str_replace($not_protocol, $protocol, $image); // Message. Convert links to real links. $pattern = array('/http:(\\S)+/', '/https:(\\S)+/', '/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/', '/([^a-zA-Z0-9-_&])#([0-9a-zA-Z_]+)/'); $replace = array(' <a href="${0}" target="_blank" rel="nofollow">${0}</a>', ' <a href="${0}" target="_blank" rel="nofollow">${0}</a>', ' <a href="' . $protocol . 'twitter.com/$2" target="_blank" rel="nofollow">@$2</a>', ' <a href="' . $protocol . 'twitter.com/search?q=%23$2&src=hash" target="_blank" rel="nofollow">#$2</a>'); $text = preg_replace($pattern, $replace, $tweet->text); // Need to get time in Unix format. $times = isset($tweet->created_at) ? $tweet->created_at : ""; $CustomDateCheck = get_option('fts-date-and-time-format'); if ($CustomDateCheck) { $CustomDateFormatTwitter = get_option('fts-date-and-time-format'); } else { $CustomDateFormatTwitter = 'F jS, Y \\a\\t g:ia'; } date_default_timezone_set(get_option('fts-timezone')); $uTime = date($CustomDateFormatTwitter, strtotime($times) - 3 * 3600); $twitter_id = isset($tweet->id_str) ? $tweet->id_str : ""; $fts_twitter_full_width = get_option('twitter_full_width'); // Now make the new array. $tweets[] = array('text' => $text, 'name' => $name, 'screen_name' => $screen_name, 'user_permalink' => $user_permalink, 'permalink' => $permalink, 'image' => $image, 'time' => $uTime, 'media_url' => $media_url, 'id' => $twitter_id); } //End FOR fts-twitter-full-width ?> <div id="twitter-feed-<?php print $twitter_name; ?> " class="fts-twitter-div<?php if ($twitter_height !== 'auto' && empty($twitter_height) == NULL) { ?> fts-twitter-scrollable<?php } if ($popup == 'yes') { ?> popup-gallery-twitter<?php } ?> " <?php if ($twitter_height !== 'auto' && empty($twitter_height) == NULL) { ?> style="height:<?php echo $twitter_height; ?> "<?php } ?> > <?php foreach ($tweets as $t) { ?> <div class="fts-tweeter-wrap"> <div class="tweeter-info"> <?php if ($fts_twitter_full_width !== 'yes') { ?> <div class="fts-twitter-image"><a href="<?php print $t['user_permalink']; ?> " target="_blank" class="black"><img class="twitter-image" src="<?php print $t['image']; ?> " /></a></div> <?php } ?> <div class="<?php if ($fts_twitter_full_width == 'yes') { ?> fts-twitter-full-width<?php } else { ?> right<?php } ?> "> <div class="uppercase bold"><a href="<?php print $t['user_permalink']; ?> " target="_blank" class="black">@<?php print $t['screen_name']; ?> </a></div> <span class="time"><a href="<?php print $t['permalink']; ?> "><?php print $t['time']; ?> </a></span><br/> <span class="fts-twitter-text"><?php print $t['text']; ?> <div class="fts-fb-caption"><a href="<?php print $t['permalink']; ?> " class="fts-view-on-twitter-link" target="_blank">View on Twitter</a></div> </span> <?php if ($t['media_url']) { ?> <a href="<?php if ($popup == 'yes') { print $t['media_url']; } else { print $t['permalink']; } ?> " class="fts-twitter-link-image" target="_blank"><img class="fts-twitter-description-image" src="<?php print $t['media_url']; ?> " /></a> <?php } ?> </div> <div class="fts-twitter-reply-wrap"> <a href="<?php print $t['permalink']; ?> "> <div class="fts-twitter-reply"></div> </a></div> <div class="clear"></div> </div> </div> <?php } ?> <div class="clear"></div> </div> <?php if ($twitter_height !== 'auto' && empty($twitter_height) == NULL) { ?> <script> // this makes it so the page does not scroll if you reach the end of scroll bar or go back to top jQuery.fn.isolatedScrollTwitter = function() { this.bind('mousewheel DOMMouseScroll', function (e) { var delta = e.wheelDelta || (e.originalEvent && e.originalEvent.wheelDelta) || -e.detail, bottomOverflow = this.scrollTop + jQuery(this).outerHeight() - this.scrollHeight >= 0, topOverflow = this.scrollTop <= 0; if ((delta < 0 && bottomOverflow) || (delta > 0 && topOverflow)) { e.preventDefault(); } }); return this; }; jQuery('.fts-twitter-scrollable').isolatedScrollTwitter(); </script> <?php } ?> <?php } // END IF $fetchedTweets } //END ELSE return ob_get_clean(); }
function fts_instagram_func($atts) { $fts_functions = new feed_them_social_functions(); include_once ABSPATH . 'wp-admin/includes/plugin.php'; if (is_plugin_active('feed-them-premium/feed-them-premium.php')) { include WP_CONTENT_DIR . '/plugins/feed-them-premium/feeds/instagram/instagram-feed.php'; } else { extract(shortcode_atts(array('instagram_id' => '', 'type' => '', 'super_gallery' => '', 'image_size' => '', 'icon_size' => '', 'space_between_photos' => '', 'hide_date_likes_comments' => '', 'center_container' => '', 'image_stack_animation' => ''), $atts)); $pics_count = '6'; } $popup = isset($popup) ? $popup : ""; if ($popup == 'yes') { // it's ok if these styles & scripts load at the bottom of the page because they are just for the popup wp_enqueue_style('fts_instagram_css_popup', plugins_url('instagram/css/magnific-popup.css', dirname(__FILE__))); wp_enqueue_script('fts_instagram_popup_js', plugins_url('instagram/js/magnific-popup.js', dirname(__FILE__))); } ob_start(); $fts_instagram_tokens_array = array('267791236.df31d88.30e266dda9f84e9f97d9e603f41aaf9e', '267791236.14c1243.a5268d6ed4cf4d2187b0e98b365443af', '267791236.f78cc02.bea846f3144a40acbf0e56b002c112f8', '258559306.502d2c4.c5ff817f173547d89477a2bd2e6047f9'); $fts_instagram_access_token = $fts_instagram_tokens_array[array_rand($fts_instagram_tokens_array, 1)]; //URL to get Feeds if ($type == 'hashtag') { $insta_url = 'https://api.instagram.com/v1/tags/' . $instagram_id . '/media/recent/?access_token=' . $fts_instagram_access_token; } else { $insta_url = 'https://api.instagram.com/v1/users/' . $instagram_id . '/media/recent/?access_token=' . $fts_instagram_access_token; } $cache = WP_CONTENT_DIR . '/plugins/feed-them-social/feeds/instagram/cache/instagram-cache-' . $instagram_id . '.cache'; // https://api.instagram.com/v1/tags/snow/media/recent?access_token=ACCESS-TOKEN // https://instagram.com/oauth/authorize/?client_id=[CLIENT_ID_HERE]&redirect_uri=http://localhost&response_type=token //Get Data for Instagram $response = wp_remote_fopen($insta_url); //Error Check $error_check = json_decode($response); if (isset($error_check->meta->error_message)) { return $error_check->meta->error_message; } if (file_exists($cache) && !filesize($cache) == 0 && filemtime($cache) > time() - 900) { $insta_data = $fts_functions->fts_get_feed_cache($cache); } else { $insta_data = json_decode($response); //if Error DON'T Cache if (!isset($error_check->meta->error_message)) { $fts_functions->fts_create_feed_cache($cache, $insta_data); } } if ($super_gallery == 'yes') { ?> <div class="fts-slicker-instagram masonry js-masonry <?php if ($popup == 'yes') { print 'popup-gallery'; } ?> " style="margin:auto" data-masonry-options='{ "isFitWidth": <?php if ($center_container == 'no') { ?> false<?php } else { ?> true<?php } if ($image_stack_animation == 'no') { ?> , "transitionDuration": 0<?php } ?> }'> <?php } else { ?> <div class="fts-instagram <?php if ($popup == 'yes') { print 'popup-gallery'; } ?> "> <?php } $set_zero = 0; if (!isset($insta_data->data)) { return '<div style="padding-right:35px;">Looks like instagram\'s API down. Please try clearing cache and reloading this page in the near future.</div></div>'; } foreach ($insta_data->data as $insta_d) { if ($set_zero == $pics_count) { break; } //Create Instagram Variables $instagram_date = isset($insta_d->created_time) ? date('F j, Y', $insta_d->created_time) : ""; $instagram_link = isset($insta_d->link) ? $insta_d->link : ""; $instagram_thumb_url = isset($insta_d->images->thumbnail->url) ? $insta_d->images->thumbnail->url : ""; $instagram_lowRez_url = isset($insta_d->images->standard_resolution->url) ? $insta_d->images->standard_resolution->url : ""; if (isset($_SERVER["HTTPS"])) { $instagram_thumb_url = str_replace('http://', 'https://', $instagram_thumb_url); $instagram_lowRez_url = str_replace('http://', 'https://', $instagram_lowRez_url); } $instagram_likes = isset($insta_d->likes->count) ? $insta_d->likes->count : ""; $instagram_comments = isset($insta_d->comments->count) ? $insta_d->comments->count : ""; $instagram_caption_a_title = isset($insta_d->caption->text) ? $insta_d->caption->text : ""; //Create links from @mentions and regular links. $pattern = array('/http:(\\S)+/', '/https:(\\S)+/', '/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/'); $replace = array(' <a href="${0}" target="_blank" rel="nofollow">${0}</a>', ' <a href="${0}" target="_blank" rel="nofollow">${0}</a>', ' <a href="http://instagram.com/$2" target="_blank" rel="nofollow">@$2</a>'); $instagram_caption = preg_replace($pattern, $replace, $instagram_caption_a_title); // Super Gallery If statement if ($super_gallery == 'yes') { ?> <div class='slicker-instagram-placeholder fts-instagram-wrapper' style="width:<?php print $image_size; ?> ; margin:<?php print $space_between_photos; ?> ;"> <?php if ($popup == 'yes') { ?> <div class="fts-instagram-caption"><?php if (!$instagram_caption == '') { print '' . $instagram_caption . '<br/>'; } ?> <a href='<?php print $instagram_link; ?> ' class="fts-view-on-instagram-link" target="_blank">View on Instagram</a></div> <?php } ?> <a href='<?php if ($popup == 'yes') { print $instagram_lowRez_url; } else { print $instagram_link; } ?> ' title='<?php print $instagram_caption_a_title; ?> ' target="_blank" class='fts-slicker-backg fts-instagram-img-link' style="height:<?php print $icon_size; ?> !important; width:<?php print $icon_size; ?> ; line-height:<?php print $icon_size; ?> ; font-size:<?php print $icon_size; ?> ;"><span class="fts-instagram-icon" style="height:<?php print $icon_size; ?> ; width:<?php print $icon_size; ?> ; line-height:<?php print $icon_size; ?> ; font-size:<?php print $icon_size; ?> ;"></span></a> <?php if ($hide_date_likes_comments == 'no') { ?> <div class='slicker-date'><?php print $instagram_date; ?> </div> <?php } ?> <div class='slicker-instaG-backg-link'> <div class='slicker-instagram-image'><img src="<?php print $instagram_lowRez_url; ?> " /></div> <div class='slicker-instaG-photoshadow'></div> </div> <?php if ($hide_date_likes_comments == 'no') { ?> <ul class='slicker-heart-comments-wrap'> <li class='slicker-instagram-image-likes'><?php print $instagram_likes; ?> </li> <li class='slicker-instagram-image-comments'><span class="fts-comment-instagram"></span><?php print $instagram_comments; ?> </li> </ul> <?php } ?> </div> <?php } else { ?> <div class='instagram-placeholder fts-instagram-wrapper'><?php if ($popup == 'yes') { print '<div class="fts-backg"></div>'; } else { ?> <a class='fts-backg' target='_blank' href='<?php print $instagram_link; ?> '></a> <?php } ?> <div class='date'><?php print $instagram_date; ?> </div> <?php if ($popup == 'yes') { ?> <div class="fts-instagram-caption"><?php if (!$instagram_caption == '') { print '' . $instagram_caption . '<br/>'; } ?> <a href='<?php print $instagram_link; ?> ' class="fts-view-on-instagram-link" target="_blank">View on Instagram</a></div> <?php } ?> <a href="<?php if ($popup == 'yes') { print $instagram_lowRez_url; } else { print $instagram_link; } ?> " class='instaG-backg-link fts-instagram-img-link' target='_blank' title="<?php print $instagram_caption_a_title; ?> "> <img src="<?php print $instagram_thumb_url; ?> " class="instagram-image" /> <div class='instaG-photoshadow'></div> </a> <ul class='heart-comments-wrap'> <li class='instagram-image-likes'><?php print $instagram_likes; ?> </li> <li class='instagram-image-comments'><?php print $instagram_comments; ?> </li> </ul> </div> <?php } $set_zero++; } ?> <div class="clear"></div> </div> <?php return ob_get_clean(); }