From 296f1b0123edd89b40b48362ffd19134499ef9f3 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Tue, 21 Jun 2011 11:41:16 +0200 Subject: [PATCH 1/3] add users infos to rss and atom api responses --- include/api.php | 44 +++++++----- view/api_timeline_atom.tpl | 135 ++++++++++++++++++++++++++++++------- view/api_timeline_rss.tpl | 9 ++- 3 files changed, 144 insertions(+), 44 deletions(-) diff --git a/include/api.php b/include/api.php index cab1431d3..e5c1e5529 100644 --- a/include/api.php +++ b/include/api.php @@ -137,7 +137,7 @@ return ''."\n".$r; break; case "atom": - #header ("Content-Type: application/atom+xml"); + header ("Content-Type: application/atom+xml"); return ''."\n".$r; break; @@ -153,6 +153,7 @@ */ function api_rss_extra(&$a, $arr, $user_info){ if (is_null($user_info)) $user_info = api_get_user($a); + $arr['$user'] = $user_info; $arr['$rss'] = array( 'alternate' => $user_info['url'], 'self' => $a->get_baseurl(). "/". $a->query_string, @@ -167,19 +168,24 @@ /** * Returns user info array. */ - function api_get_user(&$a){ + function api_get_user(&$a, $contact_id=Null){ $user = null; $extra_query = ""; - if(x($_GET, 'user_id')) { + if(!is_null($contact_id)){ + $user=$contact_id; + $extra_query = "AND `contact`.`id` = %d "; + } + + if(is_null($user) && x($_GET, 'user_id')) { $user = intval($_GET['user_id']); $extra_query = "AND `contact`.`id` = %d "; } - if(x($_GET, 'screen_name')) { + if(is_null($user) && x($_GET, 'screen_name')) { $user = dbesc($_GET['screen_name']); $extra_query = "AND `contact`.`nick` = '%s' "; } - if ($user===null){ + if (is_null($user)){ list($user, $null) = explode(".",$a->argv[3]); if(is_numeric($user)){ $user = intval($user); @@ -195,15 +201,15 @@ api_login($a); return False; } else { $user = $_SESSION['uid']; - $extra_query = "AND `user`.`uid` = %d "; + $extra_query = "AND `contact`.`uid` = %d "; } } // user info - $uinfo = q("SELECT *, `contact`.`id` as `cid` FROM `user`, `contact` - WHERE `user`.`uid`=`contact`.`uid` AND `contact`.`self`=1 + $uinfo = q("SELECT *, `contact`.`id` as `cid` FROM `contact` + WHERE 1 $extra_query", $user ); @@ -230,17 +236,18 @@ $ret = Array( + 'uid' => $uinfo[0]['uid'], 'id' => $uinfo[0]['cid'], - 'name' => $uinfo[0]['username'], - 'screen_name' => $uinfo[0]['nickname'], - 'location' => $uinfo[0]['default-location'], + 'name' => $uinfo[0]['name'], + 'screen_name' => $uinfo[0]['nick'], + 'location' => '', //$uinfo[0]['default-location'], 'profile_image_url' => $uinfo[0]['micro'], 'url' => $uinfo[0]['url'], 'protected' => false, # 'friends_count' => $countfriends, - 'created_at' => api_date($uinfo[0]['created']), + 'created_at' => api_date($uinfo[0]['name-date']), 'utc_offset' => 0, #XXX: fix me - 'time_zone' => $uinfo[0]['timezone'], + 'time_zone' => '', //$uinfo[0]['timezone'], 'geo_enabled' => false, 'statuses_count' => $countitms, #XXX: fix me 'lang' => 'en', #XXX: fix me @@ -464,7 +471,6 @@ if (local_user()===false) return false; $user_info = api_get_user($a); - // get last newtork messages $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) "; @@ -472,19 +478,20 @@ `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM `item`, `contact`, `user` - WHERE `item`.`contact-id` = %d AND `user`.`uid` = `item`.`uid` + FROM `item`, `contact` + WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `contact`.`id` = `item`.`contact-id` AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 $sql_extra ORDER BY `item`.`created` DESC LIMIT %d ,%d ", - intval($user_info['id']), + intval($user_info['uid']), 0,20 ); $ret = Array(); foreach($r as $item) { + $status_user = (($item['cid']==$user_info['id'])?$user_info: api_get_user($a,$item['cid'])); $status = array( 'created_at'=> api_date($item['created']), 'published' => datetime_convert('UTC','UTC',$item['created'],ATOM_TIME), @@ -505,9 +512,10 @@ 'contributors' => '', 'annotations' => '', 'entities' => '', - 'user' => $user_info, + 'user' => $status_user , 'objecttype' => $item['object-type'], 'verb' => $item['verb'], + 'conversation' => $a->get_baseurl() . '/display/' . $status_user['screen_name'] . '/' . $item['id'], 'self' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type, 'edit' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type, ); diff --git a/view/api_timeline_atom.tpl b/view/api_timeline_atom.tpl index bc677d237..cd91f7a97 100644 --- a/view/api_timeline_atom.tpl +++ b/view/api_timeline_atom.tpl @@ -7,33 +7,120 @@ $rss.updated + + + + http://activitystrea.ms/schema/1.0/person + $user.url + $user.name + + + + + + + $user.screen_name + $user.name + + homepage + $user.url + true + + + + + + + http://activitystrea.ms/schema/1.0/person + $user.url + $user.name + + + + + + $user.screen_name + $user.name + + homepage + $user.url + true + + + + + {{ for $statuses as $status }} - $status.objecttype - $status.id - $status.text - $status.html - - $status.verb - $status.published - $status.updated + $status.objecttype + $status.id + $status.text + $status.html + + $status.verb + $status.published + $status.updated + + + + + + + + + + http://activitystrea.ms/schema/1.0/person + $status.user.url + $status.user.name + + + + + + + $status.user.screen_name + $status.user.name + + + homepage + $status.user.url + true + + + + + + http://activitystrea.ms/schema/1.0/person + $status.user.url + $status.user.name + + + + + + + $status.user.screen_name + $status.user.name + + + homepage + $status.user.url + true + + + + - - - - - - {{ endfor }} diff --git a/view/api_timeline_rss.tpl b/view/api_timeline_rss.tpl index fbba93ee9..40239273c 100644 --- a/view/api_timeline_rss.tpl +++ b/view/api_timeline_rss.tpl @@ -6,10 +6,15 @@ Friendika timeline $rss.language 40 - + + $user.link + $user.name's items + $user.profile_image_url + + {{ for $statuses as $status }} - $status.text + $status.user.name: $status.text $status.text $status.created_at $status.url From 7cd7a79807c766da0ac39192559081f771b58a1d Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Tue, 21 Jun 2011 11:44:26 +0200 Subject: [PATCH 2/3] remove duplicate tag in atom response --- include/api.php | 1 - view/api_timeline_atom.tpl | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/api.php b/include/api.php index e5c1e5529..556bc0622 100644 --- a/include/api.php +++ b/include/api.php @@ -515,7 +515,6 @@ 'user' => $status_user , 'objecttype' => $item['object-type'], 'verb' => $item['verb'], - 'conversation' => $a->get_baseurl() . '/display/' . $status_user['screen_name'] . '/' . $item['id'], 'self' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type, 'edit' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type, ); diff --git a/view/api_timeline_atom.tpl b/view/api_timeline_atom.tpl index cd91f7a97..f9c70ebb5 100644 --- a/view/api_timeline_atom.tpl +++ b/view/api_timeline_atom.tpl @@ -61,7 +61,6 @@ $status.published $status.updated - - + {{ endfor }} From 655f5c7b9fe138de5566047e79ada034647fd6f2 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Tue, 21 Jun 2011 12:00:52 +0200 Subject: [PATCH 3/3] use "contacts/" url as subject id, as statusnet and twitter use urls like "domain/". This seem to make StatusNet Desktop client work better. --- include/api.php | 1 + view/api_timeline_atom.tpl | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/api.php b/include/api.php index 556bc0622..4e5ea43bd 100644 --- a/include/api.php +++ b/include/api.php @@ -243,6 +243,7 @@ 'location' => '', //$uinfo[0]['default-location'], 'profile_image_url' => $uinfo[0]['micro'], 'url' => $uinfo[0]['url'], + 'contact_url' => $a->get_baseurl()."/contacts/".$uinfo[0]['cid'], 'protected' => false, # 'friends_count' => $countfriends, 'created_at' => api_date($uinfo[0]['name-date']), diff --git a/view/api_timeline_atom.tpl b/view/api_timeline_atom.tpl index f9c70ebb5..bd674f330 100644 --- a/view/api_timeline_atom.tpl +++ b/view/api_timeline_atom.tpl @@ -32,7 +32,7 @@ http://activitystrea.ms/schema/1.0/person - $user.url + $user.contact_url $user.name @@ -100,7 +100,7 @@ http://activitystrea.ms/schema/1.0/person - $status.user.url + $status.user.contact_url $status.user.name