From c2712070c6d96fa10b2d4b46d567f4e71a4fc792 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Tue, 16 Feb 2010 19:40:06 -0500 Subject: [PATCH] H4 naming conventions --- ansel/config/styles.php.dist | 24 +++++------ ansel/lib/Exception.php | 15 +++++++ ansel/lib/Gallery.php | 5 +-- ansel/lib/ImageView.php | 66 ++++++++++++++++++------------- ansel/lib/ImageView/Mini.php | 19 +++++++++ ansel/lib/ImageView/PlainStack.php | 44 +++++++++++++++++++++ ansel/lib/ImageView/PolaroidStack.php.php | 44 +++++++++++++++++++++ ansel/lib/ImageView/PolaroidThumb.php | 45 +++++++++++++++++++++ ansel/lib/ImageView/PrettyThumb.php | 50 +++++++++++++++++++++++ ansel/lib/ImageView/RoundedStack.php | 46 +++++++++++++++++++++ ansel/lib/ImageView/Screen.php | 23 +++++++++++ ansel/lib/ImageView/ShadowSharpThumb.php | 48 ++++++++++++++++++++++ ansel/lib/ImageView/Thumb.php | 22 +++++++++++ 13 files changed, 408 insertions(+), 43 deletions(-) create mode 100644 ansel/lib/Exception.php create mode 100755 ansel/lib/ImageView/Mini.php create mode 100644 ansel/lib/ImageView/PlainStack.php create mode 100644 ansel/lib/ImageView/PolaroidStack.php.php create mode 100644 ansel/lib/ImageView/PolaroidThumb.php create mode 100644 ansel/lib/ImageView/PrettyThumb.php create mode 100644 ansel/lib/ImageView/RoundedStack.php create mode 100755 ansel/lib/ImageView/Screen.php create mode 100644 ansel/lib/ImageView/ShadowSharpThumb.php create mode 100755 ansel/lib/ImageView/Thumb.php diff --git a/ansel/config/styles.php.dist b/ansel/config/styles.php.dist index c239bdc2e..e3ee067de 100644 --- a/ansel/config/styles.php.dist +++ b/ansel/config/styles.php.dist @@ -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 index 000000000..8fb0514e0 --- /dev/null +++ b/ansel/lib/Exception.php @@ -0,0 +1,15 @@ + + * @package Ansel + */ +class Ansel_Exception extends Horde_Exception_Prior +{ +} diff --git a/ansel/lib/Gallery.php b/ansel/lib/Gallery.php index 2ea62f7b0..d3f8dcd56 100644 --- a/ansel/lib/Gallery.php +++ b/ansel/lib/Gallery.php @@ -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 { diff --git a/ansel/lib/ImageView.php b/ansel/lib/ImageView.php index 4cbffc187..b0d97b2a8 100644 --- a/ansel/lib/ImageView.php +++ b/ansel/lib/ImageView.php @@ -15,37 +15,49 @@ * @author Michael J. Rubinsky * @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 index 000000000..92486b56a --- /dev/null +++ b/ansel/lib/ImageView/Mini.php @@ -0,0 +1,19 @@ + + * @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 index 000000000..c5cc15e31 --- /dev/null +++ b/ansel/lib/ImageView/PlainStack.php @@ -0,0 +1,44 @@ + + * @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 index 000000000..b2b2ddbb7 --- /dev/null +++ b/ansel/lib/ImageView/PolaroidStack.php.php @@ -0,0 +1,44 @@ + + * @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 index 000000000..8b750cc00 --- /dev/null +++ b/ansel/lib/ImageView/PolaroidThumb.php @@ -0,0 +1,45 @@ + + * @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 index 000000000..3acf67b2b --- /dev/null +++ b/ansel/lib/ImageView/PrettyThumb.php @@ -0,0 +1,50 @@ + + * @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 index 000000000..5783d67a9 --- /dev/null +++ b/ansel/lib/ImageView/RoundedStack.php @@ -0,0 +1,46 @@ + + * @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 index 000000000..b80921946 --- /dev/null +++ b/ansel/lib/ImageView/Screen.php @@ -0,0 +1,23 @@ + + * @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 index 000000000..9153b17ed --- /dev/null +++ b/ansel/lib/ImageView/ShadowSharpThumb.php @@ -0,0 +1,48 @@ + + * @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 index 000000000..5e650c599 --- /dev/null +++ b/ansel/lib/ImageView/Thumb.php @@ -0,0 +1,22 @@ + + * @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; + } + +} -- 2.11.0