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 JGoogleDataPlusComments 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 comments for an activity.
42 *
43 * @param string $activityId The ID of the activity to get comments for.
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 $order The order in which to sort the list of comments. Acceptable values are "ascending" and "descending".
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 listComments($activityId, $fields = null, $max = 20, $order = null, $token = null, $alt = null)
56 {
57 if ($this->isAuthenticated())
58 {
59 $url = $this->getOption('api.url') . 'activities/' . $activityId . '/comments';
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 != 20)
69 {
70 $url .= (strpos($url, '?') === false) ? '?maxResults=' : '&maxResults=';
71 $url .= $max;
72 }
73
74 // Check if order is specified.
75 if ($order)
76 {
77 $url .= (strpos($url, '?') === false) ? '?orderBy=' : '&orderBy=';
78 $url .= $order;
79 }
80
81 // Check of token is specified.
82 if ($token)
83 {
84 $url .= (strpos($url, '?') === false) ? '?pageToken=' : '&pageToken=';
85 $url .= $token;
86 }
87
88 // Check if alt is specified.
89 if ($alt)
90 {
91 $url .= (strpos($url, '?') === false) ? '?alt=' : '&alt=';
92 $url .= $alt;
93 }
94
95 $jdata = $this->auth->query($url);
96
97 return json_decode($jdata->body, true);
98 }
99 else
100 {
101 return false;
102 }
103 }
104
105 /**
106 * Get a comment.
107 *
108 * @param string $id The ID of the comment to get.
109 * @param string $fields Used to specify the fields you want returned.
110 *
111 * @return mixed Data from Google
112 *
113 * @since 12.3
114 */
115 public function getComment($id, $fields = null)
116 {
117 if ($this->isAuthenticated())
118 {
119 $url = $this->getOption('api.url') . 'comments/' . $id;
120
121 // Check if fields is specified.
122 if ($fields)
123 {
124 $url .= '?fields=' . $fields;
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