Also, File->getEnclosure() now throws exception if not enough metadata.
Event::handle('FileEnclosureMetadata', array($this, &$enclosure));
}
}
+ if (empty($enclosure->mimetype)) {
+ // This means we don't know what it is, so it can't be an enclosure!
+ throw new ServerException('Unknown enclosure mimetype, not enough metadata');
+ }
return $enclosure;
}
- // quick back-compat hack, since there's still code using this
- function isEnclosure()
- {
- $enclosure = $this->getEnclosure();
- return !empty($enclosure);
- }
-
/**
* Get the attachment's thumbnail record, if any.
* Make sure you supply proper 'int' typed variables (or null).
$twitter_status['attachments'] = array();
foreach ($attachments as $attachment) {
- $enclosure_o=$attachment->getEnclosure();
- if ($enclosure_o) {
+ try {
+ $enclosure_o = $attachment->getEnclosure();
$enclosure = array();
$enclosure['url'] = $enclosure_o->url;
$enclosure['mimetype'] = $enclosure_o->mimetype;
$enclosure['size'] = $enclosure_o->size;
$twitter_status['attachments'][] = $enclosure;
+ } catch (ServerException $e) {
+ // There was not enough metadata available
}
}
}
$enclosures = array();
foreach ($attachments as $attachment) {
- $enclosure_o=$attachment->getEnclosure();
- if ($enclosure_o) {
+ try {
+ $enclosure_o = $attachment->getEnclosure();
$enclosure = array();
$enclosure['url'] = $enclosure_o->url;
$enclosure['mimetype'] = $enclosure_o->mimetype;
$enclosure['size'] = $enclosure_o->size;
$enclosures[] = $enclosure;
+ } catch (ServerException $e) {
+ // There was not enough metadata available
}
}
$attachments = $notice->attachments();
if($attachments){
foreach($attachments as $attachment){
- $enclosure=$attachment->getEnclosure();
- if ($enclosure) {
+ try {
+ $enclosure = $attachment->getEnclosure();
$attribs = array('rdf:resource' => $enclosure->url);
if ($enclosure->title) {
$attribs['dc:title'] = $enclosure->title;
$attribs['enc:type'] = $enclosure->mimetype;
}
$this->element('enc:enclosure', $attribs);
+ } catch (ServerException $e) {
+ // There was not enough metadata available
}
$this->element('sioc:links_to', array('rdf:resource'=>$attachment->url));
}
$f = File::getKV('url', $longurl);
- if (empty($f)) {
+ if (!$f instanceof File) {
if (common_config('attachments', 'process_links')) {
// XXX: this writes to the database. :<
$f = File::processNew($longurl);
}
}
- if (!empty($f)) {
- if ($f->getEnclosure()) {
+ if ($f instanceof File) {
+ try {
+ $enclosure = $f->getEnclosure();
$is_attachment = true;
$attachment_id = $f->id;
$thumb = File_thumbnail::getKV('file_id', $f->id);
- if (!empty($thumb)) {
- $has_thumb = true;
- }
+ $has_thumb = ($thumb instanceof File_thumbnail);
+ } catch (ServerException $e) {
+ // There was not enough metadata available
}
}
foreach($attachments as $attachment)
{
- if($enclosure = $attachment->getEnclosure()){
+ try {
+ $enclosure = $attachment->getEnclosure();
$fbmedia = $this->getFacebookMedia($enclosure);
- }else{
+ } catch (ServerException $e) {
$fbmedia = $this->getFacebookMedia($attachment);
}
if($fbmedia){