Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
activities.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Google
5  *
6  * @copyright Copyright (C) 2005 - 2013 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 /**
13  * Google+ data class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage Google
17  * @since 1234
18  */
20 {
21  /**
22  * Constructor.
23  *
24  * @param JRegistry $options Google options object
25  * @param JGoogleAuth $auth Google data http client object
26  *
27  * @since 1234
28  */
29  public function __construct(JRegistry $options = null, JGoogleAuth $auth = null)
30  {
31  parent::__construct($options, $auth);
32 
33  if (isset($this->auth) && !$this->auth->getOption('scope'))
34  {
35  $this->auth->setOption('scope', 'https://www.googleapis.com/auth/plus.me');
36  }
37  }
38 
39  /**
40  * List all of the activities in the specified collection for a particular user.
41  *
42  * @param string $userId The ID of the user to get activities for. The special value "me" can be used to indicate the authenticated user.
43  * @param string $collection The collection of activities to list. Acceptable values are: "public".
44  * @param string $fields Used to specify the fields you want returned.
45  * @param integer $max The maximum number of people to include in the response, used for paging.
46  * @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
47  * parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
48  * @param string $alt Specifies an alternative representation type. Acceptable values are: "json" - Use JSON format (default)
49  *
50  * @return mixed Data from Google
51  *
52  * @since 1234
53  */
54  public function listActivities($userId, $collection, $fields = null, $max = 10, $token = null, $alt = null)
55  {
56  if ($this->isAuthenticated())
57  {
58  $url = $this->getOption('api.url') . 'people/' . $userId . '/activities/' . $collection;
59 
60  // Check if fields is specified.
61  if ($fields)
62  {
63  $url .= '?fields=' . $fields;
64  }
65 
66  // Check if max is specified.
67  if ($max != 10)
68  {
69  $url .= (strpos($url, '?') === false) ? '?maxResults=' : '&maxResults=';
70  $url .= $max;
71  }
72 
73  // Check if token is specified.
74  if ($token)
75  {
76  $url .= (strpos($url, '?') === false) ? '?pageToken=' : '&pageToken=';
77  $url .= $token;
78  }
79 
80  // Check if alt is specified.
81  if ($alt)
82  {
83  $url .= (strpos($url, '?') === false) ? '?alt=' : '&alt=';
84  $url .= $alt;
85  }
86 
87  $jdata = $this->auth->query($url);
88 
89  return json_decode($jdata->body, true);
90  }
91  else
92  {
93  return false;
94  }
95  }
96 
97  /**
98  * Get an activity.
99  *
100  * @param string $id The ID of the activity to get.
101  * @param string $fields Used to specify the fields you want returned.
102  * @param string $alt Specifies an alternative representation type. Acceptable values are: "json" - Use JSON format (default)
103  *
104  * @return mixed Data from Google
105  *
106  * @since 1234
107  */
108  public function getActivity($id, $fields = null, $alt = null)
109  {
110  if ($this->isAuthenticated())
111  {
112  $url = $this->getOption('api.url') . 'activities/' . $id;
113 
114  // Check if fields is specified.
115  if ($fields)
116  {
117  $url .= '?fields=' . $fields;
118  }
119 
120  // Check if alt is specified.
121  if ($alt)
122  {
123  $url .= (strpos($url, '?') === false) ? '?alt=' : '&alt=';
124  $url .= $alt;
125  }
126 
127  $jdata = $this->auth->query($url);
128 
129  return json_decode($jdata->body, true);
130  }
131  else
132  {
133  return false;
134  }
135  }
136 
137  /**
138  * Search all public activities.
139  *
140  * @param string $query Full-text search query string.
141  * @param string $fields Used to specify the fields you want returned.
142  * @param string $language Specify the preferred language to search with. https://developers.google.com/+/api/search#available-languages
143  * @param integer $max The maximum number of people to include in the response, used for paging.
144  * @param string $order Specifies how to order search results. Acceptable values are "best" and "recent".
145  * @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
146  * parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
147  *
148  * @return mixed Data from Google
149  *
150  * @since 1234
151  */
152  public function search($query, $fields = null, $language = null, $max = 10, $order = null, $token = null)
153  {
154  if ($this->isAuthenticated())
155  {
156  $url = $this->getOption('api.url') . 'activities?query=' . urlencode($query);
157 
158  // Check if fields is specified.
159  if ($fields)
160  {
161  $url .= '&fields=' . $fields;
162  }
163 
164  // Check if language is specified.
165  if ($language)
166  {
167  $url .= '&language=' . $language;
168  }
169 
170  // Check if max is specified.
171  if ($max != 10)
172  {
173  $url .= '&maxResults=' . $max;
174  }
175 
176  // Check if order is specified.
177  if ($order)
178  {
179  $url .= '&orderBy=' . $order;
180  }
181 
182  // Check of token is specified.
183  if ($token)
184  {
185  $url .= '&pageToken=' . $token;
186  }
187 
188  $jdata = $this->auth->query($url);
189 
190  return json_decode($jdata->body, true);
191  }
192  else
193  {
194  return false;
195  }
196  }
197 }