# -*-ruby-*- # # Picture gallery index processor/generator # Part of nysagallery # # Copyright (c) 2006, 2007 Stephen Williams, all rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the copyright holder may not be used to endorse or # promote products derived from this software without specific prior # written permission. # # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # #Dir.chdir("/home/stephen/public_html/cgi-bin") require './gallery_lib' class GalleryIndex RCS_ID = "$Id: gallery_index.rbx,v 1.8 2007/11/25 16:39:17 stephen Exp $" include GalleryLib attr_reader :cgi # Constructor def initialize @cgi = CGI.new @index_html = "" end # Generates the index document def generate File.open("gallery.dump") do |file| @galleries = Marshal.restore(file) end make_gallery_html end # Outputs the HTML def output total_pictures = 0 @galleries.each_value do |gallery| total_pictures += gallery.picture_count end @cgi.out do < Picture Galleries

Picture Galleries

There #{@galleries.size == 1 ? "is one picture gallery" : "are #{@galleries.size} picture galleries"} available to browse, containing a total of #{total_pictures == 1 ? "one picture" : "#{total_pictures} pictures"}.

Newer pictures can be found on my Picasa gallery.

#{@index_html}

#{GalleryLib.rcs_mangle(RCS_ID)}
#{GalleryLib.rcs_mangle(GalleryLib::RCS_ID)}

END end end private # Produces the HTML for the galleries # # Gallery URLs are formatted thusly: # URL_BASE/gallery_name # so the web server must rewrite them into the CGI format: # URL_BASE/gallery.rbx?gallery=gallery_name def make_gallery_html @index_html << "\n" @galleries.each_value do |gallery| url = URL_BASE + gallery.name @index_html << "" section = gallery.random_section picture = section.random_picture @index_html << "" end @index_html << "
" @index_html << GalleryLib.format_thumbnail(gallery, section, picture, "Sample picture from #{gallery.title}", url) @index_html << "

" @index_html << "#{gallery.title}

" @index_html << "

#{gallery.description}

" if gallery.description @index_html << "

Created: #{gallery.created}" @index_html << "
Updated: #{gallery.updated}" if gallery.updated > gallery.created @index_html << "
#{gallery.picture_count} picture#{gallery.picture_count > 1 ? 's' : ''}" @index_html << "

" @index_html << "
\n" end end galleryindex = GalleryIndex.new begin galleryindex.generate galleryindex.output rescue GalleryLib::NysaGalleryException => ngex galleryindex.cgi.out("status" => ngex.status.to_s, "type" => "text/plain") do ngex.message end rescue => ex galleryindex.cgi.out("status" => "SERVER_ERROR", "type" => "text/plain") do "#{ex.message}\n#{ex.backtrace.join("\n")}\n" end end