You are here

protected function FeedsEnclosure::getSafeFilename in Feeds 7.2

Returns the safe file name.

Return value

string A filename that is safe to save to the filesystem.

Throws

RuntimeException Thrown if the file extension is invalid.

3 calls to FeedsEnclosure::getSafeFilename()
FeedsEnclosure::getFile in plugins/FeedsParser.inc
Get a Drupal file object of the enclosed resource, download if necessary.
FeedsEnclosure::getLocalValue in plugins/FeedsParser.inc
Returns the file name transformed for better local saving.
FeedsEnclosure::getSanitizedUri in plugins/FeedsParser.inc
Returns the full path to the file URI with a safe file name.

File

plugins/FeedsParser.inc, line 406
Contains FeedsParser and related classes.

Class

FeedsEnclosure
Enclosure element, can be part of the result array.

Code

protected function getSafeFilename() {
  if (isset($this->safeFilename)) {
    return $this->safeFilename;
  }

  // Strip any query string or fragment from file name.
  list($filename) = explode('?', $this
    ->getValue());
  list($filename) = explode('#', $filename);
  $filename = rawurldecode(drupal_basename($filename));

  // Remove leading and trailing whitespace and periods.
  $filename = trim($filename, " \t\n\r\0\v.");
  if (strpos($filename, '.') === FALSE) {
    $extension = FALSE;
  }
  else {
    $extension = drupal_strtolower(substr($filename, strrpos($filename, '.') + 1));
  }
  if (!$extension || !in_array($extension, explode(' ', $this->allowedExtensions), TRUE)) {
    throw new RuntimeException(t('The file @file has an invalid extension.', array(
      '@file' => $filename,
    )));
  }
  $this->safeFilename = file_munge_filename($filename, $this->allowedExtensions, FALSE);
  return $this->safeFilename;
}