From afdc29ead65a6723a403374e7b90b1cf59d01d8e Mon Sep 17 00:00:00 2001 From: Scott Ostler Date: Wed, 23 Jun 2010 04:39:03 -0400 Subject: Finished profile images --- src/site.clj | 45 +++++++++++++++++++++++++++------------------ template/profile.st | 4 ++-- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/site.clj b/src/site.clj index 1878404..7577bd2 100644 --- a/src/site.clj +++ b/src/site.clj @@ -9,6 +9,7 @@ clojure.contrib.command-line clojure.contrib.duck-streams clojure.contrib.json.write + clojure.contrib.seq-utils clojure.contrib.sql clojure.contrib.str-utils clojure.contrib.def @@ -58,6 +59,21 @@ ;; Output +;; http://snippets.dzone.com/posts/show/6995 +(def url-regex #"(?i)^((http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$") +(def pic-regex #"(?i)\.(jpg|jpeg|png|gif|bmp|svg)(\?|$)") + +(defn is-image? [word] + (and (re-find url-regex word) + (re-find pic-regex word))) + +(defn classify-msg [msg] + (let [words (.split msg " ") + imgs (map is-image? words)] + (cond (every? boolean imgs) :image + (some boolean imgs) :mixed + :else :text))) + (defn strip-empty-vals [m] (into {} (filter (fn [[k v]] (non-empty-string? v)) m))) @@ -384,6 +400,11 @@ FROM users u ;; Profile +(defn take-random-image [content] + (rand-elt (filter is-image? (.split content " ")))) + +(defn msg-transformer [key f] + (fn [msg] (assoc msg key (f (msg key))))) (defn count-dumps-posted [nick] (:count @@ -423,9 +444,12 @@ FROM users u raw-dumps (logger tags/fetch-dumps-by-nick :nick profile-nick :amount 5) - dumps (map tags/add-favorited-flag (take 5 raw-dumps) (repeat session)) - dumps (map tags/remove-tags-for-output dumps) - dumps (logger doall (map process-message-for-output dumps))] + dumps (logger doall + (map (comp process-message-for-output + (msg-transformer :content take-random-image) + tags/remove-tags-for-output + tags/add-favorited-flag) + (take 5 raw-dumps) (repeat session)))] (do (.setAttribute st "is_home" is-home) (doseq [a [:nick :avatar :contact :bio]] @@ -625,21 +649,6 @@ FROM users u (refresh session params room) (resp-error "UNKNOWN_ROOM")))) -;; http://snippets.dzone.com/posts/show/6995 -(def url-regex #"(?i)^((http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$") -(def pic-regex #"(?i)\.(jpg|jpeg|png|gif|bmp|svg)(\?|$)") - -(defn is-url? [word] - (and (re-find url-regex word) - (re-find pic-regex word))) - -(defn classify-msg [msg] - (let [words (.split msg " ") - urls (map is-url? words)] - (cond (every? boolean urls) :image - (some boolean urls) :mixed - :else :text))) - ;; admins can post arbitrary html if wrapped in ;; this is temporary so that i can test generating html messages (defn validated-content [content session] diff --git a/template/profile.st b/template/profile.st index 8c9b8f1..c36a803 100644 --- a/template/profile.st +++ b/template/profile.st @@ -74,11 +74,11 @@

$if(score_ent)$ $score$ $else$ 0 $endif$ of $if(is_home)$ your $else$ $nick$'s$endif$ dumps Faved

-
$if(isadmin)$ +
$nick$'s most recent dumps
$dumps: { d | $dash_dump(dump=d)$ }$ -
$endif$ +
-- cgit v1.2.3-70-g09d2