/**
  * Handles data retrival on the content tree level.
  *
  * The format of the returned array is the same as $result:
  * <code>
  * array( 'isFile' => bool,
  *        'isCollection' => bool,
  *        'file' => path to the storage file which contain the contents );
  * </code>
  *
  * @param array(string=>mixed) $result
  * @param string $currentSite Eg. 'plain_site_user'
  * @param string $virtualFolder Eg. 'Content'
  * @param string $target Eg. 'Folder1/file1.txt'
  * @param string $fullPath Eg. '/plain_site_user/Content/Folder1/file1.txt'
  * @return array(string=>mixed) Or false if an error appeared
  * @todo remove/replace eZContentUpload
  */
 protected function getContentNodeData($result, $currentSite, $virtualFolder, $target, $fullPath)
 {
     // Attempt to fetch the node the client wants to get.
     $nodePath = $this->internalNodePath($virtualFolder, $target);
     eZWebDAVContentBackend::appendLogEntry(__FUNCTION__ . " Path:" . $nodePath);
     $node = $this->fetchNodeByTranslation($nodePath);
     $info = $this->fetchNodeInfo($fullPath, $node);
     // Proceed only if the node is valid:
     if ($node === null) {
         return $result;
     }
     // Can we fetch the contents of the node
     if (!$node->canRead()) {
         return false;
         // @as self::FAILED_FORBIDDEN;
     }
     $object = $node->attribute('object');
     foreach ($info as $key => $value) {
         $result[$key] = $value;
     }
     $upload = new eZContentUpload();
     $info = $upload->objectFileInfo($object);
     if ($info) {
         $result['file'] = $info['filepath'];
     } else {
         $class = $object->contentClass();
         if ($this->isObjectFolder($object, $class)) {
             $result['isCollection'] = true;
         }
     }
     return $result;
 }
Пример #2
0
    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;
    }