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
25 require 'booh/rexml/document'
28 require 'booh/booh-lib'
29 require 'booh/html-merges'
31 #- bind text domain as soon as possible because some _() functions are called early to build data structures
32 bindtextdomain("booh")
36 [ '--help', '-h', GetoptLong::NO_ARGUMENT, _("Get help message") ],
37 [ '--version', '-V', GetoptLong::NO_ARGUMENT, _("Print version and exit") ],
39 [ '--source', '-s', GetoptLong::REQUIRED_ARGUMENT, _("Directory which contains original images/videos as files or subdirs") ],
40 [ '--destination', '-d', GetoptLong::REQUIRED_ARGUMENT, _("Directory which will contain the web-album") ],
41 # [ '--clean', '-c', GetoptLong::NO_ARGUMENT, _("Clean destination directory") ],
43 [ '--theme', '-t', GetoptLong::REQUIRED_ARGUMENT, _("Select HTML theme to use") ],
44 [ '--config', '-C', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing images and videos within directories with captions") ],
45 [ '--config-skel', '-k', GetoptLong::REQUIRED_ARGUMENT, _("Filename where the script will output a config skeleton") ],
46 [ '--merge-config', '-M', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, where to merge new/removed images/videos from --source, and change theme info") ],
47 [ '--merge-config-onedir', '-O', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, for merging the subdir specified with --dir") ],
48 [ '--merge-config-subdirs', '-U', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, for merging the new subdirs down the subdir specified with --dir") ],
49 [ '--dir', '-D', GetoptLong::REQUIRED_ARGUMENT, _("Directory for merge with --merge-config-onedir or --merge-config-subdirs") ],
50 [ '--use-config', '-u', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, where to change theme info") ],
51 [ '--force', '-f', GetoptLong::NO_ARGUMENT, _("Force generation of album even if the GUI marked some directories as already generated") ],
53 [ '--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)") ],
54 [ '--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 default language; for example: 'fr,eo,en,en'; supported languages: %s") % SUPPORTED_LANGUAGES.join(', ') ],
55 [ '--thumbnails-per-row', '-T', GetoptLong::REQUIRED_ARGUMENT, _("Specify the amount of thumbnails per row in the thumbnails page (if applicable in theme)") ],
56 [ '--thumbnails-per-page', '-p', GetoptLong::REQUIRED_ARGUMENT, _("Specify the amount of thumbnails per page in the thumbnails page, after which split occurs") ],
57 [ '--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)") ],
58 [ '--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)") ],
59 [ '--made-with', '-n', GetoptLong::REQUIRED_ARGUMENT, _("Specify the HTML markup to use on the bottom of pages for a small 'made with' message") ],
60 [ '--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") ],
62 [ '--mproc', '-m', GetoptLong::REQUIRED_ARGUMENT, _("Specify the number of processors for multi-processors machines") ],
64 [ '--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)") ],
66 [ '--verbose-level', '-v', GetoptLong::REQUIRED_ARGUMENT, _("Set max verbosity level (0: errors, 1: warnings, 2: important messages, 3: other messages)") ],
67 [ '--info-pipe', '-i', GetoptLong::REQUIRED_ARGUMENT, _("Name a file where to write information about what's going on (used by the GUI)") ],
70 #- default values for some globals
74 $ignore_videos = false
79 puts _("Usage: %s [OPTION]...") % File.basename($0)
81 printf " %3s, %-18s %s\n", ary[1], ary[0], ary[3]
86 parser = GetoptLong.new
87 parser.set_options(*$options.collect { |ary| ary[0..2] })
89 parser.each_option do |name, arg|
96 puts _("Booh version %s
98 Copyright (c) 2005 Guillaume Cottenceau.
99 This is free software; see the source for copying conditions. There is NO
100 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") % $VERSION
105 $source = File.expand_path(arg.sub(%r|/$|, ''))
106 if !File.directory?($source)
107 die _("Argument to --source must be a directory")
110 $dest = File.expand_path(arg.sub(%r|/$|, ''))
111 if File.exists?($dest) && !File.directory?($dest)
112 die _("If --destination exists, it must be a directory")
114 if $dest != make_dest_filename($dest)
115 die _("Sorry, destination directory can't contain non simple alphanumeric characters.")
118 # system("rm -rf #{$dest}")
123 arg = File.expand_path(arg)
124 if File.readable?(arg)
125 $xmldoc = REXML::Document.new File.new(arg)
128 die _('Config file does not exist or is unreadable.')
131 arg = File.expand_path(arg)
133 if File.directory?(arg)
134 die _("Config skeleton file (%s) already exists and is a directory! Please change the filename.") % arg
136 msg 1, _("Config skeleton file already exists, backuping to %s.backup") % arg
137 File.rename(arg, "#{arg}.backup")
140 $config_writeto = arg
142 when '--merge-config'
143 arg = File.expand_path(arg)
144 if File.readable?(arg)
145 msg 2, _("Merge config notice: backuping current config file to %s.backup") % arg
146 $xmldoc = REXML::Document.new File.new(arg)
147 File.rename(arg, "#{arg}.backup")
148 $config_writeto = arg
149 $mode = 'merge_config'
151 die _('Config file does not exist or is unreadable.')
153 when '--merge-config-onedir'
154 arg = File.expand_path(arg)
155 if File.readable?(arg)
156 msg 2, _("Merge config notice: backuping current config file to %s.backup") % arg
157 $xmldoc = REXML::Document.new File.new(arg)
158 File.rename(arg, "#{arg}.backup")
159 $config_writeto = arg
160 $mode = 'merge_config_onedir'
162 die _('Config file does not exist or is unreadable.')
164 when '--merge-config-subdirs'
165 arg = File.expand_path(arg)
166 if File.readable?(arg)
167 msg 2, _("Merge config notice: backuping current config file to %s.backup") % arg
168 $xmldoc = REXML::Document.new File.new(arg)
169 File.rename(arg, "#{arg}.backup")
170 $config_writeto = arg
171 $mode = 'merge_config_subdirs'
173 die _('Config file does not exist or is unreadable.')
176 arg = File.expand_path(arg)
177 if !File.readable?(arg)
178 die _('Specified directory to merge with --dir is not readable')
183 arg = File.expand_path(arg)
184 if File.readable?(arg)
185 msg 2, _("Use config notice: backuping current config file to %s.backup") % arg
186 $xmldoc = REXML::Document.new File.new(arg)
187 File.rename(arg, "#{arg}.backup")
188 $config_writeto = arg
189 $mode = 'use_config_changetheme'
191 die _('Config file does not exist or is unreadable.')
197 when '--multi-languages'
198 parts = arg.split(',')
199 if parts.size == 0 || parts.find_all { |e| ! SUPPORTED_LANGUAGES.include?(e.strip) }.size > 0
200 die _("--multi-languages: argument must be a comma-separated list of supported languages, with last element used as the default language; for example: 'fr,eo,en,en'; supported languages: %s") % SUPPORTED_LANGUAGES.join(', ')
202 $multi_languages = [ parts[0..-2], parts[-1] ]
204 when '--thumbnails-per-row'
207 when '--thumbnails-per-page'
210 when '--optimize-for-32'
211 $optimize_for_32 = true
219 when '--comments-format'
220 $commentsformat = arg
232 when '--verbose-level'
233 $verbose_level = arg.to_i
236 $info_pipe = File.open(arg, File::WRONLY)
237 $info_pipe.sync = true
246 if !$source && $xmldoc
247 $source = from_utf8($xmldoc.root.attributes['source']).sub(%r|/$|, '')
248 $dest = from_utf8($xmldoc.root.attributes['destination']).sub(%r|/$|, '')
249 $theme ||= $xmldoc.root.attributes['theme']
250 $limit_sizes ||= $xmldoc.root.attributes['limit-sizes']
251 if $mode == 'use_config' || $mode =~ /^merge_config/
252 $optimize_for_32 = !$xmldoc.root.attributes['optimize-for-32'].nil?
253 $N_per_row = $xmldoc.root.attributes['thumbnails-per-row']
254 languages = $xmldoc.root.attributes['multi-languages']
256 languages = languages.split(',')
257 $multi_languages = [ languages[0..-2], languages[-1] ]
259 $N_per_page = $xmldoc.root.attributes['thumbnails-per-page']
260 $madewith = $xmldoc.root.attributes['made-with']
261 $indexlink = $xmldoc.root.attributes['index-link']
265 if $mode == 'merge_config_onedir' && !$onedir
266 die _("Missing --dir for --merge-config-onedir")
268 if $mode == 'merge_config_subdirs' && !$onedir
269 die _("Missing --dir for --merge-config-subdirs")
277 die _("Missing --destination parameter.")
283 select_theme($theme, $limit_sizes, $optimize_for_32, $N_per_row)
286 additional_params = ''
288 additional_params += "limit-sizes='#{$limit_sizes}'"
291 additional_params += " multi-languages='#{$multi_languages[0].join(',')},#{$multi_languages[1]}'"
294 additional_params += " optimize-for-32='true'"
297 additional_params += " thumbnails-per-row='#{$N_per_row}'"
300 additional_params += " thumbnails-per-page='#{$N_per_page}'"
303 additional_params += " made-with='#{$madewith}'"
306 additional_params += " index-link='#{$indexlink}'"
308 $xmldoc = Document.new "<booh version='#{$VERSION}' source='#{utf8($source)}' destination='#{utf8($dest)}' theme='#{$theme}' #{additional_params}/>"
309 $xmldoc << XMLDecl.new(XMLDecl::DEFAULT_VERSION, $CURRENT_CHARSET)
313 if $mode == 'merge_config' || $mode == 'use_config_changetheme'
314 $xmldoc.root.add_attribute('theme', $theme)
315 $xmldoc.root.add_attribute('version', $VERSION)
317 $xmldoc.root.add_attribute('limit-sizes', $limit_sizes)
319 $xmldoc.root.delete_attribute('limit-sizes')
322 $xmldoc.root.add_attribute('multi-languages', $multi_languages[0].join(',') + ',' + $multi_languages[1])
324 $xmldoc.root.delete_attribute('multi-languages')
328 $xmldoc.root.add_attribute('optimize-for-32', 'true')
330 $xmldoc.root.delete_attribute('optimize-for-32')
333 $xmldoc.root.add_attribute('thumbnails-per-row', $N_per_row)
335 $xmldoc.root.delete_attribute('thumbnails-per-row')
338 $xmldoc.root.add_attribute('thumbnails-per-page', $N_per_page)
340 $xmldoc.root.delete_attribute('thumbnails-per-page')
343 $xmldoc.root.add_attribute('made-with', $madewith)
345 $xmldoc.root.delete_attribute('made-with')
348 $xmldoc.root.add_attribute('index-link', $indexlink)
350 $xmldoc.root.delete_attribute('index-link')
355 $madewith = $madewith.gsub('%booh', '"http://booh.org/"')
360 $htmlsuffix = '.html'
373 $info_pipe.puts(value)
379 $info_pipe.puts("die: " + value)
384 def check_installation
385 if !system("which convert >/dev/null 2>/dev/null")
386 die _("The program 'convert' is needed. Please install it.
387 It is generally available with the 'ImageMagick' software package.")
389 if !system("which identify >/dev/null 2>/dev/null")
390 msg 1, _("the program 'identify' is needed to get images sizes and EXIF data. Please install it.
391 It is generally available with the 'ImageMagick' software package.")
394 missing = %w(mplayer).delete_if { |prg| system("which #{prg} >/dev/null 2>/dev/null") }
396 msg 1, _("the following program(s) are needed to handle videos: '%s'. Videos will be ignored.") % missing.join(', ')
397 $ignore_videos = true
401 def replace_line(surround, keyword, line)
403 contents = eval "$#{keyword}"
404 line.sub!(/#{surround}#{keyword}#{surround}/, contents)
406 die _("No '%s' found for substitution") % keyword
410 def build_html_skeletons
411 $html_images = File.open("#{$FPATH}/themes/#{$theme}/skeleton_image.html").readlines
412 $html_thumbnails = File.open("#{$FPATH}/themes/#{$theme}/skeleton_thumbnails.html").readlines
413 $html_index = File.open("#{$FPATH}/themes/#{$theme}/skeleton_index.html").readlines
414 for line in $html_images + $html_thumbnails + $html_index
415 while line =~ /~~~(\w+)~~~/
416 replace_line('~~~', $1, line)
421 def find_caption_value(xmldir, filename)
422 if cap = xmldir.elements["*[@filename='#{utf8(filename)}']"].attributes['caption']
423 return cap.gsub("\n", '<br/>')
429 def find_captions(xmldir, images)
430 return images.collect { |img| find_caption_value(xmldir, img) }
433 #- stolen from CVSspam
435 text.sub(/[^a-zA-Z0-9\-,.*_\/]/) do
436 "%#{sprintf('%2X', $&[0])}"
441 return $limit_sizes =~ /original/ ? $images_size + [ { 'name' => 'original' } ] : $images_size
444 def html_reload_to_thumbnails
445 html_reload_to_thumbnails = $preferred_size_reloader.clone
446 html_reload_to_thumbnails.gsub!(/~~theme~~/, $theme)
447 html_reload_to_thumbnails.gsub!(/~~default_size~~/, $default_size['name'])
448 html_reload_to_thumbnails.gsub!(/~~htmlsuffix~~/, $htmlsuffix)
449 html_reload_to_thumbnails.gsub!(/~~all_sizes~~/, all_images_sizes.collect { |s| "\"#{size2js(s['name'])}\"" }.join(', '))
450 size_auto_chooser = '';
451 all_images_sizes.find_all { |s| s.has_key?('optimizedforwidth') }.
452 sort { |a,b| b['optimizedforwidth'].to_i <=> a['optimizedforwidth'].to_i }.
453 each { |s| size_auto_chooser += "if (w + 50 > #{s['optimizedforwidth']}) { return 'thumbnails-#{size2js(s['name'])}-0#{$htmlsuffix}'; }\n" }
454 html_reload_to_thumbnails.gsub!(/~~size_auto_chooser~~/, size_auto_chooser)
455 return html_reload_to_thumbnails
458 def discover_iterations(iterations, line)
459 if line =~ /~~iterate(\d)_open(_max(\d+|N))?~~/
460 for iter in iterations.values
463 iter['close_wait'] = $1.to_i
466 max = $3 == 'N' ? ($N_per_row || $default_N) : $3
467 iterations[$1.to_i] = { 'open' => true, 'max' => max, 'opening' => '', 'closing' => '' }
469 line.sub!(/.*/, '~~thumbnails~~')
473 elsif line =~ /~~iterate(\d)_close~~/
474 iterations[$1.to_i]['open'] = false;
475 iterations[$1.to_i]['close'] = true;
478 for iter in iterations.values
480 iter['opening'] += line
483 if !iter['close'] && iter['close_wait'] && iterations[iter['close_wait']]['close']
484 iter['closing'] += line
491 def reset_iterations(iterations)
492 for iter in iterations.values
497 def run_iterations(iterations, amount)
500 for level in iterations.keys.sort
501 if iterations[level]['value'] == 0
502 html += iterations[level]['opening']
503 elsif level == iterations.keys.max
504 if !iterations[level]['max'] || iterations[level]['max'] && iterations[level]['value'] + amount <= iterations[level]['max'].to_i
505 html += iterations[level]['opening']
510 iterations[level]['value'] += amount
511 if iterations[level]['max'] && iterations[level]['value'] > iterations[level]['max'].to_i
512 iterations[level]['value'] = 0
513 iterations[level-1]['value'] = 0
514 html += iterations[level-1]['closing']
518 return html + run_iterations(iterations, amount)
524 def close_iterations(iterations)
526 for level in iterations.keys.sort.reverse
527 html += iterations[level]['closing']
532 def img_element(fullpath)
533 if size = get_image_size(fullpath)
534 sizespec = 'width="' + size[:x].to_s + '" height="' + size[:y].to_s + '"'
538 return '<img src="' + File.basename(fullpath) + '" ' + sizespec + ' alt="image"/>'
542 return name.gsub(/-/, '')
545 def substitute_html_sizes(html, sizeobj, type, suffix)
547 if $images_size.length > 1 || (type == 'image' && $limit_sizes =~ /original/)
548 for sizeobj2 in $images_size
549 sizejs = size2js(sizeobj2['name'])
550 sizen = defer_translation(sizename(sizeobj2['name'], false))
551 if sizeobj != sizeobj2
552 if type == 'thumbnails'
553 sizestrings << '<a href="thumbnails-' + sizejs + suffix + $htmlsuffix + '" onclick="set_preferred_size(\'' + sizejs + '\')">' + sizen + '</a>'
555 sizestrings << '<a id="link' + sizejs + '" onclick="set_preferred_size(\'' + sizejs + '\')">' + sizen + '</a>'
561 if type == 'image' && $limit_sizes =~ /original/
562 sizestrings << '<a id="linkoriginal" target="newframe">' + defer_translation(sizename('original'), false) + '</a>'
565 html.sub!(/~~sizes~~(.+)~~/) { sizestrings.join($1) }
568 def substitute_navigation(html, xmldir)
569 if xmldir.parent.name == 'dir'
572 parent = xmldir.parent
573 while parent.name == 'dir'
574 parentcaption = parent.attributes['subdirs-caption'] || File.basename(parent.attributes['path'])
575 nav = "<a href=\"#{path}/index#{$htmlsuffix}\">#{parentcaption}</a> #{defer_translation(N_(" > "))} #{nav}"
577 parent = parent.parent
579 html.gsub!(/~~ifnavigation\?~~(.+?)~~fi~~/) { $1 }
580 html.gsub!(/~~navigation~~/, nav + (xmldir.attributes['subdirs-caption'] || File.basename(xmldir.attributes['path'])))
582 html.gsub!(/~~ifnavigation\?~~(.+?)~~fi~~/, '')
586 def substitute_pathtobase(html, xmldir)
589 while location.parent.name == 'dir'
591 location = location.parent
593 html.gsub!(/~~pathtobase~~/, path)
596 def xmldir2destdir(xmldir)
597 return make_dest_filename(from_utf8(File.basename(xmldir.attributes['path'])))
600 def find_previous_album(xmldir)
603 #- move to previous dir element if exists
604 if prevelem = xmldir.previous_element_byname_notattr('dir', 'deleted')
606 relative_pos += '../' + xmldir2destdir(xmldir) + '/'
608 #- after having moved to previous dir, we need to go down last subdir until the last one
609 while child = xmldir.elements['dir']
610 while nextchild = child.next_element_byname_notattr('dir', 'deleted')
613 relative_pos += xmldir2destdir(child) + '/'
617 #- previous dir doesn't exist, move to previous dir element if exists
618 xmldir = xmldir.parent
619 if xmldir.name == 'dir' && !xmldir.attributes['deleted']
620 relative_pos += '../'
625 end while !xmldir.child_byname_notattr('image', 'deleted') && !xmldir.child_byname_notattr('video', 'deleted')
626 return File.reduce_path(relative_pos)
629 def find_next_album(xmldir)
632 #- first child dir element (catches when initial xmldir has both thumbnails and subdirs)
633 if firstchild = xmldir.child_byname_notattr('dir', 'deleted')
635 relative_pos += xmldir2destdir(xmldir) + '/'
637 elsif nextbro = xmldir.next_element_byname_notattr('dir', 'deleted')
639 relative_pos += '../' + xmldir2destdir(xmldir) + '/'
641 #- go up until we have a next brother or we are finished
643 xmldir = xmldir.parent
644 relative_pos += '../'
645 end while xmldir && !xmldir.next_element_byname_notattr('dir', 'deleted')
647 xmldir = xmldir.next_element_byname('dir')
648 relative_pos += '../' + xmldir2destdir(xmldir) + '/'
653 end while !xmldir.child_byname_notattr('image', 'deleted') && !xmldir.child_byname_notattr('video', 'deleted')
654 return File.reduce_path(relative_pos)
657 def find_translation_for_file(file, msg)
659 if file =~ /\.(\w\w)\.html$/
660 bindtextdomain("booh", { :locale => "#{$1}.UTF-8" })
663 die "Internal error: cannot find multi language suffix of file '#{file}'"
670 def sub_previous_next_album(file, previous_album, next_album, html)
672 html.gsub!(/~~previous_album~~/, '<a href="' + previous_album + 'thumbnails' + $htmlsuffix + '">' + find_translation_for_file(file, N_('previous album')) + '</a>')
673 html.gsub!(/~~ifprevious_album\?~~(.+?)~~fi~~/) { $1 }
675 html.gsub!(/~~previous_album~~/, '')
676 html.gsub!(/~~ifprevious_album\?~~(.+?)~~fi~~/, '')
679 html.gsub!(/~~next_album~~/, '<a href="' + next_album + 'thumbnails' + $htmlsuffix + '">' + find_translation_for_file(file, N_('next album')) + '</a>')
680 html.gsub!(/~~ifnext_album\?~~(.+?)~~fi~~/) { $1 }
682 html.gsub!(/~~next_album~~/, '')
683 html.gsub!(/~~ifnext_album\?~~(.+?)~~fi~~/, '')
688 def save_html(html, base_filename)
689 if html.class == Array
690 html = html.join("\n")
693 for language in ($multi_languages[0] + [ $multi_languages[1] ]).uniq
694 bindtextdomain("booh", { :locale => "#{language}.UTF-8" })
695 ios = File.open("#{base_filename}.#{language}.html", "w")
696 ios.write(html.gsub(/@@(.*?)@@/) { _($1) })
700 ios = File.open("#{base_filename}.html", "w")
701 ios.write(html.gsub(/@@(.*?)@@/) { utf8(_($1)) })
708 #- preprocess the path->dir, rexml is very slow with that; we seem to improve speed by 7%
710 $xmldoc.elements.each('//dir') { |elem|
711 optxpath[elem.attributes['path']] = elem
715 if $mode == 'merge_config_onedir'
716 examined_dirs = [ $onedir ]
717 elsif $mode == 'merge_config_subdirs'
718 examined_dirs = `find '#{$onedir}' -type d -follow`.sort.collect { |v| v.chomp }.delete_if { |v| optxpath.has_key?(utf8(v)) }
720 examined_dirs = `find '#{$source}' -type d -follow`.sort.collect { |v| v.chomp }
721 if $mode == 'merge_config'
722 $xmldoc.elements.each('//dir') { |elem|
723 if ! examined_dirs.include?(elem.attributes['path'])
724 msg 2, _("Merging config: removing directory %s from config, isn't on filesystem anymore") % elem.attributes['path']
730 info("directories: #{examined_dirs.length}, sizes: #{$images_size.length}")
732 examined_dirs.each { |dir|
734 die _("Source directory or sub-directories can't contain a single-quote character, sorry: %s") % dir
736 if $mode !~ /^use_config/
737 Dir.entries(dir).each { |file|
738 if file =~ /['"\[\]]/
739 die _("Files can't contain any of the characters ', \", [ or ], sorry: %s") % "#{dir}/#{file}"
745 examined_dirs.each { |dir|
746 if File.basename(dir) =~ /^\./
747 msg 1, _("Ignoring directory %s, begins with a dot (indicating a hidden directory)") % dir
751 dest_dir = make_dest_filename(dir.sub(/^#{Regexp.quote($source)}/, $dest))
753 #- place xml document on proper node if exists, else create
754 xmldir = optxpath[utf8(dir)]
755 if $mode == 'use_config' || $mode == 'use_config_changetheme'
756 if !xmldir || (xmldir.attributes['already-generated'] && !$force) || xmldir.attributes['deleted']
757 info("walking: #{dir}|#{$source}, 0 elements")
758 if xmldir && xmldir.attributes['deleted']
759 system("rm -rf '#{dest_dir}'")
764 if $mode == 'gen_config' || (($mode == 'merge_config' || $mode == 'merge_config_subdirs') && !xmldir)
765 #- add the <dir..> element if necessary
766 parent = File.dirname(dir)
767 xmldir = $xmldoc.elements["//dir[@path='#{utf8(parent)}']"]
769 xmldir = $xmldoc.root
771 #- need to remove the already-generated mark of the parent because of the sub-albums page containing now one more element
772 xmldir.delete_attribute('already-generated')
773 xmldir = optxpath[utf8(dir)] = xmldir.add_element('dir', { 'path' => utf8(dir) })
776 xmldir.delete_attribute('already-generated')
778 #- read images/videos entries from config or from directories depending on mode
780 if $mode == 'use_config' || $mode == 'use_config_changetheme'
781 msg 2, _("Handling %s from config list...") % dir
782 xmldir.elements.each { |element|
783 if %w(image video).include?(element.name) && !element.attributes['deleted']
784 entries << from_utf8(element.attributes['filename'])
788 msg 2, _("Examining %s...") % dir
789 entries = Dir.entries(dir).sort
790 #- populate config in case of gen_config, add new files in case of merge_config
792 if file =~ /['"\[\]]/
793 msg 1, _("Ignoring %s, contains one of forbidden characters: '\"[]") % "#{dir}/#{file}"
795 type = entry2type(file)
796 if type && !xmldir.elements["#{type}[@filename='#{utf8(file)}']"]
797 #- hack: don't run identify (which is slow) if format only contains default %t
798 if $commentsformat && type == 'image' && $commentsformat != '%t'
799 comment = utf8(`identify -format "#{$commentsformat}" '#{dir}/#{file}'`.chomp.sub(/\.$/, ''))
801 comment = utf8cut(file.sub(/\.[^\.]+$/, ''), 18)
803 xmldir.add_element type, { "filename" => utf8(file), "caption" => comment }
807 if $mode != 'gen_config'
808 #- cleanup removed files from config and reread entries from config to get proper ordering
810 xmldir.elements.each { |element|
811 fullpath = "#{dir}/#{from_utf8(element.attributes['filename'])}"
812 if %w(image video).include?(element.name)
813 if !File.readable?(fullpath)
814 msg 1, _("Config merge: removing %s from config; use the backup file to retrieve caption info if this was a mistake") % fullpath
815 xmldir.delete(element)
816 elsif !element.attributes['deleted']
817 entries << from_utf8(element.attributes['filename'])
821 #- if there is no more elements here, there is no album here anymore
822 if !xmldir.child_byname_notattr('image', 'deleted') && !xmldir.child_byname_notattr('video', 'deleted')
823 xmldir.delete_attribute('thumbnails-caption')
824 xmldir.delete_attribute('thumbnails-captionfile')
828 images = entries.find_all { |e| entry2type(e) == 'image' }
829 msg 3, _("\t%s images") % images.length
830 videos = entries.find_all { |e| entry2type(e) == 'video' }
831 msg 3, _("\t%s videos") % videos.length
832 info("walking: #{dir}|#{$source}, #{images.length + videos.length} elements")
834 system("mkdir -p '#{dest_dir}'")
836 #- generate .htaccess file
838 ios = File.open("#{dest_dir}/.htaccess", "w")
839 ios.write("AddCharset UTF-8 .html\n")
840 if auth_user_file = xmldir.attributes['password-protect']
841 msg 3, _("\tgenerating password protection file #{dest_dir}/.htaccess")
842 ios.write("AuthType Basic\nAuthName \"protected area\"\nAuthUserFile #{auth_user_file}\nrequire valid-user\n")
845 ios.write("LanguagePriority #{$multi_languages[1]}\n")
846 ios.write("ForceLanguagePriority Prefer Fallback\n")
847 ios.write("DirectoryIndex index\n")
852 #- pass through if there are no images and videos
853 if images.size == 0 && videos.size == 0
855 #- cleanup old images/videos, especially if this directory contained images/videos previously.
856 themestuff = Dir.entries("#{$FPATH}/themes/#{$theme}").
857 find_all { |e| !%w(. .. skeleton_image.html skeleton_thumbnails.html skeleton_index.html metadata root CVS).include?(e) }
858 themestuff_root = Dir.entries("#{$FPATH}/themes/#{$theme}/root").
859 find_all { |e| !%w(. .. CVS).include?(e) }
860 if $mode != 'gen_config'
861 rightful_images = [ '.htaccess' ]
862 if xmldir.attributes['thumbnails-caption']
863 rightful_images << 'thumbnails-thumbnail.jpg'
865 xmldir.elements.each('dir') { |child|
866 if child.attributes['deleted']
869 subdir = make_dest_filename(from_utf8(File.basename(child.attributes['path'])))
870 rightful_images << "thumbnails-#{subdir}.jpg"
872 to_del = Dir.entries(dest_dir).find_all { |e| !File.directory?(File.join(dest_dir, e)) && !rightful_images.include?(e) } - themestuff - themestuff_root
874 File.delete(*to_del.collect { |e| File.join(dest_dir, e) })
878 #- copy any resource file that goes with the theme (css, images..)
879 themestuff.each { |entry|
880 if !File.exists?(File.join(dest_dir, entry))
881 psys("cp '#{$FPATH}/themes/#{$theme}/#{entry}' '#{dest_dir}'")
885 #- copy any root-only resource file that goes with the theme (css, images..)
886 if xmldir.parent.name != 'dir'
887 themestuff_root.each { |entry|
888 if !File.exists?(File.join(dest_dir, entry))
889 psys("cp '#{$FPATH}/themes/#{$theme}/root/#{entry}' '#{dest_dir}'")
897 msg 2, _("Outputting in %s...") % dest_dir
899 #- populate data structure with sizes from theme
900 for sizeobj in $images_size
901 fullscreen_images ||= {}
902 fullscreen_images[sizeobj['name']] = []
903 thumbnail_images ||= {}
904 thumbnail_images[sizeobj['name']] = []
905 thumbnail_videos ||= {}
906 thumbnail_videos[sizeobj['name']] = []
908 #- a special dummy size to keep 'references' to thumbnails in case of panorama, because the GUI will use the regular thumbnails
909 thumbnail_images['dont-delete-file-for-gui'] = []
910 if $limit_sizes =~ /original/
911 fullscreen_images['original'] = []
914 images.size >= 1 and msg 3, _("\tcreating images thumbnails...")
916 #- create thumbnails for images
918 info("processing element")
919 base_dest_img = dest_dir + '/' + make_dest_filename(img.sub(/\.[^\.]+$/, ''))
921 thumbnail_dest_img = base_dest_img + "-#{$default_size['thumbnails']}.jpg"
922 gen_thumbnails_element("#{dir}/#{img}", xmldir, true, [ { 'filename' => thumbnail_dest_img, 'size' => $default_size['thumbnails'] } ])
925 elem = xmldir.elements["image[@filename='#{utf8(img)}']"]
926 for sizeobj in $images_size
927 size_fullscreen = sizeobj['fullscreen']
928 size_thumbnails = sizeobj['thumbnails']
929 fullscreen_dest_img = base_dest_img + "-#{size_fullscreen}.jpg"
930 fullscreen_images[sizeobj['name']] << File.basename(fullscreen_dest_img)
931 todo << { 'filename' => fullscreen_dest_img, 'size' => size_fullscreen }
932 if pano = pano_amount(elem)
933 thumbnail_images['dont-delete-file-for-gui'] << File.basename(base_dest_img + "-#{size_thumbnails}.jpg")
934 size_thumbnails = size_thumbnails.sub(/(\d+)/) { ($1.to_i * pano).to_i }
936 thumbnail_dest_img = base_dest_img + "-#{size_thumbnails}.jpg"
937 thumbnail_images[sizeobj['name']] << File.basename(thumbnail_dest_img)
938 todo << { 'filename' => thumbnail_dest_img, 'size' => size_thumbnails }
940 gen_thumbnails_element("#{dir}/#{img}", xmldir, true, todo)
941 if $limit_sizes =~ /original/
942 fullscreen_images['original'] << img
944 destimg = "#{dest_dir}/#{img}"
945 if $limit_sizes =~ /original/ && !File.exists?(destimg)
947 if ! sys("ln '#{dir}/#{img}' '#{destimg}'")
948 $hardlinks_ok = false
952 psys("cp '#{dir}/#{img}' '#{destimg}'")
958 videos.size >= 1 and msg 3, _("\tcreating videos thumbnails...")
960 #- create thumbnails for videos
961 videos.each { |video|
962 info("processing element")
964 thumbnail_dest_img = dest_dir + '/' + make_dest_filename(video.sub(/\.[^\.]+$/, '')) + "-#{$default_size['thumbnails']}.jpg"
965 gen_thumbnails_element("#{dir}/#{video}", xmldir, true, [ { 'filename' => thumbnail_dest_img, 'size' => $default_size['thumbnails'] } ])
968 for sizeobj in $images_size
969 size_thumbnails = sizeobj['thumbnails']
970 thumbnail_dest_img = dest_dir + '/' + make_dest_filename(video.sub(/\.[^\.]+$/, '')) + "-#{size_thumbnails}.jpg"
971 thumbnail_videos[sizeobj['name']] << File.basename(thumbnail_dest_img)
972 todo << { 'filename' => thumbnail_dest_img, 'size' => size_thumbnails }
974 gen_thumbnails_element("#{dir}/#{video}", xmldir, true, todo)
976 destvideo = "#{dest_dir}/#{video}"
977 if !File.exists?(destvideo)
979 if ! sys("ln '#{dir}/#{video}' '#{destvideo}'")
980 $hardlinks_ok = false
984 psys("cp '#{dir}/#{video}' '#{destvideo}'")
990 themestuff = Dir.entries("#{$FPATH}/themes/#{$theme}").
991 find_all { |e| !%w(. .. skeleton_image.html skeleton_thumbnails.html skeleton_index.html metadata root CVS).include?(e) }
992 themestuff_root = Dir.entries("#{$FPATH}/themes/#{$theme}/root").
993 find_all { |e| !%w(. .. CVS).include?(e) }
995 #- cleanup old images/videos (for when removing elements or sizes)
996 all_elements = fullscreen_images.collect { |e| e[1] }.flatten.
997 concat(thumbnail_images.collect { |e| e[1] }.flatten).
998 concat(thumbnail_videos.collect { |e| e[1] }.flatten).
1001 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
1003 msg 3, _("\tcleaning up: #{to_del.join(', ')}")
1004 File.delete(*to_del.collect { |e| File.join(dest_dir, e) })
1007 #- copy any resource file that goes with the theme (css, images..)
1008 themestuff.each { |entry|
1009 if !File.exists?(File.join(dest_dir, entry))
1010 psys("cp '#{$FPATH}/themes/#{$theme}/#{entry}' '#{dest_dir}'")
1014 #- copy any root-only resource file that goes with the theme (css, images..)
1015 if xmldir.parent.name != 'dir'
1016 themestuff_root.each { |entry|
1017 if !File.exists?(File.join(dest_dir, entry))
1018 psys("cp '#{$FPATH}/themes/#{$theme}/root/#{entry}' '#{dest_dir}'")
1023 msg 3, _("\tgenerating HTML pages...")
1024 #- fixup max per page
1025 if $N_per_page && $N_per_row
1026 $N_per_page = $N_per_page.to_i / $N_per_row.to_i * $N_per_row.to_i
1029 #- generate thumbnails*.html (page with thumbnails)
1030 image2thumbnailpage4js = []
1031 for sizeobj in $images_size
1032 info("processing size")
1033 html = $html_thumbnails.collect { |l| l.clone }
1037 xmldir.attributes['thumbnails-caption'] || utf8(File.basename(dir)))
1038 discover_iterations(iterations, i)
1041 html_thumbnails = ''
1042 html_thumbnails_nojs = ''
1045 reset_iterations(iterations)
1046 #- preprocess the @filename->elem, rexml is very slow with that; we dramatically improve this part of the processing
1048 xmldir.elements.each('image') { |elem|
1049 optfilename[elem.attributes['filename']] = elem
1052 type = images.include?(file) ? 'image' : videos.include?(file) ? 'video' : nil
1054 if type == 'image' && elem = optfilename[utf8(file)]
1055 if pano = pano_amount(elem)
1056 html_elem = run_iterations(iterations, pano)
1057 counter += count = pano.ceil
1058 html_elem.gsub!(/~~colspan~~/) { "colspan=\"#{count}\"" }
1060 html_elem = run_iterations(iterations, 1)
1062 html_elem.gsub!(/~~colspan~~/, '')
1065 html_elem = run_iterations(iterations, 1)
1067 html_elem.gsub!(/~~colspan~~/, '')
1070 index = images.index(file)
1071 html_elem.gsub!(/~~caption_iteration~~/,
1072 find_caption_value(xmldir, images[index]) || utf8(images[index]))
1073 html_elem.gsub!(/~~ifimage\?~~(.+?)~~fi~~/) { $1 }
1074 html_elem.gsub!(/~~ifvideo\?~~(.+?)~~fi~~/, '')
1075 elsif type == 'video'
1076 index = videos.index(file)
1077 if File.exists?("#{dest_dir}/#{thumbnail_videos[sizeobj['name']][index]}")
1078 html_elem.gsub!(/~~image_iteration~~/,
1079 '<a href="' + videos[index] + '">' + img_element("#{dest_dir}/#{thumbnail_videos[sizeobj['name']][index]}") + '</a>')
1081 html_elem.gsub!(/~~image_iteration~~/,
1082 '<a href="' + videos[index] + '">' + defer_translation(N_("(no preview)")) + '</a>')
1084 html_elem.gsub!(/~~caption_iteration~~/, find_caption_value(xmldir, videos[index]) || utf8(videos[index]))
1085 html_elem.gsub!(/~~ifimage\?~~(.+?)~~fi~~/, '')
1086 html_elem.gsub!(/~~ifvideo\?~~(.+?)~~fi~~/) { $1 }
1088 html_thumbnails += html_elem
1089 html_thumbnails_nojs += html_elem
1091 html_thumbnails.gsub!(/~~image_iteration~~/,
1092 '<a href="image-' + size2js(sizeobj['name']) + $htmlsuffix + '#current=' + fullscreen_images[sizeobj['name']][index] +
1093 '" name="' + fullscreen_images[sizeobj['name']][index] + '">' +
1094 img_element("#{dest_dir}/#{thumbnail_images[sizeobj['name']][index]}") + '</a>')
1095 html_thumbnails_nojs.gsub!(/~~image_iteration~~/,
1096 '<a href="' + fullscreen_images[sizeobj['name']][index] + '" name="' + fullscreen_images[sizeobj['name']][index] + '">' +
1097 img_element("#{dest_dir}/#{thumbnail_images[sizeobj['name']][index]}") + '</a>')
1098 #- remember in which thumbnails page is this element, for image->thumbnail link
1099 if sizeobj == $images_size[0]
1100 image2thumbnailpage4js << pagecount
1104 if counter == $N_per_page
1105 html_thumbnails += close_iterations(iterations)
1106 html_thumbnails_nojs += close_iterations(iterations)
1107 all_pages << [ html_thumbnails, html_thumbnails_nojs ]
1108 html_thumbnails = ''
1109 html_thumbnails_nojs = ''
1111 reset_iterations(iterations)
1117 html_thumbnails += close_iterations(iterations)
1118 html_thumbnails_nojs += close_iterations(iterations)
1119 all_pages << [ html_thumbnails, html_thumbnails_nojs ]
1122 i.gsub!(/~~theme~~/, $theme)
1123 i.gsub!(/~~current_size~~/, sizeobj['name'])
1124 i.gsub!(/~~htmlsuffix~~/, $htmlsuffix)
1125 i.gsub!(/~~current_size_js~~/, size2js(sizeobj['name']))
1126 i.gsub!(/~~madewith~~/, $madewith || '')
1127 i.gsub!(/~~indexlink~~/, $indexlink || '')
1128 substitute_navigation(i, xmldir)
1130 html_nojs = html.collect { |l| l.clone }
1132 for page in all_pages
1133 html_thumbnails, html_thumbnails_nojs = page
1134 final_html = html.collect { |l| l.clone }
1135 mstuff = defer_translation(N_("Pages: ")) +
1136 (pagecount > 0 ? "<a href=\"thumbnails-#{size2js(sizeobj['name'])}%nojs-#{pagecount - 1}#{$htmlsuffix}\">" + defer_translation(N_("<- Previous")) + "</a> " : '') +
1137 all_pages.collect_with_index { |p,idx| page == p ? idx + 1 : "<a href=\"thumbnails-#{size2js(sizeobj['name'])}%nojs-#{idx}#{$htmlsuffix}\">#{idx + 1}</a>" }.join(', ') +
1138 (pagecount < all_pages.size - 1 ? " <a href=\"thumbnails-#{size2js(sizeobj['name'])}%nojs-#{pagecount + 1}#{$htmlsuffix}\">" + defer_translation(N_("Next ->")) + "</a> " : '')
1140 i.sub!(/~~run_slideshow~~/,
1141 images.size <= 1 ? '' : '<a href="image-' + size2js(sizeobj['name']) + $htmlsuffix + '#run_slideshow=1">' + defer_translation(N_("Run slideshow!"))+'</a>')
1142 i.sub!(/~~thumbnails~~/, html_thumbnails)
1143 if all_pages.size == 1
1144 i.gsub!(/~~ifmultiplepages\?~~.*~~fi~~/, '')
1146 i.gsub!(/~~ifmultiplepages\?~~(.+?)~~fi~~/) { $1 }
1147 i.gsub!(/~~multiplepagesstuff~~/, mstuff.gsub('%nojs', ''))
1149 substitute_html_sizes(i, sizeobj, 'thumbnails', "-#{pagecount}")
1150 substitute_pathtobase(i, xmldir)
1152 save_html(final_html, "#{dest_dir}/thumbnails-#{size2js(sizeobj['name'])}-#{pagecount}")
1153 final_html_nojs = html_nojs.collect { |l| l.clone }
1154 for i in final_html_nojs
1155 i.sub!(/~~run_slideshow~~/, defer_translation(N_("<i>Click on an image to view it larger</i>")))
1156 i.sub!(/~~thumbnails~~/, html_thumbnails_nojs)
1157 if all_pages.size == 1
1158 i.gsub!(/~~ifmultiplepages\?~~.*~~fi~~/, '')
1160 i.gsub!(/~~ifmultiplepages\?~~(.+?)~~fi~~/) { $1 }
1161 i.gsub!(/~~multiplepagesstuff~~/, mstuff.gsub('%nojs', '-nojs'))
1163 substitute_html_sizes(i, sizeobj, 'thumbnails', "-nojs-#{pagecount}")
1164 substitute_pathtobase(i, xmldir)
1166 save_html(final_html_nojs, "#{dest_dir}/thumbnails-#{size2js(sizeobj['name'])}-nojs-#{pagecount}")
1171 info("finished processing sizes")
1173 #- generate "main" thumbnails.html page that will reload to correct size thanks to cookie
1174 save_html(html_reload_to_thumbnails, "#{dest_dir}/thumbnails")
1176 #- generate image.html (page with fullscreen images)
1178 captions4js = find_captions(xmldir, images).collect { |e| e ? '"' + e.gsub('"', '\"') + '"' : '""' }.join(', ')
1179 thumbnailspage4js = image2thumbnailpage4js.collect { |e| "\"#{e}\"" }.join(', ')
1180 for sizeobj in $images_size
1181 html = $html_images.collect { |l| l.clone }
1182 images4js = fullscreen_images[sizeobj['name']].collect { |e| "\"#{e}\"" }.join(', ')
1185 for sizeobj2 in all_images_sizes
1186 if sizeobj != sizeobj2
1187 otherimages4js += "var images_#{size2js(sizeobj2['name'])} = new Array(" + fullscreen_images[sizeobj2['name']].collect { |e| "\"#{e}\"" }.join(', ') + ")\n"
1188 othersizes << "\"#{size2js(sizeobj2['name'])}\""
1192 i.gsub!(/~~images~~/, images4js)
1193 i.gsub!(/~~other_images~~/, otherimages4js)
1194 i.gsub!(/~~thumbnailspages~~/, thumbnailspage4js)
1195 i.gsub!(/~~other_sizes~~/, othersizes.join(', '))
1196 i.gsub!(/~~captions~~/, captions4js)
1197 i.gsub!(/~~title~~/, xmldir.attributes['thumbnails-caption'] || utf8(File.basename(dir)))
1198 i.gsub!(/~~thumbnails~~/, '<a href="thumbnails-' + size2js(sizeobj['name']) + $htmlsuffix + '" id="thumbnails">' + defer_translation(N_('return to thumbnails')) + '</a>')
1199 i.gsub!(/~~theme~~/, $theme)
1200 i.gsub!(/~~current_size~~/, size2js(sizeobj['name']))
1201 i.gsub!(/~~htmlsuffix~~/, $htmlsuffix)
1202 i.gsub!(/~~madewith~~/, $madewith || '')
1203 i.gsub!(/~~indexlink~~/, $indexlink || '')
1204 substitute_html_sizes(i, sizeobj, 'image', '')
1205 substitute_navigation(i, xmldir)
1206 substitute_pathtobase(i, xmldir)
1208 save_html(html, "#{dest_dir}/image-#{size2js(sizeobj['name'])}")
1216 #- add attributes to <dir..> elements needing so
1217 if $mode != 'use_config'
1218 msg 3, _("\tfixating configuration file...")
1219 $xmldoc.elements.each('//dir') { |element|
1220 path = captionpath = element.attributes['path']
1221 descendant_element = element.elements['descendant::image'] || element.elements['descendant::video']
1222 if !descendant_element
1223 msg 3, _("\t\tremoving %s, no element in it") % path
1224 element.remove #- means we have a directory with nothing interesting in it
1226 captionfile = "#{descendant_element.parent.attributes['path']}/#{descendant_element.attributes['filename']}"
1227 basename = File.basename(path)
1228 if element.elements['dir']
1229 if !element.attributes['subdirs-caption']
1230 element.add_attribute('subdirs-caption', basename)
1232 if !element.attributes['subdirs-captionfile']
1233 element.add_attribute('subdirs-captionfile', captionfile)
1236 if element.child_byname_notattr('image', 'deleted') || element.child_byname_notattr('video', 'deleted')
1237 if !element.attributes['thumbnails-caption']
1238 element.add_attribute('thumbnails-caption', basename)
1240 if !element.attributes['thumbnails-captionfile']
1241 element.add_attribute('thumbnails-captionfile', captionfile)
1248 #- write down to disk config if necessary
1250 ios = File.open($config_writeto, "w")
1251 $xmldoc.write(ios, 0)
1256 msg 3, _(" completed necessary stuff for GUI, exiting.")
1260 #- second pass to create index.html files and previous/next links
1261 info("creating index.html")
1262 msg 3, _("\trescanning directories to generate all 'index.html' files...")
1264 #- recompute the memoization because elements mights have been removed (the ones with no element in them)
1266 $xmldoc.elements.each('//dir') { |elem|
1267 optxpath[elem.attributes['path']] = elem
1270 examined_dirs.each { |dir|
1271 info("index.html: #{dir}|#{$source}")
1273 xmldir = optxpath[utf8(dir)]
1274 if !xmldir || (xmldir.attributes['already-generated'] && !$force) || xmldir.attributes['deleted']
1277 dest_dir = make_dest_filename(dir.sub(/^#{Regexp.quote($source)}/, $dest))
1279 previous_album = find_previous_album(xmldir)
1280 next_album = find_next_album(xmldir)
1282 if xmldir.elements['dir']
1283 html = $html_index.collect { |l| l.clone }
1286 caption = xmldir.attributes['subdirs-caption']
1287 i.gsub!(/~~title~~/, caption)
1288 substitute_navigation(i, xmldir)
1289 substitute_pathtobase(i, xmldir)
1290 discover_iterations(iterations, i)
1294 reset_iterations(iterations)
1296 #- deal with "current" album (directs to "thumbnails" page)
1297 if xmldir.attributes['thumbnails-caption']
1298 thumbnail = "#{dest_dir}/thumbnails-thumbnail.jpg"
1299 gen_thumbnails_subdir(from_utf8(xmldir.attributes['thumbnails-captionfile']), xmldir, false,
1300 [ { 'filename' => thumbnail, 'size' => $albums_thumbnail_size } ], 'thumbnails')
1301 html_index += run_iterations(iterations, 1)
1302 html_index.gsub!(/~~image_iteration~~/, "<a href=\"thumbnails#{$htmlsuffix}\">" + img_element(thumbnail) + '</a>')
1303 html_index.gsub!(/~~caption_iteration~~/, xmldir.attributes['thumbnails-caption'])
1306 #- deal with sub-albums (direct to subdirs/index.html pages)
1307 xmldir.elements.each('dir') { |child|
1308 if child.attributes['deleted']
1311 subdir = make_dest_filename(from_utf8(File.basename(child.attributes['path'])))
1312 thumbnail = "#{dest_dir}/thumbnails-#{subdir}.jpg"
1313 html_index += run_iterations(iterations, 1)
1314 captionfile, caption = find_subalbum_caption_info(child)
1315 gen_thumbnails_subdir(captionfile, child, false,
1316 [ { 'filename' => thumbnail, 'size' => $albums_thumbnail_size } ], find_subalbum_info_type(child))
1317 html_index.gsub!(/~~caption_iteration~~/, caption)
1318 html_index.gsub!(/~~image_iteration~~/, "<a href=\"#{subdir}/index#{$htmlsuffix}\">" + img_element(thumbnail) + '</a>')
1321 html_index += close_iterations(iterations)
1324 i.gsub!(/~~thumbnails~~/, html_index)
1325 i.gsub!(/~~madewith~~/, $madewith || '')
1326 i.gsub!(/~~indexlink~~/, $indexlink || '')
1330 html = html_reload_to_thumbnails
1333 save_html(html, "#{dest_dir}/index")
1335 #- in case MultiViews will not work, generate some compat
1336 ios = File.open("#{dest_dir}/index.html", "w")
1337 ios.write("<html><head><meta http-equiv=\"refresh\" content=\"0.1;url=index.#{$multi_languages[1]}.html\"></head></html>")
1341 #- substitute multiple "return to albums", previous/next correctly
1342 #- the following two statements are dramatical optimizations to executing for each substInFile callback
1343 dirpresent = xmldir.elements['dir']
1344 parentname = xmldir.parent.name
1345 if xmldir.child_byname_notattr('image', 'deleted') || xmldir.child_byname_notattr('video', 'deleted')
1346 for suffix in [ '', '-nojs' ]
1347 for sizeobj in $images_size
1348 Dir.glob("#{dest_dir}/thumbnails-#{size2js(sizeobj['name'])}#{suffix}-*.html") do |file|
1349 substInFile(file) { |line|
1350 sub_previous_next_album(file, previous_album, next_album, line)
1352 line.sub!(/~~return_to_albums~~/, '<a href="index' + $htmlsuffix + '">' + find_translation_for_file(file, N_('return to albums')) + '</a>')
1354 if parentname == 'dir'
1355 line.sub!(/~~return_to_albums~~/, '<a href="../index' + $htmlsuffix + '">' + find_translation_for_file(file, N_('return to albums')) + '</a>')
1357 line.sub!(/~~return_to_albums~~/, '')
1363 if suffix == '' && xmldir.child_byname_notattr('image', 'deleted')
1364 Dir.glob("#{dest_dir}/image-#{size2js(sizeobj['name'])}*.html") do |file|
1365 substInFile(file) { |line|
1366 sub_previous_next_album(file, previous_album, next_album, line)
1375 msg 3, _(" all done.")
1382 build_html_skeletons