*/
class TwitapistatusesAction extends TwitterapiAction {
+ function is_readonly() {
+
+ static $write_methods = array( 'update',
+ 'destroy');
+
+ $cmdtext = explode('.', $this->arg('method'));
+
+ if (in_array($cmdtext[0], $write_methods)) {
+ return false;
+ }
+
+ return true;
+ }
+
function public_timeline($args, $apidata) {
parent::handle($args);
-
+
$sitename = common_config('site', 'name');
$siteserver = common_config('site', 'server');
$title = sprintf(_("%s public timeline"), $sitename);
// Number of public statuses to return by default -- Twitter sends 20
$MAX_PUBSTATUSES = 20;
- $notice = DB_DataObject::factory('notice');
+ $notice = new Notice();
// FIXME: To really live up to the spec we need to build a list
// of notices by users who have custom avatars, so fix this SQL -- Zach
- # FIXME: bad performance
- $notice->whereAdd('EXISTS (SELECT user.id from user where user.id = notice.profile_id)');
+ # XXX: sub-optimal performance
+
+ $notice->is_local = 1;
$notice->orderBy('created DESC, notice.id DESC');
$notice->limit($MAX_PUBSTATUSES);
$cnt = $notice->find();
function show_xml_timeline($notice) {
- header('Content-Type: application/xml; charset=utf-8');
- common_start_xml();
+ $this->init_document('xml');
common_element_start('statuses', array('type' => 'array'));
if (is_array($notice)) {
}
common_element_end('statuses');
- common_end_xml();
+ $this->end_document('xml');
}
function show_rss_timeline($notice, $title, $id, $link, $subtitle) {
- header("Content-Type: application/rss+xml; charset=utf-8");
-
- $this->init_twitter_rss();
+ $this->init_document('rss');
common_element_start('channel');
common_element('title', NULL, $title);
}
common_element_end('channel');
- $this->end_twitter_rss();
+ $this->end_twitter_rss();
}
function show_atom_timeline($notice, $title, $id, $link, $subtitle=NULL) {
- header('Content-Type: application/atom+xml; charset=utf-8');
-
- $this->init_twitter_atom();
+ $this->init_document('atom');
common_element('title', NULL, $title);
common_element('id', NULL, $id);
}
}
- $this->end_twitter_atom();
+ $this->end_document('atom');
+
}
function show_json_timeline($notice) {
- header('Content-Type: application/json; charset=utf-8');
+ $this->init_document('json');
$statuses = array();
}
$this->show_twitter_json_statuses($statuses);
+
+ $this->end_document('json');
}
/*
$link = common_local_url('all', array('nickname' => $user->nickname));
$subtitle = sprintf(_("Updates from %s and friends on %s!"), $user->nickname, $sitename);
- $notice = new Notice();
-
- # XXX: chokety and bad
-
- $notice->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$profile->id.' and subscribed = notice.profile_id)', 'OR');
- $notice->whereAdd('profile_id = ' . $profile->id, 'OR');
-
- # XXX: since
- # XXX: since_id
-
- $notice->orderBy('created DESC, notice.id DESC');
-
- $notice->limit((($page-1)*20), $count);
-
- $cnt = $notice->find();
+ $notice = $user->noticesWithFriends(($page-1)*20, $count);
switch($apidata['content-type']) {
case 'xml':
if (!$profile) {
common_server_error(_('User has no profile.'));
- return;
+ exit();
}
$count = $this->arg('count');
exit();
}
-
- function show($args, $apidata) {
- parent::handle($args);
-
- $id = $apidata['api_arg'];
- $notice = Notice::staticGet($id);
-
- 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 {
- header('HTTP/1.1 404 Not Found');
- }
-
- exit();
- }
-
- function show_single_xml_status($notice) {
- header('Content-Type: application/xml; charset=utf-8');
- common_start_xml();
- $twitter_status = $this->twitter_status_array($notice);
- $this->show_twitter_xml_status($twitter_status);
- common_end_xml();
- exit();
- }
-
- function show_single_json_status($notice) {
- header('Content-Type: application/json; charset=utf-8');
- $status = $this->twitter_status_array($notice);
- $this->show_twitter_json_statuses($status);
- exit();
- }
function update($args, $apidata) {
parent::handle($args);
$user = $apidata['user'];
+ $this->is_readonly();
+
+
$notice = DB_DataObject::factory('notice');
$notice->profile_id = $user->id; # user id *is* profile id
ID. Ex: http://server/api/statuses/replies.xml?since_id=12345
*/
function replies($args, $apidata) {
+
parent::handle($args);
$since = $this->arg('since');
*/
function friends($args, $apidata) {
parent::handle($args);
- return $this->subscriptions('subscribed', 'subscriber');
+ return $this->subscriptions($apidata, 'subscribed', 'subscriber');
}
/*
function followers($args, $apidata) {
parent::handle($args);
- return $this->subscriptions('subscriber', 'subscribed');
+ return $this->subscriptions($apidata, 'subscriber', 'subscribed');
}
-
- function subscriptions($other_attr, $user_attr) {
- $user = null;
+
+ function subscriptions($apidata, $other_attr, $user_attr) {
- // function was called with an argument /statuses/user_timeline/api_arg.format
- if (isset($apidata['api_arg'])) {
+ $user = $this->get_subs_user($apidata);
- if (is_numeric($apidata['api_arg'])) {
- $user = User::staticGet($apidata['api_arg']);
- } else {
- $nickname = common_canonical_nickname($apidata['api_arg']);
- $user = User::staticGet('nickname', $nickname);
- }
- } else {
-
- // if no user was specified, then we'll use the authenticated user
- $user = $apidata['user'];
- }
-
- if (!$user) {
- // Set the user to be the auth user if asked-for can't be found
- // honestly! This is what Twitter does, I swear --Zach
- $user = $apidata['user'];
+ # XXX: id
+ # XXX: lite
+
+ $page = $this->trimmed('page');
+
+ if (!$page || !is_numeric($page)) {
+ $page = 1;
}
-
+
$profile = $user->getProfile();
if (!$profile) {
common_server_error(_('User has no profile.'));
return;
}
-
- if (!$page) {
- $page = 1;
- }
$sub = new Subscription();
$sub->$user_attr = $profile->id;
$sub->orderBy('created DESC');
-
+ $sub->limit(($page-1)*100, 100);
+
$others = array();
if ($sub->find()) {
exit();
}
+ function get_subs_user($apidata) {
+
+ // function was called with an argument /statuses/user_timeline/api_arg.format
+ if (isset($apidata['api_arg'])) {
+
+ if (is_numeric($apidata['api_arg'])) {
+ $user = User::staticGet($apidata['api_arg']);
+ } else {
+ $nickname = common_canonical_nickname($apidata['api_arg']);
+ $user = User::staticGet('nickname', $nickname);
+ }
+ } else {
+
+ // if no user was specified, then we'll use the authenticated user
+ $user = $apidata['user'];
+ }
+
+ if (!$user) {
+ // Set the user to be the auth user if asked-for can't be found
+ // honestly! This is what Twitter does, I swear --Zach
+ $user = $apidata['user'];
+ }
+
+ return $user;
+ }
+
function show_profiles($profiles, $type) {
switch ($type) {
case 'xml':
foreach ($profiles as $profile) {
$this->show_profile($profile);
}
- common_element_end();
+ common_element_end('users');
break;
case 'json':
$arrays = array();