feeds are bit more standards compliant and a bit less broken now

This commit is contained in:
friendica 2013-06-12 21:12:27 -07:00
parent d996dc58be
commit 2d3a0a6525
3 changed files with 52 additions and 60 deletions

View File

@ -204,9 +204,7 @@ function get_public_feed($channel,$params) {
} }
echo get_feed_for($channel,get_observer_hash(),$params); return get_feed_for($channel,get_observer_hash(),$params);
killme();
} }
function get_feed_for($channel, $observer_hash, $params) { function get_feed_for($channel, $observer_hash, $params) {
@ -232,22 +230,19 @@ function get_feed_for($channel, $observer_hash, $params) {
$atom = ''; $atom = '';
$hubxml = feed_hublinks();
$salmon = feed_salmonlinks($owner_nick);
$atom .= replace_macros($feed_template, array( $atom .= replace_macros($feed_template, array(
'$version' => xmlify(RED_VERSION), '$version' => xmlify(RED_VERSION),
'$red' => xmlify(RED_PLATFORM),
'$feed_id' => xmlify($channel['channel_url']), '$feed_id' => xmlify($channel['channel_url']),
'$feed_title' => xmlify($channel['channel_name']), '$feed_title' => xmlify($channel['channel_name']),
'$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now' , ATOM_TIME)) , '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now' , ATOM_TIME)) ,
'$hub' => feed_hublinks(), '$hub' => '', // feed_hublinks(),
'$salmon' => feed_salmonlinks($channel['channel_address']), '$salmon' => '', // feed_salmonlinks($channel['channel_address']),
'$name' => xmlify($channel['channel_name']), '$name' => xmlify($channel['channel_name']),
'$profile_page' => xmlify($channel['channel_url']), '$profile_page' => xmlify($channel['channel_url']),
'$mimephoto' => xmlify($channel['channel_photo_mimetype']), '$mimephoto' => xmlify($channel['xchan_photo_mimetype']),
'$photo' => xmlify($channel['channel_photo_l']), '$photo' => xmlify($channel['xchan_photo_l']),
'$thumb' => xmlify($channel['channel_photo_m']), '$thumb' => xmlify($channel['xchan_photo_m']),
'$picdate' => '', '$picdate' => '',
'$uridate' => '', '$uridate' => '',
'$namdate' => '', '$namdate' => '',
@ -285,8 +280,7 @@ function construct_activity_object($item) {
if($item['object']) { if($item['object']) {
$o = '<as:object>' . "\r\n"; $o = '<as:object>' . "\r\n";
$r = parse_xml_string($item['object'],false); $r = json_decode($item['object'],false);
if(! $r) if(! $r)
return ''; return '';
@ -296,7 +290,8 @@ function construct_activity_object($item) {
$o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n"; $o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n";
if($r->title) if($r->title)
$o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n"; $o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n";
if($r->link) { if($r->links) {
// FIXME!!
if(substr($r->link,0,1) === '<') { if(substr($r->link,0,1) === '<') {
$r->link = preg_replace('/\<link(.*?)\"\>/','<link$1"/>',$r->link); $r->link = preg_replace('/\<link(.*?)\"\>/','<link$1"/>',$r->link);
$o .= $r->link; $o .= $r->link;
@ -317,7 +312,7 @@ function construct_activity_target($item) {
if($item['target']) { if($item['target']) {
$o = '<as:target>' . "\r\n"; $o = '<as:target>' . "\r\n";
$r = parse_xml_string($item['target'],false); $r = json_decode($item['target'],false);
if(! $r) if(! $r)
return ''; return '';
if($r->type) if($r->type)
@ -326,7 +321,8 @@ function construct_activity_target($item) {
$o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n"; $o .= '<id>' . xmlify($r->id) . '</id>' . "\r\n";
if($r->title) if($r->title)
$o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n"; $o .= '<title>' . xmlify($r->title) . '</title>' . "\r\n";
if($r->link) { if($r->links) {
// FIXME !!!
if(substr($r->link,0,1) === '<') { if(substr($r->link,0,1) === '<') {
if(strstr($r->link,'&') && (! strstr($r->link,'&amp;'))) if(strstr($r->link,'&') && (! strstr($r->link,'&amp;')))
$r->link = str_replace('&','&amp;', $r->link); $r->link = str_replace('&','&amp;', $r->link);
@ -3957,7 +3953,7 @@ function lose_sharer($importer,$contact,$datarray,$item) {
} }
function atom_author($tag,$name,$uri,$h,$w,$photo) { function atom_author($tag,$name,$uri,$h,$w,$type,$photo) {
$o = ''; $o = '';
if(! $tag) if(! $tag)
return $o; return $o;
@ -3971,8 +3967,8 @@ function atom_author($tag,$name,$uri,$h,$w,$photo) {
$o .= "<$tag>\r\n"; $o .= "<$tag>\r\n";
$o .= "<name>$name</name>\r\n"; $o .= "<name>$name</name>\r\n";
$o .= "<uri>$uri</uri>\r\n"; $o .= "<uri>$uri</uri>\r\n";
$o .= '<link rel="photo" type="image/jpeg" media:width="' . $w . '" media:height="' . $h . '" href="' . $photo . '" />' . "\r\n"; $o .= '<link rel="photo" type="' . $type . '" media:width="' . $w . '" media:height="' . $h . '" href="' . $photo . '" />' . "\r\n";
$o .= '<link rel="avatar" type="image/jpeg" media:width="' . $w . '" media:height="' . $h . '" href="' . $photo . '" />' . "\r\n"; $o .= '<link rel="avatar" type="' . $type . '" media:width="' . $w . '" media:height="' . $h . '" href="' . $photo . '" />' . "\r\n";
call_hooks('atom_author', $o); call_hooks('atom_author', $o);
@ -4000,35 +3996,36 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
$o = "\r\n\r\n<entry>\r\n"; $o = "\r\n\r\n<entry>\r\n";
if(is_array($author)) if(is_array($author))
$o .= atom_author('author',$author['name'],$author['url'],80,80,$author['thumb']); $o .= atom_author('author',$author['xchan_name'],$author['xchan_url'],80,80,$author['xchan_photo_mimetype'],$author['xchan_photo_m']);
else else
$o .= atom_author('author',(($item['author-name']) ? $item['author-name'] : $item['name']),(($item['author-link']) ? $item['author-link'] : $item['url']),80,80,(($item['author-avatar']) ? $item['author-avatar'] : $item['thumb'])); $o .= atom_author('author',$item['author']['xchan_name'],$item['author']['xchan_url'],80,80,$item['author']['xchan_photo_mimetype'], $item['author']['xchan_photo_m']);
if(strlen($item['owner-name']))
$o .= atom_author('dfrn:owner',$item['owner-name'],$item['owner-link'],80,80,$item['owner-avatar']); $o .= atom_author('zot:owner',$item['owner']['xchan_name'],$item['owner']['xchan_url'],80,80,$item['owner']['xchan_photo_mimetype'],$item['owner']['xchan_photo_m']);
if(($item['parent'] != $item['id']) || ($item['parent_mid'] !== $item['mid']) || (($item['thr_parent'] !== '') && ($item['thr_parent'] !== $item['mid']))) { if(($item['parent'] != $item['id']) || ($item['parent_mid'] !== $item['mid']) || (($item['thr_parent'] !== '') && ($item['thr_parent'] !== $item['mid']))) {
$parent_item = (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']); $parent_item = (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']);
$o .= '<thr:in-reply-to ref="' . xmlify($parent_item) . '" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['parent']) . '" />' . "\r\n"; $o .= '<thr:in-reply-to ref="' . xmlify($parent_item) . '" type="text/html" href="' . xmlify($item['plink']) . '" />' . "\r\n";
} }
$o .= '<id>' . xmlify($item['mid']) . '</id>' . "\r\n"; $o .= '<id>' . xmlify($item['mid']) . '</id>' . "\r\n";
$o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n"; $o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";
$o .= '<published>' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '</published>' . "\r\n"; $o .= '<published>' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '</published>' . "\r\n";
$o .= '<updated>' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '</updated>' . "\r\n"; $o .= '<updated>' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '</updated>' . "\r\n";
$o .= '<dfrn:env>' . base64url_encode($body, true) . '</dfrn:env>' . "\r\n"; $o .= '<zot:env>' . base64url_encode($body, true) . '</zot:env>' . "\r\n";
// FIXME for other content types
$o .= '<content type="' . $type . '" >' . xmlify((($type === 'html') ? bbcode($body) : $body)) . '</content>' . "\r\n"; $o .= '<content type="' . $type . '" >' . xmlify((($type === 'html') ? bbcode($body) : $body)) . '</content>' . "\r\n";
$o .= '<link rel="alternate" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n"; $o .= '<link rel="alternate" type="text/html" href="' . xmlify($item['plink']) . '" />' . "\r\n";
if($item['location']) { if($item['location']) {
$o .= '<dfrn:location>' . xmlify($item['location']) . '</dfrn:location>' . "\r\n"; $o .= '<zot:location>' . xmlify($item['location']) . '</zot:location>' . "\r\n";
$o .= '<poco:address><poco:formatted>' . xmlify($item['location']) . '</poco:formatted></poco:address>' . "\r\n"; $o .= '<poco:address><poco:formatted>' . xmlify($item['location']) . '</poco:formatted></poco:address>' . "\r\n";
} }
if($item['coord']) if($item['coord'])
$o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n"; $o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n";
if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) if(($item['item_private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid']))
$o .= '<dfrn:private>' . (($item['private']) ? $item['private'] : 1) . '</dfrn:private>' . "\r\n"; $o .= '<zot:private>' . (($item['item_private']) ? $item['item_private'] : 1) . '</zot:private>' . "\r\n";
if($item['app']) if($item['app'])
@ -4044,18 +4041,20 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
if(strlen($actarg)) if(strlen($actarg))
$o .= $actarg; $o .= $actarg;
$tags = item_getfeedtags($item); // FIXME
if(count($tags)) { // $tags = item_getfeedtags($item);
foreach($tags as $t) { // if(count($tags)) {
$o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n"; // foreach($tags as $t) {
} // $o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n";
} // }
// }
$o .= item_getfeedattach($item); // FIXME
// $o .= item_getfeedattach($item);
$mentioned = get_mentions($item,$tags); // $mentioned = get_mentions($item,$tags);
if($mentioned) // if($mentioned)
$o .= $mentioned; // $o .= $mentioned;
call_hooks('atom_entry', $o); call_hooks('atom_entry', $o);

View File

@ -13,7 +13,7 @@ function feed_init(&$a) {
$channel = ''; $channel = '';
if(argc() > 1) { if(argc() > 1) {
$r = q("select * from channel where channel_address = '%s' limit 1", $r = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_address = '%s' limit 1",
dbesc(argv(1)) dbesc(argv(1))
); );
if(!($r && count($r))) if(!($r && count($r)))
@ -21,11 +21,6 @@ function feed_init(&$a) {
$channel = $r[0]; $channel = $r[0];
// check site and channel permissions
if(!($channel['channel_r_stream'] & PERMS_PUBLIC))
killme();
if((intval(get_config('system','block_public'))) && (! get_account_id())) if((intval(get_config('system','block_public'))) && (! get_account_id()))
killme(); killme();

View File

@ -1,14 +1,10 @@
{{*
* AUTOMATICALLY GENERATED TEMPLATE
* DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN
*
*}}
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom" <feed xmlns="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:thr="http://purl.org/syndication/thread/1.0"
xmlns:at="http://purl.org/atompub/tombstones/1.0" xmlns:at="http://purl.org/atompub/tombstones/1.0"
xmlns:media="http://purl.org/syndication/atommedia" xmlns:media="http://purl.org/syndication/atommedia"
xmlns:dfrn="http://purl.org/macgirvin/dfrn/1.0" xmlns:dfrn="http://purl.org/macgirvin/dfrn/1.0"
xmlns:zot="http://purl.org/zot"
xmlns:as="http://activitystrea.ms/spec/1.0/" xmlns:as="http://activitystrea.ms/spec/1.0/"
xmlns:georss="http://www.georss.org/georss" xmlns:georss="http://www.georss.org/georss"
xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:poco="http://portablecontacts.net/spec/1.0"
@ -17,18 +13,20 @@
<id>{{$feed_id}}</id> <id>{{$feed_id}}</id>
<title>{{$feed_title}}</title> <title>{{$feed_title}}</title>
<generator uri="http://friendica.com" version="{{$version}}">Friendica</generator> <generator uri="http://getzot.com" version="{{$version}}">{{$red}}</generator>
<link rel="license" href="http://creativecommons.org/licenses/by/3.0/" /> <link rel="license" href="http://creativecommons.org/licenses/by/3.0/" />
{{if $hub}}
{{$hub}} {{$hub}}
{{/if}}
{{if $salmon}}
{{$salmon}} {{$salmon}}
{{$community}} {{/if}}
<updated>{{$feed_updated}}</updated> <updated>{{$feed_updated}}</updated>
<dfrn:owner> <zot:owner>
<name dfrn:updated="{{$namdate}}" >{{$name}}</name> <name>{{$name}}</name>
<uri dfrn:updated="{{$uridate}}" >{{$profile_page}}</uri> <uri>{{$profile_page}}</uri>
<link rel="photo" type="image/jpeg" dfrn:updated="{{$picdate}}" media:width="175" media:height="175" href="{{$photo}}" /> <link rel="photo" type="{{$mimephoto}}" media:width="175" media:height="175" href="{{$photo}}" />
<link rel="avatar" type="image/jpeg" dfrn:updated="{{$picdate}}" media:width="175" media:height="175" href="{{$photo}}" /> <link rel="avatar" type="{{$mimephoto}}" media:width="175" media:height="175" href="{{$photo}}" />
{{$birthday}} </zot:owner>
</dfrn:owner>