Beispiel #1
0
 /**
  * Initializes the content object attribute with the uploaded HTTP file
  *
  * @param eZHTTPFile $httpFile
  * @param string $imageAltText Optional image ALT text
  *
  * @return TODO: FIXME
  */
 function initializeFromHTTPFile($httpFile, $imageAltText = false)
 {
     $this->increaseImageSerialNumber();
     $mimeData = eZMimeType::findByFileContents($httpFile->attribute('filename'));
     if (!$mimeData['is_valid']) {
         $mimeData = eZMimeType::findByName($httpFile->attribute('mime_type'));
         if (!$mimeData['is_valid']) {
             $mimeData = eZMimeType::findByURL($httpFile->attribute('original_filename'));
         }
     }
     $attr = false;
     $this->removeAliases($attr);
     $this->setOriginalAttributeDataValues($this->ContentObjectAttributeData['id'], $this->ContentObjectAttributeData['version'], $this->ContentObjectAttributeData['language_code']);
     $contentVersion = eZContentObjectVersion::fetchVersion($this->ContentObjectAttributeData['version'], $this->ContentObjectAttributeData['contentobject_id']);
     $objectName = $this->imageName($this->ContentObjectAttributeData, $contentVersion);
     $objectPathString = $this->imagePath($this->ContentObjectAttributeData, $contentVersion, true);
     eZMimeType::changeBaseName($mimeData, $objectName);
     eZMimeType::changeDirectoryPath($mimeData, $objectPathString);
     $httpFile->store(false, false, $mimeData);
     $originalFilename = $httpFile->attribute('original_filename');
     return $this->initialize($mimeData, $originalFilename, $imageAltText);
 }
 /**
  * Tries to validate uploaded file format through handler
  *
  * @param string $handler
  * @param string $option
  * @param eZHTTPFile $file
  * @return boolean	true if file validates or if no validator is defined
  */
 protected static function checkFileFormat($handler, $option, eZHTTPFile $file)
 {
     //Handler instantiation code copied from SQLIImportFactory::runImport
     //TODO : refactoring handler instantiation ?
     $importINI = eZINI::instance('sqliimport.ini');
     $handlerSection = $handler . '-HandlerSettings';
     if (!$importINI->hasSection($handlerSection)) {
         // Check INI Section
         throw new ezcConfigurationNoConfigException('Error : Handler "' . $handler . '" does not have proper config section in sqliimport.ini !');
     }
     if (!$importINI->hasVariable($handlerSection, 'ClassName')) {
         // Check if ClassName is properly defined
         throw new ezcConfigurationNoConfigException('Error : ClassName not defined for "' . $handler . '" in sqliimport.ini !');
     }
     // Default values
     $handlerClassName = $importINI->variable($handlerSection, 'ClassName');
     $handlerEnabled = true;
     $debug = false;
     $defaultParentNodeID = $importINI->variable('ImportSettings', 'DefaultParentNodeID');
     $streamTimeout = $importINI->variable('ImportSettings', 'StreamTimeout');
     if ($importINI->hasVariable($handlerSection, 'Enabled')) {
         $handlerEnabled = $importINI->variable($handlerSection, 'Enabled') === 'true';
     }
     if ($importINI->hasVariable($handlerSection, 'Debug')) {
         $debug = $importINI->variable($handlerSection, 'Debug') === 'enabled';
     }
     if ($importINI->hasVariable($handlerSection, 'DefaultParentNodeID')) {
         $localParentNodeID = $importINI->variable($handlerSection, 'DefaultParentNodeID');
         $defaultParentNodeID = is_int($localParentNodeID) ? (int) $localParentNode : $defaultParentNodeID;
     }
     // Check handler class validity
     if (!class_exists($handlerClassName)) {
         throw new SQLIImportRuntimeException('Error : invalid handler class "' . $handlerClassName . '". Did you regenerate autolads ?');
     }
     $handlerOptions = new SQLIImportHandlerOptions(array());
     $importHandler = new $handlerClassName($handlerOptions);
     if (!$importHandler instanceof ISQLIFileImportHandler) {
         return true;
     }
     $importHandler->handlerConfArray = $importINI->group($handlerSection);
     return $importHandler->validateFile($option, $file->attribute('filename'));
 }