diff options
Diffstat (limited to 'cljssss-g.clj')
-rw-r--r-- | cljssss-g.clj | 121 |
1 files changed, 65 insertions, 56 deletions
diff --git a/cljssss-g.clj b/cljssss-g.clj index 03856e1..6dcefd7 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,24 +29,6 @@ (sql/transaction ~@body))) -(defn opml-init [text xmlurl htmlurl] - (ref {:text text :xmlurl xmlurl :htmlurl htmlurl})) - -(defn opml-getText [this] - (this :text)) -(defn opml-getXmlurl [this] - (this :xmlurl)) -(defn opml-getHtmlurl [this] - (this :htmlurl)) - -;(gen-interface -; :name opmliface -; :prefix "opml-" -; :init init -; :methods [[getXmlurl [] String] -; [getHtmlurl [] String] -; [getText [] String]]) - ;;; FIXME: clojure has no way of creating interfaces on-the-fly. So I ;;; cannot use stringtemplate here. (defn opml-string [id] @@ -68,26 +53,48 @@ (rest r)) clstr)) "</body></opml>")))) -; (let [template-object (.getInstanceOf templates "opml"), -; feeds -; (to-array -; (loop [clst '() r results] -; (if (first r) -; (recur -; (concat -; clst -; (list (proxy [Object] [] -; (getText [] -; ((first r) :title)) -; (getXmlurl [] -; ((first r) :uri)) -; (getHtmlurl [] -; ((first r) :link))))) -; (rest r)) - clst)))] -; (. template-object setAttribute "date" "heute") -; (. template-object setAttribute "feeds" feeds) -; (.toString template-object))))) + +(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" @@ -100,26 +107,28 @@ (.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")))))) + (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" - (if (not (session :id)) - (redirect-to "/login") - (opml-string (session :id)))) + (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))) |