[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/datatypes/ezimage/ -> ezimage.php (source)

   1  <?php
   2  //
   3  // Definition of eZImage class
   4  //
   5  // Created on: <30-Apr-2002 16:47:08 bf>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*!
  30    \class eZImage ezimage.php
  31    \ingroup eZDatatype
  32    \brief The class eZImage handles registered images
  33  
  34    \deprecated
  35  */
  36  
  37  include_once ( "lib/ezdb/classes/ezdb.php" );
  38  include_once ( "kernel/classes/ezpersistentobject.php" );
  39  include_once ( "kernel/classes/ezcontentclassattribute.php" );
  40  include_once ( "kernel/classes/datatypes/ezimage/ezimagevariation.php");
  41  
  42  class eZImage extends eZPersistentObject
  43  {
  44      function eZImage( $row )
  45      {
  46          $this->eZPersistentObject( $row );
  47      }
  48  
  49      function definition()
  50      {
  51          return array( "fields" => array( "contentobject_attribute_id" => array( 'name' => "ContentObjectAttributeID",
  52                                                                                  'datatype' => 'integer',
  53                                                                                  'default' => 0,
  54                                                                                  'required' => true,
  55                                                                                  'foreign_class' => 'eZContentObjectAttribute',
  56                                                                                  'foreign_attribute' => 'id',
  57                                                                                  'multiplicity' => '1..*' ),
  58                                           "version" => array( 'name' => "Version",
  59                                                               'datatype' => 'integer',
  60                                                               'default' => 0,
  61                                                               'required' => true ),
  62                                           "filename" => array( 'name' => "Filename",
  63                                                                'datatype' => 'string',
  64                                                                'default' => '',
  65                                                                'required' => true ),
  66                                           "original_filename" => array( 'name' => "OriginalFilename",
  67                                                                         'datatype' => 'string',
  68                                                                         'default' => '',
  69                                                                         'required' => true ),
  70                                           "mime_type" => array( 'name' => "MimeType",
  71                                                                 'datatype' => 'string',
  72                                                                 'default' => '',
  73                                                                 'required' => true ),
  74                                           "alternative_text" => array( 'name' => "AlternativeText",
  75                                                                        'datatype' => 'string',
  76                                                                        'default' => '',
  77                                                                        'required' => true ) ),
  78                        "keys" => array( "contentobject_attribute_id", "version" ),
  79                        "relations" => array( "contentobject_attribute_id" => array( "class" => "ezcontentobjectattribute",
  80                                                                                     "field" => "id" ) ),
  81                        "class_name" => "eZImage",
  82                        "name" => "ezimage" );
  83      }
  84  
  85      function attributes()
  86      {
  87          return eZPersistentObject::attributes();
  88      }
  89  
  90      function hasAttribute( $attr )
  91      {
  92          $imageIni =& eZINI::instance( 'image.ini' );
  93          if ( $imageIni->hasVariable( 'ImageSizes', 'Height' ) )
  94              $heightList = $imageIni->variable( 'ImageSizes', 'Height' );
  95          if ( $imageIni->hasVariable( 'ImageSizes', 'Width' ) )
  96              $widthList = $imageIni->variable( 'ImageSizes', 'Width' );
  97  
  98          if ( $heightList != null )
  99          {
 100              foreach ( array_keys ( $heightList ) as $key )
 101              {
 102                  if ( ( $attr != "small" and
 103                         $attr != "medium" and
 104                         $attr != "large" and
 105                         $attr != "reference" and
 106                         $attr != "original" ) and
 107                       $attr == $key )
 108                  {
 109                      $attr = "custom_size";
 110                      return $attr == "custom_size";
 111                  }
 112              }
 113          }
 114          return $attr == 'mime_type_category' or
 115                 $attr == 'mime_type_part' or
 116                 eZPersistentObject::hasAttribute( $attr ) or
 117                 $attr == 'small' or
 118                 $attr == 'large' or
 119                 $attr == 'medium' or
 120                 $attr == 'reference' or
 121                 $attr == 'original';
 122      }
 123  
 124      function &attribute( $attr )
 125      {
 126          $ini =& eZINI::instance();
 127  
 128          $imageIni =& eZINI::instance( 'image.ini' );
 129          if ( $imageIni->hasVariable( 'ImageSizes', 'Height' ) )
 130              $heightList = $imageIni->variable( 'ImageSizes', 'Height' );
 131          if ( $imageIni->hasVariable( 'ImageSizes', 'Width' ) )
 132              $widthList = $imageIni->variable( 'ImageSizes', 'Width' );
 133  
 134          foreach ( array_keys ( $heightList ) as $key )
 135          {
 136              if ( ( $attr != "small" or
 137                     $attr != "medium" or
 138                     $attr != "large" or
 139                     $attr != "reference" or
 140                     $attr != "original" ) and
 141                   $attr == $key )
 142              {
 143                  $attr = "custom_size";
 144                  $customHeight = $heightList[$key];
 145                  $customWidth = $widthList[$key];
 146              }
 147          }
 148          switch( $attr )
 149          {
 150              case "mime_type_category":
 151              {
 152                  $types = explode( "/", eZPersistentObject::attribute( "mime_type" ) );
 153                  return $types[0];
 154              }break;
 155              case "mime_type_part":
 156              {
 157                  $types = explode( "/", eZPersistentObject::attribute( "mime_type" ) );
 158                  return $types[1];
 159              } break;
 160              case "small":
 161              case "medium":
 162              case "large":
 163              case "reference":
 164              case "original":
 165              case "custom_size":
 166              {
 167                  if ( $attr == "small" )
 168                  {
 169                      $width = $ini->variable( "ImageSettings" , "SmallSizeWidth" );
 170                      $height = $ini->variable( "ImageSettings" , "SmallSizeHeight" );
 171                  }
 172                  else if ( $attr == "medium" )
 173                  {
 174                      $width = $ini->variable( "ImageSettings" , "MediumSizeWidth" );
 175                      $height = $ini->variable( "ImageSettings" , "MediumSizeHeight" );
 176                  }
 177                  else if ( $attr == "large" )
 178                  {
 179                      $width = $ini->variable( "ImageSettings" , "LargeSizeWidth" );
 180                      $height = $ini->variable( "ImageSettings" , "LargeSizeHeight" );
 181                  }
 182                  else if ( $attr == "reference" )
 183                  {
 184                      $width = $ini->variable( "ImageSettings" , "ReferenceSizeWidth" );
 185                      $height = $ini->variable( "ImageSettings" , "ReferenceSizeHeight" );
 186                  }
 187                  else if ( $attr == "custom_size" )
 188                  {
 189                      $width = $customWidth;
 190                      $height = $customHeight;
 191                  }
 192                  else
 193                  {
 194                      $width = false;
 195                      $height = false;
 196                  }
 197  
 198                  if ( $heightList != null )
 199                  {
 200                      foreach ( array_keys ( $heightList ) as $key )
 201                      {
 202                          $heightValue =& $heightList[$key];
 203                          if ( $heightValue )
 204                          {
 205                              if ( $key == "small" and $attr == "small" )
 206                              {
 207                                  $height = $heightValue;
 208                                  $width = $widthList[$key];
 209                              }
 210                              else if ( $key == "medium" and $attr == "medium" )
 211                              {
 212                                  $height = $heightValue;
 213                                  $width = $widthList[$key];
 214                              }
 215                              else if ( $key == "large" and $attr == "large" )
 216                              {
 217                                  $height = $heightValue;
 218                                  $width = $widthList[$key];
 219                              }
 220                              else if ( $key == "reference" and $attr == "reference" )
 221                              {
 222                                  $height = $heightValue;
 223                                  $width = $widthList[$key];
 224                              }
 225                              else
 226                              {
 227                                  // No changes
 228                              }
 229                          }
 230                      }
 231                  }
 232  
 233                  $cacheString = $this->ContentObjectAttributeID . '-' . $attr . "-" . $width . "-" . $height;
 234                  if ( $attr == "original" )
 235                      $cacheString = $this->ContentObjectAttributeID . '-' . $attr;
 236  
 237                  if ( !isset( $GLOBALS[$cacheString] ) )
 238                  {
 239                      if ( $attr == "original" )
 240                          $img_variation =& eZImageVariation::createOriginal( $this->ContentObjectAttributeID, $this->Version, $this->Filename, eZDir::getPathFromFilename( $this->Filename ) );
 241                      else
 242                          $img_variation =& eZImageVariation::requestVariation( $this, $width, $height );
 243                      $GLOBALS[$cacheString] =& $img_variation;
 244                  }
 245                  else
 246                  {
 247                      $img_variation =& $GLOBALS[$cacheString];
 248                  }
 249                  return $img_variation;
 250              }break;
 251              default:
 252                  return eZPersistentObject::attribute( $attr );
 253          }
 254      }
 255  
 256      function create( $contentObjectAttributeID, $contentObjectAttributeVersion  )
 257      {
 258          $row = array( "contentobject_attribute_id" => $contentObjectAttributeID,
 259                        "version" => $contentObjectAttributeVersion,
 260                        "filename" => "",
 261                        "original_filename" => "",
 262                        "mime_type" => ""
 263                        );
 264          return new eZImage( $row );
 265      }
 266  
 267      function fetch( $id, $version = null, $asObject = true )
 268      {
 269          if( $version == null )
 270          {
 271              return eZPersistentObject::fetchObjectList( eZImage::definition(),
 272                                                          null,
 273                                                          array( "contentobject_attribute_id" => $id ),
 274                                                          null,
 275                                                          null,
 276                                                          $asObject );
 277          }
 278          else
 279          {
 280              return eZPersistentObject::fetchObject( eZImage::definition(),
 281                                                      null,
 282                                                      array( "contentobject_attribute_id" => $id,
 283                                                             "version" => $version ),
 284                                                      $asObject );
 285          }
 286      }
 287  
 288      function fetchList( $asObject = true )
 289      {
 290          return eZPersistentObject::fetchObjectList( eZImage::definition(),
 291                                                      null, null, null, null,
 292                                                      $asObject );
 293      }
 294  
 295      function remove( $id, $version )
 296      {
 297          if( $version == null )
 298          {
 299              eZPersistentObject::removeObject( eZImage::definition(),
 300                                                array( "contentobject_attribute_id" => $id ) );
 301          }
 302          else
 303          {
 304              eZPersistentObject::removeObject( eZImage::definition(),
 305                                                array( "contentobject_attribute_id" => $id,
 306                                                       "version" => $version ) );
 307          }
 308      }
 309  
 310      var $Version;
 311      var $ContentObjectAttributeID;
 312      var $Filename;
 313      var $OriginalFilename;
 314      var $MimeType;
 315  }
 316  
 317  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7