[pLog-svn] r2615 - in plog/trunk: class/gallery/dao class/gallery/resizers locale templates/admin

oscar at devel.lifetype.net oscar at devel.lifetype.net
Tue Nov 22 17:39:25 GMT 2005


Author: oscar
Date: 2005-11-22 17:39:25 +0000 (Tue, 22 Nov 2005)
New Revision: 2615

Modified:
   plog/trunk/class/gallery/dao/galleryresource.class.php
   plog/trunk/class/gallery/dao/galleryresources.class.php
   plog/trunk/class/gallery/resizers/gallerythumbnailgenerator.class.php
   plog/trunk/locale/locale_en_UK.php
   plog/trunk/templates/admin/globalsettings_resources.template
Log:
Added feature request 336 (http://bugs.lifetype.net/view.php?id=336)

Modified: plog/trunk/class/gallery/dao/galleryresource.class.php
===================================================================
--- plog/trunk/class/gallery/dao/galleryresource.class.php	2005-11-22 17:34:19 UTC (rev 2614)
+++ plog/trunk/class/gallery/dao/galleryresource.class.php	2005-11-22 17:39:25 UTC (rev 2615)
@@ -148,6 +148,17 @@
         {
         	return $this->_metadata;
         }
+		
+		/**
+		 * Set the resource metadata to the given array
+		 *
+		 * @param metadata
+		 * @return Nothing
+		 */
+		function setMetadata( $metadata )
+		{
+			$this->_metadata = $metadata;
+		}
 
 		/**
 		 * @return the flags of the resource object

Modified: plog/trunk/class/gallery/dao/galleryresources.class.php
===================================================================
--- plog/trunk/class/gallery/dao/galleryresources.class.php	2005-11-22 17:34:19 UTC (rev 2614)
+++ plog/trunk/class/gallery/dao/galleryresources.class.php	2005-11-22 17:39:25 UTC (rev 2615)
@@ -188,17 +188,20 @@
         								 $ownerId, 
         	                             CACHE_RESOURCES_USER,
         	                             null,
-										 Array( "date" => "ASC" ),
-        	                             $page,
-        	                             $itemsPerPage );
+										 Array( "date" => "ASC" ));
             if( !$resources )
-            	return Array();            	
+            	return Array();
             	
            	$result = Array();
            	foreach( $resources as $resource ) {
-				if( $this->check( $resource, $ownerId, $albumId, $resourceType ))
+				if( $this->check( $resource, $ownerId, $albumId, $resourceType )) {
 					$result[] = $resource;
+				}
            	}
+			
+			// check if we need to do any paging
+			if( $page > DEFAULT_PAGING_ENABLED && $itemsPerPage > DEFAULT_ITEMS_PER_PAGE )
+				$result = array_slice( $result, $page, $itemsPerPage );
 
             return $result;
         }
@@ -211,6 +214,7 @@
                         $albumId = GALLERY_NO_ALBUM, 
                         $resourceType = GALLERY_RESOURCE_ANY )
         {
+			//print("check: id = ".$resource->getId()." - owner = $ownerId - album = $albumId - resourceType = $resourceType<br/>");
         	if( $ownerId != -1 ) {
         		if( $resource->getOwnerId() != $ownerId )
         			return false;
@@ -223,6 +227,7 @@
            		if( $resource->getResourceType() != $resourceType )
            			return false;
            	}
+			
            	return( true );
         }
 		
@@ -237,7 +242,7 @@
 		 * @see getUserResources
 		 * @return the total number of items
 		 */
-		function getNumUserResources( $ownerId, $albumId = GALLERY_NO_ALBUM, $resourceType = GALLEY_RESOURCE_ANY )
+		function getNumUserResources( $ownerId, $albumId = GALLERY_NO_ALBUM, $resourceType = GALLERY_RESOURCE_ANY )
 		{
 			return( count( $this->getUserResources( $ownerId, $albumId, $resourceType )));
 		}
@@ -318,73 +323,9 @@
 			$this->_cache->removeData( $fileName, CACHE_RESOURCES_BY_NAME );			
 		
 			return $resourceId;	
-		}
-
-		/**
-		 * generates the thumbnail of a file that we have just added.
-		 *
-		 * @param resFile the resource file from which we're trying to generate the
-		 * thubmail.
-		 * @param fileName The name and path of the new thumbnail we're going to create
-		 */
-		function generateResourceThumbnail( $resFile, $resourceId, $ownerId )
-		{
-			// get some configuration settings regarding the size of the
-			// thumbnails, and also the default format for thumbnails
-			$config =& Config::getConfig();
-			$previewHeight = $config->getValue( "thumbnail_height", GALLERY_DEFAULT_THUMBNAIL_HEIGHT );
-			$previewWidth  = $config->getValue( "thumbnail_width", GALLERY_DEFAULT_THUMBNAIL_WIDTH );
-			$previewKeepAspectRatio = $config->getValue( "thumbnails_keep_aspect_ratio" );
-			
-			// get the file extension
-			$fileParts = explode( ".", $resFile );
-			$fileExt = strtolower($fileParts[count($fileParts)-1]);
-			$fileName = $ownerId."-".$resourceId.".".$fileExt;
-			
-			// and start the resizing process
-			$resizer = new GalleryResizer( $resFile );
-			GalleryResourceStorage::checkPreviewsStorageFolder( $ownerId );
-			$outFile = GalleryResourceStorage::getPreviewsFolder( $ownerId ).$fileName;
-			
-			// and finally, we can generate the preview!
-			$result = $resizer->generate( $outFile, $previewWidth, $previewHeight, $previewKeepAspectRatio );
-			
-			return $result;
-		}
+		}	
 		
 		/**
-		 * generates the medium-sized thumbnail of a file that we have just added
-		 *
-		 * @param resFile the resource file from which we're trying to generate the
-		 * thubmail.
-		 * @param fileName The name and path of the new thumbnail we're going to create
-		 */
-		function generateResourceMediumSizeThumbnail( $resFile, $resourceId, $ownerId )
-		{
-			// get some configuration settings regarding the size of the
-			// thumbnails, and also the default format for thumbnails
-			$config =& Config::getConfig();
-			$previewHeight = $config->getValue( "medium_size_thumbnail_height", GALLERY_DEFAULT_MEDIUM_SIZE_THUMBNAIL_HEIGHT );
-			$previewWidth  = $config->getValue( "medium_size_thumbnail_width", GALLERY_DEFAULT_MEDIUM_SIZE_THUMBNAIL_WIDTH );
-			$previewKeepAspectRatio = $config->getValue( "thumbnails_keep_aspect_ratio" );
-			
-			// get the file extension
-			$fileParts = explode( ".", $resFile );
-			$fileExt = strtolower($fileParts[count($fileParts)-1]);
-			$fileName = $ownerId."-".$resourceId.".".$fileExt;
-			
-			// and start the resizing process
-			$resizer = new GalleryResizer( $resFile );
-			GalleryResourceStorage::checkMediumSizePreviewsStorageFolder( $ownerId );
-			$outFile = GalleryResourceStorage::getMediumSizePreviewsFolder( $ownerId ).$fileName;
-			
-			// and finally, we can generate the preview!
-			$result = $resizer->generate( $outFile, $previewWidth, $previewHeight, $previewKeepAspectRatio );
-			
-			return $result;
-		}
-		
-		/**
 		 * @private
 		 * @param fileName
 		 * @param metadata
@@ -499,6 +440,24 @@
             	include_once( PLOG_CLASS_PATH."class/gallery/resizers/gallerythumbnailgenerator.class.php" );            
                 GalleryThumbnailGenerator::generateResourceThumbnail( $resFile, $resourceId, $ownerId );
 				GalleryThumbnailGenerator::generateResourceMediumSizeThumbnail( $resFile, $resourceId, $ownerId );
+				// call this method only if the settings are right
+				include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+				$config =& Config::getConfig();
+				$previewHeight = $config->getValue( "final_size_thumbnail_height", 0 );
+				$previewWidth  = $config->getValue( "final_size_thumbnail_width", 0 );				
+				if( $previewHeight != 0 && $previewWidth != 0 ) {
+					GalleryThumbnailGenerator::generateResourceFinalSizeThumbnail( $resFile, $resourceId, $ownerId );
+					// we have to recalculate the metadata because the image could be different... This is a bit cumbersome
+					// and repeats code. We know, thanks.
+					$getId3 = new GetID3();
+					$metadata = $getId3->analyze( $resFile );
+					getid3_lib::CopyTagsToComments($metadata);            
+					$info = $this->_filterMetadata( $metadata, $resourceType );
+					// and finally update the resource again		
+					$resource = $this->getResource( $resourceId );
+					$resource->setMetadata( $info );			
+					$this->updateResource( $resource );					
+				}
             }
 			
             // return the id of the resource we just added
@@ -608,7 +567,9 @@
             // move the file to disk
 		    include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );            
             $storage = new GalleryResourceStorage();
-            $resFile = $storage->storeFile( $resourceId, $ownerId, $fullFilePath,
+            $resFile = $storage->storeFile( $resourceId, 
+			                                $ownerId, 
+											$fullFilePath,
                                             RESOURCE_STORAGE_STORE_MOVE );
             
             // if the file cannot be read, we will also remove the record from the
@@ -626,9 +587,28 @@
     
             // and finally, we can generate the thumbnail only if the file is an image, of course :)
             if( $resourceType == GALLERY_RESOURCE_IMAGE ) {
-            	include_once( PLOG_CLASS_PATH."class/gallery/resizers/gallerythumbnailgenerator.class.php" );
+            	include_once( PLOG_CLASS_PATH."class/gallery/resizers/gallerythumbnailgenerator.class.php" );            
                 GalleryThumbnailGenerator::generateResourceThumbnail( $resFile, $resourceId, $ownerId );
-            }
+				GalleryThumbnailGenerator::generateResourceMediumSizeThumbnail( $resFile, $resourceId, $ownerId );
+				// call this method only if the settings are right
+				include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+				$config =& Config::getConfig();
+				$previewHeight = $config->getValue( "final_size_thumbnail_height", 0 );
+				$previewWidth  = $config->getValue( "final_size_thumbnail_width", 0 );				
+				if( $previewHeight != 0 && $previewWidth != 0 ) {
+					GalleryThumbnailGenerator::generateResourceFinalSizeThumbnail( $resFile, $resourceId, $ownerId );
+					// we have to recalculate the metadata because the image could be different... This is a bit cumbersome
+					// and repeats code. We know, thanks.
+					$getId3 = new GetID3();
+					$metadata = $getId3->analyze( $resFile );
+					getid3_lib::CopyTagsToComments($metadata);            
+					$info = $this->_filterMetadata( $metadata, $resourceType );
+					// and finally update the resource again	
+					$resource = $this->getResource( $resourceId );
+					$resource->setMetadata( $info );			
+					$this->updateResource( $resource );					
+				}
+			}
             
             // return the id of the resource we just added
             return $resourceId;        

Modified: plog/trunk/class/gallery/resizers/gallerythumbnailgenerator.class.php
===================================================================
--- plog/trunk/class/gallery/resizers/gallerythumbnailgenerator.class.php	2005-11-22 17:34:19 UTC (rev 2614)
+++ plog/trunk/class/gallery/resizers/gallerythumbnailgenerator.class.php	2005-11-22 17:39:25 UTC (rev 2615)
@@ -1,7 +1,5 @@
-<?php
-
+<?php	
 	
-	
 	class GalleryThumbnailGenerator 
 	{
 	
@@ -75,6 +73,44 @@
 			$result = $resizer->generate( $outFile, $previewWidth, $previewHeight, $previewKeepAspectRatio );
 			
 			return $result;
-		}		
+		}
+		
+		/**
+		 * generates the final version of an image
+		 *
+		 * @param resFile the resource file from which we're trying to generate the
+		 * thubmail.
+		 * @param fileName The name and path of the new thumbnail we're going to create
+		 * @static
+		 */
+		function generateResourceFinalSizeThumbnail( $resFile, $resourceId, $ownerId )
+		{
+			// get some configuration settings regarding the size of the
+			// thumbnails, and also the default format for thumbnails
+			include_once( PLOG_CLASS_PATH."class/config/config.class.php" );			
+			$config =& Config::getConfig();
+			$previewHeight = $config->getValue( "final_size_thumbnail_height", 0 );
+			$previewWidth  = $config->getValue( "final_size_thumbnail_width", 0 );
+			$previewKeepAspectRatio = $config->getValue( "thumbnails_keep_aspect_ratio" );
+			
+			// get the file extension
+			$fileParts = explode( ".", $resFile );
+			$fileExt = strtolower($fileParts[count($fileParts)-1]);
+			$fileName = $ownerId."-".$resourceId.".".$fileExt;
+			
+			print("final size = $previewHeight x $previewWidth - file = $fileName<br/>");
+			
+			// and start the resizing process
+		    include_once( PLOG_CLASS_PATH."class/gallery/resizers/galleryresizer.class.php" );			
+			$resizer = new GalleryResizer( $resFile );
+		    include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );			
+			GalleryResourceStorage::checkUserStorageFolder( $ownerId );
+			$outFile = GalleryResourceStorage::getUserFolder( $ownerId ).$fileName;
+			
+			// and finally, we can generate the preview!
+			$result = $resizer->generate( $outFile, $previewWidth, $previewHeight, $previewKeepAspectRatio );
+			
+			return $result;
+		}				
 	}
 ?>
