From da8edf29b881d9fb43485e61f4853e4be136b7dd Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Mon, 3 Aug 2009 15:00:42 -0400 Subject: [PATCH] Clean up the Ansel_View_Base::json method. Let the method take an array of paramters instead of a bunch of optional params. Pass the full link to the image view for each image instead of building it in JS to avoid issues with pretty vs GET based urls --- ansel/js/slideshow.js | 2 ++ ansel/lib/View/Base.php | 41 ++++++++++++++-------- ansel/lib/View/EmbeddedRenderer/Mini.php | 11 ++++-- ansel/lib/View/GalleryRenderer/GalleryLightbox.php | 4 +-- ansel/templates/view/slideshow.inc | 6 ++-- 5 files changed, 43 insertions(+), 21 deletions(-) diff --git a/ansel/js/slideshow.js b/ansel/js/slideshow.js index 568fff2d6..720570938 100755 --- a/ansel/js/slideshow.js +++ b/ansel/js/slideshow.js @@ -52,6 +52,7 @@ var SlideController = { }, /** + * */ play: function() { $('ssPlay').hide(); @@ -65,6 +66,7 @@ var SlideController = { }, /** + * Leaving this in here, but currently we just redirect back to the Image view */ pause: function() { $('ssPause').hide(); diff --git a/ansel/lib/View/Base.php b/ansel/lib/View/Base.php index 0353c1446..43596c1c9 100644 --- a/ansel/lib/View/Base.php +++ b/ansel/lib/View/Base.php @@ -138,26 +138,38 @@ abstract class Ansel_View_Base /** * JSON representation of this gallery's images. * - * @param array $images An array of Ansel_Image objects. If this is null - * the images are fetched based on $from and $count. - * - * @param integer $from Image to start at. - * @param integer $count Number of images to get. + * @param array $params An array of parameters for this method: + *
+     *      images -     Array of Ansel_Images to generate JSON for [null]
+     *      full   -     Should a full URL be generated? [false]
+     *      from   -     Starting image count [0]
+     *      count  -     The number of images to include (starting at from) [0]
+     *      image_view - The type of ImageView to obtain the src url for. [screen]
+     *      view_links - Should the JSON include links to the Image and/or Gallery View? [false]
+     *      perpage    - Number of images per page [from user prefs]
+     *   
* * @return string A serialized JSON array. */ - public function json($images = null, $full = false, $from = 0, $count = 0, - $image_view = 'screen', $view_links = false) + public function json($params = array()) { global $conf, $prefs; + $default = array('full' => false, + 'from' => 0, + 'count' => 0, + 'image_view' => 'screen', + 'view_links' => false, + 'perpage' => $prefs->getValue('tilesperpage', $conf['thumbnail']['perpage'])); + + $params = array_merge($default, $params); + $json = array(); - $perpage = $prefs->getValue('tilesperpage', $conf['thumbnail']['perpage']); $curimage = 0; $curpage = 0; - if (is_null($images)) { - $images = $this->gallery->getImages($from, $count); + if (empty($params['images'])) { + $images = $this->gallery->getImages($params['from'], $params['count']); } $style = $this->gallery->getStyle(); @@ -165,22 +177,23 @@ abstract class Ansel_View_Base foreach ($images as $image) { // Calculate the page this image will appear on in the // gallery view. - if (++$curimage > $perpage) { + if (++$curimage > $params['perpage']) { ++$curpage; $curimage = 0; } - $data = array(Ansel::getImageUrl($image->id, $image_view, $full, $style['name']), + $data = array(Ansel::getImageUrl($image->id, $params['image_view'], $params['full'], $style['name']), htmlspecialchars($image->filename, ENT_COMPAT, Horde_Nls::getCharset()), Horde_Text_Filter::filter($image->caption, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO_LINKURL)), $image->id, $curpage); - if ($view_links) { + if ($params['view_links']) { $data[] = Ansel::getUrlFor('view', array('gallery' => $this->gallery->id, 'slug' => $this->gallery->get('slug'), 'image' => $image->id, - 'view' => 'Image'), + 'view' => 'Image', + 'page' => $curpage), true); $data[] = Ansel::getUrlFor('view', array('gallery' => $image->gallery, diff --git a/ansel/lib/View/EmbeddedRenderer/Mini.php b/ansel/lib/View/EmbeddedRenderer/Mini.php index 6d6e804a3..b24b211f7 100644 --- a/ansel/lib/View/EmbeddedRenderer/Mini.php +++ b/ansel/lib/View/EmbeddedRenderer/Mini.php @@ -65,8 +65,15 @@ class Ansel_View_EmbeddedRenderer_Mini extends Ansel_View_Gallery } if (empty($images)) { - $json = $this->json(null, true, $start, $count, $thumbsize, true); - $json_full = $this->json(null, true, $start, $count, 'screen', true); + $json = $this->json(array('full' => true, + 'from' => $start, + 'count' => $count, + 'image_view' => $thumbsize, + 'view_links' => true)); + $json_full = $this->json(array('full' => true, + 'from' => $start, + 'count' => $count, + 'view_links' => true)); } else { $json = $GLOBALS['ansel_storage']->getImageJson($images, null, true, $thumbsize, true); $json_full = $GLOBALS['ansel_storage']->getImageJson($images, null, true, 'screen', true); diff --git a/ansel/lib/View/GalleryRenderer/GalleryLightbox.php b/ansel/lib/View/GalleryRenderer/GalleryLightbox.php index 25c150fd7..87a532e24 100644 --- a/ansel/lib/View/GalleryRenderer/GalleryLightbox.php +++ b/ansel/lib/View/GalleryRenderer/GalleryLightbox.php @@ -51,10 +51,10 @@ class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRende /* Get JSON data for view */ // 0 == normal, 1 == by date if ($this->mode == 0) { - $json = $this->view->json(null, !empty($this->view->api)); + $json = $this->view->json(array('full' => !empty($this->view->api)); } else { if (!empty($this->date['day']) && $this->numTiles) { - $json = $this->view->json(null, !empty($this->view->api)); + $json = $this->view->json(array('full' => !empty($this->view->api)); } else { $json = '[]'; } diff --git a/ansel/templates/view/slideshow.inc b/ansel/templates/view/slideshow.inc index 60b0a91ac..d9fe8703f 100644 --- a/ansel/templates/view/slideshow.inc +++ b/ansel/templates/view/slideshow.inc @@ -1,11 +1,11 @@ @@ -48,7 +48,7 @@ function stopSlideShow()
- 'Photo', 'style' => 'display:none;', 'width' => $this->_geometry['width'], 'height' => $this->_geometry['height']), $registry->getImageDir('horde')) ?> + 'Photo', 'style' => 'display:none;'), $registry->getImageDir('horde')) ?>
-- 2.11.0