/** * Pulls information about multiple vimeo IDs but for each id it makes an api call * @param $video_ids * * @return array|bool */ private static function vimeo_api_get_videos_info($video_ids) { $buffy_videos = array(); foreach ($video_ids as $video_id) { $api_url = 'http://vimeo.com/api/v2/video/' . $video_id . '.php'; // this is the old api vimeo maintained for thumbnail_small which should not be gotten without OAuth of the new api $php_serialized_api_response = td_remote_http::get_page($api_url, __CLASS__); // check for a response if ($php_serialized_api_response === false) { td_log::log(__FILE__, __FUNCTION__, 'api call failed', $api_url); continue; // try with the next one } // try to deserialize $api_response = @unserialize($php_serialized_api_response); if ($api_response === false) { td_log::log(__FILE__, __FUNCTION__, 'Error decoding the php serialized vimeo api', $api_response); continue; } @($buffy_videos[$video_id] = array('thumb' => $api_response[0]['thumbnail_small'], 'title' => $api_response[0]['title'], 'time' => gmdate("H:i:s", intval($api_response[0]['duration'])))); } // return false on no videos if (!empty($buffy_videos)) { return $buffy_videos; } return false; }
/** * adds to the &$weather_data the information for the next 5 days * @param $atts - the shortcode atts * @param $weather_data - BYREF weather data - this function will add to it * * @return bool|string * - true: if everything is ok * - string: the error message, if there was an error */ private static function owm_get_five_days_data($atts, &$weather_data) { // request 7 days because the current day may be today in a different timezone $today_weather_url = 'http://api.openweathermap.org/data/2.5/forecast/daily?q=' . urlencode($atts['w_location']) . '&lang=' . $atts['w_language'] . '&units=metric&cnt=7&appid=' . $weather_data['api_key']; $json_api_response = td_remote_http::get_page($today_weather_url, __CLASS__); // fail if ($json_api_response === false) { return 'Error getting remote data for 5 days forecast. Please check your server configuration'; } // try to decode the json $api_response = @json_decode($json_api_response, true); if ($api_response === null and json_last_error() !== JSON_ERROR_NONE) { return 'Error decoding the json from OpenWeatherMap'; } // today in format like: 20150210 $today_date = date('Ymd', current_time('timestamp', 0)); if (!empty($api_response['list']) and is_array($api_response['list'])) { $cnt = 0; foreach ($api_response['list'] as $index => $day_forecast) { if (!empty($day_forecast['dt']) and !empty($day_forecast['temp']['day']) and $today_date < date('Ymd', $day_forecast['dt'])) { // because the api return UTC time and we may have different timezones on the server. Avoid showing the same day twice if ($cnt > 4) { // show only 5 break; } $weather_data['forecast'][] = array('timestamp' => $day_forecast['dt'], 'day_temp' => array(round($day_forecast['temp']['day']), round(self::celsius_to_fahrenheit($day_forecast['temp']['day']))), 'day_name' => date_i18n('D', $day_forecast['dt']), 'owm_day_index' => $index); $cnt++; } } } return true; // return true if ~everything is ok }
/** * Returns the video thumb url from the video URL * @param $videoUrl * @return string */ private static function get_thumb_url($videoUrl) { switch (self::detect_video_service($videoUrl)) { case 'youtube': $yt_1920_url = td_global::$http_or_https . '://img.youtube.com/vi/' . self::get_youtube_id($videoUrl) . '/maxresdefault.jpg'; $yt_640_url = td_global::$http_or_https . '://img.youtube.com/vi/' . self::get_youtube_id($videoUrl) . '/sddefault.jpg'; $yt_480_url = td_global::$http_or_https . '://img.youtube.com/vi/' . self::get_youtube_id($videoUrl) . '/hqdefault.jpg'; if (!self::is_404($yt_1920_url)) { return $yt_1920_url; } elseif (!self::is_404($yt_640_url)) { return $yt_640_url; } elseif (!self::is_404($yt_480_url)) { return $yt_480_url; } else { td_log::log(__FILE__, __FUNCTION__, 'No suitable thumb found for youtube.', $videoUrl); } break; case 'dailymotion': $dailymotion_api_json = td_remote_http::get_page('https://api.dailymotion.com/video/' . self::get_dailymotion_id($videoUrl) . '?fields=thumbnail_url', __CLASS__); if ($dailymotion_api_json !== false) { $dailymotion_api = @json_decode($dailymotion_api_json); if ($dailymotion_api === null and json_last_error() !== JSON_ERROR_NONE) { td_log::log(__FILE__, __FUNCTION__, 'json decaode failed for daily motion api', $videoUrl); return ''; } if (!empty($dailymotion_api) and !empty($dailymotion_api->thumbnail_url)) { return $dailymotion_api->thumbnail_url; } } break; case 'vimeo': //@todo e stricat nu mai merge de ceva timp cred $url = 'http://vimeo.com/api/oembed.json?url=https://vimeo.com/' . self::get_vimeo_id($videoUrl); $response = wp_remote_get($url, array('timeout' => 10, 'sslverify' => false, 'user-agent' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0')); if (!is_wp_error($response)) { $td_result = @json_decode(wp_remote_retrieve_body($response)); return $td_result->thumbnail_url; } break; } return ''; }