summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Ostler <scottbot9000@gmail.com>2010-07-02 11:33:14 -0400
committerScott Ostler <scottbot9000@gmail.com>2010-07-02 11:33:14 -0400
commit1fd0be696cf74dd73697d507a7bc7b7db18a1ffd (patch)
tree8177a88fcfc280bb115414f17c8bd0ec62d7dcde
parente591afe4d4453e10344068dd5becd5aa4ed052c4 (diff)
Add /nick/popular
-rw-r--r--src/site.clj39
-rw-r--r--template/fame_dump.st19
-rw-r--r--template/log_dump.st23
-rw-r--r--template/popular.st49
-rw-r--r--template/popular_dump.st15
-rw-r--r--template/profile_dump.st2
-rw-r--r--template/userlog.st2
7 files changed, 112 insertions, 37 deletions
diff --git a/src/site.clj b/src/site.clj
index 91f982e..94abd6c 100644
--- a/src/site.clj
+++ b/src/site.clj
@@ -62,7 +62,7 @@
;; 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)(\?|$)")
+(def pic-regex #"(?i)\.(jpg|jpeg|png|gif|bmp|svg)(\?|&|$)")
(defn is-image? [word]
(and (re-find url-regex word)
@@ -536,6 +536,42 @@ FROM users u
(.toString st))
(resp-error "NO_USER")))
+;; Who faved me
+
+(def popular-dumps-qry "
+select u.nick, u.avatar, r.key, m.message_id, m.content, m.created_on, count(*) as count,
+ array_agg(u2.nick) as user_nicks,
+ array_agg(u2.avatar) as user_avs
+from users u, messages m, rooms r, tags t, users u2
+where lower(u.nick) = lower(?)
+and u.user_id = m.user_id and m.message_id = t.message_id
+and m.room_id = r.room_id and m.is_image = true and r.admin_only = false
+and lower(t.tag) = 'favorite' and t.user_id != u.user_id
+and t.user_id = u2.user_id
+group by u.nick, u.avatar, r.key, m.message_id, m.content, m.created_on
+order by count desc limit 20 offset 0")
+
+(defn get-popular-dumps [nick]
+ (for [d (do-select [popular-dumps-qry nick])]
+ (assoc d
+ :favers (map (fn [n a] {:nick n :avatar a})
+ (.getArray (:user_nicks d))
+ (.getArray (:user_avs d)))
+ :user_nicks nil :user_avs nil)))
+
+(defn popular [session profile-nick]
+ (if-let [user-info (fetch-nick profile-nick)]
+ (let [st (fetch-template "popular" session)
+ profile-nick (:nick user-info)
+ raw-dumps (get-popular-dumps profile-nick)
+ dumps (map process-message-for-output raw-dumps)]
+ (println raw-dumps)
+ (.setAttribute st "nick" profile-nick)
+ (.setAttribute st "mini_profile" (build-mini-profile user-info))
+ (.setAttribute st "dumps" dumps)
+ (.toString st))
+ (resp-error "NO_USER")))
+
;; Directory
(def *per-directory-page* 25)
@@ -1149,6 +1185,7 @@ FROM users u
(GET "/:nick/tag/:tag/:offset" (tagged-dumps-by-nick session params (request-url request)))
(GET "/:nick/favorites" (favorites session params))
(GET "/:nick/favorites/:offset" (favorites session params))
+ (GET "/:nick/popular" (popular session (params :nick)))
(GET "/:nick/favs" (favorites session params))
(GET "/:nick/favs/:offset" (favorites session params))
(GET "/:nick/log" (user-log session (params :nick) "0"))
diff --git a/template/fame_dump.st b/template/fame_dump.st
index 05cc9fe..9403696 100644
--- a/template/fame_dump.st
+++ b/template/fame_dump.st
@@ -4,21 +4,10 @@ $else$
<div class="logged-dump dump $if(dump.favorited)$favorite$endif$" id="message-$dump.message_id$" nick="$dump.nick$">
$endif$
-$dump.created_on$ -- by <a href="/$dump.nick$"><b>$dump.nick$</b>
- <div id="logavatar">
-$if(dump.avatar)$
- <img height="50" width="50" src="$dump.avatar$" />
-$else$
- <img height="50" width="50" src="/static/noinfo.png">
-$endif$
- </div></a>&nbsp;&nbsp;&nbsp;<img height="16px" width="16px" src="http://dump.fm/static/img/thumbs/heartfaved.gif">$dump.count$
-<!--
-$if(dump.favorited)$
- <img src="/static/img/thumbs/heartfaved.gif" class="thumb favorite" onclick="Tag.favorite(this)">
-$else$
- <img src="/static/img/thumbs/heart.gif" class="thumb" onclick="Tag.favorite(this)">
-$endif$
--->
+
+$dump.created_on$ -- by <a href="/$dump.nick$"><b>$dump.nick$</b></a>
+<span>&nbsp;&nbsp;&nbsp;<img height="16px" width="16px" src="http://dump.fm/static/img/thumbs/heartfaved.gif">$dump.count$</span>
+
<div class="content">$dump.content$</div>
<hr />
$share_buttons()$
diff --git a/template/log_dump.st b/template/log_dump.st
index f594cea..17e6adc 100644
--- a/template/log_dump.st
+++ b/template/log_dump.st
@@ -4,22 +4,9 @@ $else$
<div class="logged-dump dump $if(dump.favorited)$favorite$endif$" id="message-$dump.message_id$" nick="$dump.nick$">
$endif$
-$dump.created_on$ -- by <a href="/$dump.nick$"><b>$dump.nick$</b>
- <div id="logavatar">
-$if(dump.avatar)$
- <img height="50" width="50" src="$dump.avatar$" />
-$else$
- <img height="50" width="50" src="/static/noinfo.png">
-$endif$
- </div></a>
-<!--
-$if(dump.favorited)$
- <img src="/static/img/thumbs/heartfaved.gif" class="thumb favorite" onclick="Tag.favorite(this)">
-$else$
- <img src="/static/img/thumbs/heart.gif" class="thumb" onclick="Tag.favorite(this)">
-$endif$
--->
- <div class="content">$dump.content$</div>
- <hr />
+
+$dump.created_on$ -- by <a href="/$dump.nick$"><b>$dump.nick$</b></a>
+<div class="content">$dump.content$</div>
+<hr />
$share_buttons()$
- </div>
+</div>
diff --git a/template/popular.st b/template/popular.st
new file mode 100644
index 0000000..21edcc1
--- /dev/null
+++ b/template/popular.st
@@ -0,0 +1,49 @@
+<html>
+ <head>
+ <title>$nick$'s dump.fm -- popular</title>
+ $head()$
+ <link rel="stylesheet" type="text/css" media="screen" href="/static/css/dump.css">
+
+ <script>
+ jQuery(document).ready(initLog);
+ </script>
+
+ </head>
+ <body>
+ $banner()$
+ <div id="dcontent">
+
+
+ <div id="messagePanep">
+ $mini_profile$
+ <div id="messageList">
+ $if(dumps)$ <span class="content">
+ $dumps:{ d | $popular_dump(dump=d)$ }$
+ </span>
+ $else$
+ no dumps
+ $endif$
+ </div>
+
+ <div id="msgInputDiv">
+ <div id="msginputrapper">
+ $if(prev)$
+ <a href="/$nick$/whofaved/$prev$"><input id="prevbutton" value="<- Prev"></a>
+ $else$
+ <input id="prevbutton">
+ $endif$
+
+ $if(next)$
+ <a href="/$nick$/whofaved/$next$"> <input id="nextbutton" value="Next ->"></a>
+ $else$
+ <input id="nextbutton" value="nomodumps">
+ $endif$
+ </div>
+ <div id="footerc">
+ $footer()$
+ </div>
+ </div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/template/popular_dump.st b/template/popular_dump.st
new file mode 100644
index 0000000..508bc4a
--- /dev/null
+++ b/template/popular_dump.st
@@ -0,0 +1,15 @@
+<div class="logged-dump dump $if(dump.favorited)$favorite$endif$" id="message-$dump.message_id$" nick="$dump.nick$">
+
+<div id="profiletxt">
+$dump.created_on$ -- in <b><a href="http://$dump.key$.dump.fm">$dump.key$</a></b>
+<span>&nbsp;&nbsp;&nbsp;<img height="16px" width="16px" src="http://dump.fm/static/img/thumbs/heartfaved.gif">$dump.count$</span>
+</div>
+
+
+<div class="content">$dump.content$</div>
+<hr/>
+<div class="faver-list">
+$dump.favers: { f | <img height="16px" width="16px" src="$f.avatar$"> <a href="http://dump.fm/$f.nick$">$f.nick$</a> &nbsp; }$
+</div>
+$share_buttons()$
+</div>
diff --git a/template/profile_dump.st b/template/profile_dump.st
index b101a08..2e9a259 100644
--- a/template/profile_dump.st
+++ b/template/profile_dump.st
@@ -2,7 +2,7 @@
<div id="profiletxt">
$dump.created_on$ -- in <b><a href="http://$dump.key$.dump.fm">$dump.key$</a></b>
</div>
- <a href="/u/$dump.nick$">
+ <a href="/$dump.nick$">
<div id="logavatar">
$if(dump.avatar)$
<img height="50" width="50" src="$dump.avatar$" />
diff --git a/template/userlog.st b/template/userlog.st
index ee01b09..5c925fd 100644
--- a/template/userlog.st
+++ b/template/userlog.st
@@ -2,8 +2,6 @@
<head>
<title>$nick$'s dump.fm</title>
$head()$
- <script src="/static/js/jquery.editinplace.1.0.1.packed.js" type="text/javascript"></script>
- <script src="/static/js/ajaxupload.js"></script>
<script>
jQuery(document).ready(initLog);