Skip to content

Commit

Permalink
WIP Add Diaspora enhanced app files (#795)
Browse files Browse the repository at this point in the history
* Add Diaspora enhanced app files

* Update Diaspora.php

PHPCE compliance edits

* Update app.json

Add limitation into app description
  • Loading branch information
iamdoubz authored Oct 29, 2024
1 parent ef01f64 commit bb3d4bc
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 0 deletions.
187 changes: 187 additions & 0 deletions Diaspora/Diaspora.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<?php

namespace App\SupportedApps\Diaspora;

class Diaspora extends \App\SupportedApps implements \App\EnhancedApps
{
public $config;
private function getBaseDomain($url) {
$regex = '/^(https?:)/i';
$baseurl = preg_replace($regex, '', $url);
$baseurl = str_replace('/', '', $baseurl);
return $baseurl;
}
private function fetchApi() {
$url = "https://api.fediverse.observer/";
$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);
$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",
];
}
}
10 changes: 10 additions & 0 deletions Diaspora/app.json
Original file line number Diff line number Diff line change
@@ -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"
}
14 changes: 14 additions & 0 deletions Diaspora/config.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
<div class="items">
<div class="input">
<label>{{ strtoupper(__('app.url')) }}</label>
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
</div>
<div class="input">
<label>Stats to show</label>
{!! Form::select('config[availablestats][]', App\SupportedApps\Diaspora\Diaspora::getAvailableStats(), isset($item) ? $item->getConfig()->availablestats ?? null : null, ['multiple' => 'multiple']) !!}
</div>
<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
</div>
</div>
4 changes: 4 additions & 0 deletions Diaspora/diaspora.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions Diaspora/livestats.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ul class="livestats">
@foreach ($visiblestats as $stat)
<li>
<span class="title">{!! $stat->title !!}</span>
<strong>{!! $stat->value !!}</strong>
</li>
@endforeach
</ul>

0 comments on commit bb3d4bc

Please sign in to comment.