From bb3d4bcabae1162b65850e0b8fdf893aa4fca920 Mon Sep 17 00:00:00 2001 From: iamdoubz <4871781+iamdoubz@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:20:04 -0500 Subject: [PATCH] WIP Add Diaspora enhanced app files (#795) * Add Diaspora enhanced app files * Update Diaspora.php PHPCE compliance edits * Update app.json Add limitation into app description --- Diaspora/Diaspora.php | 187 +++++++++++++++++++++++++++++++++++ Diaspora/app.json | 10 ++ Diaspora/config.blade.php | 14 +++ Diaspora/diaspora.svg | 4 + Diaspora/livestats.blade.php | 8 ++ 5 files changed, 223 insertions(+) create mode 100644 Diaspora/Diaspora.php create mode 100644 Diaspora/app.json create mode 100644 Diaspora/config.blade.php create mode 100644 Diaspora/diaspora.svg create mode 100644 Diaspora/livestats.blade.php diff --git a/Diaspora/Diaspora.php b/Diaspora/Diaspora.php new file mode 100644 index 0000000000..546156d2db --- /dev/null +++ b/Diaspora/Diaspora.php @@ -0,0 +1,187 @@ +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); + $options = [ + 'http' => [ + 'method' => 'POST', + '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; + } + public function test() + { + try { + $this->fetchApi("/"); + echo "Successfully communicated with the API"; + } catch (Exception $err) { + echo $err->getMessage(); + } + } + 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; + } + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } + 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", + "signup" => "Signup", + //"podmin_statement" => "Podmin Statement", + //"services" => "Services", + //"protocols" => "Protocols", + ]; + } +} diff --git a/Diaspora/app.json b/Diaspora/app.json new file mode 100644 index 0000000000..e7855da673 --- /dev/null +++ b/Diaspora/app.json @@ -0,0 +1,10 @@ +{ + "appid": "047a5440cad6772ebe1a7af1f286a2429f16bf43", + "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/!", + "enhanced": true, + "tile_background": "light", + "icon": "diaspora.svg" +} diff --git a/Diaspora/config.blade.php b/Diaspora/config.blade.php new file mode 100644 index 0000000000..eed2ddb2f8 --- /dev/null +++ b/Diaspora/config.blade.php @@ -0,0 +1,14 @@ +

{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')

+
+
+ + {!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!} +
+
+ + {!! Form::select('config[availablestats][]', App\SupportedApps\Diaspora\Diaspora::getAvailableStats(), isset($item) ? $item->getConfig()->availablestats ?? null : null, ['multiple' => 'multiple']) !!} +
+
+ +
+
diff --git a/Diaspora/diaspora.svg b/Diaspora/diaspora.svg new file mode 100644 index 0000000000..f573a1396c --- /dev/null +++ b/Diaspora/diaspora.svg @@ -0,0 +1,4 @@ + + + + diff --git a/Diaspora/livestats.blade.php b/Diaspora/livestats.blade.php new file mode 100644 index 0000000000..66e281342d --- /dev/null +++ b/Diaspora/livestats.blade.php @@ -0,0 +1,8 @@ + \ No newline at end of file