1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Google
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 use Joomla\Registry\Registry;
13
14 /**
15 * Google+ data class for the Joomla Platform.
16 *
17 * @since 12.3
18 * @deprecated 4.0 Use the `joomla/google` package via Composer instead
19 */
20 class JGoogleDataPlusPeople extends JGoogleData
21 {
22 /**
23 * Constructor.
24 *
25 * @param Registry $options Google options object
26 * @param JGoogleAuth $auth Google data http client object
27 *
28 * @since 12.3
29 */
30 public function __construct(Registry $options = null, JGoogleAuth $auth = null)
31 {
32 parent::__construct($options, $auth);
33
34 if (isset($this->auth) && !$this->auth->getOption('scope'))
35 {
36 $this->auth->setOption('scope', 'https://www.googleapis.com/auth/plus.me');
37 }
38 }
39
40 /**
41 * Get a person's profile.
42 *
43 * @param string $id The ID of the person to get the profile for. The special value "me" can be used to indicate the authenticated user.
44 * @param string $fields Used to specify the fields you want returned.
45 *
46 * @return mixed Data from Google
47 *
48 * @since 12.3
49 */
50 public function getPeople($id, $fields = null)
51 {
52 if ($this->isAuthenticated())
53 {
54 $url = $this->getOption('api.url') . 'people/' . $id;
55
56 // Check if fields is specified.
57 if ($fields)
58 {
59 $url .= '?fields=' . $fields;
60 }
61
62 $jdata = $this->auth->query($url);
63
64 return json_decode($jdata->body, true);
65 }
66 else
67 {
68 return false;
69 }
70 }
71
72 /**
73 * Search all public profiles.
74 *
75 * @param string $query Specify a query string for full text search of public text in all profiles.
76 * @param string $fields Used to specify the fields you want returned.
77 * @param string $language Specify the preferred language to search with. https://developers.google.com/+/api/search#available-languages
78 * @param integer $max The maximum number of people to include in the response, used for paging.
79 * @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
80 * parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
81 *
82 * @return mixed Data from Google
83 *
84 * @since 12.3
85 */
86 public function search($query, $fields = null, $language = null, $max = 10, $token = null)
87 {
88 if ($this->isAuthenticated())
89 {
90 $url = $this->getOption('api.url') . 'people?query=' . urlencode($query);
91
92 // Check if fields is specified.
93 if ($fields)
94 {
95 $url .= '&fields=' . $fields;
96 }
97
98 // Check if language is specified.
99 if ($language)
100 {
101 $url .= '&language=' . $language;
102 }
103
104 // Check if max is specified.
105 if ($max != 10)
106 {
107 $url .= '&maxResults=' . $max;
108 }
109
110 // Check of token is specified.
111 if ($token)
112 {
113 $url .= '&pageToken=' . $token;
114 }
115
116 $jdata = $this->auth->query($url);
117
118 return json_decode($jdata->body, true);
119 }
120 else
121 {
122 return false;
123 }
124 }
125
126 /**
127 * List all of the people in the specified collection for a particular activity.
128 *
129 * @param string $activityId The ID of the activity to get the list of people for.
130 * @param string $collection The collection of people to list. Acceptable values are "plusoners" and "resharers".
131 * @param string $fields Used to specify the fields you want returned.
132 * @param integer $max The maximum number of people to include in the response, used for paging.
133 * @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
134 * parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
135 *
136 * @return mixed Data from Google
137 *
138 * @since 12.3
139 */
140 public function listByActivity($activityId, $collection, $fields = null, $max = 10, $token = null)
141 {
142 if ($this->isAuthenticated())
143 {
144 $url = $this->getOption('api.url') . 'activities/' . $activityId . '/people/' . $collection;
145
146 // Check if fields is specified.
147 if ($fields)
148 {
149 $url .= '?fields=' . $fields;
150 }
151
152 // Check if max is specified.
153 if ($max != 10)
154 {
155 $url .= (strpos($url, '?') === false) ? '?maxResults=' : '&maxResults=';
156 $url .= $max;
157 }
158
159 // Check of token is specified.
160 if ($token)
161 {
162 $url .= (strpos($url, '?') === false) ? '?pageToken=' : '&pageToken=';
163 $url .= $token;
164 }
165
166 $jdata = $this->auth->query($url);
167
168 return json_decode($jdata->body, true);
169 }
170 else
171 {
172 return false;
173 }
174 }
175 }
176