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 if(strlen($owner_id) && ! intval($owner_id)) {
11 $r = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
15 $owner_id = $r[0]['uid'];
18 $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
28 $r = q("SELECT * FROM `contact` WHERE `issued-id` = '%s' LIMIT 1",
35 $groups = init_groups_visitor($contact['id']);
38 $gs = '<<>>'; // should be impossible to match
40 foreach($groups as $g)
41 $gs .= '|<' . intval($g) . '>';
44 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
45 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
46 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
47 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
49 intval($contact['id']),
50 intval($contact['id']),
56 if(! strlen($last_update))
57 $last_update = 'now - 30 days';
58 $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s');
60 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
61 `contact`.`name`, `contact`.`photo`, `contact`.`url`,
62 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
63 `contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`
64 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
65 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
66 AND `item`.`type` != 'remote' AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
67 AND `item`.`edited` > '%s'
69 ORDER BY `parent` ASC, `created` ASC LIMIT 0, 300",
78 $feed_template = file_get_contents('view/atom_feed.tpl');
79 $tomb_template = file_get_contents('view/atom_tomb.tpl');
80 $item_template = file_get_contents('view/atom_item.tpl');
81 $cmnt_template = file_get_contents('view/atom_cmnt.tpl');
86 $atom .= replace_macros($feed_template, array(
87 '$feed_id' => xmlify($a->get_baseurl()),
88 '$feed_title' => xmlify($owner['name']),
89 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
90 '$name' => xmlify($owner['name']),
91 '$profile_page' => xmlify($owner['url']),
92 '$photo' => xmlify($owner['photo'])
95 foreach($items as $item) {
96 if($item['deleted']) {
97 $atom .= replace_macros($tomb_template, array(
98 '$id' => xmlify($item['uri']),
99 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
104 if($item['parent'] == $item['id']) {
105 $atom .= replace_macros($item_template, array(
106 '$name' => xmlify($item['name']),
107 '$profile_page' => xmlify($item['url']),
108 '$thumb' => xmlify($item['thumb']),
109 '$owner_name' => xmlify($item['owner-name']),
110 '$owner_profile_page' => xmlify($item['owner-link']),
111 '$owner_thumb' => xmlify($item['owner-avatar']),
112 '$item_id' => xmlify($item['uri']),
113 '$title' => xmlify($item['name']),
114 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
115 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
116 '$content' =>xmlify($item['body']),
117 '$comment_allow' => (($item['last-child'] && strlen($contact['dfrn-id'])) ? 1 : 0)
121 $atom .= replace_macros($cmnt_template, array(
122 '$name' => xmlify($item['name']),
123 '$profile_page' => xmlify($item['url']),
124 '$thumb' => xmlify($item['thumb']),
125 '$item_id' => xmlify($item['uri']),
126 '$title' => xmlify($item['title']),
127 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
128 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
129 '$content' =>xmlify($item['body']),
130 '$parent_id' => xmlify($item['parent-uri']),
131 '$comment_allow' => (($item['last-child']) ? 1 : 0)
137 $atom .= "</feed>\r\n";
145 function get_atom_elements($item) {
149 $author = $item->get_author();
150 $res['author-name'] = unxmlify($author->get_name());
151 $res['author-link'] = unxmlify($author->get_link());
152 $res['author-avatar'] = unxmlify($author->get_avatar());
153 $res['uri'] = unxmlify($item->get_id());
154 $res['title'] = unxmlify($item->get_title());
155 $res['body'] = unxmlify($item->get_content());
157 $maxlen = get_max_import_size();
158 if($maxlen && (strlen($res['body']) > $maxlen))
159 $res['body'] = substr($res['body'],0, $maxlen);
161 $allow = $item->get_item_tags('http://purl.org/macgirvin/dfrn/1.0','comment-allow');
162 if($allow && $allow[0]['data'] == 1)
163 $res['last-child'] = 1;
165 $res['last-child'] = 0;
167 $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
169 $res['created'] = unxmlify($rawcreated[0]['data']);
171 $rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'updated');
173 $res['edited'] = unxmlify($rawcreated[0]['data']);
175 $rawowner = $item->get_item_tags('http://purl.org/macgirvin/dfrn/1.0', 'owner');
176 if($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['name'][0]['data'])
177 $res['owner-name'] = unxmlify($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['name'][0]['data']);
178 if($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['uri'][0]['data'])
179 $res['owner-link'] = unxmlify($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['uri'][0]['data']);
180 if($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data'])
181 $res['owner-avatar'] = unxmlify($rawowner[0]['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data']);
186 function post_remote($a,$arr) {
190 $arr['type'] = 'remote';
191 $arr['uri'] = notags(trim($arr['uri']));
192 $arr['author-name'] = notags(trim($arr['author-name']));
193 $arr['author-link'] = notags(trim($arr['author-link']));
194 $arr['author-avatar'] = notags(trim($arr['author-avatar']));
195 $arr['owner-name'] = notags(trim($arr['owner-name']));
196 $arr['owner-link'] = notags(trim($arr['owner-link']));
197 $arr['owner-avatar'] = notags(trim($arr['owner-avatar']));
198 $arr['created'] = datetime_convert('UTC','UTC',$arr['created'],'Y-m-d H:i:s');
199 $arr['edited'] = datetime_convert('UTC','UTC',$arr['edited'],'Y-m-d H:i:s');
200 $arr['title'] = notags(trim($arr['title']));
201 $arr['body'] = escape_tags(trim($arr['body']));
202 $arr['last-child'] = intval($arr['last-child']);
205 $arr['parent-uri'] = notags(trim($arr['parent-uri']));
211 $r = q("INSERT INTO `item` (`"
212 . implode("`, `", array_keys($arr))
214 . implode("', '", array_values($arr))
217 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
218 dbesc($arr['parent-uri']),
223 $parent_id = $r[0]['id'];
225 // if parent is missing, what do we do?
228 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
233 $current_post = $r[0]['id'];
235 $r = q("UPDATE `item` SET `parent` = %d WHERE `id` = %d LIMIT 1",
237 intval($current_post)
240 return $current_post;