2008-07-14 17:09:49 +09:00
|
|
|
<?php
|
|
|
|
/*
|
2009-08-26 07:14:12 +09:00
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
2009-08-26 07:12:20 +09:00
|
|
|
* Copyright (C) 2008, 2009, StatusNet, Inc.
|
2008-07-14 17:09:49 +09:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
if (!defined('LACONICA')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-07-14 17:09:49 +09:00
|
|
|
|
2008-07-15 12:18:12 +09:00
|
|
|
require_once(INSTALLDIR.'/lib/twitterapi.php');
|
|
|
|
|
2008-12-24 04:49:23 +09:00
|
|
|
class TwitapistatusesAction extends TwitterapiAction
|
|
|
|
{
|
2008-07-29 17:06:41 +09:00
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function public_timeline($args, $apidata)
|
|
|
|
{
|
2009-06-12 17:31:22 +09:00
|
|
|
// XXX: To really live up to the spec we need to build a list
|
2008-12-24 04:19:07 +09:00
|
|
|
// of notices by users who have custom avatars, so fix this SQL -- Zach
|
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
parent::handle($args);
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$sitename = common_config('site', 'name');
|
|
|
|
$title = sprintf(_("%s public timeline"), $sitename);
|
|
|
|
$taguribase = common_config('integration', 'taguri');
|
|
|
|
$id = "tag:$taguribase:PublicTimeline";
|
|
|
|
$link = common_root_url();
|
|
|
|
$subtitle = sprintf(_("%s updates from everyone!"), $sitename);
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$page = (int)$this->arg('page', 1);
|
|
|
|
$count = (int)$this->arg('count', 20);
|
|
|
|
$max_id = (int)$this->arg('max_id', 0);
|
|
|
|
$since_id = (int)$this->arg('since_id', 0);
|
|
|
|
$since = $this->arg('since');
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$notice = Notice::publicStream(($page-1)*$count, $count, $since_id,
|
|
|
|
$max_id, $since);
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
switch($apidata['content-type']) {
|
|
|
|
case 'xml':
|
|
|
|
$this->show_xml_timeline($notice);
|
|
|
|
break;
|
|
|
|
case 'rss':
|
|
|
|
$this->show_rss_timeline($notice, $title, $link, $subtitle);
|
|
|
|
break;
|
|
|
|
case 'atom':
|
|
|
|
$selfuri = common_root_url() . 'api/statuses/public_timeline.atom';
|
|
|
|
$this->show_atom_timeline($notice, $title, $id, $link,
|
|
|
|
$subtitle, null, $selfuri);
|
|
|
|
break;
|
|
|
|
case 'json':
|
|
|
|
$this->show_json_timeline($notice);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->clientError(_('API method not found!'), $code = 404);
|
|
|
|
break;
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function friends_timeline($args, $apidata)
|
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
|
|
|
|
2009-06-24 07:53:49 +09:00
|
|
|
$this->auth_user = $apidata['user'];
|
2009-03-08 07:13:33 +09:00
|
|
|
$user = $this->get_user($apidata['api_arg'], $apidata);
|
2009-06-24 07:53:49 +09:00
|
|
|
|
2009-03-08 07:13:33 +09:00
|
|
|
if (empty($user)) {
|
2009-06-12 17:31:22 +09:00
|
|
|
$this->clientError(_('No such user!'), 404,
|
|
|
|
$apidata['content-type']);
|
2009-03-08 07:13:33 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$profile = $user->getProfile();
|
|
|
|
$sitename = common_config('site', 'name');
|
|
|
|
$title = sprintf(_("%s and friends"), $user->nickname);
|
2009-03-11 08:15:57 +09:00
|
|
|
$taguribase = common_config('integration', 'taguri');
|
2009-06-12 17:31:22 +09:00
|
|
|
$id = "tag:$taguribase:FriendsTimeline:" . $user->id;
|
|
|
|
$link = common_local_url('all',
|
|
|
|
array('nickname' => $user->nickname));
|
|
|
|
$subtitle = sprintf(_('Updates from %1$s and friends on %2$s!'),
|
|
|
|
$user->nickname, $sitename);
|
|
|
|
|
|
|
|
$page = (int)$this->arg('page', 1);
|
|
|
|
$count = (int)$this->arg('count', 20);
|
|
|
|
$max_id = (int)$this->arg('max_id', 0);
|
|
|
|
$since_id = (int)$this->arg('since_id', 0);
|
|
|
|
$since = $this->arg('since');
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2009-06-24 07:53:49 +09:00
|
|
|
if (!empty($this->auth_user) && $this->auth_user->id == $user->id) {
|
|
|
|
$notice = $user->noticeInbox(($page-1)*$count,
|
|
|
|
$count, $since_id, $max_id, $since);
|
|
|
|
} else {
|
|
|
|
$notice = $user->noticesWithFriends(($page-1)*$count,
|
|
|
|
$count, $since_id, $max_id, $since);
|
|
|
|
}
|
2008-12-24 04:19:07 +09:00
|
|
|
|
|
|
|
switch($apidata['content-type']) {
|
2009-06-12 17:31:22 +09:00
|
|
|
case 'xml':
|
2008-12-24 04:19:07 +09:00
|
|
|
$this->show_xml_timeline($notice);
|
|
|
|
break;
|
2009-06-12 17:31:22 +09:00
|
|
|
case 'rss':
|
2008-12-24 04:19:07 +09:00
|
|
|
$this->show_rss_timeline($notice, $title, $link, $subtitle);
|
|
|
|
break;
|
2009-06-12 17:31:22 +09:00
|
|
|
case 'atom':
|
2009-03-11 08:15:57 +09:00
|
|
|
if (isset($apidata['api_arg'])) {
|
2009-04-29 15:31:00 +09:00
|
|
|
$selfuri = common_root_url() .
|
2009-06-12 17:31:22 +09:00
|
|
|
'api/statuses/friends_timeline/' .
|
|
|
|
$apidata['api_arg'] . '.atom';
|
2009-03-11 08:15:57 +09:00
|
|
|
} else {
|
2009-04-29 15:31:00 +09:00
|
|
|
$selfuri = common_root_url() .
|
2009-03-11 08:15:57 +09:00
|
|
|
'api/statuses/friends_timeline.atom';
|
|
|
|
}
|
2009-06-12 17:31:22 +09:00
|
|
|
$this->show_atom_timeline($notice, $title, $id, $link,
|
|
|
|
$subtitle, null, $selfuri);
|
2008-12-24 04:19:07 +09:00
|
|
|
break;
|
2009-06-12 17:31:22 +09:00
|
|
|
case 'json':
|
2008-12-24 04:19:07 +09:00
|
|
|
$this->show_json_timeline($notice);
|
|
|
|
break;
|
2009-06-12 17:31:22 +09:00
|
|
|
default:
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('API method not found!'), $code = 404);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function user_timeline($args, $apidata)
|
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
|
|
|
|
|
|
|
$this->auth_user = $apidata['user'];
|
|
|
|
$user = $this->get_user($apidata['api_arg'], $apidata);
|
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
if (empty($user)) {
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError('Not Found', 404, $apidata['content-type']);
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$profile = $user->getProfile();
|
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$sitename = common_config('site', 'name');
|
|
|
|
$title = sprintf(_("%s timeline"), $user->nickname);
|
2009-03-11 08:15:57 +09:00
|
|
|
$taguribase = common_config('integration', 'taguri');
|
2009-06-12 17:31:22 +09:00
|
|
|
$id = "tag:$taguribase:UserTimeline:".$user->id;
|
|
|
|
$link = common_local_url('showstream',
|
|
|
|
array('nickname' => $user->nickname));
|
|
|
|
$subtitle = sprintf(_('Updates from %1$s on %2$s!'),
|
|
|
|
$user->nickname, $sitename);
|
2008-12-24 04:19:07 +09:00
|
|
|
|
|
|
|
# FriendFeed's SUP protocol
|
|
|
|
# Also added RSS and Atom feeds
|
|
|
|
|
2009-02-21 07:30:09 +09:00
|
|
|
$suplink = common_local_url('sup', null, null, $user->id);
|
2008-12-24 04:19:07 +09:00
|
|
|
header('X-SUP-ID: '.$suplink);
|
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$page = (int)$this->arg('page', 1);
|
|
|
|
$count = (int)$this->arg('count', 20);
|
|
|
|
$max_id = (int)$this->arg('max_id', 0);
|
|
|
|
$since_id = (int)$this->arg('since_id', 0);
|
|
|
|
$since = $this->arg('since');
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$notice = $user->getNotices(($page-1)*$count,
|
|
|
|
$count, $since_id, $max_id, $since);
|
2008-12-24 04:19:07 +09:00
|
|
|
|
|
|
|
switch($apidata['content-type']) {
|
|
|
|
case 'xml':
|
|
|
|
$this->show_xml_timeline($notice);
|
|
|
|
break;
|
|
|
|
case 'rss':
|
2009-06-12 17:31:22 +09:00
|
|
|
$this->show_rss_timeline($notice, $title, $link,
|
|
|
|
$subtitle, $suplink);
|
2008-12-24 04:19:07 +09:00
|
|
|
break;
|
|
|
|
case 'atom':
|
2009-03-11 08:15:57 +09:00
|
|
|
if (isset($apidata['api_arg'])) {
|
2009-04-29 15:31:00 +09:00
|
|
|
$selfuri = common_root_url() .
|
2009-06-12 17:31:22 +09:00
|
|
|
'api/statuses/user_timeline/' .
|
|
|
|
$apidata['api_arg'] . '.atom';
|
2009-03-11 08:15:57 +09:00
|
|
|
} else {
|
2009-04-29 15:31:00 +09:00
|
|
|
$selfuri = common_root_url() .
|
2009-03-11 08:15:57 +09:00
|
|
|
'api/statuses/user_timeline.atom';
|
|
|
|
}
|
2009-06-12 17:31:22 +09:00
|
|
|
$this->show_atom_timeline($notice, $title, $id, $link,
|
|
|
|
$subtitle, $suplink, $selfuri);
|
2008-12-24 04:19:07 +09:00
|
|
|
break;
|
|
|
|
case 'json':
|
|
|
|
$this->show_json_timeline($notice);
|
|
|
|
break;
|
|
|
|
default:
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('API method not found!'), $code = 404);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function update($args, $apidata)
|
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
|
|
|
|
|
|
|
if (!in_array($apidata['content-type'], array('xml', 'json'))) {
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('API method not found!'), $code = 404);
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
2009-06-12 17:31:22 +09:00
|
|
|
$this->clientError(_('This method requires a POST.'),
|
|
|
|
400, $apidata['content-type']);
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$user = $apidata['user']; // Always the auth user
|
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
$status = $this->trimmed('status');
|
|
|
|
$source = $this->trimmed('source');
|
2009-06-12 17:31:22 +09:00
|
|
|
$in_reply_to_status_id =
|
|
|
|
intval($this->trimmed('in_reply_to_status_id'));
|
2008-12-11 02:37:26 +09:00
|
|
|
$reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api');
|
2009-06-12 17:31:22 +09:00
|
|
|
|
|
|
|
if (empty($source) || in_array($source, $reserved_sources)) {
|
2008-12-24 04:19:07 +09:00
|
|
|
$source = 'api';
|
|
|
|
}
|
2008-07-31 09:49:22 +09:00
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
if (empty($status)) {
|
2008-07-29 17:06:41 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
// XXX: Note: In this case, Twitter simply returns '200 OK'
|
|
|
|
// No error is given, but the status is not posted to the
|
|
|
|
// user's timeline. Seems bad. Shouldn't we throw an
|
|
|
|
// errror? -- Zach
|
|
|
|
return;
|
2008-07-29 17:06:41 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
} else {
|
2008-12-09 14:53:45 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
$status_shortened = common_shorten_links($status);
|
2008-11-07 05:59:26 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
if (mb_strlen($status_shortened) > 140) {
|
2008-11-07 05:59:26 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
// XXX: Twitter truncates anything over 140, flags the status
|
|
|
|
// as "truncated." Sending this error may screw up some clients
|
|
|
|
// that assume Twitter will truncate for them. Should we just
|
|
|
|
// truncate too? -- Zach
|
2009-06-12 17:31:22 +09:00
|
|
|
$this->clientError(_('That\'s too long. Max notice size is 140 chars.'),
|
|
|
|
$code = 406, $apidata['content-type']);
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-07-29 17:06:41 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
// Check for commands
|
|
|
|
$inter = new CommandInterpreter();
|
|
|
|
$cmd = $inter->handle_command($user, $status_shortened);
|
2008-08-16 03:53:17 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
if ($cmd) {
|
2008-09-26 10:20:15 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
if ($this->supported($cmd)) {
|
|
|
|
$cmd->execute(new Channel());
|
|
|
|
}
|
|
|
|
|
|
|
|
// cmd not supported? Twitter just returns your latest status.
|
|
|
|
// And, it returns your last status whether the cmd was successful
|
|
|
|
// or not!
|
|
|
|
$n = $user->getCurrentNotice();
|
|
|
|
$apidata['api_arg'] = $n->id;
|
|
|
|
} else {
|
2008-10-05 12:09:15 +09:00
|
|
|
|
2008-12-24 04:21:29 +09:00
|
|
|
$reply_to = null;
|
2008-10-05 12:09:15 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
if ($in_reply_to_status_id) {
|
|
|
|
|
|
|
|
// check whether notice actually exists
|
|
|
|
$reply = Notice::staticGet($in_reply_to_status_id);
|
|
|
|
|
|
|
|
if ($reply) {
|
|
|
|
$reply_to = $in_reply_to_status_id;
|
|
|
|
} else {
|
2009-06-12 17:31:22 +09:00
|
|
|
$this->clientError(_('Not found'), $code = 404,
|
|
|
|
$apidata['content-type']);
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$notice = Notice::saveNew($user->id,
|
|
|
|
html_entity_decode($status, ENT_NOQUOTES, 'UTF-8'),
|
|
|
|
$source, 1, $reply_to);
|
2008-12-24 04:19:07 +09:00
|
|
|
|
|
|
|
if (is_string($notice)) {
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->serverError($notice);
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
common_broadcast_notice($notice);
|
|
|
|
$apidata['api_arg'] = $notice->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->show($args, $apidata);
|
|
|
|
}
|
|
|
|
|
2009-04-29 15:31:00 +09:00
|
|
|
function mentions($args, $apidata)
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
|
|
|
|
2009-03-11 08:48:14 +09:00
|
|
|
$user = $this->get_user($apidata['api_arg'], $apidata);
|
2008-12-24 04:19:07 +09:00
|
|
|
$this->auth_user = $apidata['user'];
|
2009-06-12 17:31:22 +09:00
|
|
|
|
|
|
|
if (empty($user)) {
|
|
|
|
$this->clientError(_('No such user!'), 404,
|
|
|
|
$apidata['content-type']);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
$profile = $user->getProfile();
|
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$sitename = common_config('site', 'name');
|
|
|
|
$title = sprintf(_('%1$s / Updates mentioning %2$s'),
|
2009-04-29 15:31:00 +09:00
|
|
|
$sitename, $user->nickname);
|
2009-03-11 08:15:57 +09:00
|
|
|
$taguribase = common_config('integration', 'taguri');
|
2009-06-12 17:31:22 +09:00
|
|
|
$id = "tag:$taguribase:Mentions:".$user->id;
|
|
|
|
$link = common_local_url('replies',
|
|
|
|
array('nickname' => $user->nickname));
|
|
|
|
$subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'),
|
2009-04-29 15:31:00 +09:00
|
|
|
$sitename, $user->nickname, $profile->getBestName());
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$page = (int)$this->arg('page', 1);
|
|
|
|
$count = (int)$this->arg('count', 20);
|
|
|
|
$max_id = (int)$this->arg('max_id', 0);
|
|
|
|
$since_id = (int)$this->arg('since_id', 0);
|
|
|
|
$since = $this->arg('since');
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$notice = $user->getReplies(($page-1)*$count,
|
2009-05-30 08:32:55 +09:00
|
|
|
$count, $since_id, $max_id, $since);
|
2008-12-24 04:19:07 +09:00
|
|
|
|
|
|
|
switch($apidata['content-type']) {
|
2009-06-12 17:31:22 +09:00
|
|
|
case 'xml':
|
|
|
|
$this->show_xml_timeline($notice);
|
2008-12-24 04:19:07 +09:00
|
|
|
break;
|
2009-06-12 17:31:22 +09:00
|
|
|
case 'rss':
|
|
|
|
$this->show_rss_timeline($notice, $title, $link, $subtitle);
|
2008-12-24 04:19:07 +09:00
|
|
|
break;
|
2009-06-12 17:31:22 +09:00
|
|
|
case 'atom':
|
2009-04-29 15:31:00 +09:00
|
|
|
$selfuri = common_root_url() .
|
|
|
|
ltrim($_SERVER['QUERY_STRING'], 'p=');
|
2009-06-12 17:31:22 +09:00
|
|
|
$this->show_atom_timeline($notice, $title, $id, $link, $subtitle,
|
2009-04-29 15:31:00 +09:00
|
|
|
null, $selfuri);
|
2008-12-24 04:19:07 +09:00
|
|
|
break;
|
2009-06-12 17:31:22 +09:00
|
|
|
case 'json':
|
|
|
|
$this->show_json_timeline($notice);
|
2008-12-24 04:19:07 +09:00
|
|
|
break;
|
2009-06-12 17:31:22 +09:00
|
|
|
default:
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('API method not found!'), $code = 404);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-04-29 15:31:00 +09:00
|
|
|
function replies($args, $apidata)
|
|
|
|
{
|
|
|
|
call_user_func(array($this, 'mentions'), $args, $apidata);
|
|
|
|
}
|
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function show($args, $apidata)
|
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
|
|
|
|
|
|
|
if (!in_array($apidata['content-type'], array('xml', 'json'))) {
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('API method not found!'), $code = 404);
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-07 03:57:21 +09:00
|
|
|
// 'id' is an undocumented parameter in Twitter's API. Several
|
|
|
|
// clients make use of it, so we support it too.
|
|
|
|
|
|
|
|
// show.json?id=12345 takes precedence over /show/12345.json
|
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
$this->auth_user = $apidata['user'];
|
2009-07-07 03:57:21 +09:00
|
|
|
$notice_id = $this->trimmed('id');
|
|
|
|
|
|
|
|
if (empty($notice_id)) {
|
|
|
|
$notice_id = $apidata['api_arg'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$notice = Notice::staticGet((int)$notice_id);
|
2008-12-24 04:19:07 +09:00
|
|
|
|
|
|
|
if ($notice) {
|
|
|
|
if ($apidata['content-type'] == 'xml') {
|
|
|
|
$this->show_single_xml_status($notice);
|
|
|
|
} elseif ($apidata['content-type'] == 'json') {
|
|
|
|
$this->show_single_json_status($notice);
|
|
|
|
}
|
|
|
|
} else {
|
2009-06-12 17:31:22 +09:00
|
|
|
// XXX: Twitter just sets a 404 header and doens't bother
|
|
|
|
// to return an err msg
|
|
|
|
$this->clientError(_('No status with that ID found.'),
|
|
|
|
404, $apidata['content-type']);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function destroy($args, $apidata)
|
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
|
|
|
|
|
|
|
if (!in_array($apidata['content-type'], array('xml', 'json'))) {
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('API method not found!'), $code = 404);
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for RESTfulness
|
|
|
|
if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
|
|
|
|
// XXX: Twitter just prints the err msg, no XML / JSON.
|
2009-06-12 17:31:22 +09:00
|
|
|
$this->clientError(_('This method requires a POST or DELETE.'),
|
|
|
|
400, $apidata['content-type']);
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
$user = $apidata['user']; // Always the auth user
|
2008-12-24 04:19:07 +09:00
|
|
|
$notice_id = $apidata['api_arg'];
|
2009-06-12 17:31:22 +09:00
|
|
|
$notice = Notice::staticGet($notice_id);
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
if (empty($notice)) {
|
|
|
|
$this->clientError(_('No status found with that ID.'),
|
|
|
|
404, $apidata['content-type']);
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($user->id == $notice->profile_id) {
|
|
|
|
$replies = new Reply;
|
|
|
|
$replies->get('notice_id', $notice_id);
|
|
|
|
$replies->delete();
|
|
|
|
$notice->delete();
|
|
|
|
|
|
|
|
if ($apidata['content-type'] == 'xml') {
|
|
|
|
$this->show_single_xml_status($notice);
|
|
|
|
} elseif ($apidata['content-type'] == 'json') {
|
|
|
|
$this->show_single_json_status($notice);
|
|
|
|
}
|
|
|
|
} else {
|
2009-06-12 17:31:22 +09:00
|
|
|
$this->clientError(_('You may not delete another user\'s status.'),
|
|
|
|
403, $apidata['content-type']);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function friends($args, $apidata)
|
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
2009-08-07 04:14:27 +09:00
|
|
|
$includeStatuses=! (boolean) $args['lite'];
|
|
|
|
return $this->subscriptions($apidata, 'subscribed', 'subscriber', false, $includeStatuses);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
|
2009-02-23 13:04:47 +09:00
|
|
|
function friendsIDs($args, $apidata)
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
2009-02-23 13:04:47 +09:00
|
|
|
return $this->subscriptions($apidata, 'subscribed', 'subscriber', true);
|
|
|
|
}
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2009-02-23 13:04:47 +09:00
|
|
|
function followers($args, $apidata)
|
|
|
|
{
|
|
|
|
parent::handle($args);
|
2009-08-07 04:14:27 +09:00
|
|
|
$includeStatuses=! (boolean) $args['lite'];
|
|
|
|
return $this->subscriptions($apidata, 'subscriber', 'subscribed', false, $includeStatuses);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
|
2009-02-23 13:04:47 +09:00
|
|
|
function followersIDs($args, $apidata)
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2009-02-23 13:04:47 +09:00
|
|
|
parent::handle($args);
|
|
|
|
return $this->subscriptions($apidata, 'subscriber', 'subscribed', true);
|
|
|
|
}
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2009-08-07 04:14:27 +09:00
|
|
|
function subscriptions($apidata, $other_attr, $user_attr, $onlyIDs=false, $includeStatuses=true)
|
2009-02-23 13:04:47 +09:00
|
|
|
{
|
|
|
|
$this->auth_user = $apidata['user'];
|
2008-12-24 04:19:07 +09:00
|
|
|
$user = $this->get_user($apidata['api_arg'], $apidata);
|
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
if (empty($user)) {
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError('Not Found', 404, $apidata['content-type']);
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$profile = $user->getProfile();
|
|
|
|
|
|
|
|
$sub = new Subscription();
|
|
|
|
$sub->$user_attr = $profile->id;
|
|
|
|
|
|
|
|
$sub->orderBy('created DESC');
|
2009-02-23 13:04:47 +09:00
|
|
|
|
2009-06-12 17:31:22 +09:00
|
|
|
// Normally, page 100 friends at a time
|
|
|
|
|
2009-02-23 13:04:47 +09:00
|
|
|
if (!$onlyIDs) {
|
2009-06-12 17:31:22 +09:00
|
|
|
$page = $this->arg('page', 1);
|
|
|
|
$count = $this->arg('count', 100);
|
|
|
|
$sub->limit(($page-1)*$count, $count);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// If we're just looking at IDs, return
|
|
|
|
// ALL of them, unless the user specifies a page,
|
|
|
|
// in which case, return 500 per page.
|
|
|
|
|
|
|
|
$page = $this->arg('page');
|
|
|
|
if (!empty($page)) {
|
|
|
|
if ($page < 1) {
|
|
|
|
$page = 1;
|
|
|
|
}
|
|
|
|
$count = 500;
|
|
|
|
$sub->limit(($page-1)*$count, $count);
|
|
|
|
}
|
2009-02-23 13:04:47 +09:00
|
|
|
}
|
2008-12-24 04:19:07 +09:00
|
|
|
|
|
|
|
$others = array();
|
|
|
|
|
|
|
|
if ($sub->find()) {
|
|
|
|
while ($sub->fetch()) {
|
|
|
|
$others[] = Profile::staticGet($sub->$other_attr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// user has no followers
|
|
|
|
}
|
|
|
|
|
|
|
|
$type = $apidata['content-type'];
|
|
|
|
|
|
|
|
$this->init_document($type);
|
2009-02-23 13:04:47 +09:00
|
|
|
|
|
|
|
if ($onlyIDs) {
|
|
|
|
$this->showIDs($others, $type);
|
|
|
|
} else {
|
2009-08-07 04:14:27 +09:00
|
|
|
$this->show_profiles($others, $type, $includeStatuses);
|
2009-02-23 13:04:47 +09:00
|
|
|
}
|
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
$this->end_document($type);
|
|
|
|
}
|
|
|
|
|
2009-08-07 04:14:27 +09:00
|
|
|
function show_profiles($profiles, $type, $includeStatuses)
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
switch ($type) {
|
2009-06-12 17:31:22 +09:00
|
|
|
case 'xml':
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->elementStart('users', array('type' => 'array'));
|
2008-12-24 04:19:07 +09:00
|
|
|
foreach ($profiles as $profile) {
|
2009-08-07 04:14:27 +09:00
|
|
|
$this->show_profile($profile,$type,null,$includeStatuses);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->elementEnd('users');
|
2008-12-24 04:19:07 +09:00
|
|
|
break;
|
2009-06-12 17:31:22 +09:00
|
|
|
case 'json':
|
2008-12-24 04:19:07 +09:00
|
|
|
$arrays = array();
|
|
|
|
foreach ($profiles as $profile) {
|
2009-08-07 04:14:27 +09:00
|
|
|
$arrays[] = $this->twitter_user_array($profile, $includeStatuses);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
print json_encode($arrays);
|
|
|
|
break;
|
2009-06-12 17:31:22 +09:00
|
|
|
default:
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('unsupported file type'));
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-23 13:04:47 +09:00
|
|
|
function showIDs($profiles, $type)
|
|
|
|
{
|
|
|
|
switch ($type) {
|
2009-06-12 17:31:22 +09:00
|
|
|
case 'xml':
|
2009-02-23 13:04:47 +09:00
|
|
|
$this->elementStart('ids');
|
|
|
|
foreach ($profiles as $profile) {
|
|
|
|
$this->element('id', null, $profile->id);
|
|
|
|
}
|
|
|
|
$this->elementEnd('ids');
|
|
|
|
break;
|
2009-06-12 17:31:22 +09:00
|
|
|
case 'json':
|
2009-02-23 13:04:47 +09:00
|
|
|
$ids = array();
|
|
|
|
foreach ($profiles as $profile) {
|
|
|
|
$ids[] = (int)$profile->id;
|
|
|
|
}
|
|
|
|
print json_encode($ids);
|
|
|
|
break;
|
2009-06-12 17:31:22 +09:00
|
|
|
default:
|
2009-02-23 13:04:47 +09:00
|
|
|
$this->clientError(_('unsupported file type'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function featured($args, $apidata)
|
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->serverError(_('API method under construction.'), $code=501);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function supported($cmd)
|
|
|
|
{
|
2009-06-12 17:31:22 +09:00
|
|
|
$cmdlist = array('MessageCommand', 'SubCommand', 'UnsubCommand',
|
|
|
|
'FavCommand', 'OnCommand', 'OffCommand');
|
2008-10-05 12:09:15 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
if (in_array(get_class($cmd), $cmdlist)) {
|
|
|
|
return true;
|
|
|
|
}
|
2008-10-05 12:09:15 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
return false;
|
|
|
|
}
|
2008-10-05 12:09:15 +09:00
|
|
|
|
2008-07-14 17:09:49 +09:00
|
|
|
}
|