MDL-26660 libraries: Do not try to parse non-valid XML
authorFrederic Massart <fred@moodle.com>
Tue, 30 Oct 2012 01:22:48 +0000 (09:22 +0800)
committerFrederic Massart <fred@moodle.com>
Tue, 30 Oct 2012 01:23:40 +0000 (09:23 +0800)
lib/googleapi.php

index 3ace654..f9fe137 100644 (file)
@@ -317,11 +317,14 @@ class google_picasa {
      * @return mixes $files Array in the format get_listing uses for folders
      */
     public function get_albums() {
+        $files = array();
         $content = $this->googleoauth->get(self::LIST_ALBUMS_URL);
-        $xml = new SimpleXMLElement($content);
 
-        $files = array();
+        if (empty($content)) {
+            return $files;
+        }
 
+        $xml = new SimpleXMLElement($content);
         foreach ($xml->entry as $album) {
             $gphoto = $album->children('http://schemas.google.com/photos/2007');
 
@@ -338,7 +341,6 @@ class google_picasa {
                 'thumbnail_height' => 160,
                 'children' => array(),
             );
-
         }
 
         return $files;
@@ -352,12 +354,14 @@ class google_picasa {
      * @return mixed $files A list of files for the file picker
      */
     public function get_photo_details($rawxml) {
+        $files = array();
+        if (empty($rawxml)) {
+            return $files;
+        }
 
         $xml = new SimpleXMLElement($rawxml);
         $this->lastalbumname = (string)$xml->title;
 
-        $files = array();
-
         foreach ($xml->entry as $photo) {
             $gphoto = $photo->children('http://schemas.google.com/photos/2007');