Esempio n. 1
0
 function trashStoredObjectAttribute($contentObjectAttribute, $version = null)
 {
     $contentObjectAttributeID = $contentObjectAttribute->attribute("id");
     $imageHandler = $contentObjectAttribute->attribute('content');
     $imageFiles = eZImageFile::fetchForContentObjectAttribute($contentObjectAttributeID);
     foreach ($imageFiles as $imageFile) {
         if ($imageFile == null) {
             continue;
         }
         $existingFilepath = $imageFile;
         // Check if there are any other records in ezimagefile that point to that filename.
         $imageObjectsWithSameFileName = eZImageFile::fetchByFilepath(false, $existingFilepath);
         $file = eZClusterFileHandler::instance($existingFilepath);
         if ($file->exists() and count($imageObjectsWithSameFileName) <= 1) {
             $orig_dir = dirname($existingFilepath) . '/trashed';
             $fileName = basename($existingFilepath);
             // 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
             $newFileBaseName = md5($fileBaseName . microtime() . mt_rand());
             $newFileName = $newFileBaseName . $fileSuffix;
             $newFilepath = $orig_dir . '/' . $newFileName;
             // rename the file, and update the database data
             $imageHandler->updateAliasPath($orig_dir, $newFileBaseName);
             if ($imageHandler->isStorageRequired()) {
                 $imageHandler->store($contentObjectAttribute);
                 $contentObjectAttribute->store();
             }
         }
     }
 }
