]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Oembed/OembedPlugin.php
Oembed slimmed to only do discovery (soon we get og: discovery too)
[quix0rs-gnu-social.git] / plugins / Oembed / OembedPlugin.php
index b5646ab6fc9c4bece6ce17bfe24d5b0de5630fcc..c51e0bfad1626e983e0a5bf8f1581b37856628bf 100644 (file)
@@ -35,6 +35,24 @@ class OembedPlugin extends Plugin
         $m->connect('main/oembed', array('action' => 'oembed'));
     }
 
+    public function onGetRemoteUrlMetadataFromDom($url, DOMDocument $dom, stdClass &$metadata)
+    {
+        try {
+            common_log(LOG_INFO, 'Trying to discover an oEmbed endpoint using link headers.');
+            $api = oEmbedHelper::oEmbedEndpointFromHTML($dom);
+            common_log(LOG_INFO, 'Found API endpoint ' . $api . ' for URL ' . $url);
+            $params = array(
+                'maxwidth' => common_config('thumbnail', 'width'),
+                'maxheight' => common_config('thumbnail', 'height'),
+            );
+            $metadata = oEmbedHelper::getOembedFrom($api, $url, $params);
+
+        } catch (Exception $e) {
+            common_log(LOG_INFO, 'Could not find an oEmbed endpoint using link headers.');
+            // Just ignore it!
+        }
+    }
+
     public function onEndShowHeadElements(Action $action)
     {
         switch ($action->getActionName()) {
@@ -90,12 +108,10 @@ class OembedPlugin extends Plugin
      * Normally this event is called through File::saveNew()
      *
      * @param File   $file       The newly inserted File object.
-     * @param array  $redir_data lookup data eg from File_redirection::where()
-     * @param string $given_url
      *
      * @return boolean success
      */
-    public function onEndFileSaveNew(File $file, array $redir_data, $given_url)
+    public function onEndFileSaveNew(File $file)
     {
         $fo = File_oembed::getKV('file_id', $file->id);
         if ($fo instanceof File_oembed) {
@@ -103,15 +119,12 @@ class OembedPlugin extends Plugin
             return true;
         }
 
-        if (isset($redir_data['oembed']['json'])
-                && !empty($redir_data['oembed']['json'])) {
-            File_oembed::saveNew($redir_data['oembed']['json'], $file->id);
-        } elseif (isset($redir_data['type'])
-                && (('text/html' === substr($redir_data['type'], 0, 9)
-                || 'application/xhtml+xml' === substr($redir_data['type'], 0, 21)))) {
+        if (isset($file->mimetype)
+            && (('text/html' === substr($file->mimetype, 0, 9)
+            || 'application/xhtml+xml' === substr($file->mimetype, 0, 21)))) {
 
             try {
-                $oembed_data = File_oembed::_getOembed($given_url);
+                $oembed_data = File_oembed::_getOembed($file->url);
                 if ($oembed_data === false) {
                     throw new Exception('Did not get oEmbed data from URL');
                 }