public function FeedsEnclosure::getFile in Feeds 6
Same name and namespace in other branches
- 7.2 plugins/FeedsParser.inc \FeedsEnclosure::getFile()
- 7 plugins/FeedsParser.inc \FeedsEnclosure::getFile()
@todo Get file extension from mime_type. @todo This is not concurrency safe.
Return value
A path pointing to a file containing the resource referenced by the enclosure. This method downloads the resource if it is not local. The file path must be considered temporary and is only valid for the current page load.
File
- plugins/
FeedsParser.inc, line 268
Class
- FeedsEnclosure
- Enclosure element, can be part of the result array.
Code
public function getFile() {
if (empty($this->file) && $this
->getValue()) {
// Check if this enclosure contains a local file.
if (!parse_url($this
->getValue(), PHP_URL_SCHEME)) {
if (file_check_location($this
->getValue(), file_directory_path()) || file_check_location($this
->getValue(), file_directory_temp())) {
if (file_exists($this
->getValue())) {
$this->file = $this
->getValue();
return $this->file;
}
}
throw new Exception(t('Invalid enclosure %enclosure', array(
'%enclosure' => $this
->getValue(),
)));
}
$filename = basename($this
->getValue());
if (module_exists('transliteration')) {
require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';
$filename = transliteration_clean_filename($filename);
}
$dest = file_destination(file_directory_temp() . '/' . $filename, FILE_EXISTS_RENAME);
if (ini_get('allow_url_fopen')) {
$this->file = copy($this
->getValue(), $dest) ? $dest : 0;
}
else {
$this->file = file_save_data($this
->getContent(), $dest);
}
if ($this->file === 0) {
throw new Exception(t('Cannot write content to %dest', array(
'%dest' => $dest,
)));
}
$this->delete_file = TRUE;
}
return $this->file;
}