Esempio n. 2
0
 function appendSimpleFile($key, $filepath)
 {
     if (!isset($this->Parameters['simple-file-list'])) {
         $this->Parameters['simple-file-list'] = array();
     }
     $suffix = eZFile::suffix($filepath);
     //$sourcePath = $fileInfo['original-path'];
     $packagePath = eZPackage::simpleFilesDirectory() . '/' . substr(md5(mt_rand()), 0, 8) . '.' . $suffix;
     $destinationPath = $this->path() . '/' . $packagePath;
     eZDir::mkdir(eZDir::dirpath($destinationPath), false, true);
     //SP DBfile
     $fileHandler = eZClusterFileHandler::instance();
     $fileHandler->fileFetch($filepath);
     eZFileHandler::copy($filepath, $destinationPath);
     $this->Parameters['simple-file-list'][$key] = array('original-path' => $filepath, 'package-path' => $packagePath);
 }
 /**
  * Gathers information about a given node specified as parameter.
  *
  * The format of the returned array is:
  * <code>
  * array( 'name' => node name (eg. 'Group picture'),
  *        'size' => storage size of the_node in bytes (eg. 57123),
  *        'mimetype' => mime type of the node (eg. 'image/jpeg'),
  *        'ctime' => creation time as timestamp,
  *        'mtime' => latest modification time as timestamp,
  *        'href' => the path to the node (eg. '/plain_site_user/Content/Folder1/file1.jpg')
  * </code>
  *
  * @param string $target Eg. '/plain_site_user/Content/Folder1/file1.jpg
  * @param eZContentObject &$node The node corresponding to $target
  * @return array(string=>mixed)
  * @todo remove/replace .ini calls, eZContentUpload, eZMimeType, eZSys RequestURI
  * @todo handle articles as files
  */
 protected function fetchNodeInfo($target, &$node)
 {
     // When finished, we'll return an array of attributes/properties.
     $entry = array();
     $classIdentifier = $node->attribute('class_identifier');
     $object = $node->attribute('object');
     $urlAlias = $node->urlAlias();
     // By default, everything is displayed as a folder:
     // Trim the name of the node, it is in some cases whitespace in eZ Publish
     $name = trim($node->attribute('name'));
     // @as 2009-03-09: return node_id as displayname in case name is missing
     // displayname is not actually used by WebDAV clients
     $entry["name"] = $name !== '' && $name !== NULL ? $name : $node->attribute('node_id');
     $entry["size"] = 0;
     $entry["mimetype"] = self::DIRECTORY_MIMETYPE;
     eZWebDAVContentBackend::appendLogEntry('FetchNodeInfo:' . $node->attribute('name') . '/' . $urlAlias);
     // @todo handle articles as files
     // if ( $classIdentifier === 'article' )
     // {
     //     $entry["mimetype"] = 'application/ms-word';
     // }
     $entry["ctime"] = $object->attribute('published');
     $entry["mtime"] = $object->attribute('modified');
     $upload = new eZContentUpload();
     $info = $upload->objectFileInfo($object);
     $suffix = '';
     $class = $object->contentClass();
     $isObjectFolder = $this->isObjectFolder($object, $class);
     if ($isObjectFolder) {
         // We do nothing, the default is to see it as a folder
     } else {
         if ($info) {
             $filePath = $info['filepath'];
             $entry['filepath'] = $filePath;
             $entry["mimetype"] = false;
             $entry["size"] = false;
             if (isset($info['filesize'])) {
                 $entry['size'] = $info['filesize'];
             }
             if (isset($info['mime_type'])) {
                 $entry['mimetype'] = $info['mime_type'];
             }
             // Fill in information from the actual file if they are missing.
             $file = eZClusterFileHandler::instance($filePath);
             if (!$entry['size'] and $file->exists()) {
                 $entry["size"] = $file->size();
             }
             if (!$entry['mimetype']) {
                 $mimeInfo = eZMimeType::findByURL($filePath);
                 $entry["mimetype"] = $mimeInfo['name'];
                 $suffix = $mimeInfo['suffix'];
                 if (strlen($suffix) > 0) {
                     $entry["name"] .= '.' . $suffix;
                 }
             } else {
                 // eZMimeType returns first suffix in its list
                 // this could be another one than the original file extension
                 // so let's try to get the suffix from the file path first
                 $suffix = eZFile::suffix($filePath);
                 if (!$suffix) {
                     $mimeInfo = eZMimeType::findByName($entry['mimetype']);
                     $suffix = $mimeInfo['suffix'];
                 }
                 if (strlen($suffix) > 0) {
                     $entry["name"] .= '.' . $suffix;
                 }
             }
             if ($file->exists()) {
                 $entry["ctime"] = $file->mtime();
                 $entry["mtime"] = $file->mtime();
             }
         } else {
             // Here we only show items as folders if they have
             // is_container set to true, otherwise it's an unknown binary file
             if (!$class->attribute('is_container')) {
                 $entry['mimetype'] = 'application/octet-stream';
             }
         }
     }
     $scriptURL = $target;
     if (strlen($scriptURL) > 0 and $scriptURL[strlen($scriptURL) - 1] !== "/") {
         $scriptURL .= "/";
     }
     $trimmedScriptURL = trim($scriptURL, '/');
     $scriptURLParts = explode('/', $trimmedScriptURL);
     $urlPartCount = count($scriptURLParts);
     if ($urlPartCount >= 2) {
         // one of the virtual folders
         // or inside one of the virtual folders
         $siteAccess = $scriptURLParts[0];
         $virtualFolder = $scriptURLParts[1];
         // only when the virtual folder is Content we need to add its path to the start URL
         // the paths of other top level folders (like Media) are included in URL aliases of their descending nodes
         if ($virtualFolder === self::virtualContentFolderName()) {
             $startURL = '/' . $siteAccess . '/' . $virtualFolder . '/';
         } else {
             if ($virtualFolder === self::virtualMediaFolderName()) {
                 $startURL = '/' . $siteAccess . '/' . $virtualFolder . '/';
                 $urlAlias = substr($urlAlias, strpos($urlAlias, '/') + 1);
             } else {
                 $startURL = '/' . $siteAccess . '/';
             }
         }
     } else {
         // site access level
         $startURL = $scriptURL;
     }
     // Set the href attribute (note that it doesn't just equal the name).
     if (!isset($entry['href'])) {
         if (strlen($suffix) > 0) {
             $suffix = '.' . $suffix;
         }
         $entry["href"] = $startURL . $urlAlias . $suffix;
     }
     // Return array of attributes/properties (name, size, mime, times, etc.).
     return $entry;
 }
    function fetchNodeInfo( &$node )
    {
        // When finished, we'll return an array of attributes/properties.
        $entry = array();

        // Grab settings from the ini file:
        $webdavINI = eZINI::instance( eZWebDAVContentServer::WEBDAV_INI_FILE );
        $iniSettings = $webdavINI->variable( 'DisplaySettings', 'FileAttribute' );

        $classIdentifier = $node->attribute( 'class_identifier' );

        $object = $node->attribute( 'object' );

        // By default, everything is displayed as a folder:
        // Trim the name of the node, it is in some cases whitespace in eZ Publish
        $entry["name"] = trim( $node->attribute( 'name' ) );
        $entry["size"] = 0;
        $entry["mimetype"] = 'httpd/unix-directory';
        $entry["ctime"] = $object->attribute( 'published' );
        $entry["mtime"] = $object->attribute( 'modified' );

        $upload = new eZContentUpload();
        $info = $upload->objectFileInfo( $object );
        $suffix = '';
        $class = $object->contentClass();
        $isObjectFolder = $this->isObjectFolder( $object, $class );

        if ( $isObjectFolder )
        {
            // We do nothing, the default is to see it as a folder
        }
        else if ( $info )
        {
            $filePath = $info['filepath'];
            $entry["mimetype"] = false;
            $entry["size"] = false;
            if ( isset( $info['filesize'] ) )
                $entry['size'] = $info['filesize'];
            if ( isset( $info['mime_type'] ) )
                $entry['mimetype'] = $info['mime_type'];

            // Fill in information from the actual file if they are missing.
            $file = eZClusterFileHandler::instance( $filePath );
            if ( !$entry['size'] and $file->exists() )
            {
                $entry["size"] = $file->size();
            }
            if ( !$entry['mimetype']  )
            {
                $mimeInfo = eZMimeType::findByURL( $filePath );
                $entry["mimetype"] = $mimeInfo['name'];
                $suffix = $mimeInfo['suffix'];
                if ( strlen( $suffix ) > 0 )
                    $entry["name"] .= '.' . $suffix;
            }
            else
            {
                // eZMimeType returns first suffix in its list
                // this could be another one than the original file extension
                // so let's try to get the suffix from the file path first
                $suffix = eZFile::suffix( $filePath );
                if ( !$suffix )
                {
                    $mimeInfo = eZMimeType::findByName( $entry['mimetype'] );
                    $suffix = $mimeInfo['suffix'];
                }
                if ( strlen( $suffix ) > 0 )
                    $entry["name"] .= '.' . $suffix;
            }

            if ( $file->exists() )
            {
                $entry["ctime"] = $file->mtime();
                $entry["mtime"] = $file->mtime();
            }
        }
        else
        {
            // Here we only show items as folders if they have
            // is_container set to true, otherwise it's an unknown binary file
            if ( !$class->attribute( 'is_container' ) )
            {
                $entry['mimetype'] = 'application/octet-stream';
            }
        }

        $scriptURL = eZSys::instance()->RequestURI;
        if ( strlen( $scriptURL ) > 0 and $scriptURL[ strlen( $scriptURL ) - 1 ] != "/" )
            $scriptURL .= "/";

        $trimmedScriptURL = trim( $scriptURL, '/' );
        $scriptURLParts = explode( '/', $trimmedScriptURL );

        $siteAccess = $scriptURLParts[0];
        $virtualFolder = $scriptURLParts[1];

        $startURL = '/' . $siteAccess . '/' . $virtualFolder . '/';

        // Set the href attribute (note that it doesn't just equal the name).
        if ( !isset( $entry['href'] ) )
        {
            if ( strlen( $suffix ) > 0 )
                $suffix = '.' . $suffix;

            $alias = $node->urlAlias();
            if ( $virtualFolder == eZWebDAVContentServer::virtualMediaFolderName() )
            {
                // remove the real media node url alias, the virtual media folder is already in $startURL
                $aliasParts = explode( '/', $alias );
                array_shift( $aliasParts );
                $alias = implode( '/', $aliasParts );
            }
            $entry["href"] = $startURL . $alias . $suffix;
        }
        // Return array of attributes/properties (name, size, mime, times, etc.).
        return $entry;
    }
