source: trunk/www.guidonia.net/wp/wp-content/plugins/webtv/Drivers/Zend/Gdata.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 8.4 KB
Line 
1<?php
2
3/**
4 * Zend Framework
5 *
6 * LICENSE
7 *
8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
15 *
16 * @category Zend
17 * @package Zend_Gdata
18 * @subpackage Gdata
19 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
21 */
22
23/**
24 * Zend_Gdata_App
25 */
26require_once 'Zend/Gdata/App.php';
27
28/**
29 * Provides functionality to interact with Google data APIs
30 * Subclasses exist to implement service-specific features
31 *
32 * As the Google data API protocol is based upon the Atom Publishing Protocol
33 * (APP), Gdata functionality extends the appropriate Zend_Gdata_App classes
34 *
35 * @link http://code.google.com/apis/gdata/overview.html
36 *
37 * @category Zend
38 * @package Zend_Gdata
39 * @subpackage Gdata
40 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
41 * @license http://framework.zend.com/license/new-bsd New BSD License
42 */
43class Zend_Gdata extends Zend_Gdata_App
44{
45
46 /**
47 * Service name for use with Google's authentication mechanisms
48 *
49 * @var string
50 */
51 const AUTH_SERVICE_NAME = 'xapi';
52
53 /**
54 * Default URI to which to POST.
55 *
56 * @var string
57 */
58 protected $_defaultPostUri = null;
59
60 /**
61 * Packages to search for classes when using magic __call method, in order.
62 *
63 * @var array
64 */
65 protected $_registeredPackages = array(
66 'Zend_Gdata_Kind',
67 'Zend_Gdata_Extension',
68 'Zend_Gdata',
69 'Zend_Gdata_App_Extension',
70 'Zend_Gdata_App');
71
72 /**
73 * Namespaces used for Gdata data
74 *
75 * @var array
76 */
77 public static $namespaces = array(
78 array('gd', 'http://schemas.google.com/g/2005', 1, 0),
79 array('openSearch', 'http://a9.com/-/spec/opensearchrss/1.0/', 1, 0),
80 array('openSearch', 'http://a9.com/-/spec/opensearch/1.1/', 2, 0),
81 array('rss', 'http://blogs.law.harvard.edu/tech/rss', 1, 0)
82 );
83
84 /**
85 * Client object used to communicate
86 *
87 * @var Zend_Gdata_HttpClient
88 */
89 protected $_httpClient;
90
91 /**
92 * Client object used to communicate in static context
93 *
94 * @var Zend_Gdata_HttpClient
95 */
96 protected static $_staticHttpClient = null;
97
98 /**
99 * Create Gdata object
100 *
101 * @param Zend_Http_Client $client
102 * @param string $applicationId The identity of the app in the form of
103 * Company-AppName-Version
104 */
105 public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
106 {
107 parent::__construct($client, $applicationId);
108 }
109
110 /**
111 * Imports a feed located at $uri.
112 *
113 * @param string $uri
114 * @param Zend_Http_Client $client The client used for communication
115 * @param string $className The class which is used as the return type
116 * @throws Zend_Gdata_App_Exception
117 * @return string|Zend_Gdata_App_Feed Returns string only if the object
118 * mapping has been disabled explicitly
119 * by passing false to the
120 * useObjectMapping() function.
121 */
122 public static function import($uri, $client = null,
123 $className='Zend_Gdata_Feed')
124 {
125 $app = new Zend_Gdata($client);
126 $requestData = $app->decodeRequest('GET', $uri);
127 $response = $app->performHttpRequest($requestData['method'], $requestData['url']);
128
129 $feedContent = $response->getBody();
130
131 $feed = self::importString($feedContent, $className);
132 if ($client != null) {
133 $feed->setHttpClient($client);
134 }
135 return $feed;
136 }
137
138 /**
139 * Retrieve feed as string or object
140 *
141 * @param mixed $location The location as string or Zend_Gdata_Query
142 * @param string $className The class type to use for returning the feed
143 * @throws Zend_Gdata_App_InvalidArgumentException
144 * @return string|Zend_Gdata_App_Feed Returns string only if the object
145 * mapping has been disabled explicitly
146 * by passing false to the
147 * useObjectMapping() function.
148 */
149 public function getFeed($location, $className='Zend_Gdata_Feed')
150 {
151 if (is_string($location)) {
152 $uri = $location;
153 } elseif ($location instanceof Zend_Gdata_Query) {
154 $uri = $location->getQueryUrl();
155 } else {
156 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
157 throw new Zend_Gdata_App_InvalidArgumentException(
158 'You must specify the location as either a string URI ' .
159 'or a child of Zend_Gdata_Query');
160 }
161 return parent::getFeed($uri, $className);
162 }
163
164 /**
165 * Retrieve entry as string or object
166 *
167 * @param mixed $location The location as string or Zend_Gdata_Query
168 * @throws Zend_Gdata_App_InvalidArgumentException
169 * @return string|Zend_Gdata_App_Entry Returns string only if the object
170 * mapping has been disabled explicitly
171 * by passing false to the
172 * useObjectMapping() function.
173 */
174 public function getEntry($location, $className='Zend_Gdata_Entry')
175 {
176 if (is_string($location)) {
177 $uri = $location;
178 } elseif ($location instanceof Zend_Gdata_Query) {
179 $uri = $location->getQueryUrl();
180 } else {
181 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
182 throw new Zend_Gdata_App_InvalidArgumentException(
183 'You must specify the location as either a string URI ' .
184 'or a child of Zend_Gdata_Query');
185 }
186 return parent::getEntry($uri, $className);
187 }
188
189 /**
190 * Performs a HTTP request using the specified method.
191 *
192 * Overrides the definition in the parent (Zend_Gdata_App)
193 * and uses the Zend_Gdata_HttpClient functionality
194 * to filter the HTTP requests and responses.
195 *
196 * @param string $method The HTTP method for the request -
197 * 'GET', 'POST', 'PUT', 'DELETE'
198 * @param string $url The URL to which this request is being performed,
199 * or null if found in $data
200 * @param array $headers An associative array of HTTP headers
201 * for this request
202 * @param string $body The body of the HTTP request
203 * @param string $contentType The value for the content type of the
204 * request body
205 * @param int $remainingRedirects Number of redirects to follow
206 * if requests results in one
207 * @return Zend_Http_Response The response object
208 */
209 public function performHttpRequest($method, $url, $headers = array(), $body = null, $contentType = null, $remainingRedirects = null)
210 {
211 if ($this->_httpClient instanceof Zend_Gdata_HttpClient) {
212 $filterResult = $this->_httpClient->filterHttpRequest($method, $url, $headers, $body, $contentType);
213 $method = $filterResult['method'];
214 $url = $filterResult['url'];
215 $body = $filterResult['body'];
216 $headers = $filterResult['headers'];
217 $contentType = $filterResult['contentType'];
218 return $this->_httpClient->filterHttpResponse(parent::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects));
219 } else {
220 return parent::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects);
221 }
222 }
223
224 /**
225 * Determines whether service object is authenticated.
226 *
227 * @return boolean True if service object is authenticated, false otherwise.
228 */
229 public function isAuthenticated()
230 {
231 $client = parent::getHttpClient();
232 if ($client->getClientLoginToken() ||
233 $client->getAuthSubToken()) {
234 return true;
235 }
236
237 return false;
238 }
239
240}
Note: See TracBrowser for help on using the repository browser.