<?
class shareCount {
private $url,$timeout;
function __construct($url,$timeout=10) {
$this->url=rawurlencode($url);
$this->timeout=$timeout;
}
function get_tweets() {
$json_string = $this->file_get_contents_curl('http://urls.api.twitter.com/1/urls/count.json?url=' . $this->url);
$json = json_decode($json_string, true);
return isset($json['count'])?intval($json['count']):0;
}
function get_fb() {
$json_string = $this->file_get_contents_curl('http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls='.$this->url);
$json = json_decode($json_string, true);
return isset($json[0]['total_count'])?intval($json[0]['total_count']):0;
}
function get_pinterest() {
$return_data = $this->file_get_contents_curl('http://api.pinterest.com/v1/urls/count.json?url='.$this->url);
$json_string = preg_replace('/^receiveCount\((.*)\)$/', "\\1", $return_data);
$json = json_decode($json_string, true);
return isset($json['count'])?intval($json['count']):0;
}
private function file_get_contents_curl($url){
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
$cont = curl_exec($ch);
if(curl_error($ch))
{
die(curl_error($ch));
}
return $cont;
}
}
?>
<div class="socialbuttons">
<?php $obj = new ShareCount( the_permalink() ); ?>
<a href=https://www.facebook.com/sharer/sharer.php?u="<?php the_permalink(); ?>" target=_blank><span class=black>
<? echo "".$obj->get_fb();?>
</span><span class=light>Likes</span></a>
<a href=https://www.facebook.com/sharer/sharer.php?u="<?php the_permalink(); ?>" target=_blank><span class=black>
<? echo "".$obj->get_tweets(); ?>
</span><span class=light>Tweets</span></a>
<a href=https://www.facebook.com/sharer/sharer.php?u="<?php the_permalink(); ?>" target=_blank><span class=black>
<? echo "".$obj->get_pinterest(); ?>
</span><span class=light>Pins</span></a>
</div>