Skip to content

Commit 381d003

Browse files
committed
Fixed issued with sharrre.php
Added a content type header to force returned data as json, and improved the logic for populating the data array that is returned.
1 parent 4962084 commit 381d003

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

sharrre.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
header('content-type: application/json');
23
//Sharrre by Julien Hany
34
$json = array('url'=>'','count'=>0);
45
$json['url'] = $_GET['url'];
@@ -17,21 +18,29 @@
1718
$newDom->formatOutput = true;
1819

1920
$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+
}
2125
}
2226
else if($type == 'stumbleupon'){
2327
$content = parse("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=$url");
2428

2529
$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+
2835
}
2936
else if($type == 'pinterest'){
3037
$content = parse("http://api.pinterest.com/v1/urls/count.json?callback=&url=$url");
3138

3239
$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+
}
3544
}
3645
}
3746
echo str_replace('\\/','/',json_encode($json));
@@ -67,4 +76,3 @@ function parse($encUrl){
6776
}
6877
return $content;
6978
}
70-
?>

0 commit comments

Comments
 (0)