/** * Get FiveHundredPixels Image Feed * * Fetches a FiveHundredPixels feed, caches it and returns the * cached result or the results after caching them. * * @param string $feed_url The URL of the gplus feed with a JSON response * @param integer $slidedeck_id The ID of the deck (for caching) * * @return array An array of arrays containing the images and various meta. */ function get_slides_nodes($slidedeck) { $args = array('sslverify' => false); $max_images = min($slidedeck['options']['total_slides'], 20); // Respect thy API! http://developers.500px.com/docs/terms $image_size = 4; $sort = 'created_at'; $feed_type = $slidedeck['options']['fivehundredpixels_feed_type']; if ($slidedeck['options']['fivehundredpixels_category'] == 'Any Category') { $feed_url = 'https://api.500px.com/v1/photos?feature=' . $feed_type . '&rpp=' . $max_images . '&sort=' . $sort . '&image_size=' . $image_size . '&username='******'options']['fivehundredpixels_username'] . '&consumer_key=' . $this->client_id; } else { $feed_url = 'https://api.500px.com/v1/photos?feature=' . $feed_type . '&rpp=' . $max_images . '&only=' . urlencode($slidedeck['options']['fivehundredpixels_category']) . '&sort=' . $sort . '&image_size=' . $image_size . '&username='******'options']['fivehundredpixels_username'] . '&consumer_key=' . $this->client_id; } // Create a cache key $cache_key = $slidedeck['id'] . $feed_url . $slidedeck['options']['cache_duration'] . $this->name; // Attempt to read the cache $images = slidedeck2_cache_read($cache_key); // If cache doesn't exist if (!$images) { $images = array(); $response = wp_remote_get($feed_url, $args); if (!is_wp_error($response)) { $response_json = json_decode($response['body']); if (isset($response_json->photos)) { foreach ($response_json->photos as $index => $entry) { $large_image = $entry->image_url; $small_image = str_replace('/4.', '/1.', $entry->image_url); $avatar = preg_match('/^http/', $entry->user->userpic_url) ? $entry->user->userpic_url : false; $images[$index]['title'] = $entry->name; $images[$index]['description'] = $entry->description; $images[$index]['width'] = $entry->width; $images[$index]['height'] = $entry->height; $images[$index]['created_at'] = strtotime($entry->created_at); $images[$index]['image'] = $large_image; $images[$index]['thumbnail'] = $small_image; $images[$index]['permalink'] = 'http://500px.com/photo/' . $entry->id; $images[$index]['comments_count'] = $entry->comments_count; $images[$index]['likes_count'] = $entry->favorites_count; $images[$index]['author_name'] = $entry->user->fullname; $images[$index]['author_username'] = $entry->user->username; $images[$index]['author_url'] = 'http://500px.com/' . $entry->user->username; $images[$index]['author_avatar'] = $avatar; } } } else { return false; } // Write the cache slidedeck2_cache_write($cache_key, $images, $slidedeck['options']['cache_duration']); } return $images; }
/** * Get Dribbble Image Feed * * Fetches a Dribbble feed, caches it and returns the * cached result or the results after caching them. * * @param string $feed_url The URL of the gplus feed with a JSON response * @param integer $slidedeck_id The ID of the deck (for caching) * * @return array An array of arrays containing the images and various meta. */ function get_slides_nodes($slidedeck) { $args = array('sslverify' => false); switch ($slidedeck['options']['dribbble_shots_or_likes']) { case 'shots': $feed_url = 'http://api.dribbble.com/players/' . $slidedeck['options']['dribbble_username'] . '/shots?per_page=' . $slidedeck['options']['total_slides']; break; case 'likes': $feed_url = 'http://api.dribbble.com/players/' . $slidedeck['options']['dribbble_username'] . '/shots/likes?per_page=' . $slidedeck['options']['total_slides']; break; } // Create a cache key $cache_key = $slidedeck['id'] . $feed_url . $slidedeck['options']['cache_duration'] . $this->name; // Attempt to read the cache $response = slidedeck2_cache_read($cache_key); // If cache doesn't exist if (!$response) { $response = wp_remote_get($feed_url, $args); if (!is_wp_error($response)) { // Write the cache slidedeck2_cache_write($cache_key, $response, $slidedeck['options']['cache_duration']); } } $images = array(); if (!is_wp_error($response) && isset($response['body'])) { $response_json = json_decode($response['body']); foreach ($response_json->shots as $index => $entry) { $images[$index]['title'] = $entry->title; $images[$index]['width'] = $entry->width; $images[$index]['height'] = $entry->height; $images[$index]['created_at'] = strtotime($entry->created_at); $images[$index]['image'] = preg_replace('/^(http:|https:)/', '', $entry->image_url); $images[$index]['thumbnail'] = preg_replace('/^(http:|https:)/', '', $entry->image_teaser_url); $images[$index]['permalink'] = $entry->url; $images[$index]['comments_count'] = $entry->comments_count; $images[$index]['likes_count'] = $entry->likes_count; $images[$index]['author_name'] = $entry->player->name; $images[$index]['author_username'] = $entry->player->username; $images[$index]['author_avatar'] = $entry->player->avatar_url; $images[$index]['author_url'] = 'http://dribbble.com/' . $entry->player->username; } } else { return false; } return $images; }
/** * Load slides for Twitter sourced SlideDecks * * @uses fetch_feed() * * @return array */ function get_twitter_slides($slidedeck) { $slidedeck_id = $slidedeck['id']; $args = array('sslverify' => false); switch ($slidedeck['options']['search_or_user']) { case 'search': $feed_url = 'http://search.twitter.com/search.json?q=' . urlencode($slidedeck['options']['twitter_q']) . '&include_entities=true&result_type=mixed&lang=en&rpp=' . $slidedeck['options']['total_slides']; break; case 'user': $feed_url = 'https://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $slidedeck['options']['twitter_username'] . '&include_entities=true&include_rts=true&contributor_details=true&count=' . $slidedeck['options']['total_slides']; break; } // Set a reference to the current SlideDeck for reference in actions $this->__transient_slidedeck &= $slidedeck; // Create a cache key $cache_key = $slidedeck_id . $feed_url . $slidedeck['options']['twitter_scrape_images'] . $slidedeck['options']['useGeolocationImage'] . $slidedeck['options']['feedCacheDuration'] . $this->type; // Attempt to read the cache $twitter_posts = slidedeck2_cache_read($cache_key); // If cache doesn't exist if (!$twitter_posts) { $twitter_posts = array(); $response = wp_remote_get($feed_url, $args); if (!is_wp_error($response)) { $response_json = json_decode($response['body']); switch ($slidedeck['options']['search_or_user']) { case 'search': if (!empty($response_json->results)) { foreach ($response_json->results as $index => $result) { $background = $this->get_twitter_user_background($result->from_user, $slidedeck); $tile = false; if (isset($background['tile']) && !empty($background['tile'])) { $tile = $background['tile']; } $twitter_posts[$index] = array('id' => $result->id_str, 'title' => $result->text, 'permalink' => 'http://twitter.com/' . $result->from_user . '/status/' . $result->id_str, 'image' => $this->try_fetching_tweet_image($result, $slidedeck, $result), 'image_tile' => $tile, 'author_username' => $result->from_user, 'author_name' => $result->from_user_name, 'author_url' => 'http://twitter.com/' . $result->from_user, 'author_email' => false, 'author_avatar' => $result->profile_image_url, 'content' => $this->linkify_twitter_text($result->text), 'comment_count' => false, 'plusone_count' => false, 'reshare_count' => false, 'excerpt' => $this->linkify_twitter_text($result->text), 'created_at' => $result->created_at, 'local_created_at' => $result->created_at, 'description' => $this->get_twitter_user_description($result->from_user, $slidedeck)); } } break; case 'user': foreach ($response_json as $index => $result) { // If the result is valid if (is_object($result)) { if (isset($result->retweeted_status)) { // Retweet $twitter_posts[$index] = array('id' => $result->retweeted_status->id_str, 'title' => $result->retweeted_status->text, 'permalink' => 'http://twitter.com/' . $result->retweeted_status->user->screen_name . '/status/' . $result->retweeted_status->id_str, 'image' => $this->try_fetching_tweet_image($result->retweeted_status, $slidedeck, $result->retweeted_status->user), 'image_tile' => $result->retweeted_status->user->profile_background_tile, 'author_username' => $result->retweeted_status->user->screen_name, 'author_name' => $result->retweeted_status->user->name, 'author_url' => 'http://twitter.com/' . $result->retweeted_status->user->screen_name, 'author_email' => false, 'author_avatar' => $result->retweeted_status->user->profile_image_url, 'content' => $this->linkify_twitter_text($result->retweeted_status->text), 'comment_count' => false, 'plusone_count' => false, 'reshare_count' => false, 'excerpt' => $this->linkify_twitter_text($result->retweeted_status->text), 'created_at' => $result->retweeted_status->created_at, 'local_created_at' => $result->retweeted_status->created_at, 'description' => $result->retweeted_status->user->description); // Add Replying to data for original tweet: if (!empty($result->retweeted_status->in_reply_to_screen_name)) { $twitter_posts[$index]['in_reply_to_screen_name'] = $result->retweeted_status->in_reply_to_screen_name; } if (!empty($result->retweeted_status->in_reply_to_status_id_str)) { $twitter_posts[$index]['in_reply_to_status_id_str'] = $result->retweeted_status->in_reply_to_status_id_str; } } else { // Normal Tweet $twitter_posts[$index] = array('id' => $result->id_str, 'title' => $result->text, 'permalink' => 'http://twitter.com/' . $result->user->screen_name . '/status/' . $result->id_str, 'image' => $this->try_fetching_tweet_image($result, $slidedeck, $result->user), 'image_tile' => $result->user->profile_background_tile, 'author_username' => $result->user->screen_name, 'author_name' => $result->user->name, 'author_url' => 'http://twitter.com/' . $result->user->screen_name, 'author_email' => false, 'author_avatar' => $result->user->profile_image_url, 'content' => $this->linkify_twitter_text($result->text), 'comment_count' => false, 'plusone_count' => false, 'reshare_count' => false, 'excerpt' => $this->linkify_twitter_text($result->text), 'created_at' => $result->created_at, 'local_created_at' => $result->created_at, 'description' => $result->user->description); // Add Replying to data: if (!empty($result->in_reply_to_screen_name)) { $twitter_posts[$index]['in_reply_to_screen_name'] = $result->in_reply_to_screen_name; } if (!empty($result->in_reply_to_status_id_str)) { $twitter_posts[$index]['in_reply_to_status_id_str'] = $result->in_reply_to_status_id_str; } } } } break; } } else { return false; } // Write the cache slidedeck2_cache_write($cache_key, $twitter_posts, $slidedeck['options']['feedCacheDuration']); } return $twitter_posts; }
/** * Upgrade Button * * Outputs the green upgrade button that displays contextually. * * @param string $message_text The button area subtitle * * @param string $button_text The main button text CTA * */ function upgrade_button($context = 'manage') { $tier = self::highest_installed_tier(); if ($tier == 'tier_30') { return ''; } // Here's the defaults $defaults = array('cta_text' => 'Upgrade', 'message_text' => 'Get more from SlideDeck', 'cta_url' => slidedeck2_action("/upgrades")); $array_data = array('tier_5' => array('manage' => array('message_text' => 'Get more lenses!'), 'edit' => array('message_text' => 'Get more sources!'), 'lenses' => array('message_text' => 'Copy and edit lenses!')), 'tier_10' => array('manage' => array('message_text' => 'Get more custom slides'), 'edit' => array('message_text' => 'Get the Classic lens'), 'lenses' => array('message_text' => 'Copy and edit lenses!')), 'tier_20' => array('manage' => array('message_text' => 'Get more custom slides'), 'edit' => array('message_text' => 'Use SlideDeck on more sites'), 'lenses' => array('message_text' => 'Copy and edit lenses!'))); // Fetch the data (using cache!) $url = SLIDEDECK2_UPDATE_SITE . '/upgrade-buttons.json?v=' . SLIDEDECK2_VERSION; $response = slidedeck2_cache_read($url); if (!$response) { $response = wp_remote_get($url, array('sslverify' => false)); if (!is_wp_error($response)) { slidedeck2_cache_write($url, $response, 60 * 60 * 24); // Decode the data $array_data = json_decode($response['body'], true); } else { slidedeck2_cache_write($url, '', 60 * 60 * 24); } } /** * Use the default values if all else fails. * If the found data isn't empty, replace the defaults. */ $values = $defaults; if (isset($array_data[$tier][$context]) && !empty($array_data[$tier][$context])) { $values = array_merge($defaults, $array_data[$tier][$context]); $values['tier'] = $tier; $values['context'] = $context; } // Render the button! ob_start(); include SLIDEDECK2_DIRNAME . '/views/elements/_upgrade_button.php'; $html = ob_get_contents(); ob_end_clean(); return $html; }
/** * Get a video's thumbnail * * Extract's a video's ID and provider from the URL and retrieves the URL for the * thumbnail of the video from its video service's thumbnail service. * * @param string $video_url The URL of the video being queried * * @uses is_wp_error() * @uses slidedeck2_cache_read() * @uses slidedeck2_cache_write() * @uses SlideDeck::get_video_id_from_url() * @uses SlideDeck::get_video_provider_slug_from_url() * @uses wp_remote_get() * * @return string */ function get_video_thumbnail($video_url) { $video_id = $this->get_video_id_from_url($video_url); $video_provider = $this->get_video_provider_slug_from_url($video_url); $thumbnail_url = SLIDEDECK2_URLPATH . '/images/icon-invalid.png'; switch ($video_provider) { case 'youtube': $thumbnail_url = 'http://img.youtube.com/vi/' . $video_id . '/2.jpg'; break; case 'dailymotion': $thumbnail_url = 'http://www.dailymotion.com/thumbnail/160x120/video/' . $video_id; break; case 'vimeo': // Create a cache key $cache_key = 'video-' . $video_provider . $video_id . 'vimeo-thumbs'; // Attempt to read the cache $_thumbnail_url = slidedeck2_cache_read($cache_key); // if cache doesn't exist if (!$_thumbnail_url) { $response = wp_remote_get('http://vimeo.com/api/v2/video/' . $video_id . '.json'); if (!is_wp_error($response)) { $response_json = json_decode($response['body']); $video = reset($response_json); $thumbnail_url = $video->thumbnail_small; // Write the cache slidedeck2_cache_write($cache_key, $thumbnail_url, $this->default_options['cache_duration']); } } break; } return $thumbnail_url; }
/** * Load all slides associated with this SlideDeck * * @param integer $slidedeck_id The ID of the SlideDeck being loaded * * @uses WP_Query * @uses get_the_title() * @uses maybe_unserialize() */ function get_slides_nodes($slidedeck) { $args = array('sslverify' => false); $slidedeck_id = $slidedeck['id']; $last_used_youtube_api_key = get_option($this->namespace . '_last_saved_youtube_api_key'); if (isset($slidedeck['options']['youtube_playlist']) && !empty($slidedeck['options']['youtube_playlist'])) { switch ($slidedeck['options']['search_or_user']) { case 'channel_id': switch ($slidedeck['options']['youtube_playlist']) { case 'recent': // Feed of the user's recent Videos $feed_url = "https://www.googleapis.com/youtube/v3/search?key=" . $last_used_youtube_api_key . "&channelId=" . $slidedeck['options']['youtube_channel'] . "&part=snippet,id&order=date&maxResults=20"; break; default: // Feed of the Playlist's Videos $feed_url = $slidedeck['options']['youtube_playlist'] . '&part=snippet&maxResults=' . $slidedeck['options']['total_slides'] . '&key=' . $last_used_youtube_api_key; break; } break; case 'user': switch ($slidedeck['options']['youtube_playlist']) { case 'recent': // Feed of the user's recent Videos $feed_url = 'https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername='******'options']['youtube_username'] . '&key=' . $last_used_youtube_api_key; //$feed_url = 'https://www.googleapis.com/youtube/v3/playlists?part=snippet&id='.$slidedeck['options']['youtube_username'].'&key='.$last_used_youtube_api_key; break; default: // Feed of the Playlist's Videos $feed_url = $slidedeck['options']['youtube_playlist'] . '&part=snippet&maxResults=' . $slidedeck['options']['total_slides'] . '&key=' . $last_used_youtube_api_key; break; } break; case 'search': $feed_url = 'https://www.googleapis.com/youtube/v3/search/?q=' . urlencode($slidedeck['options']['youtube_q']) . '&part=snippet&maxResults=' . $slidedeck['options']['total_slides'] . '&key=' . $last_used_youtube_api_key; break; } /* * Added by Ranjith * Get video id's if videos from selected is username */ if ($slidedeck['options']['search_or_user'] === "user") { $channel_response = wp_remote_get($feed_url, $args); if (!is_wp_error($channel_response)) { // get the channel id first $channel_response_json = json_decode($channel_response['body']); $channel_response_count = count($channel_response_json->items); $video_ids = array(); for ($i = 0; $i < $channel_response_count; $i++) { if ($slidedeck['options']['youtube_playlist'] != 'recent') { $video_ids[] = $channel_response_json->items[$i]->snippet->resourceId->videoId; } else { $channel_id = $channel_response_json->items[$i]->id; // get videos based on channel id $feed_url = "https://www.googleapis.com/youtube/v3/search?key=" . $last_used_youtube_api_key . "&channelId=" . $channel_id . "&part=snippet,id&order=date&maxResults=20"; $response = wp_remote_get($feed_url, $args); if (!is_wp_error($response)) { $response_json = json_decode($response['body']); $respons_item_count = count($response_json->items); for ($i = 0; $i < $respons_item_count; $i++) { if (isset($response_json->items[$i]->id->videoId)) { $video_ids[] = $response_json->items[$i]->id->videoId; } } } } } $video_ids_string = implode(',', $video_ids); /* * Added by Ranjith * Build url to get all videos from playlist */ $feed_url = 'https://www.googleapis.com/youtube/v3/videos?part=snippet&id=' . $video_ids_string . '&maxResults=5&key=' . $last_used_youtube_api_key; } } if ($slidedeck['options']['search_or_user'] === 'channel_id') { $response = wp_remote_get($feed_url, $args); $video_ids = array(); if (!is_wp_error($response)) { $response_json = json_decode($response['body']); if (isset($response_json->items)) { $respons_item_count = count($response_json->items); } else { $respons_item_count = 0; } for ($i = 0; $i < $respons_item_count; $i++) { if ($slidedeck['options']['youtube_playlist'] != 'recent') { $video_ids[] = $response_json->items[$i]->snippet->resourceId->videoId; } else { $video_ids[] = $response_json->items[$i]->id->videoId; } } $video_ids_string = implode(',', $video_ids); /* * Added by Ranjith * Build url to get all videos from playlist */ $feed_url = 'https://www.googleapis.com/youtube/v3/videos?part=snippet&id=' . $video_ids_string . '&maxResults=5&key=' . $last_used_youtube_api_key; } } // Create a cache key $cache_key = $slidedeck_id . $feed_url . $slidedeck['options']['cache_duration'] . $this->name; $response = slidedeck2_cache_read($cache_key); if (!$response) { $response = wp_remote_get($feed_url, $args); if (!is_wp_error($response)) { // Write the cache if a valid response if (!empty($response)) { slidedeck2_cache_write($cache_key, $response, $slidedeck['options']['cache_duration']); } } } // Fail if an error occured if (is_wp_error($response)) { return false; } $response_json = json_decode($response['body']); // Fallback fail if response was empty if (empty($response_json)) { return false; } $videos = array(); $count = 0; if (isset($response_json->items)) { $response_count = count($response_json->items); } else { $response_count = 0; } /* * Changed by Ranjith to retreive values from response json */ for ($i = 0; $i < $response_count; $i++) { if ($count < $slidedeck['options']['total_slides']) { if ($slidedeck['options']['search_or_user'] != 'search') { $video_id = $response_json->items[$i]->id; } else { $video_id = $response_json->items[$i]->id->videoId; } $url = 'http://www.youtube.com/watch?v=' . $video_id; $videos[$i]['author_username'] = $slidedeck['options']['youtube_username']; $videos[$i]['author_name'] = $slidedeck['options']['youtube_username']; $videos[$i]['author_url'] = "http://www.youtube.com/user/" . $slidedeck['options']['youtube_username']; // Set the created time even though we'll overload it shortly... $videos[$i]['created_at'] = strtotime($response_json->items[$i]->snippet->publishedAt); $videos[$i]['video_meta'] = $this->get_video_meta_from_url($url); // Overwrite the created_at date with potentially more accurate info. $videos[$i]['created_at'] = $videos[$i]['video_meta']['created_at']; } $count++; } } return $videos; }
/** * Load all slides associated with this SlideDeck * * @param integer $slidedeck_id The ID of the SlideDeck being loaded * * @uses WP_Query * @uses get_the_title() * @uses maybe_unserialize() */ function get_slides($slidedeck) { $args = array('sslverify' => false); $slidedeck_id = $slidedeck['id']; switch ($slidedeck['source']) { /** * List of Video URLs from YouTube, Dailymotion, Vimeo */ case 'listofvideos': $slidedeck_list_of_videos = get_post_meta($slidedeck_id, "{$this->namespace}_list_of_videos", true); if (empty($slidedeck_list_of_videos)) { $slidedeck_list_of_videos = $slidedeck['options']['slidedeck_list_of_videos']; } $cleaned_urls = trim(preg_replace('/[\\n\\r]+/', "\n", $slidedeck_list_of_videos)); $urls = explode("\n", $cleaned_urls); $videos = array(); foreach ($urls as $key => $url) { // Add the ID. $videos[$key]['id'] = $this->get_video_id_from_url($url); // Add the provider. $videos[$key]['service'] = $this->get_video_provider_slug_from_url($url); if (!empty($videos[$key]['service']) && isset($videos[$key]['service'])) { // Get the meta. $videos[$key]['meta'] = $this->get_video_meta($videos[$key]['service'], $videos[$key]['id']); } } break; // List /** * YouTube API User's recent videos and playlists */ // List /** * YouTube API User's recent videos and playlists */ case 'youtube': if (isset($slidedeck['options']['youtube_playlist']) && !empty($slidedeck['options']['youtube_playlist'])) { switch ($slidedeck['options']['search_or_user']) { case 'user': switch ($slidedeck['options']['youtube_playlist']) { case 'recent': // Feed of the user's recent Videos $feed_url = 'https://gdata.youtube.com/feeds/api/users/' . $slidedeck['options']['youtube_username'] . '/uploads?alt=json&max-results=' . $slidedeck['options']['total_slides']; break; default: // Feed of the Playlist's Videos $feed_url = $slidedeck['options']['youtube_playlist'] . '?alt=json&max-results=' . $slidedeck['options']['total_slides']; break; } break; case 'search': $feed_url = 'https://gdata.youtube.com/feeds/api/videos?alt=json&max-results=' . $slidedeck['options']['total_slides'] . '&q=' . urlencode($slidedeck['options']['youtube_q']); break; } // Create a cache key $cache_key = $slidedeck_id . $feed_url . $slidedeck['options']['feedCacheDuration'] . $this->type; // Attempt to read the cache $videos = slidedeck2_cache_read($cache_key); // If cache doesn't exist if (!$videos) { $videos = array(); $response = wp_remote_get($feed_url, $args); if (!is_wp_error($response)) { $response_json = json_decode($response['body']); if (!empty($response_json)) { foreach ($response_json->feed->entry as $key => $entry) { /** * Loop through the links and grab the * rel link. */ foreach ($entry->link as $link) { if ($link->rel == 'alternate') { $url = $link->href; } } // Add the ID. $videos[$key]['id'] = $this->get_video_id_from_url($url); // Add the provider. $videos[$key]['service'] = $this->get_video_provider_slug_from_url($url); if (!empty($videos[$key]['service']) && isset($videos[$key]['service'])) { // Get the meta. $videos[$key]['meta'] = $this->get_video_meta($videos[$key]['service'], $videos[$key]['id']); } } } } else { return false; } // Write the cache slidedeck2_cache_write($cache_key, $videos, $slidedeck['options']['feedCacheDuration']); } } break; // YouTube /** * Vimeo API User's recent videos and playlists */ // YouTube /** * Vimeo API User's recent videos and playlists */ case 'vimeo': if (isset($slidedeck['options']['vimeo_album']) && !empty($slidedeck['options']['vimeo_album'])) { switch ($slidedeck['options']['vimeo_album']) { case 'recent': $feed_url = 'http://vimeo.com/api/v2/' . $slidedeck['options']['vimeo_username'] . '/videos.json?page=1'; break; default: // Feed of the Playlist's Videos $feed_url = $slidedeck['options']['vimeo_album']; break; } // Create a cache key $cache_key = $slidedeck_id . $feed_url . $slidedeck['options']['feedCacheDuration'] . $slidedeck['options']['total_slides'] . $this->type; // Attempt to read the cache $videos = slidedeck2_cache_read($cache_key); // If cache doesn't exist if (!$videos) { $videos = array(); $response = wp_remote_get($feed_url, $args); if (!is_wp_error($response)) { $response_json = json_decode($response['body']); if (!empty($response_json)) { $count = 0; foreach ($response_json as $key => $entry) { if ($count < $slidedeck['options']['total_slides']) { $url = $entry->url; // Add the ID. $videos[$key]['id'] = $this->get_video_id_from_url($url); // Add the provider. $videos[$key]['service'] = $this->get_video_provider_slug_from_url($url); if (!empty($videos[$key]['service']) && isset($videos[$key]['service'])) { // Get the meta. $videos[$key]['meta'] = $this->get_video_meta($videos[$key]['service'], $videos[$key]['id']); } } $count++; } } } else { return false; } // Write the cache slidedeck2_cache_write($cache_key, $videos, $slidedeck['options']['feedCacheDuration']); } } break; // Vimeo /** * Dailymotion API User's recent videos and playlists * This has been somewhat unreliable. */ // Vimeo /** * Dailymotion API User's recent videos and playlists * This has been somewhat unreliable. */ case 'dailymotion': if (isset($slidedeck['options']['dailymotion_playlist']) && !empty($slidedeck['options']['dailymotion_playlist'])) { switch ($slidedeck['options']['dailymotion_playlist']) { case 'recent': $feed_url = 'https://api.dailymotion.com/user/' . $slidedeck['options']['dailymotion_username'] . '/videos?limit=' . $slidedeck['options']['total_slides']; break; default: // Feed of the Playlist's Videos $feed_url = $slidedeck['options']['dailymotion_playlist'] . '?limit=' . $slidedeck['options']['total_slides']; break; } // Create a cache key $cache_key = $slidedeck_id . $feed_url . $slidedeck['options']['feedCacheDuration'] . $slidedeck['options']['total_slides'] . $this->type; // Attempt to read the cache $videos = slidedeck2_cache_read($cache_key); // If cache doesn't exist if (!$videos) { $videos = array(); $response = wp_remote_get($feed_url, $args); if (!is_wp_error($response)) { $response_json = json_decode($response['body']); if (!empty($response_json)) { foreach ($response_json->list as $key => $entry) { $url = 'http://www.dailymotion.com/video/' . $entry->id; // Add the ID. $videos[$key]['id'] = $this->get_video_id_from_url($url); // Add the provider. $videos[$key]['service'] = $this->get_video_provider_slug_from_url($url); if (!empty($videos[$key]['service']) && isset($videos[$key]['service'])) { // Get the meta. $videos[$key]['meta'] = $this->get_video_meta($videos[$key]['service'], $videos[$key]['id']); } } } } else { return false; } // Write the cache slidedeck2_cache_write($cache_key, $videos, $this->default_options['feedCacheDuration']); } } break; // Dailymotion } return $videos; }
/** * Load all slides associated with this SlideDeck * * @param integer $slidedeck_id The ID of the SlideDeck being loaded * * @uses WP_Query * @uses get_the_title() * @uses maybe_unserialize() */ function get_slides_nodes($slidedeck) { $args = array('sslverify' => false); $slidedeck_id = $slidedeck['id']; if (isset($slidedeck['options']['vimeo_album']) && !empty($slidedeck['options']['vimeo_album'])) { switch ($slidedeck['options']['vimeo_album']) { case 'recent': $feed_url = 'http://vimeo.com/api/v2/' . $slidedeck['options']['vimeo_username'] . '/videos.json?page=1'; break; default: // Feed of the Playlist's Videos $feed_url = $slidedeck['options']['vimeo_album']; break; } // Create a cache key $cache_key = $slidedeck_id . $feed_url . $slidedeck['options']['cache_duration'] . $slidedeck['options']['total_slides'] . $this->name; $response = slidedeck2_cache_read($cache_key); if (!$response) { $response = wp_remote_get($feed_url, $args); if (!is_wp_error($response)) { // Write the cache if a valid response if (!empty($response)) { slidedeck2_cache_write($cache_key, $response, $slidedeck['options']['cache_duration']); } } } // Fail if an error occured if (is_wp_error($response)) { return false; } $response_json = json_decode($response['body']); // Fallback fail if response was empty if (empty($response_json)) { return false; } $count = 0; foreach ($response_json as $key => $entry) { if ($count < $slidedeck['options']['total_slides']) { $videos[$key]['created_at'] = strtotime($entry->upload_date); $videos[$key]['author_name'] = $entry->user_name; $videos[$key]['author_url'] = $entry->user_url; $videos[$key]['author_avatar'] = $entry->user_portrait_small; $videos[$key]['video_meta'] = $this->get_video_meta_from_url($entry->url); } $count++; } } return $videos; }
function get_instagram_userid($token, $username) { $args = array('sslverify' => false); // We do the extra trimming and URL encoding because technically... it's a search. $feed_url = 'https://api.instagram.com/v1/users/search?access_token=' . $token . '&q=' . urlencode(trim($username)) . '&count=1'; // Create a cache key $cache_key = 'instagram-search' . $username; // Attempt to read the cache $response = slidedeck2_cache_read($cache_key); // If cache doesn't exist if (!$response) { $response = wp_remote_get($feed_url, $args); // Write the cache slidedeck2_cache_write($cache_key, $response, 60 * 60 * 24); } if (!is_wp_error($response)) { $response_json = json_decode($response['body']); return (string) $response_json->data[0]->id; } return false; }
/** * Get Google Plus Image Feed * * Fetches a Google Plus feed, caches it and returns the * cached result or the results after caching them. * * @param string $feed_url The URL of the gplus feed with a JSON response * @param integer $slidedeck_id The ID of the deck (for caching) * * @return array An array of arrays containing the images and various meta. */ function get_slides_nodes($slidedeck) { $args = array('sslverify' => false); $gplus_user_id = $slidedeck['options']['gplus_user_id']; $max_image_size = $slidedeck['options']['gplus_max_image_size']; // API Max: http://code.google.com/apis/picasaweb/docs/2.0/reference.html#Parameters switch ($slidedeck['options']['gplus_images_album']) { case 'recent': $feed_url = 'http://photos.googleapis.com/data/feed/api/user/' . $gplus_user_id . '?kind=photo&alt=json&imgmax=' . $max_image_size . '&max-results=' . $slidedeck['options']['total_slides']; break; default: $album_id = (string) $slidedeck['options']['gplus_images_album']; $feed_url = 'http://photos.googleapis.com/data/feed/api/user/' . $gplus_user_id . '/albumid/' . $album_id . '?alt=json&imgmax=' . $max_image_size . '&max-results=' . $slidedeck['options']['total_slides']; break; } // Create a cache key $cache_key = $slidedeck['id'] . $feed_url . $slidedeck['options']['cache_duration'] . $this->name; // Attempt to read the cache $response = slidedeck2_cache_read($cache_key); if (!$response) { $response = wp_remote_get($feed_url, $args); if (!is_wp_error($response)) { // Write the cache if (!empty($response_json)) { slidedeck2_cache_write($cache_key, $response, $slidedeck['options']['cache_duration']); } } else { return false; } } // Fail if an error occured if (is_wp_error($response)) { return false; } $response_json = json_decode($response['body']); // If the response JSON was empty, end processing if (empty($response_json)) { return false; } $images = array(); foreach ((array) $response_json->feed->entry as $index => $entry) { $images[$index]['title'] = urldecode($entry->title->{'$t'}); $images[$index]['description'] = $entry->summary->{'$t'}; $images[$index]['width'] = $entry->{'gphoto$width'}->{'$t'}; $images[$index]['height'] = $entry->{'gphoto$height'}->{'$t'}; $images[$index]['created_at'] = strtotime($entry->published->{'$t'}); $images[$index]['image'] = preg_replace('/^(http:|https:)/', '', $entry->content->src); $images[$index]['thumbnail'] = preg_replace('/^(http:|https:)/', '', $entry->{'media$group'}->{'media$thumbnail'}[1]->url); $url = ""; foreach ($entry->link as $link) { // Make accommodation for videos to link to the canonical source instead of the alternate since the alternate does not work yet for videos if (isset($entry->{'gphoto$originalvideo'})) { if (preg_match("/canonical\$/", $link->rel)) { $url = $link->href; } } else { if ($link->rel == 'alternate') { $url = $link->href; } } } $images[$index]['permalink'] = $url; $images[$index]['comments_count'] = $entry->{'gphoto$commentCount'}->{'$t'}; $images[$index]['author_name'] = $entry->{'media$group'}->{'media$credit'}[0]->{'$t'}; $images[$index]['author_url'] = 'https://picasaweb.google.com/' . $gplus_user_id; } return $images; }
/** * Load all slides associated with this SlideDeck * * @param integer $slidedeck_id The ID of the SlideDeck being loaded * * @uses WP_Query * @uses get_the_title() * @uses maybe_unserialize() */ function get_slides_nodes($slidedeck) { $args = array('sslverify' => false); $slidedeck_id = $slidedeck['id']; /** * Dailymotion API User's recent videos and playlists * This has been somewhat unreliable. */ if (isset($slidedeck['options']['dailymotion_playlist']) && !empty($slidedeck['options']['dailymotion_playlist'])) { switch ($slidedeck['options']['dailymotion_playlist']) { case 'recent': $feed_url = 'https://api.dailymotion.com/user/' . $slidedeck['options']['dailymotion_username'] . '/videos?limit=' . $slidedeck['options']['total_slides']; break; default: // Feed of the Playlist's Videos $feed_url = $slidedeck['options']['dailymotion_playlist'] . '?limit=' . $slidedeck['options']['total_slides']; break; } // Create a cache key $cache_key = $slidedeck_id . $feed_url . $slidedeck['options']['cache_duration'] . $slidedeck['options']['total_slides'] . $this->name; $response = slidedeck2_cache_read($cache_key); if (!$response) { $response = wp_remote_get($feed_url, $args); if (!is_wp_error($response)) { // Write the cache if a valid response if (!empty($response_json)) { slidedeck2_cache_write($cache_key, $response, $slidedeck['options']['cache_duration']); } } } // Fail if an error occured if (is_wp_error($response)) { return false; } $response_json = json_decode($response['body']); // Fallback fail if response was empty if (empty($response_json)) { return false; } $count = 0; foreach ($response_json->list as $key => $entry) { $videos[$key]['video_meta'] = $this->get_video_meta_from_url('http://www.dailymotion.com/video/' . $entry->id); $videos[$key]['created_at'] = $videos[$key]['video_meta']['created_at']; } } return $videos; }
/** * Upgrade Button * * Outputs the green upgrade button that displays contextually. * * @param string $message_text The button area subtitle * * @param string $button_text The main button text CTA * */ function upgrade_button($context = 'manage') { $tier = self::highest_installed_tier(); // Here's the defaults $defaults = array('context' => 'manage', 'cta_text' => 'Upgrade', 'message_text' => 'Get more from SlideDeck', 'cta_url' => slidedeck2_action("/upgrades")); $array_data = array('tier_5' => array('manage' => array('message_text' => 'Get more lenses!'), 'edit' => array('message_text' => 'Get more sources!'), 'lenses' => array('message_text' => 'Copy and edit lenses!')), 'tier_10' => array('manage' => array('message_text' => 'Get more custom slides'), 'edit' => array('message_text' => 'Get the Classic lens'), 'lenses' => array('message_text' => 'Copy and edit lenses!')), 'tier_20' => array('manage' => array('message_text' => 'Get more custom slides'), 'edit' => array('message_text' => 'Use SlideDeck on more sites'), 'lenses' => array('message_text' => 'Copy and edit lenses!'))); // Fetch the data (using cache!) $url = SLIDEDECK2_UPDATE_SITE . '/upgrade-buttons.json?v=' . SLIDEDECK2_VERSION; $response = slidedeck2_cache_read($url); if (!$response) { $response = wp_remote_get($url, array('sslverify' => false)); if (!is_wp_error($response)) { slidedeck2_cache_write($url, $response, 60 * 60 * 24); // Decode the data $array_data = json_decode($response['body'], true); } else { slidedeck2_cache_write($url, '', 60 * 60 * 24); } } /** * Use the default values if all else fails. * If the found data isn't empty, replace the defaults. */ $values = $defaults; if (isset($array_data[$tier][$context]) && !empty($array_data[$tier][$context])) { $values = array_merge($defaults, $array_data[$tier][$context]); $values['tier'] = $tier; $values['context'] = $context; } // Overrides for license renewal $renewal_message = self::get_license_key_expiry_message(); $license_key = slidedeck2_get_license_key(); // If this is the developer tier, and there's no expiry message... if ($tier == 'tier_30' && $renewal_message['type'] == 'unspecified') { return ''; } // don't return a button in this case switch ($renewal_message['type']) { case 'nearing-expiration': $values['cta_text'] = "Renew Now"; $values['cta_url'] = slidedeck2_get_renewal_url() . '&when=warning'; $values['message_text'] = "<strong>License expiring soon.</strong> Upgrade to continue getting updates and support."; if ($context == 'manage') { $values['message_text'] = "<strong>License expiring soon.</strong> Upgrade to<br>continue getting updates and support."; } break; case 'expired': $values['cta_text'] = "Expired - Renew Now"; $values['cta_url'] = slidedeck2_get_renewal_url() . '&when=expired'; $values['message_text'] = "Your license is <strong>expired</strong>. Renew to resume updates and support"; if ($context == 'manage') { $values['message_text'] = "Your license is <strong>expired</strong>. Renew to<br>resume updates and support"; } break; } // Render the button! ob_start(); include SLIDEDECK2_DIRNAME . '/views/elements/_upgrade_button.php'; $html = ob_get_contents(); ob_end_clean(); return $html; }
/** * Load all slides associated with this SlideDeck * * @param integer $slidedeck_id The ID of the SlideDeck being loaded * * @uses WP_Query * @uses get_the_title() * @uses maybe_unserialize() */ function get_slides_nodes($slidedeck) { $args = array('sslverify' => false); $slidedeck_id = $slidedeck['id']; if (isset($slidedeck['options']['youtube_playlist']) && !empty($slidedeck['options']['youtube_playlist'])) { switch ($slidedeck['options']['search_or_user']) { case 'user': switch ($slidedeck['options']['youtube_playlist']) { case 'recent': // Feed of the user's recent Videos $feed_url = 'https://gdata.youtube.com/feeds/api/users/' . $slidedeck['options']['youtube_username'] . '/uploads?alt=json&max-results=' . $slidedeck['options']['total_slides']; break; default: // Feed of the Playlist's Videos $feed_url = $slidedeck['options']['youtube_playlist'] . '?alt=json&max-results=' . $slidedeck['options']['total_slides']; break; } break; case 'search': $feed_url = 'https://gdata.youtube.com/feeds/api/videos?alt=json&max-results=' . $slidedeck['options']['total_slides'] . '&q=' . urlencode($slidedeck['options']['youtube_q']); break; } // Create a cache key $cache_key = $slidedeck_id . $feed_url . $slidedeck['options']['cache_duration'] . $this->name; $response = slidedeck2_cache_read($cache_key); if (!$response) { $response = wp_remote_get($feed_url, $args); if (!is_wp_error($response)) { // Write the cache if a valid response if (!empty($response)) { slidedeck2_cache_write($cache_key, $response, $slidedeck['options']['cache_duration']); } } } // Fail if an error occured if (is_wp_error($response)) { return false; } $response_json = json_decode($response['body']); // Fallback fail if response was empty if (empty($response_json)) { return false; } $videos = array(); $count = 0; foreach ($response_json->feed->entry as $key => $entry) { if ($count < $slidedeck['options']['total_slides']) { /** * Loop through the links and grab the * rel link. */ foreach ($entry->link as $link) { if ($link->rel == 'alternate') { $url = $link->href; } } if (isset($entry->author)) { $author = reset($entry->author); $videos[$key]['author_username'] = $author->name->{'$t'}; $videos[$key]['author_name'] = $author->name->{'$t'}; $videos[$key]['author_url'] = "http://www.youtube.com/user/" . $author->name->{'$t'}; } // Set the created time even though we'll overload it shortly... $videos[$key]['created_at'] = strtotime($entry->published->{'$t'}); // Fetch the meta for this specific video $videos[$key]['video_meta'] = $this->get_video_meta_from_url($url); // Overwrite the created_at date with potentially more accurate info. $videos[$key]['created_at'] = $videos[$key]['video_meta']['created_at']; } $count++; } } return $videos; }
/** * Load slides for Google+ feed sourced SlideDecks * * @uses fetch_feed() * @uses $SlideDeck->get_dimensions() * * @return array */ function get_slides_nodes($slidedeck) { $slides = array(); $slidedeck_id = $slidedeck['id']; $slidedeck_dimensions = $this->get_dimensions($slidedeck); $expansion_factor = 1; // We may want to adjust this to multiply the size later $expanded_width = $slidedeck_dimensions['outer_width'] * $expansion_factor; $expanded_height = $slidedeck_dimensions['outer_height'] * $expansion_factor; $args = array('sslverify' => false); if (isset($slidedeck['options']['gplusUserId']) && !empty($slidedeck['options']['gplusUserId']) && isset($slidedeck['options']['gplus_api_key']) && !empty($slidedeck['options']['gplus_api_key'])) { // https Google Plus public posts feed: $feed_url = 'https://www.googleapis.com/plus/v1/people/' . $slidedeck['options']['gplusUserId'] . '/activities/public?key=' . $slidedeck['options']['gplus_api_key'] . '&maxResults=' . $slidedeck['options']['total_slides'] . '&alt=json'; } else { return $slides; } // Set a reference to the current SlideDeck for reference in actions $this->__transient_slidedeck &= $slidedeck; // Create a cache key $cache_key = $slidedeck_id . $feed_url . $slidedeck['options']['cache_duration'] . $this->name; // Attempt to read the cache $response = slidedeck2_cache_read($cache_key); if (!$response) { $response = wp_remote_get($feed_url, $args); // Write the cache if (!is_wp_error($response)) { if (!empty($response_json)) { slidedeck2_cache_write($cache_key, $response, $slidedeck['options']['cache_duration']); } } else { // Kill processing if we were unable to get the response return false; } } // Fail if an error occured if (is_wp_error($response)) { return false; } $response_json = json_decode($response['body']); // If the response JSON was empty, end processing if (empty($response_json)) { return false; } // Begin building the processed Google+ slide node array $gplus_posts = array(); foreach ((array) $response_json->items as $entry) { /** * If the post was a re-share then hanle differently. */ if ($entry->verb == 'share') { $author_name = $entry->object->actor->displayName; $author_first_name = $entry->object->actor->displayName; $author_url = $entry->object->actor->url; $author_avatar = $entry->object->actor->image->url; } else { $author_name = $entry->actor->displayName; $author_first_name = $entry->actor->name->givenName; $author_url = $entry->actor->url; $author_avatar = $entry->actor->image->url; } // Set default title $title = $entry->title; // Extra excerpt $article_excerpt = ''; // Look for media: $post_image = false; $post_video = false; if (!empty($entry->object->attachments) && isset($entry->object->attachments)) { foreach ($entry->object->attachments as $attachment) { // If there's an image, grab it... if (property_exists($attachment, 'image')) { $post_image = $attachment->image->url; } // if there's a full image, grab it too! if (property_exists($attachment, 'fullImage')) { /** * If there's no width or height on the fullImage, Google doesn't return * an image URL, but it returns a page URL instead. In this case, we should * set the image to false. (the threshold is around 150px or so) */ if (isset($attachment->fullImage->width) && isset($attachment->fullImage->height)) { $post_image = $attachment->fullImage->url; } else { $post_image = false; } } // If there's a video, grab its data if (property_exists($attachment, 'embed')) { $post_video = $attachment->embed->url; } // Override title if an article is attached ie: A link with images if ($attachment->objectType == 'article') { // Add the article title if one exists. if (isset($attachment->displayName) && !empty($attachment->displayName)) { $title = $attachment->displayName; } // Fill the extra excerpt content if it exists. if (isset($attachment->content) && !empty($attachment->content)) { $article_excerpt = $attachment->content; } } } } /** * If the post was a checkin (business level location attached) * * For Checkins, it would be nice to say that 'User' Checked in 'Place', * so let's modify the title so it says so. G+ has no titles really * anyway, so it's no big deal... I think. */ if ($entry->verb == 'checkin') { if (isset($entry->placeName) && !empty($entry->placeName)) { $title = "{$author_first_name} checked in at {$entry->placeName}"; } /** * If we've gotten this far, and there's no image, let's use a map! * We love images! Images are good m'kay? */ if (empty($post_image)) { $geocode = str_replace(' ', ',', $entry->geocode); // lat,lon $scale_factor = 2; // Integer! $map_zoom_level = 16; // Integer! $post_image = 'http://maps.googleapis.com/maps/api/staticmap?sensor=false&format=png8&markers=' . $geocode . '¢er=' . $geocode . '&zoom=' . $map_zoom_level . '&maptype=roadmap&scale=' . $scale_factor . '&size=' . round($expanded_width / $scale_factor) . 'x' . round($expanded_height / $scale_factor); } } /** * Build the final array of cool stuff for the Google+ Slide: */ $gplus_posts[] = array('id' => $entry->id, 'title' => $title, 'permalink' => $entry->url, 'image' => preg_replace('/^(http:|https:)/', '', $post_image), 'video' => $post_video, 'author_name' => $author_name, 'author_url' => $author_url, 'author_email' => false, 'author_avatar' => $author_avatar, 'content' => empty($entry->object->content) ? $entry->object->content : false, 'comment_count' => $entry->object->replies->totalItems, 'plusone_count' => $entry->object->plusoners->totalItems, 'reshare_count' => $entry->object->resharers->totalItems, 'excerpt' => strip_tags($entry->object->content . ' ' . $article_excerpt, "<b><strong><i><em><a>"), 'created_at' => strtotime($entry->published), 'local_created_at' => $entry->published); } return $gplus_posts; }