|
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...
|
| 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 |
} |
} |
| 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 |
|
|
| 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){ |
| 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 |
} |
} |