}
}
$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';
*/
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) {
'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;
}
$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)) {
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
}
}
try {
$thumb = $this->attachment->getThumbnail();
$poster = $thumb->getUrl();
+ unset ($thumb);
} catch (Exception $e) {
$poster = null;
}
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() {
// Attributes of the thumbnail, if any
- $thumbnail = $target->getThumbnail();
-
- if (!empty($thumbnail)) {
+ try {
+ $thumbnail = $target->getThumbnail();
$tattrs = array('rel' => 'preview',
'href' => $thumbnail->url);
$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;