Skip to content
Snippets Groups Projects
Commit 660aae41 authored by deuce's avatar deuce
Browse files

An example photo gallery app with a magical 404 error handler which

generates thumbnails if it doesn't already exist.

See the README for more details.
parent bccaac95
No related branches found
No related tags found
No related merge requests found
This is a sample set of simple photo gallery scripts. This also serves as and
example of usage of webctrl.ini for custom error pages.
The pics directory contains subdirectories with .jpg files.
When the gallery is initially viewed, the custom 404 error handler in the thumbs
directory will generate a thumbnail for each picture assuming that ImageMagicks
convert utility is installed and is in your path.
Remove the access.ars file to allow public access to this dir.
LEVEL 90
<html></html>
var picspath=web_root_dir+'/gallery_ex/pics';
writeln('<html><head><title>'+http_request.query['gallery']+' gallery</title></head>');
writeln('<body>');
var pics=directory(picspath+'/'+http_request.query['gallery']+'/*.jpg');
for(index in pics) {
var filename=pics[index];
filename=filename.replace(/.*\//,'');
writeln('<a target="image" href="pics/'+http_request.query['gallery']+'/'+filename+'"><img border="0" src="thumbs/'+http_request.query['gallery']+'/'+filename+'"></a> ');
}
writeln('</body></html>');
var picspath=web_root_dir+'/gallery_ex/pics';
writeln("<html><head><title>Image Gallery List</title></head>");
writeln("<body>");
var galleries=new Array();
galleries=directory(picspath+'/*');
for(gallery in galleries) {
var name=galleries[gallery];
name=name.replace(/.*\/(.*)\//,'$1');
var pics=new Array();
pics=directory(picspath+'/'+name+'/*.jpg');
writeln('<p><a href="gallery_bottom.ssjs?gallery='+name+'" target="bottom">'+name+'</a><br>'+strftime("%m/%d/%Y %H:%M:%S",file_date(picspath+'/'+name))+'<br>'+(pics.length)+' pictures</p>');
}
write('</table></body></html>');
var picspath=web_root_dir+'/gallery_ex/pics';
var gallery=http_request.query['gallery'];
if(gallery==undefined) {
writeln("<html><head><title>Synchronet Galleries"+picspath+"</title></head>");
}
else {
writeln('<html><head><title>'+gallery+'</title></head>');
}
writeln('<frameset cols="*,200" style="margin: 0;" marginheight="0" marginwidth="0" border="0" framespacing="0">');
writeln(' <frameset rows="*,110" style="margin: 0;" marginheight="0" marginwidth="0" border="0" framespacing="0">');
writeln(' <frame name="image" src="blank.html" marginheight="0" marginwidth="0" border="0" framespacing="0">');
if(gallery==undefined) {
writeln(' <frame name="bottom" src="blank.html" marginheight="0" marginwidth="0" border="0" framespacing="0">');
}
else {
writeln(' <frame name="bottom" src="gallery_bottom.ssjs?gallery='+gallery+'" marginheight="0" marginwidth="0" border="0" framespacing="0">');
}
writeln(' </frameset>');
writeln(' <frame name="gallery_index" src="gallery_index.ssjs" marginheight="0" marginwidth="0" border="0" framespacing="0">');
writeln('</frameset>');
writeln('<body>Frames required</body>');
writeln('</html>');
var picspath=web_root_dir+'/gallery_ex/pics';
var thumbpath=web_root_dir+'/gallery_ex/thumbs';
var gallery=http_request.real_path;
gallery=gallery.replace(/^.*\/([^\/]*?)\/[^\/]*$/,"$1");
var filename=http_request.real_path;
filename=filename.replace(/.*\//,'');
if(!file_isdir(thumbpath+'/'+gallery)) {
mkdir(thumbpath+'/'+gallery);
}
var fullthumb=thumbpath+'/'+gallery+'/'+filename
if(!file_exists(fullthumb)) {
var fullpic=picspath+'/'+gallery+'/'+filename
if(file_exists(fullpic)) {
system.exec('convert '+fullpic+' -thumbnail 120 '+fullthumb);
}
}
if(file_exists(fullthumb)) {
http_reply.status="200 Ok";
http_reply.header['Content-Type']='image/jpeg';
var f=new File(fullthumb);
f.open('r',true);
write(f.read());
f.close();
}
else {
http_reply.status="404 Not Found";
write("<html><head><title>404 Error</title></head><body>404 Not Found</body></html>");
}
[*.jpg]
ErrorDirectory=gallery_ex/thumbs
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment