H4 naming conventions
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 17 Feb 2010 00:40:06 +0000 (19:40 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 17 Feb 2010 00:59:39 +0000 (19:59 -0500)
13 files changed:
ansel/config/styles.php.dist
ansel/lib/Exception.php [new file with mode: 0644]
ansel/lib/Gallery.php
ansel/lib/ImageView.php
ansel/lib/ImageView/Mini.php [new file with mode: 0755]
ansel/lib/ImageView/PlainStack.php [new file with mode: 0644]
ansel/lib/ImageView/PolaroidStack.php.php [new file with mode: 0644]
ansel/lib/ImageView/PolaroidThumb.php [new file with mode: 0644]
ansel/lib/ImageView/PrettyThumb.php [new file with mode: 0644]
ansel/lib/ImageView/RoundedStack.php [new file with mode: 0644]
ansel/lib/ImageView/Screen.php [new file with mode: 0755]
ansel/lib/ImageView/ShadowSharpThumb.php [new file with mode: 0644]
ansel/lib/ImageView/Thumb.php [new file with mode: 0755]

index c239bdc..e3ee067 100644 (file)
@@ -57,7 +57,7 @@ $widgets = array('Actions' => array(),
 $styles['ansel_default'] = array(
     'name' => 'ansel_default',
     'title' => _("Default"),
-    'thumbstyle' => 'thumb',
+    'thumbstyle' => 'Thumb',
     'background' => 'none',
     'widgets' => $widgets,
 );
@@ -65,7 +65,7 @@ $styles['ansel_default'] = array(
 $styles['ansel_prettythumbs'] = array(
     'name' => 'ansel_prettythumbs',
     'title' => _("Pretty Thumbnails (No Background)"),
-    'thumbstyle' => 'prettythumb',
+    'thumbstyle' => 'PrettyThumb',
     'requires_png' => true,
     // This really only looks good with ImageMagick, not GD.
     'default_galleryimage_type' => 'roundedstack',
@@ -77,7 +77,7 @@ $styles['ansel_blackonwhite'] = array(
     'name' => 'ansel_blackonwhite',
     'title' => _("Pretty Thumbnails (White Background)"),
     'default_galleryimage_type' => 'roundedstack',
-    'thumbstyle' => 'prettythumb',
+    'thumbstyle' => 'PrettyThumb',
     'background' => 'white',
     'widgets' => $widgets,
 );
@@ -85,7 +85,7 @@ $styles['ansel_blackonwhite'] = array(
 $styles['ansel_sharpshadowed'] = array(
     'name' => 'ansel_sharpshadowed',
     'title' => _("Shadowed Thumbnails (White Background)"),
-    'thumbstyle' => 'shadowsharpthumb',
+    'thumbstyle' => 'ShadowSharpThumb',
     'background' => 'white',
     'default_galleryimage_type' => 'plainstack',
     'widgets' => $widgets
@@ -95,7 +95,7 @@ $styles['ansel_sharpshadowed'] = array(
 $styles['ansel_polaroid'] = array(
     'name' => 'ansel_polaroid',
     'title' => _("Polaroid Style Thumbnails (White Background)"),
-    'thumbstyle' => 'polaroidthumb',
+    'thumbstyle' => 'PolaroidThumb',
     'background' => 'white',
     'default_galleryimage_type' => 'polaroidstack',
     'widgets' => $widgets,
@@ -105,7 +105,7 @@ $styles['ansel_polaroid'] = array(
 $styles['ansel_lightbox'] = array(
     'name' => 'ansel_lightbox',
     'title' => _("A Lightbox Inspired Style (White Background)"),
-    'thumbstyle' => 'thumb',
+    'thumbstyle' => 'Thumb',
     'background' => 'white',
     'gallery_view' => 'GalleryLightbox',
     'widgets' => $widgets,
@@ -117,7 +117,7 @@ $styles['ansel_lightbox'] = array(
 $styles['ansel_lightbox_png'] = array(
     'name' => 'ansel_lightbox_png',
     'title' => _("A Lightbox Inspired Style (No Background)"),
-    'thumbstyle' => 'thumb',
+    'thumbstyle' => 'Thumb',
     'background' => 'none',
     'requires_png' => true,
     'gallery_view' => 'GalleryLightbox',
@@ -129,7 +129,7 @@ $styles['ansel_lightbox_png'] = array(
 $styles['ansel_lightbox_shadowed_png'] = array(
     'name' => 'ansel_lightbox_shadowed_png',
     'title' => _("A Lightbox Inspired Style (Drop Shadows, No Background)"),
-    'thumbstyle' => 'shadowsharpthumb',
+    'thumbstyle' => 'ShadowSharpThumb',
     'background' => 'none',
     'requires_png' => true,
     'gallery_view' => 'GalleryLightbox',
@@ -143,7 +143,7 @@ $styles['ansel_lightbox_shadowed_png'] = array(
 $styles['ansel_lightbox_polaroid'] = array(
     'name' => 'ansel_lightbox_polaroid',
     'title' => _("Lightbox with Polaroids (No Background)"),
-    'thumbstyle' => 'polaroidthumb',
+    'thumbstyle' => 'PolaroidThumb',
     'background' => 'none',
     'requires_png' => true,
     'default_galleryimage_type' => 'polaroidstack',
@@ -159,7 +159,7 @@ $styles['ansel_lightbox_polaroid'] = array(
 $styles['ansel_simple'] = array(
     'name' => 'ansel_simple',
     'title' => _("Simple"),
-    'thumbstyle' => 'thumb',
+    'thumbstyle' => 'Thumb',
     'background' => 'none',
     'hide' => true,
 );
@@ -168,7 +168,7 @@ $styles['ansel_simple'] = array(
 $styles['ansel_lightbox_simple'] = array(
     'name' => 'ansel_lightbox_simple',
     'title' => _("Simple Lightbox"),
-    'thumbstyle' => 'thumb',
+    'thumbstyle' => 'Thumb',
     'background' => 'none',
     'requires_png' => true,
     'gallery_view' => 'GalleryLightbox',
@@ -180,7 +180,7 @@ $styles['ansel_lightbox_simple'] = array(
 $styles['ansel_lightbox_simple_polaroid'] = array(
     'name' => 'ansel_lightbox_polaroid',
     'title' => _("Lightbox with Polaroids (No Background)"),
-    'thumbstyle' => 'polaroidthumb',
+    'thumbstyle' => 'PolaroidThumb',
     'background' => 'none',
     'requires_png' => true,
     'default_galleryimage_type' => 'polaroidstack',
diff --git a/ansel/lib/Exception.php b/ansel/lib/Exception.php
new file mode 100644 (file)
index 0000000..8fb0514
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Base exception class for Ansel.
+ *
+ * Copyright 2009-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>
+ * @package Ansel
+ */
+class Ansel_Exception extends Horde_Exception_Prior
+{
+}
index 2ea62f7..d3f8dcd 100644 (file)
@@ -636,10 +636,7 @@ class Ansel_Gallery extends Horde_Share_Object_sql_hierarchical
                                      'gallery_id' => -$this->id);
                     $newImg = new Ansel_Image($iparams);
                     $newImg->save();
-                    $prettyData = serialize(
-                        array_merge($thumbs,
-                                    array($styleHash => $newImg->id)));
-
+                    $prettyData = serialize(array_merge($thumbs, array($styleHash => $newImg->id)));
                     $this->set('default_prettythumb', $prettyData, true);
                     return $newImg->id;
                 } else {
index 4cbffc1..b0d97b2 100644 (file)
  * @author Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Ansel
  */
-class Ansel_ImageView {
-
+class Ansel_ImageView
+{
     /**
      * Ansel_Image object that this view is created from.
      *
      * @var Ansel_Image
      */
-    var $_image = null;
+    protected $_image = null;
 
     /**
      * Parameters for this view
      *
      * @var array
      */
-    var $_params = array();
+    protected $_params = array();
 
     /**
      * Image dimensions
      *
      * @var array
      */
-    var $_dimensions = array();
+    protected $_dimensions = array();
 
-    var $_style = array();
+    /**
+     * Cache the style information array
+     *
+     * @var array
+     */
+    protected $_style = array();
 
-    var $need = array();
+    /**
+     * Array of required, supported features for this ImageView to work
+     *
+     * @var array
+     */
+    public  $need = array();
 
     /**
-     * Constructor
+     * Const'r
+     *
+     * @return Horde_ImageView
      */
-    function Ansel_ImageView($params)
+    public function __construct($params)
     {
         $this->_params = $params;
         if (!empty($params['image'])) {
@@ -55,9 +67,12 @@ class Ansel_ImageView {
     }
 
     /**
-     * Function to actually create and cache the view.
+     * Create and cache the view.
+     *
+     * @return mixed  Views used as gallery key images return Horde_Image,
+     *                other views return boolean
      */
-    function create()
+    public function create()
     {
         if (!empty($this->_image)) {
             // Use Horde_Image since we don't know at this point which
@@ -70,12 +85,13 @@ class Ansel_ImageView {
     }
 
     /**
+     * Horde_ImageView factory
      *
      * @param string $type   The type of concrete instance to return.
      * @param array $params  Additional parameters needed for the instance.
      *
      * @return Ansel_ImageView
-     * @throws Horde_Exception
+     * @throws Ansel_Exception
      */
     function factory($type, $params = array())
     {
@@ -91,15 +107,14 @@ class Ansel_ImageView {
             foreach ($view->need as $need) {
                 if (!Ansel::isAvailable($need)) {
                     Horde::logMessage($err, __FILE__, __LINE__, PEAR_LOG_ERR);
-                    throw new Horde_Exception(_("This install does not support the %s feature. Please contact your administrator."), $need);
+                    throw new Ansel_Exception(_("This install does not support the %s feature. Please contact your administrator."), $need);
                 }
             }
             return $view;
         } else {
             Horde::logMessage($err, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Horde_Exception(sprintf(_("Unable to load the definition of %s."), $class));
+            throw new Ansel_Exception(sprintf(_("Unable to load the definition of %s."), $class));
         }
-
     }
 
     /**
@@ -108,15 +123,12 @@ class Ansel_ImageView {
      *
      * @param Ansel_Gallery $parent  The gallery to start looking in
      *
-     * @return An Ansel_Gallery object that has images, or the original $parent
+     * @return Ansel_Gallery  Gallery that has images, or the original $parent
      */
-    function _getGalleryWithImages($parent)
+    protected function _getGalleryWithImages($parent)
     {
-       $galleries = $GLOBALS['ansel_storage']->listGalleries(
-                                                    Horde_Perms::SHOW,
-                                                    null,
-                                                    $parent,
-                                                    false);
+        $galleries = $GLOBALS['ansel_storage']->listGalleries(
+            Horde_Perms::SHOW, null, $parent, false);
 
         foreach ($galleries as $gallery) {
             if ($gallery->countImages()) {
@@ -132,13 +144,13 @@ class Ansel_ImageView {
     }
 
    /**
-     * Utility function to return an array of Ansel_Images to use
-     * in building a polaroid stack. Returns a random set of 5 images from
-     * the gallery, or the explicitly set default image plus 4 others.
+     * Utility function to return an array of Horde_Images to use in building a
+    *  polaroid stack. Returns a random set of 5 images from the gallery, or the
+     explicitly set default image plus 4 others.
      *
      * @return array of Horde_Images
      */
-    function _getStackImages()
+    protected function _getStackImages()
     {
         $images = array();
         $gallery = $this->_params['gallery'];
@@ -154,7 +166,7 @@ class Ansel_ImageView {
             try {
                 $img = $gallery->getImage($default);
                 $img->load('screen');
-                $images[] = $img->getHordeImage();//&$gallery->getImage($default);
+                $images[] = $img->getHordeImage();
                 $cnt--;
             } catch (Horde_Exception $e) {}
         }
diff --git a/ansel/lib/ImageView/Mini.php b/ansel/lib/ImageView/Mini.php
new file mode 100755 (executable)
index 0000000..92486b5
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+/**
+ * ImageView to create the mini view.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageView_Mini extends Ansel_ImageView
+{
+    protected function _create()
+    {
+        $this->_image->resize(min(50, $this->_dimensions['width']),
+                                      min(50, $this->_dimensions['height']),
+                                      true);
+
+        return true;
+    }
+
+}
diff --git a/ansel/lib/ImageView/PlainStack.php b/ansel/lib/ImageView/PlainStack.php
new file mode 100644 (file)
index 0000000..c5cc15e
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+/**
+ * ImageView to create the gallery image stacks.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageView_PlainStack extends Ansel_ImageView
+{
+    public $need = array('PhotoStack');
+
+    /**
+     *
+     * @return Horde_Image
+     */
+    protected function _create()
+    {
+        $imgobjs = $this->_getStackImages();
+        $style = $this->_params['style'];
+        $params = array('width' => 100,
+                        'height' => 100,
+                        'background' => $style['background']);
+
+        $baseImg = Ansel::getImageObject($params);
+        try {
+            $baseImg->addEffect(
+                'PhotoStack',
+                array('images' => $imgobjs,
+                      'resize_height' => $GLOBALS['conf']['thumbnail']['height'],
+                      'padding' => 0,
+                      'background' => $style['background'],
+                      'type' => 'plain'));
+
+            $baseImg->applyEffects();
+            $baseImg->resize($GLOBALS['conf']['thumbnail']['width'],
+                             $GLOBALS['conf']['thumbnail']['height']);
+        } catch (Horde_Image_Exception $e) {
+            return false;
+        }
+
+        return $baseImg;
+    }
+
+}
diff --git a/ansel/lib/ImageView/PolaroidStack.php.php b/ansel/lib/ImageView/PolaroidStack.php.php
new file mode 100644 (file)
index 0000000..b2b2ddb
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+/**
+ * ImageView to create the gallery polaroid stacks.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageView_PolaroidStack extends Ansel_ImageView
+{
+    public $need = array('PhotoStack');
+
+    /**
+     *
+     * @return Horde_Image
+     */
+    protected function _create()
+    {
+        $imgobjs = $this->_getStackImages();
+        $style = $this->_params['style'];
+        $params = array('width' => 100,
+                        'height' => 100,
+                        'background' => $style['background']);
+
+        $baseImg = Ansel::getImageObject($params);
+        try {
+            $baseImg->addEffect(
+                'PhotoStack',
+                array('images' => $imgobjs,
+                      'resize_height' => $GLOBALS['conf']['thumbnail']['height'],
+                      'padding' => 10,
+                      'background' => $style['background'],
+                      'type' => 'polaroid'));
+            $baseImg->applyEffects();
+            $baseImg->resize($GLOBALS['conf']['thumbnail']['width'],
+                             $GLOBALS['conf']['thumbnail']['height']);
+
+        } catch (Horde_Image_Exception $e) {
+            return false;
+        }
+
+        return $baseImg;
+    }
+
+}
diff --git a/ansel/lib/ImageView/PolaroidThumb.php b/ansel/lib/ImageView/PolaroidThumb.php
new file mode 100644 (file)
index 0000000..8b750cc
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+/**
+ * ImageView to create the shadowsharpthumb view (sharp corners, shadowed)
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageView_PolaroidThumb extends Ansel_ImageView
+{
+    public $need = array('PolaroidImage');
+
+    /**
+     *
+     * @return boolean
+     */
+    protected function _create()
+    {
+        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
+                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
+                              true);
+
+        /* Don't bother with these effects for a custom gallery default image
+           (which will have a negative gallery_id). */
+        if ($this->_image->gallery > 0) {
+            if (is_null($this->_style)) {
+                $gal = $GLOBALS['ansel_storage']->getGallery($this->_image->gallery);
+                $styleDef = $gal->getStyle();
+            } else {
+                $styleDef = Ansel::getStyleDefinition($this->_style);
+            }
+            try {
+                $this->_image->addEffect('PolaroidImage',
+                                         array('background' => $styleDef['background'],
+                                               'padding' => 5));
+
+                $this->_image->applyEffects();
+            } catch (Horde_Image_Exception $e) {
+                return false;
+            }
+
+            return true;
+        }
+    }
+
+}
diff --git a/ansel/lib/ImageView/PrettyThumb.php b/ansel/lib/ImageView/PrettyThumb.php
new file mode 100644 (file)
index 0000000..3acf67b
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+/**
+ * ImageView to create the prettythumb view (rounded, shadowed thumbnails).
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageView_PrettyThumb extends Ansel_ImageView
+{
+    public $need = array('RoundCorners', 'DropShadow');
+
+    /**
+     *
+     * @return boolean
+     */
+    protected function _create()
+    {
+        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
+                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
+                              true);
+
+        /* Don't bother with these effects for a stack image
+         * (which will have a negative gallery_id). */
+        if ($this->_image->gallery > 0) {
+            if (is_null($this->_style)) {
+                $gal = $GLOBALS['ansel_storage']->getGallery($this->_image->gallery);
+                $styleDef = $gal->getStyle();
+            } else {
+                $styleDef = Ansel::getStyleDefinition($this->_style);
+            }
+
+            try {
+                /* Apply the effects - continue on error, but be sure to log */
+                $this->_image->addEffect('RoundCorners', array('border' => 2,
+                                                               'bordercolor' => '#333'));
+
+                $this->_image->addEffect('DropShadow', array('background' => $styleDef['background'],
+                                                             'padding' => 5,
+                                                             'distance' => 5,
+                                                             'fade' => 3));
+            } catch (Horde_Image_Exception $e) {
+                return false;
+            }
+            $this->_image->applyEffects();
+
+            return true;
+        }
+    }
+
+}
diff --git a/ansel/lib/ImageView/RoundedStack.php b/ansel/lib/ImageView/RoundedStack.php
new file mode 100644 (file)
index 0000000..5783d67
--- /dev/null
@@ -0,0 +1,46 @@
+ <?php
+/**
+ * ImageView to create the gallery image stacks.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ *
+ */
+class Ansel_ImageView_RoundedStack extends Ansel_ImageView
+ {
+    public $need = array('PhotoStack');
+
+    /**
+     *
+     * @return Horde_Image
+     */
+    protected function _create()
+    {
+        $imgobjs = $this->_getStackImages();
+        $style = $this->_params['style'];
+        $params = array('width' => 100,
+                        'height' => 100,
+                        'background' => $style['background']);
+
+        $baseImg = Ansel::getImageObject($params);
+
+        try {
+            $baseImg->addEffect(
+                'PhotoStack',
+                array('images' => $imgobjs,
+                      'resize_height' => $GLOBALS['conf']['thumbnail']['height'],
+                      'padding' => 0,
+                      'background' => $style['background'],
+                      'type' => 'rounded'));
+
+            $baseImg->applyEffects();
+            $baseImg->resize($GLOBALS['conf']['thumbnail']['width'],
+                             $GLOBALS['conf']['thumbnail']['height']);
+        } catch (Horde_Image_Exception $e) {
+            return false;
+        }
+
+        return $baseImg;
+    }
+
+}
diff --git a/ansel/lib/ImageView/Screen.php b/ansel/lib/ImageView/Screen.php
new file mode 100755 (executable)
index 0000000..b809219
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+/**
+ * ImageView to create the screen view - image sized for slideshow view.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageView_Screen extends Ansel_ImageView
+{
+    /**
+     *
+     * @return boolean
+     */
+    protected function _create()
+    {
+        $this->_image->resize(min($GLOBALS['conf']['screen']['width'], $this->_dimensions['width']),
+                              min($GLOBALS['conf']['screen']['height'], $this->_dimensions['height']),
+                              true);
+
+        return true;
+    }
+
+}
diff --git a/ansel/lib/ImageView/ShadowSharpThumb.php b/ansel/lib/ImageView/ShadowSharpThumb.php
new file mode 100644 (file)
index 0000000..9153b17
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/**
+ * ImageView to create the shadowsharpthumb view (sharp corners, shadowed)
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageView_ShadowSharpThumb extends Ansel_ImageView
+{
+    public $need = array('DropShadow');
+
+    /**
+     *
+     * @return boolean
+     */
+    protected function _create()
+    {
+        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
+                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
+                              true);
+
+        /* Don't bother with these effects for a stack image
+         * (which will have a negative gallery_id). */
+        if ($this->_image->gallery > 0) {
+            if (is_null($this->_style)) {
+                $gal = $GLOBALS['ansel_storage']->getGallery($this->_image->gallery);
+                $styleDef = $gal->getStyle();
+            } else {
+                $styleDef = Ansel::getStyleDefinition($this->_style);
+            }
+
+            try {
+                $this->_image->addEffect('border', array('bordercolor' => '#333'));
+                $this->_image->addEffect('DropShadow',
+                                         array('background' => $styleDef['background'],
+                                               'padding' => 5,
+                                               'distance' => '8',
+                                               'fade' => 2));
+                $this->_image->applyEffects();
+            } catch (Horde_Image_Exception $e) {
+                return false;
+            }
+
+            return true;
+        }
+    }
+
+}
diff --git a/ansel/lib/ImageView/Thumb.php b/ansel/lib/ImageView/Thumb.php
new file mode 100755 (executable)
index 0000000..5e650c5
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+/**
+ * ImageView to create the thumb view (plain, resized thumbnails).
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageView_Thumb extends Ansel_ImageView
+{
+    /**
+     *
+     * @return boolean
+     */
+    protected function _create()
+    {
+        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
+                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
+                              true);
+        return true;
+    }
+
+}