]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Twitter-compatible API: public_timeline.rss really works now
authorzach <zach@copley.name>
Wed, 16 Jul 2008 19:18:47 +0000 (15:18 -0400)
committerzach <zach@copley.name>
Wed, 16 Jul 2008 19:18:47 +0000 (15:18 -0400)
darcs-hash:20080716191847-ca946-9a75dd3aa07974408b269b31d1de3e49c5ae2a72.gz

actions/twitapistatuses.php
lib/twitterapi.php

index d1f9579425bcd77fa9dea84e0864552409e44a9e..3a495a1296d8d1e808438b92f7fcb9a41e659f4f 100644 (file)
@@ -70,25 +70,26 @@ class TwitapistatusesAction extends TwitterapiAction {
                
                        common_end_xml();
                } elseif ($apidata['content-type'] == 'rss') {
-
-                       //header('Content-Type: application/xml; charset=utf-8');               
                        
                        header("Content-Type: application/rss+xml; charset=utf-8");
 
                        $this->init_twitter_rss();
                        
+                       $sitename = common_config('site', 'name');
+                       $siteserver = common_config('site', 'server'); 
+                       
                        common_element_start('channel');
-                       common_element('title', NULL, 'Identi.ca public timeline');
-                       common_element('link', NULL, 'http://www.identi.ca');
-                       common_element('description', NULL, 'Identi.ca updates from everyone!');
+                       common_element('title', NULL, "$sitename public timeline");
+                       common_element('link', NULL, "http://$siteserver");
+                       common_element('description', NULL, "$sitename updates from everyone!");
                        common_element('language', NULL, 'en-us');
-                       common_element('ttl', NULL, '40'); // 40 what?
+                       common_element('ttl', NULL, '40');
                        
                        if ($cnt > 0) {
                                for ($i = 0; $i < 20; $i++) {
                                        if ($notice->fetch()) {
-                                               $twitter_status = $this->twitter_status_array($notice);                                         
-                                               $this->show_twitter_rss_item($twitter_status);
+                                               $entry = $this->twitter_rss_entry_array($notice);                                               
+                                               $this->show_twitter_rss_item($entry);
                                        } else {
                                                // shouldn't happen!
                                                break;
index 012057861f96b5ed9a3be54927e5b737ecbd6ddc..b11c04876bce9f6972e649202b660f245b9f9311 100644 (file)
@@ -64,6 +64,29 @@ class TwitterapiAction extends Action {
                                
                return $twitter_status;
        }
+               
+       function twitter_rss_entry_array($notice) {
+               
+               $profile = $notice->getProfile();
+               
+               $server = common_config('site', 'server');
+               
+               $entry = array();
+       
+               $entry['content'] = $profile->nickname . ': ' . $notice->content; 
+               $entry['title'] = $entry['content'];
+               $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));;
+               $entry['published'] = $this->date_iso8601($notice->created);
+               $entry['id'] = "tag:http://$server,$entry[published]:$entry[link]";
+               $entry['updated'] = $entry['published'];
+
+               # RSS Item specific
+               $entry['description'] = $entry['content'];
+               $entry['pubDate'] = $this->date_rfc2822($notice->created);
+               $entry['guid'] = $entry['link'];
+
+               return $entry;
+       }
        
        function render_twitter_xml_status($twitter_status) {   
                common_element_start('status');
@@ -94,18 +117,37 @@ class TwitterapiAction extends Action {
                common_element('followers_count', NULL, $twitter_user['followers_count']);
                common_element_end('user');
        }
-       
+
+       function show_twitter_rss_item($entry) {
+               common_element_start('item');
+               common_element('title', NULL, $entry['title']);
+               common_element('description', NULL, $entry['description']);
+               common_element('pubDate', NULL, $entry['pubDate']);
+               common_element('guid', NULL, $entry['guid']);
+               common_element('link', NULL, $entry['link']);
+               common_element_end('item');
+       }
        
        function render_twitter_json_statuses($twitter_statuses) {
                print(json_encode($twitter_statuses));
        }
                
-       // Anyone know what date format this is?  It's not RFC 2822 
+       // Anyone know what date format this is? 
        // Twitter's dates look like this: "Mon Jul 14 23:52:38 +0000 2008" -- Zach 
        function date_twitter($dt) {
                $t = strtotime($dt);
                return date("D M d G:i:s O Y", $t);
        }
+       
+       function date_rfc2822($dt) {
+               $t = strtotime($dt);
+               return date("r", $t);   
+       }
+       
+       function date_iso8601($dt) {
+               $t = strtotime($dt);
+               return date("c", $t);   
+       }
 
        function replier_by_reply($reply_id) {  
 
@@ -171,27 +213,4 @@ class TwitterapiAction extends Action {
                
        }
 
-/*
-
-  <item>
-    <title>CapitalD: @baxterd Have you read The Conquest of Cool? It looks interesting to me...</title>
-    <description>CapitalD: @baxterd Have you read The Conquest of Cool? It looks interesting to me...</description>
-    <pubDate>Mon, 14 Jul 2008 23:54:13 +0000</pubDate>
-    <guid>http://twitter.com/CapitalD/statuses/858499551</guid>
-    <link>http://twitter.com/CapitalD/statuses/858499551</link>
-  </item>
-
-*/
-
-       function show_twitter_rss_item($twitter_status) {
-               common_element_start('item');
-               common_element('title', NULL, "{$twitter_status[user][screen_name]}: $twitter_status[text]");
-               common_element('description', NULL, "{$twitter_status[user][screen_name]}: $twitter_status[text]");
-               common_element('pubDate', NULL, "$twitter_status[created_at]");
-               common_element('guid', NULL, "$twitter_status[id]");
-               common_element('link', NULL, "$twitter_status[id]");
-               common_element_end('item');
-       }
-
-       
 }
\ No newline at end of file