Merge pull request #123 from fabrixxm/api

Api
This commit is contained in:
Friendika 2011-06-21 03:47:27 -07:00
commit ab143a3102
3 changed files with 143 additions and 44 deletions

View file

@ -137,7 +137,7 @@
return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
break;
case "atom":
#header ("Content-Type: application/atom+xml");
header ("Content-Type: application/atom+xml");
return '<?xml version="1.0" encoding="UTF-8"?>'."\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,19 @@
$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'],
'contact_url' => $a->get_baseurl()."/contacts/".$uinfo[0]['cid'],
'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 +472,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 +479,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,7 +513,7 @@
'contributors' => '',
'annotations' => '',
'entities' => '',
'user' => $user_info,
'user' => $status_user ,
'objecttype' => $item['object-type'],
'verb' => $item['verb'],
'self' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type,

View file

@ -7,6 +7,49 @@
<updated>$rss.updated</updated>
<link type="text/html" rel="alternate" href="$rss.alternate"/>
<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.contact_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 }}
<entry>
<activity:object-type>$status.objecttype</activity:object-type>
@ -18,7 +61,6 @@
<published>$status.published</published>
<updated>$status.updated</updated>
<link rel="ostatus:conversation" href="$status.url"/>
<!--
<source>
<id>http://identi.ca/api/statuses/user_timeline/397830.atom</id>
@ -34,6 +76,50 @@
<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>
<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.contact_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.url"/>
</entry>
{{ endfor }}
</feed>

View file

@ -6,10 +6,15 @@
<description>Friendika timeline</description>
<language>$rss.language</language>
<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 }}
<item>
<title>$status.text</title>
<title>$status.user.name: $status.text</title>
<description>$status.text</description>
<pubDate>$status.created_at</pubDate>
<guid>$status.url</guid>