]> git.mxchange.org Git - friendica.git/commitdiff
OStatus: Better attachment handling for pictures
authorMichael <heluecht@pirati.ca>
Thu, 7 Sep 2017 15:34:50 +0000 (15:34 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 7 Sep 2017 15:34:50 +0000 (15:34 +0000)
include/ostatus.php
include/text.php

index 809a48cd0260d73f9b8a3e45c1a64a3c8d673c98..5fcf2003c385f15b1c648692e7b26ca943acec75 100644 (file)
@@ -351,17 +351,11 @@ class ostatus {
                                continue;
                        }
 
-                       $item["body"] = add_page_info_to_body(html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue));
+                       $item["body"] = html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue);
+                       //$item["body"] = add_page_info_to_body(html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue));
                        $item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue;
                        $item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue;
 
-                       // Mastodon Content Warning
-                       if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
-                               $clear_text = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
-
-                               $item["body"] = html2bbcode($clear_text) . '[spoiler]' . $item["body"] . '[/spoiler]';
-                       }
-
                        if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
                                $item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
                                $item["body"] = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
@@ -464,7 +458,6 @@ class ostatus {
                        }
 
                        $self = "";
-                       $enclosure = "";
 
                        $links = $xpath->query('atom:link', $entry);
                        if ($links) {
@@ -488,14 +481,18 @@ class ostatus {
                                                                }
                                                                break;
                                                        case "enclosure":
-                                                               $enclosure = $attribute['href'];
-                                                               if (strlen($item["attach"])) {
-                                                                       $item["attach"] .= ',';
-                                                               }
-                                                               if (!isset($attribute['length'])) {
-                                                                       $attribute['length'] = "0";
+                                                               $filetype = strtolower(substr($attribute['type'], 0, strpos($attribute['type'],'/')));
+                                                               if ($filetype == 'image') {
+                                                                       $item['body'] .= "\n[img]".$attribute['href'].'[/img]';
+                                                               } else {
+                                                                       if (strlen($item["attach"])) {
+                                                                               $item["attach"] .= ',';
+                                                                       }
+                                                                       if (!isset($attribute['length'])) {
+                                                                               $attribute['length'] = "0";
+                                                                       }
+                                                                       $item["attach"] .= '[attach]href="'.$attribute['href'].'" length="'.$attribute['length'].'" type="'.$attribute['type'].'" title="'.$attribute['title'].'"[/attach]';
                                                                }
-                                                               $item["attach"] .= '[attach]href="'.$attribute['href'].'" length="'.$attribute['length'].'" type="'.$attribute['type'].'" title="'.$attribute['title'].'"[/attach]';
                                                                break;
                                                        case "related":
                                                                if ($item["object-type"] != ACTIVITY_OBJ_BOOKMARK) {
@@ -523,6 +520,18 @@ class ostatus {
                                }
                        }
 
+                       // Only add additional data when there is no picture in the post
+                       if (!strstr($item["body"],'[/img]')) {
+                               $item["body"] = add_page_info_to_body($item["body"]);
+                       }
+
+                       // Mastodon Content Warning
+                       if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
+                               $clear_text = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
+
+                               $item["body"] = html2bbcode($clear_text) . '[spoiler]' . $item["body"] . '[/spoiler]';
+                       }
+
                        $local_id = "";
                        $repeat_of = "";
 
@@ -601,7 +610,6 @@ class ostatus {
                                                foreach ($enclosures AS $link) {
                                                        $attribute = self::read_attributes($link);
                                                        if ($href != "") {
-                                                               $enclosure = $attribute['href'];
                                                                if (strlen($item["attach"])) {
                                                                        $item["attach"] .= ',';
                                                                }
@@ -615,9 +623,6 @@ class ostatus {
                                }
                        }
 
-                       //if ($enclosure != "")
-                       //      $item["body"] .= add_page_info($enclosure);
-
                        if (isset($item["parent-uri"])) {
                                $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
                                        intval($importer["uid"]), dbesc($item["parent-uri"]));
index c2c6dcdfc992d15f61d94c426559652024475d3b..66d4f17ea66ac5b20ef9c486f207d23dfa65e68a 100644 (file)
@@ -1424,15 +1424,8 @@ function prepare_body(&$item, $attach = false, $preview = false) {
                                        $title = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1]));
                                        $title .= ' ' . $mtch[2] . ' ' . t('bytes');
 
-                                       if (($filetype == 'image') AND ($item['network'] == NETWORK_OSTATUS)) {
-                                               /// @todo Respect the spoiler for mastodon
-                                               $icon = '<img class="attached" src="'.$the_url.'" alt="" title="'.$title.'">';
-                                               $s .= '<br><a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attached" target="_blank" >' . $icon . '</a>';
-                                       } else {
-                                               $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
-                                               $as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" >' . $icon . '</a>';
-                                       }
-
+                                       $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
+                                       $as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" >' . $icon . '</a>';
                                }
                        }
                }