Example #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']);
    } 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;
}
Example #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'], $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;
}
Example #3
0
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;
}