[Embed] Removed old oEmbed and OpenGraph implementation

This commit is contained in:
Miguel Dantas
2019-07-12 03:13:40 +01:00
committed by Diogo Cordeiro
parent 0c20d35206
commit a244f3ba4d
3 changed files with 8 additions and 220 deletions

View File

@@ -93,7 +93,8 @@ class EmbedPlugin extends Plugin
* on this event to add our action handler for Embed.
*
* @param $m URLMapper the router that was initialized.
* @return bool true if successful, the exception object if it isn't.
* @return void true if successful, the exception object if it isn't.
* @throws Exception
*/
public function onRouterInitialized(URLMapper $m)
{
@@ -128,42 +129,6 @@ class EmbedPlugin extends Plugin
$metadata->thumbnail_width = $info->imageWidth;
} catch (Exception $e) {
common_log(LOG_INFO, "Failed to find Embed data for {$url} with 'oscarotero/Embed'");
try {
common_log(LOG_INFO, "Trying to discover an oEmbed endpoint for {$url} using link headers.");
$api = EmbedHelper::oEmbedEndpointFromHTML($dom);
common_log(LOG_INFO, 'Found oEmbed API endpoint ' . $api . ' for URL ' . $url);
$params = array(
'maxwidth' => common_config('thumbnail', 'width'),
'maxheight' => common_config('thumbnail', 'height'),
);
$metadata = EmbedHelper::getOembedFrom($api, $url, $params);
// Facebook just gives us javascript in its oembed html,
// so use the content of the title element instead
if (strpos($url, 'https://www.facebook.com/') === 0) {
$metadata->html = @$dom->getElementsByTagName('title')->item(0)->nodeValue;
}
// Wordpress sometimes also just gives us javascript, use og:description if it is available
$xpath = new DomXpath($dom);
$generatorNode = @$xpath->query('//meta[@name="generator"][1]')->item(0);
if ($generatorNode instanceof DomElement) {
// when wordpress only gives us javascript, the html stripped from tags
// is the same as the title, so this helps us to identify this (common) case
if (strpos($generatorNode->getAttribute('content'), 'WordPress') === 0
&& trim(strip_tags($metadata->html)) == trim($metadata->title)) {
$propertyNode = @$xpath->query('//meta[@property="og:description"][1]')->item(0);
if ($propertyNode instanceof DomElement) {
$metadata->html = $propertyNode->getAttribute('content');
}
}
}
} catch (Exception $e) {
// FIXME - make sure the error was because we couldn't get metadata, not something else! -mb
common_log(LOG_INFO, 'Could not find an oEmbed endpoint using link headers, ' .
'trying OpenGraph from HTML.');
// Just ignore it!
$metadata = OpenGraphHelper::ogFromHtml($dom);
}
}
if (isset($metadata->thumbnail_url)) {