Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
comments.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 comments for an activity.
41  *
42  * @param string $activityId The ID of the activity to get comments for.
43  * @param string $fields Used to specify the fields you want returned.
44  * @param integer $max The maximum number of people to include in the response, used for paging.
45  * @param string $order The order in which to sort the list of comments. Acceptable values are "ascending" and "descending".
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 listComments($activityId, $fields = null, $max = 20, $order = null, $token = null, $alt = null)
55  {
56  if ($this->isAuthenticated())
57  {
58  $url = $this->getOption('api.url') . 'activities/' . $activityId . '/comments';
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 != 20)
68  {
69  $url .= (strpos($url, '?') === false) ? '?maxResults=' : '&maxResults=';
70  $url .= $max;
71  }
72 
73  // Check if order is specified.
74  if ($order)
75  {
76  $url .= (strpos($url, '?') === false) ? '?orderBy=' : '&orderBy=';
77  $url .= $order;
78  }
79 
80  // Check of token is specified.
81  if ($token)
82  {
83  $url .= (strpos($url, '?') === false) ? '?pageToken=' : '&pageToken=';
84  $url .= $token;
85  }
86 
87  // Check if alt is specified.
88  if ($alt)
89  {
90  $url .= (strpos($url, '?') === false) ? '?alt=' : '&alt=';
91  $url .= $alt;
92  }
93 
94  $jdata = $this->auth->query($url);
95 
96  return json_decode($jdata->body, true);
97  }
98  else
99  {
100  return false;
101  }
102  }
103 
104  /**
105  * Get a comment.
106  *
107  * @param string $id The ID of the comment to get.
108  * @param string $fields Used to specify the fields you want returned.
109  *
110  * @return mixed Data from Google
111  *
112  * @since 1234
113  */
114  public function getComment($id, $fields = null)
115  {
116  if ($this->isAuthenticated())
117  {
118  $url = $this->getOption('api.url') . 'comments/' . $id;
119 
120  // Check if fields is specified.
121  if ($fields)
122  {
123  $url .= '?fields=' . $fields;
124  }
125 
126  $jdata = $this->auth->query($url);
127 
128  return json_decode($jdata->body, true);
129  }
130  else
131  {
132  return false;
133  }
134  }
135 }