File indexing completed on 2024-12-22 05:37:16
0001 <?php 0002 0003 /** 0004 * Zend Framework 0005 * 0006 * LICENSE 0007 * 0008 * This source file is subject to the new BSD license that is bundled 0009 * with this package in the file LICENSE.txt. 0010 * It is also available through the world-wide-web at this URL: 0011 * http://framework.zend.com/license/new-bsd 0012 * If you did not receive a copy of the license and are unable to 0013 * obtain it through the world-wide-web, please send an email 0014 * to license@zend.com so we can send you a copy immediately. 0015 * 0016 * @category Zend 0017 * @package Zend_Gdata 0018 * @subpackage Gdata 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 * @version $Id$ 0022 */ 0023 0024 /** 0025 * Zend_Gdata_App 0026 */ 0027 // require_once 'Zend/Gdata/App.php'; 0028 0029 /** 0030 * Provides functionality to interact with Google data APIs 0031 * Subclasses exist to implement service-specific features 0032 * 0033 * As the Google data API protocol is based upon the Atom Publishing Protocol 0034 * (APP), Gdata functionality extends the appropriate Zend_Gdata_App classes 0035 * 0036 * @link http://code.google.com/apis/gdata/overview.html 0037 * 0038 * @category Zend 0039 * @package Zend_Gdata 0040 * @subpackage Gdata 0041 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0042 * @license http://framework.zend.com/license/new-bsd New BSD License 0043 */ 0044 class Zend_Gdata extends Zend_Gdata_App 0045 { 0046 0047 /** 0048 * Service name for use with Google's authentication mechanisms 0049 * 0050 * @var string 0051 */ 0052 const AUTH_SERVICE_NAME = 'xapi'; 0053 0054 /** 0055 * Default URI to which to POST. 0056 * 0057 * @var string 0058 */ 0059 protected $_defaultPostUri = null; 0060 0061 /** 0062 * Packages to search for classes when using magic __call method, in order. 0063 * 0064 * @var array 0065 */ 0066 protected $_registeredPackages = array( 0067 'Zend_Gdata_Kind', 0068 'Zend_Gdata_Extension', 0069 'Zend_Gdata', 0070 'Zend_Gdata_App_Extension', 0071 'Zend_Gdata_App'); 0072 0073 /** 0074 * Namespaces used for Gdata data 0075 * 0076 * @var array 0077 */ 0078 public static $namespaces = array( 0079 array('gd', 'http://schemas.google.com/g/2005', 1, 0), 0080 array('openSearch', 'http://a9.com/-/spec/opensearchrss/1.0/', 1, 0), 0081 array('openSearch', 'http://a9.com/-/spec/opensearch/1.1/', 2, 0), 0082 array('rss', 'http://blogs.law.harvard.edu/tech/rss', 1, 0) 0083 ); 0084 0085 /** 0086 * Client object used to communicate 0087 * 0088 * @var Zend_Gdata_HttpClient 0089 */ 0090 protected $_httpClient; 0091 0092 /** 0093 * Client object used to communicate in static context 0094 * 0095 * @var Zend_Gdata_HttpClient 0096 */ 0097 protected static $_staticHttpClient = null; 0098 0099 /** 0100 * Create Gdata object 0101 * 0102 * @param Zend_Http_Client $client 0103 * @param string $applicationId The identity of the app in the form of 0104 * Company-AppName-Version 0105 */ 0106 public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0') 0107 { 0108 parent::__construct($client, $applicationId); 0109 } 0110 0111 /** 0112 * Imports a feed located at $uri. 0113 * 0114 * @param string $uri 0115 * @param Zend_Http_Client $client The client used for communication 0116 * @param string $className The class which is used as the return type 0117 * @throws Zend_Gdata_App_Exception 0118 * @return string|Zend_Gdata_App_Feed Returns string only if the object 0119 * mapping has been disabled explicitly 0120 * by passing false to the 0121 * useObjectMapping() function. 0122 */ 0123 public static function import($uri, $client = null, 0124 $className='Zend_Gdata_Feed', $useObjectMapping = true) 0125 { 0126 $app = new Zend_Gdata($client); 0127 $requestData = $app->decodeRequest('GET', $uri); 0128 $response = $app->performHttpRequest($requestData['method'], $requestData['url']); 0129 0130 $feedContent = $response->getBody(); 0131 0132 $feed = self::importString($feedContent, $className); 0133 if ($client != null) { 0134 $feed->setHttpClient($client); 0135 } 0136 return $feed; 0137 } 0138 0139 /** 0140 * Retrieve feed as string or object 0141 * 0142 * @param mixed $location The location as string or Zend_Gdata_Query 0143 * @param string $className The class type to use for returning the feed 0144 * @throws Zend_Gdata_App_InvalidArgumentException 0145 * @return string|Zend_Gdata_App_Feed Returns string only if the object 0146 * mapping has been disabled explicitly 0147 * by passing false to the 0148 * useObjectMapping() function. 0149 */ 0150 public function getFeed($location, $className='Zend_Gdata_Feed') 0151 { 0152 if (is_string($location)) { 0153 $uri = $location; 0154 } elseif ($location instanceof Zend_Gdata_Query) { 0155 $uri = $location->getQueryUrl(); 0156 } else { 0157 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0158 throw new Zend_Gdata_App_InvalidArgumentException( 0159 'You must specify the location as either a string URI ' . 0160 'or a child of Zend_Gdata_Query'); 0161 } 0162 return parent::getFeed($uri, $className); 0163 } 0164 0165 /** 0166 * Retrieve entry as string or object 0167 * 0168 * @param mixed $location The location as string or Zend_Gdata_Query 0169 * @throws Zend_Gdata_App_InvalidArgumentException 0170 * @return string|Zend_Gdata_App_Entry Returns string only if the object 0171 * mapping has been disabled explicitly 0172 * by passing false to the 0173 * useObjectMapping() function. 0174 */ 0175 public function getEntry($location, $className='Zend_Gdata_Entry') 0176 { 0177 if (is_string($location)) { 0178 $uri = $location; 0179 } elseif ($location instanceof Zend_Gdata_Query) { 0180 $uri = $location->getQueryUrl(); 0181 } else { 0182 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0183 throw new Zend_Gdata_App_InvalidArgumentException( 0184 'You must specify the location as either a string URI ' . 0185 'or a child of Zend_Gdata_Query'); 0186 } 0187 return parent::getEntry($uri, $className); 0188 } 0189 0190 /** 0191 * Performs a HTTP request using the specified method. 0192 * 0193 * Overrides the definition in the parent (Zend_Gdata_App) 0194 * and uses the Zend_Gdata_HttpClient functionality 0195 * to filter the HTTP requests and responses. 0196 * 0197 * @param string $method The HTTP method for the request - 0198 * 'GET', 'POST', 'PUT', 'DELETE' 0199 * @param string $url The URL to which this request is being performed, 0200 * or null if found in $data 0201 * @param array $headers An associative array of HTTP headers 0202 * for this request 0203 * @param string $body The body of the HTTP request 0204 * @param string $contentType The value for the content type of the 0205 * request body 0206 * @param int $remainingRedirects Number of redirects to follow 0207 * if requests results in one 0208 * @return Zend_Http_Response The response object 0209 */ 0210 public function performHttpRequest($method, $url, $headers = array(), $body = null, $contentType = null, $remainingRedirects = null) 0211 { 0212 if ($this->_httpClient instanceof Zend_Gdata_HttpClient) { 0213 $filterResult = $this->_httpClient->filterHttpRequest($method, $url, $headers, $body, $contentType); 0214 $method = $filterResult['method']; 0215 $url = $filterResult['url']; 0216 $body = $filterResult['body']; 0217 $headers = $filterResult['headers']; 0218 $contentType = $filterResult['contentType']; 0219 return $this->_httpClient->filterHttpResponse(parent::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects)); 0220 } else { 0221 return parent::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects); 0222 } 0223 } 0224 0225 /** 0226 * Determines whether service object is authenticated. 0227 * 0228 * @return boolean True if service object is authenticated, false otherwise. 0229 */ 0230 public function isAuthenticated() 0231 { 0232 $client = parent::getHttpClient(); 0233 if ($client->getClientLoginToken() || 0234 $client->getAuthSubToken()) { 0235 return true; 0236 } 0237 0238 return false; 0239 } 0240 0241 }