From: Andy Spencer Date: Mon, 24 Dec 2012 03:41:56 +0000 (+0000) Subject: Update gallery X-Git-Url: http://pileus.org/git/?p=~andy%2Fct;a=commitdiff_plain;h=abe3586c077af9d94ed2ee0ba7d565996483428a Update gallery --- diff --git a/gallery/gallery.c b/gallery/gallery.c index 08590cc..5b727dc 100644 --- a/gallery/gallery.c +++ b/gallery/gallery.c @@ -1,10 +1,11 @@ #include #include +#include #include "html.h" -void resize(gchar *orig, gchar *thumb) +void resize(gchar *orig, gchar *thumb, gchar *size) { - gchar *argv[] = {"convert", "-resize", "200x200", orig, thumb, NULL}; + gchar *argv[] = {"convert", "-resize", size, orig, thumb, NULL}; /* god damn glib */ g_spawn_sync(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, NULL, NULL); @@ -12,18 +13,21 @@ void resize(gchar *orig, gchar *thumb) GList *gen_thumbs(GList *images) { - if (!g_file_test("thumbs", G_FILE_TEST_EXISTS)) - g_mkdir("thumbs", 0644); - if (!g_file_test("images", G_FILE_TEST_EXISTS)) - g_mkdir("images", 0644); + if (!g_file_test("large", G_FILE_TEST_EXISTS)) g_mkdir("large", 0775); + if (!g_file_test("small", G_FILE_TEST_EXISTS)) g_mkdir("small", 0775); + if (!g_file_test("thumb", G_FILE_TEST_EXISTS)) g_mkdir("thumb", 0775); for (GList *cur = images; cur; cur = cur->next) { gchar *name = cur->data; - gchar *thumb = g_strconcat("thumbs/", name, NULL); - gchar *image = g_strconcat("images/", name, NULL); - if (!g_file_test(thumb, G_FILE_TEST_EXISTS)) - resize(image, thumb); + gchar *large = g_build_filename("large", name, NULL); + gchar *small = g_build_filename("small", name, NULL); + gchar *thumb = g_build_filename("thumb", name, NULL); + if (!g_file_test(thumb, G_FILE_TEST_EXISTS)) { + resize(large, thumb, "200x200"); + resize(large, small, "800x800"); + } + g_free(large); + g_free(small); g_free(thumb); - g_free(image); } return images; } @@ -35,25 +39,29 @@ GList *read_dir(gchar *dirname) GList *images = NULL; while ((name = g_dir_read_name(dir))) images = g_list_prepend(images, g_strdup(name)); + images = g_list_sort(images, (GCompareFunc)g_strcmp0); return images; } int main() { - header(); - g_print("\n"); + ct_print_header("text/html", NULL); - const gchar *query_string = g_getenv("QUERY_STRING"); - if (query_string == NULL) + const gchar *path = ct_get_path_info(); + const gchar *query = ct_get_query_string(); + + GList *thumbs = gen_thumbs(read_dir("large")); + + if (!path || g_str_equal(path, "/")) frame_index(); - else if (g_str_equal(query_string, "noframe")) - frame_nav(TRUE, gen_thumbs(read_dir("images"))); - else if (g_str_equal(query_string, "nav")) - frame_nav(FALSE, gen_thumbs(read_dir("images"))); - else if (g_str_equal(query_string, "head")) + else if (g_str_equal(path, "/head")) frame_head(); - else if (g_str_equal(query_string, "content")) - frame_content(); - else - frame_index(); + else if (g_str_equal(path, "/nav")) + frame_nav(FALSE, thumbs); + else if (g_str_equal(path, "/noframe")) + frame_nav(TRUE, thumbs); + else if (g_str_equal(path, "/show_small")) + frame_show("small", "show_large", query); + else if (g_str_equal(path, "/show_large")) + frame_show("large", "show_small", query); } diff --git a/gallery/htacces b/gallery/htacces deleted file mode 100644 index dc182aa..0000000 --- a/gallery/htacces +++ /dev/null @@ -1,4 +0,0 @@ -Options +ExecCGI -AddHandler cgi-script .bin -RewriteEngine on -RewriteRule ^$ "index.bin" diff --git a/gallery/htaccess b/gallery/htaccess new file mode 100644 index 0000000..581db05 --- /dev/null +++ b/gallery/htaccess @@ -0,0 +1,4 @@ +Options +ExecCGI +AddHandler cgi-script .bin +RewriteEngine on +RewriteRule ^(?!thumb/|small/|large/|images/|mid/|index.bin).*$ "index.bin/$0" diff --git a/gallery/html.ct b/gallery/html.ct index e62621a..20bd065 100644 --- a/gallery/html.ct +++ b/gallery/html.ct @@ -1,18 +1,12 @@ <% #include %> - -<% void header() { %> -Content-Type: text/html; charset=UTF-8 -<% } %> - - <% void frame_index(){ %> - + - - + + @@ -31,7 +25,7 @@ Content-Type: text/html; charset=UTF-8
- No Frames + No Frames
@@ -78,16 +72,20 @@ Content-Type: text/html; charset=UTF-8 <% for (GList *cur = images; cur; cur = cur->next) { %> <% gchar *img = (gchar *)cur->data; %> <% } %> <% } %> - -<% void frame_content(){ %> - - +<% void frame_show(char *this, char *link, char *image){ %> + + + "> + "> + + + <% } %> diff --git a/gallery/html.h b/gallery/html.h index 2fd46e5..48f0d20 100644 --- a/gallery/html.h +++ b/gallery/html.h @@ -6,4 +6,4 @@ void frame_head(); void frame_nav(int square, GList *images); -void frame_content(); +void frame_show(); diff --git a/gallery/mkfile b/gallery/mkfile index b141b31..2a57660 100644 --- a/gallery/mkfile +++ b/gallery/mkfile @@ -1,8 +1,12 @@ -PROGS=gallery -PKGS=glib-2.0 -CLEAN=html.c +PROGS = gallery +PKGS = glib-2.0 +CLEAN = html.c +CPPFLAGS = -I.. +CFLAGS = --std=c99 -Wall -Wno-format -g -default:V: run -gallery: gallery.o html.o +default:V: gallery + QUERY_STRING=foo ./gallery + +gallery: gallery.o html.o ../lib.o <../mkcommon diff --git a/gallery/mkgallery b/gallery/mkgallery new file mode 100755 index 0000000..60b8c75 --- /dev/null +++ b/gallery/mkgallery @@ -0,0 +1,10 @@ +#!/bin/bash + +mkdir -p large small thumb +mv "$@" large + +chgrp apache small thumb +chmod 775 small thumb + +ln -s ~/git/ct/gallery/gallery index.bin +ln -s ~/git/ct/gallery/htaccess .htaccess