]> git.mxchange.org Git - friendica.git/commitdiff
Mastodon: plink for reshares, missing hostnames for avatars
authorMichael <heluecht@pirati.ca>
Sat, 1 Apr 2017 23:39:19 +0000 (23:39 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 1 Apr 2017 23:39:19 +0000 (23:39 +0000)
include/ostatus.php

index e6087de0873e0e85aa4ac7796cf509a7b6277354..5329d98e6bd27bfe36cae1c28bdcafb48b63bc41 100644 (file)
@@ -27,6 +27,38 @@ class ostatus {
        const OSTATUS_DEFAULT_POLL_TIMEFRAME = 1440; // given in minutes
        const OSTATUS_DEFAULT_POLL_TIMEFRAME_MENTIONS = 14400; // given in minutes
 
+       /**
+        * @brief Mix two paths together to possibly fix missing parts
+        *
+        * @param string $avatar Path to the avatar
+        * @param string $base Another path that is hopefully complete
+        *
+        * @return string fixed avatar path
+        */
+       private static function fix_avatar($avatar, $base) {
+               $base_parts = parse_url($base);
+
+               // Remove all parts that could create a problem
+               unset($base_parts['path']);
+               unset($base_parts['query']);
+               unset($base_parts['fragment']);
+
+               $avatar_parts = parse_url($avatar);
+
+               // Now we mix them
+               $parts = array_merge($base_parts, $avatar_parts);
+
+               // And put them together again
+               $scheme   = isset($parts['scheme']) ? $parts['scheme'] . '://' : '';
+               $host     = isset($parts['host']) ? $parts['host'] : '';
+               $port     = isset($parts['port']) ? ':' . $parts['port'] : '';
+               $path     = isset($parts['path']) ? $parts['path'] : '';
+               $query    = isset($parts['query']) ? '?' . $parts['query'] : '';
+               $fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : '';
+
+               return $scheme.$host.$port.$path.$query.$fragment;
+       }
+
        /**
         * @brief Fetches author data
         *
@@ -77,7 +109,7 @@ class ostatus {
                }
                if (count($avatarlist) > 0) {
                        krsort($avatarlist);
-                       $author["author-avatar"] = current($avatarlist);
+                       $author["author-avatar"] = self::fix_avatar(current($avatarlist), $author["author-link"]);
                }
 
                $displayname = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue;
@@ -499,13 +531,17 @@ class ostatus {
 
                                        $item["author-name"] = $orig_author["author-name"];
                                        $item["author-link"] = $orig_author["author-link"];
-                                       $item["author-avatar"] = $orig_author["author-avatar"];
+                                       $item["author-avatar"] = self::fix_avatar($orig_author["author-avatar"], $orig_author["author-link"]);
+
                                        $item["body"] = add_page_info_to_body(html2bbcode($orig_body));
                                        $item["created"] = $orig_created;
                                        $item["edited"] = $orig_edited;
 
                                        $item["uri"] = $orig_uri;
-                                       $item["plink"] = $orig_link;
+
+                                       if (!isset($item["plink"])) {
+                                               $item["plink"] = $orig_link;
+                                       }
 
                                        $item["verb"] = $xpath->query('activity:verb/text()', $activityobjects)->item(0)->nodeValue;