]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/File_oembed.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / classes / File_oembed.php
index e41ccfd097eb4d415d02d587f2fc08d6d7e57ecc..b7bf3a5dae51d5db18ba259fd6f0a812c60e6faa 100644 (file)
@@ -58,29 +58,25 @@ class File_oembed extends Memcached_DataObject
         return array(false, false, false);
     }
 
-    function _getOembed($url, $maxwidth = 500, $maxheight = 400) {
-        require_once INSTALLDIR.'/extlib/Services/oEmbed.php';
+    function _getOembed($url) {
         $parameters = array(
-            'maxwidth'=>$maxwidth,
-            'maxheight'=>$maxheight,
+            'maxwidth' => common_config('attachments', 'thumb_width'),
+            'maxheight' => common_config('attachments', 'thumb_height'),
         );
-        try{
-            $oEmbed = new Services_oEmbed($url);
-            $object = $oEmbed->getObject($parameters);
-            return $object;
-        }catch(Exception $e){
-            try{
-                $oEmbed = new Services_oEmbed($url, array(
-                    Services_oEmbed::OPTION_API => common_config('oohembed', 'endpoint')
-                ));
-                $object = $oEmbed->getObject($parameters);
-                return $object;
-            }catch(Exception $ex){
-                return false;
-            }
+        try {
+            return oEmbedHelper::getObject($url, $parameters);
+        } catch (Exception $e) {
+            common_log(LOG_ERR, "Error during oembed lookup for $url - " . $e->getMessage());
+            return false;
         }
     }
 
+    /**
+     * Save embedding info for a new file.
+     *
+     * @param object $data Services_oEmbed_Object_*
+     * @param int $file_id
+     */
     function saveNew($data, $file_id) {
         $file_oembed = new File_oembed;
         $file_oembed->file_id = $file_id;
@@ -114,9 +110,14 @@ class File_oembed extends Memcached_DataObject
             }
         }
         $file_oembed->insert();
-        if (!empty($data->thumbnail_url)) {
-            File_thumbnail::saveNew($data, $file_id);
+        if (!empty($data->thumbnail_url) || ($data->type == 'photo')) {
+            $ft = File_thumbnail::staticGet('file_id', $file_id);
+            if (!empty($ft)) {
+                common_log(LOG_WARNING, "Strangely, a File_thumbnail object exists for new file $file_id",
+                           __FILE__);
+            } else {
+                File_thumbnail::saveNew($data, $file_id);
+            }
         }
     }
 }
-