From 819aca35c8819da2eacba5ef78cd53fab8e716ba Mon Sep 17 00:00:00 2001 From: SrPatinhas Date: Sat, 26 Apr 2014 14:31:07 +0100 Subject: [PATCH] Create social.php --- inc/social.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 inc/social.php diff --git a/inc/social.php b/inc/social.php new file mode 100644 index 0000000..e41a3b6 --- /dev/null +++ b/inc/social.php @@ -0,0 +1,46 @@ +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_plusones() { + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc"); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"'.rawurldecode($this->url).'","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]'); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); + $curl_results = curl_exec ($curl); + curl_close ($curl); + $json = json_decode($curl_results, true); + return isset($json[0]['result']['metadata']['globalCounts']['count'])?intval( $json[0]['result']['metadata']['globalCounts']['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; + } + } +?>