From 594a5cdffcdc9e6fae79938f97a8d7cc4c5fd265 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Thu, 30 Dec 2010 12:23:34 -0500 Subject: [PATCH] Start cleaning up the "prettythumb" vs "thumb" stuff in Ansel. Now that styles have been refactored, we no longer need to differentiate between a thumb and prettythumb thumbnail type, the style information does that for us. Simplifies the calls to all methods needing an image type as well as allows us to get rid of the extra prettythumb.php image generation script. Now, supported image types are "full", "screen", "thumb", and "mini". The style object specifies what image generator to use, if supported. --- ansel/img/prettythumb.php | 46 -------------------------------- ansel/img/thumb.php | 22 ++++++++++----- ansel/lib/Ansel.php | 35 +++++++++--------------- ansel/lib/Block/random_photo.php | 2 +- ansel/lib/Gallery.php | 2 +- ansel/lib/Image.php | 19 ++++++++++--- ansel/lib/Tile/DateGallery.php | 2 +- ansel/lib/Tile/Gallery.php | 2 +- ansel/lib/Tile/Image.php | 2 +- ansel/lib/View/EmbeddedRenderer/Mini.php | 2 +- ansel/lib/View/GalleryProperties.php | 2 +- ansel/preview.php | 2 +- 12 files changed, 51 insertions(+), 87 deletions(-) delete mode 100644 ansel/img/prettythumb.php diff --git a/ansel/img/prettythumb.php b/ansel/img/prettythumb.php deleted file mode 100644 index 31559c0be..000000000 --- a/ansel/img/prettythumb.php +++ /dev/null @@ -1,46 +0,0 @@ - - */ - -require_once dirname(__FILE__) . '/../lib/Application.php'; -Horde_Registry::appInit('ansel'); - -$thumbstyle = Horde_Util::getFormData('t'); -$background = Horde_Util::getFormData('b'); - -// Create a dummy style object with only what is needed to generate -if ($thumbstyle && $background) { - $style = new Ansel_Style(array('thumbstyle' => $thumbstyle, - 'background' => $background)); -} else { - $style = null; -} -$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage(Horde_Util::getFormData('image')); -$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery(abs($image->gallery)); -if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ)) { - throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo.")); -} - -/* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */ -if ($conf['vfs']['src'] == 'sendfile') { - /* Need to ensure the file exists */ - try { - $image->createView('prettythumb', $style); - } catch (Horde_Exception $e) { - Horde::logMessage($e, 'ERR'); - exit; - } - $filename = $injector->getInstance('Horde_Core_Factory_Vfs')->create('images')->readFile($image->getVFSPath('prettythumb', $style), $image->getVFSName('prettythumb')); - header('Content-Type: ' . $image->getType('prettythumb')); - header('X-LIGHTTPD-send-file: ' . $filename); - header('X-Sendfile: ' . $filename); - exit; -} - -$image->display('prettythumb', $style); diff --git a/ansel/img/thumb.php b/ansel/img/thumb.php index 4da9b0f68..2b81c8de1 100644 --- a/ansel/img/thumb.php +++ b/ansel/img/thumb.php @@ -1,16 +1,26 @@ + * @author Michael J. Rubinsky */ require_once dirname(__FILE__) . '/../lib/Application.php'; Horde_Registry::appInit('ansel'); +$thumbstyle = Horde_Util::getFormData('t'); +$background = Horde_Util::getFormData('b'); + +// Create a dummy style object with only what is needed to generate +if ($thumbstyle && $background) { + $style = new Ansel_Style(array('thumbstyle' => $thumbstyle, + 'background' => $background)); +} else { + $style = null; +} $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage(Horde_Util::getFormData('image')); $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery(abs($image->gallery)); if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ)) { @@ -21,16 +31,16 @@ if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ)) { if ($conf['vfs']['src'] == 'sendfile') { /* Need to ensure the file exists */ try { - $image->createView('thumb', Ansel::getStyleDefinition('ansel_default')); + $image->createView('thumb', $style); } catch (Horde_Exception $e) { - Horde::logMessage($result, 'ERR'); + Horde::logMessage($e, 'ERR'); exit; } - $filename = $injector->getInstance('Horde_Core_Factory_Vfs')->create('images')->readFile($image->getVFSPath('thumb'), $image->getVFSName('thumb')); + $filename = $injector->getInstance('Horde_Core_Factory_Vfs')->create('images')->readFile($image->getVFSPath('thumb', $style), $image->getVFSName('thumb')); header('Content-Type: ' . $image->getType('thumb')); header('X-LIGHTTPD-send-file: ' . $filename); header('X-Sendfile: ' . $filename); exit; } -$image->display('thumb'); +$image->display('thumb', $style); diff --git a/ansel/lib/Ansel.php b/ansel/lib/Ansel.php index 50accaf22..355a1432c 100644 --- a/ansel/lib/Ansel.php +++ b/ansel/lib/Ansel.php @@ -352,8 +352,8 @@ class Ansel * factors. * * @param string $imageId The id of the image. - * @param string $view The view ('screen', 'thumb', 'prettythumb' or - * 'full') to show. + * @param string $view The view ('screen', 'thumb', 'full', 'mini') + * to show. * @param boolean $full Return a path that includes the server name? * @param Ansel_Style $style Use this gallery style * @@ -366,16 +366,16 @@ class Ansel // To avoid having to add a new img/* file everytime we add a new // thumbstyle, we check for the 'non-prettythumb' views, then route the // rest through prettythumb, passing it the style. - switch ($view) { - case 'screen': - case 'full': - case 'thumb': - case 'mini': - // Do nothing. - break; - default: - $view = 'prettythumb'; - } +// switch ($view) { +// case 'screen': +// case 'full': +// case 'thumb': +// case 'mini': +// // Do nothing. +// break; +// default: +// $view = 'prettythumb'; +// } if (empty($imageId)) { return Horde::url((string)Ansel::getErrorImage($view), $full); @@ -651,17 +651,6 @@ class Ansel { $styles = $GLOBALS['injector']->getInstance('Ansel_Styles'); - // @TODO: Look at this code: probably duplicated in the binder above. - /* No prettythumbs allowed at all by admin choice */ - if (empty($GLOBALS['conf']['image']['prettythumbs'])) { - $test = $styles; - foreach ($test as $key => $style) { - if ($style['thumbstyle'] != 'thumb') { - unset($styles[$key]); - } - } - } - /* Build the available styles, but don't show hidden styles */ foreach ($styles as $key => $style) { if (empty($style['hide'])) { diff --git a/ansel/lib/Block/random_photo.php b/ansel/lib/Block/random_photo.php index 289a1011a..ab223dd31 100644 --- a/ansel/lib/Block/random_photo.php +++ b/ansel/lib/Block/random_photo.php @@ -59,7 +59,7 @@ class Horde_Block_ansel_random_photo extends Horde_Block 'view' => 'Image'), true); if ($gallery->isOldEnough() && !$gallery->hasPasswd()) { - $img = '[random photo]'; + $img = '[random photo]'; } else { $img = Horde::img('thumb-error.png'); } diff --git a/ansel/lib/Gallery.php b/ansel/lib/Gallery.php index 51c3ed3ee..001e4a38e 100644 --- a/ansel/lib/Gallery.php +++ b/ansel/lib/Gallery.php @@ -751,7 +751,7 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical implements Seria /** * Return a hash key for the given view and style. * - * @param string $view The view (thumb, prettythumb etc...) + * @param string $view The view (thumb, etc...) * @param Ansel_Style $style The style. * * @return string A md5 hash suitable for use as a key. diff --git a/ansel/lib/Image.php b/ansel/lib/Image.php index ae1433b83..c20810cf8 100644 --- a/ansel/lib/Image.php +++ b/ansel/lib/Image.php @@ -368,6 +368,11 @@ class Ansel_Image Implements Iterator $this->_image->setType('jpeg'); } + /* Default to the gallery's style */ + if (empty($style)) { + $style = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($this->gallery)->getStyle(); + } + /* Get the VFS info. */ $vfspath = $this->getVFSPath($view, $style); if ($GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->exists($vfspath, $this->getVFSName($view))) { @@ -382,10 +387,10 @@ class Ansel_Image Implements Iterator $vHash = $this->getViewHash($view, $style); $this->_image->loadString($data); - if ($view == 'prettythumb') { + if ($view == 'thumb') { $viewType = $style->thumbstyle; } else { - // Screen, Mini, Thumb + // Screen, Mini $viewType = ucfirst($view); } @@ -394,7 +399,8 @@ class Ansel_Image Implements Iterator } catch (Ansel_Exception $e) { // It could be we don't support the requested effect, try // ansel_default before giving up. - if ($view == 'prettythumb') { + //if ($view == 'prettythumb') { + if ($view == 'thumb' && $viewType != 'Thumb') { $iview = Ansel_ImageGenerator::factory('Thumb', array('image' => $this, 'style' => Ansel::getStyleDefinition('ansel_default'))); } else { // If it wasn't a prettythumb, then something else must be wrong @@ -1169,7 +1175,7 @@ class Ansel_Image Implements Iterator public function getViewHash($view, $style = null) { // These views do not care about style...just return the $view value. - if ($view == 'screen' || $view == 'thumb' || $view == 'mini' || $view == 'full') { + if ($view == 'screen' || $view == 'mini' || $view == 'full') { return $view; } @@ -1177,6 +1183,11 @@ class Ansel_Image Implements Iterator $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery(abs($this->gallery)); $style = $gallery->getStyle(); } + + if ($view == 'thumb' && $style->thumbstyle == 'Thumb') { + return $view; + } + $view = md5($style->thumbstyle . '.' . $style->background); return $view; diff --git a/ansel/lib/Tile/DateGallery.php b/ansel/lib/Tile/DateGallery.php index be60f1d12..6caaf5f27 100644 --- a/ansel/lib/Tile/DateGallery.php +++ b/ansel/lib/Tile/DateGallery.php @@ -71,7 +71,7 @@ class Ansel_Tile_DateGallery $style = $dgallery->getStyle(); } - $thumbstyle = $mini ? 'mini' : $style->thumbstyle; + $thumbstyle = $mini ? 'mini' : 'thumb'; $gallery_image = Ansel::getImageUrl( $dgallery->getKeyImage(), $thumbstyle, diff --git a/ansel/lib/Tile/Gallery.php b/ansel/lib/Tile/Gallery.php index 333d4f17b..4922eb080 100644 --- a/ansel/lib/Tile/Gallery.php +++ b/ansel/lib/Tile/Gallery.php @@ -46,7 +46,7 @@ class Ansel_Tile_Gallery if (is_null($style)) { $style = $gallery->getStyle(); } - $thumbstyle = $mini ? 'mini' : $style->thumbstyle; + $thumbstyle = $mini ? 'mini' : 'thumb'; if ($gallery->hasPasswd()) { $gallery_image = Horde::img('gallery-locked.png'); } else { diff --git a/ansel/lib/Tile/Image.php b/ansel/lib/Tile/Image.php index ad0241572..a76126be7 100644 --- a/ansel/lib/Tile/Image.php +++ b/ansel/lib/Tile/Image.php @@ -43,7 +43,7 @@ class Ansel_Tile_Image } /* Override the thumbnail to mini or use style default? */ - $thumbstyle = $mini ? 'mini' : $style->thumbstyle; + $thumbstyle = $mini ? 'mini' : 'thumb'; /* URL for image properties/actions etc... */ $image_url = Horde::url('image.php')->add( diff --git a/ansel/lib/View/EmbeddedRenderer/Mini.php b/ansel/lib/View/EmbeddedRenderer/Mini.php index 4f9b1f777..14c464c25 100644 --- a/ansel/lib/View/EmbeddedRenderer/Mini.php +++ b/ansel/lib/View/EmbeddedRenderer/Mini.php @@ -35,7 +35,7 @@ class Ansel_View_EmbeddedRenderer_Mini extends Ansel_View_Gallery $thumbsize = (!empty($this->_params['thumbsize'])) ? $this->_params['thumbsize'] : 'mini'; // Limit to these image views only. if ($thumbsize != 'mini' && $thumbsize != 'thumb' && - $thumbsize != 'prettythumb' && $thumbsize != 'screen') { + $thumbsize != 'screen') { $thumbsize = 'mini'; } diff --git a/ansel/lib/View/GalleryProperties.php b/ansel/lib/View/GalleryProperties.php index a00d57fe3..d2a3d0020 100644 --- a/ansel/lib/View/GalleryProperties.php +++ b/ansel/lib/View/GalleryProperties.php @@ -369,7 +369,7 @@ class Ansel_View_GalleryProperties // Make sure that the style hash is recorded, ignoring non-styled thumbs if ($style->thumbstyle != 'Thumb') { - $GLOBALS['injector']->getInstance('Ansel_Storage')->ensureHash($gallery->getViewHash('prettythumb')); + $GLOBALS['injector']->getInstance('Ansel_Storage')->ensureHash($gallery->getViewHash('thumb')); } // Clear the OtherGalleries widget cache diff --git a/ansel/preview.php b/ansel/preview.php index 4b9e41cae..c68fc5357 100644 --- a/ansel/preview.php +++ b/ansel/preview.php @@ -15,7 +15,7 @@ $imageId = Horde_Util::getFormData('image'); try { $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($imageId); $gal = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery(abs($image->gallery)); - $img = Ansel::getImageUrl($imageId, 'thumb', false); + $img = Ansel::getImageUrl($imageId, 'thumb', false, Ansel::getStyleDefinition('ansel_default')); } catch (Ansel_Exception $e) { Horde::logMessage($e->getMessage(), 'ERR'); exit; -- 2.11.0