[moodle] / moodle / lib / googleapi.php Repository:

Diff of /moodle/lib/googleapi.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5, Mon Jan 19 15:42:09 2009 WST revision 1.6, Mon Mar 9 00:53:11 2009 WST

By poltawski:

repository/googledocs New repository plugin MDL-16383 Google have now allowed documents to be downloaded via their API (http://googledataapis.blogspot.com/2009/02/start-downloads.html) so the google docs repo plugin could be finished. At the moment i've set the export format hardcoded, hopefully we can allow the repo api let the user choose later...

# Line 52  Line 52 
52          return $ret;          return $ret;
53      }      }
54    
55        protected function multi($requests, $options = array()) {
56            if($this->token){
57                // Adds authorisation head to a request so that it can be authentcated
58                $this->setHeader('Authorization: '. $this->get_auth_header_name().'"'.$this->token.'"');
59            }
60    
61            $ret = parent::multi($requests, $options);
62            // reset headers for next request
63            $this->header = array();
64            return $ret;
65        }
66    
67      public function get_sessiontoken(){      public function get_sessiontoken(){
68          return $this->token;          return $this->token;
69      }      }
# Line 190  Line 202 
202   * http://code.google.com/apis/documents/docs/2.0/developers_guide_protocol.html   * http://code.google.com/apis/documents/docs/2.0/developers_guide_protocol.html
203   */   */
204  class google_docs {  class google_docs {
205      const REALM            = 'http://docs.google.com/feeds/documents';      // need both docs and the spreadsheets realm
206        const REALM            = 'http://docs.google.com/feeds/ http://spreadsheets.google.com/feeds/';
207      const DOCUMENTFEED_URL = 'http://docs.google.com/feeds/documents/private/full';      const DOCUMENTFEED_URL = 'http://docs.google.com/feeds/documents/private/full';
208      const USER_PREF_NAME   = 'google_authsub_sesskey';      const USER_PREF_NAME   = 'google_authsub_sesskey';
209    
# Line 229  Line 242 
242       */       */
243      #FIXME      #FIXME
244      public function get_file_list($search = ''){      public function get_file_list($search = ''){
245            global $CFG;
246          $url = google_docs::DOCUMENTFEED_URL;          $url = google_docs::DOCUMENTFEED_URL;
247    
248          if($search){          if($search){
# Line 238  Line 252 
252    
253          $xml = new SimpleXMLElement($content);          $xml = new SimpleXMLElement($content);
254    
255    
256    
257          $files = array();          $files = array();
258          foreach($xml->entry as $gdoc){          foreach($xml->entry as $gdoc){
259    
260              $files[] =  array( 'title' => "$gdoc->title",              // there doesn't seem to to be cleaner way of getting the id/type
261                  'url'  =>  "{$gdoc->content['src']}",              // than spliting this..
262                  'source' => "{$gdoc->content['src']}",              if (preg_match('/^http:\/\/docs.google.com\/feeds\/documents\/private\/full\/([^%]*)%3A(.*)$/', $gdoc->id, $matches)){
263                    $docid = $matches[2];
264    
265                    // FIXME: We're making hard-coded choices about format here.
266                    // If the repo api can support it, we could let the user
267                    // chose.
268                    switch($matches[1]){
269                    case 'document':
270                        $title = $gdoc->title.'.rtf';
271                        $source = 'http://docs.google.com/feeds/download/documents/Export?docID='.$docid.'&exportFormat=rtf';
272                        break;
273                    case 'presentation':
274                        $title = $gdoc->title.'.ppt';
275                        $source = 'http://docs.google.com/feeds/download/presentations/Export?docID='.$docid.'&exportFormat=ppt';
276                        break;
277                    case 'spreadsheet':
278                        $title = $gdoc->title.'.xls';
279                        $source = 'http://spreadsheets.google.com/feeds/download/spreadsheets/Export?key='.$docid.'&fmcmd=4';
280                        break;
281                    }
282    
283                    $files[] =  array( 'title' => $title,
284                        'url' => "{$gdoc->link[0]->attributes()->href}",
285                        'source' => $source,
286                  'date'   => usertime(strtotime($gdoc->updated)),                  'date'   => usertime(strtotime($gdoc->updated)),
287                        'thumbnail' => $CFG->pixpath.'/f/'.mimeinfo('icon32', $title)
288              );              );
289          }          }
290            }
291    
292          return $files;          return $files;
293      }      }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

Moodle CVS Admin
ViewVC Help
Powered by ViewVC 1.0.7