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 * Joomla Platform class for interacting with the Google APIs.
16 *
17 * @property-read JGoogleData $data Google API object for data.
18 * @property-read JGoogleEmbed $embed Google API object for embed generation.
19 *
20 * @since 12.3
21 * @deprecated 4.0 Use the `joomla/google` package via Composer instead
22 */
23 class JGoogle
24 {
25 /**
26 * @var Registry Options for the Google object.
27 * @since 12.3
28 */
29 protected $options;
30
31 /**
32 * @var JGoogleAuth The authentication client object to use in sending authenticated HTTP requests.
33 * @since 12.3
34 */
35 protected $auth;
36
37 /**
38 * @var JGoogleData Google API object for data request.
39 * @since 12.3
40 */
41 protected $data;
42
43 /**
44 * @var JGoogleEmbed Google API object for embed generation.
45 * @since 12.3
46 */
47 protected $embed;
48
49 /**
50 * Constructor.
51 *
52 * @param Registry $options Google options object.
53 * @param JGoogleAuth $auth The authentication client object.
54 *
55 * @since 12.3
56 */
57 public function __construct(Registry $options = null, JGoogleAuth $auth = null)
58 {
59 $this->options = isset($options) ? $options : new Registry;
60 $this->auth = isset($auth) ? $auth : new JGoogleAuthOauth2($this->options);
61 }
62
63 /**
64 * Method to create JGoogleData objects
65 *
66 * @param string $name Name of property to retrieve
67 * @param Registry $options Google options object.
68 * @param JGoogleAuth $auth The authentication client object.
69 *
70 * @return JGoogleData Google data API object.
71 *
72 * @since 12.3
73 */
74 public function data($name, $options = null, $auth = null)
75 {
76 if ($this->options && !$options)
77 {
78 $options = $this->options;
79 }
80
81 if ($this->auth && !$auth)
82 {
83 $auth = $this->auth;
84 }
85
86 switch ($name)
87 {
88 case 'plus':
89 case 'Plus':
90 return new JGoogleDataPlus($options, $auth);
91 case 'picasa':
92 case 'Picasa':
93 return new JGoogleDataPicasa($options, $auth);
94 case 'adsense':
95 case 'Adsense':
96 return new JGoogleDataAdsense($options, $auth);
97 case 'calendar':
98 case 'Calendar':
99 return new JGoogleDataCalendar($options, $auth);
100 default:
101 return;
102 }
103 }
104
105 /**
106 * Method to create JGoogleEmbed objects
107 *
108 * @param string $name Name of property to retrieve
109 * @param Registry $options Google options object.
110 *
111 * @return JGoogleEmbed Google embed API object.
112 *
113 * @since 12.3
114 */
115 public function embed($name, $options = null)
116 {
117 if ($this->options && !$options)
118 {
119 $options = $this->options;
120 }
121
122 switch ($name)
123 {
124 case 'maps':
125 case 'Maps':
126 return new JGoogleEmbedMaps($options);
127 case 'analytics':
128 case 'Analytics':
129 return new JGoogleEmbedAnalytics($options);
130 default:
131 return;
132 }
133 }
134
135 /**
136 * Get an option from the JGoogle instance.
137 *
138 * @param string $key The name of the option to get.
139 *
140 * @return mixed The option value.
141 *
142 * @since 12.3
143 */
144 public function getOption($key)
145 {
146 return $this->options->get($key);
147 }
148
149 /**
150 * Set an option for the JGoogle instance.
151 *
152 * @param string $key The name of the option to set.
153 * @param mixed $value The option value to set.
154 *
155 * @return JGoogle This object for method chaining.
156 *
157 * @since 12.3
158 */
159 public function setOption($key, $value)
160 {
161 $this->options->set($key, $value);
162
163 return $this;
164 }
165 }
166