5 # A.k.a 'Best web-album Of the world, Or your money back, Humerus'.
7 # The acronyn sucks, however this is a tribute to Dragon Ball by
8 # Akira Toriyama, where the last enemy beaten by heroes of Dragon
9 # Ball is named "Boo". But there was already a free software project
10 # called Boo, so this one will be it "Booh". Or whatever.
13 # Copyright (c) 2004-2008 Guillaume Cottenceau <http://zarb.org/~gc/resource/gc_mail.png>
15 # This software may be freely redistributed under the terms of the GNU
16 # public license version 2.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 require 'gettext/locale'
26 require 'booh/rexml/document'
29 require 'booh/booh-lib'
30 require 'booh/html-merges'
32 #- bind text domain as soon as possible because some _() functions are called early to build data structures
33 bindtextdomain("booh")
34 #- save locale for restoring for multi languages
35 $default_locale = Locale.get
39 [ '--help', '-h', GetoptLong::NO_ARGUMENT, _("Get help message") ],
40 [ '--version', '-V', GetoptLong::NO_ARGUMENT, _("Print version and exit") ],
42 [ '--source', '-s', GetoptLong::REQUIRED_ARGUMENT, _("Directory which contains original images/videos as files or subdirs") ],
43 [ '--destination', '-d', GetoptLong::REQUIRED_ARGUMENT, _("Directory which will contain the web-album") ],
44 # [ '--clean', '-c', GetoptLong::NO_ARGUMENT, _("Clean destination directory") ],
46 [ '--theme', '-t', GetoptLong::REQUIRED_ARGUMENT, _("Select HTML theme to use") ],
47 [ '--config', '-C', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing images and videos within directories with captions") ],
48 [ '--config-skel', '-k', GetoptLong::REQUIRED_ARGUMENT, _("Filename where the script will output a config skeleton") ],
49 [ '--merge-config', '-M', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, where to merge new/removed images/videos from --source, and change theme info") ],
50 [ '--merge-config-onedir', '-O', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, for merging the subdir specified with --dir") ],
51 [ '--merge-config-subdirs', '-U', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, for merging the new subdirs down the subdir specified with --dir") ],
52 [ '--dir', '-D', GetoptLong::REQUIRED_ARGUMENT, _("Directory for merge with --merge-config-onedir or --merge-config-subdirs") ],
53 [ '--use-config', '-u', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, where to change theme info") ],
54 [ '--force', '-f', GetoptLong::NO_ARGUMENT, _("Force generation of album even if the GUI marked some directories as already generated") ],
56 [ '--sizes', '-S', GetoptLong::REQUIRED_ARGUMENT, _("Specify the list of images sizes to use instead of all specified in the theme (this is a comma-separated list)") ],
57 [ '--multi-languages', '-L', GetoptLong::REQUIRED_ARGUMENT, _("Specify the list of languages to support (uses Apache MultiViews); this is a comma-separated list of supported languages, with last element used as the fallback language; for example: 'fr,eo,en,en'; supported languages: %s") % SUPPORTED_LANGUAGES.join(', ') ],
58 [ '--thumbnails-per-row', '-T', GetoptLong::REQUIRED_ARGUMENT, _("Specify the amount of thumbnails per row in the thumbnails page (if applicable in theme)") ],
59 [ '--thumbnails-per-page', '-p', GetoptLong::REQUIRED_ARGUMENT, _("Specify the amount of thumbnails per page in the thumbnails page, after which split occurs") ],
60 [ '--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 pictures from non digital cameras are 3/2 when pictures from digital cameras are 4/3)") ],
61 [ '--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)") ],
62 [ '--made-with', '-n', GetoptLong::REQUIRED_ARGUMENT, _("Specify the HTML markup to use on the bottom of pages for a small 'made with' message") ],
63 [ '--comments-format','-c', GetoptLong::REQUIRED_ARGUMENT, _("Specify comments format to use for images instead of only filename when creating new albums; use ImageMagick's format") ],
65 [ '--mproc', '-m', GetoptLong::REQUIRED_ARGUMENT, _("Specify the number of processors for multi-processors machines") ],
67 [ '--for-gui', '-g', GetoptLong::NO_ARGUMENT, _("Do the minimum work to be able to see the album under the GUI (don't generate all thumbnails)") ],
69 [ '--verbose-level', '-v', GetoptLong::REQUIRED_ARGUMENT, _("Set max verbosity level (0: errors, 1: warnings, 2: important messages, 3: other messages)") ],
70 [ '--info-pipe', '-i', GetoptLong::REQUIRED_ARGUMENT, _("Name a file where to write information about what's going on (used by the GUI)") ],
73 #- default values for some globals
77 $ignore_videos = false
82 puts _("Usage: %s [OPTION]...") % File.basename($0)
84 printf " %3s, %-18s %s\n", ary[1], ary[0], ary[3]
89 parser = GetoptLong.new
90 parser.set_options(*$options.collect { |ary| ary[0..2] })
92 parser.each_option do |name, arg|
99 puts _("Booh version %s
101 Copyright (c) 2005 Guillaume Cottenceau.
102 This is free software; see the source for copying conditions. There is NO
103 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") % $VERSION
108 $source = File.expand_path(arg.sub(%r|/$|, ''))
109 if !File.directory?($source)
110 die _("Argument to --source must be a directory")
113 $dest = File.expand_path(arg.sub(%r|/$|, ''))
114 if File.exists?($dest) && !File.directory?($dest)
115 die _("If --destination exists, it must be a directory")
117 if $dest != make_dest_filename($dest)
118 die _("Sorry, destination directory can't contain non simple alphanumeric characters.")
121 # system("rm -rf #{$dest}")
126 arg = File.expand_path(arg)
127 if File.readable?(arg)
128 $xmldoc = REXML::Document.new File.new(arg)
131 die _('Config file does not exist or is unreadable.')
134 arg = File.expand_path(arg)
136 if File.directory?(arg)
137 die _("Config skeleton file (%s) already exists and is a directory! Please change the filename.") % arg
139 msg 1, _("Config skeleton file already exists, backuping to %s.backup") % arg
140 File.rename(arg, "#{arg}.backup")
143 $config_writeto = arg
145 when '--merge-config'
146 arg = File.expand_path(arg)
147 if File.readable?(arg)
148 msg 2, _("Merge config notice: backuping current config file to %s.backup") % arg
149 $xmldoc = REXML::Document.new File.new(arg)
150 File.rename(arg, "#{arg}.backup")
151 $config_writeto = arg
152 $mode = 'merge_config'
154 die _('Config file does not exist or is unreadable.')
156 when '--merge-config-onedir'
157 arg = File.expand_path(arg)
158 if File.readable?(arg)
159 msg 2, _("Merge config notice: backuping current config file to %s.backup") % arg
160 $xmldoc = REXML::Document.new File.new(arg)
161 File.rename(arg, "#{arg}.backup")
162 $config_writeto = arg
163 $mode = 'merge_config_onedir'
165 die _('Config file does not exist or is unreadable.')
167 when '--merge-config-subdirs'
168 arg = File.expand_path(arg)
169 if File.readable?(arg)
170 msg 2, _("Merge config notice: backuping current config file to %s.backup") % arg
171 $xmldoc = REXML::Document.new File.new(arg)
172 File.rename(arg, "#{arg}.backup")
173 $config_writeto = arg
174 $mode = 'merge_config_subdirs'
176 die _('Config file does not exist or is unreadable.')
179 arg = File.expand_path(arg)
180 if !File.readable?(arg)
181 die _('Specified directory to merge with --dir is not readable')
186 arg = File.expand_path(arg)
187 if File.readable?(arg)
188 msg 2, _("Use config notice: backuping current config file to %s.backup") % arg
189 $xmldoc = REXML::Document.new File.new(arg)
190 File.rename(arg, "#{arg}.backup")
191 $config_writeto = arg
192 $mode = 'use_config_changetheme'
194 die _('Config file does not exist or is unreadable.')
200 when '--multi-languages'
201 parts = arg.split(',')
202 if parts.size == 0 || parts.find_all { |e| ! SUPPORTED_LANGUAGES.include?(e.strip) }.size > 0
203 die _("--multi-languages: argument must be a comma-separated list of supported languages, with last element used as the fallback language; for example: 'fr,eo,en,en'; supported languages: %s") % SUPPORTED_LANGUAGES.join(', ')
205 $multi_languages = [ parts[0..-2], parts[-1] ]
207 when '--thumbnails-per-row'
210 when '--thumbnails-per-page'
213 when '--optimize-for-32'
214 $optimize_for_32 = true
222 when '--comments-format'
223 $commentsformat = arg
235 when '--verbose-level'
236 $verbose_level = arg.to_i
239 $info_pipe = File.open(arg, File::WRONLY)
240 $info_pipe.sync = true
249 if !$source && $xmldoc
250 $source = from_utf8($xmldoc.root.attributes['source']).sub(%r|/$|, '')
251 $dest = from_utf8($xmldoc.root.attributes['destination']).sub(%r|/$|, '')
252 $theme ||= $xmldoc.root.attributes['theme']
253 $limit_sizes ||= $xmldoc.root.attributes['limit-sizes']
254 if $mode == 'use_config' || $mode =~ /^merge_config/
255 $optimize_for_32 = !$xmldoc.root.attributes['optimize-for-32'].nil?
256 $N_per_row = $xmldoc.root.attributes['thumbnails-per-row']
257 languages = $xmldoc.root.attributes['multi-languages']
259 languages = languages.split(',')
260 $multi_languages = [ languages[0..-2], languages[-1] ]
262 $N_per_page = $xmldoc.root.attributes['thumbnails-per-page']
263 $madewith = $xmldoc.root.attributes['made-with']
264 $indexlink = $xmldoc.root.attributes['index-link']
268 if $mode == 'merge_config_onedir' && !$onedir
269 die _("Missing --dir for --merge-config-onedir")
271 if $mode == 'merge_config_subdirs' && !$onedir
272 die _("Missing --dir for --merge-config-subdirs")
280 die _("Missing --destination parameter.")
286 select_theme($theme, $limit_sizes, $optimize_for_32, $N_per_row)
289 additional_params = ''
291 additional_params += "limit-sizes='#{$limit_sizes}'"
294 additional_params += " multi-languages='#{$multi_languages[0].join(',')},#{$multi_languages[1]}'"
297 additional_params += " optimize-for-32='true'"
300 additional_params += " thumbnails-per-row='#{$N_per_row}'"
303 additional_params += " thumbnails-per-page='#{$N_per_page}'"
306 additional_params += " made-with='#{$madewith}'"
309 additional_params += " index-link='#{$indexlink}'"
311 $xmldoc = Document.new "<booh version='#{$VERSION}' source='#{utf8($source)}' destination='#{utf8($dest)}' theme='#{$theme}' #{additional_params}/>"
312 $xmldoc << XMLDecl.new(XMLDecl::DEFAULT_VERSION, $CURRENT_CHARSET)
316 if $mode == 'merge_config' || $mode == 'use_config_changetheme'
317 $xmldoc.root.add_attribute('theme', $theme)
318 $xmldoc.root.add_attribute('version', $VERSION)
320 $xmldoc.root.add_attribute('limit-sizes', $limit_sizes)
322 $xmldoc.root.delete_attribute('limit-sizes')
325 $xmldoc.root.add_attribute('multi-languages', $multi_languages[0].join(',') + ',' + $multi_languages[1])
327 $xmldoc.root.delete_attribute('multi-languages')
331 $xmldoc.root.add_attribute('optimize-for-32', 'true')
333 $xmldoc.root.delete_attribute('optimize-for-32')
336 $xmldoc.root.add_attribute('thumbnails-per-row', $N_per_row)
338 $xmldoc.root.delete_attribute('thumbnails-per-row')
341 $xmldoc.root.add_attribute('thumbnails-per-page', $N_per_page)
343 $xmldoc.root.delete_attribute('thumbnails-per-page')
346 $xmldoc.root.add_attribute('made-with', $madewith)
348 $xmldoc.root.delete_attribute('made-with')
351 $xmldoc.root.add_attribute('index-link', $indexlink)
353 $xmldoc.root.delete_attribute('index-link')
358 $madewith = $madewith.gsub('%booh', '"http://booh.org/"')
363 $htmlsuffix = '.html'
376 $info_pipe.puts(value)
382 $info_pipe.puts("die: " + value)
387 def check_installation
388 if !system("which convert >/dev/null 2>/dev/null")
389 die _("The program 'convert' is needed. Please install it.
390 It is generally available with the 'ImageMagick' software package.")
392 if !system("which identify >/dev/null 2>/dev/null")
393 msg 1, _("the program 'identify' is needed to get images sizes and EXIF data. Please install it.
394 It is generally available with the 'ImageMagick' software package.")
397 missing = %w(mplayer).delete_if { |prg| system("which #{prg} >/dev/null 2>/dev/null") }
399 msg 1, _("the following program(s) are needed to handle videos: '%s'. Videos will be ignored.") % missing.join(', ')
400 $ignore_videos = true
404 def replace_line(surround, keyword, line)
406 contents = eval "$#{keyword}"
407 line.sub!(/#{surround}#{keyword}#{surround}/, contents)
409 die _("No '%s' found for substitution") % keyword
413 def build_html_skeletons
414 $html_images = File.open("#{$FPATH}/themes/#{$theme}/skeleton_image.html").readlines
415 $html_thumbnails = File.open("#{$FPATH}/themes/#{$theme}/skeleton_thumbnails.html").readlines
416 $html_index = File.open("#{$FPATH}/themes/#{$theme}/skeleton_index.html").readlines
417 for line in $html_images + $html_thumbnails + $html_index
418 while line =~ /~~~(\w+)~~~/
419 replace_line('~~~', $1, line)
424 def find_caption_value(xmldir, filename)
425 if cap = xmldir.elements["*[@filename='#{utf8(filename)}']"].attributes['caption']
426 return cap.gsub("\n", '<br/>')
432 def find_captions(xmldir, images)
433 return images.collect { |img| find_caption_value(xmldir, img) }
436 #- stolen from CVSspam
438 text.sub(/[^a-zA-Z0-9\-,.*_\/]/) do
439 "%#{sprintf('%2X', $&[0])}"
444 return $limit_sizes =~ /original/ ? $images_size + [ { 'name' => 'original' } ] : $images_size
447 def html_reload_to_thumbnails
448 html_reload_to_thumbnails = $preferred_size_reloader.clone
449 html_reload_to_thumbnails.gsub!(/~~theme~~/, $theme)
450 html_reload_to_thumbnails.gsub!(/~~default_size~~/, $default_size['name'])
451 html_reload_to_thumbnails.gsub!(/~~htmlsuffix~~/, $htmlsuffix)
452 html_reload_to_thumbnails.gsub!(/~~all_sizes~~/, all_images_sizes.collect { |s| "\"#{size2js(s['name'])}\"" }.join(', '))
453 size_auto_chooser = '';
454 all_images_sizes.find_all { |s| s.has_key?('optimizedforwidth') }.
455 sort { |a,b| b['optimizedforwidth'].to_i <=> a['optimizedforwidth'].to_i }.
456 each { |s| size_auto_chooser += "if (w + 50 > #{s['optimizedforwidth']}) { return 'thumbnails-#{size2js(s['name'])}-0#{$htmlsuffix}'; }\n" }
457 html_reload_to_thumbnails.gsub!(/~~size_auto_chooser~~/, size_auto_chooser)
458 return html_reload_to_thumbnails
461 def discover_iterations(iterations, line)
462 if line =~ /~~iterate(\d)_open(_max(\d+|N))?~~/
463 for iter in iterations.values
466 iter['close_wait'] = $1.to_i
469 max = $3 == 'N' ? ($N_per_row || $default_N) : $3
470 iterations[$1.to_i] = { 'open' => true, 'max' => max, 'opening' => '', 'closing' => '' }
472 line.sub!(/.*/, '~~thumbnails~~')
476 elsif line =~ /~~iterate(\d)_close~~/
477 iterations[$1.to_i]['open'] = false;
478 iterations[$1.to_i]['close'] = true;
481 for iter in iterations.values
483 iter['opening'] += line
486 if !iter['close'] && iter['close_wait'] && iterations[iter['close_wait']]['close']
487 iter['closing'] += line
494 def reset_iterations(iterations)
495 for iter in iterations.values
500 def run_iterations(iterations, amount)
503 for level in iterations.keys.sort
504 if iterations[level]['value'] == 0
505 html += iterations[level]['opening']
506 elsif level == iterations.keys.max
507 if !iterations[level]['max'] || iterations[level]['max'] && iterations[level]['value'] + amount <= iterations[level]['max'].to_i
508 html += iterations[level]['opening']
513 iterations[level]['value'] += amount
514 if iterations[level]['max'] && iterations[level]['value'] > iterations[level]['max'].to_i
515 iterations[level]['value'] = 0
516 iterations[level-1]['value'] = 0
517 html += iterations[level-1]['closing']
521 return html + run_iterations(iterations, amount)
527 def close_iterations(iterations)
529 for level in iterations.keys.sort.reverse
530 html += iterations[level]['closing']
535 def img_element(fullpath)
536 if size = get_image_size(fullpath)
537 sizespec = 'width="' + size[:x].to_s + '" height="' + size[:y].to_s + '"'
541 return '<img src="' + File.basename(fullpath) + '" ' + sizespec + ' alt="image"/>'
545 return name.gsub(/-/, '')
548 def substitute_html_sizes(html, sizeobj, type, suffix)
550 if $images_size.length > 1 || (type == 'image' && $limit_sizes =~ /original/)
551 for sizeobj2 in $images_size
552 sizejs = size2js(sizeobj2['name'])
553 sizen = defer_translation(sizename(sizeobj2['name'], false))
554 if sizeobj != sizeobj2
555 if type == 'thumbnails'
556 sizestrings << '<a href="thumbnails-' + sizejs + suffix + $htmlsuffix + '" onclick="set_preferred_size(\'' + sizejs + '\')">' + sizen + '</a>'
558 sizestrings << '<a id="link' + sizejs + '" onclick="set_preferred_size(\'' + sizejs + '\')">' + sizen + '</a>'
564 if type == 'image' && $limit_sizes =~ /original/
565 sizestrings << '<a id="linkoriginal" target="newframe">' + defer_translation(sizename('original'), false) + '</a>'
568 html.sub!(/~~sizes~~(.+)~~/) { sizestrings.join($1) }
571 def substitute_navigation(html, xmldir)
572 if xmldir.parent.name == 'dir'
575 parent = xmldir.parent
576 while parent.name == 'dir'
577 parentcaption = parent.attributes['subdirs-caption'] || File.basename(parent.attributes['path'])
578 nav = "<a href=\"#{path}/index#{$htmlsuffix}\">#{parentcaption}</a> #{defer_translation(N_(" > "))} #{nav}"
580 parent = parent.parent
582 html.gsub!(/~~ifnavigation\?~~(.+?)~~fi~~/) { $1 }
583 html.gsub!(/~~navigation~~/, nav + (xmldir.attributes['subdirs-caption'] || File.basename(xmldir.attributes['path'])))
585 html.gsub!(/~~ifnavigation\?~~(.+?)~~fi~~/, '')
589 def substitute_pathtobase(html, xmldir)
592 while location.parent.name == 'dir'
594 location = location.parent
596 html.gsub!(/~~pathtobase~~/, path)
599 def xmldir2destdir(xmldir)
600 return make_dest_filename(from_utf8(File.basename(xmldir.attributes['path'])))
603 def find_previous_album(xmldir)
606 #- move to previous dir element if exists
607 if prevelem = xmldir.previous_element_byname_notattr('dir', 'deleted')
609 relative_pos += '../' + xmldir2destdir(xmldir) + '/'
611 #- after having moved to previous dir, we need to go down last subdir until the last one
612 while child = xmldir.elements['dir']
613 while nextchild = child.next_element_byname_notattr('dir', 'deleted')
616 relative_pos += xmldir2destdir(child) + '/'
620 #- previous dir doesn't exist, move to previous dir element if exists
621 xmldir = xmldir.parent
622 if xmldir.name == 'dir' && !xmldir.attributes['deleted']
623 relative_pos += '../'
628 end while !xmldir.child_byname_notattr('image', 'deleted') && !xmldir.child_byname_notattr('video', 'deleted')
629 return File.reduce_path(relative_pos)
632 def find_next_album(xmldir)
635 #- first child dir element (catches when initial xmldir has both thumbnails and subdirs)
636 if firstchild = xmldir.child_byname_notattr('dir', 'deleted')
638 relative_pos += xmldir2destdir(xmldir) + '/'
640 elsif nextbro = xmldir.next_element_byname_notattr('dir', 'deleted')
642 relative_pos += '../' + xmldir2destdir(xmldir) + '/'
644 #- go up until we have a next brother or we are finished
646 xmldir = xmldir.parent
647 relative_pos += '../'
648 end while xmldir && !xmldir.next_element_byname_notattr('dir', 'deleted')
650 xmldir = xmldir.next_element_byname('dir')
651 relative_pos += '../' + xmldir2destdir(xmldir) + '/'
656 end while !xmldir.child_byname_notattr('image', 'deleted') && !xmldir.child_byname_notattr('video', 'deleted')
657 return File.reduce_path(relative_pos)
660 def find_translation_for_file(file, msg)
662 if file =~ /\.(\w\w)\.html$/
663 bindtextdomain("booh", { :locale => "#{$1}.UTF-8" })
665 Locale.set_current($default_locale)
668 die "Internal error: cannot find multi language suffix of file '#{file}'"
675 def sub_previous_next_album(file, previous_album, next_album, html)
677 html.gsub!(/~~previous_album~~/, '<a href="' + previous_album + 'thumbnails' + $htmlsuffix + '">' + find_translation_for_file(file, N_('previous album')) + '</a>')
678 html.gsub!(/~~ifprevious_album\?~~(.+?)~~fi~~/) { $1 }
680 html.gsub!(/~~previous_album~~/, '')
681 html.gsub!(/~~ifprevious_album\?~~(.+?)~~fi~~/, '')
684 html.gsub!(/~~next_album~~/, '<a href="' + next_album + 'thumbnails' + $htmlsuffix + '">' + find_translation_for_file(file, N_('next album')) + '</a>')
685 html.gsub!(/~~ifnext_album\?~~(.+?)~~fi~~/) { $1 }
687 html.gsub!(/~~next_album~~/, '')
688 html.gsub!(/~~ifnext_album\?~~(.+?)~~fi~~/, '')
693 def save_html(html, base_filename)
694 if html.class == Array
695 html = html.join("\n")
698 for language in ($multi_languages[0] + [ $multi_languages[1] ]).uniq
699 bindtextdomain("booh", { :locale => "#{language}.UTF-8" })
700 ios = File.open("#{base_filename}.#{language}.html", "w")
701 ios.write(html.gsub(/@@(.*?)@@/) { _($1) })
703 Locale.set_current($default_locale)
706 ios = File.open("#{base_filename}.html", "w")
707 ios.write(html.gsub(/@@(.*?)@@/) { utf8(_($1)) })
714 #- preprocess the path->dir, rexml is very slow with that; we seem to improve speed by 7%
716 $xmldoc.elements.each('//dir') { |elem|
717 optxpath[elem.attributes['path']] = elem
721 if $mode == 'merge_config_onedir'
722 examined_dirs = [ $onedir ]
723 elsif $mode == 'merge_config_subdirs'
724 examined_dirs = `find '#{$onedir}' -type d -follow`.sort.collect { |v| v.chomp }.delete_if { |v| optxpath.has_key?(utf8(v)) }
726 examined_dirs = `find '#{$source}' -type d -follow`.sort.collect { |v| v.chomp }
727 if $mode == 'merge_config'
728 $xmldoc.elements.each('//dir') { |elem|
729 if ! examined_dirs.include?(elem.attributes['path'])
730 msg 2, _("Merging config: removing directory %s from config, isn't on filesystem anymore") % elem.attributes['path']
736 info("directories: #{examined_dirs.length}, sizes: #{$images_size.length}")
738 examined_dirs.each { |dir|
740 die _("Source directory or sub-directories can't contain a single-quote character, sorry: %s") % dir
742 if $mode !~ /^use_config/
743 Dir.entries(dir).each { |file|
744 if file =~ /['"\[\]]/
745 die _("Files can't contain any of the characters ', \", [ or ], sorry: %s") % "#{dir}/#{file}"
751 examined_dirs.each { |dir|
752 if File.basename(dir) =~ /^\./
753 msg 1, _("Ignoring directory %s, begins with a dot (indicating a hidden directory)") % dir
757 dest_dir = make_dest_filename(dir.sub(/^#{Regexp.quote($source)}/, $dest))
759 #- place xml document on proper node if exists, else create
760 xmldir = optxpath[utf8(dir)]
761 if $mode == 'use_config' || $mode == 'use_config_changetheme'
762 if !xmldir || (xmldir.attributes['already-generated'] && !$force) || xmldir.attributes['deleted']
763 info("walking: #{dir}|#{$source}, 0 elements")
764 if xmldir && xmldir.attributes['deleted']
765 system("rm -rf '#{dest_dir}'")
770 if $mode == 'gen_config' || (($mode == 'merge_config' || $mode == 'merge_config_subdirs') && !xmldir)
771 #- add the <dir..> element if necessary
772 parent = File.dirname(dir)
773 xmldir = $xmldoc.elements["//dir[@path='#{utf8(parent)}']"]
775 xmldir = $xmldoc.root
777 #- need to remove the already-generated mark of the parent because of the sub-albums page containing now one more element
778 xmldir.delete_attribute('already-generated')
779 xmldir = optxpath[utf8(dir)] = xmldir.add_element('dir', { 'path' => utf8(dir) })
782 xmldir.delete_attribute('already-generated')
784 #- read images/videos entries from config or from directories depending on mode
786 if $mode == 'use_config' || $mode == 'use_config_changetheme'
787 msg 2, _("Handling %s from config list...") % dir
788 xmldir.elements.each { |element|
789 if %w(image video).include?(element.name) && !element.attributes['deleted']
790 entries << from_utf8(element.attributes['filename'])
794 msg 2, _("Examining %s...") % dir
795 entries = Dir.entries(dir).sort
796 #- populate config in case of gen_config, add new files in case of merge_config
798 if file =~ /['"\[\]]/
799 msg 1, _("Ignoring %s, contains one of forbidden characters: '\"[]") % "#{dir}/#{file}"
801 type = entry2type(file)
802 if type && !xmldir.elements["#{type}[@filename='#{utf8(file)}']"]
803 #- hack: don't run identify (which is slow) if format only contains default %t
804 if $commentsformat && type == 'image' && $commentsformat != '%t'
805 comment = utf8(`identify -format "#{$commentsformat}" '#{dir}/#{file}'`.chomp.sub(/\.$/, ''))
807 comment = utf8cut(file.sub(/\.[^\.]+$/, ''), 18)
809 xmldir.add_element type, { "filename" => utf8(file), "caption" => comment }
813 if $mode != 'gen_config'
814 #- cleanup removed files from config and reread entries from config to get proper ordering
816 xmldir.elements.each { |element|
817 fullpath = "#{dir}/#{from_utf8(element.attributes['filename'])}"
818 if %w(image video).include?(element.name)
819 if !File.readable?(fullpath)
820 msg 1, _("Config merge: removing %s from config; use the backup file to retrieve caption info if this was a mistake") % fullpath
821 xmldir.delete(element)
822 elsif !element.attributes['deleted']
823 entries << from_utf8(element.attributes['filename'])
827 #- if there is no more elements here, there is no album here anymore
828 if !xmldir.child_byname_notattr('image', 'deleted') && !xmldir.child_byname_notattr('video', 'deleted')
829 xmldir.delete_attribute('thumbnails-caption')
830 xmldir.delete_attribute('thumbnails-captionfile')
834 images = entries.find_all { |e| entry2type(e) == 'image' }
835 msg 3, _("\t%s images") % images.length
836 videos = entries.find_all { |e| entry2type(e) == 'video' }
837 msg 3, _("\t%s videos") % videos.length
838 info("walking: #{dir}|#{$source}, #{images.length + videos.length} elements")
840 system("mkdir -p '#{dest_dir}'")
842 #- generate .htaccess file
844 ios = File.open("#{dest_dir}/.htaccess", "w")
845 ios.write("AddCharset UTF-8 .html\n")
846 if auth_user_file = xmldir.attributes['password-protect']
847 msg 3, _("\tgenerating password protection file #{dest_dir}/.htaccess")
848 ios.write("AuthType Basic\nAuthName \"protected area\"\nAuthUserFile #{auth_user_file}\nrequire valid-user\n")
851 ios.write("LanguagePriority #{$multi_languages[1]}\n")
852 ios.write("ForceLanguagePriority Prefer Fallback\n")
853 ios.write("DirectoryIndex index\n")
858 #- pass through if there are no images and videos
859 if images.size == 0 && videos.size == 0
861 #- cleanup old images/videos, especially if this directory contained images/videos previously.
862 themestuff = Dir.entries("#{$FPATH}/themes/#{$theme}").
863 find_all { |e| !%w(. .. skeleton_image.html skeleton_thumbnails.html skeleton_index.html metadata root CVS).include?(e) }
864 themestuff_root = Dir.entries("#{$FPATH}/themes/#{$theme}/root").
865 find_all { |e| !%w(. .. CVS).include?(e) }
866 if $mode != 'gen_config'
867 rightful_images = [ '.htaccess' ]
868 if xmldir.attributes['thumbnails-caption']
869 rightful_images << 'thumbnails-thumbnail.jpg'
871 xmldir.elements.each('dir') { |child|
872 if child.attributes['deleted']
875 subdir = make_dest_filename(from_utf8(File.basename(child.attributes['path'])))
876 rightful_images << "thumbnails-#{subdir}.jpg"
878 to_del = Dir.entries(dest_dir).find_all { |e| !File.directory?(File.join(dest_dir, e)) && !rightful_images.include?(e) } - themestuff - themestuff_root
880 File.delete(*to_del.collect { |e| File.join(dest_dir, e) })
884 #- copy any resource file that goes with the theme (css, images..)
885 themestuff.each { |entry|
886 if !File.exists?(File.join(dest_dir, entry))
887 psys("cp '#{$FPATH}/themes/#{$theme}/#{entry}' '#{dest_dir}'")
891 #- copy any root-only resource file that goes with the theme (css, images..)
892 if xmldir.parent.name != 'dir'
893 themestuff_root.each { |entry|
894 if !File.exists?(File.join(dest_dir, entry))
895 psys("cp '#{$FPATH}/themes/#{$theme}/root/#{entry}' '#{dest_dir}'")
903 msg 2, _("Outputting in %s...") % dest_dir
905 #- populate data structure with sizes from theme
906 for sizeobj in $images_size
907 fullscreen_images ||= {}
908 fullscreen_images[sizeobj['name']] = []
909 thumbnail_images ||= {}
910 thumbnail_images[sizeobj['name']] = []
911 thumbnail_videos ||= {}
912 thumbnail_videos[sizeobj['name']] = []
914 #- a special dummy size to keep 'references' to thumbnails in case of panorama, because the GUI will use the regular thumbnails
915 thumbnail_images['dont-delete-file-for-gui'] = []
916 if $limit_sizes =~ /original/
917 fullscreen_images['original'] = []
920 images.size >= 1 and msg 3, _("\tcreating images thumbnails...")
922 #- create thumbnails for images
924 info("processing element")
925 base_dest_img = dest_dir + '/' + make_dest_filename(img.sub(/\.[^\.]+$/, ''))
927 thumbnail_dest_img = base_dest_img + "-#{$default_size['thumbnails']}.jpg"
928 gen_thumbnails_element("#{dir}/#{img}", xmldir, true, [ { 'filename' => thumbnail_dest_img, 'size' => $default_size['thumbnails'] } ])
931 elem = xmldir.elements["image[@filename='#{utf8(img)}']"]
932 for sizeobj in $images_size
933 size_fullscreen = sizeobj['fullscreen']
934 size_thumbnails = sizeobj['thumbnails']
935 fullscreen_dest_img = base_dest_img + "-#{size_fullscreen}.jpg"
936 fullscreen_images[sizeobj['name']] << File.basename(fullscreen_dest_img)
937 todo << { 'filename' => fullscreen_dest_img, 'size' => size_fullscreen }
938 if pano = pano_amount(elem)
939 thumbnail_images['dont-delete-file-for-gui'] << File.basename(base_dest_img + "-#{size_thumbnails}.jpg")
940 size_thumbnails = size_thumbnails.sub(/(\d+)/) { ($1.to_i * pano).to_i }
942 thumbnail_dest_img = base_dest_img + "-#{size_thumbnails}.jpg"
943 thumbnail_images[sizeobj['name']] << File.basename(thumbnail_dest_img)
944 todo << { 'filename' => thumbnail_dest_img, 'size' => size_thumbnails }
946 gen_thumbnails_element("#{dir}/#{img}", xmldir, true, todo)
947 if $limit_sizes =~ /original/
948 fullscreen_images['original'] << img
950 destimg = "#{dest_dir}/#{img}"
951 if $limit_sizes =~ /original/ && !File.exists?(destimg)
953 if ! sys("ln '#{dir}/#{img}' '#{destimg}'")
954 $hardlinks_ok = false
958 psys("cp '#{dir}/#{img}' '#{destimg}'")
964 videos.size >= 1 and msg 3, _("\tcreating videos thumbnails...")
966 #- create thumbnails for videos
967 videos.each { |video|
968 info("processing element")
970 thumbnail_dest_img = dest_dir + '/' + make_dest_filename(video.sub(/\.[^\.]+$/, '')) + "-#{$default_size['thumbnails']}.jpg"
971 gen_thumbnails_element("#{dir}/#{video}", xmldir, true, [ { 'filename' => thumbnail_dest_img, 'size' => $default_size['thumbnails'] } ])
974 for sizeobj in $images_size
975 size_thumbnails = sizeobj['thumbnails']
976 thumbnail_dest_img = dest_dir + '/' + make_dest_filename(video.sub(/\.[^\.]+$/, '')) + "-#{size_thumbnails}.jpg"
977 thumbnail_videos[sizeobj['name']] << File.basename(thumbnail_dest_img)
978 todo << { 'filename' => thumbnail_dest_img, 'size' => size_thumbnails }
980 gen_thumbnails_element("#{dir}/#{video}", xmldir, true, todo)
982 destvideo = "#{dest_dir}/#{video}"
983 if !File.exists?(destvideo)
985 if ! sys("ln '#{dir}/#{video}' '#{destvideo}'")
986 $hardlinks_ok = false
990 psys("cp '#{dir}/#{video}' '#{destvideo}'")
996 themestuff = Dir.entries("#{$FPATH}/themes/#{$theme}").
997 find_all { |e| !%w(. .. skeleton_image.html skeleton_thumbnails.html skeleton_index.html metadata root CVS).include?(e) }
998 themestuff_root = Dir.entries("#{$FPATH}/themes/#{$theme}/root").
999 find_all { |e| !%w(. .. CVS).include?(e) }
1001 #- cleanup old images/videos (for when removing elements or sizes)
1002 all_elements = fullscreen_images.collect { |e| e[1] }.flatten.
1003 concat(thumbnail_images.collect { |e| e[1] }.flatten).
1004 concat(thumbnail_videos.collect { |e| e[1] }.flatten).
1007 to_del = Dir.entries(dest_dir).find_all { |e| !File.directory?(File.join(dest_dir, e)) && !all_elements.include?(e) && e !~ /^thumbnails-\w+\.jpg/ } - themestuff - themestuff_root
1009 msg 3, _("\tcleaning up: #{to_del.join(', ')}")
1010 File.delete(*to_del.collect { |e| File.join(dest_dir, e) })
1013 #- copy any resource file that goes with the theme (css, images..)
1014 themestuff.each { |entry|
1015 if !File.exists?(File.join(dest_dir, entry))
1016 psys("cp '#{$FPATH}/themes/#{$theme}/#{entry}' '#{dest_dir}'")
1020 #- copy any root-only resource file that goes with the theme (css, images..)
1021 if xmldir.parent.name != 'dir'
1022 themestuff_root.each { |entry|
1023 if !File.exists?(File.join(dest_dir, entry))
1024 psys("cp '#{$FPATH}/themes/#{$theme}/root/#{entry}' '#{dest_dir}'")
1029 msg 3, _("\tgenerating HTML pages...")
1030 #- fixup max per page
1031 if $N_per_page && $N_per_row
1032 $N_per_page = $N_per_page.to_i / $N_per_row.to_i * $N_per_row.to_i
1035 #- generate thumbnails*.html (page with thumbnails)
1036 image2thumbnailpage4js = []
1037 for sizeobj in $images_size
1038 info("processing size")
1039 html = $html_thumbnails.collect { |l| l.clone }
1043 xmldir.attributes['thumbnails-caption'] || utf8(File.basename(dir)))
1044 discover_iterations(iterations, i)
1047 html_thumbnails = ''
1048 html_thumbnails_nojs = ''
1051 reset_iterations(iterations)
1052 #- preprocess the @filename->elem, rexml is very slow with that; we dramatically improve this part of the processing
1054 xmldir.elements.each('image') { |elem|
1055 optfilename[elem.attributes['filename']] = elem
1058 type = images.include?(file) ? 'image' : videos.include?(file) ? 'video' : nil
1060 if type == 'image' && elem = optfilename[utf8(file)]
1061 if pano = pano_amount(elem)
1062 html_elem = run_iterations(iterations, pano)
1063 counter += count = pano.ceil
1064 html_elem.gsub!(/~~colspan~~/) { "colspan=\"#{count}\"" }
1066 html_elem = run_iterations(iterations, 1)
1068 html_elem.gsub!(/~~colspan~~/, '')
1071 html_elem = run_iterations(iterations, 1)
1073 html_elem.gsub!(/~~colspan~~/, '')
1076 index = images.index(file)
1077 html_elem.gsub!(/~~caption_iteration~~/,
1078 find_caption_value(xmldir, images[index]) || utf8(images[index]))
1079 html_elem.gsub!(/~~ifimage\?~~(.+?)~~fi~~/) { $1 }
1080 html_elem.gsub!(/~~ifvideo\?~~(.+?)~~fi~~/, '')
1081 elsif type == 'video'
1082 index = videos.index(file)
1083 if File.exists?("#{dest_dir}/#{thumbnail_videos[sizeobj['name']][index]}")
1084 html_elem.gsub!(/~~image_iteration~~/,
1085 '<a href="' + videos[index] + '">' + img_element("#{dest_dir}/#{thumbnail_videos[sizeobj['name']][index]}") + '</a>')
1087 html_elem.gsub!(/~~image_iteration~~/,
1088 '<a href="' + videos[index] + '">' + defer_translation(N_("(no preview)")) + '</a>')
1090 html_elem.gsub!(/~~caption_iteration~~/, find_caption_value(xmldir, videos[index]) || utf8(videos[index]))
1091 html_elem.gsub!(/~~ifimage\?~~(.+?)~~fi~~/, '')
1092 html_elem.gsub!(/~~ifvideo\?~~(.+?)~~fi~~/) { $1 }
1094 html_thumbnails += html_elem
1095 html_thumbnails_nojs += html_elem
1097 html_thumbnails.gsub!(/~~image_iteration~~/,
1098 '<a href="image-' + size2js(sizeobj['name']) + $htmlsuffix + '#current=' + fullscreen_images[sizeobj['name']][index] +
1099 '" name="' + fullscreen_images[sizeobj['name']][index] + '">' +
1100 img_element("#{dest_dir}/#{thumbnail_images[sizeobj['name']][index]}") + '</a>')
1101 html_thumbnails_nojs.gsub!(/~~image_iteration~~/,
1102 '<a href="' + fullscreen_images[sizeobj['name']][index] + '" name="' + fullscreen_images[sizeobj['name']][index] + '">' +
1103 img_element("#{dest_dir}/#{thumbnail_images[sizeobj['name']][index]}") + '</a>')
1104 #- remember in which thumbnails page is this element, for image->thumbnail link
1105 if sizeobj == $images_size[0]
1106 image2thumbnailpage4js << pagecount
1110 if counter == $N_per_page
1111 html_thumbnails += close_iterations(iterations)
1112 html_thumbnails_nojs += close_iterations(iterations)
1113 all_pages << [ html_thumbnails, html_thumbnails_nojs ]
1114 html_thumbnails = ''
1115 html_thumbnails_nojs = ''
1117 reset_iterations(iterations)
1123 html_thumbnails += close_iterations(iterations)
1124 html_thumbnails_nojs += close_iterations(iterations)
1125 all_pages << [ html_thumbnails, html_thumbnails_nojs ]
1128 i.gsub!(/~~theme~~/, $theme)
1129 i.gsub!(/~~current_size~~/, sizeobj['name'])
1130 i.gsub!(/~~htmlsuffix~~/, $htmlsuffix)
1131 i.gsub!(/~~current_size_js~~/, size2js(sizeobj['name']))
1132 i.gsub!(/~~madewith~~/, $madewith || '')
1133 i.gsub!(/~~indexlink~~/, $indexlink || '')
1134 substitute_navigation(i, xmldir)
1136 html_nojs = html.collect { |l| l.clone }
1138 for page in all_pages
1139 html_thumbnails, html_thumbnails_nojs = page
1140 final_html = html.collect { |l| l.clone }
1141 mstuff = defer_translation(N_("Pages: ")) +
1142 (pagecount > 0 ? "<a href=\"thumbnails-#{size2js(sizeobj['name'])}%nojs-#{pagecount - 1}#{$htmlsuffix}\">" + defer_translation(N_("<- Previous")) + "</a> " : '') +
1143 all_pages.collect_with_index { |p,idx| page == p ? idx + 1 : "<a href=\"thumbnails-#{size2js(sizeobj['name'])}%nojs-#{idx}#{$htmlsuffix}\">#{idx + 1}</a>" }.join(', ') +
1144 (pagecount < all_pages.size - 1 ? " <a href=\"thumbnails-#{size2js(sizeobj['name'])}%nojs-#{pagecount + 1}#{$htmlsuffix}\">" + defer_translation(N_("Next ->")) + "</a> " : '')
1146 i.sub!(/~~run_slideshow~~/,
1147 images.size <= 1 ? '' : '<a href="image-' + size2js(sizeobj['name']) + $htmlsuffix + '#run_slideshow=1">' + defer_translation(N_("Run slideshow!"))+'</a>')
1148 i.sub!(/~~thumbnails~~/, html_thumbnails)
1149 if all_pages.size == 1
1150 i.gsub!(/~~ifmultiplepages\?~~.*~~fi~~/, '')
1152 i.gsub!(/~~ifmultiplepages\?~~(.+?)~~fi~~/) { $1 }
1153 i.gsub!(/~~multiplepagesstuff~~/, mstuff.gsub('%nojs', ''))
1155 substitute_html_sizes(i, sizeobj, 'thumbnails', "-#{pagecount}")
1156 substitute_pathtobase(i, xmldir)
1158 save_html(final_html, "#{dest_dir}/thumbnails-#{size2js(sizeobj['name'])}-#{pagecount}")
1159 final_html_nojs = html_nojs.collect { |l| l.clone }
1160 for i in final_html_nojs
1161 i.sub!(/~~run_slideshow~~/, defer_translation(N_("<i>Click on an image to view it larger</i>")))
1162 i.sub!(/~~thumbnails~~/, html_thumbnails_nojs)
1163 if all_pages.size == 1
1164 i.gsub!(/~~ifmultiplepages\?~~.*~~fi~~/, '')
1166 i.gsub!(/~~ifmultiplepages\?~~(.+?)~~fi~~/) { $1 }
1167 i.gsub!(/~~multiplepagesstuff~~/, mstuff.gsub('%nojs', '-nojs'))
1169 substitute_html_sizes(i, sizeobj, 'thumbnails', "-nojs-#{pagecount}")
1170 substitute_pathtobase(i, xmldir)
1172 save_html(final_html_nojs, "#{dest_dir}/thumbnails-#{size2js(sizeobj['name'])}-nojs-#{pagecount}")
1177 info("finished processing sizes")
1179 #- generate "main" thumbnails.html page that will reload to correct size thanks to cookie
1180 save_html(html_reload_to_thumbnails, "#{dest_dir}/thumbnails")
1182 #- generate image.html (page with fullscreen images)
1184 captions4js = find_captions(xmldir, images).collect { |e| e ? '"' + e.gsub('"', '\"') + '"' : '""' }.join(', ')
1185 thumbnailspage4js = image2thumbnailpage4js.collect { |e| "\"#{e}\"" }.join(', ')
1186 for sizeobj in $images_size
1187 html = $html_images.collect { |l| l.clone }
1188 images4js = fullscreen_images[sizeobj['name']].collect { |e| "\"#{e}\"" }.join(', ')
1191 for sizeobj2 in all_images_sizes
1192 if sizeobj != sizeobj2
1193 otherimages4js += "var images_#{size2js(sizeobj2['name'])} = new Array(" + fullscreen_images[sizeobj2['name']].collect { |e| "\"#{e}\"" }.join(', ') + ")\n"
1194 othersizes << "\"#{size2js(sizeobj2['name'])}\""
1198 i.gsub!(/~~images~~/, images4js)
1199 i.gsub!(/~~other_images~~/, otherimages4js)
1200 i.gsub!(/~~thumbnailspages~~/, thumbnailspage4js)
1201 i.gsub!(/~~other_sizes~~/, othersizes.join(', '))
1202 i.gsub!(/~~captions~~/, captions4js)
1203 i.gsub!(/~~title~~/, xmldir.attributes['thumbnails-caption'] || utf8(File.basename(dir)))
1204 i.gsub!(/~~thumbnails~~/, '<a href="thumbnails-' + size2js(sizeobj['name']) + $htmlsuffix + '" id="thumbnails">' + defer_translation(N_('return to thumbnails')) + '</a>')
1205 i.gsub!(/~~theme~~/, $theme)
1206 i.gsub!(/~~current_size~~/, size2js(sizeobj['name']))
1207 i.gsub!(/~~htmlsuffix~~/, $htmlsuffix)
1208 i.gsub!(/~~madewith~~/, $madewith || '')
1209 i.gsub!(/~~indexlink~~/, $indexlink || '')
1210 substitute_html_sizes(i, sizeobj, 'image', '')
1211 substitute_navigation(i, xmldir)
1212 substitute_pathtobase(i, xmldir)
1214 save_html(html, "#{dest_dir}/image-#{size2js(sizeobj['name'])}")
1222 #- add attributes to <dir..> elements needing so
1223 if $mode != 'use_config'
1224 msg 3, _("\tfixating configuration file...")
1225 $xmldoc.elements.each('//dir') { |element|
1226 path = captionpath = element.attributes['path']
1227 descendant_element = element.elements['descendant::image'] || element.elements['descendant::video']
1228 if !descendant_element
1229 msg 3, _("\t\tremoving %s, no element in it") % path
1230 element.remove #- means we have a directory with nothing interesting in it
1232 captionfile = "#{descendant_element.parent.attributes['path']}/#{descendant_element.attributes['filename']}"
1233 basename = File.basename(path)
1234 if element.elements['dir']
1235 if !element.attributes['subdirs-caption']
1236 element.add_attribute('subdirs-caption', basename)
1238 if !element.attributes['subdirs-captionfile']
1239 element.add_attribute('subdirs-captionfile', captionfile)
1242 if element.child_byname_notattr('image', 'deleted') || element.child_byname_notattr('video', 'deleted')
1243 if !element.attributes['thumbnails-caption']
1244 element.add_attribute('thumbnails-caption', basename)
1246 if !element.attributes['thumbnails-captionfile']
1247 element.add_attribute('thumbnails-captionfile', captionfile)
1254 #- write down to disk config if necessary
1256 ios = File.open($config_writeto, "w")
1257 $xmldoc.write(ios, 0)
1262 msg 3, _(" completed necessary stuff for GUI, exiting.")
1266 #- second pass to create index.html files and previous/next links
1267 info("creating index.html")
1268 msg 3, _("\trescanning directories to generate all 'index.html' files...")
1270 #- recompute the memoization because elements mights have been removed (the ones with no element in them)
1272 $xmldoc.elements.each('//dir') { |elem|
1273 optxpath[elem.attributes['path']] = elem
1276 examined_dirs.each { |dir|
1277 info("index.html: #{dir}|#{$source}")
1279 xmldir = optxpath[utf8(dir)]
1280 if !xmldir || (xmldir.attributes['already-generated'] && !$force) || xmldir.attributes['deleted']
1283 dest_dir = make_dest_filename(dir.sub(/^#{Regexp.quote($source)}/, $dest))
1285 previous_album = find_previous_album(xmldir)
1286 next_album = find_next_album(xmldir)
1288 if xmldir.elements['dir']
1289 html = $html_index.collect { |l| l.clone }
1292 caption = xmldir.attributes['subdirs-caption']
1293 i.gsub!(/~~title~~/, caption)
1294 substitute_navigation(i, xmldir)
1295 substitute_pathtobase(i, xmldir)
1296 discover_iterations(iterations, i)
1300 reset_iterations(iterations)
1302 #- deal with "current" album (directs to "thumbnails" page)
1303 if xmldir.attributes['thumbnails-caption']
1304 thumbnail = "#{dest_dir}/thumbnails-thumbnail.jpg"
1305 gen_thumbnails_subdir(from_utf8(xmldir.attributes['thumbnails-captionfile']), xmldir, false,
1306 [ { 'filename' => thumbnail, 'size' => $albums_thumbnail_size } ], 'thumbnails')
1307 html_index += run_iterations(iterations, 1)
1308 html_index.gsub!(/~~image_iteration~~/, "<a href=\"thumbnails#{$htmlsuffix}\">" + img_element(thumbnail) + '</a>')
1309 html_index.gsub!(/~~caption_iteration~~/, xmldir.attributes['thumbnails-caption'])
1312 #- deal with sub-albums (direct to subdirs/index.html pages)
1313 xmldir.elements.each('dir') { |child|
1314 if child.attributes['deleted']
1317 subdir = make_dest_filename(from_utf8(File.basename(child.attributes['path'])))
1318 thumbnail = "#{dest_dir}/thumbnails-#{subdir}.jpg"
1319 html_index += run_iterations(iterations, 1)
1320 captionfile, caption = find_subalbum_caption_info(child)
1321 gen_thumbnails_subdir(captionfile, child, false,
1322 [ { 'filename' => thumbnail, 'size' => $albums_thumbnail_size } ], find_subalbum_info_type(child))
1323 html_index.gsub!(/~~caption_iteration~~/, caption)
1324 html_index.gsub!(/~~image_iteration~~/, "<a href=\"#{subdir}/index#{$htmlsuffix}\">" + img_element(thumbnail) + '</a>')
1327 html_index += close_iterations(iterations)
1330 i.gsub!(/~~thumbnails~~/, html_index)
1331 i.gsub!(/~~madewith~~/, $madewith || '')
1332 i.gsub!(/~~indexlink~~/, $indexlink || '')
1336 html = html_reload_to_thumbnails
1339 save_html(html, "#{dest_dir}/index")
1341 #- in case MultiViews will not work, generate some compat
1342 ios = File.open("#{dest_dir}/index.html", "w")
1343 ios.write("<html><head><meta http-equiv=\"refresh\" content=\"0.1;url=index.#{$multi_languages[1]}.html\"></head></html>")
1347 #- substitute multiple "return to albums", previous/next correctly
1348 #- the following two statements are dramatical optimizations to executing for each substInFile callback
1349 dirpresent = xmldir.elements['dir']
1350 parentname = xmldir.parent.name
1351 if xmldir.child_byname_notattr('image', 'deleted') || xmldir.child_byname_notattr('video', 'deleted')
1352 for suffix in [ '', '-nojs' ]
1353 for sizeobj in $images_size
1354 Dir.glob("#{dest_dir}/thumbnails-#{size2js(sizeobj['name'])}#{suffix}-*.html") do |file|
1355 substInFile(file) { |line|
1356 sub_previous_next_album(file, previous_album, next_album, line)
1358 line.sub!(/~~return_to_albums~~/, '<a href="index' + $htmlsuffix + '">' + find_translation_for_file(file, N_('return to albums')) + '</a>')
1360 if parentname == 'dir'
1361 line.sub!(/~~return_to_albums~~/, '<a href="../index' + $htmlsuffix + '">' + find_translation_for_file(file, N_('return to albums')) + '</a>')
1363 line.sub!(/~~return_to_albums~~/, '')
1369 if suffix == '' && xmldir.child_byname_notattr('image', 'deleted')
1370 Dir.glob("#{dest_dir}/image-#{size2js(sizeobj['name'])}*.html") do |file|
1371 substInFile(file) { |line|
1372 sub_previous_next_album(file, previous_album, next_album, line)
1381 msg 3, _(" all done.")
1388 build_html_skeletons