From: Michael J. Rubinsky Date: Thu, 16 Sep 2010 00:00:05 +0000 (-0400) Subject: Implement Ansel_Style X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=c3c6189c23971de660d2f8f1876562d15a086286;p=horde.git Implement Ansel_Style Style info is always passed around as an Ansel_Style object now, except when calling via the API...which will take a named style. Also, now optionally pass the thumbbnail type and background color to the img/* scripts since each gallery now has it's own copy of the style information. Some other misc. changes...basically a touchstone commit. --- diff --git a/ansel/gallery/captions.php b/ansel/gallery/captions.php index cbf277206..0862dd7a3 100644 --- a/ansel/gallery/captions.php +++ b/ansel/gallery/captions.php @@ -48,7 +48,6 @@ case 'save': } $notification->push(_("Captions Saved."), 'horde.success'); - $style = $gallery->getStyle(); Ansel::getUrlFor('view', array_merge(array('gallery' => $galleryId, 'slug' => $gallery->get('slug'), 'view' => 'Gallery'), diff --git a/ansel/gallery/sort.php b/ansel/gallery/sort.php index 9d455ad23..d386cd4f6 100644 --- a/ansel/gallery/sort.php +++ b/ansel/gallery/sort.php @@ -86,7 +86,7 @@ $notification->notify(array('listeners' => 'status')); -
+
getImages(); @@ -94,7 +94,7 @@ foreach ($images as $image) { $caption = empty($image->caption) ? htmlspecialchars($image->filename, ENT_COMPAT, $GLOBALS['registry']->getCharset()) : htmlspecialchars($image->caption, ENT_COMPAT, $GLOBALS['registry']->getCharset()); echo ''; } echo '
'; diff --git a/ansel/img/mini.php b/ansel/img/mini.php index 25f5c2f42..38dbd2eeb 100644 --- a/ansel/img/mini.php +++ b/ansel/img/mini.php @@ -21,7 +21,7 @@ if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ)) { if ($conf['vfs']['src'] == 'sendfile') { /* Need to ensure the file exists */ try { - $image->createView('mini', 'ansel_default'); + $image->createView('mini', Ansel::getStyleDefinition('ansel_default')); } catch (Horde_Exception $e) { Horde::logMessage($e, 'ERR'); exit; diff --git a/ansel/img/prettythumb.php b/ansel/img/prettythumb.php index 203e979e0..d125a1033 100644 --- a/ansel/img/prettythumb.php +++ b/ansel/img/prettythumb.php @@ -11,7 +11,16 @@ require_once dirname(__FILE__) . '/../lib/Application.php'; Horde_Registry::appInit('ansel'); -$style = Horde_Util::getFormData('style'); +$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')->getScope()->getImage(Horde_Util::getFormData('image')); $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery(abs($image->gallery)); if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ)) { diff --git a/ansel/img/screen.php b/ansel/img/screen.php index a9ea08a48..68af698cb 100644 --- a/ansel/img/screen.php +++ b/ansel/img/screen.php @@ -21,7 +21,7 @@ if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ)) { if ($conf['vfs']['src'] == 'sendfile') { /* Need to ensure the file exists */ try { - $image->createView('screen', 'ansel_default'); + $image->createView('screen', Ansel::getStyleDefinition('ansel_default')); } catch (Horde_Exception $e) { Horde::logMessage($result, 'ERR'); exit; diff --git a/ansel/img/thumb.php b/ansel/img/thumb.php index 1caea0d2d..ef6c290c7 100644 --- a/ansel/img/thumb.php +++ b/ansel/img/thumb.php @@ -21,7 +21,7 @@ if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ)) { if ($conf['vfs']['src'] == 'sendfile') { /* Need to ensure the file exists */ try { - $image->createView('thumb', 'ansel_default'); + $image->createView('thumb', Ansel::getStyleDefinition('ansel_default')); } catch (Horde_Exception $e) { Horde::logMessage($result, 'ERR'); exit; diff --git a/ansel/lib/Ansel.php b/ansel/lib/Ansel.php index 814f5be48..ed630bc59 100644 --- a/ansel/lib/Ansel.php +++ b/ansel/lib/Ansel.php @@ -363,11 +363,11 @@ class Ansel * Takes into account $conf['vfs']['direct'] and other * factors. * - * @param string $imageId The id of the image. - * @param string $view The view ('screen', 'thumb', 'prettythumb' or - * 'full') to show. - * @param boolean $full Return a path that includes the server name? - * @param string $style Use this gallery style + * @param string $imageId The id of the image. + * @param string $view The view ('screen', 'thumb', 'prettythumb' or + * 'full') to show. + * @param boolean $full Return a path that includes the server name? + * @param Ansel_Style $style Use this gallery style * * @return Horde_Url The image path. */ @@ -396,7 +396,7 @@ class Ansel // Default to ansel_default since we really only need to know the style // if we are requesting a 'prettythumb' if (is_null($style)) { - $style = 'ansel_default'; + $style = Ansel::getStyleDefinition('ansel_default'); } // Don't load the image if the view exists @@ -423,8 +423,10 @@ class Ansel if ($conf['vfs']['src'] != 'direct') { $params = array('image' => $imageId); if (!is_null($style)) { - $params['style'] = $style; + $params['t'] = $style->thumbstyle; + $params['b'] = $style->background; } + return Horde::url('img/' . $view . '.php', $full)->add($params); } @@ -669,8 +671,9 @@ class Ansel */ static public function getStyleSelect($element_name, $selected = '') { - $styles = Horde::loadConfiguration('styles.php', 'styles', '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; @@ -702,52 +705,38 @@ class Ansel } /** - * Get a style definition for the requested named style + * Get a pre-defined style definition for the requested named style * * @param string $style The name of the style to fetch * - * @return array The definition of the requested style if it's available - * otherwise, the ansel_default style is returned. + * @return Ansel_Style The definition of the requested style if it's + * available, otherwise, the ansel_default style is + * returned. */ static public function getStyleDefinition($style) { $styles = $GLOBALS['injector']->getInstance('Ansel_Styles'); if (isset($styles[$style])) { - $style_def = $styles[$style]; + return new Ansel_Style($styles[$style]); } else { - $style_def = $styles['ansel_default']; - } - - /* Fill in defaults */ - if (empty($style_def['gallery_view'])) { - $style_def['gallery_view'] = 'Gallery'; + return new Ansel_Style($styles['ansel_default']); } - if (empty($style_def['default_galleryimage_type'])) { - $style_def['default_galleryimage_type'] = 'plain'; - } - if (empty($style_def['requires_png'])) { - $style_def['requires_png'] = false; - } - - return $style_def; } /** * Return a hash key for the given view and style. * - * @param string $view The view (thumb, prettythumb etc...) - * @param string $style The named style. + * @param string $view The view (thumb, prettythumb etc...) + * @param Ansel_Style $style The style object. * * @return string A md5 hash suitable for use as a key. */ static public function getViewHash($view, $style) { - $style = Ansel::getStyleDefinition($style); - if ($view != 'screen' && $view != 'thumb' && $view != 'mini' && $view != 'full') { - $view = md5($style['thumbstyle'] . '.' . $style['background']); + $view = md5($style->thumbstyle . '.' . $style->background); } return $view; diff --git a/ansel/lib/Api.php b/ansel/lib/Api.php index 4555213ff..02a87cda0 100644 --- a/ansel/lib/Api.php +++ b/ansel/lib/Api.php @@ -641,7 +641,12 @@ class Ansel_Api extends Horde_Registry_Api throw new Ansel_Exception($e->getMessage()); } } else { - $result = $image->load($view, $style); + if (!empty($params['style'])) { + $params['style'] = Ansel::getStyleDefinition($style); + } else { + $params['style'] = null; + } + $result = $image->load($view, $params['style']); $data = $image->_image->raw(); } @@ -776,6 +781,7 @@ class Ansel_Api extends Horde_Registry_Api if (!is_null($app)) { $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app); } + $storage = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope(); // Determine the default gallery when none is given. The first gallery // in the list is the default gallery. @@ -794,6 +800,11 @@ class Ansel_Api extends Horde_Registry_Api } $images = $gallery->listImages(); + if ($style) { + $style = Ansel::getStyleDefinition($style); + } else { + $style = $gallery->getStyle(); + } $counter = 0; $imagelist = array(); @@ -839,6 +850,9 @@ class Ansel_Api extends Horde_Registry_Api } $images = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getRecentImages($galleries, $limit, $slugs); $imagelist = array(); + if ($style) { + $style = Ansel::getStyleDefinition($style); + } foreach ($images as $image) { $id = $image->id; $imagelist[$id]['id'] = $id; @@ -988,7 +1002,7 @@ class Ansel_Api extends Horde_Registry_Api } /** - * Get a list of all configured styles. + * Get a list of all pre-configured styles. * * @return hash of style definitions. */ diff --git a/ansel/lib/Block/gallery.php b/ansel/lib/Block/gallery.php index 7c84e9bde..9095a0e4a 100644 --- a/ansel/lib/Block/gallery.php +++ b/ansel/lib/Block/gallery.php @@ -78,8 +78,6 @@ class Horde_Block_ansel_gallery extends Horde_Block } else { $name = $gallery->get('name'); } - - $style = $gallery->getStyle(); $viewurl = Ansel::getUrlFor('view', array('view' => 'Gallery', 'gallery' => $gallery->id, @@ -112,17 +110,16 @@ class Horde_Block_ansel_gallery extends Horde_Block $html = Ansel::embedCode($params); // Be nice to people with