aboutsummaryrefslogtreecommitdiffstats
path: root/mod/p.php
blob: 80e835a918d790dcc4ba66044e06c2f47def7320 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php /** @file */

require_once('include/bb2diaspora.php');

// used in Diaspora communications to provide a server copy of a sent post in XML format.

function p_init(&$a) {

	if(argc() < 2)
		http_status_exit(401);

	$mid = str_replace('.xml','',argv(1));

	$r = q("select * from item where mid = '%s' and item_wall = 1 and item_private = 0 limit 1",
		dbesc($mid)
	);


	if((! $r) || (! perm_is_allowed($r[0]['uid'],'','view_stream')))
		http_status_exit(404);


	$c = q("select * from channel where channel_id = %d limit 1",
		intval($r[0]['uid'])
	);

	if(! $c)
		http_status_exit(404);

	$myaddr = $c[0]['channel_address'] . '@' . $a->get_hostname();

	$item = $r[0];
   
	$title = $item['title'];
	$body = bb2diaspora_itembody($item);
	$created = datetime_convert('UTC','UTC',$item['created'],'Y-m-d H:i:s \U\T\C');

	$tpl = get_markup_template('diaspora_post.tpl');
	$msg = replace_macros($tpl, array(
		'$body' => xmlify($body),
		'$guid' => $item['mid'],
		'$handle' => xmlify($myaddr),
		'$public' => 'true',
		'$created' => $created,
		'$provider' => (($item['app']) ? $item['app'] : 'redmatrix')
	));

	header('Content-type: text/xml');
	echo $msg;
	killme();
}