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 JGoogleDataPlusActivities 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 * List all of the activities in the specified collection for a particular user.
42 *
43 * @param string $userId The ID of the user to get activities for. The special value "me" can be used to indicate the authenticated user.
44 * @param string $collection The collection of activities to list. Acceptable values are: "public".
45 * @param string $fields Used to specify the fields you want returned.
46 * @param integer $max The maximum number of people to include in the response, used for paging.
47 * @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
48 * parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
49 * @param string $alt Specifies an alternative representation type. Acceptable values are: "json" - Use JSON format (default)
50 *
51 * @return mixed Data from Google
52 *
53 * @since 12.3
54 */
55 public function listActivities($userId, $collection, $fields = null, $max = 10, $token = null, $alt = null)
56 {
57 if ($this->isAuthenticated())
58 {
59 $url = $this->getOption('api.url') . 'people/' . $userId . '/activities/' . $collection;
60
61 // Check if fields is specified.
62 if ($fields)
63 {
64 $url .= '?fields=' . $fields;
65 }
66
67 // Check if max is specified.
68 if ($max != 10)
69 {
70 $url .= (strpos($url, '?') === false) ? '?maxResults=' : '&maxResults=';
71 $url .= $max;
72 }
73
74 // Check if token is specified.
75 if ($token)
76 {
77 $url .= (strpos($url, '?') === false) ? '?pageToken=' : '&pageToken=';
78 $url .= $token;
79 }
80
81 // Check if alt is specified.
82 if ($alt)
83 {
84 $url .= (strpos($url, '?') === false) ? '?alt=' : '&alt=';
85 $url .= $alt;
86 }
87
88 $jdata = $this->auth->query($url);
89
90 return json_decode($jdata->body, true);
91 }
92 else
93 {
94 return false;
95 }
96 }
97
98 /**
99 * Get an activity.
100 *
101 * @param string $id The ID of the activity to get.
102 * @param string $fields Used to specify the fields you want returned.
103 * @param string $alt Specifies an alternative representation type. Acceptable values are: "json" - Use JSON format (default)
104 *
105 * @return mixed Data from Google
106 *
107 * @since 12.3
108 */
109 public function getActivity($id, $fields = null, $alt = null)
110 {
111 if ($this->isAuthenticated())
112 {
113 $url = $this->getOption('api.url') . 'activities/' . $id;
114
115 // Check if fields is specified.
116 if ($fields)
117 {
118 $url .= '?fields=' . $fields;
119 }
120
121 // Check if alt is specified.
122 if ($alt)
123 {
124 $url .= (strpos($url, '?') === false) ? '?alt=' : '&alt=';
125 $url .= $alt;
126 }
127
128 $jdata = $this->auth->query($url);
129
130 return json_decode($jdata->body, true);
131 }
132 else
133 {
134 return false;
135 }
136 }
137
138 /**
139 * Search all public activities.
140 *
141 * @param string $query Full-text search query string.
142 * @param string $fields Used to specify the fields you want returned.
143 * @param string $language Specify the preferred language to search with. https://developers.google.com/+/api/search#available-languages
144 * @param integer $max The maximum number of people to include in the response, used for paging.
145 * @param string $order Specifies how to order search results. Acceptable values are "best" and "recent".
146 * @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
147 * parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
148 *
149 * @return mixed Data from Google
150 *
151 * @since 12.3
152 */
153 public function search($query, $fields = null, $language = null, $max = 10, $order = null, $token = null)
154 {
155 if ($this->isAuthenticated())
156 {
157 $url = $this->getOption('api.url') . 'activities?query=' . urlencode($query);
158
159 // Check if fields is specified.
160 if ($fields)
161 {
162 $url .= '&fields=' . $fields;
163 }
164
165 // Check if language is specified.
166 if ($language)
167 {
168 $url .= '&language=' . $language;
169 }
170
171 // Check if max is specified.
172 if ($max != 10)
173 {
174 $url .= '&maxResults=' . $max;
175 }
176
177 // Check if order is specified.
178 if ($order)
179 {
180 $url .= '&orderBy=' . $order;
181 }
182
183 // Check of token is specified.
184 if ($token)
185 {
186 $url .= '&pageToken=' . $token;
187 }
188
189 $jdata = $this->auth->query($url);
190
191 return json_decode($jdata->body, true);
192 }
193 else
194 {
195 return false;
196 }
197 }
198 }
199