From 925c03fda8e6e14b68011570968c88f40605da5d Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 6 Dec 2017 20:09:59 +0000 Subject: [PATCH 1/3] Retrieve data about Mastodon servers --- doc/htconfig.md | 1 + src/Protocol/PortableContact.php | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/doc/htconfig.md b/doc/htconfig.md index 3f5b28b91..10536141c 100644 --- a/doc/htconfig.md +++ b/doc/htconfig.md @@ -46,6 +46,7 @@ Example: To set the directory value please add this line to your .htconfig.php: * **frontend_worker_timeout** - Value in minutes after we think that a frontend task was killed by the webserver. Default value is 10. * **hsts** (Boolean) - Enables the sending of HTTP Strict Transport Security headers * **ignore_cache** (Boolean) - For development only. Disables the item cache. +* **instances_social_key** - Key to the API of https://instances.social which retrieves data about mastodon servers. * **ipv4_resolve** (Boolean) - Resolve IPV4 addresses only. Don't resolve to IPV6. Default value is false. * **like_no_comment** (Boolean) - Don't update the "commented" value of an item when it is liked. * **local_block** (Boolean) - Used in conjunction with "block_public". diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index feb4dfdc8..84bfd4c4f 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -1343,14 +1343,17 @@ class PortableContact // Disvover Mastodon servers if (!Config::get('system', 'ostatus_disabled')) { - $serverdata = fetch_url("https://instances.mastodon.xyz/instances.json"); - - if ($serverdata) { - $servers = json_decode($serverdata); - - foreach ($servers as $server) { - $url = (is_null($server->https_score) ? 'http' : 'https').'://'.$server->name; - Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $url); + $accesstoken = Config::get('system', 'instances_social_key'); + if (!empty($accesstoken)) { + $api = 'https://instances.social/api/1.0/instances/list?count=0'; + $header = array('Authorization: Bearer '.$accesstoken); + $serverdata = z_fetch_url($api, false, $redirects, ['headers' => $header]); + if ($serverdata['success']) { + $servers = json_decode($serverdata['body']); + foreach ($servers->instances as $server) { + $url = (is_null($server->https_score) ? 'http' : 'https').'://'.$server->name; + Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $url); + } } } } From e272a5b8470bb9f3e75f63cbbb2fbe300c84d96b Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 6 Dec 2017 20:23:39 +0000 Subject: [PATCH 2/3] Added documentation --- doc/htconfig.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/htconfig.md b/doc/htconfig.md index 10536141c..b78cf7fe3 100644 --- a/doc/htconfig.md +++ b/doc/htconfig.md @@ -46,7 +46,7 @@ Example: To set the directory value please add this line to your .htconfig.php: * **frontend_worker_timeout** - Value in minutes after we think that a frontend task was killed by the webserver. Default value is 10. * **hsts** (Boolean) - Enables the sending of HTTP Strict Transport Security headers * **ignore_cache** (Boolean) - For development only. Disables the item cache. -* **instances_social_key** - Key to the API of https://instances.social which retrieves data about mastodon servers. +* **instances_social_key** - Key to the API of https://instances.social which retrieves data about mastodon servers. See https://instances.social/api/token for getting an API key. * **ipv4_resolve** (Boolean) - Resolve IPV4 addresses only. Don't resolve to IPV6. Default value is false. * **like_no_comment** (Boolean) - Don't update the "commented" value of an item when it is liked. * **local_block** (Boolean) - Used in conjunction with "block_public". From 4268f424123765f82b05d4665b3834514549c951 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 6 Dec 2017 20:26:33 +0000 Subject: [PATCH 3/3] Grammar ... --- doc/htconfig.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/htconfig.md b/doc/htconfig.md index b78cf7fe3..4d7816f49 100644 --- a/doc/htconfig.md +++ b/doc/htconfig.md @@ -46,7 +46,7 @@ Example: To set the directory value please add this line to your .htconfig.php: * **frontend_worker_timeout** - Value in minutes after we think that a frontend task was killed by the webserver. Default value is 10. * **hsts** (Boolean) - Enables the sending of HTTP Strict Transport Security headers * **ignore_cache** (Boolean) - For development only. Disables the item cache. -* **instances_social_key** - Key to the API of https://instances.social which retrieves data about mastodon servers. See https://instances.social/api/token for getting an API key. +* **instances_social_key** - Key to the API of https://instances.social which retrieves data about mastodon servers. See https://instances.social/api/token to get an API key. * **ipv4_resolve** (Boolean) - Resolve IPV4 addresses only. Don't resolve to IPV6. Default value is false. * **like_no_comment** (Boolean) - Don't update the "commented" value of an item when it is liked. * **local_block** (Boolean) - Used in conjunction with "block_public".