-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
261 lines (225 loc) · 7.32 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php
require __DIR__ . '/vendor/autoload.php';
set_time_limit(0);
header('Access-Control-Allow-Origin: *');
/**
* @packcage [sosmedstats]
* @Author Muaz Ramdany
* @blog https://www.webmestudio.xyz/
* @version 1.0
* -------------------------------------------------------------------------
* How to Access
* [Twitter] https://domain.com/?provider=twitter&username={value}
* [Youtube] https://domain.com/?provider=youtube&channel_id={value}
* [facebook] https://domain.com/?provider=facebook&type=fanspage&username={value}¶m={likes,followers}
* [instagram] https://domain.com/?provider=instagram&username={value}¶m={followers,following}
*/
$provider = isset($_GET['provider']) ? $_GET['provider'] : null;
$fb_username = isset($_GET['username']) ? $_GET['username'] : null;
$fb_type = isset($_GET['type']) ? $_GET['type'] : null;
$fb_param = isset($_GET['param']) ? $_GET['param'] : null;
$twitter_username = isset($_GET['username']) ? $_GET['username'] : null;
$youtube_channel = isset($_GET['channel_id']) ? $_GET['channel_id'] : null;
$instagram_username = isset($_GET['username']) ? $_GET['username'] : null;
$instagram_param = isset($_GET['param']) ? $_GET['param'] : null;
switch($provider) {
case 'facebook':
if($fb_username && $fb_type == 'fanspage') {
getFBFansPageReaction($fb_username, $fb_param);
}
else {
httpStatus(403);
}
break;
case 'twitter':
if($twitter_username) {
getTwitterFollowers($twitter_username);
}
else {
httpStatus(403);
}
break;
case 'youtube':
if($youtube_channel) {
getYoutubeSubscriber($youtube_channel);
}
else {
httpStatus(403);
}
break;
case 'instagram':
if($instagram_username) {
getInstagramReaction($instagram_username, $instagram_param);
}
else {
httpStatus(403);
}
break;
default:
httpStatus(403);
break;
}
function getTwitterFollowers($twitter_username) {
if($twitter_username == null) {
httpStatus(403);
exit;
}
$twitter_data = file_get_contents('https://mobile.twitter.com/'.$twitter_username);
preg_match('#followers">\n.*<div class="statnum">([0-9,]*)</div>#', $twitter_data, $match);
$twitter['count'] = str_replace(',', '', $match[1]);
$twitter['count'] = intval($twitter['count']);
$data = [ 'followers' => $twitter['count'] ];
echo json_encode($data);
}
function getYoutubeSubscriber($youtube_channel_id) {
if($youtube_channel_id == null) {
httpStatus(403);
exit;
}
$url = 'https://www.youtube.com/subscribe_embed?channelid='. $youtube_channel_id;
$button_html = file_get_contents($url);
$found_subscribers = preg_match( '/="0">(\d+)</i', $button_html, $matches );
if ( $found_subscribers && isset( $matches[1] ) ) {
$data = [ 'subscriber' => intval($matches[1]) ];
echo json_encode($data);
}
else {
$data = [ 'subscriber' => @intval($matches[1]) ];
echo json_encode($data);
}
}
function getInstagramReaction($username, $param) {
if($username == null || $param == null) {
httpStatus(403);
exit;
}
/*
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
$account = $instagram->getAccount($username);
*/
if($param == 'followers') {
$output = [
'followers' => 0
];
}
elseif($param == 'following') {
$output = [
'following' => 0
];
}
else {
httpStatus(403);
exit;
}
echo json_encode($output);
}
function getFBFansPageReaction($username, $param) {
if($username == null || $param == null) {
httpStatus(403);
exit;
}
header('Content-Type: text/html');
// Extract HTML using curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'https://m.facebook.com/'.$username);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
$data = curl_exec($ch);
curl_close($ch);
echo $data;
/*
// Load HTML to DOM Object
$dom = new DOMDocument();
@$dom->loadHTML($data);
// parse DOM to get div
$divs = $dom->getElementsByTagName('div');
for ($i = 0; $i < $divs->length; $i ++) {
$div = $divs->item($i);
$cls = $div->nodeValue;
$cls = (int) $cls;
if($cls != 0) {
$cls_arr[] = $cls;
}
}
$cls_arr = array_unique($cls_arr);
$cls_arr = array_values($cls_arr);
if(@$cls_arr[0] == null || @$cls_arr[1] == null) {
httpStatus(403);
exit;
}
if($param == 'likes') {
$output = [
'likes' => $cls_arr[0],
];
}
elseif($param == 'followers') {
$output = [
'followers' => $cls_arr[1]
];
}
else {
httpStatus(403);
exit;
}
echo json_encode($output);
*/
}
function httpStatus($num) {
$http = array(
100 => 'HTTP/1.1 100 Continue',
101 => 'HTTP/1.1 101 Switching Protocols',
200 => 'HTTP/1.1 200 OK',
201 => 'HTTP/1.1 201 Created',
202 => 'HTTP/1.1 202 Accepted',
203 => 'HTTP/1.1 203 Non-Authoritative Information',
204 => 'HTTP/1.1 204 No Content',
205 => 'HTTP/1.1 205 Reset Content',
206 => 'HTTP/1.1 206 Partial Content',
300 => 'HTTP/1.1 300 Multiple Choices',
301 => 'HTTP/1.1 301 Moved Permanently',
302 => 'HTTP/1.1 302 Found',
303 => 'HTTP/1.1 303 See Other',
304 => 'HTTP/1.1 304 Not Modified',
305 => 'HTTP/1.1 305 Use Proxy',
307 => 'HTTP/1.1 307 Temporary Redirect',
400 => 'HTTP/1.1 400 Bad Request',
401 => 'HTTP/1.1 401 Unauthorized',
402 => 'HTTP/1.1 402 Payment Required',
403 => 'HTTP/1.1 403 Forbidden',
404 => 'HTTP/1.1 404 Not Found',
405 => 'HTTP/1.1 405 Method Not Allowed',
406 => 'HTTP/1.1 406 Not Acceptable',
407 => 'HTTP/1.1 407 Proxy Authentication Required',
408 => 'HTTP/1.1 408 Request Time-out',
409 => 'HTTP/1.1 409 Conflict',
410 => 'HTTP/1.1 410 Gone',
411 => 'HTTP/1.1 411 Length Required',
412 => 'HTTP/1.1 412 Precondition Failed',
413 => 'HTTP/1.1 413 Request Entity Too Large',
414 => 'HTTP/1.1 414 Request-URI Too Large',
415 => 'HTTP/1.1 415 Unsupported Media Type',
416 => 'HTTP/1.1 416 Requested Range Not Satisfiable',
417 => 'HTTP/1.1 417 Expectation Failed',
500 => 'HTTP/1.1 500 Internal Server Error',
501 => 'HTTP/1.1 501 Not Implemented',
502 => 'HTTP/1.1 502 Bad Gateway',
503 => 'HTTP/1.1 503 Service Unavailable',
504 => 'HTTP/1.1 504 Gateway Time-out',
505 => 'HTTP/1.1 505 HTTP Version Not Supported',
);
header($http[$num]);
header('Content-Type: application/json');
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.
$data = [
'code' => $num,
'error' => $http[$num]
];
echo json_encode($data, JSON_PRETTY_PRINT);
}
?>