From: Michael J. Rubinsky Date: Sat, 18 Sep 2010 02:14:33 +0000 (-0400) Subject: More style related refactoring: X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=eb29b00fb8aaf7a9de0ac0a250a31837b60a46d6;p=horde.git More style related refactoring: Ansel now automatically picks up and makes available any new image generators placed in lib/ImageGenerator. Will look for a matching "Stack" generator for generating image stacks, if no match found, reverts to standard thumbnail. Ditto for gallery view styles placed in lib/View/GalleryRenderer. Gallery property page now displays and allows changing current gallery style settings. Some other phpdoc, and cleanup. --- diff --git a/ansel/config/conf.xml b/ansel/config/conf.xml index b434138b2..0f369ea1e 100644 --- a/ansel/config/conf.xml +++ b/ansel/config/conf.xml @@ -84,7 +84,8 @@ 0 false + hit on some installations but is required for the generation of all but the + most basic image thumbnails." required="false">false 5 'PrettyThumb', - 'requires_png' => true, - // This really only looks good with ImageMagick, not GD. - 'default_galleryimage_type' => 'RoundedStack', + 'title' => _("Rounded Thumbnails (No Background)"), + 'thumbstyle' => 'RoundedThumb', 'background' => 'none', 'widgets' => $widgets, ); $styles['ansel_blackonwhite'] = array( 'name' => 'ansel_blackonwhite', - 'title' => _("Pretty Thumbnails (White Background)"), - 'default_galleryimage_type' => 'RoundedStack', - 'thumbstyle' => 'PrettyThumb', + 'title' => _("Rounded Thumbnails (White Background)"), + 'thumbstyle' => 'RoundedThumb', 'background' => 'white', 'widgets' => $widgets, ); @@ -85,9 +69,8 @@ $styles['ansel_blackonwhite'] = array( $styles['ansel_sharpshadowed'] = array( 'name' => 'ansel_sharpshadowed', 'title' => _("Shadowed Thumbnails (White Background)"), - 'thumbstyle' => 'ShadowSharpThumb', + 'thumbstyle' => 'ShadowThumb', 'background' => 'white', - 'default_galleryimage_type' => 'PlainStack', 'widgets' => $widgets ); @@ -97,7 +80,6 @@ $styles['ansel_polaroid'] = array( 'title' => _("Polaroid Style Thumbnails (White Background)"), 'thumbstyle' => 'PolaroidThumb', 'background' => 'white', - 'default_galleryimage_type' => 'PolaroidStack', 'widgets' => $widgets, ); @@ -108,10 +90,9 @@ $styles['ansel_lightbox'] = array( 'thumbstyle' => 'Thumb', 'background' => 'white', 'gallery_view' => 'GalleryLightbox', - 'widgets' => $widgets, + 'widgets' => $widgets ); - /* Lightbox image views with no background * (requires PNG) */ $styles['ansel_lightbox_png'] = array( @@ -119,9 +100,8 @@ $styles['ansel_lightbox_png'] = array( 'title' => _("A Lightbox Inspired Style (No Background)"), 'thumbstyle' => 'Thumb', 'background' => 'none', - 'requires_png' => true, 'gallery_view' => 'GalleryLightbox', - 'widgets' => $widgets, + 'widgets' => $widgets ); /* Lightbox image views with no background and shadowed thumbs @@ -129,15 +109,13 @@ $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' => 'ShadowThumb', 'background' => 'none', - 'requires_png' => true, 'gallery_view' => 'GalleryLightbox', 'widgets' => $widgets, 'fallback' => 'ansel_lightbox' ); - /* Same as above, but with Polaroid thumbnails/stacks * and no background (so required png support) */ $styles['ansel_lightbox_polaroid'] = array( @@ -145,10 +123,8 @@ $styles['ansel_lightbox_polaroid'] = array( 'title' => _("Lightbox with Polaroids (No Background)"), 'thumbstyle' => 'PolaroidThumb', 'background' => 'none', - 'requires_png' => true, - 'default_galleryimage_type' => 'PolaroidStack', 'gallery_view' => 'GalleryLightbox', - 'widgets' => $widgets, + 'widgets' => $widgets ); /* Simple styles with no Ansel_Widgets useful for rendering on external sites @@ -160,8 +136,7 @@ $styles['ansel_simple'] = array( 'name' => 'ansel_simple', 'title' => _("Simple"), 'thumbstyle' => 'Thumb', - 'background' => 'none', - 'hide' => true, + 'background' => 'none' ); /* An API friendly lightbox style */ @@ -170,10 +145,7 @@ $styles['ansel_lightbox_simple'] = array( 'title' => _("Simple Lightbox"), 'thumbstyle' => 'Thumb', 'background' => 'none', - 'requires_png' => true, - 'gallery_view' => 'GalleryLightbox', - 'hide' => true, - 'fallback' => 'ansel_simple' + 'gallery_view' => 'GalleryLightbox' ); /* Same as above, but with polaroid thumbnails */ @@ -182,9 +154,5 @@ $styles['ansel_lightbox_simple_polaroid'] = array( 'title' => _("Lightbox with Polaroids (No Background)"), 'thumbstyle' => 'PolaroidThumb', 'background' => 'none', - 'requires_png' => true, - 'default_galleryimage_type' => 'PolaroidStack', - 'gallery_view' => 'GalleryLightbox', - 'hide' => true, - 'fallback' => 'ansel_simple' + 'gallery_view' => 'GalleryLightbox' ); diff --git a/ansel/lib/Gallery.php b/ansel/lib/Gallery.php index 2acb9ece1..c02fb83c7 100644 --- a/ansel/lib/Gallery.php +++ b/ansel/lib/Gallery.php @@ -710,23 +710,34 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical } /** - * Return the style definition for this gallery. Returns the first available - * style in this order: Explicitly configured style if available, if - * configured style is not available, use ansel_default. If nothing has - * been configured, the user's selected default is attempted. - * - * @TODO: Verify availability of selected style and fallback to ansel_default + * Return the style definition for this gallery. * * @return array The style definition array. */ public function getStyle() { + // No styles allowed per admin. + if (!$GLOBALS['conf']['image']['prettythumbs']) { + return Ansel::getStyleDefinition('ansel_default'); + } + if (empty($this->data['attribute_style'])) { + // No style configured, use user's prefered default $style = Ansel::getStyleDefinition($GLOBALS['prefs']->getValue('default_gallerystyle')); } else { + // Explicitly defined style $style = unserialize($this->data['attribute_style']); } + // Check browser requirements. If we require PNG support, and do not + // have it, revert to the basic ansel_default style. + if ($style->requiresPng() && + ($GLOBALS['browser']->hasQuirk('png_transparency') || + $GLOBALS['conf']['image']['type'] != 'png')) { + + return Ansel::getStyleDefinition('ansel_default'); + } + return $style; } diff --git a/ansel/lib/ImageGenerator.php b/ansel/lib/ImageGenerator.php index 983d027cb..8e4f8831b 100644 --- a/ansel/lib/ImageGenerator.php +++ b/ansel/lib/ImageGenerator.php @@ -1,6 +1,21 @@ need as $need) { if (!Ansel::isAvailable($need)) { Horde::logMessage($err, 'ERR'); @@ -154,10 +168,10 @@ class Ansel_ImageGenerator /** * 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 + * stack. Returns a random set of 5 images from the gallery, or the * explicitly set key image plus 4 others. * - * @return array of Horde_Images + * @return array An array of Horde_Image objects. */ protected function _getStackImages() { diff --git a/ansel/lib/ImageGenerator/PolaroidThumb.php b/ansel/lib/ImageGenerator/PolaroidThumb.php index 3b8b5a54c..27a9b7f62 100644 --- a/ansel/lib/ImageGenerator/PolaroidThumb.php +++ b/ansel/lib/ImageGenerator/PolaroidThumb.php @@ -9,6 +9,12 @@ class Ansel_ImageGenerator_PolaroidThumb extends Ansel_ImageGenerator { public $need = array('PolaroidImage'); + public function __construct($params) + { + parent::__construct($params); + $this->title = _("Polaroids"); + } + /** * * @return Horde_Image diff --git a/ansel/lib/ImageGenerator/RoundedThumb.php b/ansel/lib/ImageGenerator/RoundedThumb.php index 72f08ab48..c60ce13d8 100644 --- a/ansel/lib/ImageGenerator/RoundedThumb.php +++ b/ansel/lib/ImageGenerator/RoundedThumb.php @@ -9,6 +9,12 @@ class Ansel_ImageGenerator_RoundedThumb extends Ansel_ImageGenerator { public $need = array('RoundCorners', 'DropShadow'); + public function __construct($params) + { + parent::__construct($params); + $this->title = _("Rounded Corners"); + } + /** * * @return Horde_Image diff --git a/ansel/lib/ImageGenerator/ShadowThumb.php b/ansel/lib/ImageGenerator/ShadowThumb.php index 98ce8abab..6be90f9ad 100644 --- a/ansel/lib/ImageGenerator/ShadowThumb.php +++ b/ansel/lib/ImageGenerator/ShadowThumb.php @@ -9,6 +9,12 @@ class Ansel_ImageGenerator_ShadowThumb extends Ansel_ImageGenerator { public $need = array('DropShadow'); + public function __construct($params) + { + parent::__construct($params); + $this->title = _("Drop Shadows"); + } + /** * * @return boolean diff --git a/ansel/lib/ImageGenerator/Thumb.php b/ansel/lib/ImageGenerator/Thumb.php index d563b4fd2..fdb56da70 100755 --- a/ansel/lib/ImageGenerator/Thumb.php +++ b/ansel/lib/ImageGenerator/Thumb.php @@ -7,6 +7,12 @@ */ class Ansel_ImageGenerator_Thumb extends Ansel_ImageGenerator { + public function __construct($params) + { + parent::__construct($params); + $this->title = _("Basic Thumbnails"); + } + /** * * @return Horde_Image diff --git a/ansel/lib/Injector/Binder/Styles.php b/ansel/lib/Injector/Binder/Styles.php index b288c185a..9a8d20ada 100644 --- a/ansel/lib/Injector/Binder/Styles.php +++ b/ansel/lib/Injector/Binder/Styles.php @@ -1,6 +1,6 @@ * @category Horde @@ -18,7 +18,7 @@ class Ansel_Injector_Binder_Styles Implements Horde_Injector_Binder if (empty($GLOBALS['conf']['image']['prettythumbs'])) { $test = $styles; foreach ($test as $key => $style) { - if ($style['thumbstyle'] != 'thumb') { + if ($style['thumbstyle'] != 'Thumb') { unset($styles[$key]); } } diff --git a/ansel/lib/View/GalleryProperties.php b/ansel/lib/View/GalleryProperties.php index d94adabe7..62eb09c85 100644 --- a/ansel/lib/View/GalleryProperties.php +++ b/ansel/lib/View/GalleryProperties.php @@ -11,12 +11,6 @@ * @author Michael J. Rubinsky * @package Ansel */ - -/** - * Description of GalleryProperties - * - * @author mrubinsk - */ class Ansel_View_GalleryProperties { /** @@ -48,22 +42,6 @@ class Ansel_View_GalleryProperties public function __construct($params = array()) { $this->_params = $params; - - /*Gallery properties */ - $this->_properties = array( - 'name' => '', - 'desc' => '', - 'tags' => '', - 'style' => '', - 'slug' => '', - 'age' => 0, - 'download' => $GLOBALS['prefs']->getValue('default_download'), - 'parent' => null, - 'id' => null, - 'mode' => 'Normal', - 'passwd' => '', - 'owner' => '' - ); } /** @@ -92,6 +70,25 @@ class Ansel_View_GalleryProperties } } + private function _loadDefaults() + { + /*Gallery properties */ + $this->_properties = array( + 'name' => '', + 'desc' => '', + 'tags' => '', + 'style' => Ansel::getStyleDefinition($GLOBALS['prefs']->getValue('default_gallerystyle')), + 'slug' => '', + 'age' => 0, + 'download' => $GLOBALS['prefs']->getValue('default_download'), + 'parent' => null, + 'id' => null, + 'mode' => 'Normal', + 'passwd' => '', + 'owner' => '' + ); + } + /** * Outputs the view to the browser. * @@ -107,6 +104,8 @@ class Ansel_View_GalleryProperties $view->title = $this->_title; $view->action = $this->_params['actionID']; $view->url = $this->_params['url']; + $view->availableThumbs = $this->_thumbStyles(); + $view->galleryViews = $this->_galleryViewStyles(); Horde::addInlineScript(array('$("gallery_name").focus()'), 'dom'); Horde::addScriptFile('stripe.js', 'horde'); @@ -132,6 +131,7 @@ class Ansel_View_GalleryProperties */ private function _runNew() { + $this->_loadDefaults(); $this->_title = _("Adding a New Gallery"); $this->_properties['owner'] = $GLOBALS['registry']->getAuth(); } @@ -143,6 +143,8 @@ class Ansel_View_GalleryProperties */ private function _runNewChild() { + $this->_loadDefaults(); + // Get the parent and make sure that it exists and that we have // permissions to add to it. $parentId = $this->_params['gallery']; @@ -237,7 +239,8 @@ class Ansel_View_GalleryProperties $style = new Ansel_Style(array( 'thumbstyle' => Horde_Util::getFormData('thumbnail_style'), 'background' => Horde_Util::getFormData('background_color'), - // temporary hack + 'gallery_view' => Horde_Util::getFormData('gallery_view'), + // temporary hack until widgets are also configurable. 'widgets' => array( 'Tags' => array('view' => 'gallery'), 'OtherGalleries' => array(), @@ -274,7 +277,7 @@ class Ansel_View_GalleryProperties $gallery->get('owner') == $GLOBALS['registry']->getAuth()) { $gallery->set('passwd', $gallery_passwd); } - + // Did the parent change? $old_parent = $gallery->getParent(); if (!is_null($old_parent)) { @@ -386,5 +389,50 @@ class Ansel_View_GalleryProperties } $url->redirect(); } + + /** + * Get a list of available, currently usable thumbnail styles. + * + * @return array An array of Classnames => titles + */ + protected function _thumbStyles() + { + // Iterate all available thumbstyles: + $dir = ANSEL_BASE . '/lib/ImageGenerator'; + $files = scandir($dir); + $thumbs = array(); + foreach ($files as $file) { + if (substr($file, -9) == 'Thumb.php') { + try { + $generator = Ansel_ImageGenerator::factory(substr($file, 0, -4), array('style' => '')); + $thumbs[substr($file, 0, -4)] = $generator->title; + } catch (Ansel_Exception $e) {} + } + } + + return $thumbs; + } + + /** + * Get a list of available Gallery View styles + * + * @return array + */ + protected function _galleryViewStyles() + { + // Iterate all available thumbstyles: + $dir = ANSEL_BASE . '/lib/View/GalleryRenderer'; + $files = scandir($dir); + $views = array(); + foreach ($files as $file) { + if ($file != 'Base.php' && $file != '.' && $file != '..') { + $class = 'Ansel_View_GalleryRenderer_' . substr($file, 0, -4); + $view = new $class(null); + $views[substr($file, 0, -4)] = $view->title; + } + } + + return $views; + } } diff --git a/ansel/lib/View/GalleryRenderer/Base.php b/ansel/lib/View/GalleryRenderer/Base.php index 673ed32af..564f2b8a8 100644 --- a/ansel/lib/View/GalleryRenderer/Base.php +++ b/ansel/lib/View/GalleryRenderer/Base.php @@ -51,7 +51,7 @@ abstract class Ansel_View_GalleryRenderer_Base public $mode; /** - * The style definition array for this gallery. + * The style definition. * * @var Ansel_Style */ @@ -101,11 +101,18 @@ abstract class Ansel_View_GalleryRenderer_Base public $date = array(); /** + * Human readable title for this view type + * + * @var string + */ + public $title; + + /** * Constructor * * @param Ansel_View_Gallery The view object for this renderer. */ - public function __construct(Ansel_View_Gallery $view) + public function __construct($view) { $this->view = $view; } diff --git a/ansel/lib/View/GalleryRenderer/Gallery.php b/ansel/lib/View/GalleryRenderer/Gallery.php index db63dd96b..7fe5cee55 100644 --- a/ansel/lib/View/GalleryRenderer/Gallery.php +++ b/ansel/lib/View/GalleryRenderer/Gallery.php @@ -13,6 +13,13 @@ */ class Ansel_View_GalleryRenderer_Gallery extends Ansel_View_GalleryRenderer_Base { + + public function __construct($view) + { + parent::__construct($view); + $this->title = _("Standard Gallery"); + } + /** * Perform any tasks that should be performed before the view is rendered. * diff --git a/ansel/lib/View/GalleryRenderer/GalleryLightbox.php b/ansel/lib/View/GalleryRenderer/GalleryLightbox.php index f77ee684d..5fba62d40 100644 --- a/ansel/lib/View/GalleryRenderer/GalleryLightbox.php +++ b/ansel/lib/View/GalleryRenderer/GalleryLightbox.php @@ -13,6 +13,13 @@ */ class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRenderer_Base { + + public function __construct($view) + { + parent::__construct($view); + $this->title = _("Lightbox Gallery"); + } + /** * Perform any tasks that should be performed before the view is rendered. * diff --git a/ansel/templates/gallery/partial/_styles.html.php b/ansel/templates/gallery/partial/_styles.html.php index 17161eb01..3823d1225 100644 --- a/ansel/templates/gallery/partial/_styles.html.php +++ b/ansel/templates/gallery/partial/_styles.html.php @@ -1,27 +1,15 @@ - + - - + - - + galleryViews as $type => $title): ?> + + \ No newline at end of file diff --git a/ansel/templates/gallery/properties.html.php b/ansel/templates/gallery/properties.html.php index 9102d8f00..e9a23794a 100644 --- a/ansel/templates/gallery/properties.html.php +++ b/ansel/templates/gallery/properties.html.php @@ -69,7 +69,7 @@  
-
+
@@ -122,7 +122,7 @@ -renderPartial('styles'); ?> +renderPartial('styles'); }?>