shithub: werc

Download patch

ref: 2c8139eb9e6efd5712116299ad0f5ccd0bb4b153
parent: ab0ce13ca975cc147dec86c0f3e89f7fd09329a7
author: uriel <uriel@engel.se.cat-v.org>
date: Thu Feb 26 06:42:20 EST 2009

Make bridge app more correct: only activated when GET-ing pages which can have comments and don't get confused by other apps POSTs. Simplify code along the way.

--- a/apps/bridge/app.rc
+++ b/apps/bridge/app.rc
@@ -11,23 +11,27 @@
 }
 
 fn bridge_init {
-    if(~ $#enable_comments 1) {
-    
+    if(~ $#enable_comments 1 && ! ~ `{ls $local_path.$comment_file_types >[2]/dev/null|wc -l} 0) {
+
         comments_dir=$sitedir$req_path'_werc/comments'
-        if(test -d $comments_dir)
+        if(~ $REQUEST_METHOD GET && test -d $comments_dir)
             ll_add handlers_body_foot template apps/bridge/comments_list.tpl
 
-        if({ check_user $groups_allowed_comments || {~ $#logged_user 0 && ! ~ $#allow_new_user_comments 0} } && ! ~ `{ls $local_path.$comment_file_types >[2]/dev/null|wc -l} 0) {
-            ll_add handlers_body_foot template apps/bridge/foot.tpl
+        if(check_user $groups_allowed_comments || {~ $#logged_user 0 && ! ~ $#allow_new_user_comments 0}) {
 
-            if(~ $REQUEST_METHOD POST && mk_new_comment $comments_dir)
-                post_redirect $base_url^$post_arg_document_uri
-            if not
-                saved_comment_text=$post_arg_comment_text
+            if(~ $#post_arg_bridge_post 1) {
+                ll_add handlers_body_foot template apps/bridge/foot.tpl
+
+                if(mk_new_comment $comments_dir)
+                    post_redirect $base_url^$req_path
+                if not
+                    saved_comment_text=$post_arg_comment_text
+            }
+            if not if(~ $REQUEST_METHOD GET)
+                ll_add handlers_body_foot template apps/bridge/foot.tpl
         }
-        if not
+        if not if(~ $REQUEST_METHOD GET)
             ll_add handlers_body_foot echo '<hr /><p>To post a comment you need to <a href="/_users/login">login</a> first.'
-        
     }
 }
 
--- a/apps/bridge/foot.tpl
+++ b/apps/bridge/foot.tpl
@@ -1,12 +1,10 @@
 <hr />
 
 % notices_handler
-% # XXX should post to bridge_post or similar
 <form action="" method="post">
     <textarea name="comment_text" id="comment_text" cols="80" rows="16">%($"saved_comment_text%)</textarea>
     <br />
-    <input type="hidden" name="document_uri" value="%($req_path%)" />
-    <input type="submit" name="post_comment" value="Post a comment" />
+    <input type="submit" name="bridge_post" value="Post a comment" />
 
 % if(~ $#logged_user 0 && ! ~ $#allow_new_user_comments 0) {
     <label>New user name: