[pLog-svn] r2431 - plog/branches/plog-1.0.2/class/gallery/dao
Oscar Renalias
oscar at renalias.net
Tue Aug 30 22:03:24 GMT 2005
Nick, could you please test this and let me know? I'd like to hear
your comments about it...
Oscar
On 31 Aug 2005, at 00:32, oscar at devel.plogworld.net wrote:
> Author: oscar
> Date: 2005-08-30 21:32:15 +0000 (Tue, 30 Aug 2005)
> New Revision: 2431
>
> Modified:
> plog/branches/plog-1.0.2/class/gallery/dao/
> galleryresources.class.php
> Log:
> This is a merge of nick's work in mantis issue 650 (http://
> bugs.plogworld.net/view.php?id=650) with some of my own
> discoveries... Turns out that php has problems unserializing
> certain arrays (the output of getid3 is serialized into a database
> field, and later on unserialized whenever needed) and that caused
> WMA and ASF files not to display any information but more
> importantly, this solves the long-standing bug where images with
> EXIF tags could not be displayed. I would have never thought that
> these two issues could be related, but removing certain fields
> which are part of the EXIF tags automatically made all images
> display just fine... (in my opinion, this is a bug in php because
> unserialization errors shouldn't affect the rest of the script!)
>
> I tried with an image taken with my girlfriend's Canon EOS 300D at
> 6mpx, full of EXIF metadata. Before the fix, it was not working.
> After the fix, it worked like a charm but I would appreciate it if
> somebody tested this a bit more (try first with a 1.0.1 version and
> then try with this new version)
>
> Now GalleryResources::_filterMetadata takes care of extracting only
> the information that we really need from the metadata extracted by
> getid3, which is not so much anymore. As as side effect, the medata
> field from the plog_gallery_resources table won't grow too big
> anymore!
>
> Modified: plog/branches/plog-1.0.2/class/gallery/dao/
> galleryresources.class.php
> ===================================================================
> --- plog/branches/plog-1.0.2/class/gallery/dao/
> galleryresources.class.php 2005-08-30 19:09:04 UTC (rev 2430)
> +++ plog/branches/plog-1.0.2/class/gallery/dao/
> galleryresources.class.php 2005-08-30 21:32:15 UTC (rev 2431)
> @@ -63,7 +63,7 @@
> "mpg" => GALLERY_RESOURCE_VIDEO,
> "mpeg" => GALLERY_RESOURCE_VIDEO,
> "wmv" => GALLERY_RESOURCE_VIDEO,
> - "asf" => GALLERY_RESOURCE_VIDEO,
> + //"asf" => GALLERY_RESOURCE_VIDEO,
> "mov" => GALLERY_RESOURCE_VIDEO,
> "divx" => GALLERY_RESOURCE_VIDEO,
> "rm" => GALLERY_RESOURCE_VIDEO,
> @@ -276,23 +276,6 @@
> }
>
> /**
> - * @private
> - * finds out the right resource type for a given file upload
> - */
> - function getResourceType( $fileName )
> - {
> - // get the resource type
> - $fileParts = explode( ".", $fileName );
> - $fileExt = strtolower($fileParts[count($fileParts)-1]);
> - if( array_key_exists( $fileExt, $this-
> >_extensionToType ))
> - $resourceType = $this->_extensionToType[ $fileExt ];
> - else
> - $resourceType = GALLERY_RESOURCE_UNKNOWN;
> -
> - return $resourceType;
> - }
> -
> - /**
> * Adds a row related to a resource to the database. You
> should usually use
> * GalleryResources::addResource() or
> GalleryResources::addResourceFromDisk(), which are more
> * suitable and will do most of the job for you.
> @@ -417,7 +400,36 @@
> $result = $resizer->generate( $outFile, $previewWidth,
> $previewHeight, $previewKeepAspectRatio );
>
> return $result;
> - }
> + }
> +
> + /**
> + * @private
> + * @param fileName
> + * @param metadata
> + */
> + function _getResourceType( $fileName, &$metadata )
> + {
> + // find out the right resource type based on the
> extension
> + // get the resource type
> + $fileParts = explode( ".", $fileName );
> + $fileExt = strtolower($fileParts[count($fileParts)-1]);
> +
> + //asf need special working
> + if ("asf" == $fileExt ){
> + if (!($metadata["audio"]["codec"]))
> + $resourceType = GALLERY_RESOURCE_SOUND;
> + else
> + $resourceType = GALLERY_RESOURCE_VIDEO;
> + }
> + else {
> + if( array_key_exists( $fileExt, $this-
> >_extensionToType ))
> + $resourceType = $this->_extensionToType
> [ $fileExt ];
> + else
> + $resourceType = GALLERY_RESOURCE_UNKNOWN;
> + }
> +
> + return( $resourceType );
> + }
>
> /**
> * adds a resource to the database. This method requires a
> FileUpload parameter and it
> @@ -462,18 +474,21 @@
> // get the metadata
> $getId3 = new GetID3();
> $metadata = $getId3->analyze( $upload->getTmpName());
> -
> - // find out the right resource type based on the
> extension
> - $resourceType = $this->getResourceType( $upload-
> >getFileName());
> -
> + // nifty helper method from the getid3 package
> + getid3_lib::CopyTagsToComments($metadata);
> +
> + $resourceType = $this->_getResourceType( $upload-
> >getFileName(), $metadata );
> +
> // set the flags
> $flags = 0;
> if( $resourceType == GALLERY_RESOURCE_IMAGE )
> $flags = $flags|GALLERY_RESOURCE_PREVIEW_AVAILABLE;
> -
> +
> + $info = $this->_filterMetadata( $metadata,
> $resourceType );
> +
> // add the record to the database
> $fileName = $upload->getFileName();
> - $resourceId = $this->addResourceToDatabase( $ownerId,
> $albumId, $description, $flags, $resourceType, $filePath,
> $fileName, $metadata );
> + $resourceId = $this->addResourceToDatabase( $ownerId,
> $albumId, $description, $flags, $resourceType, $filePath,
> $fileName, $info );
> if( !$resourceId )
> return false;
>
> @@ -504,6 +519,46 @@
> }
>
> /**
> + * @private
> + * Returns an array with only those bits of metadata as
> generate by getid3 that
> + * we'd like to keep, instead of one huge array
> + *
> + * @param metadata
> + * @param resourceType
> + */
> + function _filterMetadata( &$metadata, $resourceType )
> + {
> + $info = Array();
> + $info["md5_file"] = $metadata["md5_file"];
> + $info["md5_data"] = $metadata["md5_data"];
> + $info["filesize"]= $metadata["filesize"];
> + $info["fileformat"] = $metadata["fileformat"];
> + $info["comments"] = $metadata["comments"];
> +
> + if($resourceType == GALLERY_RESOURCE_IMAGE){
> + $info["video"] = $metadata["video"];
> + $info["jpg"]["exif"]["FILE"] = $metadata["jpg"]
> ["exif"]["FILE"];
> + $info["jpg"]["exif"]["COMPUTED"] = $metadata["jpg"]
> ["exif"]["COMPUTED"];
> + $info["jpg"]["exif"]["IFD0"] = $metadata["jpg"]
> ["exif"]["IFD0"];
> + $metadata["jpg"]["exif"]["EXIF"]["MakerNote"] = "";
> + $info["jpg"]["exif"]["EXIF"] = $metadata["jpg"]
> ["exif"]["EXIF"];
> + }
> + else if($resourceType == GALLERY_RESOURCE_SOUND){
> + $info["audio"] = $metadata["audio"];
> + $info["playtime_string"] = $metadata
> ["playtime_string"];
> + $info["playtime_seconds"] = $metadata
> ["playtime_seconds"];
> + }
> + else if($resourceType == GALLERY_RESOURCE_VIDEO){
> + $info["video"] = $metadata["video"];
> + $info["audio"] = $metadata["audio"];
> + $info["playtime_seconds"] = $metadata
> ["playtime_seconds"];
> + $info["playtime_string"] = $metadata
> ["playtime_string"];
> + }
> +
> + return( $info );
> + }
> +
> + /**
> * adds a resource to the gallery when the resource is
> already stored on disk, instead of
> * it coming from an upload as it usually happens. This
> method is better than
> * GalleryResources::addResource() when instead of dealing
> with uploaded files, the file
> @@ -536,10 +591,12 @@
> // get the metadata
> $getId3 = new GetID3();
> $metadata = $getId3->analyze( $fullFilePath );
> + // nifty helper method from the getid3 package
> + getid3_lib::CopyTagsToComments($metadata);
>
> - // find out the right resource type based on the
> extension
> - $resourceType = $this->getResourceType( $fileName );
> -
> + $resourceType = $this->_getResourceType
> ( $fullFilePath, $metadata );
> + $info = $this->_filterMetadata( $metadata,
> $resourceType );
> +
> // set the flags
> $flags = 0;
> if( $resourceType == GALLERY_RESOURCE_IMAGE )
> @@ -735,6 +792,7 @@
> // to which album this resource belongs
> $album = $this->albums->getAlbum( $row["album_id"],
> $row["owner_id"], false );
> $res->setAlbum( $album );
> + // print_r(unserialize($row["metadata"]));
>
> return $res;
> }
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.plogworld.net
> http://devel.plogworld.net/mailman/listinfo/plog-svn
>
>
More information about the pLog-svn
mailing list