From a70175759c5761f7aa4280280afa44fcb3f85c3b Mon Sep 17 00:00:00 2001 From: Scott Ostler Date: Mon, 23 Aug 2010 20:00:49 -0400 Subject: Use rooms/ subdirectory for templates; add per-room templates --- src/site.clj | 42 ++++--- src/utils.clj | 30 +++-- template/butt.st | 302 ----------------------------------------------- template/chat.st | 192 ------------------------------ template/goodies.st | 71 ----------- template/rooms/butt.st | 302 +++++++++++++++++++++++++++++++++++++++++++++++ template/rooms/chat.st | 192 ++++++++++++++++++++++++++++++ template/rooms/vortex.st | 291 +++++++++++++++++++++++++++++++++++++++++++++ template/vortex.st | 291 --------------------------------------------- template/webcam.st | 105 ---------------- 10 files changed, 828 insertions(+), 990 deletions(-) delete mode 100644 template/butt.st delete mode 100644 template/chat.st delete mode 100644 template/goodies.st create mode 100644 template/rooms/butt.st create mode 100644 template/rooms/chat.st create mode 100644 template/rooms/vortex.st delete mode 100644 template/vortex.st delete mode 100644 template/webcam.st diff --git a/src/site.clj b/src/site.clj index ab7a17f..67fab63 100644 --- a/src/site.clj +++ b/src/site.clj @@ -4,12 +4,13 @@ java.util.Date java.io.File javax.imageio.ImageIO - javax.servlet.http.Cookie) + javax.servlet.http.Cookie + org.antlr.stringtemplate.StringTemplateGroup) (:use clojure.xml clojure.contrib.command-line clojure.contrib.duck-streams clojure.contrib.json.write - clojure.contrib.seq-utils + clojure.contrib.seq-utils clojure.contrib.sql clojure.contrib.str-utils clojure.contrib.def @@ -18,7 +19,7 @@ admin compojure email - fame + fame utils cookie-login session-sweeper @@ -650,8 +651,14 @@ order by count desc limit ? offset ?") (or (not (room :admin_only)) (is-vip? session)))) +(def default-room-template "chat") + +(defn lookup-room-template [session room-key template] + (or (fetch-template (str "rooms/" (or template room-key)) session) + (fetch-template (str "rooms/" default-room-template) session))) + (defn chat [session room template] - (if-let [st (fetch-template template session)] + (if-let [st (lookup-room-template session (:key room) template)] (let [now (System/currentTimeMillis) nick (session :nick) limit (if (:admin_only room) *vip-dumps-per-page* *dumps-per-page*) @@ -677,11 +684,13 @@ order by count desc limit ? offset ?") (.toString st)) [404 "UNKNOWN PAGE"])) -(defn validated-chat [session room-key template] - (let [room-key (if (= (lower-case room-key) "www") *default-room* room-key)] - (if (validate-room-access room-key session) - (chat session (lookup-room room-key) template) - (resp-error "UNKNOWN_ROOM")))) +(defn validated-chat + ([session room-key] (validated-chat session room-key nil)) + ([session room-key template] + (let [room-key (if (= (lower-case room-key) "www") *default-room* room-key)] + (if (validate-room-access room-key session) + (chat session (lookup-room room-key) template) + (resp-error "UNKNOWN_ROOM"))))) (defn refresh [session params room] (dosync @@ -754,9 +763,9 @@ order by count desc limit ? offset ?") ;; TODO: make work for all rooms (defn browser [session] (let [room (lookup-room *default-room*) - now (System/currentTimeMillis) - nick (session :nick) - st (fetch-template "browser" session)] + now (System/currentTimeMillis) + nick (session :nick) + st (fetch-template "browser" session)] (if nick (dosync (login-user (user-struct-from-session session) room))) @@ -1129,10 +1138,11 @@ order by count desc limit ? offset ?") (GET "/avatars/*" (serve-static *avatar-directory* (params :*)))) (defroutes pichat - (GET "http://:sub.dump.fm/" (validated-chat session (params :sub) "chat")) - (GET "http://:sub.dump.fm/chat" (validated-chat session (params :sub) "chat")) - (GET "/:room/chat" (validated-chat session (params :room) "chat")) - (GET "/chat" (validated-chat session *default-room* "chat")) + (GET "http://:sub.dump.fm/" (validated-chat session (params :sub))) + (GET "http://:sub.dump.fm/chat" (validated-chat session (params :sub))) + (GET "http://:sub.dump.fm/chat" (validated-chat session (params :sub) (params :t))) + (GET "/:room/chat" (validated-chat session (params :room))) + (GET "/chat" (validated-chat session *default-room*)) (GET "/chat/:t" (validated-chat session *default-room* (params :t))) (GET "http://:sub.dump.fm/log" (validated-log session (params :sub) "0" params)) diff --git a/src/utils.clj b/src/utils.clj index 4a3343f..1dc4a2c 100755 --- a/src/utils.clj +++ b/src/utils.clj @@ -263,22 +263,26 @@ ;; Templates (def template-group (new StringTemplateGroup "dumpfm" "template")) -(.setRefreshInterval template-group 3) +(.setRefreshInterval template-group 10) + +(defn initialize-template [st session] + (if (session :nick) + (doto st + (.setAttribute "user_email" (session :email)) + (.setAttribute "user_nick" (session :nick)) + (.setAttribute "user_avatar" (if (non-empty-string? (session :avatar)) + (session :avatar) nil)) + (.setAttribute "isadmin" (session :is_admin)) + (.setAttribute "domain" config/*server-url*)) + (doto st + (.setAttribute "domain" config/*server-url*)))) (defn fetch-template [template session] (try (let [st (.getInstanceOf template-group template)] - (if (session :nick) - (doto st - (.setAttribute "user_email" (session :email)) - (.setAttribute "user_nick" (session :nick)) - (.setAttribute "user_avatar" (if (non-empty-string? (session :avatar)) - (session :avatar) nil)) - (.setAttribute "isadmin" (session :is_admin)) - (.setAttribute "domain" config/*server-url*)) - (doto st - (.setAttribute "domain" config/*server-url*)))) - (catch Exception e nil))) + (initialize-template st session)) + (catch Exception e + nil))) (defn fetch-template-fragment [template] (.getInstanceOf template-group template)) @@ -305,6 +309,6 @@ `(if (is-vip? ~'session) ~e (unknown-page))) (defmacro if-super-vip [e] - "Evaluates expr if user is vip otherwise returns 404. Can only be used + "Evaluates expr if user is super-vip otherwise returns 404. Can only be used where session is defined." `(if (is-super-vip? ~'session) ~e (unknown-page))) diff --git a/template/butt.st b/template/butt.st deleted file mode 100644 index e97390e..0000000 --- a/template/butt.st +++ /dev/null @@ -1,302 +0,0 @@ - - - -dump.fm image vortex - - - - - - -$if(!user_nick)$ - -$endif$ - -$if(isadmin)$ - - - - -$endif$ -$if(!user_avatar)$ - -$endif$ - - - - - -$if(user_nick)$ - -$endif$ - - - - - - - - -
-$messages: { m | -$m.nick$ - }$ - - -
- - -Loading... - - - - - diff --git a/template/chat.st b/template/chat.st deleted file mode 100644 index f4c4162..0000000 --- a/template/chat.st +++ /dev/null @@ -1,192 +0,0 @@ - - - - -$head()$ - $roomname$ dump.fm - - - - -$if(user_nick)$ - -$endif$ - - - - -$if(dis)$ - $banner_dis()$ -$else$ - $banner()$ - $if(!user_nick)$ - -
-

- If you already have an account, . If not, register now. -

-
-
- - -
dump.fm lets you talk with pictures! Paste an image url, upload, or snap a pic right from your webcam. Talk to friends, fav images, and keep track of the pix you love! -
-
-
- - - - -$endif$ -$endif$ - - -
- -
-
-
-
- -
- - -$if(user_nick)$ $endif$ -
-
-$messages: { m | -
- - $m.nick$ - $if(m.favorited)$ - - $else$ - - $endif$ - - $m.content$ -
-}$ -
-
- - $if(user_nick)$ -
-
- - - - - - -
-
-$else$ -
-
- - - - - - -
-
- $endif$ - $if(isadmin)$ - -$endif$ -
- - - -
-
- $footer()$ -
-$preload()$ - - diff --git a/template/goodies.st b/template/goodies.st deleted file mode 100644 index 4289c11..0000000 --- a/template/goodies.st +++ /dev/null @@ -1,71 +0,0 @@ - - - dump.fm | Image Search Beta - $head()$ - - - - - - - - - - - - - $banner()$ -
-
-
- -
-
-
- -
-
-
- -
- -
-
-
- - - - - -
-

- $footer()$

-

-

-
- - - diff --git a/template/rooms/butt.st b/template/rooms/butt.st new file mode 100644 index 0000000..e97390e --- /dev/null +++ b/template/rooms/butt.st @@ -0,0 +1,302 @@ + + + +dump.fm image vortex + + + + + + +$if(!user_nick)$ + +$endif$ + +$if(isadmin)$ + + + + +$endif$ +$if(!user_avatar)$ + +$endif$ + + + + + +$if(user_nick)$ + +$endif$ + + + + + + + + +
+$messages: { m | +$m.nick$ + }$ + + +
+ + +Loading... + + + + + diff --git a/template/rooms/chat.st b/template/rooms/chat.st new file mode 100644 index 0000000..f4c4162 --- /dev/null +++ b/template/rooms/chat.st @@ -0,0 +1,192 @@ + + + + +$head()$ + $roomname$ dump.fm + + + + +$if(user_nick)$ + +$endif$ + + + + +$if(dis)$ + $banner_dis()$ +$else$ + $banner()$ + $if(!user_nick)$ + +
+

+ If you already have an account, . If not, register now. +

+
+
+ + +
dump.fm lets you talk with pictures! Paste an image url, upload, or snap a pic right from your webcam. Talk to friends, fav images, and keep track of the pix you love! +
+
+
+ + + + +$endif$ +$endif$ + + +
+ +
+
+
+
+ +
+ + +$if(user_nick)$ $endif$ +
+
+$messages: { m | +
+ + $m.nick$ + $if(m.favorited)$ + + $else$ + + $endif$ + + $m.content$ +
+}$ +
+
+ + $if(user_nick)$ +
+
+ + + + + + +
+
+$else$ +
+
+ + + + + + +
+
+ $endif$ + $if(isadmin)$ + +$endif$ +
+ + + +
+
+ $footer()$ +
+$preload()$ + + diff --git a/template/rooms/vortex.st b/template/rooms/vortex.st new file mode 100644 index 0000000..c15c890 --- /dev/null +++ b/template/rooms/vortex.st @@ -0,0 +1,291 @@ + + + +dump.fm image vortex + + + + + + + + + + + + +
+$messages: { m | +$m.nick$ + }$ + +
dump.fm image vortex

Real-Time Visualization of whats being dumped now.

Return Home

+
+ +
+
+ + +
+ +Loading... + + + + + diff --git a/template/vortex.st b/template/vortex.st deleted file mode 100644 index c15c890..0000000 --- a/template/vortex.st +++ /dev/null @@ -1,291 +0,0 @@ - - - -dump.fm image vortex - - - - - - - - - - - - -
-$messages: { m | -$m.nick$ - }$ - -
dump.fm image vortex

Real-Time Visualization of whats being dumped now.

Return Home

-
- -
-
- - -
- -Loading... - - - - - diff --git a/template/webcam.st b/template/webcam.st deleted file mode 100644 index e3e653d..0000000 --- a/template/webcam.st +++ /dev/null @@ -1,105 +0,0 @@ - - - - -$head()$ - $roomname$ dump.fm -$if(isadmin)$ - - -$endif$ - - - -$if(user_nick)$ - -$endif$ - - - - - -
- -
-
-
-
- -
- -
- - -
- -
-
- - - - - - -
-
- -
-
- - -$preload()$ - - -- cgit v1.2.3-70-g09d2