3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
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.
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.
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/>.
20 if (!defined('LACONICA')) { exit(1); }
22 class TwitterapiAction extends Action {
24 function handle($args) {
25 parent::handle($args);
29 * Spits out a Laconica notice as a Twitter-compatible "status"
31 function show_xml_status($notice) {
33 $profile = $notice->getProfile();
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
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);
52 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
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');
60 common_element_end('status');
63 // XXX: Candidate for a general utility method somewhere?
64 function count_subscriptions($profile) {
67 $sub = new Subscription();
68 $sub->subscribed = $profile->id;
71 while ($sub->fetch()) {
73 $other = Remote_profile::staticGet('id', $sub->subscriber);
75 $other = User::staticGet('id', $sub->subscriber);
78 common_debug('Got a bad subscription: '.print_r($sub,TRUE));