]> Pileus Git - ~andy/ct/commitdiff
Update gallery
authorAndy Spencer <andy753421@gmail.com>
Mon, 24 Dec 2012 03:41:56 +0000 (03:41 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 24 Dec 2012 03:41:56 +0000 (03:41 +0000)
gallery/gallery.c
gallery/htacces [deleted file]
gallery/htaccess [new file with mode: 0644]
gallery/html.ct
gallery/html.h
gallery/mkfile
gallery/mkgallery [new file with mode: 0755]

index 08590cc0fd067dddc8d13bf6c67696fc0e5dc4ee..5b727dc1f3f5a4030f08a0737f6571f0a2a2e0f8 100644 (file)
@@ -1,10 +1,11 @@
 #include <glib.h>
 #include <glib/gstdio.h>
 #include <glib.h>
 #include <glib/gstdio.h>
+#include <ct.h>
 #include "html.h"
 
 #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);
        /* 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)
 {
 
 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;
        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(thumb);
-               g_free(image);
        }
        return images;
 }
        }
        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));
        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()
 {
        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();
                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();
                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 (file)
index dc182aa..0000000
+++ /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 (file)
index 0000000..581db05
--- /dev/null
@@ -0,0 +1,4 @@
+Options +ExecCGI
+AddHandler cgi-script .bin
+RewriteEngine on
+RewriteRule ^(?!thumb/|small/|large/|images/|mid/|index.bin).*$ "index.bin/$0"
index e62621aa1920d97f3f84e3d08de1a850a34babe6..20bd065c145d98611177116c5b6aee3c231823f1 100644 (file)
@@ -1,18 +1,12 @@
 <% #include <glib.h> %>
 
 <% #include <glib.h> %>
 
-
-<% void header() { %>
-Content-Type: text/html; charset=UTF-8
-<% } %>
-
-
 <% void frame_index(){ %>
 <html>
        <frameset rows="20, *">
 <% void frame_index(){ %>
 <html>
        <frameset rows="20, *">
-               <frame name="head" src="?head">
+               <frame name="head" src="head">
                <frameset cols="248,*">
                <frameset cols="248,*">
-                       <frame name="nav" src="?nav">
-                       <frame name="content" src="?content">
+                       <frame name="nav" src="nav">
+                       <frame name="content" src="content">
                </frameset>
        </frameset>
 </html>
                </frameset>
        </frameset>
 </html>
@@ -31,7 +25,7 @@ Content-Type: text/html; charset=UTF-8
        </head>
        <body>
                <center>
        </head>
        <body>
                <center>
-                       <a href="?noframe" target="parent">No Frames</a>
+                       <a href="noframe" target="parent">No Frames</a>
                </center>
        </body>
 </html>
                </center>
        </body>
 </html>
@@ -78,16 +72,20 @@ Content-Type: text/html; charset=UTF-8
                <% for (GList *cur = images; cur; cur = cur->next) { %>
                        <% gchar *img = (gchar *)cur->data; %>
                        <div class="align">
                <% for (GList *cur = images; cur; cur = cur->next) { %>
                        <% gchar *img = (gchar *)cur->data; %>
                        <div class="align">
-                               <a class="box" target="content" href="images/<%= "%s", img %>">
-                               <img src="thumbs/<%= "%s", img %>"></a>
+                               <a class="box" target="content" href="show_small?<%= "%s", img %>">
+                               <img src="thumb/<%= "%s", img %>"></a>
                        </div>
                <% } %>
        </body>
 </html>
 <% } %>
 
                        </div>
                <% } %>
        </body>
 </html>
 <% } %>
 
-
-<% void frame_content(){ %>
-<html>
-</html>
+<% void frame_show(char *this, char *link, char *image){ %>
+<html> 
+       <body style="text-align:center;"> 
+               <a href="<%= "%s?%s", link, image %>">
+                       <img src="<%= "%s/%s", this, image %>">
+               </a> 
+       </body> 
+</html> 
 <% } %>
 <% } %>
index 2fd46e5ef0f8b024525994b28257c489880ecd80..48f0d20d7009f817ea266150db1e8638c7a98c14 100644 (file)
@@ -6,4 +6,4 @@ void frame_head();
 
 void frame_nav(int square, GList *images);
 
 
 void frame_nav(int square, GList *images);
 
-void frame_content();
+void frame_show();
index b141b312ce71efea3652ca8c49871d7d33460fc5..2a57660896aabbc2d4b2d909a8e99ce7e9b2eabd 100644 (file)
@@ -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
 
 <../mkcommon
diff --git a/gallery/mkgallery b/gallery/mkgallery
new file mode 100755 (executable)
index 0000000..60b8c75
--- /dev/null
@@ -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