PluginProbe
Social Share Buttons / 1.0
Social Share Buttons v1.0
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 1.0, at classes/network/googleplus.php

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