You are here

public function FeedsFileFetcher::sourceFormValidate in Feeds 7

Same name and namespace in other branches
  1. 6 plugins/FeedsFileFetcher.inc \FeedsFileFetcher::sourceFormValidate()
  2. 7.2 plugins/FeedsFileFetcher.inc \FeedsFileFetcher::sourceFormValidate()

Override parent::sourceFormValidate().

Overrides FeedsPlugin::sourceFormValidate

File

plugins/FeedsFileFetcher.inc, line 81
Home of the FeedsFileFetcher and related classes.

Class

FeedsFileFetcher
Fetches data via HTTP.

Code

public function sourceFormValidate(&$values) {
  $feed_dir = 'public://feeds';
  file_prepare_directory($feed_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);

  // If there is a file uploaded, save it, otherwise validate input on
  // file.
  // @todo: Track usage of file, remove file when removing source.
  if ($file = file_save_upload('feeds', array(
    'file_validate_extensions' => array(
      0 => $this->config['allowed_extensions'],
    ),
  ), $feed_dir)) {
    $values['source'] = $file->uri;
    $values['file'] = $file;
  }
  elseif (empty($values['source'])) {
    form_set_error('feeds][source', t('Upload a file first.'));
  }
  elseif (strpos($values['source'], 'public://') !== 0) {
    form_set_error('feeds][source', t('File needs to reside within the site\'s file directory, its path needs to start with public://.'));
  }
}