require_once("include/Contact.php");
require_once("include/threads.php");
require_once("include/html2bbcode.php");
+require_once("include/bbcode.php");
require_once("include/items.php");
require_once("mod/share.php");
require_once("include/enotify.php");
require_once("include/Photo.php");
require_once("include/Scrape.php");
require_once("include/follow.php");
+require_once("mod/proxy.php");
define('OSTATUS_DEFAULT_POLL_INTERVAL', 30); // given in minutes
define('OSTATUS_DEFAULT_POLL_TIMEFRAME', 1440); // given in minutes
$value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue;
if ($value != "")
- $contact["about"] = $value;
+ $contact["about"] = html2bbcode($value);
$value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue;
if ($value != "")
$contact["location"] = $value;
- q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d",
+ q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d AND `network` = '%s'",
dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["about"]), dbesc($contact["location"]),
- dbesc(datetime_convert()), intval($contact["id"]));
+ dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS));
poco_check($contact["url"], $contact["name"], $contact["network"], $author["author-avatar"], $contact["about"], $contact["location"],
"", "", "", datetime_convert(), 2, $contact["id"], $contact["uid"]);
$photos = import_profile_photo($author["author-avatar"], $importer["uid"], $contact["id"]);
- q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
+ q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d AND `network` = '%s'",
dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
- dbesc(datetime_convert()), intval($contact["id"]));
+ dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS));
}
}
}
function xml_add_element($doc, $parent, $element, $value = "", $attributes = array()) {
- $element = $doc->createElement($element, $value);
+ $element = $doc->createElement($element, xmlify($value));
foreach ($attributes AS $key => $value) {
$attribute = $doc->createAttribute($key);
- $attribute->value = $value;
+ $attribute->value = xmlify($value);
$element->appendChild($attribute);
}
$parent->appendChild($element);
}
+function ostatus_format_picture_post($body) {
+ $siteinfo = get_attached_data($body);
+
+ if (($siteinfo["type"] == "photo")) {
+ if (isset($siteinfo["preview"]))
+ $preview = $siteinfo["preview"];
+ else
+ $preview = $siteinfo["image"];
+
+ // Is it a remote picture? Then make a smaller preview here
+ $preview = proxy_url($preview, false, PROXY_SIZE_SMALL);
+
+ // Is it a local picture? Then make it smaller here
+ $preview = str_replace(array("-0.jpg", "-0.png"), array("-2.jpg", "-2.png"), $preview);
+ $preview = str_replace(array("-1.jpg", "-1.png"), array("-2.jpg", "-2.png"), $preview);
+
+ if (isset($siteinfo["url"]))
+ $url = $siteinfo["url"];
+ else
+ $url = $siteinfo["image"];
+
+ $body = trim($siteinfo["text"])." [url]".$url."[/url]\n[img]".$preview."[/img]";
+ }
+
+ return $body;
+}
+
function ostatus_add_header($doc, $owner) {
$a = get_app();
$r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`",
- intval($owner["user_uid"]));
+ intval($owner["uid"]));
if (!$r)
return;
$root = $doc->createElementNS(NS_ATOM, 'feed');
$doc->appendChild($root);
- $root->setAttributeNS(NS_ATOM, "xmlns:thr", NS_THR);
- $root->setAttributeNS(NS_ATOM, "xmlns:georss", NS_GEORSS);
- $root->setAttributeNS(NS_ATOM, "xmlns:activity", NS_ACTIVITY);
- $root->setAttributeNS(NS_ATOM, "xmlns:media", NS_MEDIA);
- $root->setAttributeNS(NS_ATOM, "xmlns:poco", NS_POCO);
- $root->setAttributeNS(NS_ATOM, "xmlns:ostatus", NS_OSTATUS);
- $root->setAttributeNS(NS_ATOM, "xmlns:statusnet", NS_STATUSNET);
+ $root->setAttribute("xmlns:thr", NS_THR);
+ $root->setAttribute("xmlns:georss", NS_GEORSS);
+ $root->setAttribute("xmlns:activity", NS_ACTIVITY);
+ $root->setAttribute("xmlns:media", NS_MEDIA);
+ $root->setAttribute("xmlns:poco", NS_POCO);
+ $root->setAttribute("xmlns:ostatus", NS_OSTATUS);
+ $root->setAttribute("xmlns:statusnet", NS_STATUSNET);
$attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
xml_add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
break;
}
+ if (($siteinfo["type"] != "photo") AND isset($siteinfo["image"])) {
+ $photodata = get_photo_info($siteinfo["image"]);
+
+ $attributes = array("rel" => "preview", "href" => $siteinfo["image"], "media:width" => $photodata[0], "media:height" => $photodata[1]);
+ xml_add_element($doc, $root, "link", "", $attributes);
+ }
+
+
$arr = explode('[/attach],',$item['attach']);
if(count($arr)) {
foreach($arr as $r) {
$author = $doc->createElement("author");
xml_add_element($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
xml_add_element($doc, $author, "uri", $owner["url"]);
- xml_add_element($doc, $author, "name", $owner["nick"]);
+ xml_add_element($doc, $author, "name", $profile["name"]);
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $owner["url"]);
xml_add_element($doc, $author, "link", "", $attributes);
xml_add_element($doc, $author, "poco:preferredUsername", $owner["nick"]);
xml_add_element($doc, $author, "poco:displayName", $profile["name"]);
- xml_add_element($doc, $author, "poco:note", $profile["about"]);
+ xml_add_element($doc, $author, "poco:note", bbcode($profile["about"]));
if (trim($owner["location"]) != "") {
$element = $doc->createElement("poco:address");
}
xml_add_element($doc, $author, "followers", "", array("url" => $a->get_baseurl()."/viewcontacts/".$owner["nick"]));
- xml_add_element($doc, $author, "statusnet:profile_info", "", array("local_id" => $owner["user_uid"]));
+ xml_add_element($doc, $author, "statusnet:profile_info", "", array("local_id" => $owner["uid"]));
return $author;
}
+/*
+To-Do: Picture attachments should look like this:
+
+<a href="https://status.pirati.ca/attachment/572819" title="https://status.pirati.ca/file/heluecht-20151202T222602-rd3u49p.gif"
+class="attachment thumbnail" id="attachment-572819" rel="nofollow external">https://status.pirati.ca/attachment/572819</a>
+
+*/
+
function ostatus_entry($doc, $item, $owner, $toplevel = false) {
$a = get_app();
} else {
$entry = $doc->createElementNS(NS_ATOM, "entry");
- $entry->setAttributeNS(NS_ATOM, "xmlns:thr", NS_THR);
- $entry->setAttributeNS(NS_ATOM, "xmlns:georss", NS_GEORSS);
- $entry->setAttributeNS(NS_ATOM, "xmlns:activity", NS_ACTIVITY);
- $entry->setAttributeNS(NS_ATOM, "xmlns:media", NS_MEDIA);
- $entry->setAttributeNS(NS_ATOM, "xmlns:poco", NS_POCO);
- $entry->setAttributeNS(NS_ATOM, "xmlns:ostatus", NS_OSTATUS);
- $entry->setAttributeNS(NS_ATOM, "xmlns:statusnet", NS_STATUSNET);
+ $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["user_uid"]));
+ intval($owner["uid"]));
if (!$r)
return;
$title = sprintf("New comment by %s", $owner["nick"]);
}
- xml_add_element($doc, $entry, "activity:object-type", $item["object-type"]);
- xml_add_element($doc, $entry, "id", $item["uri"]); //<id>tag:fresh.federati.net,2015-11-22:noticeId=324796:objectType=note</id>
+ // 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'])
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",
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']);
"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"]));
if(count($tags))
foreach($tags as $t)
if ($t[0] == "@")
- xml_add_element($doc, $entry, "link", "", array("rel" => "mentioned",
+ $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" => $t[1]));
+ "href" => $mention));
+ }
if (!$item["private"])
xml_add_element($doc, $entry, "link", "", array("rel" => "mentioned",
// 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" => "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);
+ //$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 == "")
function ostatus_feed(&$a, $owner_nick, $last_update) {
- $r = q("SELECT `contact`.*, `user`.`uid` AS `user_uid`, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`
+ $r = q("SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`
FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
WHERE `contact`.`self` AND `user`.`nickname` = '%s' LIMIT 1",
dbesc($owner_nick));
AND (`item`.`owner-link` IN ('%s', '%s'))
ORDER BY `item`.`received` DESC
LIMIT 0, 300",
- intval($owner["user_uid"]), dbesc($check_date),
+ intval($owner["uid"]), dbesc($check_date),
dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS),
dbesc($owner["nurl"]), dbesc(str_replace("http://", "https://", $owner["nurl"]))
);
$root->appendChild($entry);
}
- return($doc->saveXML());
+ return(trim($doc->saveXML()));
}
function ostatus_salmon($item,$owner) {
$doc->appendChild($entry);
- return($doc->saveXML());
+ return(trim($doc->saveXML()));
}
?>