[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/gallery/dao/ -> galleryresource.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/database/dbobject.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/gallery/galleryconstants.php" );
   5      
   6      // Add this to avoid long file name error in windows server
   7      define('GETID3_HELPERAPPSDIR', 'no_helper_apps_needed'); 
   8  
   9      /**
  10       * \ingroup Gallery
  11       *
  12       * Encapsulates a resource from our database.
  13       *
  14       * Each GalleryResource object can belong to only one GalleryAlbum object, and therefore every object
  15       * has a reference to its album.
  16       *
  17       * This class also provides methods for getting the correct metadata reader, for checking the type of the
  18       * resource, for getting access to the thumbnail of the object, etc.
  19       */
  20      class GalleryResource extends DbObject
  21      {
  22  
  23          var $_id;
  24          var $_ownerId;
  25          var $_albumId;
  26          var $_date;
  27          var $_description;
  28          var $_flags;
  29          var $_resourceType;
  30          var $_filePath;
  31          var $_fileName;
  32          var $_metadata;
  33          var $_album;
  34          var $_thumbnailFormat;
  35          var $_fileDescriptor;
  36          var $_fileSize;
  37          
  38          /**
  39           * Constructor.
  40           *
  41           * @param ownerId Id of the user to whom this resource belongs
  42           * @param albumId The id of the GalleryAlbum object to which this resource belongs
  43           * @param description Description of this file
  44           * @param flags As of pLog 1.0, there is only one flag available: GALLERY_RESOURCE_PREVIEW_AVAILABLE.
  45           * @param resourceType The type of the resource. One of the following constants:
  46           * - GALLERY_RESOURCE_IMAGE
  47           * - GALLERY_RESOURCE_VIDEO
  48           * - GALLERY_RESOURCE_SOUND
  49           * - GALLERY_RESOURCE_UNKNOWN
  50           * - GALLERY_RESOURCE_DOCUMENT
  51           * - GALLERY_RESOURCE_ZIP
  52           * @param filePath path in disk to the real file. Not used.
  53           * @param fileName name of the file, which is not exactly the same name that the file has in disk, since the
  54           * GalleryResourceStorage class is taking care of managing things in disk. Nevertheless, this is the file that will
  55           * be shown to users in the user interface
  56           * @param metadata An array, as generated by the getID3 class.
  57           * @param date A SQL date
  58           * @param thumbnailFormat The format of the thumbnail
  59           * @param id Optinally, the id. When creating new resources, the GalleryResources::addResource() method will
  60           * update the id so it does not matter what we provide here.
  61           * @see getID3
  62           */
  63          function GalleryResource( $ownerId, $albumId, $description, $flags, $resourceType,
  64                                    $filePath, $fileName, $metadata, $date, $thumbnailFormat, $properties = Array(), $id = -1 )
  65          {
  66              $this->DbObject();
  67              $this->_ownerId = $ownerId;
  68              $this->_albumId = $albumId;
  69              $this->_description = $description;
  70              $this->_flags = $flags;
  71              $this->_resourceType = $resourceType;
  72              $this->_filePath = $filePath;
  73              $this->_fileName = $fileName;
  74              $this->_fileSize = 0;
  75              $this->_metadata = $metadata;
  76              $this->_date = $date;
  77              $this->_thumbnailFormat = $thumbnailFormat;
  78              $this->_id = $id;
  79              $this->_album = null;
  80              $this->setProperties( $properties );
  81              
  82              $this->_fields = Array(
  83                  "owner_id" => "getOwnerId",
  84                  "album_id" => "getAlbumId",
  85                  "description" => "getDescription",
  86                  "date" => "getDate",
  87                  "flags" => "getFlags",
  88                  "resource_type" => "getResourceType",
  89                  "file_path" => "getFilePath",
  90                  "file_name" => "getFileName",
  91                  "file_size" => "getFileSize", 
  92                  "thumbnail_format" => "getThumbnailFormat",
  93                  "normalized_description" => "getNormalizedDescription",
  94                  "properties" => "getProperties",
  95                  "metadata" => "getMetadata"
  96              );
  97              $this->_fileDescriptor = false;
  98          }
  99  
 100          /**
 101           * @return the identifier of the resource, or -1 if none has been set yet.
 102           */
 103          function getId()
 104          {
 105              return $this->_id;
 106          }
 107  
 108          /**
 109           * @return the identifier of the owner of this resource
 110           */
 111          function getOwnerId()
 112          {
 113              return $this->_ownerId;
 114          }
 115  
 116          /**
 117           * @return the bloginfo of the owner of this resource
 118           */        
 119          function getBlogInfo()
 120          {
 121              lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
 122              $blogs = new Blogs();
 123              $blogInfo = $blogs->getBlogInfo( $this->_ownerId );
 124              return $blogInfo;
 125          }
 126  
 127          /**
 128           * @return returns the identifier of the GalleryAlbum object to which this resource belongs
 129           */
 130          function getAlbumId()
 131          {
 132              return $this->_albumId;
 133          }
 134  
 135          /**
 136           * @return Returns a 14-digit SQL date
 137           */
 138          function getDate()
 139          {
 140              return $this->_date;
 141          }
 142  
 143          /**
 144           * @return Returns a Timestamp object
 145           * @see Timestamp
 146           */    
 147          function getTimestamp()
 148          {
 149              // source necessary source
 150              lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
 151  
 152              return new Timestamp($this->_date);
 153          }
 154  
 155          /**
 156           * @return returns the "raw" metadata information, as generated by the getID3 class. It is
 157           * advisable to use the GalleryResource::getResourceMetadataReader to get the right
 158           * metadata reader class, since these classes provide convenience methods for accessing
 159           * the most common attributes of sound files, videos, etc.
 160           */
 161          function getMetadata()
 162          {
 163              return $this->_metadata;
 164          }
 165          
 166          /**
 167           * Set the resource metadata to the given array
 168           *
 169           * @param metadata
 170           * @return Nothing
 171           */
 172  		function setMetadata( $metadata )
 173          {
 174              $this->_metadata = $metadata;
 175          }
 176  
 177          /**
 178           * @return the flags of the resource object
 179           */
 180          function getFlags()
 181          {
 182              return $this->_flags;
 183          }
 184  
 185          /**
 186           * @return The path of the file in disk
 187           */
 188          function getFilePath()
 189          {
 190              return $this->_filePath;
 191          }
 192  
 193          /**
 194           * @return the name of the file in disk
 195           */
 196          function getFileName()
 197          {
 198              return $this->_fileName;
 199          }
 200  
 201          /**
 202           * @return the encoded name of the file in disk
 203           */
 204          function getEncodedFileName()
 205          {
 206              $fileParts = explode( ".", $this->_fileName );
 207              $fileExt = strtolower($fileParts[count($fileParts)-1]);
 208              $encodedFileName = $this->getOwnerId()."-".$this->getId().".".$fileExt;
 209              return $encodedFileName;
 210          }
 211  
 212          /**
 213           * @return the description of the resource
 214           */
 215          function getDescription()
 216          {
 217              return $this->_description;
 218          }
 219  
 220          /**
 221           * returns the mime type of the resource
 222           *
 223           * @return a valid mime type
 224           */
 225          function getMimeType()
 226          {
 227              lt_include( PLOG_CLASS_PATH."class/data/mimetype.class.php" );        
 228          
 229              $mimeType = new MimeType();
 230              return $mimeType->getType( $this->_fileName );
 231          }
 232          
 233          /**
 234           * returns the mime type of the thumbnails
 235           *
 236           * @return a valid mime type
 237           */
 238  		function getThumbnailMimeType()
 239          {
 240            lt_include( PLOG_CLASS_PATH."class/data/mimetype.class.php" );
 241              if( $this->getThumbnailFormat() == "same" )
 242                  return $this->getMimeType();
 243              else {
 244                  $mimeType = new MimeType();
 245                  return $mimeType->getType( $this->getThumbnailFormat());
 246              }
 247          }
 248  
 249          function getResourceType()
 250          {
 251              return $this->_resourceType;
 252          }
 253  
 254          /**
 255           * Sets the album id. You should normally not need to use this method
 256           *
 257           * @param albumId The id of the album
 258           */
 259          function setAlbumId( $albumId )
 260          {
 261              $this->_albumId = $albumId;
 262          }
 263  
 264          /**
 265           * Sets the GalleryAlbum object to which this file belongs
 266           */    
 267          function setAlbum( $album )
 268          {
 269              $this->_album = $album;
 270          }
 271          
 272          /**
 273           * @return The GalleryAlbum object to which this resource belongs
 274           */        
 275  		function getAlbum()
 276          {
 277              if( $this->_album == null ) {
 278                  lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
 279                  $albums = new GalleryAlbums();
 280                  $this->_album = $albums->getAlbum( $this->getAlbumId());
 281              }
 282              
 283              return $this->_album;
 284          }
 285  
 286          /**
 287           * Sets the descriptoion of the object
 288           *
 289           * @param description the new description
 290           */
 291          function setDescription( $description )
 292          {
 293              $this->_description = $description;
 294          }
 295          
 296          /**
 297           * @return returns the format of the thumbnail that was generated for this file, if any. Of
 298           * course this method has no relevance if the object is not representing an image
 299           */        
 300  		function getThumbnailFormat()
 301          {
 302              return $this->_thumbnailFormat;
 303          }
 304          
 305          /**
 306           * Sets the thumbnail format
 307           *
 308           * @return nothing
 309           */        
 310  		function setThumbnailFormat( $format )
 311          {
 312              $this->_thumbnailFormat = $format;
 313          }
 314          
 315          /**
 316           * returns the size of the resource file
 317           *
 318           * @return the size of the file in bytes
 319           */
 320  		function getFileSize()
 321          {
 322              return( $this->_fileSize );
 323          }
 324          
 325  		function setFileSize( $size )
 326          {
 327              $this->_fileSize = $size;
 328          }
 329  
 330          /**
 331           * returns an object that will allow to access the metadata of this resource
 332           *
 333           * @see GalleryResourceImageMetadataReader
 334           * @see GalleryResourceSoundMetadataReader
 335           * @see GalleryResourceVideoMoetadataReader
 336           * @see GalleryResourceZipMetadataReader
 337           * @see GalleryResourceBaseMetadataReader
 338           */
 339          function getMetadataReader()
 340          {
 341              lt_include( PLOG_CLASS_PATH."class/gallery/data/galleryresourceimagemetadatareader.class.php" );
 342              lt_include( PLOG_CLASS_PATH."class/gallery/data/galleryresourcesoundmetadatareader.class.php" );
 343              lt_include( PLOG_CLASS_PATH."class/gallery/data/galleryresourcevideometadatareader.class.php" );
 344              lt_include( PLOG_CLASS_PATH."class/gallery/data/galleryresourcezipmetadatareader.class.php" );
 345                  
 346              switch( $this->getResourceType()) {
 347                  case GALLERY_RESOURCE_IMAGE:
 348                      $reader = new GalleryResourceImageMetadataReader( $this );
 349                      break;
 350                  case GALLERY_RESOURCE_SOUND:
 351                      $reader = new GalleryResourceSoundMetadataReader( $this );
 352                      break;
 353                  case GALLERY_RESOURCE_VIDEO:
 354                      $reader = new GalleryResourceVideoMetadataReader( $this );
 355                      break;
 356                  case GALLERY_RESOURCE_ZIP:
 357                      $reader = new GalleryResourceZipMetadataReader( $this );
 358                      break;
 359                  default:
 360                      $reader = new GalleryResourceBaseMetadataReader( $this );
 361                      break;
 362              }
 363  
 364              return $reader;
 365          }
 366  
 367          /**
 368           * Returns true if this resource has a preview or false if not.
 369           *
 370           * @return True if preview available or false otherwise.
 371           */
 372          function hasPreview()
 373          {
 374              return( $this->_flags & GALLERY_RESOURCE_PREVIEW_AVAILABLE );
 375          }
 376          
 377          /**
 378           * returns the name of the file in disk where the preview is
 379           * stored
 380           *
 381           * @return the path to the small preview file
 382           */
 383  		function getPreviewFileName()
 384          {            
 385              lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );    
 386  
 387              $config =& Config::getConfig();
 388  
 389              // encoding the filename if "encoded_file_name" enabled
 390              if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" )
 391                  $fileName = $this->getEncodedFileName();
 392              else
 393                  $fileName = $this->getFileName();
 394          
 395              // change the file extension, if the thumbnail output format is different from the original file
 396              if( $this->getThumbnailFormat() == THUMBNAIL_OUTPUT_FORMAT_SAME_AS_IMAGE )
 397                  $previewFile = $fileName;
 398              else {
 399                  $previewFile = str_replace( ".".strtolower($this->getFileExtension()), ".".strtolower($this->getThumbnailFormat()), $fileName );
 400              }
 401  
 402              return $previewFile;
 403          }
 404          
 405          /**
 406           * Returns the file extension
 407           *
 408           * @param toLower Whether the extension should be returned in lower case, false by default
 409           * @return The file extension
 410           */
 411  		function getFileExtension( $toLower = false )
 412          {
 413              $fileName = $this->getFileName();
 414              if(( $extPos = strrpos( $fileName, "." )) !== false ) {                    
 415                  $fileExt = substr( $fileName, $extPos+1, strlen( $fileName ));
 416              }
 417              else {
 418                  $fileExt = "";
 419              }            
 420              
 421              return( $fileExt );
 422          }
 423  
 424          /**
 425           * returns the full path to the file with the medium-sized preview
 426           *
 427           * @return full path to the medium-sized preview
 428           */
 429  		function getMediumSizePreviewFileName()
 430          {
 431              lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );        
 432          
 433              $config =& Config::getConfig();
 434  
 435              // encoding the filename if "encoded_file_name" enabled
 436              if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" )
 437                  $fileName = $this->getEncodedFileName();
 438              else
 439                  $fileName = $this->getFileName();
 440              
 441              // change the file extension, if the thumbnail output format is different from the original file
 442              if( $this->getThumbnailFormat() == THUMBNAIL_OUTPUT_FORMAT_SAME_AS_IMAGE )
 443                  $previewFile = $fileName;
 444              else
 445                  $previewFile = str_replace( ".".strtolower($this->getFileExtension()), ".".strtolower($this->getThumbnailFormat()), $fileName );
 446  
 447              return $previewFile;
 448          }
 449  
 450          /**
 451           * returns the full path to the file with the original size
 452           *
 453           * @return full path to the original size
 454           */
 455  		function getOriginalSizeFileName()
 456          {
 457              lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );        
 458          
 459              $config =& Config::getConfig();
 460  
 461              // encoding the filename if "encoded_file_name" enabled
 462              if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" )
 463                  $fileName = $this->getEncodedFileName();
 464              else
 465                  $fileName = $this->getFileName();
 466              
 467              return $fileName;
 468          }
 469          
 470  		function getNormalizedDescription()
 471          {
 472              lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
 473              $tf = new Textfilter();
 474              return( $tf->normalizeText( $this->getDescription()));
 475          }
 476          
 477          /**
 478           * @return true if the resource is an image
 479           */
 480          function isImage()
 481          {
 482              return( $this->_resourceType == GALLERY_RESOURCE_IMAGE );
 483          }
 484  
 485          /**
 486           * @return true if the resource is a sound file
 487           */
 488          function isSound()
 489          {
 490              return( $this->_resourceType == GALLERY_RESOURCE_SOUND );
 491          }
 492  
 493          /**
 494           * @return true if the resource file is a video
 495           */
 496          function isVideo()
 497          {
 498              return( $this->_resourceType == GALLERY_RESOURCE_VIDEO );
 499          }
 500  
 501          /**
 502           * @return true if the resource file is a ZIP file
 503           */
 504          function isZip()
 505          {
 506              return( $this->_resourceType == GALLERY_RESOURCE_ZIP );
 507          }
 508  
 509          /**
 510           * returns the link to the resource page
 511           */
 512  		function getResourceLink()
 513          {
 514              $blog = $this->getBlogInfo();
 515              $url = $blog->getBlogRequestGenerator();
 516              return( $url->resourceLink( $this ));            
 517          }
 518  
 519          /**
 520           * returns the download link for this resource
 521           */
 522  		function getLink()
 523          {
 524              $blog = $this->getBlogInfo();
 525              $url = $blog->getBlogRequestGenerator();
 526              return( $url->resourceDownloadLink( $this ));
 527          }
 528          
 529          /**
 530           * returns the preview link (thumbnail) for this resource if it's an image, or an empty string otherwise
 531           */
 532  		function getPreviewLink()
 533          {
 534              $link = "";
 535              if( $this->isImage()) {            
 536                  $blog = $this->getBlogInfo();
 537                  $url = $blog->getBlogRequestGenerator();
 538                  $link = $url->resourcePreviewLink( $this );
 539              }
 540              
 541              return( $link );
 542          }
 543          
 544          /**
 545           * returns the medium preview link (thumbnail) for this resource if it's an image, 
 546           * or an empty string otherwise
 547           */
 548  		function getMediumPreviewLink()
 549          {
 550              $link = "";
 551              if( $this->isImage()) {            
 552                  $blog = $this->getBlogInfo();
 553                  $url = $blog->getBlogRequestGenerator();
 554                  $link = $url->resourceMediumSizePreviewLink( $this );
 555              }
 556              
 557              return( $link );            
 558          }        
 559      }
 560  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics