aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriendika <info@friendika.com>2011-06-21 03:47:27 -0700
committerFriendika <info@friendika.com>2011-06-21 03:47:27 -0700
commitab143a3102560c3a507bf45f9a5c4cd4d6937b91 (patch)
treec1099ad228788b0a0b16bb3202b4b919f45c05a5
parent7f387d93ae9f45a9feb7488f3b34bf2de90f328e (diff)
parent655f5c7b9fe138de5566047e79ada034647fd6f2 (diff)
downloadvolse-hubzilla-ab143a3102560c3a507bf45f9a5c4cd4d6937b91.tar.gz
volse-hubzilla-ab143a3102560c3a507bf45f9a5c4cd4d6937b91.tar.bz2
volse-hubzilla-ab143a3102560c3a507bf45f9a5c4cd4d6937b91.zip
Merge pull request #123 from fabrixxm/api
Api
-rw-r--r--include/api.php44
-rw-r--r--view/api_timeline_atom.tpl134
-rw-r--r--view/api_timeline_rss.tpl9
3 files changed, 143 insertions, 44 deletions
diff --git a/include/api.php b/include/api.php
index cab1431d3..4e5ea43bd 100644
--- a/include/api.php
+++ b/include/api.php
@@ -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,
diff --git a/view/api_timeline_atom.tpl b/view/api_timeline_atom.tpl
index bc677d237..bd674f330 100644
--- a/view/api_timeline_atom.tpl
+++ b/view/api_timeline_atom.tpl
@@ -7,33 +7,119 @@
<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>
- <id>$status.id</id>
- <title>$status.text</title>
- <content type="html">$status.html</content>
- <link rel="alternate" type="text/html" href="$status.url"/>
- <activity:verb>$status.verb</activity:verb>
- <published>$status.published</published>
- <updated>$status.updated</updated>
+ <activity:object-type>$status.objecttype</activity:object-type>
+ <id>$status.id</id>
+ <title>$status.text</title>
+ <content type="html">$status.html</content>
+ <link rel="alternate" type="text/html" href="$status.url"/>
+ <activity:verb>$status.verb</activity:verb>
+ <published>$status.published</published>
+ <updated>$status.updated</updated>
+
+ <!--
+ <source>
+ <id>http://identi.ca/api/statuses/user_timeline/397830.atom</id>
+ <title>Sin Mobopolitan</title>
+ <link rel="alternate" type="text/html" href="http://identi.ca/mobopolitan"/>
+ <link rel="self" type="application/atom+xml" href="http://identi.ca/api/statuses/user_timeline/397830.atom"/>
+ <link rel="license" href="http://creativecommons.org/licenses/by/3.0/"/>
+ <icon>http://avatar.identi.ca/397830-96-20110312195623.jpeg</icon>
+ <updated>2011-04-21T18:39:32+00:00</updated>
+ </source>
+ -->
+ <link rel="self" type="application/atom+xml" href="$status.self"/>
+ <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"/>
- <link rel="ostatus:conversation" href="$status.url"/>
- <!--
- <source>
- <id>http://identi.ca/api/statuses/user_timeline/397830.atom</id>
- <title>Sin Mobopolitan</title>
- <link rel="alternate" type="text/html" href="http://identi.ca/mobopolitan"/>
- <link rel="self" type="application/atom+xml" href="http://identi.ca/api/statuses/user_timeline/397830.atom"/>
- <link rel="license" href="http://creativecommons.org/licenses/by/3.0/"/>
- <icon>http://avatar.identi.ca/397830-96-20110312195623.jpeg</icon>
- <updated>2011-04-21T18:39:32+00:00</updated>
- </source>
- -->
- <link rel="self" type="application/atom+xml" href="$status.self"/>
- <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>
</entry>
{{ endfor }}
</feed>
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 @@
<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>