]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/twitterapi.php
Some UI adjustments for form notice
[quix0rs-gnu-social.git] / lib / twitterapi.php
index 638efba2415b56ac006247cffc37f942f9f0b59b..4a5de6ab3af99573badeac5441c88055db71580a 100644 (file)
@@ -274,11 +274,12 @@ class TwitterapiAction extends Action
         $enclosures = 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;
                  $enclosures[] = $enclosure;
             }
         }
@@ -501,7 +502,7 @@ class TwitterapiAction extends Action
             $enclosure = $entry['enclosures'][0];
             $this->element('enclosure', array('url'=>$enclosure['url'],'type'=>$enclosure['mimetype'],'length'=>$enclosure['size']), null);
         }
-        
+
         if(array_key_exists('tags', $entry)){
             foreach($entry['tags'] as $tag){
                 $this->element('category', null,$tag);
@@ -594,7 +595,6 @@ class TwitterapiAction extends Action
 
         $this->init_document('rss');
 
-        $this->elementStart('channel');
         $this->element('title', null, $title);
         $this->element('link', null, $link);
         if (!is_null($suplink)) {
@@ -620,7 +620,6 @@ class TwitterapiAction extends Action
             }
         }
 
-        $this->elementEnd('channel');
         $this->end_twitter_rss();
     }
 
@@ -667,7 +666,6 @@ class TwitterapiAction extends Action
 
         $this->init_document('rss');
 
-        $this->elementStart('channel');
         $this->element('title', null, $title);
         $this->element('link', null, $link);
         $this->element('description', null, $subtitle);
@@ -686,7 +684,6 @@ class TwitterapiAction extends Action
             }
         }
 
-        $this->elementEnd('channel');
         $this->end_twitter_rss();
     }
 
@@ -939,35 +936,16 @@ class TwitterapiAction extends Action
 
     function clientError($msg, $code = 400, $content_type = 'json')
     {
-
-        static $status = array(400 => 'Bad Request',
-                               401 => 'Unauthorized',
-                               402 => 'Payment Required',
-                               403 => 'Forbidden',
-                               404 => 'Not Found',
-                               405 => 'Method Not Allowed',
-                               406 => 'Not Acceptable',
-                               407 => 'Proxy Authentication Required',
-                               408 => 'Request Timeout',
-                               409 => 'Conflict',
-                               410 => 'Gone',
-                               411 => 'Length Required',
-                               412 => 'Precondition Failed',
-                               413 => 'Request Entity Too Large',
-                               414 => 'Request-URI Too Long',
-                               415 => 'Unsupported Media Type',
-                               416 => 'Requested Range Not Satisfiable',
-                               417 => 'Expectation Failed');
-
         $action = $this->trimmed('action');
 
         common_debug("User error '$code' on '$action': $msg", __FILE__);
 
-        if (!array_key_exists($code, $status)) {
+        if (!array_key_exists($code, ClientErrorAction::$status)) {
             $code = 400;
         }
 
-        $status_string = $status[$code];
+        $status_string = ClientErrorAction::$status[$code];
+
         header('HTTP/1.1 '.$code.' '.$status_string);
 
         if ($content_type == 'xml') {
@@ -986,14 +964,46 @@ class TwitterapiAction extends Action
 
     }
 
+    function serverError($msg, $code = 500, $content_type = 'json')
+    {
+        $action = $this->trimmed('action');
+
+        common_debug("Server error '$code' on '$action': $msg", __FILE__);
+
+        if (!array_key_exists($code, ServerErrorAction::$status)) {
+            $code = 400;
+        }
+
+        $status_string = ServerErrorAction::$status[$code];
+
+        header('HTTP/1.1 '.$code.' '.$status_string);
+
+        if ($content_type == 'xml') {
+            $this->init_document('xml');
+            $this->elementStart('hash');
+            $this->element('error', null, $msg);
+            $this->element('request', null, $_SERVER['REQUEST_URI']);
+            $this->elementEnd('hash');
+            $this->end_document('xml');
+        } else {
+            $this->init_document('json');
+            $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
+            print(json_encode($error_array));
+            $this->end_document('json');
+        }
+    }
+
     function init_twitter_rss()
     {
         $this->startXML();
-        $this->elementStart('rss', array('version' => '2.0'));
+        $this->elementStart('rss', array('version' => '2.0', 'xmlns:atom'=>'http://www.w3.org/2005/Atom'));
+        $this->elementStart('channel');
+        Event::handle('StartApiRss', array($this));
     }
 
     function end_twitter_rss()
     {
+        $this->elementEnd('channel');
         $this->elementEnd('rss');
         $this->endXML();
     }
@@ -1005,6 +1015,7 @@ class TwitterapiAction 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 end_twitter_atom()