eZ Publish  [4.0]
ezimage.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZImage class
00004 //
00005 // Created on: <30-Apr-2002 16:47:08 bf>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*!
00032   \class eZImage ezimage.php
00033   \ingroup eZDatatype
00034   \brief The class eZImage handles registered images
00035 
00036   \deprecated
00037 */
00038 
00039 //include_once( "lib/ezdb/classes/ezdb.php" );
00040 //include_once( "kernel/classes/ezpersistentobject.php" );
00041 //include_once( "kernel/classes/ezcontentclassattribute.php" );
00042 //include_once( "kernel/classes/datatypes/ezimage/ezimagevariation.php");
00043 
00044 class eZImage extends eZPersistentObject
00045 {
00046     function eZImage( $row )
00047     {
00048         $this->eZPersistentObject( $row );
00049     }
00050 
00051     static function definition()
00052     {
00053         return array( "fields" => array( "contentobject_attribute_id" => array( 'name' => "ContentObjectAttributeID",
00054                                                                                 'datatype' => 'integer',
00055                                                                                 'default' => 0,
00056                                                                                 'required' => true,
00057                                                                                 'foreign_class' => 'eZContentObjectAttribute',
00058                                                                                 'foreign_attribute' => 'id',
00059                                                                                 'multiplicity' => '1..*' ),
00060                                          "version" => array( 'name' => "Version",
00061                                                              'datatype' => 'integer',
00062                                                              'default' => 0,
00063                                                              'required' => true ),
00064                                          "filename" => array( 'name' => "Filename",
00065                                                               'datatype' => 'string',
00066                                                               'default' => '',
00067                                                               'required' => true ),
00068                                          "original_filename" => array( 'name' => "OriginalFilename",
00069                                                                        'datatype' => 'string',
00070                                                                        'default' => '',
00071                                                                        'required' => true ),
00072                                          "mime_type" => array( 'name' => "MimeType",
00073                                                                'datatype' => 'string',
00074                                                                'default' => '',
00075                                                                'required' => true ),
00076                                          "alternative_text" => array( 'name' => "AlternativeText",
00077                                                                       'datatype' => 'string',
00078                                                                       'default' => '',
00079                                                                       'required' => true ) ),
00080                       "keys" => array( "contentobject_attribute_id", "version" ),
00081                       "relations" => array( "contentobject_attribute_id" => array( "class" => "eZContentObjectAttribute",
00082                                                                                    "field" => "id" ) ),
00083                       "class_name" => "eZImage",
00084                       "name" => "ezimage" );
00085     }
00086 
00087     function attributes()
00088     {
00089         return eZPersistentObject::attributes();
00090     }
00091 
00092     function hasAttribute( $attr )
00093     {
00094         $imageIni = eZINI::instance( 'image.ini' );
00095         if ( $imageIni->hasVariable( 'ImageSizes', 'Height' ) )
00096             $heightList = $imageIni->variable( 'ImageSizes', 'Height' );
00097         if ( $imageIni->hasVariable( 'ImageSizes', 'Width' ) )
00098             $widthList = $imageIni->variable( 'ImageSizes', 'Width' );
00099 
00100         if ( $heightList != null )
00101         {
00102             foreach ( array_keys ( $heightList ) as $key )
00103             {
00104                 if ( ( $attr != "small" and
00105                        $attr != "medium" and
00106                        $attr != "large" and
00107                        $attr != "reference" and
00108                        $attr != "original" ) and
00109                      $attr == $key )
00110                 {
00111                     $attr = "custom_size";
00112                     return $attr == "custom_size";
00113                 }
00114             }
00115         }
00116         return $attr == 'mime_type_category' or
00117                $attr == 'mime_type_part' or
00118                eZPersistentObject::hasAttribute( $attr ) or
00119                $attr == 'small' or
00120                $attr == 'large' or
00121                $attr == 'medium' or
00122                $attr == 'reference' or
00123                $attr == 'original';
00124     }
00125 
00126     function attribute( $attr )
00127     {
00128         $ini = eZINI::instance();
00129 
00130         $imageIni = eZINI::instance( 'image.ini' );
00131         if ( $imageIni->hasVariable( 'ImageSizes', 'Height' ) )
00132             $heightList = $imageIni->variable( 'ImageSizes', 'Height' );
00133         if ( $imageIni->hasVariable( 'ImageSizes', 'Width' ) )
00134             $widthList = $imageIni->variable( 'ImageSizes', 'Width' );
00135 
00136         foreach ( array_keys ( $heightList ) as $key )
00137         {
00138             if ( ( $attr != "small" or
00139                    $attr != "medium" or
00140                    $attr != "large" or
00141                    $attr != "reference" or
00142                    $attr != "original" ) and
00143                  $attr == $key )
00144             {
00145                 $attr = "custom_size";
00146                 $customHeight = $heightList[$key];
00147                 $customWidth = $widthList[$key];
00148             }
00149         }
00150         switch( $attr )
00151         {
00152             case "mime_type_category":
00153             {
00154                 $types = explode( "/", eZPersistentObject::attribute( "mime_type" ) );
00155                 return $types[0];
00156             }break;
00157             case "mime_type_part":
00158             {
00159                 $types = explode( "/", eZPersistentObject::attribute( "mime_type" ) );
00160                 return $types[1];
00161             } break;
00162             case "small":
00163             case "medium":
00164             case "large":
00165             case "reference":
00166             case "original":
00167             case "custom_size":
00168             {
00169                 if ( $attr == "small" )
00170                 {
00171                     $width = $ini->variable( "ImageSettings" , "SmallSizeWidth" );
00172                     $height = $ini->variable( "ImageSettings" , "SmallSizeHeight" );
00173                 }
00174                 else if ( $attr == "medium" )
00175                 {
00176                     $width = $ini->variable( "ImageSettings" , "MediumSizeWidth" );
00177                     $height = $ini->variable( "ImageSettings" , "MediumSizeHeight" );
00178                 }
00179                 else if ( $attr == "large" )
00180                 {
00181                     $width = $ini->variable( "ImageSettings" , "LargeSizeWidth" );
00182                     $height = $ini->variable( "ImageSettings" , "LargeSizeHeight" );
00183                 }
00184                 else if ( $attr == "reference" )
00185                 {
00186                     $width = $ini->variable( "ImageSettings" , "ReferenceSizeWidth" );
00187                     $height = $ini->variable( "ImageSettings" , "ReferenceSizeHeight" );
00188                 }
00189                 else if ( $attr == "custom_size" )
00190                 {
00191                     $width = $customWidth;
00192                     $height = $customHeight;
00193                 }
00194                 else
00195                 {
00196                     $width = false;
00197                     $height = false;
00198                 }
00199 
00200                 if ( $heightList != null )
00201                 {
00202                     foreach ( $heightList as $key => $heightValue )
00203                     {
00204                         if ( $heightValue )
00205                         {
00206                             if ( $key == "small" and $attr == "small" )
00207                             {
00208                                 $height = $heightValue;
00209                                 $width = $widthList[$key];
00210                             }
00211                             else if ( $key == "medium" and $attr == "medium" )
00212                             {
00213                                 $height = $heightValue;
00214                                 $width = $widthList[$key];
00215                             }
00216                             else if ( $key == "large" and $attr == "large" )
00217                             {
00218                                 $height = $heightValue;
00219                                 $width = $widthList[$key];
00220                             }
00221                             else if ( $key == "reference" and $attr == "reference" )
00222                             {
00223                                 $height = $heightValue;
00224                                 $width = $widthList[$key];
00225                             }
00226                             else
00227                             {
00228                                 // No changes
00229                             }
00230                         }
00231                     }
00232                 }
00233 
00234                 $cacheString = $this->ContentObjectAttributeID . '-' . $attr . "-" . $width . "-" . $height;
00235                 if ( $attr == "original" )
00236                     $cacheString = $this->ContentObjectAttributeID . '-' . $attr;
00237 
00238                 if ( !isset( $GLOBALS[$cacheString] ) )
00239                 {
00240                     if ( $attr == "original" )
00241                     {
00242                         $img_variation = eZImageVariation::createOriginal( $this->ContentObjectAttributeID, $this->Version, $this->Filename, eZDir::getPathFromFilename( $this->Filename ) );
00243                     }
00244                     else
00245                     {
00246                         $img_variation = eZImageVariation::requestVariation( $this, $width, $height );
00247                     }
00248                     $GLOBALS[$cacheString] = $img_variation;
00249                 }
00250                 else
00251                 {
00252                     $img_variation = $GLOBALS[$cacheString];
00253                 }
00254                 return $img_variation;
00255             }break;
00256             default:
00257                 return eZPersistentObject::attribute( $attr );
00258         }
00259     }
00260 
00261     function create( $contentObjectAttributeID, $contentObjectAttributeVersion  )
00262     {
00263         $row = array( "contentobject_attribute_id" => $contentObjectAttributeID,
00264                       "version" => $contentObjectAttributeVersion,
00265                       "filename" => "",
00266                       "original_filename" => "",
00267                       "mime_type" => ""
00268                       );
00269         return new eZImage( $row );
00270     }
00271 
00272     function fetch( $id, $version = null, $asObject = true )
00273     {
00274         if( $version == null )
00275         {
00276             return eZPersistentObject::fetchObjectList( eZImage::definition(),
00277                                                         null,
00278                                                         array( "contentobject_attribute_id" => $id ),
00279                                                         null,
00280                                                         null,
00281                                                         $asObject );
00282         }
00283         else
00284         {
00285             return eZPersistentObject::fetchObject( eZImage::definition(),
00286                                                     null,
00287                                                     array( "contentobject_attribute_id" => $id,
00288                                                            "version" => $version ),
00289                                                     $asObject );
00290         }
00291     }
00292 
00293     function fetchList( $asObject = true )
00294     {
00295         return eZPersistentObject::fetchObjectList( eZImage::definition(),
00296                                                     null, null, null, null,
00297                                                     $asObject );
00298     }
00299 
00300     function remove( $id, $version )
00301     {
00302         if( $version == null )
00303         {
00304             eZPersistentObject::removeObject( eZImage::definition(),
00305                                               array( "contentobject_attribute_id" => $id ) );
00306         }
00307         else
00308         {
00309             eZPersistentObject::removeObject( eZImage::definition(),
00310                                               array( "contentobject_attribute_id" => $id,
00311                                                      "version" => $version ) );
00312         }
00313     }
00314 
00315     public $Version;
00316     public $ContentObjectAttributeID;
00317     public $Filename;
00318     public $OriginalFilename;
00319     public $MimeType;
00320 }
00321 
00322 ?>