support panoramas
[booh] / bin / booh-backend
index a9b4b7645e8c7fe1950bbaf46c9420cdf31d77cd..35ec7b4f26b8b1b9c01267db57af22cf05d87878 100755 (executable)
@@ -406,24 +406,35 @@ end
 
 def reset_iterations(iterations)
     for iter in iterations.values
-        iter['value'] = 1
+        iter['value'] = 0
     end
 end
 
-def run_iterations(iterations)
+def run_iterations(iterations, amount)
     html = ''
+    should_rerun = false
     for level in iterations.keys.sort
-        if iterations[level]['value'] == 1 || level == iterations.keys.max
+        if iterations[level]['value'] == 0
             html += iterations[level]['opening']
+        elsif level == iterations.keys.max
+            if !iterations[level]['max'] || iterations[level]['max'] && iterations[level]['value'] + amount <= iterations[level]['max'].to_i
+                html += iterations[level]['opening']
+            else
+                should_rerun = true
+            end
         end
-        iterations[level]['value'] += 1
+        iterations[level]['value'] += amount
         if iterations[level]['max'] && iterations[level]['value'] > iterations[level]['max'].to_i
-            iterations[level]['value'] = 1
-            iterations[level-1]['value'] = 1
+            iterations[level]['value'] = 0
+            iterations[level-1]['value'] = 0
             html += iterations[level-1]['closing']
         end
     end
-    return html
+    if should_rerun
+        return html + run_iterations(iterations, amount)
+    else
+        return html
+    end
 end
 
 def close_iterations(iterations)
@@ -696,6 +707,8 @@ def walk_source_dir
             thumbnail_videos ||= {}
             thumbnail_videos[sizeobj['name']] = []
         end
+        #- a special dummy size to keep 'references' to thumbnails in case of panorama, because the GUI will use the regular thumbnails
+        thumbnail_images['dont-delete-file-for-gui'] = []
         if $limit_sizes =~ /original/
             fullscreen_images['original'] = []
         end
@@ -711,14 +724,19 @@ def walk_source_dir
                 gen_thumbnails_element("#{dir}/#{img}", xmldir, true, [ { 'filename' => thumbnail_dest_img, 'size' => $default_size['thumbnails'] } ])
             else
                 todo = []
+                elem = xmldir.elements["image[@filename='#{utf8(img)}']"]
                 for sizeobj in $images_size
                     size_fullscreen = sizeobj['fullscreen']
                     size_thumbnails = sizeobj['thumbnails']
                     fullscreen_dest_img = base_dest_img + "-#{size_fullscreen}.jpg"
-                    thumbnail_dest_img  = base_dest_img + "-#{size_thumbnails}.jpg"
                     fullscreen_images[sizeobj['name']] << File.basename(fullscreen_dest_img)
-                    thumbnail_images[sizeobj['name']]  << File.basename(thumbnail_dest_img)
                     todo << { 'filename' => fullscreen_dest_img, 'size' => size_fullscreen }
+                    if pano = pano_amount(elem)
+                        thumbnail_images['dont-delete-file-for-gui'] << File.basename(base_dest_img + "-#{size_thumbnails}.jpg")
+                        size_thumbnails = size_thumbnails.sub(/(\d+)/) { ($1.to_i * pano).to_i }
+                    end
+                    thumbnail_dest_img = base_dest_img + "-#{size_thumbnails}.jpg"
+                    thumbnail_images[sizeobj['name']] << File.basename(thumbnail_dest_img)
                     todo << { 'filename' => thumbnail_dest_img,  'size' => size_thumbnails }
                 end
                 gen_thumbnails_element("#{dir}/#{img}", xmldir, true, todo)
@@ -795,7 +813,18 @@ def walk_source_dir
                 for file in entries
                     type = images.include?(file) ? 'image' : videos.include?(file) ? 'video' : nil
                     if type
-                        html_thumbnails += run_iterations(iterations)
+                        if type == 'image' && elem = xmldir.elements["image[@filename='#{utf8(file)}']"]
+                            if  pano = pano_amount(elem)
+                                html_thumbnails += run_iterations(iterations, pano)
+                                html_thumbnails.gsub!(/~~colspan~~/) { 'colspan="' + pano.ceil.to_s + '"' }
+                            else
+                                html_thumbnails += run_iterations(iterations, 1)
+                                html_thumbnails.gsub!(/~~colspan~~/, '')
+                            end
+                        else 
+                            html_thumbnails += run_iterations(iterations, 1)
+                            html_thumbnails.gsub!(/~~colspan~~/, '')
+                        end
                         if type == 'image'
                             index = images.index(file)
                             html_thumbnails.gsub!(/~~image_iteration~~/,
@@ -976,7 +1005,7 @@ def walk_source_dir
                 thumbnail = "#{dest_dir}/thumbnails-thumbnail.jpg"
                 gen_thumbnails_subdir(from_utf8(xmldir.attributes['thumbnails-captionfile']), xmldir, false,
                                       [ { 'filename' => thumbnail, 'size' => $albums_thumbnail_size } ], 'thumbnails')
-                html_index += run_iterations(iterations)
+                html_index += run_iterations(iterations, 1)
                 html_index.gsub!(/~~image_iteration~~/, "<a href='thumbnails.html'>" + img_element(thumbnail) + '</a>')
                 html_index.gsub!(/~~caption_iteration~~/, xmldir.attributes['thumbnails-caption'])
             end
@@ -988,7 +1017,7 @@ def walk_source_dir
                 end
                 subdir = make_dest_filename(from_utf8(File.basename(child.attributes['path'])))
                 thumbnail = "#{dest_dir}/thumbnails-#{subdir}.jpg"
-                html_index += run_iterations(iterations)
+                html_index += run_iterations(iterations, 1)
                 captionfile, caption = find_subalbum_caption_info(child)
                 gen_thumbnails_subdir(captionfile, child, false,
                                       [ { 'filename' => thumbnail, 'size' => $albums_thumbnail_size } ], find_subalbum_info_type(child))