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