Skip to content
Snippets Groups Projects
Commit d08fdac5 authored by febbraro's avatar febbraro Committed by Eric Mckenna
Browse files

Issue #686470 by johnv, wojtha, febbraro | rjbrown99: Fixed Filefield

mapper: URLs with spaces not parsed properly.
parent 4234b51c
No related branches found
No related tags found
No related merge requests found
......@@ -263,15 +263,41 @@ class FeedsEnclosure extends FeedsElement {
return $this->mime_type;
}
/**
* Use this method instead of FeedsElement::getValue() when fetching the file
* from the URL.
*
* @return
* Value with encoded space characters to safely fetch the file from the URL.
*
* @see FeedsElement::getValue()
*/
public function getUrlEncodedValue() {
return str_replace(' ', '%20', $this->getValue());
}
/**
* Use this method instead of FeedsElement::getValue() to get the file name
* transformed for better local saving (underscores instead of spaces)
*
* @return
* Value with space characters changed to underscores.
*
* @see FeedsElement::getValue()
*/
public function getLocalValue() {
return str_replace(' ', '_', $this->getValue());
}
/**
* @return
* The content of the referenced resource.
*/
public function getContent() {
feeds_include_library('http_request.inc', 'http_request');
$result = http_request_get($this->getValue());
$result = http_request_get($this->getUrlEncodedValue());
if ($result->code != 200) {
throw new Exception(t('Download of @url failed with code !code.', array('@url' => $this->getValue(), '!code' => $result->code)));
throw new Exception(t('Download of @url failed with code !code.', array('@url' => $this->getUrlEncodedValue(), '!code' => $result->code)));
}
return $result->data;
}
......@@ -318,7 +344,7 @@ class FeedsEnclosure extends FeedsElement {
}
}
else {
$filename = basename($this->getValue());
$filename = basename($this->getLocalValue());
if (module_exists('transliteration')) {
require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';
$filename = transliteration_clean_filename($filename);
......
......@@ -3,3 +3,4 @@ Title,published,file,GUID
"Jeff vs Tom",428112720,<?php print $files[1]; ?>,1
"Attersee",1151766000,<?php print $files[2]; ?>,2
"H Street NE",1256326995,<?php print $files[3]; ?>,3
"La Fayette Park",1256326995,<?php print $files[4]; ?>,4
......@@ -168,4 +168,36 @@ print '<?xml version="1.0" encoding="utf-8" standalone="yes"?>';
<category term="hstreetbynight" scheme="http://www.flickr.com/photos/tags/" />
<category term="forlaia" scheme="http://www.flickr.com/photos/tags/" />
</entry>
<entry>
<title>La Fayette Park</title>
<link rel="alternate" type="text/html" href="http://www.flickr.com/photos/a-barth/4209685951/in/set-72157603970496952/"/>
<id>tag:flickr.com,2005:/photo/4209685951/in/set-72157603970496952</id>
<published>2009-07-09T21:48:04Z</published>
<updated>2009-07-09T21:48:04Z</updated>
<dc:date.Taken>2009-05-01T00:00:00-08:00</dc:date.Taken>
<content type="html">&lt;p&gt;&lt;a href=&quot;http://www.flickr.com/people/a-barth/&quot;&gt;Alex Barth&lt;/a&gt; posted a photo:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/a-barth/3596408735/&quot; title=&quot;Tubing is fun&quot;&gt;&lt;img src=&quot;http://farm3.staticflickr.com/2675/4209685951_cb073de96f_m.jpg&quot; width=&quot;239&quot; height=&quot;240&quot; alt=&quot;La Fayette park&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Virginia, 2009&lt;/p&gt;</content>
<author>
<name>Alex Barth</name>
<uri>http://www.flickr.com/people/a-barth/</uri>
</author>
<link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc/2.0/deed.en" />
<link rel="enclosure" type="image/jpeg" href="<?php print $image_urls[4]; ?>" />
<category term="color" scheme="http://www.flickr.com/photos/tags/" />
<category term="film" scheme="http://www.flickr.com/photos/tags/" />
<category term="virginia" scheme="http://www.flickr.com/photos/tags/" />
<category term="awesome" scheme="http://www.flickr.com/photos/tags/" />
<category term="ishootfilm" scheme="http://www.flickr.com/photos/tags/" />
<category term="va" scheme="http://www.flickr.com/photos/tags/" />
<category term="badge" scheme="http://www.flickr.com/photos/tags/" />
<category term="tubing" scheme="http://www.flickr.com/photos/tags/" />
<category term="fuji160c" scheme="http://www.flickr.com/photos/tags/" />
<category term="anfamiliebarth" scheme="http://www.flickr.com/photos/tags/" />
<category term="canon24l" scheme="http://www.flickr.com/photos/tags/" />
</entry>
</feed>
\ No newline at end of file
......@@ -54,7 +54,7 @@ class FeedsMapperFileTestCase extends FeedsMapperTestCase {
),
));
$nid = $this->createFeedNode('syndication', $GLOBALS['base_url'] . '/testing/feeds/flickr.xml');
$this->assertText('Created 4 nodes');
$this->assertText('Created 5 nodes');
$files = $this->testFiles();
$entities = db_select('feeds_item')
......@@ -63,7 +63,8 @@ class FeedsMapperFileTestCase extends FeedsMapperTestCase {
->execute();
foreach ($entities as $entity) {
$this->drupalGet('node/' . $entity->entity_id . '/edit');
$this->assertText(array_shift($files));
$f = new FeedsEnclosure(array_shift($files), NULL);
$this->assertText($f->getLocalValue());
}
// 2) Test mapping local resources to file field.
......@@ -101,7 +102,7 @@ class FeedsMapperFileTestCase extends FeedsMapperTestCase {
'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/testing/feeds/files.csv',
);
$this->drupalPost('import/node', $edit, 'Import');
$this->assertText('Created 4 nodes');
$this->assertText('Created 5 nodes');
// Assert: files should be in resources/.
$files = $this->testFiles();
......@@ -111,7 +112,8 @@ class FeedsMapperFileTestCase extends FeedsMapperTestCase {
->execute();
foreach ($entities as $entity) {
$this->drupalGet('node/' . $entity->entity_id . '/edit');
$this->assertRaw('resources/' . array_shift($files));
$f = new FeedsEnclosure(array_shift($files), NULL);
$this->assertRaw('resources/' . $f->getUrlEncodedValue());
}
// 3) Test mapping of local resources, this time leave files in place.
......@@ -126,7 +128,7 @@ class FeedsMapperFileTestCase extends FeedsMapperTestCase {
'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/testing/feeds/files.csv',
);
$this->drupalPost('import/node', $edit, 'Import');
$this->assertText('Created 4 nodes');
$this->assertText('Created 5 nodes');
// Assert: files should be in images/ now.
$files = $this->testFiles();
......@@ -136,7 +138,8 @@ class FeedsMapperFileTestCase extends FeedsMapperTestCase {
->execute();
foreach ($entities as $entity) {
$this->drupalGet('node/' . $entity->entity_id . '/edit');
$this->assertRaw('images/' . array_shift($files));
$f = new FeedsEnclosure(array_shift($files), NULL);
$this->assertRaw('images/' . $f->getUrlEncodedValue());
}
// Deleting all imported items will delete the files from the images/ dir.
......@@ -151,7 +154,7 @@ class FeedsMapperFileTestCase extends FeedsMapperTestCase {
* Lists test files.
*/
public function testFiles() {
return array('tubing.jpeg', 'foosball.jpeg', 'attersee.jpeg', 'hstreet.jpeg');
return array('tubing.jpeg', 'foosball.jpeg', 'attersee.jpeg', 'hstreet.jpeg', 'la fayette.jpeg');
}
/**
......
......@@ -44,6 +44,7 @@ function feeds_tests_flickr() {
1 => "foosball.jpeg",
2 => "attersee.jpeg",
3 => "hstreet.jpeg",
4 => "la fayette.jpeg",
);
$path = drupal_get_path('module', 'feeds_tests') . '/feeds/assets';
foreach ($images as &$image) {
......@@ -62,6 +63,7 @@ function feeds_tests_files() {
1 => "foosball.jpeg",
2 => "attersee.jpeg",
3 => "hstreet.jpeg",
4 => "la fayette.jpeg",
);
foreach ($images as &$image) {
$image = "public://images/$image";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment