add friend statuses, refactor output functions

darcs-hash:20080717210519-84dde-4a2e4caa23d793e74208dcf5c21221e4166366f2.gz
This commit is contained in:
Evan Prodromou 2008-07-17 17:05:19 -04:00
parent b5659ed85a
commit bbc1b747f8

View File

@ -30,6 +30,13 @@ class TwitapistatusesAction extends TwitterapiAction {
function public_timeline($args, $apidata) { function public_timeline($args, $apidata) {
parent::handle($args); parent::handle($args);
$sitename = common_config('site', 'name');
$siteserver = common_config('site', 'server');
$title = sprintf(_("%s public timeline"), $sitename);
$id = "tag:$siteserver:Statuses";
$link = common_root_url();
$subtitle = sprintf(_("%s updates from everyone!"));
// Number of public statuses to return by default -- Twitter sends 20 // Number of public statuses to return by default -- Twitter sends 20
$MAX_PUBSTATUSES = 20; $MAX_PUBSTATUSES = 20;
@ -48,16 +55,16 @@ class TwitapistatusesAction extends TwitterapiAction {
switch($apidata['content-type']) { switch($apidata['content-type']) {
case 'xml': case 'xml':
$this->show_xml_public_timeline($notice); $this->show_xml_timeline($notice);
break; break;
case 'rss': case 'rss':
$this->show_rss_public_timeline($notice); $this->show_rss_timeline($notice, $title, $id, $link, $subtitle);
break; break;
case 'atom': case 'atom':
$this->show_atom_public_timeline($notice); $this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
break; break;
case 'json': case 'json':
$this->show_json_public_timeline($notice); $this->show_json_timeline($notice);
break; break;
default: default:
common_user_error("API method not found!", $code = 404); common_user_error("API method not found!", $code = 404);
@ -71,7 +78,7 @@ class TwitapistatusesAction extends TwitterapiAction {
exit(); exit();
} }
function show_xml_public_timeline($notice) { function show_xml_timeline($notice) {
header('Content-Type: application/xml; charset=utf-8'); header('Content-Type: application/xml; charset=utf-8');
common_start_xml(); common_start_xml();
@ -86,17 +93,16 @@ class TwitapistatusesAction extends TwitterapiAction {
common_end_xml(); common_end_xml();
} }
function show_rss_public_timeline($notice) { function show_rss_timeline($notice, $title, $id, $link, $subtitle) {
header("Content-Type: application/rss+xml; charset=utf-8"); header("Content-Type: application/rss+xml; charset=utf-8");
$this->init_twitter_rss(); $this->init_twitter_rss();
$sitename = common_config('site', 'name');
$siteserver = common_config('site', 'server');
common_element_start('channel'); common_element_start('channel');
common_element('title', NULL, "$sitename public timeline"); common_element('title', NULL, $title);
common_element('link', NULL, "http://$siteserver"); common_element('link', NULL, $link);
common_element('description', NULL, "$sitename updates from everyone!"); common_element('description', NULL, $subtitle);
common_element('language', NULL, 'en-us'); common_element('language', NULL, 'en-us');
common_element('ttl', NULL, '40'); common_element('ttl', NULL, '40');
@ -109,18 +115,16 @@ class TwitapistatusesAction extends TwitterapiAction {
$this->end_twitter_rss(); $this->end_twitter_rss();
} }
function show_atom_public_timeline($notice) { function show_atom_timeline($notice, $title, $id, $link, $subtitle=NULL) {
header('Content-Type: application/atom+xml; charset=utf-8'); header('Content-Type: application/atom+xml; charset=utf-8');
$this->init_twitter_atom(); $this->init_twitter_atom();
$sitename = common_config('site', 'name');
$siteserver = common_config('site', 'server');
common_element('title', NULL, "$sitename public timeline"); common_element('title', NULL, $title);
common_element('id', NULL, "tag:$siteserver:Statuses"); common_element('id', NULL, $id);
common_element('link', array('href' => "http://$siteserver", 'rel' => 'alternate', 'type' => 'text/html'), NULL); common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL);
common_element('subtitle', NULL, "$sitename updates from everyone!"); common_element('subtitle', NULL, $subtitle);
while ($notice->fetch()) { while ($notice->fetch()) {
$entry = $this->twitter_rss_entry_array($notice); $entry = $this->twitter_rss_entry_array($notice);
@ -130,7 +134,7 @@ class TwitapistatusesAction extends TwitterapiAction {
$this->end_twitter_atom(); $this->end_twitter_atom();
} }
function show_json_public_timeline($notice) { function show_json_timeline($notice) {
header('Content-Type: application/json; charset=utf-8'); header('Content-Type: application/json; charset=utf-8');
@ -172,11 +176,59 @@ class TwitapistatusesAction extends TwitterapiAction {
$count = $this->arg('count'); $count = $this->arg('count');
$page = $this->arg('page'); $page = $this->arg('page');
print "Friends Timeline! requested content-type: " . $apidata['content-type'] . "\n"; if (!$page) {
print "since: $since, since_id: $since_id, count: $count, page: $page\n"; $page = 1;
}
if (!$count) {
$count = 20;
}
$user = $apidata['user'];
$profile = $user->getProfile();
$sitename = common_config('site', 'name');
$siteserver = common_config('site', 'server');
$title = sprintf(_("%s and friends"), $user->nickname);
$id = "tag:$siteserver:friends:".$user->id;
$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();
switch($apidata['content-type']) {
case 'xml':
$this->show_xml_timeline($notice);
break;
case 'rss':
$this->show_rss_timeline($notice, $title, $id, $link, $subtitle);
break;
case 'atom':
$this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
break;
case 'json':
$this->show_json_timeline($notice);
break;
default:
common_user_error("API method not found!", $code = 404);
}
exit(); exit();
} }
/* /*