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-XML "status"
31 function render_xml_status($notice) {
34 common_element_start('status');
35 common_element('created_at', NULL, $this->date_twitter($notice->created));
36 common_element('id', NULL, $notice->id);
37 common_element('text', NULL, $notice->content);
38 common_element('source', NULL, ''); # XXX: twitterific, twitterfox, etc. Not supported yet.
39 common_element('truncated', NULL, 'false'); # Not possible on Laconica
40 common_element('in_reply_to_status_id', NULL, $notice->reply_to);
41 common_element('in_reply_to_user_id', NULL, ($notice->reply_to) ? $this->replier_by_reply($notice->reply_to) : '');
42 common_element('favorited', Null, ''); # XXX: Not implemented on Laconica yet.
44 $profile = $notice->getProfile();
45 $this->render_xml_user($profile);
47 common_element_end('status');
51 * Spits out a Laconica Profile as a Twitter-XML "user"
53 function render_xml_user($profile) {
54 common_element_start('user');
55 common_element('id', NULL, $profile->id);
56 common_element('name', NULL, $profile->getBestName());
57 common_element('screen_name', NULL, $profile->nickname);
58 common_element('location', NULL, $profile->location);
59 common_element('description', NULL, $profile->bio);
61 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
63 common_element('profile_image_url', NULL, ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE));
64 common_element('url', NULL, $profile->homepage);
65 common_element('protected', NULL, 'false'); # not supported by Laconica yet
66 common_element('followers_count', NULL, $this->count_subscriptions($profile));
67 common_element_end('user');
70 // Anyone know what date format this is? It's not RFC 2822
71 // Twitter's dates look like this: "Mon Jul 14 23:52:38 +0000 2008" -- Zach
72 function date_twitter($dt) {
74 return date("D M d G:i:s O Y", $t);
77 function replier_by_reply($reply_id) {
79 $notice = Notice::staticGet($reply_id);
82 common_debug("Got a bad notice_id: $reply_id");
85 $profile = $notice->getProfile();
88 common_debug("Got a bad profile_id: $profile_id");
95 // XXX: Candidate for a general utility method somewhere?
96 function count_subscriptions($profile) {
99 $sub = new Subscription();
100 $sub->subscribed = $profile->id;
103 while ($sub->fetch()) {
105 $other = Remote_profile::staticGet('id', $sub->subscriber);
107 $other = User::staticGet('id', $sub->subscriber);
110 common_debug('Got a bad subscription: '.print_r($sub,TRUE));