X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Foembedhelper.php;h=903f80c581a03b92a17ec5f2a698809d9c307cab;hb=d81b25729005973e6daa27fc787a042f05a12c94;hp=3cd20c8e8efb1c3d82990c95e4cc0b3d79306c2c;hpb=32eb4c5e2d13ff527494a1ca84e326fcf52cb5cb;p=quix0rs-gnu-social.git diff --git a/lib/oembedhelper.php b/lib/oembedhelper.php index 3cd20c8e8e..903f80c581 100644 --- a/lib/oembedhelper.php +++ b/lib/oembedhelper.php @@ -43,6 +43,13 @@ class oEmbedHelper protected static $apiMap = array( 'flickr.com' => 'http://www.flickr.com/services/oembed/', 'yfrog.com' => 'http://www.yfrog.com/api/oembed', + 'youtube.com' => 'http://www.youtube.com/oembed', + 'viddler.com' => 'http://lab.viddler.com/services/oembed/', + 'qik.com' => 'http://qik.com/api/oembed.json', + 'revision3.com' => 'http://revision3.com/api/oembed/', + 'hulu.com' => 'http://www.hulu.com/api/oembed.json', + 'vimeo.com' => 'http://www.vimeo.com/api/oembed.json', + 'my.opera.com' => 'http://my.opera.com/service/oembed', ); protected static $functionMap = array( 'twitpic.com' => 'oEmbedHelper::twitPic', @@ -54,7 +61,7 @@ class oEmbedHelper * Some known hosts are whitelisted with API endpoints where we * know they exist but autodiscovery data isn't available. * If autodiscovery links are missing and we don't recognize the - * host, we'll pass it to oohembed.com's public service which + * host, we'll pass it to noembed.com's public service which * will either proxy or fake info on a lot of sites. * * A few hosts are blacklisted due to known problems with oohembed, @@ -74,30 +81,60 @@ class oEmbedHelper $host = substr($host, 4); } - // Blacklist: systems with no oEmbed API of their own, which are - // either missing from or broken on oohembed.com's proxy. - // we know how to look data up in another way... - if (array_key_exists($host, self::$functionMap)) { - $func = self::$functionMap[$host]; - return call_user_func($func, $url, $params); - } + common_log(LOG_INFO, 'Checking for oEmbed data for ' . $url); - // Whitelist: known API endpoints for sites that don't provide discovery... - if (array_key_exists($host, self::$apiMap)) { - $api = self::$apiMap[$host]; - } else { - try { - $api = self::discover($url); - } catch (Exception $e) { - // Discovery failed... fall back to oohembed if enabled. - $oohembed = common_config('oohembed', 'endpoint'); - if ($oohembed) { - $api = $oohembed; - } else { - throw $e; + // You can fiddle with the order of discovery -- either skipping + // some types or re-ordering them. + + $order = common_config('oembed', 'order'); + + foreach ($order as $method) { + + switch ($method) { + case 'built-in': + common_log(LOG_INFO, 'Considering built-in oEmbed methods...'); + // Blacklist: systems with no oEmbed API of their own, which are + // either missing from or broken on noembed.com's proxy. + // we know how to look data up in another way... + if (array_key_exists($host, self::$functionMap)) { + common_log(LOG_INFO, 'We have a built-in method for ' . $host); + $func = self::$functionMap[$host]; + return call_user_func($func, $url, $params); } + break; + case 'well-known': + common_log(LOG_INFO, 'Considering well-known oEmbed endpoints...'); + // Whitelist: known API endpoints for sites that don't provide discovery... + if (array_key_exists($host, self::$apiMap)) { + $api = self::$apiMap[$host]; + common_log(LOG_INFO, 'Using well-known endpoint "' . $api . '" for "' . $host . '"'); + break 2; + } + break; + case 'discovery': + try { + common_log(LOG_INFO, 'Trying to discover an oEmbed endpoint using link headers.'); + $api = self::discover($url); + common_log(LOG_INFO, 'Found API endpoint ' . $api . ' for URL ' . $url); + break 2; + } catch (Exception $e) { + common_log(LOG_INFO, 'Could not find an oEmbed endpoint using link headers.'); + // Just ignore it! + } + break; + case 'service': + $api = common_config('oembed', 'endpoint'); + common_log(LOG_INFO, 'Using service API endpoint ' . $api); + break 2; + break; } } + + if (empty($api)) { + // TRANS: Server exception thrown in oEmbed action if no API endpoint is available. + throw new ServerException(_('No oEmbed API endpoint available.')); + } + return self::getObjectFrom($api, $url, $params); }