Clean up the Ansel_View_Base::json method.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 3 Aug 2009 19:00:42 +0000 (15:00 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 3 Aug 2009 19:00:42 +0000 (15:00 -0400)
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
ansel/lib/View/Base.php
ansel/lib/View/EmbeddedRenderer/Mini.php
ansel/lib/View/GalleryRenderer/GalleryLightbox.php
ansel/templates/view/slideshow.inc

index 568fff2..7205709 100755 (executable)
@@ -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();
index 0353c14..43596c1 100644 (file)
@@ -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:
+     *   <pre>
+     *      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]
+     *   </pre>
      *
      * @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,
index 6d6e804..b24b211 100644 (file)
@@ -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);
index 25c150f..87a532e 100644 (file)
@@ -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 = '[]';
             }
index 60b0a91..d9fe870 100644 (file)
@@ -1,11 +1,11 @@
 <script type="text/javascript">
 //<![CDATA[
-SlideController.initialize(<?php echo $this->json() ?>, <?php echo $imageIndex ?>, "<?php echo $GLOBALS['registry']->get('webroot')?>", <?php echo $this->gallery->id ?>, "<?php echo $this->gallery->getName()?>");
+SlideController.initialize(<?php echo $this->json(array('view_links' => true)) ?>, <?php echo $imageIndex ?>, "<?php echo $GLOBALS['registry']->get('webroot')?>", <?php echo $this->gallery->id ?>, "<?php echo $this->gallery->getName()?>");
 //]]>
 
 function stopSlideShow()
 {
-    location.href = "<?php echo Horde::applicationUrl($this->_urls['gallery'], true) ?>?image=" + SlideController.photos[SlideController.photoId][3] + "&view=Image&page=" + SlideController.photos[SlideController.photoId][4];
+    location.href = SlideController.photos[SlideController.photoId][5];
 }
 </script>
 
@@ -48,7 +48,7 @@ function stopSlideShow()
   <tr>
    <td style="margin:5px;height:<?php echo $GLOBALS['conf']['screen']['height'] ?>px;vertical-align:top;">
      <div id="Container">
-      <?php echo Horde::img('blank.gif', '', array('id' => 'Photo', 'style' => 'display:none;', 'width' => $this->_geometry['width'], 'height' => $this->_geometry['height']), $registry->getImageDir('horde')) ?>
+      <?php echo Horde::img('blank.gif', '', array('id' => 'Photo', 'style' => 'display:none;'), $registry->getImageDir('horde')) ?>
      </div>
    </td>
   </tr>