]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/api.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / lib / api.php
index b7ab407a1a58734f46b8adaf627cdc369452702c..7d94eaee4eda1de4a8e7750106afc19e3afe262e 100644 (file)
@@ -53,13 +53,19 @@ if (!defined('STATUSNET')) {
 
 class ApiAction extends Action
 {
-     var $format   = null;
-     var $user     = null;
-     var $page     = null;
-     var $count    = null;
-     var $max_id   = null;
-     var $since_id = null;
-     var $since    = null;
+    const READ_ONLY  = 1;
+    const READ_WRITE = 2;
+
+    var $format    = null;
+    var $user      = null;
+    var $auth_user = null;
+    var $page      = null;
+    var $count     = null;
+    var $max_id    = null;
+    var $since_id  = null;
+    var $since     = null;
+
+    var $access    = self::READ_ONLY;  // read (default) or read-write
 
     /**
      * Initialization.
@@ -139,12 +145,14 @@ class ApiAction extends Action
 
         // Note: some profiles don't have an associated user
 
+        $defaultDesign = Design::siteDesign();
+
         if (!empty($user)) {
             $design = $user->getDesign();
         }
 
         if (empty($design)) {
-            $design = Design::siteDesign();
+            $design = $defaultDesign;
         }
 
         $color = Design::toWebColor(empty($design->backgroundcolor) ? $defaultDesign->backgroundcolor : $design->backgroundcolor);
@@ -165,7 +173,7 @@ class ApiAction extends Action
 
         $timezone = 'UTC';
 
-        if ($user->timezone) {
+        if (!empty($user) && $user->timezone) {
             $timezone = $user->timezone;
         }
 
@@ -190,13 +198,14 @@ class ApiAction extends Action
         $twitter_user['following'] = false;
         $twitter_user['notifications'] = false;
 
-        if (isset($apidata['user'])) {
+        if (isset($this->auth_user)) {
 
-            $twitter_user['following'] = $apidata['user']->isSubscribed($profile);
+            $twitter_user['following'] = $this->auth_user->isSubscribed($profile);
 
             // Notifications on?
             $sub = Subscription::pkeyGet(array('subscriber' =>
-                $apidata['user']->id, 'subscribed' => $profile->id));
+                                               $this->auth_user->id,
+                                               'subscribed' => $profile->id));
 
             if ($sub) {
                 $twitter_user['notifications'] = ($sub->jabber || $sub->sms);
@@ -218,14 +227,15 @@ class ApiAction extends Action
     {
         $base = $this->twitterSimpleStatusArray($notice, $include_user);
 
-        if (empty($notice->repeat_of)) {
-            return $base;
-        } else {
+        if (!empty($notice->repeat_of)) {
             $original = Notice::staticGet('id', $notice->repeat_of);
-            $original_array = $this->twitterSimpleStatusArray($original, $include_user);
-            $original_array['retweeted_status'] = $base;
-            return $original_array;
+            if (!empty($original)) {
+                $original_array = $this->twitterSimpleStatusArray($original, $include_user);
+                $base['retweeted_status'] = $original_array;
+            }
         }
+
+        return $base;
     }
 
     function twitterSimpleStatusArray($notice, $include_user=true)
@@ -278,17 +288,18 @@ class ApiAction extends Action
             $twitter_status['attachments'] = array();
 
             foreach ($attachments as $attachment) {
-                if ($attachment->isEnclosure()) {
+                $enclosure_o=$attachment->getEnclosure();
+                if ($enclosure_o) {
                     $enclosure = array();
-                    $enclosure['url'] = $attachment->url;
-                    $enclosure['mimetype'] = $attachment->mimetype;
-                    $enclosure['size'] = $attachment->size;
+                    $enclosure['url'] = $enclosure_o->url;
+                    $enclosure['mimetype'] = $enclosure_o->mimetype;
+                    $enclosure['size'] = $enclosure_o->size;
                     $twitter_status['attachments'][] = $enclosure;
                 }
             }
         }
 
-        if ($include_user) {
+        if ($include_user && $profile) {
             # Don't get notice (recursive!)
             $twitter_user = $this->twitterUserArray($profile, false);
             $twitter_status['user'] = $twitter_user;
@@ -784,7 +795,7 @@ class ApiAction extends Action
 
         $from = $message->getFrom();
 
-        $entry['title'] = sprintf('Message from %s to %s',
+        $entry['title'] = sprintf('Message from %1$s to %2$s',
             $from->nickname, $message->getTo()->nickname);
 
         $entry['content'] = common_xml_safe_str($message->rendered);
@@ -1239,10 +1250,27 @@ class ApiAction extends Action
         case 'api':
             break;
         default:
+
+            $name = null;
+            $url  = null;
+
             $ns = Notice_source::staticGet($source);
+
             if ($ns) {
-                $source_name = '<a href="' . $ns->url . '">' . $ns->name . '</a>';
+                $name = $ns->name;
+                $url  = $ns->url;
+            } else {
+                $app = Oauth_application::staticGet('name', $source);
+                if ($app) {
+                    $name = $app->name;
+                    $url  = $app->source_url;
+                }
             }
+
+            if (!empty($name) && !empty($url)) {
+                $source_name = '<a href="' . $url . '">' . $name . '</a>';
+            }
+
             break;
         }
         return $source_name;