$script->startup();
$options = $script->getOptions('', '', array());
$script->initialize();
$limit = 20;
$offset = 0;
$db = eZDB::instance();
$script->setIterationData('.', '~');
while ($binaryFiles = eZPersistentObject::fetchObjectList(eZBinaryFile::definition(), null, null, null, array('offset' => $offset, 'limit' => $limit))) {
    foreach ($binaryFiles as $binaryFile) {
        $fileName = $binaryFile->attribute('filename');
        if (strpos($fileName, '.') !== false) {
            $text = "skipping {$fileName}, it contains a suffix";
            $script->iterate($cli, true, $text);
            continue;
        }
        $suffix = eZFile::suffix($binaryFile->attribute('original_filename'));
        if ($suffix) {
            $newFileName = $fileName . '.' . $suffix;
            $db->begin();
            $oldFilePath = $binaryFile->attribute('filepath');
            $binaryFile->setAttribute('filename', $newFileName);
            $binaryFile->store();
            $newFilePath = $binaryFile->attribute('filepath');
            $file = eZClusterFileHandler::instance($oldFilePath);
            if ($file->exists()) {
                $text = "renamed {$fileName} to {$newFileName}";
                $file->move($newFilePath);
            } else {
                $text = "file not found: {$oldFilePath}";
                $script->iterate($cli, false, $text);
                $db->rollback();
 /**
  * Fetches the list of available translations, as an eZTSTranslator for each translation.
  *
  * @param array $localList
  *
  * @return array( eZTSTranslator ) list of eZTranslator objects representing available translations
  */
 static function fetchList($localeList = array())
 {
     $ini = eZINI::instance();
     $dir = $ini->variable('RegionalSettings', 'TranslationRepository');
     $fileInfoList = array();
     $translationList = array();
     $locale = '';
     if (count($localeList) == 0) {
         $localeList = eZDir::findSubdirs($dir);
     }
     foreach ($localeList as $locale) {
         if ($locale != 'untranslated') {
             $translationFiles = eZDir::findSubitems($dir . '/' . $locale, 'f');
             foreach ($translationFiles as $translationFile) {
                 if (eZFile::suffix($translationFile) == 'ts') {
                     $translationList[] = new eZTSTranslator($locale, $translationFile);
                 }
             }
         }
     }
     return $translationList;
 }
    function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
    {
        $fileNode = $attributeNode->getElementsByTagName( 'binary-file' )->item( 0 );
        if ( !is_object( $fileNode ) or !$fileNode->hasAttributes() )
        {
            return;
        }

        $binaryFile = eZBinaryFile::create( $objectAttribute->attribute( 'id' ), $objectAttribute->attribute( 'version' ) );

        $sourcePath = $package->simpleFilePath( $fileNode->getAttribute( 'filekey' ) );

        if ( !file_exists( $sourcePath ) )
        {
            eZDebug::writeError( "The file '$sourcePath' does not exist, cannot initialize file attribute with it", __METHOD__ );
            return false;
        }

        $ini = eZINI::instance();
        $mimeType = $fileNode->getAttribute( 'mime-type' );
        list( $mimeTypeCategory, $mimeTypeName ) = explode( '/', $mimeType );
        $destinationPath = eZSys::storageDirectory() . '/original/' . $mimeTypeCategory . '/';
        if ( !file_exists( $destinationPath ) )
        {
            $oldumask = umask( 0 );
            if ( !eZDir::mkdir( $destinationPath, false, true ) )
            {
                umask( $oldumask );
                return false;
            }
            umask( $oldumask );
        }

        $basename = basename( $fileNode->getAttribute( 'filename' ) );
        while ( file_exists( $destinationPath . $basename ) )
        {
            $basename = substr( md5( mt_rand() ), 0, 8 ) . '.' . eZFile::suffix( $fileNode->getAttribute( 'filename' ) );
        }

        eZFileHandler::copy( $sourcePath, $destinationPath . $basename );
        eZDebug::writeNotice( 'Copied: ' . $sourcePath . ' to: ' . $destinationPath . $basename, __METHOD__ );

        $binaryFile->setAttribute( 'contentobject_attribute_id', $objectAttribute->attribute( 'id' ) );
        $binaryFile->setAttribute( 'filename', $basename );
        $binaryFile->setAttribute( 'original_filename', $fileNode->getAttribute( 'original-filename' ) );
        $binaryFile->setAttribute( 'mime_type', $fileNode->getAttribute( 'mime-type' ) );

        $binaryFile->store();

        $fileHandler = eZClusterFileHandler::instance();
        $fileHandler->fileStore( $destinationPath . $basename, 'binaryfile', true );
    }
Esempio n. 8
0
 function unserializeContentObjectAttribute($package, $objectAttribute, $attributeNode)
 {
     $mediaNode = $attributeNode->getElementsByTagName('media-file')->item(0);
     if (!$mediaNode) {
         // No media type data found.
         return;
     }
     $mediaFile = eZMedia::create($objectAttribute->attribute('id'), $objectAttribute->attribute('version'));
     $sourcePath = $package->simpleFilePath($mediaNode->getAttribute('filekey'));
     $ini = eZINI::instance();
     $mimeType = $mediaNode->getAttribute('mime-type');
     list($mimeTypeCategory, $mimeTypeName) = explode('/', $mimeType);
     $destinationPath = eZSys::storageDirectory() . '/original/' . $mimeTypeCategory . '/';
     if (!file_exists($destinationPath)) {
         if (!eZDir::mkdir($destinationPath, false, true)) {
             return false;
         }
     }
     $basename = basename($mediaNode->getAttribute('filename'));
     while (file_exists($destinationPath . $basename)) {
         $basename = substr(md5(mt_rand()), 0, 8) . '.' . eZFile::suffix($mediaNode->getAttribute('filename'));
     }
     eZFileHandler::copy($sourcePath, $destinationPath . $basename);
     eZDebug::writeNotice('Copied: ' . $sourcePath . ' to: ' . $destinationPath . $basename, __METHOD__);
     $mediaFile->setAttribute('contentobject_attribute_id', $objectAttribute->attribute('id'));
     $mediaFile->setAttribute('filename', $basename);
     $mediaFile->setAttribute('original_filename', $mediaNode->getAttribute('original-filename'));
     $mediaFile->setAttribute('mime_type', $mediaNode->getAttribute('mime-type'));
     $mediaFile->setAttribute('width', $mediaNode->getAttribute('width'));
     $mediaFile->setAttribute('height', $mediaNode->getAttribute('height'));
     $mediaFile->setAttribute('has_controller', $mediaNode->getAttribute('has-controller'));
     $mediaFile->setAttribute('controls', $mediaNode->getAttribute('controls'));
     $mediaFile->setAttribute('is_autoplay', $mediaNode->getAttribute('is-autoplay'));
     $mediaFile->setAttribute('pluginspage', $mediaNode->getAttribute('plugins-page'));
     $mediaFile->setAttribute('quality', $mediaNode->getAttribute('quality'));
     $mediaFile->setAttribute('is_loop', $mediaNode->getAttribute('is-loop'));
     $fileHandler = eZClusterFileHandler::instance();
     $fileHandler->fileStore($destinationPath . $basename, 'mediafile', true);
     $mediaFile->store();
 }