|
1 | 1 | <?php
|
| 2 | + header('content-type: application/json'); |
2 | 3 | //Sharrre by Julien Hany
|
3 | 4 | $json = array('url'=>'','count'=>0);
|
4 | 5 | $json['url'] = $_GET['url'];
|
|
17 | 18 | $newDom->formatOutput = true;
|
18 | 19 |
|
19 | 20 | $filtered = $domxpath->query("//div[@id='aggregateCount']");
|
20 |
| - $json['count'] = str_replace('>', '', $filtered->item(0)->nodeValue); |
| 21 | + if (isset($filtered->item(0)->nodeValue)) |
| 22 | + { |
| 23 | + $json['count'] = str_replace('>', '', $filtered->item(0)->nodeValue); |
| 24 | + } |
21 | 25 | }
|
22 | 26 | else if($type == 'stumbleupon'){
|
23 | 27 | $content = parse("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=$url");
|
24 | 28 |
|
25 | 29 | $result = json_decode($content);
|
26 |
| - $json['count'] = $result->result->views; |
27 |
| - if( !isset($json['count']) ) $json['count'] = 0; |
| 30 | + if (isset($result->result->views)) |
| 31 | + { |
| 32 | + $json['count'] = $result->result->views; |
| 33 | + } |
| 34 | + |
28 | 35 | }
|
29 | 36 | else if($type == 'pinterest'){
|
30 | 37 | $content = parse("http://api.pinterest.com/v1/urls/count.json?callback=&url=$url");
|
31 | 38 |
|
32 | 39 | $result = json_decode(str_replace(array('(', ')'), array('', ''), $content));
|
33 |
| - $json['count'] = $result->count; |
34 |
| - if( !isset($json['count']) || $json['count'] === '-' ) $json['count'] = 0; |
| 40 | + if (is_int($result->count)) |
| 41 | + { |
| 42 | + $json['count'] = $result->count; |
| 43 | + } |
35 | 44 | }
|
36 | 45 | }
|
37 | 46 | echo str_replace('\\/','/',json_encode($json));
|
@@ -67,4 +76,3 @@ function parse($encUrl){
|
67 | 76 | }
|
68 | 77 | return $content;
|
69 | 78 | }
|
70 |
| -?> |
|
0 commit comments