@@ -29,12 +29,14 @@ public function test()
29
29
if ($ test ["valid " ]) {
30
30
echo "Successfully communicated with the API " ;
31
31
} else {
32
- echo "Error while communicating with the API " ;
32
+ echo "Error while communicating with the API: " . $ test [ " message " ] ;
33
33
}
34
34
}
35
35
}
36
36
public function livestats ()
37
37
{
38
+ $ data = [];
39
+ $ status = "inactive " ;
38
40
$ version = $ this ->config ->version ;
39
41
40
42
if ($ version == 5 ) {
@@ -56,10 +58,12 @@ public function livestats()
56
58
if ($ version == 6 ) {
57
59
$ results = $ this ->getInfo ();
58
60
59
- $ data ["ads_blocked " ] = $ results ["queries " ];
60
- $ data ["ads_percentage " ] = $ results ["percent " ];
61
+ if ($ results ["valid " ]) {
62
+ $ data ["ads_blocked " ] = $ results ["queries " ];
63
+ $ data ["ads_percentage " ] = $ results ["percent " ];
61
64
62
- $ status = "active " ;
65
+ $ status = "active " ;
66
+ }
63
67
}
64
68
return parent ::getLiveStats ($ status , $ data );
65
69
}
@@ -106,10 +110,23 @@ public function getInfo()
106
110
];
107
111
}
108
112
109
- // Create session and retreave data
113
+ // Create session and retrieve data
110
114
$ response = parent ::execute ($ this ->url ("api/auth " ), $ attrs , null , "POST " );
111
115
$ auth = json_decode ($ response ->getBody ());
112
116
117
+ if (!$ auth ->session ->valid ) {
118
+
119
+ $ data = [
120
+ 'valid ' => false ,
121
+ 'validity ' => -1 ,
122
+ 'message ' => $ auth ->session ->message ,
123
+ 'queries ' => 0 ,
124
+ 'percent ' => 0
125
+ ];
126
+
127
+ return $ data ;
128
+ }
129
+
113
130
if ($ ignoreTls ) {
114
131
$ attrsid = [
115
132
"body " => json_encode (['sid ' => $ auth ->session ->sid ]),
@@ -142,8 +159,14 @@ public function getInfo()
142
159
$ valid = $ auth ->session ->valid ;
143
160
$ validity = $ auth ->session ->validity ;
144
161
$ message = $ auth ->session ->message ;
145
- $ queriesblocked = $ datasummary ->queries ->blocked ;
146
- $ percentblocked = round ($ datasummary ->queries ->percent_blocked , 2 );
162
+
163
+ if (!$ auth ->session ->valid ) {
164
+ $ queriesblocked = 0 ;
165
+ $ percentblocked = 0 ;
166
+ } else {
167
+ $ queriesblocked = $ datasummary ->queries ->blocked ;
168
+ $ percentblocked = round ($ datasummary ->queries ->percent_blocked , 2 );
169
+ }
147
170
148
171
$ data = [
149
172
'valid ' => $ valid ,
0 commit comments