add users infos to rss and atom api responses

This commit is contained in:
Fabio Comuni 2011-06-21 11:41:16 +02:00
parent 5a23440fb4
commit 296f1b0123
3 changed files with 144 additions and 44 deletions

View file

@ -137,7 +137,7 @@
return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r; return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
break; break;
case "atom": case "atom":
#header ("Content-Type: application/atom+xml"); header ("Content-Type: application/atom+xml");
return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r; return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
break; break;
@ -153,6 +153,7 @@
*/ */
function api_rss_extra(&$a, $arr, $user_info){ function api_rss_extra(&$a, $arr, $user_info){
if (is_null($user_info)) $user_info = api_get_user($a); if (is_null($user_info)) $user_info = api_get_user($a);
$arr['$user'] = $user_info;
$arr['$rss'] = array( $arr['$rss'] = array(
'alternate' => $user_info['url'], 'alternate' => $user_info['url'],
'self' => $a->get_baseurl(). "/". $a->query_string, 'self' => $a->get_baseurl(). "/". $a->query_string,
@ -167,19 +168,24 @@
/** /**
* Returns user info array. * Returns user info array.
*/ */
function api_get_user(&$a){ function api_get_user(&$a, $contact_id=Null){
$user = null; $user = null;
$extra_query = ""; $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']); $user = intval($_GET['user_id']);
$extra_query = "AND `contact`.`id` = %d "; $extra_query = "AND `contact`.`id` = %d ";
} }
if(x($_GET, 'screen_name')) { if(is_null($user) && x($_GET, 'screen_name')) {
$user = dbesc($_GET['screen_name']); $user = dbesc($_GET['screen_name']);
$extra_query = "AND `contact`.`nick` = '%s' "; $extra_query = "AND `contact`.`nick` = '%s' ";
} }
if ($user===null){ if (is_null($user)){
list($user, $null) = explode(".",$a->argv[3]); list($user, $null) = explode(".",$a->argv[3]);
if(is_numeric($user)){ if(is_numeric($user)){
$user = intval($user); $user = intval($user);
@ -195,15 +201,15 @@
api_login($a); return False; api_login($a); return False;
} else { } else {
$user = $_SESSION['uid']; $user = $_SESSION['uid'];
$extra_query = "AND `user`.`uid` = %d "; $extra_query = "AND `contact`.`uid` = %d ";
} }
} }
// user info // user info
$uinfo = q("SELECT *, `contact`.`id` as `cid` FROM `user`, `contact` $uinfo = q("SELECT *, `contact`.`id` as `cid` FROM `contact`
WHERE `user`.`uid`=`contact`.`uid` AND `contact`.`self`=1 WHERE 1
$extra_query", $extra_query",
$user $user
); );
@ -230,17 +236,18 @@
$ret = Array( $ret = Array(
'uid' => $uinfo[0]['uid'],
'id' => $uinfo[0]['cid'], 'id' => $uinfo[0]['cid'],
'name' => $uinfo[0]['username'], 'name' => $uinfo[0]['name'],
'screen_name' => $uinfo[0]['nickname'], 'screen_name' => $uinfo[0]['nick'],
'location' => $uinfo[0]['default-location'], 'location' => '', //$uinfo[0]['default-location'],
'profile_image_url' => $uinfo[0]['micro'], 'profile_image_url' => $uinfo[0]['micro'],
'url' => $uinfo[0]['url'], 'url' => $uinfo[0]['url'],
'protected' => false, # 'protected' => false, #
'friends_count' => $countfriends, 'friends_count' => $countfriends,
'created_at' => api_date($uinfo[0]['created']), 'created_at' => api_date($uinfo[0]['name-date']),
'utc_offset' => 0, #XXX: fix me 'utc_offset' => 0, #XXX: fix me
'time_zone' => $uinfo[0]['timezone'], 'time_zone' => '', //$uinfo[0]['timezone'],
'geo_enabled' => false, 'geo_enabled' => false,
'statuses_count' => $countitms, #XXX: fix me 'statuses_count' => $countitms, #XXX: fix me
'lang' => 'en', #XXX: fix me 'lang' => 'en', #XXX: fix me
@ -464,7 +471,6 @@
if (local_user()===false) return false; if (local_user()===false) return false;
$user_info = api_get_user($a); $user_info = api_get_user($a);
// get last newtork messages // get last newtork messages
$sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) "; $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`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item`, `contact`, `user` FROM `item`, `contact`
WHERE `item`.`contact-id` = %d AND `user`.`uid` = `item`.`uid` WHERE `item`.`uid` = %d
AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `contact`.`id` = `item`.`contact-id` AND `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra $sql_extra
ORDER BY `item`.`created` DESC LIMIT %d ,%d ", ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
intval($user_info['id']), intval($user_info['uid']),
0,20 0,20
); );
$ret = Array(); $ret = Array();
foreach($r as $item) { foreach($r as $item) {
$status_user = (($item['cid']==$user_info['id'])?$user_info: api_get_user($a,$item['cid']));
$status = array( $status = array(
'created_at'=> api_date($item['created']), 'created_at'=> api_date($item['created']),
'published' => datetime_convert('UTC','UTC',$item['created'],ATOM_TIME), 'published' => datetime_convert('UTC','UTC',$item['created'],ATOM_TIME),
@ -505,9 +512,10 @@
'contributors' => '', 'contributors' => '',
'annotations' => '', 'annotations' => '',
'entities' => '', 'entities' => '',
'user' => $user_info, 'user' => $status_user ,
'objecttype' => $item['object-type'], 'objecttype' => $item['object-type'],
'verb' => $item['verb'], 'verb' => $item['verb'],
'conversation' => $a->get_baseurl() . '/display/' . $status_user['screen_name'] . '/' . $item['id'],
'self' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type, 'self' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type,
'edit' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type, 'edit' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type,
); );

View file

@ -7,6 +7,49 @@
<updated>$rss.updated</updated> <updated>$rss.updated</updated>
<link type="text/html" rel="alternate" href="$rss.alternate"/> <link type="text/html" rel="alternate" href="$rss.alternate"/>
<link type="application/atom+xml" rel="self" href="$rss.self"/> <link type="application/atom+xml" rel="self" href="$rss.self"/>
<author>
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
<uri>$user.url</uri>
<name>$user.name</name>
<link rel="alternate" type="text/html" href="$user.url"/>
<link rel="avatar" type="image/jpeg" media:width="106" media:height="106" href="$user.profile_image_url"/>
<link rel="avatar" type="image/jpeg" media:width="96" media:height="96" href="$user.profile_image_url"/>
<link rel="avatar" type="image/jpeg" media:width="48" media:height="48" href="$user.profile_image_url"/>
<link rel="avatar" type="image/jpeg" media:width="24" media:height="24" href="$user.profile_image_url"/>
<georss:point></georss:point>
<poco:preferredUsername>$user.screen_name</poco:preferredUsername>
<poco:displayName>$user.name</poco:displayName>
<poco:urls>
<poco:type>homepage</poco:type>
<poco:value>$user.url</poco:value>
<poco:primary>true</poco:primary>
</poco:urls>
<statusnet:profile_info local_id="$user.id"></statusnet:profile_info>
</author>
<!--Deprecation warning: activity:subject is present only for backward compatibility. It will be removed in the next version of StatusNet.-->
<activity:subject>
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
<id>$user.url</id>
<title>$user.name</title>
<link rel="alternate" type="text/html" href="$user.url"/>
<link rel="avatar" type="image/jpeg" media:width="106" media:height="106" href="$user.profile_image_url"/>
<link rel="avatar" type="image/jpeg" media:width="96" media:height="96" href="$user.profile_image_url"/>
<link rel="avatar" type="image/jpeg" media:width="48" media:height="48" href="$user.profile_image_url"/>
<link rel="avatar" type="image/jpeg" media:width="24" media:height="24" href="$user.profile_image_url"/>
<poco:preferredUsername>$user.screen_name</poco:preferredUsername>
<poco:displayName>$user.name</poco:displayName>
<poco:urls>
<poco:type>homepage</poco:type>
<poco:value>$user.url</poco:value>
<poco:primary>true</poco:primary>
</poco:urls>
<statusnet:profile_info local_id="$user.id"></statusnet:profile_info>
</activity:subject>
{{ for $statuses as $status }} {{ for $statuses as $status }}
<entry> <entry>
<activity:object-type>$status.objecttype</activity:object-type> <activity:object-type>$status.objecttype</activity:object-type>
@ -34,6 +77,50 @@
<link rel="edit" type="application/atom+xml" href="$status.edit"/> <link rel="edit" type="application/atom+xml" href="$status.edit"/>
<statusnet:notice_info local_id="$status.id" source="$status.source" favorite="false" repeated="false"> <statusnet:notice_info local_id="$status.id" source="$status.source" favorite="false" repeated="false">
</statusnet:notice_info> </statusnet:notice_info>
<author>
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
<uri>$status.user.url</uri>
<name>$status.user.name</name>
<link rel="alternate" type="text/html" href="$status.user.url"/>
<link rel="avatar" type="image/jpeg" media:width="106" media:height="106" href="$status.user.profile_image_url"/>
<link rel="avatar" type="image/jpeg" media:width="96" media:height="96" href="$status.user.profile_image_url"/>
<link rel="avatar" type="image/jpeg" media:width="48" media:height="48" href="$status.user.profile_image_url"/>
<link rel="avatar" type="image/jpeg" media:width="24" media:height="24" href="$status.user.profile_image_url"/>
<georss:point/>
<poco:preferredUsername>$status.user.screen_name</poco:preferredUsername>
<poco:displayName>$status.user.name</poco:displayName>
<poco:address/>
<poco:urls>
<poco:type>homepage</poco:type>
<poco:value>$status.user.url</poco:value>
<poco:primary>true</poco:primary>
</poco:urls>
<!-- <statusnet:profile_info local_id="123710" following="true" blocking="false"></statusnet:profile_info> -->
</author>
<!--Deprecation warning: activity:actor is present only for backward compatibility. It will be removed in the next version of StatusNet.-->
<activity:actor>
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
<id>$status.user.url</id>
<title>$status.user.name</title>
<link rel="alternate" type="text/html" href="$status.user.url"/>
<link rel="avatar" type="image/jpeg" media:width="106" media:height="106" href="$status.user.profile_image_url"/>
<link rel="avatar" type="image/jpeg" media:width="96" media:height="96" href="$status.user.profile_image_url"/>
<link rel="avatar" type="image/jpeg" media:width="48" media:height="48" href="$status.user.profile_image_url"/>
<link rel="avatar" type="image/jpeg" media:width="24" media:height="24" href="$status.user.profile_image_url"/>
<georss:point/>
<poco:preferredUsername>$status.user.screen_name</poco:preferredUsername>
<poco:displayName>$status.user.name</poco:displayName>
<poco:address />
<poco:urls>
<poco:type>homepage</poco:type>
<poco:value>$status.user.url</poco:value>
<poco:primary>true</poco:primary>
</poco:urls>
<!-- <statusnet:profile_info local_id="123710" following="true" blocking="false"></statusnet:profile_info> -->
</activity:actor>
<link rel="ostatus:conversation" href="$status.conversation"/>
</entry> </entry>
{{ endfor }} {{ endfor }}
</feed> </feed>

View file

@ -6,10 +6,15 @@
<description>Friendika timeline</description> <description>Friendika timeline</description>
<language>$rss.language</language> <language>$rss.language</language>
<ttl>40</ttl> <ttl>40</ttl>
<image>
<link>$user.link</link>
<title>$user.name's items</title>
<url>$user.profile_image_url</url>
</image>
{{ for $statuses as $status }} {{ for $statuses as $status }}
<item> <item>
<title>$status.text</title> <title>$status.user.name: $status.text</title>
<description>$status.text</description> <description>$status.text</description>
<pubDate>$status.created_at</pubDate> <pubDate>$status.created_at</pubDate>
<guid>$status.url</guid> <guid>$status.url</guid>