]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/api.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
[quix0rs-gnu-social.git] / lib / api.php
index 4ed49e45293197f790d167f9a8da24e882ce4b98..0bcf4cc21afbdc870aee26b5e307b62ccc66db8a 100644 (file)
@@ -53,6 +53,9 @@ if (!defined('STATUSNET')) {
 
 class ApiAction extends Action
 {
+    const READ_ONLY  = 1;
+    const READ_WRITE = 2;
+
     var $format    = null;
     var $user      = null;
     var $auth_user = null;
@@ -62,6 +65,8 @@ class ApiAction extends Action
     var $since_id  = null;
     var $since     = null;
 
+    var $access    = self::READ_ONLY;  // read (default) or read-write
+
     /**
      * Initialization.
      *
@@ -72,6 +77,7 @@ class ApiAction extends Action
 
     function prepare($args)
     {
+        StatusNet::setApi(true); // reduce exception reports to aid in debugging
         parent::prepare($args);
 
         $this->format   = $this->arg('format');
@@ -140,12 +146,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);
@@ -166,7 +174,7 @@ class ApiAction extends Action
 
         $timezone = 'UTC';
 
-        if ($user->timezone) {
+        if (!empty($user) && $user->timezone) {
             $timezone = $user->timezone;
         }
 
@@ -291,7 +299,7 @@ class ApiAction extends Action
             }
         }
 
-        if ($include_user) {
+        if ($include_user && $profile) {
             # Don't get notice (recursive!)
             $twitter_user = $this->twitterUserArray($profile, false);
             $twitter_status['user'] = $twitter_user;
@@ -350,7 +358,7 @@ class ApiAction extends Action
         $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));
         $entry['published'] = common_date_iso8601($notice->created);
 
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $entry['id'] = "tag:$taguribase:$entry[link]";
 
         $entry['updated'] = $entry['published'];
@@ -787,14 +795,14 @@ 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);
         $entry['link'] = common_local_url('showmessage', array('message' => $message->id));
         $entry['published'] = common_date_iso8601($message->created);
 
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
 
         $entry['id'] = "tag:$taguribase:$entry[link]";
         $entry['updated'] = $entry['published'];
@@ -1095,7 +1103,7 @@ class ApiAction extends Action
         }
     }
 
-    function serverError($msg, $code = 500, $content_type = 'json')
+    function serverError($msg, $code = 500, $content_type = 'xml')
     {
         $action = $this->trimmed('action');
 
@@ -1146,7 +1154,6 @@ class ApiAction extends Action
         $this->elementStart('feed', array('xmlns' => 'http://www.w3.org/2005/Atom',
                                           'xml:lang' => 'en-US',
                                           'xmlns:thr' => 'http://purl.org/syndication/thread/1.0'));
-        Event::handle('StartApiAtom', array($this));
     }
 
     function endTwitterAtom()
@@ -1242,10 +1249,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;
@@ -1296,4 +1320,22 @@ class ApiAction extends Action
         }
     }
 
+    function getSelfUri($action, $aargs)
+    {
+        parse_str($_SERVER['QUERY_STRING'], $params);
+        $pstring = '';
+        if (!empty($params)) {
+            unset($params['p']);
+            $pstring = http_build_query($params);
+        }
+
+        $uri = common_local_url($action, $aargs);
+
+        if (!empty($pstring)) {
+            $uri .= '?' . $pstring;
+        }
+
+        return $uri;
+    }
+
 }