Author Topic

Felipe Jaramillo

Monday 31 July 2006 9:58:35 am

Comment46406

Hi Xavier,

Maybe this helps. The CSV extension available in pubsvn.ez.no has this code for the ezimage attribute:

case 'ezimage':
        {
            $contentObjectID = $contentObjectAttribute->attribute( 'contentobject_id' );
            $contentObjectVersion = $contentObjectAttribute->attribute( 'version' );
            makeImage( $contentObjectID, $contentObjectVersion, $contentObjectAttribute, $attributeContent );
            break;
        }

It calls the makeImage function:

function makeImage( $objectID, $version, &$attribute, $blob )
{
    $img =& imageInit();
    $contentObjectAttributeID = $attribute->attribute( "id" );
    $sys =& eZSys::instance();
    $storage_dir = $sys->storageDirectory();
    $tmpname = tempnam( "/tmp/" , "eZ" );
    $httpFileName = $blob;
    $content =& $attribute->attribute( 'content' );
    if ( trim( $httpFileName ) != "" and ( preg_match( "/http/i", $httpFileName ) ) )
    {
        $fhandler = fopen( $httpFileName, "r");
        if ( $fhandler  )
        {
            if ( $hasImageAltText )
                $content->setAttribute( 'alternative_text', $imageAltText );
            $result = true;

            $sys =& eZSys::instance();
            $storage_dir = $sys->storageDirectory();

            $urlArray = split('/', $httpFileName );
            $arrayCount = count( $urlArray );
            $tempFile = $urlArray[$arrayCount-1];

            $fwriter = fopen( $storage_dir. "/" . $tempFile, "w");
            $contentValue = "";
            do
            {
                $data = fread( $fhandler, 4096 );
                if ( strlen( $data ) == 0)
                {
                    break;
                }
                $contentValue .= $data;
            } while (true);

            fwrite( $fwriter, $contentValue);
            fclose( $fwriter );

            fclose( $fhandler );

            if ( is_object( $content ) )
            {
                $sys =& eZSys::instance();
                $storage_dir = $sys->storageDirectory();
                $imageFile= $storage_dir . "/" . $tempFile;
                $GLOBALS['eZURLImageIsStored'] = 1;
                if ( $hasImageAltText )
                {
                    $content->initializeFromFile( $imageFile, $imageAltText );
                }
                else
                {
                    $content->initializeFromFile( $imageFile );
                }
                if ( $content->isStorageRequired() )
                {
                    $content->store();
                }
                unlink( $imageFile );
            }
        }
    }
}

Regards,

Felipe

Felipe Jaramillo
eZ Certified Extension Developer
http://www.aplyca.com | Bogotá, Colombia