\ No newline at end of file

Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php	2005-11-22 17:34:19 UTC (rev 2614)
+++ plog/trunk/locale/locale_en_UK.php	2005-11-22 17:39:25 UTC (rev 2615)
@@ -956,6 +956,8 @@
 
 $messages['help_page_suffix_format'] = 'Suffix that will be appended to URLs that support paging';
 
+$messages['help_final_size_thumbnail_width'] = 'Final width of uploaded images. Leave empty or as zero to store the full size image';
+$messages['help_final_size_thumbnail_height'] = 'Final height of uploaded images. Leave empty or as zero to store the full size image';
 $messages['error_comment_too_big'] = 'The comment is too big';
 $messages['error_you_have_been_blocked'] = 'Blocked: this request was not completed.';
 $messages['created'] = 'Created';

Modified: plog/trunk/templates/admin/globalsettings_resources.template
===================================================================
--- plog/trunk/templates/admin/globalsettings_resources.template	2005-11-22 17:34:19 UTC (rev 2614)
+++ plog/trunk/templates/admin/globalsettings_resources.template	2005-11-22 17:39:25 UTC (rev 2615)
@@ -51,18 +51,30 @@
     <div class="formHelp">{$locale->tr("help_thumbnail_width")}</div>	
     <input style="width:100%" type="text" name="config[thumbnail_width]" value="{$thumbnail_width}"/>
    </div>
