no longer use internalized rexml
[booh] / bin / booh-backend
old mode 100755 (executable)
new mode 100644 (file)
index ed4b7e9..12de9d8
@@ -10,7 +10,7 @@
 # called Boo, so this one will be it "Booh". Or whatever.
 #
 #
-# Copyright (c) 2004-2011 Guillaume Cottenceau <http://zarb.org/~gc/resource/gc_mail.png>
+# Copyright (c) 2004-2013 Guillaume Cottenceau <http://zarb.org/~gc/resource/gc_mail.png>
 #
 # This software may be freely redistributed under the terms of the GNU
 # public license version 2.
@@ -34,7 +34,7 @@ rescue LoadError
 end
 require 'gettext'
 include GetText
-require 'booh/rexml/document'
+require 'rexml/document'
 include REXML
 
 require 'booh/booh-lib'
@@ -69,7 +69,7 @@ $options = [
     [ '--thumbnails-per-page', '-p', GetoptLong::REQUIRED_ARGUMENT, _("Specify the amount of thumbnails per page in the thumbnails page, after which split occurs") ],
     [ '--optimize-for-32', '-o', GetoptLong::NO_ARGUMENT, _("Resize images with optimized sizes for 3/2 aspect ratio rather than 4/3 (typical aspect ratio of photos from point-and-shoot cameras - also called compact cameras - is 4/3, whereas photos from SLR cameras - also called reflex cameras - is 3/2)") ],
     [ '--transcode-videos', '-r', GetoptLong::REQUIRED_ARGUMENT, _("Transcode videos with given external program; %f is the placeholder for the input video, %o for the output video; before the external program, the output video extension should be given followed by a colon") ],
-    [ '--flv-generator', '-F', GetoptLong::REQUIRED_ARGUMENT, _("Use embedded flash player for videos (flowplayer) and use this .flv generator (%f is the placeholder for the input video, %o for the output video)") ],
+    [ '--mp4-generator', '-F', GetoptLong::REQUIRED_ARGUMENT, _("Use this .mp4 generator (%f is the placeholder for the input video, %o for the output video)") ],
     [ '--index-link',    '-l', GetoptLong::REQUIRED_ARGUMENT, _("Specify the HTML markup to use on the bottom of pages for a small link returning to wherever you see fit in your website (or somewhere else)") ],
     [ '--addthis', '-a', GetoptLong::NO_ARGUMENT, _("Include the 'addthis' bookmarking and sharing button") ],
     [ '--made-with',     '-n', GetoptLong::REQUIRED_ARGUMENT, _("Specify the HTML markup to use on the bottom of pages for a small 'made with' message") ],
@@ -112,7 +112,7 @@ def handle_options
             when '--version'
                 puts _("Booh version %s
 
-Copyright (c) 2005-2011 Guillaume Cottenceau.
+Copyright (c) 2005-2013 Guillaume Cottenceau.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") % $VERSION
 
@@ -234,11 +234,11 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
                 end
                 $transcode_videos = arg
 
-            when '--flv-generator'
+            when '--mp4-generator'
                 if arg !~ /%f/ || arg !~ /%o/
-                    die _("--flv-generator: argument must contain %f for the input video and %o for the output video")
+                    die _("--mp4-generator: argument must contain %f for the input video and %o for the output video")
                 end
-                $flv_generator = arg
+                $mp4_generator = arg
 
             when '--made-with'
                 $madewith = arg
@@ -315,7 +315,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
         die _("Missing --destination parameter.")
     end
     if !$theme
-        $theme = 'simple'
+        $theme = 'gradient'
     end
 
     select_theme($theme, $limit_sizes, $optimize_for_32, $N_per_row)
@@ -414,10 +414,10 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
         $xmldoc.root.delete_attribute('transcode-videos')
     end
 
-    if $flv_generator
-        $xmldoc.root.add_attribute('flv-generator', $flv_generator)
+    if $mp4_generator
+        $xmldoc.root.add_attribute('mp4-generator', $mp4_generator)
     else
-        $xmldoc.root.delete_attribute('flv-generator')
+        $xmldoc.root.delete_attribute('mp4-generator')
     end
 
     if $madewith
@@ -943,6 +943,12 @@ def walk_source_dir
         if !$forgui
             ios = File.open("#{dest_dir}/.htaccess", "w")
             ios.write("AddCharset UTF-8 .html\n")
+            ios.write("\n")
+            ios.write("<IfModule mod_expires.c>\n")
+            ios.write(" ExpiresActive On\n")
+            ios.write(" ExpiresDefault A1800\n")
+            ios.write("</IfModule>")
+            ios.write("\n")
             if auth_user_file = xmldir.attributes['password-protect']
                 msg 3, _("\tgenerating password protection file #{dest_dir}/.htaccess")
                 ios.write("AuthType Basic\nAuthName \"protected area\"\nAuthUserFile #{auth_user_file}\nrequire valid-user\n")
@@ -996,10 +1002,6 @@ def walk_source_dir
                             psys("cp '#{$themedir}/root/#{entry}' '#{dest_dir}'")
                         end
                     }
-                    #- copy flowplayer stuff if needed
-                    if $flv_generator
-                        psys("cp #{$FPATH}/flowplayer/flowplayer* '#{dest_dir}'")
-                    end
                 end
             end
             next
@@ -1049,7 +1051,7 @@ def walk_source_dir
                     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 }
