From 5e53a97a41038151959c0280d988c609c0834aa2 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 28 May 2009 16:18:58 -0700 Subject: Warning log msg when http basic auth fails --- actions/api.php | 1 + 1 file changed, 1 insertion(+) (limited to 'actions') diff --git a/actions/api.php b/actions/api.php index 8762b4bcd..b25ba99f3 100644 --- a/actions/api.php +++ b/actions/api.php @@ -67,6 +67,7 @@ class ApiAction extends Action $this->process_command(); } else { # basic authentication failed + common_log(LOG_WARNING, "Failed API auth attempt, nickname: $nickname."); $this->show_basic_auth_error(); } } -- cgit v1.2.3-54-g00ecf From eb76a3bbb36e1f73007cb9b602001ec14f6853c6 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 29 May 2009 16:32:55 -0700 Subject: Ticket #1567 - API: Change before_id parameter to max_id --- actions/twitapidirect_messages.php | 6 +++--- actions/twitapistatuses.php | 36 ++++++++++++++++-------------------- classes/Fave.php | 6 +++--- classes/Notice_inbox.php | 10 +++++----- classes/Notice_tag.php | 6 +++--- classes/Reply.php | 10 +++++----- classes/User_group.php | 6 +++--- 7 files changed, 38 insertions(+), 42 deletions(-) (limited to 'actions') diff --git a/actions/twitapidirect_messages.php b/actions/twitapidirect_messages.php index 7101db8df..ab8f07810 100644 --- a/actions/twitapidirect_messages.php +++ b/actions/twitapidirect_messages.php @@ -43,7 +43,7 @@ class Twitapidirect_messagesAction extends TwitterapiAction $count = $this->arg('count'); $since = $this->arg('since'); $since_id = $this->arg('since_id'); - $before_id = $this->arg('before_id'); + $max_id = $this->arg('max_id'); $page = $this->arg('page'); @@ -74,8 +74,8 @@ class Twitapidirect_messagesAction extends TwitterapiAction $link = $server . $user->nickname . '/outbox'; } - if ($before_id) { - $message->whereAdd("id < $before_id"); + if ($max_id) { + $message->whereAdd("id < $max_id"); } if ($since_id) { diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index 3abeba367..1fbde6639 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -45,22 +45,21 @@ class TwitapistatusesAction extends TwitterapiAction $page = $this->arg('page'); $since_id = $this->arg('since_id'); - $before_id = $this->arg('before_id'); + $max_id = $this->arg('max_id'); - // NOTE: page, since_id, and before_id are extensions to Twitter API -- TB if (!$page) { $page = 1; } if (!$since_id) { $since_id = 0; } - if (!$before_id) { - $before_id = 0; + if (!$max_id) { + $max_id = 0; } $since = strtotime($this->arg('since')); - $notice = Notice::publicStream((($page-1)*$MAX_PUBSTATUSES), $MAX_PUBSTATUSES, $since_id, $before_id, $since); + $notice = Notice::publicStream((($page-1)*$MAX_PUBSTATUSES), $MAX_PUBSTATUSES, $since_id, $max_id, $since); if ($notice) { @@ -97,7 +96,7 @@ class TwitapistatusesAction extends TwitterapiAction $since_id = $this->arg('since_id'); $count = $this->arg('count'); $page = $this->arg('page'); - $before_id = $this->arg('before_id'); + $max_id = $this->arg('max_id'); if (!$page) { $page = 1; @@ -111,9 +110,8 @@ class TwitapistatusesAction extends TwitterapiAction $since_id = 0; } - // NOTE: before_id is an extension to Twitter API -- TB - if (!$before_id) { - $before_id = 0; + if (!$max_id) { + $max_id = 0; } $since = strtotime($this->arg('since')); @@ -133,7 +131,7 @@ class TwitapistatusesAction extends TwitterapiAction $link = common_local_url('all', array('nickname' => $user->nickname)); $subtitle = sprintf(_('Updates from %1$s and friends on %2$s!'), $user->nickname, $sitename); - $notice = $user->noticesWithFriends(($page-1)*20, $count, $since_id, $before_id, $since); + $notice = $user->noticesWithFriends(($page-1)*20, $count, $since_id, $max_id, $since); switch($apidata['content-type']) { case 'xml': @@ -184,7 +182,7 @@ class TwitapistatusesAction extends TwitterapiAction $since = $this->arg('since'); $since_id = $this->arg('since_id'); $page = $this->arg('page'); - $before_id = $this->arg('before_id'); + $max_id = $this->arg('max_id'); if (!$page) { $page = 1; @@ -198,9 +196,8 @@ class TwitapistatusesAction extends TwitterapiAction $since_id = 0; } - // NOTE: before_id is an extensions to Twitter API -- TB - if (!$before_id) { - $before_id = 0; + if (!$max_id) { + $max_id = 0; } $since = strtotime($this->arg('since')); @@ -220,7 +217,7 @@ class TwitapistatusesAction extends TwitterapiAction # XXX: since - $notice = $user->getNotices((($page-1)*20), $count, $since_id, $before_id, $since); + $notice = $user->getNotices((($page-1)*20), $count, $since_id, $max_id, $since); switch($apidata['content-type']) { case 'xml': @@ -353,7 +350,7 @@ class TwitapistatusesAction extends TwitterapiAction $count = $this->arg('count'); $page = $this->arg('page'); $since_id = $this->arg('since_id'); - $before_id = $this->arg('before_id'); + $max_id = $this->arg('max_id'); $user = $this->get_user($apidata['api_arg'], $apidata); $this->auth_user = $apidata['user']; @@ -380,15 +377,14 @@ class TwitapistatusesAction extends TwitterapiAction $since_id = 0; } - // NOTE: before_id is an extension to Twitter API -- TB - if (!$before_id) { - $before_id = 0; + if (!$max_id) { + $max_id = 0; } $since = strtotime($this->arg('since')); $notice = $user->getReplies((($page-1)*20), - $count, $since_id, $before_id, $since); + $count, $since_id, $max_id, $since); $notices = array(); while ($notice->fetch()) { diff --git a/classes/Fave.php b/classes/Fave.php index 915b4572f..cdb479856 100644 --- a/classes/Fave.php +++ b/classes/Fave.php @@ -46,7 +46,7 @@ class Fave extends Memcached_DataObject return $ids; } - function _streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since) + function _streamDirect($user_id, $offset, $limit, $since_id, $max_id, $since) { $fav = new Fave(); @@ -59,8 +59,8 @@ class Fave extends Memcached_DataObject $fav->whereAdd('notice_id > ' . $since_id); } - if ($before_id != 0) { - $fav->whereAdd('notice_id < ' . $before_id); + if ($max_id != 0) { + $fav->whereAdd('notice_id < ' . $max_id); } if (!is_null($since)) { diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php index dec14b0d1..65d7927b7 100644 --- a/classes/Notice_inbox.php +++ b/classes/Notice_inbox.php @@ -43,15 +43,15 @@ class Notice_inbox extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - function stream($user_id, $offset, $limit, $since_id, $before_id, $since) + function stream($user_id, $offset, $limit, $since_id, $max_id, $since) { return Notice::stream(array('Notice_inbox', '_streamDirect'), array($user_id), 'notice_inbox:by_user:'.$user_id, - $offset, $limit, $since_id, $before_id, $since); + $offset, $limit, $since_id, $max_id, $since); } - function _streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since) + function _streamDirect($user_id, $offset, $limit, $since_id, $max_id, $since) { $inbox = new Notice_inbox(); @@ -61,8 +61,8 @@ class Notice_inbox extends Memcached_DataObject $inbox->whereAdd('notice_id > ' . $since_id); } - if ($before_id != 0) { - $inbox->whereAdd('notice_id < ' . $before_id); + if ($max_id != 0) { + $inbox->whereAdd('notice_id < ' . $max_id); } if (!is_null($since)) { diff --git a/classes/Notice_tag.php b/classes/Notice_tag.php index e5b772243..758a66594 100644 --- a/classes/Notice_tag.php +++ b/classes/Notice_tag.php @@ -46,7 +46,7 @@ class Notice_tag extends Memcached_DataObject return Notice::getStreamByIds($ids); } - function _streamDirect($tag, $offset, $limit, $since_id, $before_id, $since) + function _streamDirect($tag, $offset, $limit, $since_id, $max_id, $since) { $nt = new Notice_tag(); @@ -59,8 +59,8 @@ class Notice_tag extends Memcached_DataObject $nt->whereAdd('notice_id > ' . $since_id); } - if ($before_id != 0) { - $nt->whereAdd('notice_id < ' . $before_id); + if ($max_id != 0) { + $nt->whereAdd('notice_id < ' . $max_id); } if (!is_null($since)) { diff --git a/classes/Reply.php b/classes/Reply.php index 4439053b4..49b1e05e5 100644 --- a/classes/Reply.php +++ b/classes/Reply.php @@ -22,16 +22,16 @@ class Reply extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) + function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0, $since=null) { $ids = Notice::stream(array('Reply', '_streamDirect'), array($user_id), 'reply:stream:' . $user_id, - $offset, $limit, $since_id, $before_id, $since); + $offset, $limit, $since_id, $max_id, $since); return $ids; } - function _streamDirect($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) + function _streamDirect($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0, $since=null) { $reply = new Reply(); $reply->profile_id = $user_id; @@ -40,8 +40,8 @@ class Reply extends Memcached_DataObject $reply->whereAdd('notice_id > ' . $since_id); } - if ($before_id != 0) { - $reply->whereAdd('notice_id < ' . $before_id); + if ($max_id != 0) { + $reply->whereAdd('notice_id < ' . $max_id); } if (!is_null($since)) { diff --git a/classes/User_group.php b/classes/User_group.php index 7cc31e702..43591d655 100755 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -58,7 +58,7 @@ class User_group extends Memcached_DataObject return Notice::getStreamByIds($ids); } - function _streamDirect($offset, $limit, $since_id, $before_id, $since) + function _streamDirect($offset, $limit, $since_id, $max_id, $since) { $inbox = new Group_inbox(); @@ -71,8 +71,8 @@ class User_group extends Memcached_DataObject $inbox->whereAdd('notice_id > ' . $since_id); } - if ($before_id != 0) { - $inbox->whereAdd('notice_id < ' . $before_id); + if ($max_id != 0) { + $inbox->whereAdd('notice_id < ' . $max_id); } if (!is_null($since)) { -- cgit v1.2.3-54-g00ecf From 425f9d703c5258920079b268c085b0c7112c3b70 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 29 May 2009 16:54:24 -0700 Subject: Ticket #1567 - Change max_id to return notices <= ID instead of < ID --- actions/twitapidirect_messages.php | 2 +- classes/Fave.php | 2 +- classes/Notice.php | 32 ++++++++++++++++---------------- classes/Notice_inbox.php | 2 +- classes/Profile.php | 10 +++++----- classes/User_group.php | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) (limited to 'actions') diff --git a/actions/twitapidirect_messages.php b/actions/twitapidirect_messages.php index ab8f07810..d2dbdb619 100644 --- a/actions/twitapidirect_messages.php +++ b/actions/twitapidirect_messages.php @@ -75,7 +75,7 @@ class Twitapidirect_messagesAction extends TwitterapiAction } if ($max_id) { - $message->whereAdd("id < $max_id"); + $message->whereAdd("id <= $max_id"); } if ($since_id) { diff --git a/classes/Fave.php b/classes/Fave.php index cdb479856..572334ce4 100644 --- a/classes/Fave.php +++ b/classes/Fave.php @@ -60,7 +60,7 @@ class Fave extends Memcached_DataObject } if ($max_id != 0) { - $fav->whereAdd('notice_id < ' . $max_id); + $fav->whereAdd('notice_id <= ' . $max_id); } if (!is_null($since)) { diff --git a/classes/Notice.php b/classes/Notice.php index 8dd14b3b7..3f6c5cebb 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -426,22 +426,22 @@ class Notice extends Memcached_DataObject # XXX: too many args; we need to move to named params or even a separate # class for notice streams - static function getStream($qry, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $order=null, $since=null) { + static function getStream($qry, $cachekey, $offset=0, $limit=20, $since_id=0, $max_id=0, $order=null, $since=null) { if (common_config('memcached', 'enabled')) { - # Skip the cache if this is a since, since_id or before_id qry - if ($since_id > 0 || $before_id > 0 || $since) { - return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since); + # Skip the cache if this is a since, since_id or max_id qry + if ($since_id > 0 || $max_id > 0 || $since) { + return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $max_id, $order, $since); } else { return Notice::getCachedStream($qry, $cachekey, $offset, $limit, $order); } } - return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since); + return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $max_id, $order, $since); } - static function getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since) { + static function getStreamDirect($qry, $offset, $limit, $since_id, $max_id, $order, $since) { $needAnd = false; $needWhere = true; @@ -463,7 +463,7 @@ class Notice extends Memcached_DataObject $qry .= ' notice.id > ' . $since_id; } - if ($before_id > 0) { + if ($max_id > 0) { if ($needWhere) { $qry .= ' WHERE '; @@ -472,7 +472,7 @@ class Notice extends Memcached_DataObject $qry .= ' AND '; } - $qry .= ' notice.id < ' . $before_id; + $qry .= ' notice.id <= ' . $max_id; } if ($since) { @@ -630,17 +630,17 @@ class Notice extends Memcached_DataObject } } - function publicStream($offset=0, $limit=20, $since_id=0, $before_id=0, $since=null) + function publicStream($offset=0, $limit=20, $since_id=0, $max_id=0, $since=null) { $ids = Notice::stream(array('Notice', '_publicStreamDirect'), array(), 'public', - $offset, $limit, $since_id, $before_id, $since); + $offset, $limit, $since_id, $max_id, $since); return Notice::getStreamByIds($ids); } - function _publicStreamDirect($offset=0, $limit=20, $since_id=0, $before_id=0, $since=null) + function _publicStreamDirect($offset=0, $limit=20, $since_id=0, $max_id=0, $since=null) { $notice = new Notice(); @@ -664,8 +664,8 @@ class Notice extends Memcached_DataObject $notice->whereAdd('id > ' . $since_id); } - if ($before_id != 0) { - $notice->whereAdd('id < ' . $before_id); + if ($max_id != 0) { + $notice->whereAdd('id <= ' . $max_id); } if (!is_null($since)) { @@ -998,15 +998,15 @@ class Notice extends Memcached_DataObject } } - function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $since=null) + function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $max_id=0, $since=null) { $cache = common_memcache(); if (empty($cache) || - $since_id != 0 || $before_id != 0 || !is_null($since) || + $since_id != 0 || $max_id != 0 || !is_null($since) || ($offset + $limit) > NOTICE_CACHE_WINDOW) { return call_user_func_array($fn, array_merge($args, array($offset, $limit, $since_id, - $before_id, $since))); + $max_id, $since))); } $idkey = common_cache_key($cachekey); diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php index 65d7927b7..8a27e1747 100644 --- a/classes/Notice_inbox.php +++ b/classes/Notice_inbox.php @@ -62,7 +62,7 @@ class Notice_inbox extends Memcached_DataObject } if ($max_id != 0) { - $inbox->whereAdd('notice_id < ' . $max_id); + $inbox->whereAdd('notice_id <= ' . $max_id); } if (!is_null($since)) { diff --git a/classes/Profile.php b/classes/Profile.php index ae5641d79..3d13cd46a 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -153,18 +153,18 @@ class Profile extends Memcached_DataObject return null; } - function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) + function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0) { // XXX: I'm not sure this is going to be any faster. It probably isn't. $ids = Notice::stream(array($this, '_streamDirect'), array(), 'profile:notice_ids:' . $this->id, - $offset, $limit, $since_id, $before_id); + $offset, $limit, $since_id, $max_id); return Notice::getStreamByIds($ids); } - function _streamDirect($offset, $limit, $since_id, $before_id, $since) + function _streamDirect($offset, $limit, $since_id, $max_id, $since) { $notice = new Notice(); @@ -177,8 +177,8 @@ class Profile extends Memcached_DataObject $notice->whereAdd('id > ' . $since_id); } - if ($before_id != 0) { - $notice->whereAdd('id < ' . $before_id); + if ($max_id != 0) { + $notice->whereAdd('id <= ' . $max_id); } if (!is_null($since)) { diff --git a/classes/User_group.php b/classes/User_group.php index 43591d655..a135015ba 100755 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -72,7 +72,7 @@ class User_group extends Memcached_DataObject } if ($max_id != 0) { - $inbox->whereAdd('notice_id < ' . $max_id); + $inbox->whereAdd('notice_id <= ' . $max_id); } if (!is_null($since)) { -- cgit v1.2.3-54-g00ecf From 78f8b91a13ee07ed3344fd6411a0829a16bef4b1 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 29 May 2009 19:23:53 -0700 Subject: Ticket #1568 - API should return full user objects --- actions/twitapiusers.php | 145 ++++++++++++++++------------------------------- lib/twitterapi.php | 77 ++++++++++++++++++++++--- 2 files changed, 117 insertions(+), 105 deletions(-) (limited to 'actions') diff --git a/actions/twitapiusers.php b/actions/twitapiusers.php index 1542cfb33..b90bbfa98 100644 --- a/actions/twitapiusers.php +++ b/actions/twitapiusers.php @@ -25,110 +25,61 @@ class TwitapiusersAction extends TwitterapiAction { function show($args, $apidata) - { + { parent::handle($args); - if (!in_array($apidata['content-type'], array('xml', 'json'))) { + if (!in_array($apidata['content-type'], array('xml', 'json'))) { $this->clientError(_('API method not found!'), $code = 404); return; } - - $user = null; - $email = $this->arg('email'); - $user_id = $this->arg('user_id'); - - if ($email) { - $user = User::staticGet('email', $email); - } elseif ($user_id) { - $user = $this->get_user($user_id); - } elseif (isset($apidata['api_arg'])) { - $user = $this->get_user($apidata['api_arg']); - } elseif (isset($apidata['user'])) { - $user = $apidata['user']; - } - - if (!$user) { - // XXX: Twitter returns a random(?) user instead of throwing and err! -- Zach - $this->client_error(_('Not found.'), 404, $apidata['content-type']); - return; - } - - $profile = $user->getProfile(); - - if (!$profile) { - common_server_error(_('User has no profile.')); - return; - } - - $twitter_user = $this->twitter_user_array($profile, true); - - // Add in extended user fields offered up by this method - $twitter_user['created_at'] = $this->date_twitter($profile->created); - - $subbed = DB_DataObject::factory('subscription'); - $subbed->subscriber = $profile->id; - $subbed_count = (int) $subbed->count() - 1; - - $notices = DB_DataObject::factory('notice'); - $notices->profile_id = $profile->id; - $notice_count = (int) $notices->count(); - - $twitter_user['friends_count'] = (is_int($subbed_count)) ? $subbed_count : 0; - $twitter_user['statuses_count'] = (is_int($notice_count)) ? $notice_count : 0; - - // Other fields Twitter sends... - $twitter_user['profile_background_color'] = ''; - $twitter_user['profile_background_image_url'] = ''; - $twitter_user['profile_text_color'] = ''; - $twitter_user['profile_link_color'] = ''; - $twitter_user['profile_sidebar_fill_color'] = ''; - $twitter_user['profile_sidebar_border_color'] = ''; - $twitter_user['profile_background_tile'] = false; - - $faves = DB_DataObject::factory('fave'); - $faves->user_id = $user->id; - $faves_count = (int) $faves->count(); - $twitter_user['favourites_count'] = $faves_count; - - $timezone = 'UTC'; - - if ($user->timezone) { - $timezone = $user->timezone; - } - - $t = new DateTime; - $t->setTimezone(new DateTimeZone($timezone)); - $twitter_user['utc_offset'] = $t->format('Z'); - $twitter_user['time_zone'] = $timezone; - - if (isset($apidata['user'])) { - - $twitter_user['following'] = $apidata['user']->isSubscribed($profile); - - // Notifications on? - $sub = Subscription::pkeyGet(array('subscriber' => - $apidata['user']->id, 'subscribed' => $profile->id)); - - if ($sub) { - $twitter_user['notifications'] = ($sub->jabber || $sub->sms); - } - } - - if ($apidata['content-type'] == 'xml') { - $this->init_document('xml'); - $this->show_twitter_xml_user($twitter_user); - $this->end_document('xml'); - } elseif ($apidata['content-type'] == 'json') { - $this->init_document('json'); - $this->show_json_objects($twitter_user); - $this->end_document('json'); - } else { - - // This is in case 'show' was called via /account/verify_credentials - // without a format (xml or json). + + $user = null; + $email = $this->arg('email'); + $user_id = $this->arg('user_id'); + + // XXX: email field deprecated in Twitter's API + + // XXX: Also: need to add screen_name param + + if ($email) { + $user = User::staticGet('email', $email); + } elseif ($user_id) { + $user = $this->get_user($user_id); + } elseif (isset($apidata['api_arg'])) { + $user = $this->get_user($apidata['api_arg']); + } elseif (isset($apidata['user'])) { + $user = $apidata['user']; + } + + if (!$user) { + $this->client_error(_('Not found.'), 404, $apidata['content-type']); + return; + } + + $profile = $user->getProfile(); + + if (!$profile) { + common_server_error(_('User has no profile.')); + return; + } + + $twitter_user = $this->twitter_user_array($profile, true); + + if ($apidata['content-type'] == 'xml') { + $this->init_document('xml'); + $this->show_twitter_xml_user($twitter_user); + $this->end_document('xml'); + } elseif ($apidata['content-type'] == 'json') { + $this->init_document('json'); + $this->show_json_objects($twitter_user); + $this->end_document('json'); + } else { + + // This is in case 'show' was called via /account/verify_credentials + // without a format (xml or json). header('Content-Type: text/html; charset=utf-8'); print 'Authorized'; } - } + } } diff --git a/lib/twitterapi.php b/lib/twitterapi.php index caf8c0716..1d527b935 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -54,7 +54,7 @@ class TwitterapiAction extends Action /** * Overrides XMLOutputter::element to write booleans as strings (true|false). * See that method's documentation for more info. - * + * * @param string $tag Element type or tagname * @param array $attrs Array of element attributes, as * key-value pairs @@ -70,24 +70,85 @@ class TwitterapiAction extends Action return parent::element($tag, $attrs, $content); } - + function twitter_user_array($profile, $get_notice=false) { - $twitter_user = array(); + $twitter_user['id'] = intval($profile->id); $twitter_user['name'] = $profile->getBestName(); - $twitter_user['followers_count'] = $this->count_subscriptions($profile); $twitter_user['screen_name'] = $profile->nickname; - $twitter_user['description'] = ($profile->bio) ? $profile->bio : null; $twitter_user['location'] = ($profile->location) ? $profile->location : null; - $twitter_user['id'] = intval($profile->id); + $twitter_user['description'] = ($profile->bio) ? $profile->bio : null; $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); + $twitter_user['profile_image_url'] = ($avatar) ? $avatar->displayUrl() : + Avatar::defaultImage(AVATAR_STREAM_SIZE); - $twitter_user['profile_image_url'] = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE); - $twitter_user['protected'] = false; # not supported by Laconica yet $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : null; + $twitter_user['protected'] = false; # not supported by Laconica yet + $twitter_user['followers_count'] = $this->count_subscriptions($profile); + + // To be supported soon... + $twitter_user['profile_background_color'] = ''; + $twitter_user['profile_text_color'] = ''; + $twitter_user['profile_link_color'] = ''; + $twitter_user['profile_sidebar_fill_color'] = ''; + $twitter_user['profile_sidebar_border_color'] = ''; + + $subbed = DB_DataObject::factory('subscription'); + $subbed->subscriber = $profile->id; + $subbed_count = (int) $subbed->count() - 1; + $twitter_user['friends_count'] = (is_int($subbed_count)) ? $subbed_count : 0; + + $twitter_user['created_at'] = $this->date_twitter($profile->created); + + $faves = DB_DataObject::factory('fave'); + $faves->user_id = $user->id; + $faves_count = (int) $faves->count(); + $twitter_user['favourites_count'] = $faves_count; // British spelling! + + // Need to pull up the user for some of this + $user = User::staticGet($profile->id); + + $timezone = 'UTC'; + + if ($user->timezone) { + $timezone = $user->timezone; + } + + $t = new DateTime; + $t->setTimezone(new DateTimeZone($timezone)); + + $twitter_user['utc_offset'] = $t->format('Z'); + $twitter_user['time_zone'] = $timezone; + + // To be supported some day, perhaps + $twitter_user['profile_background_image_url'] = ''; + $twitter_user['profile_background_tile'] = false; + + $notices = DB_DataObject::factory('notice'); + $notices->profile_id = $profile->id; + $notice_count = (int) $notices->count(); + + $twitter_user['statuses_count'] = (is_int($notice_count)) ? $notice_count : 0; + + // Is the requesting user following this user? + $twitter_user['following'] = false; + $twitter_user['notifications'] = false; + + if (isset($apidata['user'])) { + + $twitter_user['following'] = $apidata['user']->isSubscribed($profile); + + // Notifications on? + $sub = Subscription::pkeyGet(array('subscriber' => + $apidata['user']->id, 'subscribed' => $profile->id)); + + if ($sub) { + $twitter_user['notifications'] = ($sub->jabber || $sub->sms); + } + } if ($get_notice) { $notice = $profile->getCurrentNotice(); -- cgit v1.2.3-54-g00ecf From 791f5defaf07372de6453ac7903a9a32611b0284 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 29 May 2009 20:23:32 -0700 Subject: Ticket #1572 - Implement Twitter's account/rate_limit_status API method We don't have a rate limit (yet) but some clients check this method. This dummy implementation always says the auth user has 100 requests left. --- actions/twitapiaccount.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'actions') diff --git a/actions/twitapiaccount.php b/actions/twitapiaccount.php index 68a18cb57..8b956f897 100644 --- a/actions/twitapiaccount.php +++ b/actions/twitapiaccount.php @@ -98,9 +98,31 @@ class TwitapiaccountAction extends TwitterapiAction $this->serverError(_('API method under construction.'), $code=501); } + // We don't have a rate limit, but some clients check this method. + // It always returns the same thing: 100 hit left. function rate_limit_status($args, $apidata) { parent::handle($args); - $this->serverError(_('API method under construction.'), $code=501); + + $type = $apidata['content-type']; + $this->init_document($type); + + if ($apidata['content-type'] == 'xml') { + $this->elementStart('hash'); + $this->element('remaining-hits', array('type' => 'integer'), 100); + $this->element('hourly-limit', array('type' => 'integer'), 100); + $this->element('reset-time', array('type' => 'datetime'), null); + $this->element('reset_time_in_seconds', array('type' => 'integer'), 0); + $this->elementEnd('hash'); + } elseif ($apidata['content-type'] == 'json') { + + $out = array('reset_time_in_seconds' => 0, + 'remaining_hits' => 100, + 'hourly_limit' => 100, + 'reset_time' => ''); + print json_encode($out); + } + + $this->end_document($type); } } -- cgit v1.2.3-54-g00ecf From 4ec1c333073fd693147ff34895cf7e3664f83cf6 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 30 May 2009 21:45:11 -0400 Subject: correct last-modified date for shownotice.php --- actions/shownotice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actions') diff --git a/actions/shownotice.php b/actions/shownotice.php index 2c469c9de..1be1e2414 100644 --- a/actions/shownotice.php +++ b/actions/shownotice.php @@ -122,7 +122,7 @@ class ShownoticeAction extends Action function lastModified() { - return max(strtotime($this->notice->created), + return max(strtotime($this->notice->modified), strtotime($this->profile->modified), ($this->avatar) ? strtotime($this->avatar->modified) : 0); } -- cgit v1.2.3-54-g00ecf From 6658e2a2ee9517bebd59cf69d7483e6eda691b4e Mon Sep 17 00:00:00 2001 From: Dan Moore Date: Thu, 4 Jun 2009 17:57:03 -0400 Subject: Handle the ways Twitter accepts passing the user in the query string. --- actions/api.php | 4 ++-- lib/twitterapi.php | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'actions') diff --git a/actions/api.php b/actions/api.php index b25ba99f3..b8da852b5 100644 --- a/actions/api.php +++ b/actions/api.php @@ -144,8 +144,8 @@ class ApiAction extends Action } if (in_array($fullname, $bareauth)) { - # bareauth: only needs auth if without an argument - if ($this->api_arg) { + # bareauth: only needs auth if without an argument or query param specifying user + if ($this->api_arg || $this->arg('id') || is_numeric($this->arg('user_id')) || $this->arg('screen_name')) { return false; } else { return true; diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 1d527b935..ca8b03cdc 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -673,7 +673,27 @@ class TwitterapiAction extends Action function get_user($id, $apidata=null) { if (!$id) { - return $apidata['user']; + + // Twitter supports these other ways of passing the user ID + if (is_numeric($this->arg('id'))) { + return User::staticGet($this->arg('id')); + } else if ($this->arg('id')) { + $nickname = common_canonical_nickname($this->arg('id')); + return User::staticGet('nickname', $nickname); + } else if ($this->arg('user_id')) { + // This is to ensure that a non-numeric user_id still + // overrides screen_name even if it doesn't get used + if (is_numeric($this->arg('user_id'))) { + return User::staticGet('id', $this->arg('user_id')); + } + } else if ($this->arg('screen_name')) { + $nickname = common_canonical_nickname($this->arg('screen_name')); + return User::staticGet('nickname', $nickname); + } else { + // Fall back to trying the currently authenticated user + return $apidata['user']; + } + } else if (is_numeric($id)) { return User::staticGet($id); } else { -- cgit v1.2.3-54-g00ecf