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'
72 ORDER BY `parent` ASC, `created` ASC LIMIT 0, 300",
81 $feed_template = file_get_contents('view/atom_feed.tpl');
82 $tomb_template = file_get_contents('view/atom_tomb.tpl');
83 $item_template = file_get_contents('view/atom_item.tpl');
84 $cmnt_template = file_get_contents('view/atom_cmnt.tpl');
89 $atom .= replace_macros($feed_template, array(
90 '$feed_id' => xmlify($a->get_baseurl()),
91 '$feed_title' => xmlify($owner['name']),
92 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
93 '$name' => xmlify($owner['name']),
94 '$profile_page' => xmlify($owner['url']),
95 '$photo' => xmlify($owner['photo']),
96 '$thumb' => xmlify($owner['thumb']),
97 '$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
98 '$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
99 '$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
103 foreach($items as $item) {
104 if($item['deleted']) {
105 $atom .= replace_macros($tomb_template, array(
106 '$id' => xmlify($item['uri']),
107 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
111 if($item['parent'] == $item['id']) {
112 $atom .= replace_macros($item_template, array(
113 '$name' => xmlify($item['name']),
114 '$profile_page' => xmlify($item['url']),
115 '$thumb' => xmlify($item['thumb']),
116 '$owner_name' => xmlify($item['owner-name']),
117 '$owner_profile_page' => xmlify($item['owner-link']),
118 '$owner_thumb' => xmlify($item['owner-avatar']),
119 '$item_id' => xmlify($item['uri']),
120 '$title' => xmlify($item['title']),
121 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
122 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
123 '$location' => xmlify($item['location']),
124 '$content' => xmlify($item['body']),
125 '$comment_allow' => (($item['last-child'] && strlen($contact['dfrn-id'])) ? 1 : 0)
129 $atom .= replace_macros($cmnt_template, array(
130 '$name' => xmlify($item['name']),
131 '$profile_page' => xmlify($item['url']),
132 '$thumb' => xmlify($item['thumb']),
133 '$item_id' => xmlify($item['uri']),
134 '$title' => xmlify($item['title']),
135 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
136 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
137 '$content' =>xmlify($item['body']),
138 '$parent_id' => xmlify($item['parent-uri']),
139 '$comment_allow' => (($item['last-child']) ? 1 : 0)
145 $atom .= '</feed>' . "\r\n";
152 function get_atom_elements($item) {
156 $author = $item->get_author();
157 $res['author-name'] = unxmlify($author->get_name());
158 $res['author-link'] = unxmlify($author->get_link());
159 $res['author-avatar'] = unxmlify($author->get_avatar());
160 $res['uri'] = unxmlify($item->get_id());
161 $res['title'] = unxmlify($item->get_title());
162 $res['body'] = unxmlify($item->get_content());
164 $maxlen = get_max_import_size();
165 if($maxlen && (strlen($res['body']) > $maxlen))
166 $res['body'] = substr($res['body'],0, $maxlen);
168 $allow = $item->get_item_tags(NAMESPACE_DFRN,'comment-allow');
169 if($allow && $allow[0]['data'] == 1)
170 $res['last-child'] = 1;
172 $res['last-child'] = 0;
174 $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
176 $res['created'] = unxmlify($rawcreated[0]['data']);
178 $rawlocation = $item->get_item_tags('http://activitystrea.ms/spec/1.0/', 'place');
180 $res['location'] = unxmlify($rawlocation[0]['data']);
183 $rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'updated');
185 $res['edited'] = unxmlify($rawcreated[0]['data']);
187 $rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner');
188 if($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data'])
189 $res['owner-name'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']);
190 if($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data'])
191 $res['owner-link'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']);
192 if($rawowner[0]['child'][NAMESPACE_DFRN]['avatar'][0]['data'])
193 $res['owner-avatar'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['avatar'][0]['data']);
198 function post_remote($a,$arr) {
202 $arr['type'] = 'remote';
203 $arr['uri'] = notags(trim($arr['uri']));
204 $arr['author-name'] = notags(trim($arr['author-name']));
205 $arr['author-link'] = notags(trim($arr['author-link']));
206 $arr['author-avatar'] = notags(trim($arr['author-avatar']));
207 $arr['owner-name'] = notags(trim($arr['owner-name']));
208 $arr['owner-link'] = notags(trim($arr['owner-link']));
209 $arr['owner-avatar'] = notags(trim($arr['owner-avatar']));
210 $arr['created'] = datetime_convert('UTC','UTC',$arr['created'],'Y-m-d H:i:s');
211 $arr['edited'] = datetime_convert('UTC','UTC',$arr['edited'],'Y-m-d H:i:s');
212 $arr['title'] = notags(trim($arr['title']));
213 $arr['location'] = notags(trim($arr['location']));
214 $arr['body'] = escape_tags(trim($arr['body']));
215 $arr['last-child'] = intval($arr['last-child']);
218 $arr['parent-uri'] = notags(trim($arr['parent-uri']));
224 $r = q("INSERT INTO `item` (`"
225 . implode("`, `", array_keys($arr))
227 . implode("', '", array_values($arr))
230 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
231 dbesc($arr['parent-uri']),
236 $parent_id = $r[0]['id'];
238 // if parent is missing, what do we do?
241 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
246 $current_post = $r[0]['id'];
248 $r = q("UPDATE `item` SET `parent` = %d WHERE `id` = %d LIMIT 1",
250 intval($current_post)
253 return $current_post;