From 92ea88fd6030b3def92e100291102187be032490 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 9 Dec 2008 00:53:45 -0500 Subject: trac540 - Add 'since' param to Twitter-compatible API calls darcs-hash:20081209055345-7b5ce-e48fd4c87963b8ae15859fd03d2f1f86a16f3a2b.gz --- actions/twitapidirect_messages.php | 20 ++++++- actions/twitapistatuses.php | 118 +++++++++++++++++++++---------------- 2 files changed, 85 insertions(+), 53 deletions(-) (limited to 'actions') diff --git a/actions/twitapidirect_messages.php b/actions/twitapidirect_messages.php index a14a9e567..535795ca4 100644 --- a/actions/twitapidirect_messages.php +++ b/actions/twitapidirect_messages.php @@ -40,6 +40,8 @@ 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'); + $page = $this->arg('page'); if (!$page) { @@ -69,6 +71,21 @@ class Twitapidirect_messagesAction extends TwitterapiAction { $link = $server . $user->nickname . '/outbox'; } + if ($before_id) { + $message->whereAdd("id < $before_id"); + } + + if ($since_id) { + $message->whereAdd("id > $since_id"); + } + + $since = strtotime($this->arg('since')); + + if ($since) { + $d = date('Y-m-d H:i:s', $since); + $message->whereAdd("created > '$d'"); + } + $message->orderBy('created DESC, id DESC'); $message->limit((($page-1)*20), $count); $message->find(); @@ -102,7 +119,7 @@ class Twitapidirect_messagesAction extends TwitterapiAction { } $user = $apidata['user']; - $source = $this->trimmed('source'); // Not supported by Twitter. + $source = $this->trimmed('source'); // Not supported by Twitter. $reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api'); if (!$source || in_array($source, $reserved_sources)) { @@ -113,7 +130,6 @@ class Twitapidirect_messagesAction extends TwitterapiAction { if (!$content) { $this->client_error(_('No message text!'), $code = 406, $apidata['content-type']); -// } else if (mb_strlen($status) > 140) { } else { $content_shortened = common_shorten_links($content); if (mb_strlen($content_shortened) > 140) { diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index 947d21032..e17f23aea 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -39,22 +39,24 @@ class TwitapistatusesAction extends TwitterapiAction { // 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 - $page = $this->arg('page'); - $since_id = $this->arg('since_id'); - $before_id = $this->arg('before_id'); + $page = $this->arg('page'); + $since_id = $this->arg('since_id'); + $before_id = $this->arg('before_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; - } - - $notice = Notice::publicStream((($page-1)*$MAX_PUBSTATUSES), $MAX_PUBSTATUSES, $since_id, $before_id); + if (!$page) { + $page = 1; + } + if (!$since_id) { + $since_id = 0; + } + if (!$before_id) { + $before_id = 0; + } + + $since = strtotime($this->arg('since')); + + $notice = Notice::publicStream((($page-1)*$MAX_PUBSTATUSES), $MAX_PUBSTATUSES, $since_id, $before_id, $since); if ($notice) { @@ -88,25 +90,27 @@ class TwitapistatusesAction extends TwitterapiAction { $since = $this->arg('since'); $since_id = $this->arg('since_id'); $count = $this->arg('count'); - $page = $this->arg('page'); - $before_id = $this->arg('before_id'); + $page = $this->arg('page'); + $before_id = $this->arg('before_id'); - if (!$page) { - $page = 1; - } + if (!$page) { + $page = 1; + } if (!$count) { $count = 20; } - if (!$since_id) { - $since_id = 0; - } + if (!$since_id) { + $since_id = 0; + } // NOTE: before_id is an extension to Twitter API -- TB - if (!$before_id) { - $before_id = 0; - } + if (!$before_id) { + $before_id = 0; + } + + $since = strtotime($this->arg('since')); $user = $this->get_user($id, $apidata); $this->auth_user = $user; @@ -121,7 +125,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); + $notice = $user->noticesWithFriends(($page-1)*20, $count, $since_id, $before_id, $since); switch($apidata['content-type']) { case 'xml': @@ -162,9 +166,9 @@ class TwitapistatusesAction extends TwitterapiAction { $count = $this->arg('count'); $since = $this->arg('since'); - $since_id = $this->arg('since_id'); + $since_id = $this->arg('since_id'); $page = $this->arg('page'); - $before_id = $this->arg('before_id'); + $before_id = $this->arg('before_id'); if (!$page) { $page = 1; @@ -174,14 +178,16 @@ class TwitapistatusesAction extends TwitterapiAction { $count = 20; } - if (!$since_id) { - $since_id = 0; - } + if (!$since_id) { + $since_id = 0; + } // NOTE: before_id is an extensions to Twitter API -- TB - if (!$before_id) { - $before_id = 0; - } + if (!$before_id) { + $before_id = 0; + } + + $since = strtotime($this->arg('since')); $sitename = common_config('site', 'name'); $siteserver = common_config('site', 'server'); @@ -199,7 +205,7 @@ class TwitapistatusesAction extends TwitterapiAction { # XXX: since - $notice = $user->getNotices((($page-1)*20), $count, $since_id, $before_id); + $notice = $user->getNotices((($page-1)*20), $count, $since_id, $before_id, $since); switch($apidata['content-type']) { case 'xml': @@ -248,24 +254,23 @@ class TwitapistatusesAction extends TwitterapiAction { // 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 + // user's timeline. Seems bad. Shouldn't we throw an // errror? -- Zach return; -// } else if (mb_strlen($status) > 140) { } else { - + $status_shortened = common_shorten_links($status); if (mb_strlen($status_shortened) > 140) { // 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 + // as "truncated." Sending this error may screw up some clients + // that assume Twitter will truncate for them. Should we just + // truncate too? -- Zach $this->client_error(_('That\'s too long. Max notice size is 140 chars.'), $code = 406, $apidata['content-type']); return; - + } } @@ -323,8 +328,8 @@ class TwitapistatusesAction extends TwitterapiAction { $since = $this->arg('since'); $count = $this->arg('count'); $page = $this->arg('page'); - $since_id = $this->arg('since_id'); - $before_id = $this->arg('before_id'); + $since_id = $this->arg('since_id'); + $before_id = $this->arg('before_id'); $this->auth_user = $apidata['user']; $user = $this->auth_user; @@ -346,15 +351,18 @@ class TwitapistatusesAction extends TwitterapiAction { $count = 20; } - if (!$since_id) { - $since_id = 0; - } + if (!$since_id) { + $since_id = 0; + } // NOTE: before_id is an extension to Twitter API -- TB - if (!$before_id) { - $before_id = 0; - } - $notice = $user->getReplies((($page-1)*20), $count, $since_id, $before_id); + if (!$before_id) { + $before_id = 0; + } + + $since = strtotime($this->arg('since')); + + $notice = $user->getReplies((($page-1)*20), $count, $since_id, $before_id, $since); $notices = array(); while ($notice->fetch()) { @@ -487,6 +495,14 @@ class TwitapistatusesAction extends TwitterapiAction { $sub = new Subscription(); $sub->$user_attr = $profile->id; + + $since = strtotime($this->trimmed('since')); + + if ($since) { + $d = date('Y-m-d H:i:s', $since); + $sub->whereAdd("created > '$d'"); + } + $sub->orderBy('created DESC'); $sub->limit(($page-1)*100, 100); -- cgit v1.2.3-54-g00ecf