]> git.mxchange.org Git - friendica.git/blobdiff - include/ostatus.php
Issue 2122: Make sure to always return the correct number of entries
[friendica.git] / include / ostatus.php
index ce254ed61ad012328d362234882b6738c03c5cea..932fc1fa9a7ea142fe06518c14e50fab657e16e9 100644 (file)
@@ -9,6 +9,7 @@ require_once("include/socgraph.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
@@ -1089,6 +1090,33 @@ function xml_add_element($doc, $parent, $element, $value = "", $attributes = arr
        $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();
 
@@ -1201,6 +1229,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 +1265,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 +1310,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();
 
@@ -1324,9 +1368,12 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false) {
        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"));
@@ -1440,7 +1487,7 @@ function ostatus_feed(&$a, $owner_nick, $last_update) {
                $root->appendChild($entry);
        }
 
-       return($doc->saveXML());
+       return(trim($doc->saveXML()));
 }
 
 function ostatus_salmon($item,$owner) {
@@ -1452,6 +1499,6 @@ function ostatus_salmon($item,$owner) {
 
        $doc->appendChild($entry);
 
-       return($doc->saveXML());
+       return(trim($doc->saveXML()));
 }
 ?>