Only create attachment elements if attachment is an enclosure

This commit is contained in:
Zach Copley 2009-07-17 14:22:11 -07:00
parent 9c670ba695
commit 44f3f2bd2a

View File

@ -186,12 +186,9 @@ class TwitterapiAction extends Action
$twitter_status['favorited'] = false; $twitter_status['favorited'] = false;
} }
# Enclosures // Enclosures
$attachments = $notice->attachments(); $attachments = $notice->attachments();
$enclosures = array();
if (!empty($attachments)) {
$twitter_status['attachments'] = array();
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
if ($attachment->isEnclosure()) { if ($attachment->isEnclosure()) {
@ -199,9 +196,12 @@ class TwitterapiAction extends Action
$enclosure['url'] = $attachment->url; $enclosure['url'] = $attachment->url;
$enclosure['mimetype'] = $attachment->mimetype; $enclosure['mimetype'] = $attachment->mimetype;
$enclosure['size'] = $attachment->size; $enclosure['size'] = $attachment->size;
$twitter_status['attachments'][] = $enclosure; $enclosures[] = $enclosure;
} }
} }
if (!empty($enclosures)) {
$twitter_status['attachments'] = $enclosures;
} }
if ($include_user) { if ($include_user) {
@ -218,7 +218,7 @@ class TwitterapiAction extends Action
$profile = $notice->getProfile(); $profile = $notice->getProfile();
$entry = array(); $entry = array();
# We trim() to avoid extraneous whitespace in the output // We trim() to avoid extraneous whitespace in the output
$entry['content'] = common_xml_safe_str(trim($notice->rendered)); $entry['content'] = common_xml_safe_str(trim($notice->rendered));
$entry['title'] = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content)); $entry['title'] = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
@ -231,7 +231,26 @@ class TwitterapiAction extends Action
$entry['updated'] = $entry['published']; $entry['updated'] = $entry['published'];
$entry['author'] = $profile->getBestName(); $entry['author'] = $profile->getBestName();
# Enclosure // Enclosures
$attachments = $notice->attachments();
$enclosures = array();
foreach ($attachments as $attachment) {
if ($attachment->isEnclosure()) {
$enclosure = array();
$enclosure['url'] = $attachment->url;
$enclosure['mimetype'] = $attachment->mimetype;
$enclosure['size'] = $attachment->size;
$enclosures[] = $enclosure;
}
}
if (!empty($enclosures)) {
$entry['enclosures'] = $enclosures;
}
/*
// Enclosure
$attachments = $notice->attachments(); $attachments = $notice->attachments();
if($attachments){ if($attachments){
$entry['enclosures']=array(); $entry['enclosures']=array();
@ -245,8 +264,8 @@ class TwitterapiAction extends Action
} }
} }
} }
*/
# RSS Item specific // RSS Item specific
$entry['description'] = $entry['content']; $entry['description'] = $entry['content'];
$entry['pubDate'] = common_date_rfc2822($notice->created); $entry['pubDate'] = common_date_rfc2822($notice->created);
$entry['guid'] = $entry['link']; $entry['guid'] = $entry['link'];