| | @@ -95,10 +95,36 @@ |
| 95 | 95 | return forum_post_is_closed(p->pIrt->pEditTail |
| 96 | 96 | ? p->pIrt->pEditTail : p->pIrt); |
| 97 | 97 | } |
| 98 | 98 | return 0; |
| 99 | 99 | } |
| 100 | + |
| 101 | +/* |
| 102 | +** Given a forum post RID, this function returns true if that post or |
| 103 | +** the latest version of any parent post in its hierarchy have an |
| 104 | +** active "closed" tag. |
| 105 | +*/ |
| 106 | +int forum_rid_is_closed(int rid){ |
| 107 | + static Stmt qIrt = empty_Stmt_m; |
| 108 | + int rc; |
| 109 | + |
| 110 | + /* TODO: this can probably be turned into a CTE, rather than a |
| 111 | + ** recursive call into this function, by someone with superior |
| 112 | + ** SQL-fu. */ |
| 113 | + rc = rid_has_active_tag_name(rid, "closed"); |
| 114 | + if( rc ) return rc; |
| 115 | + else if( !qIrt.pStmt ) { |
| 116 | + db_static_prepare(&qIrt, |
| 117 | + "SELECT firt FROM forumpost " |
| 118 | + "WHERE fpid=$fpid ORDER BY fmtime DESC" |
| 119 | + ); |
| 120 | + } |
| 121 | + db_bind_int(&qIrt, "$fpid", rid); |
| 122 | + rc = SQLITE_ROW==db_step(&qIrt) ? db_column_int(&qIrt, 0) : 0; |
| 123 | + db_reset(&qIrt); |
| 124 | + return rc>0 ? forum_rid_is_closed(rc) : 0; |
| 125 | +} |
| 100 | 126 | |
| 101 | 127 | /* |
| 102 | 128 | ** Delete a complete ForumThread and all its entries. |
| 103 | 129 | */ |
| 104 | 130 | static void forumthread_delete(ForumThread *pThread){ |
| | @@ -1105,10 +1131,11 @@ |
| 1105 | 1131 | ** But first prompt to see if the user would like to log in. |
| 1106 | 1132 | */ |
| 1107 | 1133 | void forum_page_init(void){ |
| 1108 | 1134 | int isEdit; |
| 1109 | 1135 | char *zGoto; |
| 1136 | + |
| 1110 | 1137 | login_check_credentials(); |
| 1111 | 1138 | if( !g.perm.WrForum ){ |
| 1112 | 1139 | login_needed(g.anon.WrForum); |
| 1113 | 1140 | return; |
| 1114 | 1141 | } |
| | @@ -1236,10 +1263,11 @@ |
| 1236 | 1263 | const char *zTitle = 0; |
| 1237 | 1264 | char *zDate = 0; |
| 1238 | 1265 | const char *zFpid = PD("fpid",""); |
| 1239 | 1266 | int isCsrfSafe; |
| 1240 | 1267 | int isDelete = 0; |
| 1268 | + int fClosed = 0; |
| 1241 | 1269 | |
| 1242 | 1270 | login_check_credentials(); |
| 1243 | 1271 | if( !g.perm.WrForum ){ |
| 1244 | 1272 | login_needed(g.anon.WrForum); |
| 1245 | 1273 | return; |
| | @@ -1254,10 +1282,11 @@ |
| 1254 | 1282 | } |
| 1255 | 1283 | if( P("cancel") ){ |
| 1256 | 1284 | cgi_redirectf("%R/forumpost/%S",P("fpid")); |
| 1257 | 1285 | return; |
| 1258 | 1286 | } |
| 1287 | + fClosed = forum_rid_is_closed(fpid); |
| 1259 | 1288 | isCsrfSafe = cgi_csrf_safe(1); |
| 1260 | 1289 | if( g.perm.ModForum && isCsrfSafe ){ |
| 1261 | 1290 | if( P("approve") ){ |
| 1262 | 1291 | const char *zUserToTrust; |
| 1263 | 1292 | moderation_approve('f', fpid); |
| 1264 | 1293 | |