PluginProbe
Social Share Buttons / 0.9
Social Share Buttons v0.9
trunk 0.9 1.0 1.1 1.1.1 1.1.2 1.10 1.11 1.12 1.15 1.16 1.17 1.18 1.19 1.2 1.20 1.3 1.30 1.4 1.5 1.6 1.7 1.8 1.9
share-button / classes / network / googleplus.php

googleplus.php in Social Share Buttons 0.9, at classes/network/googleplus.php

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