Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 602 lines (563 sloc) 20.014 kb
9c99cb3 Added patch for comment threading for articles.
p8191 authored
1 Index: article.c
2 ===================================================================
3 --- article.c (revision 145)
4 +++ article.c (working copy)
5 @@ -30,7 +30,26 @@
6 char *url;
7 };
8
9 +typedef struct _Reply Reply;
10 +typedef struct _ReplyList ReplyList;
11
12 +struct _ReplyList {
13 + Reply *head;
14 + Reply **tail;
15 +};
16 +
17 +struct _Reply {
18 + Reply *next;
19 + int key;
20 + Reply *parent;
21 + char *date;
22 + char *update;
23 + char *author;
24 + char *title;
25 + char *body;
26 + ReplyList children;
27 +};
28 +
29 /**
30 * Render an img tag for the topic icon based on the passed topic name
31 **/
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
32 @@ -50,46 +69,105 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
33 (*t)->url,(*t)->desc,(*t)->desc);
34 }
35
36 +static void
37 +article_render_reply_children (VirguleReq *vr, int art_num, const Reply *children)
38 +{
39 + if (children != NULL)
40 + {
41 + Buffer *b = vr->b;
42 + const Reply *reply;
43
44 + virgule_buffer_puts (vr->b, "<ul>\n");
45 +
46 + for (reply = children; reply != NULL; reply = reply->next)
47 + {
48 + char *updatestr = "";
49 +
50 + if (reply->update != NULL)
51 + updatestr = apr_psprintf (vr->r->pool, " (updated %s)", virgule_render_date (vr, reply->update, 1));
52 +
53 +
54 + virgule_buffer_printf (b, "<li><a href=\"%s/article/%u/%u.html#%u\"><b>%s</b></a>, by ",
55 + vr->prefix, art_num, reply->key, reply->key, reply->title);
56 +
57 + virgule_buffer_printf (b, "<a href=\"%s/person/%s/\">%s</a>",
58 + vr->prefix, ap_escape_uri(vr->r->pool, reply->author), reply->author);
59 +
60 + virgule_buffer_printf (b, ", %s%s</li>\n", virgule_render_date (vr, reply->date, 1), updatestr);
61 +
62 + article_render_reply_children (vr, art_num, reply->children.head);
63 + }
64 +
65 + virgule_buffer_puts (vr->b, "</ul>\n");
66 + }
67 +}
68 +
69 static void
70 -article_render_reply (VirguleReq *vr, int art_num, int reply_num)
71 +article_render_reply (VirguleReq *vr, int art_num, const Reply *reply)
72 {
73 - apr_pool_t *p = vr->r->pool;
74 Buffer *b = vr->b;
75 - char *key;
76 - xmlDoc *doc;
77
78 - key = apr_psprintf (p, "articles/_%d/_%d/reply.xml", art_num, reply_num);
79 + int reply_num = reply->key;
80 + const char *author = reply->author;
81 + const char *title = reply->title;
82 + const char *body = reply->body;
83 + const char *date = reply->date;
84 + const char *update = reply->update;
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
85 + int ok_to_reply;
9c99cb3 Added patch for comment threading for articles.
p8191 authored
86
87 - doc = virgule_db_xml_get (p, vr->db, key);
88 - if (doc != NULL)
89 + char *updatestr = "";
90 +
91 + if (update != NULL)
92 + updatestr = apr_psprintf (vr->r->pool, " (updated %s)", virgule_render_date (vr, update, 1));
93 +
94 + virgule_render_cert_level_begin (vr, author, CERT_STYLE_MEDIUM);
95 + virgule_buffer_printf (b, "<a name=\"%u\"><b>%s</b></a>, posted %s%s by <a href=\"%s/person/%s/\">%s</a> <a href=\"#%u\" style=\"text-decoration: none\">&raquo;</a>\n",
96 + reply_num, title, virgule_render_date (vr, date, 1), updatestr, vr->prefix, ap_escape_uri(vr->r->pool, author), author, reply_num);
97 + if (vr->u && !strcmp (vr->u, author))
98 + virgule_buffer_printf (b,
99 + "&nbsp; <a href=\"%s/article/editreply.html?art_num=%u&reply_num=%u\" style=\"text-decoration: none\">[ Edit ]</a>",
100 + vr->prefix, art_num, reply_num);
101 + virgule_render_cert_level_text (vr, author);
102 + virgule_render_cert_level_end (vr, CERT_STYLE_MEDIUM);
103 +
104 + virgule_buffer_puts (b, "<blockquote>\n");
105 +
106 + virgule_buffer_printf (b, "%s\n", body);
107 +
108 + if (reply->children.head != NULL)
109 {
110 - xmlNode *root = doc->xmlRootNode;
111 - char *author;
112 - char *title;
113 - char *body;
114 - char *date;
115 + article_render_reply_children (vr, art_num, reply->children.head);
116 + }
117
118 - author = virgule_xml_find_child_string (root, "author", "(no author)");
119 - title = virgule_xml_find_child_string (root, "title", "(no title)");
120 - body = virgule_xml_find_child_string (root, "body", "(no body)");
121 - date = virgule_xml_find_child_string (root, "date", "(no date)");
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
122 + ok_to_reply = virgule_req_ok_to_reply (vr);
9c99cb3 Added patch for comment threading for articles.
p8191 authored
123
124 - virgule_render_cert_level_begin (vr, author, CERT_STYLE_MEDIUM);
125 - virgule_buffer_printf (b, "<a name=\"%u\"><b>%s</b></a>, posted %s by <a href=\"%s/person/%s/\">%s</a> <a href=\"#%u\" style=\"text-decoration: none\">&raquo;</a>\n",
126 - reply_num, title, virgule_render_date (vr, date, 1), vr->prefix, ap_escape_uri(vr->r->pool, author), author, reply_num);
127 - virgule_render_cert_level_text (vr, author);
128 - virgule_render_cert_level_end (vr, CERT_STYLE_MEDIUM);
129 - virgule_buffer_printf (b, "<blockquote>\n%s\n</blockquote>\n", body);
130 - }
131 - else
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
132 + if (ok_to_reply || reply->parent != NULL)
9c99cb3 Added patch for comment threading for articles.
p8191 authored
133 {
134 - virgule_buffer_printf (b, "<p>Error reading <x>article</x> %d.\n", art_num);
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
135 - }
136 + virgule_buffer_puts (b, "<p>[ ");
137 +
138 + if (ok_to_reply)
139 + {
140 + virgule_buffer_printf (b, "<a href=\"%s/article/reply.html?art_num=%u&parent_num=%u\">Reply</a>",
141 + vr->prefix, art_num, reply->key);
142 +
143 + if (reply->parent != NULL)
144 + virgule_buffer_puts (b, " | ");
145 + }
146 +
147 + if (reply->parent != NULL)
148 + {
149 + virgule_buffer_printf (b, "<a href=\"%s/article/%u/%u.html#%u\">Parent</a>",
150 + vr->prefix, art_num, reply->parent->key, reply->parent->key);
151 + }
152 +
153 + virgule_buffer_puts (b, " ]\n");
154 + }
155 +
156 + virgule_buffer_puts (b, " </blockquote>\n");
9c99cb3 Added patch for comment threading for articles.
p8191 authored
157 }
158
159 static void
160 -article_render_replies (VirguleReq *vr, int art_num)
161 +article_render_replies (VirguleReq *vr, int art_num, int root_reply_num)
162 {
163 apr_pool_t *p = vr->r->pool;
164 int lastread;
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
165 @@ -105,13 +183,91 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
166 #endif
167 if (n_art > 0)
168 {
169 + /* load reply tree */
170 +
171 + ReplyList root_replies = { NULL, &root_replies.head }, *replies_to_render;
172 + Reply *reply;
173 +
174 + Reply *replies = apr_pcalloc (p, n_art*sizeof *replies);
175 +
176 + for (i = 0; i < n_art; i++)
177 + {
178 + reply = &replies[i];
179 +
180 + reply->key = i;
181 + reply->children.tail = &reply->children.head;
182 +
183 + char *key = apr_psprintf (p, "articles/_%d/_%d/reply.xml", art_num, i);
184 + xmlDoc *doc = virgule_db_xml_get (p, vr->db, key);
185 +
186 + if (doc != NULL)
187 + {
188 + char *parent_str;
189 + ReplyList *parent_children;
190 +
191 + xmlNode *root = doc->xmlRootNode;
192 +
193 + reply->author = virgule_xml_find_child_string (root, "author", "(no author)");
194 + reply->title = virgule_xml_find_child_string (root, "title", "(no title)");
195 + reply->body = virgule_xml_find_child_string (root, "body", "(no body)");
196 + reply->date = virgule_xml_find_child_string (root, "date", "(no date)");
197 + reply->update = virgule_xml_find_child_string (root, "update", NULL);
198 + reply->parent = NULL;
199 +
200 + parent_children = &root_replies;
201 +
202 + parent_str = (char *)xmlGetProp (root, (xmlChar *)"parent");
203 +
204 + if (parent_str != NULL)
205 + {
206 + int parent = atoi (parent_str);
207 +
208 + if (parent >= 0 && parent < n_art)
209 + {
210 + reply->parent = &replies[parent];
211 + parent_children = &reply->parent->children;
212 + }
213 + }
214 +
215 + *parent_children->tail = reply;
216 + parent_children->tail = &reply->next;
217 + }
218 + }
219 +
220 + /* render replies */
221 +
222 virgule_buffer_puts (vr->b, "<hr>\n");
223 +
224 + if (root_reply_num == -1 || root_reply_num < 0 || root_reply_num >= n_art)
225 + {
226 + replies_to_render = &root_replies;
227 + }
228 + else
229 + {
230 + Reply *root_reply = &replies[root_reply_num];
231 +
232 + if (root_reply->parent == NULL)
233 + replies_to_render = &root_replies;
234 + else
235 + replies_to_render = &root_reply->parent->children;
236 + }
237 +
238 + for (reply = replies_to_render->head; reply != NULL; reply = reply->next)
239 + {
240 + article_render_reply (vr, art_num, reply);
241 + }
242 +
243 + /* TODO: lastread */
244 +
245 +#if 0
246 for (i = 0; i < n_art; i++)
247 {
248 if (i == lastread)
249 virgule_buffer_puts (vr->b, "<a name=\"lastread\">");
250 article_render_reply (vr, art_num, i);
251 }
252 +#endif
253 +
254 }
255 virgule_acct_set_lastread(vr, "articles", apr_psprintf(p, "%d", art_num), n_art - 1);
256 }
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
257 @@ -208,7 +364,7 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
258 if (body)
259 virgule_buffer_printf (b, "<p>%s</p>\n", body);
260
261 - article_render_replies (vr, art_num);
262 + article_render_replies (vr, art_num, -1);
263
264 if (virgule_req_ok_to_reply (vr))
265 {
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
266 @@ -366,7 +522,8 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
267 const char *submit_type,
268 const char *key_base,
269 const char *key_suffix,
270 - const char *art_num_str)
271 + const char *art_num_str,
272 + const char *parent_num_str)
273 {
274 apr_pool_t *p = vr->r->pool;
275 apr_table_t *args;
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
276 @@ -429,7 +586,15 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
277 virgule_buffer_printf (b, "<p>%s</p>\n", nice_body);
278 virgule_buffer_puts (b, "<hr>\n");
279 virgule_buffer_printf (b, "<p>Edit your reply:</p>\n"
280 - "<form method=\"POST\" action=\"replysubmit.html\" accept-charset=\"UTF-8\">\n"
281 + "<form method=\"POST\" action=\"replysubmit.html\" accept-charset=\"UTF-8\">\n");
282 +
283 + if (olddate && oldkey)
284 + {
285 + virgule_buffer_printf (b, "<input type=\"hidden\" name=\"olddate\" value=\"%s\" />\n", olddate);
286 + virgule_buffer_printf (b, "<input type=\"hidden\" name=\"oldkey\" value=\"%s\" />\n", oldkey);
287 + }
288 +
289 + virgule_buffer_printf (b,
290 "<p><x>Article</x> title: <br>\n"
291 "<input type=\"text\" name=\"title\" value=\"%s\" size=\"40\" maxlength=\"60\"></p>\n"
292 "<p>Body of <x>article</x>: <br>\n"
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
293 @@ -532,6 +697,11 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
294 root = xmlNewDocNode (doc, NULL, (xmlChar *)"article", NULL);
295 doc->xmlRootNode = root;
296
297 + if (parent_num_str != NULL && (olddate == NULL && oldkey == NULL))
298 + {
299 + xmlSetProp (root, (xmlChar *)"parent", (xmlChar *)parent_num_str);
300 + }
301 +
302 if(olddate != NULL)
303 {
304 xmlNewChild (root, NULL, (xmlChar *)"date", (xmlChar *)olddate);
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
305 @@ -570,8 +740,7 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
306 char *a, *d;
307 time_t t;
308 xmlNodePtr r;
309 - int art_num = atoi (oldkey);
310 - char *k = apr_psprintf (vr->r->pool, "articles/_%d/article.xml", art_num);
311 + char *k = apr_psprintf (vr->r->pool, "%s/_%d%s", key_base, atoi (oldkey), key_suffix);
312 xmlDocPtr old = virgule_db_xml_get (vr->r->pool, vr->db, k);
313 if (old == NULL)
314 return virgule_send_error_page (vr, vERROR, "not found", "The specified <x>article</x> does not exist.");
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
315 @@ -587,6 +756,20 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
316 a = virgule_xml_find_child_string (r, "author", NULL);
317 if (strcmp (vr->u, a))
318 return virgule_send_error_page (vr, vERROR, "forbidden", "Only <x>articles</x> posted by you may be edited.");
319 +
320 + /* copy previous reply parent to new entry */
321 + if (!strcmp (submit_type, "reply"))
322 + {
323 + const xmlChar *parent = xmlGetProp (r, (xmlChar *)"parent");
324 +
325 + if (parent != NULL)
326 + {
327 + /* parent will always be the one in the previous entry. we don't want anyone to fiddle with
328 + * this and create loops or anything. */
329 +
330 + xmlSetProp (root, (xmlChar *)"parent", parent);
331 + }
332 + }
333 }
334
335 status = virgule_db_xml_put (p, vr->db, key, doc);
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
336 @@ -650,7 +833,7 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
337
338 return article_generic_submit_serve (vr, topic, title, lead, body, NULL, NULL,
339 "article",
340 - "articles", "/article.xml", NULL);
341 + "articles", "/article.xml", NULL, NULL);
342 }
343
344
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
345 @@ -680,6 +863,9 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
346
347 /* try to read the article */
348 art_num_str = apr_table_get (args, "key");
349 + if (art_num_str == NULL)
350 + return virgule_send_error_page (vr, vERROR, "form data", "No <x>article</x> key was specified.");
351 +
352 art_num = atoi (art_num_str);
353 key = apr_psprintf (vr->r->pool, "articles/_%d/article.xml", art_num);
354 doc = virgule_db_xml_get (vr->r->pool, vr->db, key);
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
355 @@ -708,7 +894,7 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
356 return article_generic_submit_serve (vr, topic, title, lead, body, date,
357 art_num_str,
358 "article",
359 - "articles", "/article.xml", NULL);
360 + "articles", "/article.xml", NULL, NULL);
361 }
362
363
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
364 @@ -718,8 +904,8 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
365 {
366 apr_pool_t *p = vr->r->pool;
367 apr_table_t *args;
368 - const char *art_num_str;
369 - int art_num;
370 + const char *art_num_str, *parent_num_str;
371 + int art_num, parent_num;
372 char *key;
373 xmlDoc *doc;
374 xmlNode *root, *tree;
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
375 @@ -740,7 +926,17 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
376
377 art_num = atoi (art_num_str);
378
379 - key = apr_psprintf (p, "articles/_%d/article.xml", art_num);
380 + parent_num_str = apr_table_get (args, "parent_num");
381 + if (parent_num_str == NULL)
382 + parent_num = -1;
383 + else
384 + parent_num = atoi (parent_num_str);
385 +
386 + if (parent_num == -1)
387 + key = apr_psprintf (p, "articles/_%d/article.xml", art_num);
388 + else
389 + key = apr_psprintf (p, "articles/_%d/_%d/reply.xml", art_num, parent_num);
390 +
391 doc = virgule_db_xml_get (p, vr->db, key);
392 if (doc == NULL)
393 return virgule_send_error_page (vr, vERROR, "database", "<x>Article</x> %d not found.", art_num);
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
394 @@ -754,7 +950,7 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
395 if (virgule_set_temp_buffer (vr) != 0)
396 return HTTP_INTERNAL_SERVER_ERROR;
397
398 - virgule_buffer_printf (vr->b, "<p>Post a reply to <x>article</x>: %s.</p>\n"
399 + virgule_buffer_printf (vr->b, "<p>Post a reply to <x>article%s</x>: %s.</p>\n"
400 "<form method=\"POST\" action=\"replysubmit.html\" accept-charset=\"UTF-8\">\n"
401 "<p>Reply title: <br>\n"
402 "<input type=\"text\" name=\"title\" size=50 maxlength=50></p>\n"
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
403 @@ -763,9 +959,14 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
404 "</textarea></p>\n"
405 "<input type=\"hidden\" name=\"art_num\" value=\"%d\">\n"
406 "<p><input type=\"submit\" name=post value=\"Post\">\n"
407 - "<input type=\"submit\" name=preview value=\"Preview\">\n"
408 - "</form>\n", title, art_num);
409 + "<input type=\"submit\" name=preview value=\"Preview\">\n",
410 + parent_num == -1 ? "" : " comment", title, art_num);
411
412 + if (parent_num != -1)
413 + virgule_buffer_printf (vr->b, "<input type=\"hidden\" name=\"parent\" value=\"%d\">\n", parent_num);
414 +
415 + virgule_buffer_puts (vr->b, "</form>\n");
416 +
417 virgule_render_acceptable_html (vr);
418
419 virgule_set_main_buffer (vr);
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
420 @@ -774,14 +975,77 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
421 }
422
423 static int
424 +article_edit_reply_serve (VirguleReq *vr)
425 +{
426 + apr_pool_t *p = vr->r->pool;
427 + apr_table_t *args;
428 + const char *art_num_str, *reply_num_str;
429 + int art_num, reply_num;
430 + char *key, *title, *author, *body, *date, *key_base;
431 + xmlDoc *doc;
432 + xmlNode *root;
433 +
434 + virgule_auth_user (vr);
435 +
436 + /* user must be logged in */
437 + if (vr->u == NULL)
438 + return virgule_send_error_page (vr, vERROR, "forbidden", "You can't post a reply because you're not logged in.");
439 +
440 + if (!virgule_req_ok_to_reply (vr))
441 + return virgule_send_error_page (vr, vERROR, "forbidden", "You can't post because you're not certified. Please see the <a href=\"%s/certs.html\">certification overview</a> for more details.", vr->prefix);
442 +
443 + args = virgule_get_args_table (vr);
444 + if (args == NULL)
445 + return virgule_send_error_page (vr, vERROR, "form data", "No arguments specified.");
446 +
447 + art_num_str = apr_table_get (args, "art_num");
448 + if (art_num_str == NULL)
449 + return virgule_send_error_page (vr, vERROR, "form data", "Need <x>article</x> number to reply to.");
450 +
451 + art_num = atoi (art_num_str);
452 +
453 + reply_num_str = apr_table_get (args, "reply_num");
454 + if (reply_num_str == NULL)
455 + return virgule_send_error_page (vr, vERROR, "form data", "Need to specify reply to edit.");
456 +
457 + reply_num = atoi (reply_num_str);
458 +
459 + key = apr_psprintf (p, "articles/_%d/_%d/reply.xml", art_num, reply_num);
460 + doc = virgule_db_xml_get(p, vr->db, key);
461 + if (doc == NULL)
462 + return virgule_send_error_page (vr, vERROR, "database", "The specified <x>reply</x> to <x>article</x> could not be loaded.");
463 +
464 + root = doc->xmlRootNode;
465 +
466 + author = virgule_xml_find_child_string (root, "author", NULL);
467 + if (strcmp (vr->u, author))
468 + return virgule_send_error_page (vr, vERROR, "forbidden", "Only <x>replies</x> posted by you may be edited.");
469 +
470 + date = virgule_xml_find_child_string (root, "date", NULL);
471 + title = virgule_xml_find_child_string (root, "title", NULL);
472 + body = virgule_xml_find_child_string (root, "body", NULL);
473 +
474 + if (virgule_set_temp_buffer (vr) != 0)
475 + return HTTP_INTERNAL_SERVER_ERROR;
476 +
477 + key_base = apr_psprintf (p, "articles/_%d", atoi (art_num_str));
478 +
479 + /* load the editor in preview mode */
480 + return article_generic_submit_serve (vr, NULL, title, NULL, body, date,
481 + reply_num_str, "reply",
482 + key_base, "/reply.xml", art_num_str, NULL);
483 +}
484 +
485 +
486 +static int
487 article_reply_submit_serve (VirguleReq *vr)
488 {
489 apr_pool_t *p = vr->r->pool;
490 apr_table_t *args;
491 - const char *title, *art_num_str, *body;
492 + const char *title, *art_num_str, *body, *oldkey, *parent_num_str;
493 char *key_base;
494 char *key_reply;
495 - int last_reply;
496 + int last_reply, parent_num;
497 xmlDoc *doc;
498
499 virgule_auth_user (vr);
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
500 @@ -796,17 +1060,28 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
501 title = apr_table_get (args, "title");
502 art_num_str = apr_table_get (args, "art_num");
503 body = apr_table_get (args, "body");
504 + oldkey = apr_table_get (args, "oldkey");
505 + parent_num_str = apr_table_get (args, "parent");
506
507 if (art_num_str == NULL)
508 return virgule_send_error_page (vr, vERROR, "form data", "This page requires <x>an article</x> number. If you're not playing around manually with URLs, it suggests there's something wrong with the site.");
509
510 key_base = apr_psprintf (p, "articles/_%d", atoi (art_num_str));
511
512 + last_reply = virgule_db_dir_max (vr->db, key_base);
513 +
514 + if (parent_num_str != NULL)
515 + {
516 + parent_num = atoi (parent_num_str);
517 +
518 + if (parent_num < 0 || parent_num > last_reply)
519 + return virgule_send_error_page (vr, vERROR, "form data", "Invalid parent key.");
520 + }
521 +
522 /* Reject duplicate replies */
523 - last_reply = virgule_db_dir_max (vr->db, key_base);
524 key_reply = apr_psprintf (p, "articles/_%d/_%d/reply.xml", atoi (art_num_str),last_reply);
525 doc = virgule_db_xml_get (p, vr->db, key_reply);
526 - if (doc != NULL)
527 + if (doc != NULL && oldkey == NULL)
528 {
529 const char *old_author;
530 const char *old_title;
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
531 @@ -818,7 +1093,7 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
532
533 return article_generic_submit_serve (vr, NULL, title, NULL, body, NULL, NULL,
534 "reply",
535 - key_base, "/reply.xml", art_num_str);
536 + key_base, "/reply.xml", art_num_str, parent_num_str);
537 }
538
539 /**
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
540 @@ -877,19 +1152,29 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
541 article_num_serve (VirguleReq *vr, const char *t)
542 {
543 char *tail, *key, *title;
544 - int n;
545 + int art_num, root_reply_num;
546 xmlDoc *doc;
547 xmlNode *root;
548
549 virgule_auth_user (vr);
550
551 - n = strtol (t, &tail, 10);
552 + art_num = strtol (t, &tail, 10);
553 +
554 + if (tail == t)
555 + return virgule_send_error_page (vr, vERROR, "form data", "Invalid <x>article</x> number");
556 +
557 + if (tail[0] == '/' && isdigit (tail[1]))
558 + root_reply_num = strtol (&tail[1], &tail, 10);
559 + else
560 + root_reply_num = -1;
561 +
562 if (strcmp (tail, ".html"))
563 return virgule_send_error_page (vr, vERROR, "form data", "Invalid <x>Article</x> URL: %s", tail);
564 - key = apr_psprintf (vr->r->pool, "articles/_%d/article.xml", n);
565 +
566 + key = apr_psprintf (vr->r->pool, "articles/_%d/article.xml", art_num);
567 doc = virgule_db_xml_get (vr->r->pool, vr->db, key);
568 if (doc == NULL)
569 - return virgule_send_error_page (vr, vERROR, "database", "<x>Article</x> %d not found.", n);
570 + return virgule_send_error_page (vr, vERROR, "database", "<x>Article</x> %d not found.", art_num);
571 root = xmlDocGetRootElement (doc);
572 title = virgule_xml_find_child_string (root, "title", "(no title)");
573
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
574 @@ -897,8 +1182,15 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
575 if (virgule_set_temp_buffer (vr) != 0)
576 return HTTP_INTERNAL_SERVER_ERROR;
577
578 - /* render the article to the temp buffer */
579 - article_render_from_xml (vr, n, doc, ARTICLE_RENDER_FULL);
580 + if (root_reply_num == -1)
581 + {
582 + /* render the article to the temp buffer */
583 + article_render_from_xml (vr, art_num, doc, ARTICLE_RENDER_FULL);
584 + }
585 + else
586 + {
587 + article_render_replies (vr, art_num, root_reply_num);
588 + }
589
590 /* switch back to the main buffer */
591 virgule_set_main_buffer (vr);
053de7e Checking if it's ok to reply before rendering link to comment replies.
p8191 authored
592 @@ -950,6 +1242,9 @@
9c99cb3 Added patch for comment threading for articles.
p8191 authored
593 if (!strcmp (p, "edit.html"))
594 return article_edit_serve (vr);
595
596 + if (!strcmp (p, "editreply.html"))
597 + return article_edit_reply_serve (vr);
598 +
599 if (isdigit (p[0]))
600 return article_num_serve (vr, p);
601
Something went wrong with that request. Please try again.