+                    todo << { 'filename' => thumbnail_dest_img, 'size' => size_thumbnails }
                 end
                 gen_thumbnails_element("#{dir}/#{img}", elem, true, todo)
                 if $limit_sizes =~ /original/
@@ -1071,7 +1073,7 @@ def walk_source_dir
 
         videos.size >= 1 and msg 3, _("\tcreating videos thumbnails...")
         transcoded_videos = {}
-        flv_videos = {}
+        mp4_videos = {}
 
         #- create thumbnails for videos
         videos.each { |video|
@@ -1104,16 +1106,18 @@ def walk_source_dir
                         psys(parts[1].gsub(/%f/, "'#{dir}/#{video}'").gsub(/%o/, "'#{destvideo}'"))
                     end
 
-                elsif $flv_generator
-                    basedestvideo = video.sub(/\.\w+/, '') + '.flv'
-                    flv_videos[video] = basedestvideo
+                elsif $mp4_generator
+                    msg 3, "video1"
+                    basedestvideo = video.sub(/\.\w+/, '') + '.mp4'
+                    mp4_videos[video] = basedestvideo
                     destvideo = "#{dest_dir}/#{basedestvideo}"
                     if File.exists?(destvideo) && File.size(destvideo) == 0
                         File.delete(destvideo)
                     end
                     if ! File.exists?(destvideo)
-                        psys($flv_generator.gsub(/%f/, "'#{dir}/#{video}'").gsub(/%o/, "'#{destvideo}'"))
+                        psys($mp4_generator.gsub(/%f/, "'#{dir}/#{video}'").gsub(/%o/, "'#{destvideo}'"))
                     end
+                    msg 3, "video2"
 
                 else
                     destvideo = "#{dest_dir}/#{video}"
@@ -1137,11 +1141,11 @@ def walk_source_dir
                      concat(thumbnail_images.collect { |e| e[1] }.flatten).
                      concat(fullscreen_videos.collect { |e| e[1] }.flatten).
                      concat(thumbnail_videos.collect { |e| e[1] }.flatten).
-                     concat($transcode_videos ? transcoded_videos.values : $flv_generator ? flv_videos.values : videos).
+                     concat($transcode_videos ? transcoded_videos.values : $mp4_generator ? mp4_videos.values : videos).
                      push('.htaccess')
             to_del = Dir.entries(dest_dir).find_all { |e| !File.directory?(File.join(dest_dir, e)) && !all_elements.include?(e) && e !~ /^thumbnails-\w+\.jpg/ }
             if to_del.size > 0
-                msg 3, _("\tcleaning up: #{to_del.join(', ')}")
+                msg 3, _("\tcleaning up: ") + to_del.join(', ')
                 File.delete(*to_del.collect { |e| File.join(dest_dir, e) })
             end
 
@@ -1163,10 +1167,6 @@ def walk_source_dir
                         psys("cp '#{$themedir}/root/#{entry}' '#{dest_dir}'")
                     end
                 }
-                #- copy flowplayer stuff if needed
-                if $flv_generator
-                    psys("cp #{$FPATH}/flowplayer/flowplayer* '#{dest_dir}'")
-                end
             end
             
             msg 3, _("\tgenerating HTML pages...")
@@ -1183,7 +1183,6 @@ def walk_source_dir
                 iterations = {}
                 for i in html
                     i.sub!(/~~title~~/, quote_caption(xmldir.attributes['thumbnails-caption'] || utf8(File.basename(dir))))
-                    i.sub!(/~~flowplayer_head_code~~/, ($flv_generator && videos.size > 0) ? '<script type="text/javascript" src="~~pathtobase~~flowplayer-3.2.6.min.js"></script>' : '')
                     discover_iterations(iterations, i)
                 end
                 all_pages = []
@@ -1232,17 +1231,16 @@ def walk_source_dir
                             else
                                 video_preview = defer_translation(N_("(no preview)"))
                             end
-                            if $flv_generator
+                            if $mp4_generator
                                 size = get_image_size("#{dest_dir}/#{thumbnail_videos[sizeobj['name']][index]}")
                                 if ! size
                                     sizeobj['thumbnails'] =~ /(\d+)x(\d+)/
                                     size = { :x => $1, :y => $2 }
                                 end
                                 sizespec = 'width:' + size[:x].to_s + 'px;height:' + (size[:y] + 24).to_s + 'px'
