@@ -11,84 +11,26 @@ private function getBaseDomain($url) {
1111 $ baseurl = str_replace ('/ ' , '' , $ baseurl );
1212 return $ baseurl ;
1313 }
14- private function fetchApi () {
15- $ url = "https://api.fediverse.observer/ " ;
14+ private function fetchNodeInfo () {
1615 $ podurl = parent ::normaliseurl ($ this ->config ->url );
17- $ podurl = $ this ->getBaseDomain ($ podurl );
18- $ query = 'query{
19- node(domain: " ' . $ podurl . '"){
20- id
21- name
22- metatitle
23- metadescription
24- detectedlanguage
25- metaimage
26- owner
27- onion
28- i2p
29- ip
30- ipv6
31- greenhost
32- host
33- dnssec
34- sslexpire
35- servertype
36- camo
37- terms
38- pp
39- support
40- softwarename
41- shortversion
42- fullversion
43- masterversion
44- daysmonitored
45- monthsmonitored
46- date_updated
47- date_laststats
48- date_created
49- metalocation
50- country
51- city
52- state
53- zipcode
54- countryname
55- lat
56- long
57- uptime_alltime
58- latency
59- sslexpire
60- total_users
61- active_users_monthly
62- active_users_halfyear
63- local_posts
64- comment_counts
65- score
66- status
67- signup
68- podmin_statement
69- services
70- protocols
71- }
72- } ' ;
73- $ data = array ('query ' => $ query );
16+ $ nodeinfo = $ podurl . '/nodeinfo/2.1 ' ;
7417 $ options = [
7518 'http ' => [
76- 'method ' => 'POST ' ,
19+ 'method ' => 'GET ' ,
7720 'header ' => [
7821 "Content-Type: application/json "
79- ],
80- 'content ' => json_encode ($ data ),
22+ ]
8123 ],
8224 ];
8325 $ context = stream_context_create ($ options );
84- $ res = file_get_contents ($ url , false , $ context );
85- $ rdata = json_decode ($ res , true );
86- return $ rdata ;
26+ $ res = file_get_contents ($ nodeinfo , false , $ context );
27+ $ RawDetails = json_decode ($ res , true );
28+ return $ RawDetails ;
8729 }
8830 public function test ()
8931 {
9032 try {
91- $ this ->fetchApi ("/ " );
33+ $ this ->fetchNodeInfo ("/ " );
9234 echo "Successfully communicated with the API " ;
9335 } catch (Exception $ err ) {
9436 echo $ err ->getMessage ();
@@ -97,31 +39,23 @@ public function test()
9739 public function livestats ()
9840 {
9941 $ status = "inactive " ;
100-
101- $ RawDetails = $ this ->fetchApi ();
102- $ nodeCount = count ($ RawDetails ['data ' ]['node ' ]);
103- if ($ nodeCount > 0 ) {
104- $ Details = $ RawDetails ['data ' ]['node ' ][0 ];
105- $ data = [
106- "COMMENT_COUNTS " => $ Details ["comment_counts " ],
107- "LOCAL_POSTS " => $ Details ["local_posts " ],
108- "TOTAL_USERS " => $ Details ["total_users " ],
109- "ACTIVE_USERS_MONTHLY " => $ Details ["active_users_monthly " ],
110- "ACTIVE_USERS_HALFYEAR " => $ Details ["active_users_halfyear " ],
111- "SIGNUP " => $ Details ["signup " ],
112- ];
113-
114- foreach ($ this ->config ->availablestats as $ stat ) {
115- $ newstat = new \stdClass ();
116- $ newstat ->title = self ::getAvailableStats ()[$ stat ];
117- $ newstat ->value = number_format ($ data [strtoupper ($ stat )]);
118- $ data ["visiblestats " ][] = $ newstat ;
119- }
120- $ status = "active " ;
121- return parent ::getLiveStats ($ status , $ data );
122- } else {
123- return null ;
42+ $ RawDetails = $ this ->fetchNodeInfo ();
43+ $ data = [
44+ "COMMENT_COUNTS " => $ RawDetails ["usage " ]["localComments " ],
45+ "LOCAL_POSTS " => $ RawDetails ["usage " ]["localPosts " ],
46+ "TOTAL_USERS " => $ RawDetails ["usage " ]["users " ]["total " ],
47+ "ACTIVE_USERS_MONTHLY " => $ RawDetails ["usage " ]["users " ]["activeMonth " ],
48+ "ACTIVE_USERS_HALFYEAR " => $ RawDetails ["usage " ]["users " ]["activeHalfyear " ],
49+ "SIGNUP " => $ RawDetails ["openRegistrations " ],
50+ ];
51+ foreach ($ this ->config ->availablestats as $ stat ) {
52+ $ newstat = new \stdClass ();
53+ $ newstat ->title = self ::getAvailableStats ()[$ stat ];
54+ $ newstat ->value = number_format ($ data [strtoupper ($ stat )]);
55+ $ data ["visiblestats " ][] = $ newstat ;
12456 }
57+ $ status = "active " ;
58+ return parent ::getLiveStats ($ status , $ data );
12559 }
12660 public function url ($ endpoint )
12761 {
@@ -131,57 +65,12 @@ public function url($endpoint)
13165 public static function getAvailableStats ()
13266 {
13367 return [
134- //"id" => "ID",
135- //"name" => "NAME",
136- //"metatitle" => "METATITLE",
137- //"metadescription" => "METADESCRIPTION",
138- //"detectedlanguage" => "DETECTEDLANGUAGE",
139- //"metaimage" => "METAIMAGE",
140- //"owner" => "OWNER",
141- //"onion" => "ONION",
142- //"i2p" => "I2P",
143- //"ip" => "IP",
144- //"ipv6" => "IPV6",
145- //"greenhost" => "GREENHOST",
146- //"host" => "HOST",
147- //"dnssec" => "DNSSEC",
148- //"sslexpire" => "SSLEXPIRE",
149- //"servertype" => "SERVERTYPE",
150- //"camo" => "CAMO",
151- //"terms" => "TERMS",
152- //"pp" => "PP",
153- //"support" => "SUPPORT",
154- //"softwarename" => "SOFTWARENAME",
155- //"shortversion" => "SHORTVERSION",
156- //"fullversion" => "FULLVERSION",
157- //"masterversion" => "MASTERVERSION",
158- //"daysmonitored" => "DAYSMONITORED",
159- //"monthsmonitored" => "MONTHSMONITORED",
160- //"date_updated" => "Date Updated",
161- //"date_laststats" => "Date Laststats",
162- //"date_created" => "Date Created",
163- //"metalocation" => "METALOCATION",
164- //"country" => "COUNTRY",
165- //"city" => "CITY",
166- //"state" => "STATE",
167- //"zipcode" => "ZIP",
168- //"countryname" => "Country Name",
169- //"lat" => "LAT",
170- //"long" => "LONG",
171- //"uptime_alltime" => "Uptime Alltime",
172- //"latency" => "Latency",
173- //"sslexpire" => "SSLExpire",
174- "total_users " => "Total Users " ,
175- "active_users_monthly " => "Active Users Monthly " ,
176- "active_users_halfyear " => "Active Users HalfYear " ,
177- "local_posts " => "Local Posts " ,
178- "comment_counts " => "Comment Counts " ,
179- //"score" => "Score",
180- //"status" => "Status",
68+ "total_users " => "Total " ,
69+ "active_users_monthly " => "Monthly " ,
70+ "active_users_halfyear " => "HalfYear " ,
71+ "local_posts " => "Posts " ,
72+ "comment_counts " => "Comments " ,
18173 "signup " => "Signup " ,
182- //"podmin_statement" => "Podmin Statement",
183- //"services" => "Services",
184- //"protocols" => "Protocols",
18574 ];
18675 }
18776}
0 commit comments