mod_display: provide alternate serialisations (starting with atom)

This commit is contained in:
zotlabs 2017-10-22 21:44:39 -07:00
parent fd5764e166
commit 37b7b2f1a8
2 changed files with 115 additions and 54 deletions

View File

@ -12,6 +12,12 @@ class Display extends \Zotlabs\Web\Controller {
function get($update = 0, $load = false) {
if(argc() > 1) {
$module_format = substr(argv(1),strrpos(argv(1),'.') + 1);
if(! in_array($module_format,['atom','zot','json']))
$module_format = 'html';
}
$checkjs = new \Zotlabs\Web\CheckJS(1);
if($load)
@ -22,8 +28,12 @@ class Display extends \Zotlabs\Web\Controller {
return;
}
if(argc() > 1 && argv(1) !== 'load')
if(argc() > 1 && argv(1) !== 'load') {
$item_hash = argv(1);
if($module_format !== 'html') {
$item_hash = substr($item_hash,0,strrpos($item_hash,'.'));
}
}
if($_REQUEST['mid'])
$item_hash = $_REQUEST['mid'];
@ -139,10 +149,11 @@ class Display extends \Zotlabs\Web\Controller {
$static = ((local_channel()) ? channel_manual_conv_update(local_channel()) : 1);
//if the target item is not a post (eg a like) we want to address its thread parent
// if the target item is not a post (eg a like) we want to address its thread parent
$mid = ((($target_item['verb'] == ACTIVITY_LIKE) || ($target_item['verb'] == ACTIVITY_DISLIKE)) ? $target_item['thr_parent'] : $target_item['mid']);
//if we got a decoded hash we must encode it again before handing to javascript
// if we got a decoded hash we must encode it again before handing to javascript
if($decoded)
$mid = 'b64.' . base64url_encode($mid);
@ -195,11 +206,11 @@ class Display extends \Zotlabs\Web\Controller {
$sql_extra = public_permissions_sql($observer_hash);
if(($update && $load) || ($checkjs->disabled())) {
if(($update && $load) || ($checkjs->disabled()) || ($module_format !== 'html')) {
$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']),intval(\App::$pager['start']));
if($load || ($checkjs->disabled())) {
if($load || ($checkjs->disabled()) || ($module_format !== 'html')) {
$r = null;
require_once('include/channel.php');
@ -311,6 +322,11 @@ class Display extends \Zotlabs\Web\Controller {
$items = array();
}
switch($module_format) {
case 'html':
if ($checkjs->disabled()) {
$o .= conversation($items, 'display', $update, 'traditional');
if ($items[0]['title'])
@ -320,6 +336,49 @@ class Display extends \Zotlabs\Web\Controller {
$o .= conversation($items, 'display', $update, 'client');
}
break;
case 'atom':
$atom = replace_macros(get_markup_template('atom_feed.tpl'), array(
'$version' => xmlify(\Zotlabs\Lib\System::get_project_version()),
'$red' => xmlify(\Zotlabs\Lib\System::get_platform_name()),
'$feed_id' => xmlify(\App::$cmd),
'$feed_title' => xmlify(t('Article')),
'$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now', ATOM_TIME)),
'$author' => '',
'$owner' => '',
'$profile_page' => xmlify(z_root() . '/display/' . $target_item['mid']),
));
$x = [ 'xml' => $atom, 'channel' => $channel, 'observer_hash' => $observer_hash, 'params' => $params ];
call_hooks('atom_feed_top',$x);
$atom = $x['xml'];
// a much simpler interface
call_hooks('atom_feed', $atom);
if($items) {
$type = 'html';
foreach($items as $item) {
if($item['item_private'])
continue;
$atom .= atom_entry($item, $type, null, '', true, '', false);
}
}
call_hooks('atom_feed_end', $atom);
$atom .= '</feed>' . "\r\n";
header('Content-type: application/atom+xml');
echo $atom;
killme();
}
if($updateable) {
$x = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 AND uid = %d and parent = %d ",
intval(local_channel()),

View File

@ -15,7 +15,9 @@
<title>{{$feed_title}}</title>
<generator uri="http://hubzilla.org" version="{{$version}}">{{$red}}</generator>
<link rel="license" href="http://creativecommons.org/licenses/by/3.0/" />
{{if $profile_page}}
<link rel="alternate" type="text/html" href="{{$profile_page}}" />
{{/if}}
{{if $author}}
{{$author}}
{{/if}}