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 require_once(INSTALLDIR.'/lib/twitterapi.php');
24 class TwitapiusersAction extends TwitterapiAction {
26 function is_readonly() {
31 Returns extended information of a given user, specified by ID or
32 screen name as per the required id parameter below. This information
33 includes design settings, so third party developers can theme their
34 widgets according to a given user's preferences. You must be properly
35 authenticated to request the page of a protected user.
37 URL: http://twitter.com/users/show/id.format
43 * id. Required. The ID or screen name of a user.
44 Ex: http://twitter.com/users/show/12345.json or
45 http://twitter.com/users/show/bob.xml
47 * email. Optional. The email address of a user. Ex:
48 http://twitter.com/users/show.xml?email=test@example.com
51 function show($args, $apidata) {
52 parent::handle($args);
55 $email = $this->arg('email');
57 if (isset($apidata['api_arg'])) {
58 if (is_numeric($apidata['api_arg'])) {
60 $user = User::staticGet($apidata['api_arg']);
63 $nickname = common_canonical_nickname($apidata['api_arg']);
64 $user = User::staticGet('nickname', $nickname);
67 // or, find user by email address
68 // XXX: The Twitter API spec say an id is *required*, but you can actually
69 // pull up a user with just an email address. -- Zach
70 $user = User::staticGet('email', $email);
74 // XXX: Twitter returns a random(?) user instead of throwing and err! -- Zach
75 $this->client_error(_('User not found.'), 404, $apidata['content-type']);
79 $profile = $user->getProfile();
82 common_server_error(_('User has no profile.'));
86 $twitter_user = $this->twitter_user_array($profile, true);
88 // Add in extended user fields offered up by this method
89 $twitter_user['created_at'] = $this->date_twitter($profile->created);
91 $subbed = DB_DataObject::factory('subscription');
92 $subbed->subscriber = $profile->id;
93 $subbed_count = (int) $subbed->count() - 1;
95 $notices = DB_DataObject::factory('notice');
96 $notices->profile_id = $profile->id;
97 $notice_count = (int) $notices->count();
99 $twitter_user['friends_count'] = (is_int($subbed_count)) ? $subbed_count : 0;
100 $twitter_user['statuses_count'] = (is_int($notice_count)) ? $notice_count : 0;
102 // Other fields Twitter sends...
103 $twitter_user['profile_background_color'] = '';
104 $twitter_user['profile_text_color'] = '';
105 $twitter_user['profile_link_color'] = '';
106 $twitter_user['profile_sidebar_fill_color'] = '';
107 $twitter_user['favourites_count'] = 0;
108 $twitter_user['utc_offset'] = '';
109 $twitter_user['time_zone'] = '';
110 $twitter_user['following'] = '';
111 $twitter_user['notifications'] = '';
113 if ($apidata['content-type'] == 'xml') {
114 $this->init_document('xml');
115 $this->show_twitter_xml_user($twitter_user);
116 $this->end_document('xml');
117 } elseif ($apidata['content-type'] == 'json') {
118 $this->init_document('json');
119 $this->show_json_objects($twitter_user);
120 $this->end_document('json');
122 common_user_error(_('API method not found!'), $code = 404);