]> git.mxchange.org Git - friendica.git/blobdiff - include/ostatus.php
Merge pull request #2130 from annando/1512-contact-rework
[friendica.git] / include / ostatus.php
index 875e1527e29103a8c19fa53531361f6256c36ed5..07eaec85d50f4b962a3b281507e84606ade94ce9 100644 (file)
@@ -146,9 +146,9 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch)
                        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"]);
@@ -161,9 +161,9 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch)
 
                        $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));
                }
        }
 
@@ -1201,6 +1201,14 @@ function ostatus_get_attachment($doc, $root, $item) {
                        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) {
@@ -1229,7 +1237,7 @@ function ostatus_add_author($doc, $owner, $profile) {
        $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);
@@ -1274,6 +1282,14 @@ function ostatus_add_author($doc, $owner, $profile) {
        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();
 
@@ -1304,8 +1320,19 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false) {
                $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'])
@@ -1316,6 +1343,7 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false) {
        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"));
@@ -1371,13 +1399,13 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false) {
 
        // 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 == "")
@@ -1429,7 +1457,7 @@ function ostatus_feed(&$a, $owner_nick, $last_update) {
                $root->appendChild($entry);
        }
 
-       return($doc->saveXML());
+       return(trim($doc->saveXML()));
 }
 
 function ostatus_salmon($item,$owner) {
@@ -1441,6 +1469,6 @@ function ostatus_salmon($item,$owner) {
 
        $doc->appendChild($entry);
 
-       return($doc->saveXML());
+       return(trim($doc->saveXML()));
 }
 ?>