+   <!-- medium_size_thumbnail_width -->
+   <div class="field">
+    <label for="config[medium_size_thumbnail_width]">medium_size_thumbnail_width</label>
+    <div class="formHelp">{$locale->tr("help_medium_size_thumbnail_width")}</div>	
+    <input style="width:100%" type="text" name="config[medium_size_thumbnail_width]" value="{$medium_size_thumbnail_width}"/>
+   </div>
    <!-- medium_size_thumbnail_height -->
    <div class="field">
     <label for="config[medium_size_thumbnail_height]">medium_size_thumbnail_height</label>
     <div class="formHelp">{$locale->tr("help_medium_size_thumbnail_height")}</div>	
     <input style="width:100%" type="text" name="config[medium_size_thumbnail_height]" value="{$medium_size_thumbnail_height}"/>
-   </div>
-   <!-- medium_size_thumbnail_width -->
+   </div>   
+   <!-- final_size_thumbnail_width -->
    <div class="field">
-    <label for="config[medium_size_thumbnail_width]">medium_size_thumbnail_width</label>
-    <div class="formHelp">{$locale->tr("help_medium_size_thumbnail_width")}</div>	
-    <input style="width:100%" type="text" name="config[medium_size_thumbnail_width]" value="{$medium_size_thumbnail_width}"/>
+    <label for="config[final_size_thumbnail_width]">final_size_thumbnail_width</label>
+    <div class="formHelp">{$locale->tr("help_final_size_thumbnail_width")}</div>	
+    <input style="width:100%" type="text" name="config[final_size_thumbnail_width]" value="{$final_size_thumbnail_width}"/>
    </div>   
+   <!-- final_size_thumbnail_height -->
+   <div class="field">
+    <label for="config[final_size_thumbnail_height]">final_size_thumbnail_height</label>
+    <div class="formHelp">{$locale->tr("help_final_size_thumbnail_height")}</div>	
+    <input style="width:100%" type="text" name="config[final_size_thumbnail_height]" value="{$final_size_thumbnail_height}"/>
+   </div>   
    <!-- thumbnails_keep_aspect_ratio -->
    <div class="field">
     <label for="config[thumbnails_keep_aspect_ratio]">thumbnails_keep_aspect_ratio</label>




More information about the pLog-svn mailing list