]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/twitterapi.php
b0aec677518a0ce3569a12b50298069f708b6f21
[quix0rs-gnu-social.git] / lib / twitterapi.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 class TwitterapiAction extends Action {
23
24         function handle($args) {
25                 parent::handle($args);
26         }
27         
28         /*
29          * Spits out a Laconica notice as a Twitter-compatible "status"
30          */
31         function show_xml_status($notice) {
32                 global $config;
33                 $profile = $notice->getProfile();
34                 
35                 common_element_start('status');
36                 // XXX: twitter created_at date looks like this: Mon Jul 14 23:52:38 +0000 2008
37                 common_element('created_at', NULL, common_exact_date($notice->created));
38                 common_element('text', NULL, $notice->content);
39                 common_element('source', NULL, 'Web');  # twitterific, twitterfox, etc.
40                 common_element('truncated', NULL, 'false'); # how do we tell in Laconica?
41                 common_element('in_reply_to_status_id', NULL, $notice->reply_to);
42                 common_element('in_reply_to_user_id', NULL,'');
43                 common_element('favorited', Null, '');  # feature for some day
44                 
45                 common_element_start('user');
46                 common_element('id', NULL, $notice->id);
47                 common_element('name', NULL, $profile->getBestName());
48                 common_element('screen_name', NULL, $profile->nickname);
49                 common_element('location', NULL, $profile->location);
50                 common_element('description', NULL, $profile->bio);
51                 
52                 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
53                 
54                 common_element('profile_image_url', NULL, ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE));
55                 common_element('url', NULL, $profile->homepage);
56                 common_element('protected', NULL, 'false'); # not supported yet
57                 common_element('followers_count', NULL, $this->count_subscriptions($profile)); # where do I get this?
58                 common_element_end('user');
59                 
60                 common_element_end('status');
61         }       
62
63         // XXX: Candidate for a general utility method somewhere?       
64         function count_subscriptions($profile) {
65                 
66                 $count = 0;
67                 $sub = new Subscription();
68                 $sub->subscribed = $profile->id;
69
70                 if ($sub->find()) {
71                         while ($sub->fetch()) {
72                                 if ($sub->token) {
73                                         $other = Remote_profile::staticGet('id', $sub->subscriber);
74                                 } else {
75                                         $other = User::staticGet('id', $sub->subscriber);
76                                 }
77                                 if (!$other) {
78                                         common_debug('Got a bad subscription: '.print_r($sub,TRUE));
79                                         continue;
80                                 }               
81                                 $count++;
82                         }
83                 }
84                 return $count;
85         }
86         
87 }