コード例 #1
0
ファイル: Upload.php プロジェクト: lchen01/STEdwards
 /**
  * In addition to the default options available for 
  * Omeka_File_Ingest_AbstractIngest, this understands the following options:
  * - 'ignoreNoFile' => boolean False by default.  Whether or not to ignore 
  * - validation errors that occur when an uploaded file is missing.  This 
  * - may occur when a file input is left empty on a form.  
  * 
  * This option can be overridden by the 'ignore_invalid_files' option.  For 
  * instance, if 'ignoreNoFile' is set to false but 'ignore_invalid_files' is
  * set to true, any exceptions due to missing uploads will be suppressed and
  * ignored.
  * 
  * @param array $options
  * @return void
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (array_key_exists('ignoreNoFile', $options)) {
         $this->_adapterOptions['ignoreNoFile'] = $options['ignoreNoFile'];
     }
 }
コード例 #2
0
ファイル: MimeType.php プロジェクト: kyfr59/cg35
 /**
  * Vaidate the file MIME type.
  * 
  * @param string $file
  * @return bool
  */
 public function isValid($file)
 {
     $this->_file = $file;
     // Detect the definitive MIME type.
     $detect = new Omeka_File_MimeType_Detect($this->_file);
     $this->_mimeType = $detect->detect();
     // Set the relevant MIME type whitelist.
     if ($this->_customWhitelist) {
         $whitelist = $this->_customWhitelist;
     } else {
         $whitelist = self::DEFAULT_WHITELIST;
     }
     // Validate the MIME type against the whitelist.
     if (in_array($this->_mimeType, explode(',', $whitelist))) {
         // Valid MIME type. Set the MIME type to the ingest class so that it
         // can assign it to the File record. Doing this avoids more than one
         // call to the MIME type detection class.
         Omeka_File_Ingest_AbstractIngest::$mimeType = $this->_mimeType;
         return true;
     } else {
         // Invalid MIME type.
         Zend_Debug::dump(explode(',', $whitelist));
         $this->_error(self::INVALID_TYPE);
         return false;
     }
 }
コード例 #3
0
 protected function importFiles($item)
 {
     $ingester = Omeka_File_Ingest_AbstractIngest::factory('Url', $item, array());
     $files = $this->files();
     //have to step through one by one so we can save the id map for each $fileRecord and $fileData
     foreach ($files as $fileData) {
         try {
             $fileRecords = $ingester->ingest(array($fileData));
         } catch (Exception $e) {
             _log($e);
             continue;
         }
         $item->saveFiles();
         $fileRecord = array_pop($fileRecords);
         $map = new OmekaApiImportRecordIdMap();
         $map->record_type = 'File';
         $map->local_id = $fileRecord->id;
         $map->external_id = $fileData['externalId'];
         $map->endpoint_uri = $this->endpointUri;
         $map->save();
     }
 }
コード例 #4
0
ファイル: Item.php プロジェクト: lchen01/STEdwards
 /**
  * Add the default validators for ingested files.  
  * 
  * The default validators are whitelists for file extensions and MIME types,
  * and those lists can be configured via the admin settings form.
  * 
  * These default validators can be disabled by the 'disable_default_file_validation'
  * flag in the settings panel.
  * 
  * Plugins can add/remove/modify validators via the 'file_ingest_validators'
  * filter.
  * 
  * @param Omeka_File_Ingest_AbstractIngest $ingester
  * @return void
  */
 protected function _addIngestValidators(Omeka_File_Ingest_AbstractIngest $ingester)
 {
     $validators = get_option(File::DISABLE_DEFAULT_VALIDATION_OPTION) ? array() : array('extension whitelist' => new Omeka_Validate_File_Extension(), 'MIME type whitelist' => new Omeka_Validate_File_MimeType());
     $validators = apply_filters(self::FILE_INGEST_VALIDATORS_FILTER, $validators);
     // Build the default validators.
     foreach ($validators as $validator) {
         $ingester->addValidator($validator);
     }
 }
コード例 #5
0
ファイル: AbstractIngest.php プロジェクト: lchen01/STEdwards
 /**
  * Insert a File record corresponding to an ingested file and its metadata.
  * 
  * @param string $newFilePath Path to the file within Omeka.
  * @param string $oldFilename The original filename for the file.  This will
  * usually be displayed to the end user.
  * @param array $elementMetadata See ActsAsElementText::addElementTextsByArray()
  * for more information about the format of this array.
  * @uses ActsAsElementText::addElementTextsByArray()
  * @return File
  */
 private function _createFile($newFilePath, $oldFilename, $elementMetadata = array())
 {
     // Normally, the MIME type validator sets the type to this class's
     // static $mimeType property during validation. If that validator has
     // been disabled (from the admin settings menu, for example), set the
     // MIME type here.
     if (self::$mimeType) {
         $mimeType = self::$mimeType;
         // Make sure types don't leak between files.
         self::$mimeType = null;
     } else {
         $detect = new Omeka_File_MimeType_Detect($newFilePath);
         $mimeType = $detect->detect();
     }
     $file = new File();
     try {
         $file->original_filename = $oldFilename;
         $file->mime_type = $mimeType;
         $file->setDefaults($newFilePath);
         if ($elementMetadata) {
             $file->addElementTextsByArray($elementMetadata);
         }
         fire_plugin_hook('after_ingest_file', array('file' => $file, 'item' => $this->_item));
         $this->_item->addFile($file);
     } catch (Exception $e) {
         if (!$file->exists()) {
             $file->unlinkFile();
         }
         throw $e;
     }
     return $file;
 }