Start cleaning up the "prettythumb" vs "thumb" stuff in Ansel.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 30 Dec 2010 17:23:34 +0000 (12:23 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 30 Dec 2010 19:40:57 +0000 (14:40 -0500)
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.

12 files changed:
ansel/img/prettythumb.php [deleted file]
ansel/img/thumb.php
ansel/lib/Ansel.php
ansel/lib/Block/random_photo.php
ansel/lib/Gallery.php
ansel/lib/Image.php
ansel/lib/Tile/DateGallery.php
ansel/lib/Tile/Gallery.php
ansel/lib/Tile/Image.php
ansel/lib/View/EmbeddedRenderer/Mini.php
ansel/lib/View/GalleryProperties.php
ansel/preview.php

diff --git a/ansel/img/prettythumb.php b/ansel/img/prettythumb.php
deleted file mode 100644 (file)
index 31559c0..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/**
- * Copyright 2007-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- */
-
-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);
index 4da9b0f..2b81c8d 100644 (file)
@@ -1,16 +1,26 @@
 <?php
 /**
- * Copyright 2003-2010 The Horde Project (http://www.horde.org/)
+ * Copyright 2007-2010 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (GPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  *
- * @author Chuck Hagenbuch <chuck@horde.org>
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
  */
 
 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);
index 50accaf..355a143 100644 (file)
@@ -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'])) {
index 289a101..ab223dd 100644 (file)
@@ -59,7 +59,7 @@ class Horde_Block_ansel_random_photo extends Horde_Block
                                                   'view' => 'Image'), true);
 
         if ($gallery->isOldEnough() && !$gallery->hasPasswd()) {
-            $img = '<img src="' . Ansel::getImageUrl($imageId, 'thumb', true) . '" alt="[random photo]" />';
+            $img = '<img src="' . Ansel::getImageUrl($imageId, 'thumb', true, Ansel::getStyleDefinition('ansel_default')) . '" alt="[random photo]" />';
         } else {
             $img = Horde::img('thumb-error.png');
         }
index 51c3ed3..001e4a3 100644 (file)
@@ -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.
index ae1433b..c20810c 100644 (file)
@@ -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;
index be60f1d..6caaf5f 100644 (file)
@@ -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,
index 333d4f1..4922eb0 100644 (file)
@@ -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 {
index ad02415..a76126b 100644 (file)
@@ -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(
index 4f9b1f7..14c464c 100644 (file)
@@ -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';
         }
index a00d57f..d2a3d00 100644 (file)
@@ -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
index 4b9e41c..c68fc53 100644 (file)
@@ -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;