]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/attachmentlist.php
Dynamically generate thumbnails (see full text)
[quix0rs-gnu-social.git] / lib / attachmentlist.php
index 1b323cd2a148b62fb895d36a5d25cd4951f371ca..073581593381fb3ea3405286d663b71670ae8705 100644 (file)
@@ -201,34 +201,14 @@ class AttachmentListItem extends Widget
     }
 
     function showRepresentation() {
-        $thumb = $this->getThumbInfo();
-        if ($thumb instanceof File_thumbnail) {
+        try {
+            $thumb = $this->attachment->getThumbnail();
             $this->out->element('img', array('alt' => '', 'src' => $thumb->getUrl(), 'width' => $thumb->width, 'height' => $thumb->height));
+        } catch (Exception $e) {
+            // Image representation unavailable
         }
     }
 
-    /**
-     * Pull a thumbnail image reference for the given file, and if necessary
-     * resize it to match currently thumbnail size settings.
-     *
-     * @return File_Thumbnail or false/null
-     */
-    function getThumbInfo()
-    {
-        $thumbnail = File_thumbnail::getKV('file_id', $this->attachment->id);
-        if ($thumbnail) {
-            $maxWidth = common_config('attachments', 'thumb_width');
-            $maxHeight = common_config('attachments', 'thumb_height');
-            if ($thumbnail->width > $maxWidth) {
-                $thumb = clone($thumbnail);
-                $thumb->width = $maxWidth;
-                $thumb->height = intval($thumbnail->height * $maxWidth / $thumbnail->width);
-                return $thumb;
-            }
-        }
-        return $thumbnail;
-    }
-
     /**
      * start a single notice.
      *
@@ -342,10 +322,12 @@ class Attachment extends AttachmentListItem
                 case 'video/quicktime':
                 case 'video/webm':
                     $mediatype = common_get_mime_media($this->attachment->mimetype);
-                    $thumb = $this->getThumbInfo();
-                    $poster = ($thumb instanceof File_thumbnail)
-                                ? $thumb->getUrl()
-                                : null;
+                    try {
+                        $thumb = $this->attachment->getThumbnail();
+                        $poster = $thumb->getUrl();
+                    } catch (Exception $e) {
+                        $poster = null;
+                    }
                     $this->out->elementStart($mediatype,
                                         array('class'=>'attachment_player',
                                             'poster'=>$poster,