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 for($x = 0; $x < count($groups); $x ++)
39 $groups[$x] = '<' . intval($groups[$x]) . '>' ;
40 $gs = implode('|', $groups);
43 $gs = '<<>>' ; // Impossible to match
46 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
47 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
48 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
49 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
51 intval($contact['id']),
52 intval($contact['id']),
58 if(! strlen($last_update))
59 $last_update = 'now - 30 days';
60 $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s');
62 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
63 `contact`.`name`, `contact`.`photo`, `contact`.`url`,
64 `contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
65 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
66 `contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`
67 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
68 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
69 AND NOT `item`.`type` IN ( 'remote', 'net-comment' ) AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
70 AND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' )
72 ORDER BY `parent` ASC, `created` ASC LIMIT 0, 300",
82 $feed_template = file_get_contents('view/atom_feed.tpl');
83 $tomb_template = file_get_contents('view/atom_tomb.tpl');
84 $item_template = file_get_contents('view/atom_item.tpl');
85 $cmnt_template = file_get_contents('view/atom_cmnt.tpl');
90 $atom .= replace_macros($feed_template, array(
91 '$feed_id' => xmlify($a->get_baseurl()),
92 '$feed_title' => xmlify($owner['name']),
93 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
94 '$name' => xmlify($owner['name']),
95 '$profile_page' => xmlify($owner['url']),
96 '$photo' => xmlify($owner['photo']),
97 '$thumb' => xmlify($owner['thumb']),
98 '$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
99 '$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
100 '$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
104 foreach($items as $item) {
105 if($item['deleted']) {
106 $atom .= replace_macros($tomb_template, array(
107 '$id' => xmlify($item['uri']),
108 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
112 if($item['parent'] == $item['id']) {
113 $atom .= replace_macros($item_template, array(
114 '$name' => xmlify($item['name']),
115 '$profile_page' => xmlify($item['url']),
116 '$thumb' => xmlify($item['thumb']),
117 '$owner_name' => xmlify($item['owner-name']),
118 '$owner_profile_page' => xmlify($item['owner-link']),
119 '$owner_thumb' => xmlify($item['owner-avatar']),
120 '$item_id' => xmlify($item['uri']),
121 '$title' => xmlify($item['title']),
122 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
123 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
124 '$location' => xmlify($item['location']),
125 '$content' => xmlify($item['body']),
126 '$comment_allow' => (($item['last-child'] && strlen($contact['dfrn-id'])) ? 1 : 0)
130 $atom .= replace_macros($cmnt_template, array(
131 '$name' => xmlify($item['name']),
132 '$profile_page' => xmlify($item['url']),
133 '$thumb' => xmlify($item['thumb']),
134 '$item_id' => xmlify($item['uri']),
135 '$title' => xmlify($item['title']),
136 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
137 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
138 '$content' =>xmlify($item['body']),
139 '$parent_id' => xmlify($item['parent-uri']),
140 '$comment_allow' => (($item['last-child']) ? 1 : 0)
146 $atom .= '</feed>' . "\r\n";
153 function get_atom_elements($item) {
157 $author = $item->get_author();
158 $res['author-name'] = unxmlify($author->get_name());
159 $res['author-link'] = unxmlify($author->get_link());
160 $res['author-avatar'] = unxmlify($author->get_avatar());
161 $res['uri'] = unxmlify($item->get_id());
162 $res['title'] = unxmlify($item->get_title());
163 $res['body'] = unxmlify($item->get_content());
165 $maxlen = get_max_import_size();
166 if($maxlen && (strlen($res['body']) > $maxlen))
167 $res['body'] = substr($res['body'],0, $maxlen);
169 $allow = $item->get_item_tags(NAMESPACE_DFRN,'comment-allow');
170 if($allow && $allow[0]['data'] == 1)
171 $res['last-child'] = 1;
173 $res['last-child'] = 0;
175 $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
177 $res['created'] = unxmlify($rawcreated[0]['data']);
179 $rawlocation = $item->get_item_tags('http://activitystrea.ms/spec/1.0/', 'place');
181 $res['location'] = unxmlify($rawlocation[0]['data']);
184 $rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'updated');
186 $res['edited'] = unxmlify($rawcreated[0]['data']);
188 $rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner');
189 if($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data'])
190 $res['owner-name'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']);
191 if($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data'])
192 $res['owner-link'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']);
193 if($rawowner[0]['child'][NAMESPACE_DFRN]['avatar'][0]['data'])
194 $res['owner-avatar'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['avatar'][0]['data']);
199 function post_remote($a,$arr) {
203 $arr['type'] = 'remote';
204 $arr['uri'] = notags(trim($arr['uri']));
205 $arr['author-name'] = notags(trim($arr['author-name']));
206 $arr['author-link'] = notags(trim($arr['author-link']));
207 $arr['author-avatar'] = notags(trim($arr['author-avatar']));
208 $arr['owner-name'] = notags(trim($arr['owner-name']));
209 $arr['owner-link'] = notags(trim($arr['owner-link']));
210 $arr['owner-avatar'] = notags(trim($arr['owner-avatar']));
211 $arr['created'] = datetime_convert('UTC','UTC',$arr['created'],'Y-m-d H:i:s');
212 $arr['edited'] = datetime_convert('UTC','UTC',$arr['edited'],'Y-m-d H:i:s');
213 $arr['changed'] = datetime_convert();
214 $arr['title'] = notags(trim($arr['title']));
215 $arr['location'] = notags(trim($arr['location']));
216 $arr['body'] = escape_tags(trim($arr['body']));
217 $arr['last-child'] = intval($arr['last-child']);
220 $arr['parent-uri'] = notags(trim($arr['parent-uri']));
226 $r = q("INSERT INTO `item` (`"
227 . implode("`, `", array_keys($arr))
229 . implode("', '", array_values($arr))
232 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
233 dbesc($arr['parent-uri']),
238 $parent_id = $r[0]['id'];
240 // if parent is missing, what do we do?
243 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
248 $current_post = $r[0]['id'];
250 $r = q("UPDATE `item` SET `parent` = %d WHERE `id` = %d LIMIT 1",
252 intval($current_post)
255 return $current_post;