#!/usr/bin/ruby
#
# gallery.cgi
#
# Image gallery script.
#
# Usage: say all your gallery stuff is in a directory called pics/.
# Each different gallery lives in a subdirectory of pics (say, pics/cats/,
# pics/computers/, etc.). Put this script in pics and make it readable
# and executable. Edit the galleries variable below so that it's a list of
# all the galleries you want viewable. (In our example, it should say
#
# galleries = ["cats", "computers", ...]
#
# Finally, link to pics/gallery.cgi?page=cats to show the cats gallery.
# Link to pics/gallery.cgi?page=cats&display=muffin to show the picture
# in pics/cats/muffin.jpg. If pics/cats/muffin.desc exists, the description
# text in that file will be displayed below the picture.
#
# Oh. Thumbnails. The thumbnail for any given picture, e.g. pics/cats/muffin.jpg
# needs to live in pics/cats/thumbs/muffin.jpg.
#
# You should also go through and edit the html that's emitted in this script.
#
# So, to reiterate:
# pics/ - images directory
# pics/gallery.cgi - this file
# pics/cats.header - description for the cats gallery
# pics/cats/ - directory for a single gallery
# pics/cats/muffin.jpg - a picture of a cat
# pics/cats/muffin.desc - the description for muffin.jpg
# pics/cats/tama.jpg - another picture of a cat
# pics/cats/tama.desc - description of another picture of a cat
# ...
# pics/cats/thumbs/muffin.jpg - thumbnail for muffin.jpg
# pics/cats/thumbs/tama.jpg - thumbnail for tama.jpg
# ...
# pics/computers.header - description for the computers gallery
# pics/computers/ - another gallery
# ...
#
# http://server.com/pics/gallery.cgi?page=cats
# Will display thumbnails and descriptions for all the pictures in cats/.
# http://server.com/pics/gallery.cgi?page=cats&display=muffin
# Will display cats/muffin.jpg with its description.
#
# Written by Matthew Reppert on 15 Nov, 2004 and released into the
# public domain. (As such, this software has no warranty and is provided
# "as-is".)
# Comments added 19, November 2004.
#
require 'cgi'
#
# A list of valid galleries to display.
#
galleries = ["crap", "pencil", "smut", "color"]
this_page_url = "http://sacredchao.net/~arashi/art/gallery.cgi"
#
# Works like the include virtual SSI directive.
#
def ssi_include(filename)
if FileTest.exists?(filename)
lines = IO.readlines(filename)
lines.each {|l| print l }
end
end
def ssi_include_alt(filename, alt)
if FileTest.exists?(filename)
lines = IO.readlines(filename)
lines.each {|l| print l }
elsif FileTest.exists?(alt)
lines = IO.readlines(alt)
lines.each {|l| print l }
end
end
#
# Write up to max bytes of s to fout.
#
def write_string_bound(fout, s, max)
if s == nil
fout.write [0].pack("n")
return
end
if (s.length > max)
fout.write [max].pack("n")
fout.write s[0, max];
else
fout.write [s.length].pack("n")
fout.write s;
end
end
#
# An image.
#
class Image
attr_accessor :filename
def initialize
@filename = ""
end
def print_code(section, lang)
a_text = ''
img_text = ' \n" + a_text + "\n" + img_text + "\n'
=begin
print "\n
Comment by "
print '' if @email
print @name
print '' if @email
comment.gsub!(/, "<")
comment.gsub!(/>/, ">")
print "
\n" + @comment
print "\n
Navigation
\n" print 'Back to home page
' + "\n"
print 'Art home'
print "
Welcome to my art page. Here I have random bits of drawing\n" print "that I've done over time. There are currently " print galleries.size print " galleries available:\n" print "
By the way, you may notice that gallery generation is\n" print "totally dynamic now, and you can post comments.
\n" ssi_include(updates) print"\n\nYou tried to look in the nonexistant " + page print " gallery. You seem lost. Try going back to the " print 'main art page.
' print "\n\n\n" exit 0 end # # Make sure display points to a file in the current gallery, if it's given. # if display display.sub!(/.*\//, "") if FileTest.exists?(page + '/' + display) if File.stat(page + '/' + display).readable? == false display = nil else comment_file = page + '/' + display.sub(/\.[^.]*$/, '.comment') end else display = nil end end # # If a comment was posted, save it in the file containing comments for this # picture. # if post == true and comment == nil post = false end if post && comment_file if name == nil name = "Nanashi-san" end File.open(comment_file, "a") { |fout| fout.seek(0, IO::SEEK_END) write_string_bound(fout, name, 16) write_string_bound(fout, email, 240) write_string_bound(fout, comment, 512) } end # # Print out boilerplate # print "\n\n\nHey ... nothing to see here yet.
\n\n" else files.sort { |x,y| File.ctime(x) <=> File.ctime(y) } files.reverse! files.each { |x| i.filename = x ; i.print_code(page, lang) } end else # # We were asked to display a specific image. Do so, with links to the # previous image in the gallery, the gallery index, and the next image # in the gallery. # files = Dir.glob(page + "/*.??g") files.sort { |x,y| File.ctime(x) <=> File.ctime(y) } ind = files.index(page + '/' + display) print '" desc_file = page + '/' + display.sub(/\.[^.]*$/, '.desc') if lang ssi_include_alt(desc_file + "." + lang, desc_file) else ssi_include(desc_file) end print "
\n" print '