4 function get_feed_for(&$a,$dfrn_id,$owner_id,$last_update) {
6 // default permissions - anonymous user
8 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
10 $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
20 $r = q("SELECT * FROM `contact` WHERE `issued-id` = '%s' LIMIT 1",
27 $groups = init_groups_visitor($contact['id']);
30 $gs = '<<>>'; // should be impossible to match
32 foreach($groups as $g)
33 $gs .= '|<' . intval($g) . '>';
36 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
37 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
38 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
39 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
41 intval($_SESSION['visitor_id']),
42 intval($_SESSION['visitor_id']),
48 if(! strlen($last_update))
49 $last_update = 'now - 30 days';
50 $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s');
52 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
53 `contact`.`name`, `contact`.`photo`, `contact`.`url`,
54 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
55 `contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`
56 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
57 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
58 AND `item`.`type` != 'remote' AND `contact`.`blocked` = 0
59 AND `item`.`edited` > '%s'
61 ORDER BY `parent` DESC, `id` ASC LIMIT 0, 300",
70 $feed_template = file_get_contents('view/atom_feed.tpl');
71 $tomb_template = file_get_contents('view/atom_tomb.tpl');
72 $item_template = file_get_contents('view/atom_item.tpl');
73 $cmnt_template = file_get_contents('view/atom_cmnt.tpl');
78 $atom .= replace_macros($feed_template, array(
79 '$feed_id' => xmlify($a->get_baseurl()),
80 '$feed_title' => xmlify($owner['name']),
81 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
82 '$name' => xmlify($owner['name']),
83 '$profile_page' => xmlify($owner['url']),
84 '$photo' => xmlify($owner['photo'])
87 foreach($items as $item) {
88 if($item['deleted']) {
89 $atom .= replace_macros($tomb_template, array(
90 '$id' => xmlify(((strlen($item['remote-id'])) ? $item['remote-id'] : "urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}")),
91 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
96 if($item['parent'] == $item['id']) {
97 $atom .= replace_macros($item_template, array(
98 '$name' => xmlify($item['name']),
99 '$profile_page' => xmlify($item['url']),
100 '$thumb' => xmlify($item['thumb']),
101 '$owner_name' => xmlify($item['owner-name']),
102 '$owner_profile_page' => xmlify($item['owner-link']),
103 '$owner_thumb' => xmlify($item['owner-avatar']),
104 '$item_id' => xmlify(((strlen($item['remote-id'])) ? $item['remote-id'] : "urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}")),
105 '$title' => xmlify($item['name']),
106 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
107 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
108 '$content' =>xmlify($item['body']),
109 '$comment_allow' => (($item['last-child'] && strlen($contact['dfrn-id'] && (! $contact['blocked']))) ? 1 : 0)
113 $atom .= replace_macros($cmnt_template, array(
114 '$name' => xmlify($item['name']),
115 '$profile_page' => xmlify($item['url']),
116 '$thumb' => xmlify($item['thumb']),
117 '$item_id' => xmlify(((strlen($item['remote-id'])) ? $item['remote-id'] : "urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}")),
118 '$title' => xmlify($item['title']),
119 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
120 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
121 '$content' =>xmlify($item['body']),
122 '$parent_id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$items[0]['hash']}"),
123 '$comment_allow' => (($item['last-child']) ? 1 : 0)
130 $atom .= "</feed>\r\n";