Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
people.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  * Get a person's profile.
41  *
42  * @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.
43  * @param string $fields Used to specify the fields you want returned.
44  *
45  * @return mixed Data from Google
46  *
47  * @since 1234
48  */
49  public function getPeople($id, $fields = null)
50  {
51  if ($this->isAuthenticated())
52  {
53  $url = $this->getOption('api.url') . 'people/' . $id;
54 
55  // Check if fields is specified.
56  if ($fields)
57  {
58  $url .= '?fields=' . $fields;
59  }
60 
61  $jdata = $this->auth->query($url);
62 
63  return json_decode($jdata->body, true);
64  }
65  else
66  {
67  return false;
68  }
69  }
70 
71  /**
72  * Search all public profiles.
73  *
74  * @param string $query Specify a query string for full text search of public text in all profiles.
75  * @param string $fields Used to specify the fields you want returned.
76  * @param string $language Specify the preferred language to search with. https://developers.google.com/+/api/search#available-languages
77  * @param integer $max The maximum number of people to include in the response, used for paging.
78  * @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
79  * parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
80  *
81  * @return mixed Data from Google
82  *
83  * @since 1234
84  */
85  public function search($query, $fields = null, $language = null, $max = 10, $token = null)
86  {
87  if ($this->isAuthenticated())
88  {
89  $url = $this->getOption('api.url') . 'people?query=' . urlencode($query);
90 
91  // Check if fields is specified.
92  if ($fields)
93  {
94  $url .= '&fields=' . $fields;
95  }
96 
97  // Check if language is specified.
98  if ($language)
99  {
100  $url .= '&language=' . $language;
101  }
102 
103  // Check if max is specified.
104  if ($max != 10)
105  {
106  $url .= '&maxResults=' . $max;
107  }
108 
109  // Check of token is specified.
110  if ($token)
111  {
112  $url .= '&pageToken=' . $token;
113  }
114 
115  $jdata = $this->auth->query($url);
116 
117  return json_decode($jdata->body, true);
118  }
119  else
120  {
121  return false;
122  }
123  }
124 
125  /**
126  * List all of the people in the specified collection for a particular activity.
127  *
128  * @param string $activityId The ID of the activity to get the list of people for.
129  * @param string $collection The collection of people to list. Acceptable values are "plusoners" and "resharers".
130  * @param string $fields Used to specify the fields you want returned.
131  * @param integer $max The maximum number of people to include in the response, used for paging.
132  * @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
133  * parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
134  *
135  * @return mixed Data from Google
136  *
137  * @since 1234
138  */
139  public function listByActivity($activityId, $collection, $fields = null, $max = 10, $token = null)
140  {
141  if ($this->isAuthenticated())
142  {
143  $url = $this->getOption('api.url') . 'activities/' . $activityId . '/people/' . $collection;
144 
145  // Check if fields is specified.
146  if ($fields)
147  {
148  $url .= '?fields=' . $fields;
149  }
150 
151  // Check if max is specified.
152  if ($max != 10)
153  {
154  $url .= (strpos($url, '?') === false) ? '?maxResults=' : '&maxResults=';
155  $url .= $max;
156  }
157 
158  // Check of token is specified.
159  if ($token)
160  {
161  $url .= (strpos($url, '?') === false) ? '?pageToken=' : '&pageToken=';
162  $url .= $token;
163  }
164 
165  $jdata = $this->auth->query($url);
166 
167  return json_decode($jdata->body, true);
168  }
169  else
170  {
171  return false;
172  }
173  }
174 }