From 9ec022df93a41c33c15ed0b2b3592f3faff40414 Mon Sep 17 00:00:00 2001
From: Zach Copley <zach@controlyourself.ca>
Date: Fri, 17 Jul 2009 12:39:54 -0700
Subject: [PATCH] Only populate attachments array element if there are
 attachments

---
 lib/twitterapi.php | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/lib/twitterapi.php b/lib/twitterapi.php
index 66664334c8..ab6c0d62c8 100644
--- a/lib/twitterapi.php
+++ b/lib/twitterapi.php
@@ -188,15 +188,18 @@ class TwitterapiAction extends Action
 
         # Enclosures
         $attachments = $notice->attachments();
-        $twitter_status['attachments']=array();
-        if($attachments){
-            foreach($attachments as $attachment){
+
+        if (!empty($attachments)) {
+
+            $twitter_status['attachments'] = array();
+
+            foreach ($attachments as $attachment) {
                 if ($attachment->isEnclosure()) {
-                    $enclosure=array();
-                    $enclosure['url']=$attachment->url;
-                    $enclosure['mimetype']=$attachment->mimetype;
-                    $enclosure['size']=$attachment->size;
-                    $twitter_status['attachments'][]=$enclosure;
+                    $enclosure = array();
+                    $enclosure['url'] = $attachment->url;
+                    $enclosure['mimetype'] = $attachment->mimetype;
+                    $enclosure['size'] = $attachment->size;
+                    $twitter_status['attachments'][] = $enclosure;
                 }
             }
         }
-- 
2.39.5