forked from famfam/Sharrre
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharrre.php
executable file
·49 lines (38 loc) · 1.28 KB
/
sharrre.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
<?php
/* Based on original Sharrre by Julien Hany
* by Brando Meniconi ([email protected])
*/
header('content-type: application/json');
$json = array(
'url'=>filter_input(INPUT_GET, 'url', FILTER_VALIDATE_URL),
'count'=>0
);
if(empty($json['url'])){
return json_encode($json);
}
$context = stream_context_create(array(
'http'=>array(
//'proxy' => 'tcp://proxy.example.com:5100', //
'max_redirects' => 5,
'user_agent' => 'Sharrre',
'timeout' => 5,
'verify_peer' => false,
)
));
switch(filter_input(INPUT_GET, 'type')){
case 'googlePlus':
$response = file_get_contents('https://plusone.google.com/u/0/_/+1/fastbutton?url=' . urlencode($json['url']) . '&count=true', false, $context);
$matches = array();
if(!empty($response) && preg_match( '/window\.__SSR = {c: ([\d]+)/', $response, $matches )){
$json['count'] = $matches[1];
}
break;
case 'stumbleupon':
$response = file_get_contents("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=".urlencode($json['url']), false, $context);
if (!empty($response) && ($result = json_decode($response)) && isset($result->result->views))
{
$json['count'] = (int)$result->result->views;
}
break;
}
echo json_encode($json);