Better fallback on UnsupportedMediaException
This commit is contained in:
parent
e526909bd8
commit
37ce1f4766
|
@ -127,11 +127,14 @@ class OembedAction extends Action
|
|||
}
|
||||
}
|
||||
$oembed['url']=$attachment->getUrl();
|
||||
$thumb = $attachment->getThumbnail();
|
||||
if ($thumb) {
|
||||
try {
|
||||
$thumb = $attachment->getThumbnail();
|
||||
$oembed['thumbnail_url'] = $thumb->getUrl();
|
||||
$oembed['thumbnail_width'] = $thumb->width;
|
||||
$oembed['thumbnail_height'] = $thumb->height;
|
||||
unset($thumb);
|
||||
} catch (UnsupportedMediaException $e) {
|
||||
// No thumbnail data available
|
||||
}
|
||||
}else{
|
||||
$oembed['type']='link';
|
||||
|
|
|
@ -444,9 +444,11 @@ class File extends Managed_DataObject
|
|||
*/
|
||||
public function getThumbnail($width=null, $height=null, $crop=false)
|
||||
{
|
||||
if ($this->width < 1 || $this->height < 1) {
|
||||
if (intval($this->width) < 1 || intval($this->height) < 1) {
|
||||
// Old files may have 0 until migrated with scripts/upgrade.php
|
||||
return null;
|
||||
// For any legitimately unrepresentable ones, we could generate our
|
||||
// own image (like a square with MIME type in text)
|
||||
throw new UnsupportedMediaException('Object does not have an image representation.');
|
||||
}
|
||||
|
||||
if ($width === null) {
|
||||
|
@ -476,13 +478,8 @@ class File extends Managed_DataObject
|
|||
'height' => $height);
|
||||
$thumb = File_thumbnail::pkeyGet($params);
|
||||
if ($thumb === null) {
|
||||
try {
|
||||
$thumb = $this->generateThumbnail($width, $height, $crop);
|
||||
} catch (UnsupportedMediaException $e) {
|
||||
// FIXME: Add "unknown media" icon or something
|
||||
} catch (ServerException $e) {
|
||||
// Probably a remote media file, maybe not available locally
|
||||
}
|
||||
// throws exception on failure to generate thumbnail
|
||||
$thumb = $this->generateThumbnail($width, $height, $crop);
|
||||
}
|
||||
return $thumb;
|
||||
}
|
||||
|
|
|
@ -573,10 +573,11 @@ class ActivityObject
|
|||
$object->date = $file->date;
|
||||
}
|
||||
|
||||
$thumbnail = $file->getThumbnail();
|
||||
|
||||
if (!empty($thumbnail)) {
|
||||
try {
|
||||
$thumbnail = $file->getThumbnail();
|
||||
$object->thumbnail = $thumbnail;
|
||||
} catch (UnsupportedMediaException $e) {
|
||||
$object->thumbnail = null;
|
||||
}
|
||||
|
||||
switch (ActivityObject::canonicalType($object->type)) {
|
||||
|
|
|
@ -204,7 +204,7 @@ class AttachmentListItem extends Widget
|
|||
try {
|
||||
$thumb = $this->attachment->getThumbnail();
|
||||
$this->out->element('img', array('alt' => '', 'src' => $thumb->getUrl(), 'width' => $thumb->width, 'height' => $thumb->height));
|
||||
} catch (Exception $e) {
|
||||
} catch (UnsupportedMediaException $e) {
|
||||
// Image representation unavailable
|
||||
}
|
||||
}
|
||||
|
@ -325,6 +325,7 @@ class Attachment extends AttachmentListItem
|
|||
try {
|
||||
$thumb = $this->attachment->getThumbnail();
|
||||
$poster = $thumb->getUrl();
|
||||
unset ($thumb);
|
||||
} catch (Exception $e) {
|
||||
$poster = null;
|
||||
}
|
||||
|
|
|
@ -62,16 +62,12 @@ class InlineAttachmentListItem extends AttachmentListItem
|
|||
|
||||
function show()
|
||||
{
|
||||
$this->thumb = $this->attachment->getThumbnail();
|
||||
if (!empty($this->thumb)) {
|
||||
try {
|
||||
$this->thumb = $this->attachment->getThumbnail();
|
||||
parent::show();
|
||||
} catch (UnsupportedMediaException $e) {
|
||||
$this->thumb = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getThumbInfo()
|
||||
{
|
||||
return $this->thumb;
|
||||
}
|
||||
|
||||
function showLink() {
|
||||
|
|
|
@ -492,9 +492,8 @@ class BookmarkPlugin extends MicroAppPlugin
|
|||
|
||||
// Attributes of the thumbnail, if any
|
||||
|
||||
$thumbnail = $target->getThumbnail();
|
||||
|
||||
if (!empty($thumbnail)) {
|
||||
try {
|
||||
$thumbnail = $target->getThumbnail();
|
||||
$tattrs = array('rel' => 'preview',
|
||||
'href' => $thumbnail->url);
|
||||
|
||||
|
@ -506,7 +505,9 @@ class BookmarkPlugin extends MicroAppPlugin
|
|||
$tattrs['media:height'] = $thumbnail->height;
|
||||
}
|
||||
|
||||
$object->extra[] = array('link', $attrs, null);
|
||||
$object->extra[] = array('link', $tattrs, null);
|
||||
} catch (UnsupportedMediaException $e) {
|
||||
// No image thumbnail metadata available
|
||||
}
|
||||
|
||||
return $object;
|
||||
|
|
Loading…
Reference in New Issue
Block a user