diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2009-02-23 14:45:50 +0100 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2009-02-23 14:45:50 +0100 |
commit | 7c791f06ff0887c57f68dea9351b8f22142ae0ad (patch) | |
tree | 3a7a8c46c5048a3dfb7252df8da4a7cd62420c8c /cljssss-g.clj | |
parent | 1d7292fda2170d3c8ab5c56d1c266a5856a14012 (diff) | |
parent | 64b7320d281382f325aa5e8b7df64564771c18ba (diff) |
Merge branch 'master' of ssh://matthias@uxul.org:63332/home/matthias/public_html/cljssss-g
Conflicts:
cljssss-g.clj
Diffstat (limited to 'cljssss-g.clj')
-rw-r--r-- | cljssss-g.clj | 108 |
1 files changed, 92 insertions, 16 deletions
diff --git a/cljssss-g.clj b/cljssss-g.clj index a9e8ffe..315cbc4 100644 --- a/cljssss-g.clj +++ b/cljssss-g.clj @@ -17,6 +17,9 @@ :subname "cljssss-g.sqlite3" :create true}) +;; FIXME: WAAAAAAAAAH! +(def session {:id false}) + (defmacro with-db [& body] `(sql/with-connection db-connection-data ~@body)) @@ -26,6 +29,73 @@ (sql/transaction ~@body))) +;;; FIXME: clojure has no way of creating interfaces on-the-fly. So I +;;; cannot use stringtemplate here. +(defn opml-string [id] + (with-dbt + (sql/with-query-results + results + ["SELECT feed.uri, feed.link, user_feed_link.title FROM feed, user_feed_link WHERE user_feed_link.feed=feed.id AND user_feed_link.user=?" id] + (str "<?xml version=\"1.0\" encoding=\"utf-8\"?><opml version=\"1.0\"><head>" + "<dateCreated>blah</dateCreated>" + "<title>Gödel-Gentzen Clojure Syndication Services Super System Feed Export</title></head><body>" + (loop [clstr "" r results] + (if (first r) + (recur + (str clstr + "<outline text=\"" + (:title (first r)) + "\" xmlUrl=\"" + (:uri (first r)) + "\" htmlUrl=\"" + (:link (first r)) + "\" />") + (rest r)) + clstr)) + "</body></opml>")))) + +(defn lynxy-feedlist [id] + (with-dbt + (sql/with-query-results + results + ["SELECT feed.id, feed.uri, feed.link, user_feed_link.title FROM feed, user_feed_link WHERE user_feed_link.feed=feed.id AND user_feed_link.user=?" id] + (html `[html [head [title "Gödel-Gentzen Clojure Syndication Services Super System"]] + [body [ul + ~@(loop [back '[] r results] + (if (first r) + (recur (concat back `[[li + [a {:href ~(str "lynxy-showfeed?feed=" (:id (first r)))} + ~(:title (first r)) " - " + ~(:link (first r)) + ]]]) + (rest r)) + back))]]])))) + +(defn lynxy-showfeed [id feednum] + (with-dbt + (sql/with-query-results + results + ["SELECT entry.link, entry.title FROM entry, feed_entry_link, user_feed_link WHERE entry.id = feed_entry_link.entry AND feed_entry_link.feed = user_feed_link.feed AND user_feed_link.user = ? AND user_feed_link.feed = ?" id feednum] + (html `[html [head [title "Gödel-Gentzen Clojure Syndication Services Super System"]] + [body [ul + ~@(loop [back '[] r results] + (if (first r) + (recur (concat back `[[li + [a {:href ~(:link (first r))} + ~(:title (first r)) " - " + ~(:link (first r)) + ]]]) + (rest r)) + back))] + [a {:href "lynxy-feedlist.html"} "« To Feedlist"] + ]])))) + +(defmacro with-session [& body] + `(if (not (session :id)) + (redirect-to "/login") + (do ~@body))) + + (defservlet cljssss-g (GET "/login" (if (= (params :valuesofbetawillgiverisetodom) "true") @@ -36,23 +106,29 @@ (.getInstanceOf templates "login") (.setAttributes {"logintext" "Login"}))))) (POST "/login" - (dosync - (with-db - (sql/with-query-results [{id :id password :password}] - ["SELECT id, password FROM user WHERE name = ?" - (@params :name)] - (if (= password (@params :password)) - (do - (alter session assoc :id id) - (redirect-to "/")) - (redirect-to "/login?valuesofbetawillgiverisetodom=true")))))) + (dosync + (with-db + (sql/with-query-results [{id :id password :password}] + ["SELECT id, password FROM user WHERE name = ?" + (params :name)] + (if (= password (params :password)) + (do + (alter session assoc :id id) + (redirect-to "/")) + (redirect-to "/login?valuesofbetawillgiverisetodom=true")))))) + (GET "/feedlist.opml" + (with-session (opml-string (session :id)))) + (GET "/lynxy-feedlist.html" + (with-session (lynxy-feedlist (session :id)))) + (GET "/lynxy-showfeed" + (with-session + (lynxy-showfeed (session :id) (. Integer parseInt (params :feed))))) (GET "/" - (if (@session :id) - (.toString - (doto (.getInstanceOf templates "index") - (.setAttributes {"title" "Subscriptions", - "mainParagraph" "Hi there!"}))) - (redirect-to "/login"))) + (with-session + (.toString + (doto (.getInstanceOf templates "index") + (.setAttributes {"title" "Subscriptions", + "mainParagraph" "Hi there!"}))))) (ANY "*" (page-not-found))) |