function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) { if (!$item['parent']) { return; } if ($item['deleted']) { return '<at:deleted-entry ref="' . xmlify($item['mid']) . '" when="' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '" />' . "\r\n"; } if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) { $body = fix_private_photos($item['body'], $owner['uid'], $item, $cid); } else { $body = $item['body']; } $o = "\r\n\r\n<entry>\r\n"; if (is_array($author)) { $o .= atom_author('author', $author['xchan_name'], $author['xchan_url'], 80, 80, $author['xchan_photo_mimetype'], $author['xchan_photo_m']); } else { $o .= atom_author('author', $item['author']['xchan_name'], $item['author']['xchan_url'], 80, 80, $item['author']['xchan_photo_mimetype'], $item['author']['xchan_photo_m']); } $o .= atom_author('zot:owner', $item['owner']['xchan_name'], $item['owner']['xchan_url'], 80, 80, $item['owner']['xchan_photo_mimetype'], $item['owner']['xchan_photo_m']); if ($item['parent'] != $item['id'] || $item['parent_mid'] !== $item['mid'] || $item['thr_parent'] !== '' && $item['thr_parent'] !== $item['mid']) { $parent_item = $item['thr_parent'] ? $item['thr_parent'] : $item['parent_mid']; $o .= '<thr:in-reply-to ref="' . xmlify($parent_item) . '" type="text/html" href="' . xmlify($item['plink']) . '" />' . "\r\n"; } $o .= '<id>' . xmlify($item['mid']) . '</id>' . "\r\n"; $o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n"; $o .= '<published>' . xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', ATOM_TIME)) . '</published>' . "\r\n"; $o .= '<updated>' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '</updated>' . "\r\n"; $o .= '<content type="' . $type . '" >' . xmlify(prepare_text($body, $item['mimetype'])) . '</content>' . "\r\n"; $o .= '<link rel="alternate" type="text/html" href="' . xmlify($item['plink']) . '" />' . "\r\n"; if ($item['location']) { $o .= '<zot:location>' . xmlify($item['location']) . '</zot:location>' . "\r\n"; $o .= '<poco:address><poco:formatted>' . xmlify($item['location']) . '</poco:formatted></poco:address>' . "\r\n"; } if ($item['coord']) { $o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n"; } if ($item['item_private'] || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) { $o .= '<zot:private>' . ($item['item_private'] ? $item['item_private'] : 1) . '</zot:private>' . "\r\n"; } if ($item['app']) { $o .= '<statusnet:notice_info local_id="' . $item['id'] . '" source="' . xmlify($item['app']) . '" ></statusnet:notice_info>' . "\r\n"; } $verb = construct_verb($item); $o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n"; $actobj = construct_activity_object($item); if (strlen($actobj)) { $o .= $actobj; } $actarg = construct_activity_target($item); if (strlen($actarg)) { $o .= $actarg; } // FIXME // $tags = item_getfeedtags($item); // if(count($tags)) { // foreach($tags as $t) { // $o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n"; // } // } // FIXME // $o .= item_getfeedattach($item); // $mentioned = get_mentions($item,$tags); // if($mentioned) // $o .= $mentioned; call_hooks('atom_entry', $o); $o .= '</entry>' . "\r\n"; return $o; }
function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update) { require_once 'bbcode.php'; // default permissions - anonymous user $sql_extra = " \n\t\tAND `allow_cid` = '' \n\t\tAND `allow_gid` = '' \n\t\tAND `deny_cid` = '' \n\t\tAND `deny_gid` = '' \n\t"; if (strlen($owner_id) && !intval($owner_id)) { $r = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1", dbesc($owner_id)); if (count($r)) { $owner_id = $r[0]['uid']; $owner_nick = $r[0]['nickname']; } } $r = q("SELECT * FROM `contact` WHERE `self` = 1 LIMIT 1"); if (count($r)) { $owner = $r[0]; } else { killme(); } if ($dfrn_id != '*') { $r = q("SELECT * FROM `contact` WHERE ( `issued-id` = '%s' OR ( `duplex` = 1 AND `dfrn-id` = '%s' )) LIMIT 1", dbesc($dfrn_id), dbesc($dfrn_id)); if (!count($r)) { return false; } $contact = $r[0]; $groups = init_groups_visitor($contact['id']); if (count($groups)) { for ($x = 0; $x < count($groups); $x++) { $groups[$x] = '<' . intval($groups[$x]) . '>'; } $gs = implode('|', $groups); } else { $gs = '<<>>'; } // Impossible to match $sql_extra = sprintf(" \n\t\t\tAND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) \n\t\t\tAND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' ) \n\t\t\tAND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )\n\t\t\tAND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') \n\t\t", intval($contact['id']), intval($contact['id']), dbesc($gs), dbesc($gs)); } if ($dfrn_id == '' || $dfrn_id == '*') { $sort = 'DESC'; } else { $sort = 'ASC'; } if (!strlen($last_update)) { $last_update = 'now - 30 days'; } $check_date = datetime_convert('UTC', 'UTC', $last_update, 'Y-m-d H:i:s'); $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, \n\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, \n\t\t`contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,\n\t\t`contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, \n\t\t`contact`.`id` AS `contact-id`\n\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\tWHERE `item`.`visible` = 1 \n\t\tAND NOT `item`.`type` IN ( 'remote', 'net-comment' ) AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\tAND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' )\n\t\t{$sql_extra}\n\t\tORDER BY `parent` %s, `created` ASC LIMIT 0, 300", dbesc($check_date), dbesc($check_date), dbesc($sort)); if (!count($r)) { killme(); } $items = $r; $feed_template = file_get_contents('view/atom_feed.tpl'); $tomb_template = file_get_contents('view/atom_tomb.tpl'); $item_template = file_get_contents('view/atom_item.tpl'); $cmnt_template = file_get_contents('view/atom_cmnt.tpl'); $atom = ''; $atom .= replace_macros($feed_template, array('$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner_nick), '$feed_title' => xmlify($owner['name']), '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$name' => xmlify($owner['name']), '$profile_page' => xmlify($owner['url']), '$photo' => xmlify($owner['photo']), '$thumb' => xmlify($owner['thumb']), '$picdate' => xmlify(datetime_convert('UTC', 'UTC', $owner['avatar-date'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$uridate' => xmlify(datetime_convert('UTC', 'UTC', $owner['uri-date'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$namdate' => xmlify(datetime_convert('UTC', 'UTC', $owner['name-date'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')))); foreach ($items as $item) { // public feeds get html, our own nodes use bbcode if ($dfrn_id == '*') { $item['body'] = bbcode($item['body']); $type = 'html'; } else { $type = 'text'; } if ($item['deleted']) { $atom .= replace_macros($tomb_template, array('$id' => xmlify($item['uri']), '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')))); } else { $verb = construct_verb($item); $actobj = construct_activity($item); if ($item['parent'] == $item['id']) { $atom .= replace_macros($item_template, array('$name' => xmlify($item['name']), '$profile_page' => xmlify($item['url']), '$thumb' => xmlify($item['thumb']), '$owner_name' => xmlify($item['owner-name']), '$owner_profile_page' => xmlify($item['owner-link']), '$owner_thumb' => xmlify($item['owner-avatar']), '$item_id' => xmlify($item['uri']), '$title' => xmlify($item['title']), '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$location' => xmlify($item['location']), '$type' => $type, '$content' => xmlify($item['body']), '$verb' => xmlify($verb), '$actobj' => $actobj, '$comment_allow' => $item['last-child'] && strlen($contact['dfrn-id']) ? 1 : 0)); } else { $atom .= replace_macros($cmnt_template, array('$name' => xmlify($item['name']), '$profile_page' => xmlify($item['url']), '$thumb' => xmlify($item['thumb']), '$item_id' => xmlify($item['uri']), '$title' => xmlify($item['title']), '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$type' => $type, '$content' => xmlify($item['body']), '$verb' => xmlify($verb), '$actobj' => $actobj, '$parent_id' => xmlify($item['parent-uri']), '$comment_allow' => $item['last-child'] ? 1 : 0)); } } } $atom .= '</feed>' . "\r\n"; return $atom; }
function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) { $a = get_app(); if (!$item['parent']) { return; } if ($item['deleted']) { return '<at:deleted-entry ref="' . xmlify($item['uri']) . '" when="' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '" />' . "\r\n"; } if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) { $body = fix_private_photos($item['body'], $owner['uid'], $item, $cid); } else { $body = $item['body']; } $o = "\r\n\r\n<entry>\r\n"; if (is_array($author)) { $o .= atom_author('author', $author['name'], $author['url'], 80, 80, $author['thumb'], $item['coord']); } else { $o .= atom_author('author', $item['author-name'] ? $item['author-name'] : $item['name'], $item['author-link'] ? $item['author-link'] : $item['url'], 80, 80, $item['author-avatar'] ? $item['author-avatar'] : $item['thumb'], $item['coord']); } if (strlen($item['owner-name'])) { $o .= atom_author('dfrn:owner', $item['owner-name'], $item['owner-link'], 80, 80, $item['owner-avatar'], $item['coord']); } if ($item['parent'] != $item['id'] || $item['parent-uri'] !== $item['uri'] || $item['thr-parent'] !== '' && $item['thr-parent'] !== $item['uri']) { $parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"])); $parent_item = $item['thr-parent'] ? $item['thr-parent'] : $item['parent-uri']; $o .= '<thr:in-reply-to ref="' . xmlify($parent_item) . '" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $parent[0]['guid']) . '" />' . "\r\n"; } $htmlbody = $body; if ($item['title'] != "") { $htmlbody = "[b]" . $item['title'] . "[/b]\n\n" . $htmlbody; } $htmlbody = bbcode($htmlbody, false, false, 7); $o .= '<id>' . xmlify($item['uri']) . '</id>' . "\r\n"; $o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n"; $o .= '<published>' . xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', ATOM_TIME)) . '</published>' . "\r\n"; $o .= '<updated>' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '</updated>' . "\r\n"; $o .= '<dfrn:env>' . base64url_encode($body, true) . '</dfrn:env>' . "\r\n"; $o .= '<content type="' . $type . '" >' . xmlify($type === 'html' ? $htmlbody : $body) . '</content>' . "\r\n"; $o .= '<link rel="alternate" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $item['guid']) . '" />' . "\r\n"; $o .= '<status_net notice_id="' . $item['id'] . '"></status_net>' . "\r\n"; if ($comment) { $o .= '<dfrn:comment-allow>' . intval($item['last-child']) . '</dfrn:comment-allow>' . "\r\n"; } if ($item['location']) { $o .= '<dfrn:location>' . xmlify($item['location']) . '</dfrn:location>' . "\r\n"; $o .= '<poco:address><poco:formatted>' . xmlify($item['location']) . '</poco:formatted></poco:address>' . "\r\n"; } if ($item['coord']) { $o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n"; } if ($item['private'] || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) { $o .= '<dfrn:private>' . ($item['private'] ? $item['private'] : 1) . '</dfrn:private>' . "\r\n"; } if ($item['extid']) { $o .= '<dfrn:extid>' . xmlify($item['extid']) . '</dfrn:extid>' . "\r\n"; } if ($item['bookmark']) { $o .= '<dfrn:bookmark>true</dfrn:bookmark>' . "\r\n"; } if ($item['app']) { $o .= '<statusnet:notice_info local_id="' . $item['id'] . '" source="' . xmlify($item['app']) . '" ></statusnet:notice_info>' . "\r\n"; } if ($item['guid']) { $o .= '<dfrn:diaspora_guid>' . $item['guid'] . '</dfrn:diaspora_guid>' . "\r\n"; } if ($item['signed_text']) { $sign = base64_encode(json_encode(array('signed_text' => $item['signed_text'], 'signature' => $item['signature'], 'signer' => $item['signer']))); $o .= '<dfrn:diaspora_signature>' . xmlify($sign) . '</dfrn:diaspora_signature>' . "\r\n"; } $verb = construct_verb($item); $o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n"; $actobj = construct_activity_object($item); if (strlen($actobj)) { $o .= $actobj; } $actarg = construct_activity_target($item); if (strlen($actarg)) { $o .= $actarg; } $tags = item_getfeedtags($item); if (count($tags)) { foreach ($tags as $t) { if ($type != 'html' or $t[0] != "@") { $o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n"; } } } // To-Do: // To support these elements, the API needs to be enhanced //$o .= '<link rel="ostatus:conversation" href="'.xmlify($a->get_baseurl().'/display/'.$owner['nickname'].'/'.$item['parent']).'"/>'."\r\n"; //$o .= "\t".'<link rel="self" type="application/atom+xml" href="'.xmlify($a->get_baseurl().'/api/statuses/show/'.$item['id'].'.atom').'"/>'."\r\n"; //$o .= "\t".'<link rel="edit" type="application/atom+xml" href="'.xmlify($a->get_baseurl().'/api/statuses/show/'.$item['id'].'.atom').'"/>'."\r\n"; // Deactivated since it was meant only for OStatus //$o .= item_get_attachment($item); $o .= item_getfeedattach($item); $mentioned = get_mentions($item); if ($mentioned) { $o .= $mentioned; } call_hooks('atom_entry', $o); $o .= '</entry>' . "\r\n"; return $o; }
function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) { $a = get_app(); if (!$item['parent']) { return; } if ($item['deleted']) { return '<at:deleted-entry ref="' . xmlify($item['uri']) . '" when="' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '" />' . "\r\n"; } if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) { $body = fix_private_photos($item['body'], $owner['uid'], $item, $cid); } else { $body = $item['body']; } $o = "\r\n\r\n<entry>\r\n"; if (is_array($author)) { $o .= atom_author('author', $author['name'], $author['url'], 80, 80, $author['thumb']); } else { $o .= atom_author('author', $item['author-name'] ? $item['author-name'] : $item['name'], $item['author-link'] ? $item['author-link'] : $item['url'], 80, 80, $item['author-avatar'] ? $item['author-avatar'] : $item['thumb']); } if (strlen($item['owner-name'])) { $o .= atom_author('dfrn:owner', $item['owner-name'], $item['owner-link'], 80, 80, $item['owner-avatar']); } if ($item['parent'] != $item['id'] || $item['parent-uri'] !== $item['uri']) { $o .= '<thr:in-reply-to ref="' . xmlify($item['parent-uri']) . '" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['parent']) . '" />' . "\r\n"; } $o .= '<id>' . xmlify($item['uri']) . '</id>' . "\r\n"; $o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n"; $o .= '<published>' . xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', ATOM_TIME)) . '</published>' . "\r\n"; $o .= '<updated>' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '</updated>' . "\r\n"; $o .= '<dfrn:env>' . base64url_encode($body, true) . '</dfrn:env>' . "\r\n"; $o .= '<content type="' . $type . '" >' . xmlify($type === 'html' ? bbcode($body) : $body) . '</content>' . "\r\n"; $o .= '<link rel="alternate" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n"; if ($comment) { $o .= '<dfrn:comment-allow>' . intval($item['last-child']) . '</dfrn:comment-allow>' . "\r\n"; } if ($item['location']) { $o .= '<dfrn:location>' . xmlify($item['location']) . '</dfrn:location>' . "\r\n"; $o .= '<poco:address><poco:formatted>' . xmlify($item['location']) . '</poco:formatted></poco:address>' . "\r\n"; } if ($item['coord']) { $o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n"; } if ($item['private'] || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) { $o .= '<dfrn:private>1</dfrn:private>' . "\r\n"; } if ($item['extid']) { $o .= '<dfrn:extid>' . xmlify($item['extid']) . '</dfrn:extid>' . "\r\n"; } if ($item['bookmark']) { $o .= '<dfrn:bookmark>true</dfrn:bookmark>' . "\r\n"; } if ($item['app']) { $o .= '<statusnet:notice_info local_id="' . $item['id'] . '" source="' . xmlify($item['app']) . '" ></statusnet:notice_info>' . "\r\n"; } if ($item['guid']) { $o .= '<dfrn:diaspora_guid>' . $item['guid'] . '</dfrn:diaspora_guid>' . "\r\n"; } if ($item['signed_text']) { $sign = base64_encode(json_encode(array('signed_text' => $item['signed_text'], 'signature' => $item['signature'], 'signer' => $item['signer']))); $o .= '<dfrn:diaspora_signature>' . xmlify($sign) . '</dfrn:diaspora_signature>' . "\r\n"; } $verb = construct_verb($item); $o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n"; $actobj = construct_activity_object($item); if (strlen($actobj)) { $o .= $actobj; } $actarg = construct_activity_target($item); if (strlen($actarg)) { $o .= $actarg; } $tags = item_getfeedtags($item); if (count($tags)) { foreach ($tags as $t) { $o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n"; } } $o .= item_getfeedattach($item); $mentioned = get_mentions($item); if ($mentioned) { $o .= $mentioned; } call_hooks('atom_entry', $o); $o .= '</entry>' . "\r\n"; return $o; }
killme(); } $contacts = $r; $tomb_template = file_get_contents('view/atom_tomb.tpl'); $item_template = file_get_contents('view/atom_item.tpl'); $cmnt_template = file_get_contents('view/atom_cmnt.tpl'); } $feed_template = file_get_contents('view/atom_feed.tpl'); $mail_template = file_get_contents('view/atom_mail.tpl'); $atom = ''; $atom .= replace_macros($feed_template, array('$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner['nickname']), '$feed_title' => xmlify($owner['name']), '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$name' => xmlify($owner['name']), '$profile_page' => xmlify($owner['url']), '$photo' => xmlify($owner['photo']), '$thumb' => xmlify($owner['thumb']), '$picdate' => xmlify(datetime_convert('UTC', 'UTC', $owner['avatar-date'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$uridate' => xmlify(datetime_convert('UTC', 'UTC', $owner['uri-date'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$namdate' => xmlify(datetime_convert('UTC', 'UTC', $owner['name-date'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')))); if ($cmd == 'mail') { $atom .= replace_macros($mail_template, array('$name' => xmlify($owner['name']), '$profile_page' => xmlify($owner['url']), '$thumb' => xmlify($owner['thumb']), '$item_id' => xmlify($item['uri']), '$subject' => xmlify($item['title']), '$created' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$content' => xmlify($item['body']), '$parent_id' => xmlify($item['parent-uri']))); } else { require_once 'include/items.php'; $verb = construct_verb($item); $actobj = construct_activity($item); if ($followup) { foreach ($items as $item) { if ($item['id'] == $item_id) { $atom .= replace_macros($cmnt_template, array('$name' => xmlify($owner['name']), '$profile_page' => xmlify($owner['url']), '$thumb' => xmlify($owner['thumb']), '$owner_name' => xmlify($item['owner-name']), '$owner_profile_page' => xmlify($item['owner-link']), '$owner_thumb' => xmlify($item['owner-avatar']), '$item_id' => xmlify($item['uri']), '$title' => xmlify($item['title']), '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')), '$location' => xmlify($item['location']), '$type' => 'text', '$verb' => xmlify($verb), '$actobj' => $actobj, '$content' => xmlify($item['body']), '$parent_id' => xmlify($item['parent-uri']), '$comment_allow' => 0)); } } } else { foreach ($items as $item) { if ($item['deleted']) { $atom .= replace_macros($tomb_template, array('$id' => xmlify($item['uri']), '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', 'Y-m-d\\TH:i:s\\Z')))); } else { foreach ($contacts as $contact) { if ($item['contact-id'] == $contact['id']) { if ($item['parent'] == $item['id']) {
function ostatus_entry($doc, $item, $owner, $toplevel = false) { $a = get_app(); if (!$toplevel) { $entry = $doc->createElement("entry"); $title = sprintf("New note by %s", $owner["nick"]); } else { $entry = $doc->createElementNS(NS_ATOM, "entry"); $entry->setAttribute("xmlns:thr", NS_THR); $entry->setAttribute("xmlns:georss", NS_GEORSS); $entry->setAttribute("xmlns:activity", NS_ACTIVITY); $entry->setAttribute("xmlns:media", NS_MEDIA); $entry->setAttribute("xmlns:poco", NS_POCO); $entry->setAttribute("xmlns:ostatus", NS_OSTATUS); $entry->setAttribute("xmlns:statusnet", NS_STATUSNET); $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`", intval($owner["uid"])); if (!$r) { return; } $profile = $r[0]; $author = ostatus_add_author($doc, $owner, $profile); $entry->appendChild($author); $title = sprintf("New comment by %s", $owner["nick"]); } // To use the object-type "bookmark" we have to implement these elements: // // <activity:object-type>http://activitystrea.ms/schema/1.0/bookmark</activity:object-type> // <title>Historic Rocket Landing</title> // <summary>Nur ein Testbeitrag.</summary> // <link rel="related" href="https://www.youtube.com/watch?v=9pillaOxGCo"/> // <link rel="preview" href="https://pirati.cc/file/thumb-4526-450x338-b48c8055f0c2fed0c3f67adc234c4b99484a90c42ed3cac73dc1081a4d0a7bc1.jpg.jpg" media:width="450" media:height="338"/> // // But: it seems as if it doesn't federate well between the GS servers // So we just set it to "note" to be sure that it reaches their target systems xml_add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE); xml_add_element($doc, $entry, "id", $item["uri"]); xml_add_element($doc, $entry, "title", $title); if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) { $body = fix_private_photos($item['body'], $owner['uid'], $item, 0); } else { $body = $item['body']; } $body = ostatus_format_picture_post($body); if ($item['title'] != "") { $body = "[b]" . $item['title'] . "[/b]\n\n" . $body; } //$body = bb_remove_share_information($body); $body = bbcode($body, false, false, 7); xml_add_element($doc, $entry, "content", $body, array("type" => "html")); xml_add_element($doc, $entry, "link", "", array("rel" => "alternate", "type" => "text/html", "href" => $a->get_baseurl() . "/display/" . $item["guid"])); xml_add_element($doc, $entry, "status_net", "", array("notice_id" => $item["id"])); xml_add_element($doc, $entry, "activity:verb", construct_verb($item)); xml_add_element($doc, $entry, "published", datetime_convert("UTC", "UTC", $item["created"] . "+00:00", ATOM_TIME)); xml_add_element($doc, $entry, "updated", datetime_convert("UTC", "UTC", $item["edited"] . "+00:00", ATOM_TIME)); $mentioned = array(); if ($item['parent'] != $item['id'] || $item['parent-uri'] !== $item['uri'] || $item['thr-parent'] !== '' && $item['thr-parent'] !== $item['uri']) { $parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"])); $parent_item = $item['thr-parent'] ? $item['thr-parent'] : $item['parent-uri']; $attributes = array("ref" => $parent_item, "type" => "text/html", "href" => $a->get_baseurl() . "/display/" . $parent[0]["guid"]); xml_add_element($doc, $entry, "thr:in-reply-to", "", $attributes); $attributes = array("rel" => "related", "href" => $a->get_baseurl() . "/display/" . $parent[0]["guid"]); xml_add_element($doc, $entry, "link", "", $attributes); $mentioned[$parent[0]["author-link"]] = $parent[0]["author-link"]; $mentioned[$parent[0]["owner-link"]] = $parent[0]["owner-link"]; $thrparent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", intval($owner["uid"]), dbesc($parent_item)); if ($thrparent) { $mentioned[$thrparent[0]["author-link"]] = $thrparent[0]["author-link"]; $mentioned[$thrparent[0]["owner-link"]] = $thrparent[0]["owner-link"]; } } xml_add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation", "href" => $a->get_baseurl() . "/display/" . $owner["nick"] . "/" . $item["parent"])); xml_add_element($doc, $entry, "ostatus:conversation", $a->get_baseurl() . "/display/" . $owner["nick"] . "/" . $item["parent"]); $tags = item_getfeedtags($item); if (count($tags)) { foreach ($tags as $t) { if ($t[0] == "@") { $mentioned[$t[1]] = $t[1]; } } } // Make sure that mentions are accepted (GNU Social has problems with mixing HTTP and HTTPS) $newmentions = array(); foreach ($mentioned as $mention) { $newmentions[str_replace("http://", "https://", $mention)] = str_replace("http://", "https://", $mention); $newmentions[str_replace("https://", "http://", $mention)] = str_replace("https://", "http://", $mention); } $mentioned = $newmentions; foreach ($mentioned as $mention) { $r = q("SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'", intval($owner["uid"]), dbesc(normalise_link($mention))); if ($r[0]["forum"] or $r[0]["prv"]) { xml_add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_GROUP, "href" => $mention)); } else { xml_add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_PERSON, "href" => $mention)); } } if (!$item["private"]) { xml_add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/collection", "href" => "http://activityschema.org/collection/public")); } if (count($tags)) { foreach ($tags as $t) { if ($t[0] != "@") { xml_add_element($doc, $entry, "category", "", array("term" => $t[2])); } } } ostatus_get_attachment($doc, $entry, $item); // To-Do: // The API call has yet to be implemented //$attributes = array("href" => $a->get_baseurl()."/api/statuses/show/".$item["id"].".atom", // "rel" => "self", "type" => "application/atom+xml"); //xml_add_element($doc, $entry, "link", "", $attributes); //$attributes = array("href" => $a->get_baseurl()."/api/statuses/show/".$item["id"].".atom", // "rel" => "edit", "type" => "application/atom+xml"); //xml_add_element($doc, $entry, "link", "", $attributes); $app = $item["app"]; if ($app == "") { $app = "web"; } xml_add_element($doc, $entry, "statusnet:notice_info", "", array("local_id" => $item["id"], "source" => $app)); return $entry; }