%
' +------------------------------------------------------------------+
' | ASP Slideshow v1.2 |
' | Jonathon Jongsma (slideshow@quotidian.org) |
' +------------------------------------------------------------------+
' | This program is free software; you can redistribute it and/or |
' | modify it under the terms of the GNU General Public License as |
' | published by the Free Software Foundation; either version 2 of |
' | the License, or(at your option) any later version. |
' | |
' | This program is distributed in the hope that it will be useful, |
' | but WITHOUT ANY WARRANTY; without even the implied warranty of |
' | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
' | GNU General Public License for more details. |
' | |
' | You should have received a copy of the GNU General Public |
' | License along with this program; if not, write to the Free |
' | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
' | MA 02111-1307 USA |
' +------------------------------------------------------------------+
' | To use the script, save it with a .asp extension and change all |
' | the values in the script that look like **this** to a value |
' | appropriate for your website. |
' | |
' | Create a parent directory for your image galleries and in this |
' | directory create separate directories for each gallery (the |
' | directory name will become the gallery name). Within each |
' | gallery directory, create a 'thumbs' directory which will |
' | contain the thumbnail images of your gallery images [note: the |
' | thumbnail images must have filenames identical to the full-size |
' | images]. The filename (without the extension) will become the |
' | name of the image, but all underscores will be displayed as |
' | as spaces. |
' | |
' | If you use this code on your website, please let me know as I'd |
' | love to see how it's being used. |
' +------------------------------------------------------------------+
'the url of this script
Dim asp_url, strGalleryParentFolder
asp_url = Request.ServerVariables("URL")
' note: the following value must have a trailing "/" in order to work correctly
strGalleryParentFolder = "graphics/slideshow/"
'this simply defines constants for an array of file information to make it easier
'to refer to the array data
const FILENAME = 0
const FILECREATED = 1
const DESC = 2
const GALLERY = 3
const ARRAYID = 4
'create an array to hold the filenames
dim arrImages()
' define variables to capture the arguments passed to the script from the querystring
' strGallery holds the album name, and strID holds the picture number
dim strGallery, strID
strGallery = Request.Querystring("album")
strID = Request.QueryString("id")
' kill /.. attacks, etc. [this is not guaranteed to make the script secure.
' In fact, I'm not sure if it works at all. you may want to modify it to fit your needs]
dim fixGalleryName
Set fixGalleryName = new RegExp
fixGalleryName.Global = true
fixGalleryName.IgnoreCase = true
fixGalleryName.Pattern = "\.\.\/*"
strGallery = fixGalleryName.Replace(strGallery, "")
' kill escape characters
fixGalleryName.Pattern = "([;<>\*\|'\$!#\(\)\[\]\{\}:'""])"
strGallery = fixGalleryName.Replace(strGallery, "")
set fixGalleryName = nothing
' The URL to the images
dim strGalleryURL
strGalleryURL = strGalleryParentFolder & strGallery
' Get the path to the images
dim strGalleryPath
strGalleryPath = Server.MapPath("strGalleryURL")
'output html file
response.write "" & _
"" & _
"
" & _
"Cherokee Property Survey" & _
"" & _
"" & _
"" & _
""
response.write ""& _
"" & _
""& _
"" & _
" " & _
" " & _
"Cherokee County Digital History Project"& _
""& _
" | "& _
""& _
""& _
" "& _
""& _
" "& _
" | "& _
""& _
""& _
" "& _
""& _
" | "& _
"
"& _
"" & _
""& _
" "& _
" "& _
" | "& _
""& _
" "& _
" "& _
" | "& _
"
"& _
""& _
"" & _
""& _
"Preservation Multimedia Archive"& _
""& _
" | "& _
""& _
""& _
"Email Us"& _
""& _
" "& _
" "& _
" "& _
" "& _
" | "& _
"
"& _
"
"& _
"
"
response.write ""& _
""& _
""& _
""& _
""& _
"Home"& _
""& _
" · "& _
""& _
"Property Survey Database"& _
""& _
""& _
""& _
""& _
""& _
" · "& _
"Image Slideshow"& _
" · "& _
""& _
"Historical Interpretations"& _
""& _
" · "& _
""& _
"Pedagogical Interpretations"& _
""& _
""& _
""& _
"
"& _
" "& _
"
"
dim i
if strGallery <> "" Then
i = 0
' if a gallery name was specified, attempt to load all of the image info
' from that gallery (directory) into an array
for each item in GetImageList(strGallery)
redim preserve arrImages(i)
arrImages(i) = item
i = i + 1
next
if strID <> "" Then
' if an gallery name was specified AND an image number was specified,
' then display that specific image
ShowImage arrImages, cInt(strID)
else
' if a gallery name was specified and an image number was NOT specified,
' then display a gallery of all thumbnail images in that gallery
ShowThumbs arrImages
End If
Else
' if no gallery name was specified, then display a list of all galleries
' (actually a list of all directories in the galleries parent folder)
showGalleries
end if
response.write ""
response.write ""
response.write ""
'Define functions used above
'#######################################
' GetImageList takes a gallery name as an argument, opens the folder with
' this name, and reads the image filenames into an array, which is returned
Function GetImageList(gallery)
' create a filesystemobject to read filenames from the directory
dim objFSO
set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' create an object for the folder and file list
dim objGalleryFolder, objImageList
dim strGalleryPath
strGalleryPath = Server.mappath(strGalleryParentFolder & gallery & "/")
Set objGalleryFolder = objFSO.GetFolder(strGalleryPath)
Set objImageList = objGalleryFolder.Files
'check for .jpg or .gif files
Dim checkType, strText
Set checkType = New RegExp
checkType.Global = true
checkType.IgnoreCase = True
' Pattern finds any filename with .jpg, .jpeg, or gif on the end of it
' can be modified to suit your needs (i.e. adding .png, etc.)
checkType.Pattern = "([\w]+\.(gif)|(jpg)|(jpeg))"
' read filenames from objImageList to the images array
dim file, i, arrImages()
i = 0
for each file in objImageList
redim Preserve arrImages(i)
if checkType.Test(file.Name) Then
' only store filenames for image files that match the pattern defined above
' arrImages will hold an array of arrays that contain filename, date, description
' (modified from the filename), gallery name, and ID of each image
arrImages(i) = array(file.Name, file.DateCreated, ConvUnderscore(file.Name), gallery, i)
i = i + 1
End if
next
Set objFSO = nothing
Set objGalleryFolder = nothing
Set objImageList = nothing
Set checkType = nothing
' remember the total number of images in the gallery (actually i)
dim intTotalImages
intTotalImages = i-1
' sort the image list by FILENAME
dim arrImagesSorted(), item, subItem
i = 0
for each item in sortArray(arrImages, FILENAME)
redim preserve arrImagesSorted(i)
arrImagesSorted(i) = item
i = i + 1
next
GetImageList = arrImagesSorted
End Function
'#######################################
Function ConvUnderscore(filename)
' this function takes a filename (such as image_file.jpg) as an argument, replaces all of the
' underscore characters (_) with spaces, and strips off the extention, and uses this as a
' desciption of the image. for example, "image_file.jpg" would be converted to "image file"
dim strDescription, intExtPos
' strip extention (i.e. ".jpg")
if inStr(filename, ".") then
intExtPos = inStrRev(filename, ".") - 1
strDescription = left(filename, intExtPos)
else
strDescription = filename
end if
' convert underscores to spaces in the description
dim fixDesc
set fixDesc = New RegExp
fixDesc.Global = true
fixDesc.Pattern = "_"
strDescription = fixDesc.Replace(strDescription," ")
set fixDesc = nothing
' return the description
ConvUnderscore = strDescription
End Function
'#######################################
' SortArray takes as arguments the array that you want to sort, and type of sorting that you want to
' perform. setting sortBy = 0 will sort by string, and setting it equal to 1 will sort by number (descending)
' which is useful for dates.
Function SortArray(arrInput, sortBy)
dim i, j, tempVar
for i = 0 to UBound(arrInput)-1
for j = i to UBound(arrInput)
if sortBy = 0 Then ' sort by string
if strComp(arrInput(i)(sortBy), arrInput(j)(sortBy),1) > 1 Then
tempvar = arrInput(i)
arrInput(i) = arrInput(j)
arrInput(j) = tempVar
end if
else ' descending date
if arrInput(i)(sortBy) < arrInput(j)(sortBy) Then
tempvar = arrInput(i)
arrInput(i) = arrInput(j)
arrInput(j) = tempVar
end if
end if
Next
Next
' return the sorted array
sortArray = arrInput
End Function
'#######################################
' ShowImage needs an image list (in array form) and an image number. it then generates the html for
' displaying this image in detail mode (full-size) and also generates the links for previous and next
' images (so the user can browse through the 'slideshow').
sub ShowImage(arrImageList, ImageNumber)
intTotalImages = Ubound(arrImageList)
response.write "Gallery: " & ConvUnderscore(arrImageList(ImageNumber)(GALLERY)) & "
"
' if the image id that is specified is not valid, it displays a link to display the thumbnail
' view for this gallery and stops processing this function
if ImageNumber < 0 OR ImageNumber > intTotalImages Then
Response.Write "You have entered an invalid image id, go to the
the thumbnails "
exit sub
End if
' display the links for navigating forward and backward through the slideshow, as well as a link
' to return 'home' to the gallery list
response.write ""
if ImageNumber > 0 Then
Response.Write "
« Prev . . . "
else ' if we are currently already at the first image in the slideshow, grey out the 'previous' link
response.Write "« prev . . . "
End if
Response.Write "
pics"
if ImageNumber < intTotalImages Then
Response.Write " . . .
Next »"
else ' if we are currently at the last image in the slideshow, grey out the 'next' link
Response.Write " . . . next »"
End if
response.write "
"
' display the image
response.write "
"
' show the desciption
response.write "" & arrImageList(ImageNumber)(DESC) & "
"
' display position within the slideshow
response.write "Picture " & ImageNumber+1 & " of " & intTotalImages+1 & "
"
' link to go back to the thumbnail view
response.write "[view thumbnails]
"
response.write "© **your name**
"
response.write ""
End sub
'#######################################
' showThumbs takes in an image list in array form and displays a gallery of thumbnails
sub ShowThumbs(arrImageList)
Response.write "Gallery: " & ConvUnderscore(arrImageList(id)(GALLERY)) & "
"
'displays thumbnails as floated divs, could also be done with tables so that it would be displayed
' correctly in older browsers, but the code would be considerably more complex
dim counter
for counter = 0 to Ubound(arrImageList)
response.write "
"
next
response.write "
[click to view larger image]
"
' link back to gallery list
response.write "Back to
pictures"
response.write "
"
End Sub
'#######################################
' showGalleries reads the names of the folders inside of your galleries parent folder
' and writes them out as a list, with links to the gallery pages.
sub showGalleries
const FILENAME = 0
const DATECREATED = 1
dim arrGalleries()
dim i, item
i = 0
dim objFSO
set objFSO = Server.CreateObject("Scripting.FileSystemObject")
dim objGalleryFolder, objGalleryList, strGalleryPath
strGalleryPath = Server.Mappath(strGalleryParentFolder)
Set objGalleryFolder = objFSO.GetFolder(strGalleryPath)
Set objGalleryList = objGalleryFolder.subfolders
' Write out a list of galleries with date added
response.write "Choose a gallery
"
response.write "
"
for each file in objGalleryList
redim preserve arrGalleries(i)
arrGalleries(i) = array(file.Name, file.dateCreated)
i = i + 1
next
i = 0
dim arrNewGallery()
for each item in sortArray(arrGalleries, DATECREATED)
redim preserve arrNewGallery(i)
arrNewGallery(i) = array(item(FILENAME), item(DATECREATED))
i = i + 1
next
for each item in arrNewGallery
Response.write "· " & _
ConvUnderscore(item(FILENAME)) & " added " & formatDateTime(item(DATECREATED),2) & " ·
"
next
response.write "
"
Set objFSO = nothing
Set objGalleryFolder = nothing
Set objImageList = nothing
set objGalleryList = nothing
end Sub
'#######################################
' CHANGELOG:
' v1.0: initial release
' v1.1: changed license to GPL, added more documentation
' v1.2: Converted Underscores to spaces in gallery title
%>