51 * @link http://code.google.com/apis/documents/ |
51 * @link http://code.google.com/apis/documents/ |
52 * |
52 * |
53 * @category Zend |
53 * @category Zend |
54 * @package Zend_Gdata |
54 * @package Zend_Gdata |
55 * @subpackage Docs |
55 * @subpackage Docs |
56 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
56 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
57 * @license http://framework.zend.com/license/new-bsd New BSD License |
57 * @license http://framework.zend.com/license/new-bsd New BSD License |
58 */ |
58 */ |
59 class Zend_Gdata_Docs extends Zend_Gdata |
59 class Zend_Gdata_Docs extends Zend_Gdata |
60 { |
60 { |
61 |
|
62 const DOCUMENTS_LIST_FEED_URI = 'https://docs.google.com/feeds/documents/private/full'; |
61 const DOCUMENTS_LIST_FEED_URI = 'https://docs.google.com/feeds/documents/private/full'; |
63 const DOCUMENTS_FOLDER_FEED_URI = 'https://docs.google.com/feeds/folders/private/full'; |
62 const DOCUMENTS_FOLDER_FEED_URI = 'https://docs.google.com/feeds/folders/private/full'; |
64 const DOCUMENTS_CATEGORY_SCHEMA = 'http://schemas.google.com/g/2005#kind'; |
63 const DOCUMENTS_CATEGORY_SCHEMA = 'http://schemas.google.com/g/2005#kind'; |
65 const DOCUMENTS_CATEGORY_TERM = 'http://schemas.google.com/docs/2007#folder'; |
64 const DOCUMENTS_CATEGORY_TERM = 'http://schemas.google.com/docs/2007#folder'; |
66 const AUTH_SERVICE_NAME = 'writely'; |
65 const AUTH_SERVICE_NAME = 'writely'; |
67 |
66 |
|
67 /** |
|
68 * @var string |
|
69 */ |
68 protected $_defaultPostUri = self::DOCUMENTS_LIST_FEED_URI; |
70 protected $_defaultPostUri = self::DOCUMENTS_LIST_FEED_URI; |
69 |
71 |
70 private static $SUPPORTED_FILETYPES = array( |
72 /** |
71 'TXT'=>'text/plain', |
73 * @var array |
72 'CSV'=>'text/csv', |
74 */ |
73 'TSV'=>'text/tab-separated-values', |
75 protected static $SUPPORTED_FILETYPES = array( |
74 'TAB'=>'text/tab-separated-values', |
76 'TXT' => 'text/plain', |
75 'HTML'=>'text/html', |
77 'CSV' => 'text/csv', |
76 'HTM'=>'text/html', |
78 'TSV' => 'text/tab-separated-values', |
77 'DOC'=>'application/msword', |
79 'TAB' => 'text/tab-separated-values', |
78 'ODS'=>'application/vnd.oasis.opendocument.spreadsheet', |
80 'HTML' => 'text/html', |
79 'ODT'=>'application/vnd.oasis.opendocument.text', |
81 'HTM' => 'text/html', |
80 'RTF'=>'application/rtf', |
82 'DOC' => 'application/msword', |
81 'SXW'=>'application/vnd.sun.xml.writer', |
83 'DOCX' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
82 'XLS'=>'application/vnd.ms-excel', |
84 'ODS' => 'application/vnd.oasis.opendocument.spreadsheet', |
83 'XLSX'=>'application/vnd.ms-excel', |
85 'ODT' => 'application/vnd.oasis.opendocument.text', |
84 'PPT'=>'application/vnd.ms-powerpoint', |
86 'RTF' => 'application/rtf', |
85 'PPS'=>'application/vnd.ms-powerpoint'); |
87 'SXW' => 'application/vnd.sun.xml.writer', |
|
88 'XLS' => 'application/vnd.ms-excel', |
|
89 'XLSX' => 'application/vnd.ms-excel', |
|
90 'PPT' => 'application/vnd.ms-powerpoint', |
|
91 'PPS' => 'application/vnd.ms-powerpoint' |
|
92 ); |
86 |
93 |
87 /** |
94 /** |
88 * Create Gdata_Docs object |
95 * Create Gdata_Docs object |
89 * |
96 * |
90 * @param Zend_Http_Client $client (optional) The HTTP client to use when |
97 * @param Zend_Http_Client $client (optional) The HTTP client to use when |
133 /** |
141 /** |
134 * Retreive entry object representing a single document. |
142 * Retreive entry object representing a single document. |
135 * |
143 * |
136 * @param mixed $location The location for the entry, as a URL or Query |
144 * @param mixed $location The location for the entry, as a URL or Query |
137 * @return Zend_Gdata_Docs_DocumentListEntry |
145 * @return Zend_Gdata_Docs_DocumentListEntry |
|
146 * @throws Zend_Gdata_App_InvalidArgumentException |
138 */ |
147 */ |
139 public function getDocumentListEntry($location = null) |
148 public function getDocumentListEntry($location = null) |
140 { |
149 { |
141 if ($location === null) { |
150 if ($location === null) { |
142 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; |
151 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; |
143 throw new Zend_Gdata_App_InvalidArgumentException( |
152 throw new Zend_Gdata_App_InvalidArgumentException( |
144 'Location must not be null'); |
153 'Location must not be null' |
|
154 ); |
145 } else if ($location instanceof Zend_Gdata_Query) { |
155 } else if ($location instanceof Zend_Gdata_Query) { |
146 $uri = $location->getQueryUrl(); |
156 $uri = $location->getQueryUrl(); |
147 } else { |
157 } else { |
148 $uri = $location; |
158 $uri = $location; |
149 } |
159 } |
159 * dcmg89gw_62hfjj8m, pKq0CzjiF3YmGd0AIlHKqeg |
169 * dcmg89gw_62hfjj8m, pKq0CzjiF3YmGd0AIlHKqeg |
160 * @param string $docType The type of the document as used in the Google |
170 * @param string $docType The type of the document as used in the Google |
161 * Document List URLs. Examples: document, spreadsheet, presentation |
171 * Document List URLs. Examples: document, spreadsheet, presentation |
162 * @return Zend_Gdata_Docs_DocumentListEntry |
172 * @return Zend_Gdata_Docs_DocumentListEntry |
163 */ |
173 */ |
164 public function getDoc($docId, $docType) { |
174 public function getDoc($docId, $docType) |
|
175 { |
165 $location = 'https://docs.google.com/feeds/documents/private/full/' . |
176 $location = 'https://docs.google.com/feeds/documents/private/full/' . |
166 $docType . '%3A' . $docId; |
177 $docType . '%3A' . $docId; |
|
178 |
167 return $this->getDocumentListEntry($location); |
179 return $this->getDocumentListEntry($location); |
168 } |
180 } |
169 |
181 |
170 /** |
182 /** |
171 * Retreive entry object for the desired word processing document. |
183 * Retreive entry object for the desired word processing document. |
172 * |
184 * |
173 * @param string $id The URL id for the document. Example: |
185 * @param string $id The URL id for the document. Example: dcmg89gw_62hfjj8m |
174 * dcmg89gw_62hfjj8m |
186 * @return Zend_Gdata_Docs_DocumentListEntry |
175 */ |
187 */ |
176 public function getDocument($id) { |
188 public function getDocument($id) |
177 return $this->getDoc($id, 'document'); |
189 { |
|
190 return $this->getDoc($id, 'document'); |
178 } |
191 } |
179 |
192 |
180 /** |
193 /** |
181 * Retreive entry object for the desired spreadsheet. |
194 * Retreive entry object for the desired spreadsheet. |
182 * |
195 * |
183 * @param string $id The URL id for the document. Example: |
196 * @param string $id The URL id for the document. Example: pKq0CzjiF3YmGd0AIlHKqeg |
184 * pKq0CzjiF3YmGd0AIlHKqeg |
197 * @return Zend_Gdata_Docs_DocumentListEntry |
185 */ |
198 */ |
186 public function getSpreadsheet($id) { |
199 public function getSpreadsheet($id) |
187 return $this->getDoc($id, 'spreadsheet'); |
200 { |
|
201 return $this->getDoc($id, 'spreadsheet'); |
188 } |
202 } |
189 |
203 |
190 /** |
204 /** |
191 * Retreive entry object for the desired presentation. |
205 * Retreive entry object for the desired presentation. |
192 * |
206 * |
193 * @param string $id The URL id for the document. Example: |
207 * @param string $id The URL id for the document. Example: dcmg89gw_21gtrjcn |
194 * dcmg89gw_21gtrjcn |
208 * @return Zend_Gdata_Docs_DocumentListEntry |
195 */ |
209 */ |
196 public function getPresentation($id) { |
210 public function getPresentation($id) |
197 return $this->getDoc($id, 'presentation'); |
211 { |
|
212 return $this->getDoc($id, 'presentation'); |
198 } |
213 } |
199 |
214 |
200 /** |
215 /** |
201 * Upload a local file to create a new Google Document entry. |
216 * Upload a local file to create a new Google Document entry. |
202 * |
217 * |
217 * made. |
232 * made. |
218 * Example: 'https://docs.google.com/feeds/documents/private/full'. |
233 * Example: 'https://docs.google.com/feeds/documents/private/full'. |
219 * @return Zend_Gdata_Docs_DocumentListEntry The entry for the newly |
234 * @return Zend_Gdata_Docs_DocumentListEntry The entry for the newly |
220 * created Google Document. |
235 * created Google Document. |
221 */ |
236 */ |
222 public function uploadFile($fileLocation, $title=null, $mimeType=null, |
237 public function uploadFile($fileLocation, $title = null, $mimeType = null, |
223 $uri=null) |
238 $uri = null |
|
239 ) |
224 { |
240 { |
225 // Set the URI to which the file will be uploaded. |
241 // Set the URI to which the file will be uploaded. |
226 if ($uri === null) { |
242 if ($uri === null) { |
227 $uri = $this->_defaultPostUri; |
243 $uri = $this->_defaultPostUri; |
228 } |
244 } |
262 * ("folder%3Amy_parent_folder") |
278 * ("folder%3Amy_parent_folder") |
263 * @return Zend_Gdata_Entry The folder entry created. |
279 * @return Zend_Gdata_Entry The folder entry created. |
264 * @todo ZF-8732: This should return a *subclass* of Zend_Gdata_Entry, but |
280 * @todo ZF-8732: This should return a *subclass* of Zend_Gdata_Entry, but |
265 * the appropriate type doesn't exist yet. |
281 * the appropriate type doesn't exist yet. |
266 */ |
282 */ |
267 public function createFolder($folderName, $folderResourceId=null) { |
283 public function createFolder($folderName, $folderResourceId = null) |
268 $category = new Zend_Gdata_App_Extension_Category(self::DOCUMENTS_CATEGORY_TERM, |
284 { |
269 self::DOCUMENTS_CATEGORY_SCHEMA); |
285 $category = new Zend_Gdata_App_Extension_Category( |
270 $title = new Zend_Gdata_App_Extension_Title($folderName); |
286 self::DOCUMENTS_CATEGORY_TERM, |
271 $entry = new Zend_Gdata_Entry(); |
287 self::DOCUMENTS_CATEGORY_SCHEMA |
|
288 ); |
|
289 $title = new Zend_Gdata_App_Extension_Title($folderName); |
|
290 $entry = new Zend_Gdata_Entry(); |
272 |
291 |
273 $entry->setCategory(array($category)); |
292 $entry->setCategory(array($category)); |
274 $entry->setTitle($title); |
293 $entry->setTitle($title); |
275 |
294 |
276 $uri = self::DOCUMENTS_LIST_FEED_URI; |
295 $uri = self::DOCUMENTS_LIST_FEED_URI; |
293 * The default is a 'Zend_Gdata_Docs_DocumentListEntry'. |
312 * The default is a 'Zend_Gdata_Docs_DocumentListEntry'. |
294 * @return Zend_Gdata_Docs_DocumentListEntry The entry returned by the |
313 * @return Zend_Gdata_Docs_DocumentListEntry The entry returned by the |
295 * service after insertion. |
314 * service after insertion. |
296 */ |
315 */ |
297 public function insertDocument($data, $uri, |
316 public function insertDocument($data, $uri, |
298 $className='Zend_Gdata_Docs_DocumentListEntry') |
317 $className = 'Zend_Gdata_Docs_DocumentListEntry') |
299 { |
318 { |
300 return $this->insertEntry($data, $uri, $className); |
319 return $this->insertEntry($data, $uri, $className); |
301 } |
320 } |
302 |
|
303 } |
321 } |