From 7e6423ae177a04e16d2f3fde0d278b85a0527d5f Mon Sep 17 00:00:00 2001 From: iamdoubz <> Date: Thu, 30 Jan 2025 11:52:23 -0600 Subject: [PATCH] Remove external api dependency --- Diaspora/Diaspora.php | 169 ++++++++---------------------------------- Diaspora/app.json | 2 +- 2 files changed, 30 insertions(+), 141 deletions(-) diff --git a/Diaspora/Diaspora.php b/Diaspora/Diaspora.php index 546156d2db..6a01b76ca5 100644 --- a/Diaspora/Diaspora.php +++ b/Diaspora/Diaspora.php @@ -11,84 +11,26 @@ private function getBaseDomain($url) { $baseurl = str_replace('/', '', $baseurl); return $baseurl; } - private function fetchApi() { - $url = "https://api.fediverse.observer/"; + private function fetchNodeInfo() { $podurl = parent::normaliseurl($this->config->url); - $podurl = $this->getBaseDomain($podurl); - $query = 'query{ - node(domain: "' . $podurl . '"){ - id - name - metatitle - metadescription - detectedlanguage - metaimage - owner - onion - i2p - ip - ipv6 - greenhost - host - dnssec - sslexpire - servertype - camo - terms - pp - support - softwarename - shortversion - fullversion - masterversion - daysmonitored - monthsmonitored - date_updated - date_laststats - date_created - metalocation - country - city - state - zipcode - countryname - lat - long - uptime_alltime - latency - sslexpire - total_users - active_users_monthly - active_users_halfyear - local_posts - comment_counts - score - status - signup - podmin_statement - services - protocols - } - }'; - $data = array('query' => $query); + $nodeinfo = $podurl . '/nodeinfo/2.1'; $options = [ 'http' => [ - 'method' => 'POST', + 'method' => 'GET', 'header' => [ "Content-Type: application/json" - ], - 'content' => json_encode($data), + ] ], ]; $context = stream_context_create($options); - $res = file_get_contents($url, false, $context); - $rdata = json_decode($res, true); - return $rdata; + $res = file_get_contents($nodeinfo, false, $context); + $RawDetails = json_decode($res, true); + return $RawDetails; } public function test() { try { - $this->fetchApi("/"); + $this->fetchNodeInfo("/"); echo "Successfully communicated with the API"; } catch (Exception $err) { echo $err->getMessage(); @@ -97,31 +39,23 @@ public function test() public function livestats() { $status = "inactive"; - - $RawDetails = $this->fetchApi(); - $nodeCount = count($RawDetails['data']['node']); - if ($nodeCount > 0) { - $Details = $RawDetails['data']['node'][0]; - $data = [ - "COMMENT_COUNTS" => $Details["comment_counts"], - "LOCAL_POSTS" => $Details["local_posts"], - "TOTAL_USERS" => $Details["total_users"], - "ACTIVE_USERS_MONTHLY" => $Details["active_users_monthly"], - "ACTIVE_USERS_HALFYEAR" => $Details["active_users_halfyear"], - "SIGNUP" => $Details["signup"], - ]; - - foreach ($this->config->availablestats as $stat) { - $newstat = new \stdClass(); - $newstat->title = self::getAvailableStats()[$stat]; - $newstat->value = number_format($data[strtoupper($stat)]); - $data["visiblestats"][] = $newstat; - } - $status = "active"; - return parent::getLiveStats($status, $data); - } else { - return null; + $RawDetails = $this->fetchNodeInfo(); + $data = [ + "COMMENT_COUNTS" => $RawDetails["usage"]["localComments"], + "LOCAL_POSTS" => $RawDetails["usage"]["localPosts"], + "TOTAL_USERS" => $RawDetails["usage"]["users"]["total"], + "ACTIVE_USERS_MONTHLY" => $RawDetails["usage"]["users"]["activeMonth"], + "ACTIVE_USERS_HALFYEAR" => $RawDetails["usage"]["users"]["activeHalfyear"], + "SIGNUP" => $RawDetails["openRegistrations"], + ]; + foreach ($this->config->availablestats as $stat) { + $newstat = new \stdClass(); + $newstat->title = self::getAvailableStats()[$stat]; + $newstat->value = number_format($data[strtoupper($stat)]); + $data["visiblestats"][] = $newstat; } + $status = "active"; + return parent::getLiveStats($status, $data); } public function url($endpoint) { @@ -131,57 +65,12 @@ public function url($endpoint) public static function getAvailableStats() { return [ - //"id" => "ID", - //"name" => "NAME", - //"metatitle" => "METATITLE", - //"metadescription" => "METADESCRIPTION", - //"detectedlanguage" => "DETECTEDLANGUAGE", - //"metaimage" => "METAIMAGE", - //"owner" => "OWNER", - //"onion" => "ONION", - //"i2p" => "I2P", - //"ip" => "IP", - //"ipv6" => "IPV6", - //"greenhost" => "GREENHOST", - //"host" => "HOST", - //"dnssec" => "DNSSEC", - //"sslexpire" => "SSLEXPIRE", - //"servertype" => "SERVERTYPE", - //"camo" => "CAMO", - //"terms" => "TERMS", - //"pp" => "PP", - //"support" => "SUPPORT", - //"softwarename" => "SOFTWARENAME", - //"shortversion" => "SHORTVERSION", - //"fullversion" => "FULLVERSION", - //"masterversion" => "MASTERVERSION", - //"daysmonitored" => "DAYSMONITORED", - //"monthsmonitored" => "MONTHSMONITORED", - //"date_updated" => "Date Updated", - //"date_laststats" => "Date Laststats", - //"date_created" => "Date Created", - //"metalocation" => "METALOCATION", - //"country" => "COUNTRY", - //"city" => "CITY", - //"state" => "STATE", - //"zipcode" => "ZIP", - //"countryname" => "Country Name", - //"lat" => "LAT", - //"long" => "LONG", - //"uptime_alltime" => "Uptime Alltime", - //"latency" => "Latency", - //"sslexpire" => "SSLExpire", - "total_users" => "Total Users", - "active_users_monthly" => "Active Users Monthly", - "active_users_halfyear" => "Active Users HalfYear", - "local_posts" => "Local Posts", - "comment_counts" => "Comment Counts", - //"score" => "Score", - //"status" => "Status", + "total_users" => "Total", + "active_users_monthly" => "Monthly", + "active_users_halfyear" => "HalfYear", + "local_posts" => "Posts", + "comment_counts" => "Comments", "signup" => "Signup", - //"podmin_statement" => "Podmin Statement", - //"services" => "Services", - //"protocols" => "Protocols", ]; } } diff --git a/Diaspora/app.json b/Diaspora/app.json index e7855da673..011049c4a6 100644 --- a/Diaspora/app.json +++ b/Diaspora/app.json @@ -3,7 +3,7 @@ "name": "Diaspora", "website": "https://diasporafoundation.org/", "license": "GNU Affero General Public License v3.0 only", - "description": "A privacy-aware, distributed, open source social network. Limitation: diaspora pod must be available at https://fediverse.observer/!", + "description": "A privacy-aware, distributed, open source social network", "enhanced": true, "tile_background": "light", "icon": "diaspora.svg"