Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Gdata/Docs.php
Go to the documentation of this file.
00001 <?php
00002 
00027 require_once 'Zend/Gdata.php';
00028 
00032 require_once 'Zend/Gdata/Docs/DocumentListFeed.php';
00033 
00037 require_once 'Zend/Gdata/Docs/DocumentListEntry.php';
00038 
00042 require_once 'Zend/Gdata/App/Extension/Category.php';
00043 
00047 require_once 'Zend/Gdata/App/Extension/Title.php';
00048 
00059 class Zend_Gdata_Docs extends Zend_Gdata
00060 {
00061 
00062     const DOCUMENTS_LIST_FEED_URI = 'http://docs.google.com/feeds/documents/private/full';
00063     const DOCUMENTS_FOLDER_FEED_URI = 'http://docs.google.com/feeds/folders/private/full';
00064     const DOCUMENTS_CATEGORY_SCHEMA = 'http://schemas.google.com/g/2005#kind';
00065     const DOCUMENTS_CATEGORY_TERM = 'http://schemas.google.com/docs/2007#folder';
00066     const AUTH_SERVICE_NAME = 'writely';
00067 
00068     protected $_defaultPostUri = self::DOCUMENTS_LIST_FEED_URI;
00069 
00070     private static $SUPPORTED_FILETYPES = array(
00071       'TXT'=>'text/plain',
00072       'CSV'=>'text/csv',
00073       'TSV'=>'text/tab-separated-values',
00074       'TAB'=>'text/tab-separated-values',
00075       'HTML'=>'text/html',
00076       'HTM'=>'text/html',
00077       'DOC'=>'application/msword',
00078       'ODS'=>'application/vnd.oasis.opendocument.spreadsheet',
00079       'ODT'=>'application/vnd.oasis.opendocument.text',
00080       'RTF'=>'application/rtf',
00081       'SXW'=>'application/vnd.sun.xml.writer',
00082       'XLS'=>'application/vnd.ms-excel',
00083       'XLSX'=>'application/vnd.ms-excel',
00084       'PPT'=>'application/vnd.ms-powerpoint',
00085       'PPS'=>'application/vnd.ms-powerpoint');
00086 
00094     public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
00095     {
00096         $this->registerPackage('Zend_Gdata_Docs');
00097         parent::__construct($client, $applicationId);
00098         $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
00099     }
00100 
00111     public static function lookupMimeType($fileExtension) {
00112       return self::$SUPPORTED_FILETYPES[strtoupper($fileExtension)];
00113     }
00114 
00121     public function getDocumentListFeed($location = null)
00122     {
00123         if ($location === null) {
00124             $uri = self::DOCUMENTS_LIST_FEED_URI;
00125         } else if ($location instanceof Zend_Gdata_Query) {
00126             $uri = $location->getQueryUrl();
00127         } else {
00128             $uri = $location;
00129         }
00130         return parent::getFeed($uri, 'Zend_Gdata_Docs_DocumentListFeed');
00131     }
00132 
00139     public function getDocumentListEntry($location = null)
00140     {
00141         if ($location === null) {
00142             require_once 'Zend/Gdata/App/InvalidArgumentException.php';
00143             throw new Zend_Gdata_App_InvalidArgumentException(
00144                     'Location must not be null');
00145         } else if ($location instanceof Zend_Gdata_Query) {
00146             $uri = $location->getQueryUrl();
00147         } else {
00148             $uri = $location;
00149         }
00150         return parent::getEntry($uri, 'Zend_Gdata_Docs_DocumentListEntry');
00151     }
00152 
00164     public function getDoc($docId, $docType) {
00165         $location = 'http://docs.google.com/feeds/documents/private/full/' .
00166             $docType . '%3A' . $docId;
00167         return $this->getDocumentListEntry($location);
00168     }
00169 
00176     public function getDocument($id) {
00177       return $this->getDoc($id, 'document');
00178     }
00179 
00186     public function getSpreadsheet($id) {
00187       return $this->getDoc($id, 'spreadsheet');
00188     }
00189 
00196     public function getPresentation($id) {
00197       return $this->getDoc($id, 'presentation');
00198     }
00199 
00222     public function uploadFile($fileLocation, $title=null, $mimeType=null,
00223                                $uri=null)
00224     {
00225         // Set the URI to which the file will be uploaded.
00226         if ($uri === null) {
00227             $uri = $this->_defaultPostUri;
00228         }
00229 
00230         // Create the media source which describes the file.
00231         $fs = $this->newMediaFileSource($fileLocation);
00232         if ($title !== null) {
00233             $slugHeader = $title;
00234         } else {
00235             $slugHeader = $fileLocation;
00236         }
00237 
00238         // Set the slug header to tell the Google Documents server what the
00239         // title of the document should be and what the file extension was
00240         // for the original file.
00241         $fs->setSlug($slugHeader);
00242 
00243         // Set the mime type of the data.
00244         if ($mimeType === null) {
00245           $filenameParts = explode('.', $fileLocation);
00246           $fileExtension = end($filenameParts);
00247           $mimeType = self::lookupMimeType($fileExtension);
00248         }
00249 
00250         // Set the mime type for the upload request.
00251         $fs->setContentType($mimeType);
00252 
00253         // Send the data to the server.
00254         return $this->insertDocument($fs, $uri);
00255     }
00256 
00267     public function createFolder($folderName, $folderResourceId=null) {
00268         $category = new Zend_Gdata_App_Extension_Category(self::DOCUMENTS_CATEGORY_TERM, 
00269                                                           self::DOCUMENTS_CATEGORY_SCHEMA);
00270         $title = new Zend_Gdata_App_Extension_Title($folderName);
00271         $entry = new Zend_Gdata_Entry();
00272 
00273         $entry->setCategory(array($category));
00274         $entry->setTitle($title);
00275 
00276         $uri = self::DOCUMENTS_LIST_FEED_URI;
00277         if ($folderResourceId != null) {
00278             $uri = self::DOCUMENTS_FOLDER_FEED_URI . '/' . $folderResourceId;
00279         }
00280 
00281         return $this->insertEntry($entry, $uri);
00282     }
00283 
00297     public function insertDocument($data, $uri,
00298         $className='Zend_Gdata_Docs_DocumentListEntry')
00299     {
00300         return $this->insertEntry($data, $uri, $className);
00301     }
00302 
00303 }
 All Data Structures Namespaces Files Functions Variables Enumerations