Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}