1 # ===================================================================== 2 # cmtList: list comments belonging to a specified a TW page. 3 # 4 # Copyright (c) 2007,2008,2009,2010 Carlo Strozzi 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; version 2 dated June, 1991. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 # 19 # ===================================================================== 20 21 # ===================================================================== 22 # Local variables and functions 23 # ===================================================================== 24 25 cgi.group = () 26 cgi.group.literal = () 27 cgi.page = () 28 cgi.page.literal = () 29 cgi.paging = 0 # default is no paging. 30 cgi.author = () 31 32 captcha_code = () 33 34 # ===================================================================== 35 # Main program 36 # ===================================================================== 37 38 # Load call arguments. 39 csaGetArgs GET 40 41 ~ $'cgi.paging' 0 && csaTrue $TNS_PAGER_DEFAULT && cgi.paging = 1 42 43 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 44 45 . $CSA_ROOT/lib/group-stuff.rc 46 47 . $CSA_ROOT/lib/group-editor.rc 48 49 . $CSA_ROOT/lib/page-stuff.rc 50 51 . $CSA_ROOT/lib/tpl-stuff.rc 52 53 if (!csaIsFullPath --exists --quiet $tw_pstem+cmt) { 54 55 # Test whether comments are explicitly disabled for this page. 56 57 csaIsFullPath --exists --quiet \ 58 $tw_gstem/.$'cgi.page'+cmt && csaExit.fault --back 1013 59 60 # Proceed only if comments are allowed for this group. 61 csaTrue $TNS_CMT_ENABLE || csaExit.fault --back 1013 62 63 # Set Principal Lock Semaphore(s) (PLS). Unfortunately the lock 64 # needs to be set on the 'recent-comment' table, which is common to 65 # all pages within a group; this may become a bottleneck in case of 66 # heavily commented groups. 67 68 csaLock $tw_gstem/recent-comment+dat || csaExit.fault 69 70 # Make sure neither tables were created in the meantime. 71 72 csaIsFullPath --exists --quiet \ 73 $tw_gstem/.$'cgi.page'+cmt && csaExit.fault --back 1013 74 75 if (!csaIsFullPath --exists --quiet $tw_pstem+cmt) { 76 maketable --input $CSA_ROOT/lib/comment.xrf > $tw_pstem+cmt || 77 csaExit.fault 0003 maketable 78 } 79 } 80 81 tpl.var.tw.page.cmt.last = $CSA_SESSION(14) 82 83 if (csaIsFullPath --exists --quiet $CSA_TPL_ROOT/tw-page-comments.txt) { 84 # custom template. 85 tpl.include.html.body = $CSA_TPL_ROOT/tw-page-comments.txt 86 } else { 87 # default template. 88 tpl.include.html.body = $tw_dstem/tw-page-comments.txt 89 } 90 91 # Check authorizations. An empty group list means that everyone can 92 # list these comments. Editors are granted access in any case. 93 94 if (!~ $'tbl_page.p_allow' ()) { 95 96 if (!csvMatch $TNS_AUTH_GRP $'tbl_page.p_allow',editor) { 97 98 # Show self-registration form if appropriate. 99 csaIsInteractive && !csaTrue $CSA_AUTH_OK && 100 ~ $TNS_SELFREG_AUTH *[a-z]* && csaTrue $TNS_SELFREG_AUTOASK && 101 csaExit.location $CSA_RPC_URI'?0=showStatic&x-csa-lang='$CSA_LANG^'&1='$'cgi.group'^'&2=tw-reg-form' 102 103 csaExit.needauth 104 } 105 } 106 107 # Tree-listing of all comments associated to the specified page. I read 108 # the whole table upon every request, but since it is specific to the 109 # target page it should never be too big. Show threaded view, unless 110 # flat mode was explicitly requested. 111 112 # un-comment to test with flat listing. 113 #~ $REMOTE_ADDR 192.168.1.2 && csaAssign TNS_GROUP_MISC_PROP f 5 114 115 getcolumn --input $tw_pstem+cmt \ 116 k_cmt c_^(ctime subject tree banned other creau text) > $tmp1 || 117 csaExit.fault 0003 getcolumn 118 119 cmt_tmp = $tmp1 120 121 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.pcdata $cmt_tmp 122 123 csaMkTemp tpl.include.tw.page.captcha 124 captcha_code = `{pwgen -1 -A -B 6} 125 ~ $bqstatus 0 || csaExit.fault 0003 pwgen 126 csaSession.set $captcha_code 10 127 echo $captcha_code | figlet -w 80 -k > $'tpl.include.tw.page.captcha' 128 csaStatus || csaExit.fault 0003 figlet 129 130 # Set comment template vars to their final values. 131 tpl.var.tw.author = $'cgi.author' 132 ~ $CSA_SESSION(13) *'@'*.* && tpl.var.tw.author.email = $CSA_SESSION(13) 133 134 # This can be useful to avoid requesting the captcha code if desired, 135 # by turning the relevant form field from type=text to type=hidden 136 # value=$[tpl.var.tw.captcha:x] 137 138 tpl.var.tw.captcha = $captcha_code 139 140 csaMkTemp tpl.include.tw.page 141 142 # This view does not correspond to an actual page on disk, 143 # so we need to toggle unapplicable sections in templates. 144 145 tpl.if.tw.ispage = '(::DEL:)' 146 tpl.fi.tw.ispage = '(:DEL::)' 147 #tpl.if.tw.printable = '(::DEL:)' 148 #tpl.fi.tw.printable = '(:DEL::)' 149 tpl.if.tw.isview = () 150 tpl.fi.tw.isview = () 151 152 csaExit.ok --table $cmt_tmp $tpl_file 153 154 # End of program.