From 07fd61b91230b6c80b2cd602291a1005d127827d Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 1 Apr 2017 23:39:19 +0000 Subject: [PATCH] Mastodon: plink for reshares, missing hostnames for avatars --- include/ostatus.php | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index e6087de087..5329d98e6b 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -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;