Esempio n. 1
0
 function insertRegularFile($object, $objectVersion, $objectLanguage, $objectAttribute, $filePath, &$result)
 {
     $result = array('errors' => array(), 'require_storage' => false);
     $attributeID = $objectAttribute->attribute('id');
     $media = eZMedia::fetch($attributeID, $objectVersion);
     if ($media === null) {
         $media = eZMedia::create($attributeID, $objectVersion);
     }
     $fileName = basename($filePath);
     $mimeData = eZMimeType::findByFileContents($filePath);
     $storageDir = eZSys::storageDirectory();
     list($group, $type) = explode('/', $mimeData['name']);
     $destination = $storageDir . '/original/' . $group;
     if (!file_exists($destination)) {
         if (!eZDir::mkdir($destination, false, true)) {
             return false;
         }
     }
     // create dest filename in the same manner as eZHTTPFile::store()
     // grab file's suffix
     $fileSuffix = eZFile::suffix($fileName);
     // prepend dot
     if ($fileSuffix) {
         $fileSuffix = '.' . $fileSuffix;
     }
     // grab filename without suffix
     $fileBaseName = basename($fileName, $fileSuffix);
     // create dest filename
     $destFileName = md5($fileBaseName . microtime() . mt_rand()) . $fileSuffix;
     $destination = $destination . '/' . $destFileName;
     copy($filePath, $destination);
     $fileHandler = eZClusterFileHandler::instance();
     $fileHandler->fileStore($destination, 'mediafile', true, $mimeData['name']);
     $classAttribute = $objectAttribute->contentClassAttribute();
     $player = $classAttribute->attribute("data_text1");
     $pluginPage = eZMediaType::pluginPage($player);
     $media->setAttribute("contentobject_attribute_id", $attributeID);
     $media->setAttribute("version", $objectVersion);
     $media->setAttribute("filename", $destFileName);
     $media->setAttribute("original_filename", $fileName);
     $media->setAttribute("mime_type", $mimeData['name']);
     // Setting width and height to zero means that the browser/player must find the size itself.
     // In the future we will probably analyze the media file and find this information
     $width = $height = 0;
     // Quality is not known, so we don't set any
     $quality = false;
     // Not sure what this is for, set to false
     $controls = false;
     // We want to show controllers by default
     $hasController = true;
     // Don't play automatically
     $isAutoplay = false;
     // Don't loop movie
     $isLoop = false;
     $media->setAttribute("width", $width);
     $media->setAttribute("height", $height);
     $media->setAttribute("quality", $quality);
     $media->setAttribute("controls", $controls);
     $media->setAttribute("pluginspage", $pluginPage);
     $media->setAttribute("is_autoplay", $isAutoplay);
     $media->setAttribute("has_controller", $hasController);
     $media->setAttribute("is_loop", $isLoop);
     $media->store();
     $objectAttribute->setContent($media);
     return true;
 }