Subversion Repositories enhancedezbinaryfile

[/] [datatypes/] [enhancedezbinaryfile/] [enhancedezbinaryfiletype.php] - Diff between revs 4 and 5

Show entire file | Ignore whitespace | Details | Blame | View Log

Rev 4 Rev 5
Line 1... Line 1...
<?php
<?php
//
//
// Definition of EnhancedeZBinaryFileType class
// Definition of EnhancedeZBinaryFileType class
//
//
// SOFTWARE NAME: eZ Publish
// SOFTWARE NAME: eZ Publish
// SOFTWARE RELEASE: 4.4.0
// SOFTWARE RELEASE: 4.5.0
// BUILD VERSION: 21995
// BUILD VERSION: 21995
// COPYRIGHT NOTICE: Copyright (C) 1999-2010 Contactivity.com
// COPYRIGHT NOTICE: Copyright (C) 1999-2010 Contactivity.com
// SOFTWARE LICENSE: GNU General Public License v2.0
// SOFTWARE LICENSE: GNU General Public License v2.0
// NOTICE: >
// NOTICE: >
//   This program is free software; you can redistribute it and/or
//   This program is free software; you can redistribute it and/or
Line 41... Line 41...
     Construction of the class, note that the second parameter in eZDataType
     Construction of the class, note that the second parameter in eZDataType
     is the actual name showed in the datatype dropdown list.
     is the actual name showed in the datatype dropdown list.
    */
    */
    function __construct()
    function __construct()
    {
    {
        parent::__construct( self::DATA_TYPE_STRING, ezi18n( 'extension/enhancedezbinaryfile/datatype', 'Enhanced File', 'Datatype name' ), array( 'serialize_supported' => true, 'object_serialize_map' => array( 'data_text' => 'filename' )));
        parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'extension/enhancedezbinaryfile/datatype', 'Enhanced File', 'Datatype name' ), array( 'serialize_supported' => true, 'object_serialize_map' => array( 'data_text' => 'filename' )));
    }
    }
 
 
    function EnhancedeZBinaryFileType()
    function EnhancedeZBinaryFileType()
    {
    {
        $this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'kernel/classes/datatypes', "Enhanced File", 'Datatype name' ),
        $this->eZDataType( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', "Enhanced File", 'Datatype name' ),
                           array( 'serialize_supported' => true,'object_serialize_map' => array( 'data_text' => 'filename' )
                           array( 'serialize_supported' => true,'object_serialize_map' => array( 'data_text' => 'filename' )
                            ));
                            ));
    }
    }
 
 
    /*!
    /*!
Line 201... Line 201...
            if ( !isset( $isFileWarningAdded ) or
            if ( !isset( $isFileWarningAdded ) or
                 !$isFileWarningAdded )
                 !$isFileWarningAdded )
            {
            {
                eZAppendWarningItem( array( 'error' => array( 'type' => 'kernel',
                eZAppendWarningItem( array( 'error' => array( 'type' => 'kernel',
                                                              'number' => eZError::KERNEL_NOT_AVAILABLE ),
                                                              'number' => eZError::KERNEL_NOT_AVAILABLE ),
                                            'text' => ezi18n( 'kernel/classes/datatypes',
                                            'text' => ezpI18n::tr( 'kernel/classes/datatypes',
                                                              'File uploading is not enabled. Please contact the site administrator to enable it.' ) ) );
                                                              'File uploading is not enabled. Please contact the site administrator to enable it.' ) ) );
                $GLOBALS['eZBinaryFileTypeWarningAdded'] = true;
                $GLOBALS['eZBinaryFileTypeWarningAdded'] = true;
            }
            }
        }
        }
    }
    }
Line 395... Line 395...
 
 
        // $binaryFile->attribute( 'mime_type_part' ) not always the extension
        // $binaryFile->attribute( 'mime_type_part' ) not always the extension
        $extension = preg_replace('/.*\.(.+?)$/', '\\1', $binaryFile->attribute( "original_filename" ) );
        $extension = preg_replace('/.*\.(.+?)$/', '\\1', $binaryFile->attribute( "original_filename" ) );
        if (!in_array(strtolower($extension),$allowed))
        if (!in_array(strtolower($extension),$allowed))
        {
        {
                $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes','Failed to store file. Only the following file types are allowed: %1.' ), implode(", ",$allowed) );
                $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes','Failed to store file. Only the following file types are allowed: %1.' ), implode(", ",$allowed) );
                return eZInputValidator::STATE_INVALID;
                return eZInputValidator::STATE_INVALID;
        }
        }
 
 
        //$contentObjectAttribute->setContent( $binaryFile );
        //$contentObjectAttribute->setContent( $binaryFile );
 
 
Line 491... Line 491...
        //This is only checking if it is required or not
        //This is only checking if it is required or not
        if ( !$binaryFile )
        if ( !$binaryFile )
        {
        {
                if ( $contentObjectAttribute->validateIsRequired() )
                if ( $contentObjectAttribute->validateIsRequired() )
                {
                {
                        $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes','Input required.' ) );
                        $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes','Input required.' ) );
                        return eZInputValidator::STATE_INVALID;
                        return eZInputValidator::STATE_INVALID;
                }
                }
                else
                else
                        return eZInputValidator::STATE_ACCEPTED;
                        return eZInputValidator::STATE_ACCEPTED;
        }
        }
Line 520... Line 520...
 
 
        // $binaryFile->attribute( 'mime_type_part' ) not always the extension
        // $binaryFile->attribute( 'mime_type_part' ) not always the extension
        $extension = preg_replace('/.*\.(.+?)$/', '\\1', $binaryFile->attribute( "original_filename" ) );
        $extension = preg_replace('/.*\.(.+?)$/', '\\1', $binaryFile->attribute( "original_filename" ) );
        if (!in_array(strtolower($extension),$allowed))
        if (!in_array(strtolower($extension),$allowed))
        {
        {
                $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes','Failed to store file. Only the following file types are allowed: %1.' ), implode(", ",$allowed) );
                $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes','Failed to store file. Only the following file types are allowed: %1.' ), implode(", ",$allowed) );
                return eZInputValidator::STATE_INVALID;
                return eZInputValidator::STATE_INVALID;
        }
        }
 
 
        //Check size
        //Check size
        $mustUpload = false;
        $mustUpload = false;
Line 548... Line 548...
*/
*/
        $canFetchResult = EnhancedeZBinaryFileType::canFetch( $base . "_data_enhancedbinaryfilename_" . $contentObjectAttribute->attribute( "id" ), $maxSize );
        $canFetchResult = EnhancedeZBinaryFileType::canFetch( $base . "_data_enhancedbinaryfilename_" . $contentObjectAttribute->attribute( "id" ), $maxSize );
        //$binaryfile doesn't have an attribute(http_name)
        //$binaryfile doesn't have an attribute(http_name)
        if ( $mustUpload && $canFetchResult === eZHTTPFile::UPLOADEDFILE_DOES_NOT_EXIST )
        if ( $mustUpload && $canFetchResult === eZHTTPFile::UPLOADEDFILE_DOES_NOT_EXIST )
        {
        {
            $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 'A valid file is required.' ) );
            $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'A valid file is required.' ) );
            return eZInputValidator::STATE_INVALID;
            return eZInputValidator::STATE_INVALID;
        }
        }
        if ( $canFetchResult == eZHTTPFile::UPLOADEDFILE_EXCEEDS_PHP_LIMIT )
        if ( $canFetchResult == eZHTTPFile::UPLOADEDFILE_EXCEEDS_PHP_LIMIT )
        {
        {
            $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 'The size of the uploaded file exceeds the limit set by the upload_max_filesize directive in php.ini.' ) );
            $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'The size of the uploaded file exceeds the limit set by the upload_max_filesize directive in php.ini.' ) );
            return eZInputValidator::STATE_INVALID;
            return eZInputValidator::STATE_INVALID;
        }
        }
        if ( $canFetchResult == eZHTTPFile::UPLOADEDFILE_EXCEEDS_MAX_SIZE )
        if ( $canFetchResult == eZHTTPFile::UPLOADEDFILE_EXCEEDS_MAX_SIZE )
        {
        {
            $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 'The size of the uploaded file exceeds the maximum upload size: %1 bytes.' ), $maxSize );
            $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'The size of the uploaded file exceeds the maximum upload size: %1 bytes.' ), $maxSize );
            return eZInputValidator::STATE_INVALID;
            return eZInputValidator::STATE_INVALID;
        }
        }
        //Dropped all the way through with no error
        //Dropped all the way through with no error
        return eZInputValidator::STATE_ACCEPTED;
        return eZInputValidator::STATE_ACCEPTED;
    }
    }