summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/site.clj29
-rwxr-xr-xsrc/utils.clj24
-rwxr-xr-xstatic/js/pichat.js51
-rw-r--r--template/about_us.st7
-rw-r--r--template/goodies.st8
-rwxr-xr-xtemplate/head.st4
-rw-r--r--template/help.st7
-rw-r--r--template/privacy.st7
-rwxr-xr-xtemplate/profile.st167
-rw-r--r--template/terms.st7
10 files changed, 185 insertions, 126 deletions
diff --git a/src/site.clj b/src/site.clj
index 167f4d5..60f07d7 100755
--- a/src/site.clj
+++ b/src/site.clj
@@ -155,12 +155,6 @@
(def *dumps-per-page* 20)
-(defn maybe-parse-int [s f]
- (if s (Integer/parseInt s) f))
-
-(defn maybe-parse-long [s f]
- (if s (Long/parseLong s) f))
-
(defn count-messages-by-room [room-id image-only]
(let [query (str "SELECT COUNT(*) "
"FROM messages m, users u "
@@ -210,13 +204,17 @@
;; Templates
-(defn fetch-template [template-name session]
- (let [st (.getInstanceOf template-group template-name)]
- (if (and st (session :nick))
+;; TODO: avoid exception
+(defn fetch-template [template session]
+ (let [st (.getInstanceOf template-group template)]
+ (if (session :nick)
(do (.setAttribute st "user_nick" (session :nick))
(.setAttribute st "isadmin" (session :is_admin))))
st))
+(defn serve-template [template session]
+ (.toString (fetch-template template session)))
+
;; Login code
(defn session-map-from-db
@@ -301,7 +299,7 @@
invalid-nick-reason (is-invalid-nick? nick)]
(cond invalid-nick-reason (resp-error invalid-nick-reason)
(fetch-nick nick) (resp-error "NICK_TAKEN")
- :else (with-connection db
+ :else (with-connection *db*
(insert-values :users
[:nick :hash :email]
[nick hash email])
@@ -338,7 +336,7 @@
(defn update-user-db [user-id attr val]
- (with-connection db
+ (with-connection *db*
(update-values "users" ["user_id = ?" user-id] {attr val})))
(defn download-avatar [session url]
@@ -430,7 +428,7 @@
(let [is-image (is-image? content)
qry (str "INSERT INTO messages (user_id, room_id, content, is_image) "
"VALUES (?, ?, ?, ?) RETURNING message_id")]
- (with-connection db
+ (with-connection *db*
((first (do-select [qry user-id room-id content is-image]))
:message_id))))
@@ -596,7 +594,7 @@
(defroutes pichat
(GET "/" (no-cache (landing session)))
(GET "/favicon.ico" (serve-static "static" "favicon.ico"))
- (GET "/u/:nick" (profile session (params :nick) "0"))
+ (GET "/u/:nick" (profile session (params :nick) "0"))
(GET "/u/:nick/" (profile session (params :nick) "0"))
(GET "/u/:nick/:offset" (profile session
(params :nick)
@@ -621,6 +619,11 @@
(POST "/msg" (validated-msg session params))
(POST "/submit-registration" (register session params))
(POST "/update-profile" (update-profile session params))
+ (GET "/about_us" (serve-template "about_us" session))
+ (GET "/goodies" (serve-template "goodies" session))
+ (GET "/help" (serve-template "help" session))
+ (GET "/privacy" (serve-template "privacy" session))
+ (GET "/terms" (serve-template "terms" session))
(ANY "*" (unknown-page params)))
(defroutes multipart
diff --git a/src/utils.clj b/src/utils.clj
index 3ffd54b..33a247f 100755
--- a/src/utils.clj
+++ b/src/utils.clj
@@ -7,11 +7,11 @@
(let [db-host "localhost"
db-port 5432
db-name "dumpfm"]
- (def db {:classname "org.postgresql.Driver"
- :subprotocol "postgresql"
- :subname (str "//" db-host ":" db-port "/" db-name)
- :user "postgres"
- :password "root"}))
+ (def *db* {:classname "org.postgresql.Driver"
+ :subprotocol "postgresql"
+ :subname (str "//" db-host ":" db-port "/" db-name)
+ :user "postgres"
+ :password "root"}))
;; JSON responses
@@ -30,12 +30,12 @@
;; Database
(defn do-select [query]
- (with-connection db
+ (with-connection *db*
(with-query-results rs query
(doall rs))))
(defn do-count [query]
- ((first (with-connection db
+ ((first (with-connection *db*
(with-query-results rs query
(doall rs))))
:count))
@@ -72,4 +72,12 @@
(defn validated-stats [session params]
(if (session :is_admin)
(stats session params)
- (resp-error "BAD_REQUEST"))) \ No newline at end of file
+ (resp-error "BAD_REQUEST")))
+
+;; Parsing
+
+(defn maybe-parse-int [s f]
+ (if s (Integer/parseInt s) f))
+
+(defn maybe-parse-long [s f]
+ (if s (Long/parseLong s) f)) \ No newline at end of file
diff --git a/static/js/pichat.js b/static/js/pichat.js
index 071e8e6..d348d93 100755
--- a/static/js/pichat.js
+++ b/static/js/pichat.js
@@ -240,18 +240,12 @@ function initChat() {
setTimeout(refresh, 1000);
}
-function initProfile() {
- jQuery(".linkify").each(function() {
- var text = jQuery(this).text();
- jQuery(this).html(linkify(text));
- });
-
-
- $('.logged-dump .content').each(function() {
- var t = $(this);
- t.html(buildMsgContent(t.text()));
- });
+function makePlainText() {
+ var j = $(this);
+ j.text(j.text());
+}
+function enableProfileEdit() {
var onSubmit = function(attr, newVal, oldVal) {
newVal = $.trim(newVal);
if (newVal == oldVal) { return oldVal };
@@ -273,22 +267,43 @@ function initProfile() {
return escapeHtml(newVal);
};
+ $('#avatar-editing').show();
+
var avatarOpts = { 'default_text': 'Enter here!',
'callback': onSubmit,
'field_type': 'text',
'callbackShowErrors': false };
$('#avatar.editable').editInPlace(avatarOpts);
+ if ($('#upload').length > 0) {
+ setupUploadAvatar('upload');
+ }
+
var textareaOpts = { 'default_text': 'Enter here!',
'callback': onSubmit,
'field_type': 'textarea',
- 'callbackShowErrors': false };
- $('#contact.editable, #bio.editable').editInPlace(textareaOpts);
+ 'callbackShowErrors': false };
+ $('#contact, #bio')
+ .addClass('editable')
+ .editInPlace(textareaOpts)
+ .each(makePlainText);
- if ($('#upload').length > 0) {
- setupUploadAvatar('upload');
- }
+ var resetPage = function() { location.reload() };
+ $('#edit-toggle a').text('--> Done editing <--').click(resetPage);
+}
+function initProfile() {
+ $(".linkify").each(function() {
+ var text = jQuery(this).text();
+ jQuery(this).html(linkify(text));
+ });
+
+ $('#edit-toggle').click(enableProfileEdit);
+
+ $('.logged-dump .content').each(function() {
+ var t = $(this);
+ t.html(buildMsgContent(t.text()));
+ });
};
function initLog() {
@@ -331,9 +346,9 @@ function setupUploadAvatar(elementId) {
var onComplete = function(file, resp) {
$('#spinner').hide();
if (resp == 'INVALID_REQUEST') {
- location.href = location.href;
+ location.reload();
} else if (resp == 'NOT_LOGGED_IN') {
- location.href = location.href;
+ location.reload();
} else if (resp == 'INVALID_IMAGE') {
alert("Sorry, dump.fm can't deal with your image. Pick another :(");
return;
diff --git a/template/about_us.st b/template/about_us.st
new file mode 100644
index 0000000..b8ee9f9
--- /dev/null
+++ b/template/about_us.st
@@ -0,0 +1,7 @@
+<html>
+ <head>
+ <title>About Us</title>
+ $head()$
+ </head>
+ <body></body>
+</html>
diff --git a/template/goodies.st b/template/goodies.st
new file mode 100644
index 0000000..a7c0824
--- /dev/null
+++ b/template/goodies.st
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <title>Goodies</title>
+ $head()$
+ </head>
+ <body></body>
+</html>
+ \ No newline at end of file
diff --git a/template/head.st b/template/head.st
index 46ce6a5..e83e687 100755
--- a/template/head.st
+++ b/template/head.st
@@ -1,7 +1,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
-<!-- <script type="text/javascript" src="/static/jquery-1.3.2.min.js"></script> -->
+<script type="text/javascript" src="/static/jquery-1.3.2.min.js"></script>
+<!-- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> -->
<!--<script type="text/javascript" src="/static/js/underscore-min.js"></script> -->
<script type="text/javascript" src="/static/js/sha1.js"></script>
<script type="text/javascript" src="/static/js/pichat.js"></script>
diff --git a/template/help.st b/template/help.st
new file mode 100644
index 0000000..0d41e21
--- /dev/null
+++ b/template/help.st
@@ -0,0 +1,7 @@
+<html>
+ <head>
+ <title>Help</title>
+ $head()$
+ </head>
+ <body></body>
+</html>
diff --git a/template/privacy.st b/template/privacy.st
new file mode 100644
index 0000000..513eca3
--- /dev/null
+++ b/template/privacy.st
@@ -0,0 +1,7 @@
+<html>
+ <head>
+ <title>Privacy</title>
+ $head()$
+ </head>
+ <body></body>
+</html> \ No newline at end of file
diff --git a/template/profile.st b/template/profile.st
index 9f085c6..e3f59ae 100755
--- a/template/profile.st
+++ b/template/profile.st
@@ -32,111 +32,108 @@
$if(dumps)$
$dumps:{ d | $logged_dump(dump=d)$ }$
- <div id="lolbanner">
- <img src="/static/welcomebanner.gif">
- </div>
- <div id="profile">
-
- <h2>$nick$</h2>
-
- $if(avatar)$
- <img id="avatarPic" src="$avatar$" width="150px"/>
- $else$
- <b id="avatarPic"><img src="/static/noinfo.png"></b>
- $endif$
-
- $if(is_home)$
- <input id="upload" value="Upload Icon" type="submit">
-
- <img id="spinner" src="/static/spinner.gif" style="display: none" />
- $endif$
+ <div id="profile">
+ <h2>$nick$</h2>
+ $if(avatar)$
+ <img id="avatarPic" src="$avatar$" width="150px"/>
+ $else$
+ <b id="avatarPic"><img src="/static/noinfo.png"></b>
+ $endif$
+
+ $if(is_home)$
+ <div id="avatar-editing" style="display: none">
+ <div id="avatar" class="editable">$avatar$</div>
+ <input id="upload" value="Upload" type="submit">
+ <img id="spinner" src="/static/spinner.gif" style="display: none" />
+ </div>
+ $endif$
- $if(is_home)$
- <h3>contact info</h3>
- <div id="contact" class="editable">$contact$</div>
- $elseif(contact)$
- <h3>contact info</h3>
- <div id="contact" class="linkify">$contact$</div>
- $else$
- <br><br>
- <div><img src="/static/noinfo.png"></div>
- $endif$
-
+ $endif$
+
+ <h3>contact info</h3>
+ $if(contact)$
+ <div id="contact" class="linkify">$contact$</div>
+ $else$
+ <br><br>
+ <div><img src="/static/noinfo.png"></div>
+ $endif$
+ <br>
+
+ <h3>bio</h3>
+ $if(bio)$
+ <div id="bio" class="linkify">$bio$</div>
+ $else$
+ <div><img src="/static/noinfo.png"></div>
+ $endif$
- <br>
+ $if(is_home)$
+ <br>
+ <div id="edit-toggle"><a href="#">--> Edit your information <--</a></div>
+ $endif$
- $if(is_home)$
- <h3>bio</h3>
- <div id="bio" class="editable">$bio$</div>
- $elseif(bio)$
- <h3>bio</h3>
- <div id="bio" class="linkify">$bio$</div>
- $else$
- <div><img src="/static/noinfo.png"></div>
- $endif$
+ <br>
+ <div id="date">
+ <div type="text" id="datepicker"></div></div>
+ </div>
- <br>
- <div id="date">
- <div type="text" id="datepicker"></div></div>
- </div>
$else$
<h3>&nbsp;</h3>
<h3>&nbsp;</h3>
- <h3>&nbsp;</h3> <h3>&nbsp;</h3>
<h3>&nbsp;</h3>
- <h3>&nbsp;</h3><div id="newuser">
-<h2>&#x263A;&#x270C; Welcome to dump.fm &#x270C;&#x263A;</h2>
-
-<br><br>
-
-<h1>Step &#x2776;</h1>
-<h3>&#x261F; Find a sweet image for your avatar, paste the URL below &#x261F;</h3>
- $if(avatar)$
- <img id="avatarPic" src="$avatar$" width="150px"/>
- $else$
- <b id="avatarPic"></b>
- $endif$
-
- $if(is_home)$
- <div id="avatar" class="editable">$avatar$</div>
- $endif$
-
-<h1>Step &#x2777;</h1>
-<h3>&#x261F; Enter some contact info below &#x261F;</h3>
- <div id="contact" class="$if(is_home)$editable$else$linkify$endif$">$contact$</div>
- <br>
-
-<h1>Step &#x2778;</h1>
-<h3>&#x261F; Enter some personal info below &#x261F;</h3>
- <div id="bio" class="$if(is_home)$editable$else$linkify$endif$">$bio$</div>
- <br>
- <h1>Step &#x2779;</h1>
-
- <h3> <a href="/chat">Join the &#x2663; and start posting pictures!</a></h3>
- <h3>&nbsp;</h3></div>
+ <h3>&nbsp;</h3>
+ <h3>&nbsp;</h3>
+ <h3>&nbsp;</h3>
+ <div id="newuser">
+ <h2>&#x263A;&#x270C; Welcome to dump.fm &#x270C;&#x263A;</h2>
+ <br><br>
+
+ <h1>Step &#x2776;</h1>
+ <h3>&#x261F; Find a sweet image for your avatar, paste the URL below &#x261F;</h3>
+ $if(avatar)$
+ <img id="avatarPic" src="$avatar$" width="150px"/>
+ $else$
+ <b id="avatarPic"></b>
+ $endif$
+
+ $if(is_home)$
+ <div id="avatar" class="editable">$avatar$</div>
+ $endif$
+
+ <h1>Step &#x2777;</h1>
+ <h3>&#x261F; Enter some contact info below &#x261F;</h3>
+ <div id="contact" class="$if(is_home)$editable$else$linkify$endif$">$contact$</div>
+ <br>
+
+ <h1>Step &#x2778;</h1>
+ <h3>&#x261F; Enter some personal info below &#x261F;</h3>
+ <div id="bio" class="$if(is_home)$editable$else$linkify$endif$">$bio$</div>
+ <br>
+ <h1>Step &#x2779;</h1>
+
+ <h3> <a href="/chat">Join the &#x2663; and start posting pictures!</a></h3>
+ <h3>&nbsp;</h3></div>
<h3>&nbsp;</h3>
<h3>&nbsp;</h3>
<h3>&nbsp;</h3>
<h3>&nbsp;</h3>
<h3>&nbsp;</h3>
$endif$
-
+
<p>&nbsp;</p>
<div id="pnav">
- $if(next)$
- <div id="pnavn"><a href="/u/$nick$/$next$">next &#9758;</a></div>
- $endif$
-
- &nbsp;
- $if(prev)$
- <div id="pnavo"> <a href="/u/$nick$/$prev$">&#9756; prev</a> </div>
- $endif$
-
+ $if(next)$
+ <div id="pnavn"><a href="/u/$nick$/$next$">next &#9758;</a></div>
+ $endif$
- <br><br>
+ &nbsp;
+ $if(prev)$
+ <div id="pnavo"> <a href="/u/$nick$/$prev$">&#9756; prev</a></div>
+ $endif$
+
+ <br><br>
</div>
<div id="footer">
diff --git a/template/terms.st b/template/terms.st
new file mode 100644
index 0000000..29a41cc
--- /dev/null
+++ b/template/terms.st
@@ -0,0 +1,7 @@
+<html>
+ <head>
+ <title>Terms and Conditions</title>
+ $head()$
+ </head>
+ <body></body>
+</html>