From 17f15e793f1507b7988dea970b4a6784ee68c6d8 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 12 Dec 2016 06:46:02 +0000 Subject: [PATCH 1/2] Issue 2999: Better Mastodon handling --- include/items.php | 4 ++++ include/socgraph.php | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/items.php b/include/items.php index 0445c4490c..c2c4c10293 100644 --- a/include/items.php +++ b/include/items.php @@ -280,6 +280,10 @@ function add_page_info_to_body($body, $texturl = false, $no_photos = false) { $URLSearchString = "^\[\]"; + // Fix for Mastodon where the mentions are in a different format + $body = preg_replace("/\[url\=([$URLSearchString]*)\]([#!@])(.*?)\[\/url\]/ism", + '$2[url=$1]$3[/url]', $body); + // Adding these spaces is a quick hack due to my problems with regular expressions :) preg_match("/[^!#@]\[url\]([$URLSearchString]*)\[\/url\]/ism", " ".$body, $matches); diff --git a/include/socgraph.php b/include/socgraph.php index 421a68cc9e..f138843538 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -391,6 +391,15 @@ function poco_detect_server($profile) { } } + // Mastodon + if ($server_url == "") { + $red = preg_replace("=(https?://)(.*)/users/(.*)=ism", "$1$2", $profile); + if ($red != $profile) { + $server_url = $red; + $network = NETWORK_OSTATUS; + } + } + return $server_url; } @@ -723,7 +732,6 @@ function poco_check_server($server_url, $network = "", $force = false) { if (!$serverret["success"] OR ($serverret["body"] == "") OR (@sizeof($xmlobj) == 0) OR !is_object($xmlobj)) { $server_url = str_replace("https://", "http://", $server_url); $serverret = z_fetch_url($server_url."/.well-known/host-meta"); - $xmlobj = @simplexml_load_string($serverret["body"],'SimpleXMLElement',0, "http://docs.oasis-open.org/ns/xri/xrd-1.0"); } @@ -755,6 +763,13 @@ function poco_check_server($server_url, $network = "", $force = false) { $versionparts = explode("-", $version); $version = $versionparts[0]; } + + if(stristr($line,'Server: Mastodon')) { + $platform = "Mastodon"; + $network = NETWORK_OSTATUS; + // Mastodon doesn't reveal version numbers + $version = ""; + } } } } From 73e330abbe38a1a70ae247279f6d8ae84ee21261 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 12 Dec 2016 06:51:08 +0000 Subject: [PATCH 2/2] Restore empty line --- include/socgraph.php | 1 + 1 file changed, 1 insertion(+) diff --git a/include/socgraph.php b/include/socgraph.php index f138843538..765ed5d891 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -732,6 +732,7 @@ function poco_check_server($server_url, $network = "", $force = false) { if (!$serverret["success"] OR ($serverret["body"] == "") OR (@sizeof($xmlobj) == 0) OR !is_object($xmlobj)) { $server_url = str_replace("https://", "http://", $server_url); $serverret = z_fetch_url($server_url."/.well-known/host-meta"); + $xmlobj = @simplexml_load_string($serverret["body"],'SimpleXMLElement',0, "http://docs.oasis-open.org/ns/xri/xrd-1.0"); }