]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/twitterapi.php
Updated Cloudy theme default avatars and minor CSS
[quix0rs-gnu-social.git] / lib / twitterapi.php
index e7239acd5e4e1d6c84a790ec2d30fac5d5ab6c18..caf8c071639212a4ec8c7eb19dc37509fddd197e 100644 (file)
@@ -51,6 +51,26 @@ class TwitterapiAction extends Action
         parent::handle($args);
     }
 
+    /**
+     * Overrides XMLOutputter::element to write booleans as strings (true|false).
+     * See that method's documentation for more info.
+     * 
+     * @param string $tag     Element type or tagname
+     * @param array  $attrs   Array of element attributes, as
+     *                        key-value pairs
+     * @param string $content string content of the element
+     *
+     * @return void
+     */
+    function element($tag, $attrs=null, $content=null)
+    {
+        if (is_bool($content)) {
+            $content = ($content ? 'true' : 'false');
+        }
+
+        return parent::element($tag, $attrs, $content);
+    }
+    
     function twitter_user_array($profile, $get_notice=false)
     {
 
@@ -66,7 +86,7 @@ class TwitterapiAction extends Action
         $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
 
         $twitter_user['profile_image_url'] = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE);
-        $twitter_user['protected'] = 'false'; # not supported by Laconica yet
+        $twitter_user['protected'] = false; # not supported by Laconica yet
         $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : null;
 
         if ($get_notice) {
@@ -86,7 +106,7 @@ class TwitterapiAction extends Action
 
         $twitter_status = array();
         $twitter_status['text'] = $notice->content;
-        $twitter_status['truncated'] = 'false'; # Not possible on Laconica
+        $twitter_status['truncated'] = false; # Not possible on Laconica
         $twitter_status['created_at'] = $this->date_twitter($notice->created);
         $twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ?
             intval($notice->reply_to) : null;
@@ -108,10 +128,9 @@ class TwitterapiAction extends Action
             ($replier_profile) ? $replier_profile->nickname : null;
 
         if (isset($this->auth_user)) {
-            $twitter_status['favorited'] =
-                ($this->auth_user->hasFave($notice)) ? 'true' : 'false';
+            $twitter_status['favorited'] = $this->auth_user->hasFave($notice);
         } else {
-            $twitter_status['favorited'] = 'false';
+            $twitter_status['favorited'] = false;
         }
 
         if ($include_user) {
@@ -238,21 +257,6 @@ class TwitterapiAction extends Action
         $this->elementEnd('item');
     }
 
-    function show_twitter_atom_entry($entry)
-    {
-        $this->elementStart('entry');
-        $this->element('title', null, $entry['title']);
-        $this->element('content', array('type' => 'html'), $entry['content']);
-        $this->element('id', null, $entry['id']);
-        $this->element('published', null, $entry['published']);
-        $this->element('updated', null, $entry['updated']);
-        $this->element('link', array('href' => $entry['link'], 'rel' => 'alternate', 'type' => 'text/html'), null);
-        $this->elementStart('author');
-        $this->element('name', null, $entry['author']);
-        $this->elementEnd('author');
-        $this->elementEnd('entry');
-    }
-
     function show_json_objects($objects)
     {
         print(json_encode($objects));
@@ -383,7 +387,7 @@ class TwitterapiAction extends Action
         }
 
         if (!is_null($selfuri)) {
-            $this->element('link', array('href' => $selfuri, 
+            $this->element('link', array('href' => $selfuri,
                 'rel' => 'self', 'type' => 'application/atom+xml'), null);
         }
 
@@ -392,13 +396,11 @@ class TwitterapiAction extends Action
 
         if (is_array($notice)) {
             foreach ($notice as $n) {
-                $entry = $this->twitter_rss_entry_array($n);
-                $this->show_twitter_atom_entry($entry);
+                $this->raw($n->asAtomEntry());
             }
         } else {
             while ($notice->fetch()) {
-                $entry = $this->twitter_rss_entry_array($notice);
-                $this->show_twitter_atom_entry($entry);
+                $this->raw($notice->asAtomEntry());
             }
         }
 
@@ -435,7 +437,7 @@ class TwitterapiAction extends Action
     function date_twitter($dt)
     {
         $t = strtotime($dt);
-        return date("D M d G:i:s O Y", $t);
+        return date("D M d H:i:s O Y", $t);
     }
 
     // XXX: Candidate for a general utility method somewhere?
@@ -578,13 +580,16 @@ class TwitterapiAction extends Action
     function init_twitter_atom()
     {
         $this->startXML();
-        $this->elementStart('feed', array('xmlns' => 'http://www.w3.org/2005/Atom', 'xml:lang' => 'en-US'));
+        // FIXME: don't hardcode the language here!
+        $this->elementStart('feed', array('xmlns' => 'http://www.w3.org/2005/Atom',
+                                          'xml:lang' => 'en-US',
+                                          'xmlns:thr' => 'http://purl.org/syndication/thread/1.0'));
     }
 
     function end_twitter_atom()
     {
-        $this->endXML();
         $this->elementEnd('feed');
+        $this->endXML();
     }
 
     function show_profile($profile, $content_type='xml', $notice=null)