-
-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
5 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |