00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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 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 ( array_keys ( $heightList ) as $key )
00203 {
00204 $heightValue =& $heightList[$key];
00205 if ( $heightValue )
00206 {
00207 if ( $key == "small" and $attr == "small" )
00208 {
00209 $height = $heightValue;
00210 $width = $widthList[$key];
00211 }
00212 else if ( $key == "medium" and $attr == "medium" )
00213 {
00214 $height = $heightValue;
00215 $width = $widthList[$key];
00216 }
00217 else if ( $key == "large" and $attr == "large" )
00218 {
00219 $height = $heightValue;
00220 $width = $widthList[$key];
00221 }
00222 else if ( $key == "reference" and $attr == "reference" )
00223 {
00224 $height = $heightValue;
00225 $width = $widthList[$key];
00226 }
00227 else
00228 {
00229
00230 }
00231 }
00232 }
00233 }
00234
00235 $cacheString = $this->ContentObjectAttributeID . '-' . $attr . "-" . $width . "-" . $height;
00236 if ( $attr == "original" )
00237 $cacheString = $this->ContentObjectAttributeID . '-' . $attr;
00238
00239 if ( !isset( $GLOBALS[$cacheString] ) )
00240 {
00241 if ( $attr == "original" )
00242 $img_variation =& eZImageVariation::createOriginal( $this->ContentObjectAttributeID, $this->Version, $this->Filename, eZDir::getPathFromFilename( $this->Filename ) );
00243 else
00244 $img_variation =& eZImageVariation::requestVariation( $this, $width, $height );
00245 $GLOBALS[$cacheString] =& $img_variation;
00246 }
00247 else
00248 {
00249 $img_variation =& $GLOBALS[$cacheString];
00250 }
00251 return $img_variation;
00252 }break;
00253 default:
00254 return eZPersistentObject::attribute( $attr );
00255 }
00256 }
00257
00258 function create( $contentObjectAttributeID, $contentObjectAttributeVersion )
00259 {
00260 $row = array( "contentobject_attribute_id" => $contentObjectAttributeID,
00261 "version" => $contentObjectAttributeVersion,
00262 "filename" => "",
00263 "original_filename" => "",
00264 "mime_type" => ""
00265 );
00266 return new eZImage( $row );
00267 }
00268
00269 function fetch( $id, $version = null, $asObject = true )
00270 {
00271 if( $version == null )
00272 {
00273 return eZPersistentObject::fetchObjectList( eZImage::definition(),
00274 null,
00275 array( "contentobject_attribute_id" => $id ),
00276 null,
00277 null,
00278 $asObject );
00279 }
00280 else
00281 {
00282 return eZPersistentObject::fetchObject( eZImage::definition(),
00283 null,
00284 array( "contentobject_attribute_id" => $id,
00285 "version" => $version ),
00286 $asObject );
00287 }
00288 }
00289
00290 function fetchList( $asObject = true )
00291 {
00292 return eZPersistentObject::fetchObjectList( eZImage::definition(),
00293 null, null, null, null,
00294 $asObject );
00295 }
00296
00297 function remove( $id, $version )
00298 {
00299 if( $version == null )
00300 {
00301 eZPersistentObject::removeObject( eZImage::definition(),
00302 array( "contentobject_attribute_id" => $id ) );
00303 }
00304 else
00305 {
00306 eZPersistentObject::removeObject( eZImage::definition(),
00307 array( "contentobject_attribute_id" => $id,
00308 "version" => $version ) );
00309 }
00310 }
00311
00312 var $Version;
00313 var $ContentObjectAttributeID;
00314 var $Filename;
00315 var $OriginalFilename;
00316 var $MimeType;
00317 }
00318
00319 ?>