| 1 |
<?php |
| 2 |
namespace MBSocial; |
| 3 |
|
| 4 |
class googleplusNetwork extends mbNetwork |
| 5 |
{ |
| 6 |
protected $network = 'googleplus'; |
| 7 |
protected $icon = 'fa-google-plus-g'; |
| 8 |
protected $color = '#dd4b39'; |
| 9 |
|
| 10 |
public function __construct() |
| 11 |
{ |
| 12 |
$this->label = __('+1','mbsocial'); |
| 13 |
$this->share_url = 'https://plus.google.com/share?url={url}'; |
| 14 |
$this->profile_url = 'https://plus.google.com/{profile}'; |
| 15 |
$this->countable = true; |
| 16 |
$this->count_api = '{url}'; |
| 17 |
$this->popup_dimensions = array(600,600); |
| 18 |
parent::__construct(); |
| 19 |
|
| 20 |
} |
| 21 |
|
| 22 |
public function remoteRequest($url) |
| 23 |
{ |
| 24 |
$args = array( |
| 25 |
'method' => 'POST', |
| 26 |
'headers' => array( |
| 27 |
// setup content type to JSON |
| 28 |
'Content-Type' => 'application/json', |
| 29 |
), |
| 30 |
// setup POST options to Google API |
| 31 |
'body' => json_encode(array( |
| 32 |
'method' => 'pos.plusones.get', |
| 33 |
'id' => 'p', |
| 34 |
'method' => 'pos.plusones.get', |
| 35 |
'jsonrpc' => '2.0', |
| 36 |
'key' => 'p', |
| 37 |
'apiVersion' => 'v1', |
| 38 |
'params' => array( |
| 39 |
'nolog' => true, |
| 40 |
'id' => $url, |
| 41 |
'source' => 'widget', |
| 42 |
'userId' => '@viewer', |
| 43 |
'groupId' => '@self', |
| 44 |
), |
| 45 |
)), |
| 46 |
|
| 47 |
'sslverify' => false, |
| 48 |
); |
| 49 |
$response = wp_remote_post('https://clients6.google.com/rpc', $args); |
| 50 |
|
| 51 |
|
| 52 |
if (is_wp_error($response) || $response['response']['code'] != 200) { |
| 53 |
return false; |
| 54 |
} |
| 55 |
else { |
| 56 |
$result = wp_remote_retrieve_body($response); |
| 57 |
} |
| 58 |
|
| 59 |
$result = json_decode($result, true); |
| 60 |
$count = 0; |
| 61 |
if (isset($result['result']['metadata']['globalCounts']['count'])) |
| 62 |
{ $count = intval($result['result']['metadata']['globalCounts']['count']); |
| 63 |
return $count; |
| 64 |
} |
| 65 |
|
| 66 |
return 0; |
| 67 |
|
| 68 |
} |
| 69 |
} |
| 70 |
|