-                                image_iteration = '<a href="' + flv_videos[videos[index]] + '" style="display:block;' + sizespec + '"' +
+                                image_iteration = '<a href="' + mp4_videos[videos[index]] + '" style="display:block;' + sizespec + '"' +
                                                   '   id="player' + index.to_s + '">' + video_preview +
-                                                  '<img src="~~pathtobase~~play_video.png" style="position:relative;top:-' + ((size[:y]+48)/2).to_s + 'px;border:0;background-color:transparent"/></a>' +
-                                                  '<script>flowplayer("player' + index.to_s + '", "~~pathtobase~~flowplayer-3.2.7.swf")</script>'
+                                                  '<img src="~~pathtobase~~play_video.png" style="position:relative;top:-' + ((size[:y]+48)/2).to_s + 'px;border:0;background-color:transparent"/></a>'
                                 html_elem.gsub!(/~~image_iteration~~/, apply_hook(:image_iteration, image_iteration, 'video'))
                             else
                                 html_elem.gsub!(/~~image_iteration~~/,
@@ -1365,8 +1363,8 @@ def walk_source_dir
                     types4js << '"' + type + '"'
                     if type == 'video'
                         index = videos.index(file)
-                        if $flv_generator
-                            videos4js << '"' + flv_videos[videos[index]] + '"'
+                        if $mp4_generator
+                            videos4js << '"' + mp4_videos[videos[index]] + '"'
                         else
                             videos4js << '"' + videos[index] + '"'
                         end
@@ -1378,26 +1376,32 @@ def walk_source_dir
 
             for sizeobj in $images_size
                 elements4js = []
-                videoswidths4js = []
-                videosheights4js = []
+                elemswidths4js = []
+                elemsheights4js = []
                 for file in entries
                     type = images.include?(file) ? 'image' : videos.include?(file) ? 'video' : nil
                     if type
                         if type == 'image'
                             index = images.index(file)
                             elements4js << '"' + fullscreen_images[sizeobj['name']][index] + '"'
-                            videoswidths4js << "''"
-                            videosheights4js << "''"
+                            size = get_image_size("#{dest_dir}/#{fullscreen_images[sizeobj['name']][index]}")
+                            if size
+                                elemswidths4js << size[:x].to_s
+                                elemsheights4js << size[:y].to_s
+                            else
+                                elemswidths4js << "''"
+                                elemsheights4js << "''"
+                            end
                         else
                             index = videos.index(file)
                             elements4js << '"' + fullscreen_videos[sizeobj['name']][index] + '"'
                             size = get_image_size("#{dest_dir}/#{fullscreen_videos[sizeobj['name']][index]}")
                             if size
-                                videoswidths4js << size[:x].to_s
-                                videosheights4js << size[:y].to_s
+                                elemswidths4js << size[:x].to_s
+                                elemsheights4js << size[:y].to_s
                             else
-                                videoswidths4js << "''"
-                                videosheights4js << "''"
+                                elemswidths4js << "''"
+                                elemsheights4js << "''"
                             end
                         end
                     end
@@ -1430,21 +1434,14 @@ def walk_source_dir
                     i.gsub!(/~~images~~/, elements4js.join(', '))
                     i.gsub!(/~~types~~/, types4js.join(', '))
                     i.gsub!(/~~videos~~/, videos4js.join(', '))
-                    i.gsub!(/~~videos_widths~~/, videoswidths4js.join(', '))
-                    i.gsub!(/~~videos_heights~~/, videosheights4js.join(', '))
+                    i.gsub!(/~~widths~~/, elemswidths4js.join(', '))
+                    i.gsub!(/~~heights~~/, elemsheights4js.join(', '))
                     i.gsub!(/~~hidden_images_for_remotes~~/, hiddenimages4remotes)
                     i.gsub!(/~~other_images~~/, otherelements4js)
                     i.gsub!(/~~thumbnailspages~~/, element2thumbnailpage4js.collect { |e| "\"#{e}\"" }.join(', '))
                     i.gsub!(/~~other_sizes~~/, othersizes.join(', '))
                     i.gsub!(/~~captions~~/, captions4js.join(', '))
                     i.gsub!(/~~title~~/, quote_caption(xmldir.attributes['thumbnails-caption'] || utf8(File.basename(dir))))
-                    if $flv_generator && videos.size > 0
-                        i.sub!(/~~flowplayer_head_code~~/, '<script type="text/javascript" src="~~pathtobase~~flowplayer-3.2.6.min.js"></script>')
-                        i.sub!(/~~flowplayer_active~~/, 'true')
-                    else
-                        i.sub!(/~~flowplayer_head_code~~/, '')
-                        i.sub!(/~~flowplayer_active~~/, 'false')
-                    end
 
                     i.gsub!(/~~thumbnails~~/, '<a id="thumbnails">' + defer_translation(N_('return to thumbnails')) + '</a>')
                     i.gsub!(/~~theme~~/, $theme)