diff --git a/lib/flickrlib.php b/lib/flickrlib.php index 79b83ebdf32..2e6452317bc 100644 --- a/lib/flickrlib.php +++ b/lib/flickrlib.php @@ -1113,7 +1113,9 @@ class phpFlickr { $args['content_type'] = isset($meta['content_type']) ? $meta['content_type'] : 1; // photo by default $args['hidden'] = isset($meta['hidden']) ? $meta['hidden'] : 2; // hide from public searches by default - $args['async'] = 1; + // Do not enable the asynchronous more because then the query does not return a photo ID, + // and we need a photo ID to add the photo to a set later on. + // $args['async'] = 1; $args['api_key'] = $this->api_key; if (!empty($this->email)) { @@ -1144,8 +1146,17 @@ class phpFlickr { $args['photo'] = $photo; // $this->curl will process it correctly if ($response = $this->curl->post($this->Upload, $args)) { + $xml = simplexml_load_string($response); + if ($xml['stat'] == 'fail') { + $this->parsed_response = array('stat' => (string) $xml['stat'], 'code' => (int) $xml->err['code'], + 'message' => (string) $xml->err['msg']); + } elseif ($xml['stat'] == 'ok') { + $this->parsed_response = array('stat' => (string) $xml['stat'], 'photoid' => (int) $xml->photoid); + } return true; } else { + $this->parsed_response = array('stat' => 'fail', 'code' => $this->curl->get_errno(), + 'message' => $this->curl->error); return false; } } diff --git a/portfolio/flickr/lib.php b/portfolio/flickr/lib.php index 6fc9659afb5..df85a00a3f9 100644 --- a/portfolio/flickr/lib.php +++ b/portfolio/flickr/lib.php @@ -64,7 +64,7 @@ class portfolio_plugin_flickr extends portfolio_plugin_push_base { 'hidden' => $this->get_export_config('hidden'))); if ($return) { // Attach photo to a set if requested - if ($this->get_export_config('set')) { + if ($this->get_export_config('set') && !empty($this->flickr->parsed_response['photoid'])) { $this->flickr->photosets_addPhoto($this->get_export_config('set'), $this->flickr->parsed_response['photoid']); } @@ -188,10 +188,12 @@ class portfolio_plugin_flickr extends portfolio_plugin_push_base { $mform->setDefaults(array('plugin_is_public' => true)); - $sets = $this->get_sets(); - - if (!empty($sets)) { - $sets[0] = '----'; + $rawsets = $this->get_sets(); + if (!empty($rawsets)) { + $sets = array('0' => '----'); + foreach ($rawsets as $key => $value) { + $sets[$key] = $value; + } $mform->addElement('select', 'plugin_set', get_string('set', 'portfolio_flickr'), $sets); } }