From 1e12baddde828b0aa941f44621ef000cd3cbebd2 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Mon, 27 Aug 2012 14:47:01 +0800 Subject: [PATCH] MDL-35034 Repository: Google Docs does not fail when download is restricted Conflicts: lib/googleapi.php repository/googledocs/lib.php --- lib/googleapi.php | 20 +++++++++++--------- repository/googledocs/lib.php | 4 +++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/googleapi.php b/lib/googleapi.php index a079ffb5d2f..75d697cafb5 100644 --- a/lib/googleapi.php +++ b/lib/googleapi.php @@ -316,19 +316,21 @@ class google_docs { $source = 'https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key='.$docid.'&exportFormat=xls'; break; case 'pdf': + case 'file': $title = (string)$gdoc->title; - $source = (string)$gdoc->content[0]->attributes()->src; + // Some files don't have a content probably because the download has been restricted. + if (isset($gdoc->content)) { + $source = (string)$gdoc->content[0]->attributes()->src; + } break; } - if(!empty($source)){ - $files[] = array( 'title' => $title, - 'url' => "{$gdoc->link[0]->attributes()->href}", - 'source' => $source, - 'date' => usertime(strtotime($gdoc->updated)), - 'thumbnail' => (string) $OUTPUT->pix_url(file_extension_icon($title, 32)) - ); - } + $files[] = array( 'title' => $title, + 'url' => "{$gdoc->link[0]->attributes()->href}", + 'source' => $source, + 'date' => usertime(strtotime($gdoc->updated)), + 'thumbnail' => (string) $OUTPUT->pix_url(file_extension_icon($title, 32)) + ); } return $files; diff --git a/repository/googledocs/lib.php b/repository/googledocs/lib.php index 36e5d8e05c3..cfa274c8141 100644 --- a/repository/googledocs/lib.php +++ b/repository/googledocs/lib.php @@ -109,7 +109,9 @@ class repository_googledocs extends repository { } public function get_file($url, $file) { - global $CFG; + if (empty($url)) { + throw new repository_exception('cannotdownload', 'repository'); + } $path = $this->prepare_file($file); $fp = fopen($path, 'w');