]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/apiaction.php
isSubscribed and hasBlocked need instance of Profile, not User
[quix0rs-gnu-social.git] / lib / apiaction.php
old mode 100644 (file)
new mode 100755 (executable)
index 9f26b3b..4b4c94a
@@ -127,6 +127,7 @@ class ApiAction extends Action
     var $since_id  = null;
     var $source    = null;
     var $callback  = null;
+    var $format    = null;
 
     var $access    = self::READ_ONLY;  // read (default) or read-write
 
@@ -243,8 +244,6 @@ class ApiAction extends Action
 
         $twitter_user['created_at'] = $this->dateTwitter($profile->created);
 
-        $twitter_user['favourites_count'] = $profile->faveCount(); // British spelling!
-
         $timezone = 'UTC';
 
         if (!empty($user) && $user->timezone) {
@@ -290,6 +289,9 @@ class ApiAction extends Action
 
         $twitter_user['statusnet_profile_url'] = $profile->profileurl;
 
+        // The event call to handle NoticeSimpleStatusArray lets plugins add data to the output array
+        Event::handle('TwitterUserArray', array($profile, &$twitter_user, $this->scoped, array()));
+
         return $twitter_user;
     }
 
@@ -299,9 +301,9 @@ class ApiAction extends Action
 
         if (!empty($notice->repeat_of)) {
             $original = Notice::getKV('id', $notice->repeat_of);
-            if (!empty($original)) {
-                $original_array = $this->twitterSimpleStatusArray($original, $include_user);
-                $base['retweeted_status'] = $original_array;
+            if ($original instanceof Notice) {
+                $orig_array = $this->twitterSimpleStatusArray($original, $include_user);
+                $base['retweeted_status'] = $orig_array;
             }
         }
 
@@ -369,10 +371,8 @@ class ApiAction extends Action
         }
 
         if (!is_null($this->scoped)) {
-            $twitter_status['favorited'] = $this->scoped->hasFave($notice);
             $twitter_status['repeated']  = $this->scoped->hasRepeated($notice);
         } else {
-            $twitter_status['favorited'] = false;
             $twitter_status['repeated'] = false;
         }
 
@@ -384,13 +384,15 @@ class ApiAction extends Action
             $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
                 }
             }
         }
@@ -406,6 +408,10 @@ class ApiAction extends Action
         $twitter_status['statusnet_html'] = $notice->rendered;
         $twitter_status['statusnet_conversation_id'] = intval($notice->conversation);
 
+        // The event call to handle NoticeSimpleStatusArray lets plugins add data to the output array
+        Event::handle('NoticeSimpleStatusArray', array($notice, &$twitter_status, $this->scoped,
+                                                       array('include_user'=>$include_user)));
+
         return $twitter_status;
     }
 
@@ -510,13 +516,15 @@ class ApiAction extends Action
             $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
                 }
             }
 
@@ -572,13 +580,16 @@ class ApiAction extends Action
     {
         $details = array();
 
+               $source_profile = $source->getProfile();
+               $target_profile = $target->getProfile();                
+
         $details['screen_name'] = $source->nickname;
-        $details['followed_by'] = $target->isSubscribed($source);
-        $details['following'] = $source->isSubscribed($target);
+        $details['followed_by'] = $target->isSubscribed($source_profile);
+        $details['following'] = $source->isSubscribed($target_profile);
 
         $notifications = false;
 
-        if ($source->isSubscribed($target)) {
+        if ($source->isSubscribed($target_profile)) {
             $sub = Subscription::pkeyGet(array('subscriber' =>
                 $source->id, 'subscribed' => $target->id));
 
@@ -588,7 +599,7 @@ class ApiAction extends Action
         }
 
         $details['notifications_enabled'] = $notifications;
-        $details['blocking'] = $source->hasBlocked($target);
+        $details['blocking'] = $source->hasBlocked($target_profile);
         $details['id'] = intval($source->id);
 
         return $details;