Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 29 additions & 140 deletions Diaspora/Diaspora.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
{
Expand All @@ -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",
];
}
}
2 changes: 1 addition & 1 deletion Diaspora/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down