File::processNew can return -1 which was not true for empty()
Also, File->getEnclosure() now throws exception if not enough metadata.
This commit is contained in:
parent
d596513e39
commit
d6f52f5939
|
@ -364,16 +364,13 @@ class File extends Managed_DataObject
|
||||||
Event::handle('FileEnclosureMetadata', array($this, &$enclosure));
|
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;
|
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.
|
* Get the attachment's thumbnail record, if any.
|
||||||
* Make sure you supply proper 'int' typed variables (or null).
|
* Make sure you supply proper 'int' typed variables (or null).
|
||||||
|
|
|
@ -384,13 +384,15 @@ class ApiAction extends Action
|
||||||
$twitter_status['attachments'] = array();
|
$twitter_status['attachments'] = array();
|
||||||
|
|
||||||
foreach ($attachments as $attachment) {
|
foreach ($attachments as $attachment) {
|
||||||
$enclosure_o=$attachment->getEnclosure();
|
try {
|
||||||
if ($enclosure_o) {
|
$enclosure_o = $attachment->getEnclosure();
|
||||||
$enclosure = array();
|
$enclosure = array();
|
||||||
$enclosure['url'] = $enclosure_o->url;
|
$enclosure['url'] = $enclosure_o->url;
|
||||||
$enclosure['mimetype'] = $enclosure_o->mimetype;
|
$enclosure['mimetype'] = $enclosure_o->mimetype;
|
||||||
$enclosure['size'] = $enclosure_o->size;
|
$enclosure['size'] = $enclosure_o->size;
|
||||||
$twitter_status['attachments'][] = $enclosure;
|
$twitter_status['attachments'][] = $enclosure;
|
||||||
|
} catch (ServerException $e) {
|
||||||
|
// There was not enough metadata available
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -510,13 +512,15 @@ class ApiAction extends Action
|
||||||
$enclosures = array();
|
$enclosures = array();
|
||||||
|
|
||||||
foreach ($attachments as $attachment) {
|
foreach ($attachments as $attachment) {
|
||||||
$enclosure_o=$attachment->getEnclosure();
|
try {
|
||||||
if ($enclosure_o) {
|
$enclosure_o = $attachment->getEnclosure();
|
||||||
$enclosure = array();
|
$enclosure = array();
|
||||||
$enclosure['url'] = $enclosure_o->url;
|
$enclosure['url'] = $enclosure_o->url;
|
||||||
$enclosure['mimetype'] = $enclosure_o->mimetype;
|
$enclosure['mimetype'] = $enclosure_o->mimetype;
|
||||||
$enclosure['size'] = $enclosure_o->size;
|
$enclosure['size'] = $enclosure_o->size;
|
||||||
$enclosures[] = $enclosure;
|
$enclosures[] = $enclosure;
|
||||||
|
} catch (ServerException $e) {
|
||||||
|
// There was not enough metadata available
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -278,8 +278,8 @@ class Rss10Action extends Action
|
||||||
$attachments = $notice->attachments();
|
$attachments = $notice->attachments();
|
||||||
if($attachments){
|
if($attachments){
|
||||||
foreach($attachments as $attachment){
|
foreach($attachments as $attachment){
|
||||||
$enclosure=$attachment->getEnclosure();
|
try {
|
||||||
if ($enclosure) {
|
$enclosure = $attachment->getEnclosure();
|
||||||
$attribs = array('rdf:resource' => $enclosure->url);
|
$attribs = array('rdf:resource' => $enclosure->url);
|
||||||
if ($enclosure->title) {
|
if ($enclosure->title) {
|
||||||
$attribs['dc:title'] = $enclosure->title;
|
$attribs['dc:title'] = $enclosure->title;
|
||||||
|
@ -294,6 +294,8 @@ class Rss10Action extends Action
|
||||||
$attribs['enc:type'] = $enclosure->mimetype;
|
$attribs['enc:type'] = $enclosure->mimetype;
|
||||||
}
|
}
|
||||||
$this->element('enc:enclosure', $attribs);
|
$this->element('enc:enclosure', $attribs);
|
||||||
|
} catch (ServerException $e) {
|
||||||
|
// There was not enough metadata available
|
||||||
}
|
}
|
||||||
$this->element('sioc:links_to', array('rdf:resource'=>$attachment->url));
|
$this->element('sioc:links_to', array('rdf:resource'=>$attachment->url));
|
||||||
}
|
}
|
||||||
|
|
13
lib/util.php
13
lib/util.php
|
@ -989,22 +989,23 @@ function common_linkify($url) {
|
||||||
|
|
||||||
$f = File::getKV('url', $longurl);
|
$f = File::getKV('url', $longurl);
|
||||||
|
|
||||||
if (empty($f)) {
|
if (!$f instanceof File) {
|
||||||
if (common_config('attachments', 'process_links')) {
|
if (common_config('attachments', 'process_links')) {
|
||||||
// XXX: this writes to the database. :<
|
// XXX: this writes to the database. :<
|
||||||
$f = File::processNew($longurl);
|
$f = File::processNew($longurl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($f)) {
|
if ($f instanceof File) {
|
||||||
if ($f->getEnclosure()) {
|
try {
|
||||||
|
$enclosure = $f->getEnclosure();
|
||||||
$is_attachment = true;
|
$is_attachment = true;
|
||||||
$attachment_id = $f->id;
|
$attachment_id = $f->id;
|
||||||
|
|
||||||
$thumb = File_thumbnail::getKV('file_id', $f->id);
|
$thumb = File_thumbnail::getKV('file_id', $f->id);
|
||||||
if (!empty($thumb)) {
|
$has_thumb = ($thumb instanceof File_thumbnail);
|
||||||
$has_thumb = true;
|
} catch (ServerException $e) {
|
||||||
}
|
// There was not enough metadata available
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -651,9 +651,10 @@ class Facebookclient
|
||||||
|
|
||||||
foreach($attachments as $attachment)
|
foreach($attachments as $attachment)
|
||||||
{
|
{
|
||||||
if($enclosure = $attachment->getEnclosure()){
|
try {
|
||||||
|
$enclosure = $attachment->getEnclosure();
|
||||||
$fbmedia = $this->getFacebookMedia($enclosure);
|
$fbmedia = $this->getFacebookMedia($enclosure);
|
||||||
}else{
|
} catch (ServerException $e) {
|
||||||
$fbmedia = $this->getFacebookMedia($attachment);
|
$fbmedia = $this->getFacebookMedia($attachment);
|
||||||
}
|
}
|
||||||
if($fbmedia){
|
if($fbmedia){
|
||||||
|
|
Loading…
Reference in New Issue
Block a user