| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
article_post.c - description |
/* |
| 3 |
------------------- |
* article_post |
| 4 |
copyright : (C) 2004-2025 by Leaflet |
* - user interactive feature to post / modify / reply article |
| 5 |
email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
|
/*************************************************************************** |
|
|
* * |
|
|
* This program is free software; you can redistribute it and/or modify * |
|
|
* it under the terms of the GNU General Public License as published by * |
|
|
* the Free Software Foundation; either version 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 8 |
|
|
|
#define _POSIX_C_SOURCE 200809L |
|
|
|
|
|
#include "article_post.h" |
|
| 9 |
#include "article_cache.h" |
#include "article_cache.h" |
| 10 |
#include "editor.h" |
#include "article_post.h" |
|
#include "screen.h" |
|
| 11 |
#include "bbs.h" |
#include "bbs.h" |
| 12 |
#include "log.h" |
#include "database.h" |
| 13 |
|
#include "editor.h" |
| 14 |
#include "io.h" |
#include "io.h" |
| 15 |
|
#include "log.h" |
| 16 |
#include "lml.h" |
#include "lml.h" |
| 17 |
#include "database.h" |
#include "screen.h" |
| 18 |
#include "user_priv.h" |
#include "user_priv.h" |
| 19 |
#include <ctype.h> |
#include <ctype.h> |
| 20 |
#include <string.h> |
#include <string.h> |
| 21 |
#include <stdlib.h> |
#include <stdlib.h> |
| 22 |
#include <time.h> |
#include <time.h> |
| 23 |
|
|
| 24 |
#define TITLE_INPUT_MAX_LEN 74 |
#define TITLE_INPUT_MAX_LEN 72 |
| 25 |
#define ARTICLE_CONTENT_MAX_LEN 1024 * 1024 * 4 // 4MB |
#define ARTICLE_CONTENT_MAX_LEN 1024 * 1024 * 4 // 4MB |
| 26 |
#define ARTICLE_QUOTE_MAX_LINES 20 |
#define ARTICLE_QUOTE_MAX_LINES 20 |
|
#define ARTICLE_QUOTE_LINE_MAX_LEN 76 |
|
| 27 |
|
|
| 28 |
#define MODIFY_DT_MAX_LEN 50 |
#define MODIFY_DT_MAX_LEN 50 |
| 29 |
|
|
| 35 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 36 |
char *sql_content = NULL; |
char *sql_content = NULL; |
| 37 |
EDITOR_DATA *p_editor_data = NULL; |
EDITOR_DATA *p_editor_data = NULL; |
| 38 |
char title_input[TITLE_INPUT_MAX_LEN + 1]; |
char title_input[BBS_article_title_max_len + 1]; |
| 39 |
char title_f[BBS_article_title_max_len * 2 + 1]; |
char title_f[BBS_article_title_max_len * 2 + 1]; |
| 40 |
char *content = NULL; |
char *content = NULL; |
| 41 |
char *content_f = NULL; |
char *content_f = NULL; |
| 42 |
long len_content; |
long len_content; |
| 43 |
|
int content_display_length; |
| 44 |
char nickname_f[BBS_nickname_max_len * 2 + 1]; |
char nickname_f[BBS_nickname_max_len * 2 + 1]; |
| 45 |
int sign_id = 0; |
int sign_id = 0; |
| 46 |
|
int reply_note = 1; |
| 47 |
long len; |
long len; |
| 48 |
int ch; |
int ch; |
| 49 |
char *p, *q; |
char *p, *q; |
| 58 |
{ |
{ |
| 59 |
clearscr(); |
clearscr(); |
| 60 |
moveto(1, 1); |
moveto(1, 1); |
| 61 |
prints("您没有权限在本版块发表文章\n"); |
prints("鎮ㄦ病鏈夋潈闄愬湪鏈増鍧楀彂琛ㄦ枃绔燶n"); |
| 62 |
press_any_key(); |
press_any_key(); |
| 63 |
|
|
| 64 |
return 0; |
return 0; |
| 72 |
if (p_editor_data == NULL) |
if (p_editor_data == NULL) |
| 73 |
{ |
{ |
| 74 |
log_error("editor_data_load() error\n"); |
log_error("editor_data_load() error\n"); |
| 75 |
return -2; |
ret = -1; |
| 76 |
|
goto cleanup; |
| 77 |
} |
} |
| 78 |
|
|
| 79 |
// Set title and sign |
// Set title and sign |
| 81 |
{ |
{ |
| 82 |
clearscr(); |
clearscr(); |
| 83 |
moveto(21, 1); |
moveto(21, 1); |
| 84 |
prints("发表文章于 %s[%s] 讨论区,类型: %s", p_section->stitle, p_section->sname, (p_article_new->transship ? "转载" : "原创")); |
prints("鍙戣〃鏂囩珷浜 %s[%s] 璁ㄨ鍖猴紝绫诲瀷: %s锛屽洖澶嶉氱煡锛%s", |
| 85 |
|
p_section->stitle, p_section->sname, |
| 86 |
|
(p_article_new->transship ? "杞浇" : "鍘熷垱"), |
| 87 |
|
(reply_note ? "寮鍚" : "鍏抽棴")); |
| 88 |
moveto(22, 1); |
moveto(22, 1); |
| 89 |
prints("标题: %s", (p_article_new->title[0] == '\0' ? "[无]" : p_article_new->title)); |
prints("鏍囬: %s", (p_article_new->title[0] == '\0' ? "[鏃燷" : p_article_new->title)); |
| 90 |
moveto(23, 1); |
moveto(23, 1); |
| 91 |
prints("使用第 [1;32m%d[m 个签名", sign_id); |
prints("浣跨敤绗 [1;32m%d[m 涓鍚", sign_id); |
| 92 |
|
|
| 93 |
if (toupper(ch) != 'T') |
if (toupper(ch) != 'T') |
| 94 |
{ |
{ |
| 95 |
prints(" 按[1;32m0[m~[1;32m3[m选签名档(0表示不使用)"); |
prints(" 鎸[1;32m0[m~[1;32m3[m閫夌鍚嶆。(0琛ㄧず涓嶄娇鐢)"); |
| 96 |
|
|
| 97 |
moveto(24, 1); |
moveto(24, 1); |
| 98 |
prints("[1;32mT[m改标题, [1;32mC[m取消, [1;32mZ[m设为转载, [1;32mY[m设为原创, [1;32mEnter[m继续: "); |
prints("[1;32mT[m鏀规爣棰, [1;32mC[m鍙栨秷, [1;32mZ[m璁句负%s, [1;32mN[m%s, [1;32mEnter[m缁х画: ", |
| 99 |
|
(p_article_new->transship ? "鍘熷垱" : "杞浇"), |
| 100 |
|
(reply_note ? "鍏抽棴鍥炲閫氱煡" : "寮鍚洖澶嶉氱煡")); |
| 101 |
iflush(); |
iflush(); |
| 102 |
ch = 0; |
ch = 0; |
| 103 |
} |
} |
| 106 |
{ |
{ |
| 107 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 108 |
{ |
{ |
| 109 |
|
case KEY_NULL: |
| 110 |
|
case KEY_TIMEOUT: |
| 111 |
|
goto cleanup; |
| 112 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 113 |
break; |
break; |
| 114 |
case 'T': |
case 'T': |
| 115 |
moveto(24, 1); |
len = get_data(24, 1, "鏍囬: ", title_input, sizeof(title_input), TITLE_INPUT_MAX_LEN); |
|
clrtoeol(); |
|
|
len = get_data(24, 1, "标题: ", title_input, TITLE_INPUT_MAX_LEN, 1); |
|
| 116 |
for (p = title_input; *p == ' '; p++) |
for (p = title_input; *p == ' '; p++) |
| 117 |
; |
; |
| 118 |
for (q = title_input + len; q > p && *(q - 1) == ' '; q--) |
for (q = title_input + len; q > p && *(q - 1) == ' '; q--) |
| 129 |
case 'C': |
case 'C': |
| 130 |
clearscr(); |
clearscr(); |
| 131 |
moveto(1, 1); |
moveto(1, 1); |
| 132 |
prints("取消..."); |
prints("鍙栨秷..."); |
| 133 |
press_any_key(); |
press_any_key(); |
| 134 |
goto cleanup; |
goto cleanup; |
|
case 'Y': |
|
|
p_article_new->transship = 0; |
|
|
break; |
|
| 135 |
case 'Z': |
case 'Z': |
| 136 |
p_article_new->transship = 1; |
p_article_new->transship = (p_article_new->transship ? 0 : 1); |
| 137 |
|
break; |
| 138 |
|
case 'N': |
| 139 |
|
reply_note = (reply_note ? 0 : 1); |
| 140 |
break; |
break; |
| 141 |
case '0': |
case '0': |
| 142 |
case '1': |
case '1': |
| 162 |
|
|
| 163 |
clearscr(); |
clearscr(); |
| 164 |
moveto(1, 1); |
moveto(1, 1); |
| 165 |
prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: "); |
prints("(S)鍙戦, (C)鍙栨秷, (T)鏇存敼鏍囬 or (E)鍐嶇紪杈? [S]: "); |
| 166 |
iflush(); |
iflush(); |
| 167 |
|
|
| 168 |
for (ch = 0; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) |
for (ch = 0; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) |
| 169 |
{ |
{ |
| 170 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 171 |
{ |
{ |
| 172 |
|
case KEY_NULL: |
| 173 |
|
case KEY_TIMEOUT: |
| 174 |
|
goto cleanup; |
| 175 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 176 |
case 'S': |
case 'S': |
| 177 |
break; |
break; |
| 178 |
case 'C': |
case 'C': |
| 179 |
clearscr(); |
clearscr(); |
| 180 |
moveto(1, 1); |
moveto(1, 1); |
| 181 |
prints("取消..."); |
prints("鍙栨秷..."); |
| 182 |
press_any_key(); |
press_any_key(); |
| 183 |
goto cleanup; |
goto cleanup; |
| 184 |
case 'T': |
case 'T': |
| 199 |
} |
} |
| 200 |
} |
} |
| 201 |
|
|
| 202 |
|
if (SYS_server_exit) // Do not save data on shutdown |
| 203 |
|
{ |
| 204 |
|
goto cleanup; |
| 205 |
|
} |
| 206 |
|
|
| 207 |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
| 208 |
if (content == NULL) |
if (content == NULL) |
| 209 |
{ |
{ |
| 216 |
if (len_content < 0) |
if (len_content < 0) |
| 217 |
{ |
{ |
| 218 |
log_error("editor_data_save() error\n"); |
log_error("editor_data_save() error\n"); |
| 219 |
ret = -2; |
ret = -1; |
| 220 |
goto cleanup; |
goto cleanup; |
| 221 |
} |
} |
| 222 |
|
|
| 257 |
rs = NULL; |
rs = NULL; |
| 258 |
} |
} |
| 259 |
|
|
| 260 |
|
// Calculate display length of content |
| 261 |
|
content_display_length = str_length(content, 1); |
| 262 |
|
|
| 263 |
// Begin transaction |
// Begin transaction |
| 264 |
if (mysql_query(db, "SET autocommit=0") != 0) |
if (mysql_query(db, "SET autocommit=0") != 0) |
| 265 |
{ |
{ |
| 323 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 324 |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
| 325 |
"sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) " |
"sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) " |
| 326 |
"VALUES(%d, 0, %d, '%s', '%s', '%s', %d, %d, NOW(), '%s', 1, %d, NOW(), 1, %ld)", |
"VALUES(%d, 0, %d, '%s', '%s', '%s', %d, %d, NOW(), '%s', %d, %d, NOW(), 1, %d)", |
| 327 |
p_section->sid, BBS_priv.uid, BBS_username, nickname_f, title_f, |
p_section->sid, BBS_priv.uid, BBS_username, nickname_f, title_f, |
| 328 |
p_article_new->cid, p_article_new->transship, hostaddr_client, BBS_user_exp, len_content); |
p_article_new->cid, p_article_new->transship, hostaddr_client, |
| 329 |
|
reply_note, BBS_user_exp, content_display_length); |
| 330 |
|
|
| 331 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 332 |
{ |
{ |
| 385 |
goto cleanup; |
goto cleanup; |
| 386 |
} |
} |
| 387 |
|
|
| 388 |
|
mysql_close(db); |
| 389 |
|
db = NULL; |
| 390 |
|
|
| 391 |
clearscr(); |
clearscr(); |
| 392 |
moveto(1, 1); |
moveto(1, 1); |
| 393 |
prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval); |
prints("鍙戦佸畬鎴愶紝鏂版枃绔犻氬父浼氬湪%d绉掑悗鍙", BBS_section_list_load_interval); |
| 394 |
press_any_key(); |
press_any_key(); |
| 395 |
ret = 1; // Success |
ret = 1; // Success |
| 396 |
|
|
| 417 |
char *content = NULL; |
char *content = NULL; |
| 418 |
char *content_f = NULL; |
char *content_f = NULL; |
| 419 |
long len_content; |
long len_content; |
| 420 |
|
int content_display_length; |
| 421 |
|
int reply_note = 1; |
| 422 |
int ch; |
int ch; |
| 423 |
long ret = 0; |
long ret = 0; |
| 424 |
time_t now; |
time_t now; |
| 436 |
{ |
{ |
| 437 |
clearscr(); |
clearscr(); |
| 438 |
moveto(1, 1); |
moveto(1, 1); |
| 439 |
prints("该文章无法被编辑,请联系版主。"); |
prints("璇ユ枃绔犳棤娉曡缂栬緫锛岃鑱旂郴鐗堜富銆"); |
|
press_any_key(); |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
|
if (!checkpriv(&BBS_priv, p_section->sid, S_POST)) |
|
|
{ |
|
|
clearscr(); |
|
|
moveto(1, 1); |
|
|
prints("您没有权限在本版块发表文章\n"); |
|
| 440 |
press_any_key(); |
press_any_key(); |
| 441 |
|
|
| 442 |
return 0; |
return 0; |
| 446 |
if (db == NULL) |
if (db == NULL) |
| 447 |
{ |
{ |
| 448 |
log_error("db_open() error: %s\n", mysql_error(db)); |
log_error("db_open() error: %s\n", mysql_error(db)); |
| 449 |
return -1; |
ret = -1; |
| 450 |
|
goto cleanup; |
| 451 |
} |
} |
| 452 |
|
|
| 453 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 454 |
"SELECT bbs_content.CID, bbs_content.content " |
"SELECT bbs_content.CID, bbs_content.content, reply_note " |
| 455 |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
| 456 |
"WHERE bbs.AID = %d", |
"WHERE bbs.AID = %d", |
| 457 |
p_article->aid); |
p_article->aid); |
| 459 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 460 |
{ |
{ |
| 461 |
log_error("Query article content error: %s\n", mysql_error(db)); |
log_error("Query article content error: %s\n", mysql_error(db)); |
| 462 |
ret = -2; |
ret = -1; |
| 463 |
goto cleanup; |
goto cleanup; |
| 464 |
} |
} |
| 465 |
if ((rs = mysql_use_result(db)) == NULL) |
if ((rs = mysql_use_result(db)) == NULL) |
| 466 |
{ |
{ |
| 467 |
log_error("Get article content data failed\n"); |
log_error("Get article content data failed\n"); |
| 468 |
ret = -2; |
ret = -1; |
| 469 |
goto cleanup; |
goto cleanup; |
| 470 |
} |
} |
| 471 |
|
|
| 483 |
content[ARTICLE_CONTENT_MAX_LEN - 1] = '\0'; |
content[ARTICLE_CONTENT_MAX_LEN - 1] = '\0'; |
| 484 |
|
|
| 485 |
// Remove control sequence |
// Remove control sequence |
| 486 |
len_content = ctrl_seq_filter(content); |
len_content = str_filter(content, 0); |
| 487 |
|
|
| 488 |
p_editor_data = editor_data_load(content); |
p_editor_data = editor_data_load(content); |
| 489 |
if (p_editor_data == NULL) |
if (p_editor_data == NULL) |
| 490 |
{ |
{ |
| 491 |
log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0])); |
log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0])); |
| 492 |
ret = -3; |
ret = -1; |
| 493 |
goto cleanup; |
goto cleanup; |
| 494 |
} |
} |
| 495 |
|
|
| 496 |
free(content); |
free(content); |
| 497 |
content = NULL; |
content = NULL; |
| 498 |
|
|
| 499 |
|
reply_note = atoi(row[2]); |
| 500 |
} |
} |
| 501 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 502 |
rs = NULL; |
rs = NULL; |
| 508 |
{ |
{ |
| 509 |
editor_display(p_editor_data); |
editor_display(p_editor_data); |
| 510 |
|
|
| 511 |
clearscr(); |
while (!SYS_server_exit) |
|
moveto(1, 1); |
|
|
prints("(S)保存, (C)取消 or (E)再编辑? [S]: "); |
|
|
iflush(); |
|
|
|
|
|
for (ch = 0; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) |
|
| 512 |
{ |
{ |
| 513 |
|
clearscr(); |
| 514 |
|
moveto(1, 1); |
| 515 |
|
prints("(S)淇濆瓨, (C)鍙栨秷, (N)%s鍥炲閫氱煡 or (E)鍐嶇紪杈? [S]: ", |
| 516 |
|
(reply_note ? "鍏抽棴" : "寮鍚")); |
| 517 |
|
iflush(); |
| 518 |
|
|
| 519 |
|
ch = igetch_t(MAX_DELAY_TIME); |
| 520 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 521 |
{ |
{ |
| 522 |
|
case KEY_NULL: |
| 523 |
|
case KEY_TIMEOUT: |
| 524 |
|
goto cleanup; |
| 525 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 526 |
case 'S': |
case 'S': |
| 527 |
break; |
break; |
| 528 |
case 'C': |
case 'C': |
| 529 |
clearscr(); |
clearscr(); |
| 530 |
moveto(1, 1); |
moveto(1, 1); |
| 531 |
prints("取消..."); |
prints("鍙栨秷..."); |
| 532 |
press_any_key(); |
press_any_key(); |
| 533 |
goto cleanup; |
goto cleanup; |
| 534 |
|
case 'N': |
| 535 |
|
reply_note = (reply_note ? 0 : 1); |
| 536 |
|
continue; |
| 537 |
case 'E': |
case 'E': |
| 538 |
break; |
break; |
| 539 |
default: // Invalid selection |
default: // Invalid selection |
| 544 |
} |
} |
| 545 |
} |
} |
| 546 |
|
|
| 547 |
|
if (SYS_server_exit) // Do not save data on shutdown |
| 548 |
|
{ |
| 549 |
|
goto cleanup; |
| 550 |
|
} |
| 551 |
|
|
| 552 |
// Allocate buffers in big size |
// Allocate buffers in big size |
| 553 |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
| 554 |
if (content == NULL) |
if (content == NULL) |
| 562 |
if (len_content < 0) |
if (len_content < 0) |
| 563 |
{ |
{ |
| 564 |
log_error("editor_data_save() error\n"); |
log_error("editor_data_save() error\n"); |
| 565 |
ret = -2; |
ret = -1; |
| 566 |
goto cleanup; |
goto cleanup; |
| 567 |
} |
} |
| 568 |
|
|
| 571 |
strftime(str_modify_dt, sizeof(str_modify_dt), "%Y-%m-%d %H:%M:%S (UTC %z)", &tm_modify_dt); |
strftime(str_modify_dt, sizeof(str_modify_dt), "%Y-%m-%d %H:%M:%S (UTC %z)", &tm_modify_dt); |
| 572 |
|
|
| 573 |
len_content += snprintf(content + len_content, LINE_BUFFER_LEN, |
len_content += snprintf(content + len_content, LINE_BUFFER_LEN, |
| 574 |
"\n--\n※ 作者已于 %s 修改本文※\n", |
"\n--\n鈥 浣滆呭凡浜 %s 淇敼鏈枃鈥籠n", |
| 575 |
str_modify_dt); |
str_modify_dt); |
| 576 |
|
|
| 577 |
|
// Calculate display length of content |
| 578 |
|
content_display_length = str_length(content, 1); |
| 579 |
|
|
| 580 |
db = db_open(); |
db = db_open(); |
| 581 |
if (db == NULL) |
if (db == NULL) |
| 582 |
{ |
{ |
| 644 |
|
|
| 645 |
// Update article |
// Update article |
| 646 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 647 |
"UPDATE bbs SET CID = %d, length = %ld WHERE AID = %d", |
"UPDATE bbs SET CID = %d, length = %d, reply_note = %d, excerption = 0 WHERE AID = %d", // Set excerption = 0 explictly in case of rare condition |
| 648 |
p_article_new->cid, len_content, p_article->aid); |
p_article_new->cid, content_display_length, reply_note, p_article->aid); |
| 649 |
|
|
| 650 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 651 |
{ |
{ |
| 682 |
goto cleanup; |
goto cleanup; |
| 683 |
} |
} |
| 684 |
|
|
| 685 |
|
mysql_close(db); |
| 686 |
|
db = NULL; |
| 687 |
|
|
| 688 |
clearscr(); |
clearscr(); |
| 689 |
moveto(1, 1); |
moveto(1, 1); |
| 690 |
prints("修改完成,新内容通常会在%d秒后可见", BBS_section_list_load_interval); |
prints("淇敼瀹屾垚锛屾柊鍐呭閫氬父浼氬湪%d绉掑悗鍙", BBS_section_list_load_interval); |
| 691 |
press_any_key(); |
press_any_key(); |
| 692 |
ret = 1; // Success |
ret = 1; // Success |
| 693 |
|
|
| 719 |
char *content = NULL; |
char *content = NULL; |
| 720 |
char *content_f = NULL; |
char *content_f = NULL; |
| 721 |
long len_content; |
long len_content; |
| 722 |
|
int content_display_length; |
| 723 |
char nickname_f[BBS_nickname_max_len * 2 + 1]; |
char nickname_f[BBS_nickname_max_len * 2 + 1]; |
| 724 |
int sign_id = 0; |
int sign_id = 0; |
| 725 |
|
int reply_note = 0; |
| 726 |
long len; |
long len; |
| 727 |
int ch; |
int ch; |
| 728 |
char *p, *q; |
char *p, *q; |
| 731 |
long quote_content_lines; |
long quote_content_lines; |
| 732 |
long i; |
long i; |
| 733 |
long ret = 0; |
long ret = 0; |
| 734 |
|
int topic_locked = 0; |
| 735 |
|
char msg[BBS_msg_max_len]; |
| 736 |
|
char msg_f[BBS_msg_max_len * 2 + 1]; |
| 737 |
|
int len_msg; |
| 738 |
|
|
| 739 |
if (p_section == NULL || p_article == NULL) |
if (p_section == NULL || p_article == NULL) |
| 740 |
{ |
{ |
| 745 |
{ |
{ |
| 746 |
clearscr(); |
clearscr(); |
| 747 |
moveto(1, 1); |
moveto(1, 1); |
| 748 |
prints("您没有权限在本版块发表文章\n"); |
prints("鎮ㄦ病鏈夋潈闄愬湪鏈増鍧楀彂琛ㄦ枃绔燶n"); |
|
press_any_key(); |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
|
if (p_article->lock) // Reply is not allowed |
|
|
{ |
|
|
clearscr(); |
|
|
moveto(1, 1); |
|
|
prints("该文章谢绝回复"); |
|
| 749 |
press_any_key(); |
press_any_key(); |
| 750 |
|
|
| 751 |
return 0; |
return 0; |
| 753 |
|
|
| 754 |
p_article_new->title[0] = '\0'; |
p_article_new->title[0] = '\0'; |
| 755 |
snprintf(title_input, sizeof(title_input), "Re: %s", p_article->title); |
snprintf(title_input, sizeof(title_input), "Re: %s", p_article->title); |
| 756 |
len = split_line(title_input, TITLE_INPUT_MAX_LEN, &eol, &display_len); |
len = split_line(title_input, TITLE_INPUT_MAX_LEN, &eol, &display_len, 0); |
| 757 |
title_input[len] = '\0'; |
title_input[len] = '\0'; |
| 758 |
|
|
| 759 |
db = db_open(); |
db = db_open(); |
| 760 |
if (db == NULL) |
if (db == NULL) |
| 761 |
{ |
{ |
| 762 |
log_error("db_open() error: %s\n", mysql_error(db)); |
log_error("db_open() error: %s\n", mysql_error(db)); |
| 763 |
return -1; |
ret = -1; |
| 764 |
|
goto cleanup; |
| 765 |
|
} |
| 766 |
|
|
| 767 |
|
snprintf(sql, sizeof(sql), |
| 768 |
|
"SELECT `lock` FROM bbs WHERE AID = %d", |
| 769 |
|
(p_article->tid == 0 ? p_article->aid : p_article->tid)); |
| 770 |
|
|
| 771 |
|
if (mysql_query(db, sql) != 0) |
| 772 |
|
{ |
| 773 |
|
log_error("Query article status error: %s\n", mysql_error(db)); |
| 774 |
|
ret = -1; |
| 775 |
|
goto cleanup; |
| 776 |
|
} |
| 777 |
|
if ((rs = mysql_store_result(db)) == NULL) |
| 778 |
|
{ |
| 779 |
|
log_error("Get article status data failed\n"); |
| 780 |
|
ret = -1; |
| 781 |
|
goto cleanup; |
| 782 |
|
} |
| 783 |
|
|
| 784 |
|
if ((row = mysql_fetch_row(rs))) |
| 785 |
|
{ |
| 786 |
|
if (atoi(row[0]) != 0) |
| 787 |
|
{ |
| 788 |
|
topic_locked = 1; |
| 789 |
|
} |
| 790 |
|
} |
| 791 |
|
mysql_free_result(rs); |
| 792 |
|
rs = NULL; |
| 793 |
|
|
| 794 |
|
if (topic_locked) // Reply is not allowed |
| 795 |
|
{ |
| 796 |
|
mysql_close(db); |
| 797 |
|
db = NULL; |
| 798 |
|
|
| 799 |
|
clearscr(); |
| 800 |
|
moveto(1, 1); |
| 801 |
|
prints("璇ヤ富棰樿阿缁濆洖澶"); |
| 802 |
|
press_any_key(); |
| 803 |
|
|
| 804 |
|
goto cleanup; |
| 805 |
} |
} |
| 806 |
|
|
| 807 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 813 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 814 |
{ |
{ |
| 815 |
log_error("Query article content error: %s\n", mysql_error(db)); |
log_error("Query article content error: %s\n", mysql_error(db)); |
| 816 |
return -2; |
ret = -1; |
| 817 |
|
goto cleanup; |
| 818 |
} |
} |
| 819 |
if ((rs = mysql_use_result(db)) == NULL) |
if ((rs = mysql_use_result(db)) == NULL) |
| 820 |
{ |
{ |
| 821 |
log_error("Get article content data failed\n"); |
log_error("Get article content data failed\n"); |
| 822 |
return -2; |
ret = -1; |
| 823 |
|
goto cleanup; |
| 824 |
} |
} |
| 825 |
|
|
| 826 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 842 |
} |
} |
| 843 |
|
|
| 844 |
// Apply LML render to content body |
// Apply LML render to content body |
| 845 |
len = lml_plain(row[1], content_f, ARTICLE_CONTENT_MAX_LEN); |
len = lml_render(row[1], content_f, ARTICLE_CONTENT_MAX_LEN, MAX_EDITOR_DATA_LINE_LENGTH - 3, 1); |
| 846 |
content_f[len] = '\0'; |
content_f[len] = '\0'; |
| 847 |
|
|
| 848 |
// Remove control sequence |
// Remove control sequence |
| 849 |
len = ctrl_seq_filter(content_f); |
len = str_filter(content_f, 0); |
| 850 |
|
|
| 851 |
len = snprintf(content, ARTICLE_CONTENT_MAX_LEN, |
len = snprintf(content, ARTICLE_CONTENT_MAX_LEN, |
| 852 |
"\n\n【 在 %s (%s) 的大作中提到: 】\n", |
"\n\n銆 鍦 %s (%s) 鐨勫ぇ浣滀腑鎻愬埌: 銆慭n", |
| 853 |
p_article->username, p_article->nickname); |
p_article->username, p_article->nickname); |
| 854 |
|
|
| 855 |
quote_content_lines = split_data_lines(content_f, ARTICLE_QUOTE_LINE_MAX_LEN, line_offsets, ARTICLE_QUOTE_MAX_LINES + 1); |
quote_content_lines = split_data_lines(content_f, MAX_EDITOR_DATA_LINE_LENGTH - 2, line_offsets, ARTICLE_QUOTE_MAX_LINES + 1, 0, NULL); |
| 856 |
for (i = 0; i < quote_content_lines; i++) |
for (i = 0; i < quote_content_lines; i++) |
| 857 |
{ |
{ |
| 858 |
memcpy(content + len, ": ", 2); // quote line prefix |
memcpy(content + len, ": ", 2); // quote line prefix |
| 859 |
len += 2; |
len += 2; |
| 860 |
memcpy(content + len, content_f + line_offsets[i], (size_t)(line_offsets[i + 1] - line_offsets[i])); |
memcpy(content + len, content_f + line_offsets[i], (size_t)(line_offsets[i + 1] - line_offsets[i])); |
| 861 |
len += (line_offsets[i + 1] - line_offsets[i]); |
len += (line_offsets[i + 1] - line_offsets[i]); |
| 862 |
|
if (content[len - 1] != '\n') // Appennd \n if not exist |
| 863 |
|
{ |
| 864 |
|
content[len] = '\n'; |
| 865 |
|
len++; |
| 866 |
|
} |
| 867 |
} |
} |
| 868 |
if (content[len - 1] != '\n') // Appennd \n if not exist |
if (content[len - 1] != '\n') // Appennd \n if not exist |
| 869 |
{ |
{ |
| 879 |
if (p_editor_data == NULL) |
if (p_editor_data == NULL) |
| 880 |
{ |
{ |
| 881 |
log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0])); |
log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0])); |
| 882 |
ret = -3; |
ret = -1; |
| 883 |
goto cleanup; |
goto cleanup; |
| 884 |
} |
} |
| 885 |
|
|
| 897 |
{ |
{ |
| 898 |
clearscr(); |
clearscr(); |
| 899 |
moveto(21, 1); |
moveto(21, 1); |
| 900 |
prints("回复文章于 %s[%s] 讨论区", p_section->stitle, p_section->sname); |
prints("鍥炲鏂囩珷浜 %s[%s] 璁ㄨ鍖猴紝鍥炲閫氱煡锛%s", p_section->stitle, p_section->sname, (reply_note ? "寮鍚" : "鍏抽棴")); |
| 901 |
moveto(22, 1); |
moveto(22, 1); |
| 902 |
prints("标题: %s", (p_article_new->title[0] == '\0' ? "[无]" : p_article_new->title)); |
prints("鏍囬: %s", (p_article_new->title[0] == '\0' ? "[鏃燷" : p_article_new->title)); |
| 903 |
moveto(23, 1); |
moveto(23, 1); |
| 904 |
prints("使用第 [1;32m%d[m 个签名", sign_id); |
prints("浣跨敤绗 [1;32m%d[m 涓鍚", sign_id); |
| 905 |
|
|
| 906 |
if (toupper(ch) != 'T') |
if (toupper(ch) != 'T') |
| 907 |
{ |
{ |
| 908 |
prints(" 按[1;32m0[m~[1;32m3[m选签名档(0表示不使用)"); |
prints(" 鎸[1;32m0[m~[1;32m3[m閫夌鍚嶆。(0琛ㄧず涓嶄娇鐢)"); |
| 909 |
|
|
| 910 |
moveto(24, 1); |
moveto(24, 1); |
| 911 |
prints("[1;32mT[m改标题, [1;32mC[m取消, [1;32mEnter[m继续: "); |
prints("[1;32mT[m鏀规爣棰, [1;32mC[m鍙栨秷, [1;32mN[m%s, [1;32mEnter[m缁х画: ", |
| 912 |
|
(reply_note ? "鍏抽棴鍥炲閫氱煡" : "寮鍚洖澶嶉氱煡")); |
| 913 |
iflush(); |
iflush(); |
| 914 |
ch = 0; |
ch = 0; |
| 915 |
} |
} |
| 918 |
{ |
{ |
| 919 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 920 |
{ |
{ |
| 921 |
|
case KEY_NULL: |
| 922 |
|
case KEY_TIMEOUT: |
| 923 |
|
goto cleanup; |
| 924 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 925 |
break; |
break; |
| 926 |
case 'T': |
case 'T': |
| 927 |
moveto(24, 1); |
len = get_data(24, 1, "鏍囬: ", title_input, sizeof(title_input), TITLE_INPUT_MAX_LEN); |
|
clrtoeol(); |
|
|
len = get_data(24, 1, "标题: ", title_input, TITLE_INPUT_MAX_LEN, 1); |
|
| 928 |
for (p = title_input; *p == ' '; p++) |
for (p = title_input; *p == ' '; p++) |
| 929 |
; |
; |
| 930 |
for (q = title_input + len; q > p && *(q - 1) == ' '; q--) |
for (q = title_input + len; q > p && *(q - 1) == ' '; q--) |
| 941 |
case 'C': |
case 'C': |
| 942 |
clearscr(); |
clearscr(); |
| 943 |
moveto(1, 1); |
moveto(1, 1); |
| 944 |
prints("取消..."); |
prints("鍙栨秷..."); |
| 945 |
press_any_key(); |
press_any_key(); |
| 946 |
goto cleanup; |
goto cleanup; |
| 947 |
|
case 'N': |
| 948 |
|
reply_note = (reply_note ? 0 : 1); |
| 949 |
|
break; |
| 950 |
case '0': |
case '0': |
| 951 |
case '1': |
case '1': |
| 952 |
case '2': |
case '2': |
| 971 |
|
|
| 972 |
clearscr(); |
clearscr(); |
| 973 |
moveto(1, 1); |
moveto(1, 1); |
| 974 |
prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: "); |
prints("(S)鍙戦, (C)鍙栨秷, (T)鏇存敼鏍囬 or (E)鍐嶇紪杈? [S]: "); |
| 975 |
iflush(); |
iflush(); |
| 976 |
|
|
| 977 |
for (ch = 0; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) |
for (ch = 0; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) |
| 978 |
{ |
{ |
| 979 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 980 |
{ |
{ |
| 981 |
|
case KEY_NULL: |
| 982 |
|
case KEY_TIMEOUT: |
| 983 |
|
goto cleanup; |
| 984 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 985 |
case 'S': |
case 'S': |
| 986 |
break; |
break; |
| 987 |
case 'C': |
case 'C': |
| 988 |
clearscr(); |
clearscr(); |
| 989 |
moveto(1, 1); |
moveto(1, 1); |
| 990 |
prints("取消..."); |
prints("鍙栨秷..."); |
| 991 |
press_any_key(); |
press_any_key(); |
| 992 |
goto cleanup; |
goto cleanup; |
| 993 |
case 'T': |
case 'T': |
| 1008 |
} |
} |
| 1009 |
} |
} |
| 1010 |
|
|
| 1011 |
|
if (SYS_server_exit) // Do not save data on shutdown |
| 1012 |
|
{ |
| 1013 |
|
goto cleanup; |
| 1014 |
|
} |
| 1015 |
|
|
| 1016 |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
content = malloc(ARTICLE_CONTENT_MAX_LEN); |
| 1017 |
if (content == NULL) |
if (content == NULL) |
| 1018 |
{ |
{ |
| 1025 |
if (len_content < 0) |
if (len_content < 0) |
| 1026 |
{ |
{ |
| 1027 |
log_error("editor_data_save() error\n"); |
log_error("editor_data_save() error\n"); |
| 1028 |
ret = -2; |
ret = -1; |
| 1029 |
goto cleanup; |
goto cleanup; |
| 1030 |
} |
} |
| 1031 |
|
|
| 1066 |
rs = NULL; |
rs = NULL; |
| 1067 |
} |
} |
| 1068 |
|
|
| 1069 |
|
// Calculate display length of content |
| 1070 |
|
content_display_length = str_length(content, 1); |
| 1071 |
|
|
| 1072 |
// Begin transaction |
// Begin transaction |
| 1073 |
if (mysql_query(db, "SET autocommit=0") != 0) |
if (mysql_query(db, "SET autocommit=0") != 0) |
| 1074 |
{ |
{ |
| 1132 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 1133 |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
| 1134 |
"sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) " |
"sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) " |
| 1135 |
"VALUES(%d, %d, %d, '%s', '%s', '%s', %d, 0, NOW(), '%s', 1, %d, NOW(), 1, %ld)", |
"VALUES(%d, %d, %d, '%s', '%s', '%s', %d, 0, NOW(), '%s', %d, %d, NOW(), 1, %d)", |
| 1136 |
p_section->sid, (p_article->tid == 0 ? p_article->aid : p_article->tid), |
p_section->sid, (p_article->tid == 0 ? p_article->aid : p_article->tid), |
| 1137 |
BBS_priv.uid, BBS_username, nickname_f, title_f, |
BBS_priv.uid, BBS_username, nickname_f, title_f, |
| 1138 |
p_article_new->cid, hostaddr_client, BBS_user_exp, len_content); |
p_article_new->cid, hostaddr_client, |
| 1139 |
|
reply_note, BBS_user_exp, content_display_length); |
| 1140 |
|
|
| 1141 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 1142 |
{ |
{ |
| 1174 |
goto cleanup; |
goto cleanup; |
| 1175 |
} |
} |
| 1176 |
|
|
| 1177 |
|
// Notify the authors of the topic / article which is replyed. |
| 1178 |
|
snprintf(sql, sizeof(sql), |
| 1179 |
|
"SELECT DISTINCT UID FROM bbs WHERE (AID = %d OR AID = %d) " |
| 1180 |
|
"AND visible AND reply_note AND UID <> %d", |
| 1181 |
|
p_article->tid, p_article->aid, BBS_priv.uid); |
| 1182 |
|
|
| 1183 |
|
if (mysql_query(db, sql) != 0) |
| 1184 |
|
{ |
| 1185 |
|
log_error("Read reply info error: %s\n", mysql_error(db)); |
| 1186 |
|
ret = -1; |
| 1187 |
|
goto cleanup; |
| 1188 |
|
} |
| 1189 |
|
if ((rs = mysql_store_result(db)) == NULL) |
| 1190 |
|
{ |
| 1191 |
|
log_error("Get reply info failed\n"); |
| 1192 |
|
ret = -1; |
| 1193 |
|
goto cleanup; |
| 1194 |
|
} |
| 1195 |
|
|
| 1196 |
|
while ((row = mysql_fetch_row(rs))) |
| 1197 |
|
{ |
| 1198 |
|
// Send notification message |
| 1199 |
|
len_msg = snprintf(msg, BBS_msg_max_len, |
| 1200 |
|
"鏈変汉鍥炲浜嗘偍鎵鍙戣〃/鍥炲鐨勬枃绔狅紝蹇潵" |
| 1201 |
|
"[article %d]鐪嬬湅[/article]銆%s銆嬪惂锛乗n", |
| 1202 |
|
p_article_new->aid, title_f); |
| 1203 |
|
|
| 1204 |
|
mysql_real_escape_string(db, msg_f, msg, (unsigned long)len_msg); |
| 1205 |
|
|
| 1206 |
|
snprintf(sql, sizeof(sql), |
| 1207 |
|
"INSERT INTO bbs_msg(fromUID, toUID, content, send_dt, send_ip) " |
| 1208 |
|
"VALUES(%d, %d, '%s', NOW(), '%s')", |
| 1209 |
|
BBS_sys_id, atoi(row[0]), msg_f, hostaddr_client); |
| 1210 |
|
|
| 1211 |
|
if (mysql_query(db, sql) != 0) |
| 1212 |
|
{ |
| 1213 |
|
log_error("Insert msg error: %s\n", mysql_error(db)); |
| 1214 |
|
ret = -1; |
| 1215 |
|
goto cleanup; |
| 1216 |
|
} |
| 1217 |
|
} |
| 1218 |
|
mysql_free_result(rs); |
| 1219 |
|
rs = NULL; |
| 1220 |
|
|
| 1221 |
// Add exp |
// Add exp |
| 1222 |
if (checkpriv(&BBS_priv, p_section->sid, S_GETEXP)) // Except in test section |
if (checkpriv(&BBS_priv, p_section->sid, S_GETEXP)) // Except in test section |
| 1223 |
{ |
{ |
| 1254 |
goto cleanup; |
goto cleanup; |
| 1255 |
} |
} |
| 1256 |
|
|
| 1257 |
|
mysql_close(db); |
| 1258 |
|
db = NULL; |
| 1259 |
|
|
| 1260 |
clearscr(); |
clearscr(); |
| 1261 |
moveto(1, 1); |
moveto(1, 1); |
| 1262 |
prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval); |
prints("鍙戦佸畬鎴愶紝鏂版枃绔犻氬父浼氬湪%d绉掑悗鍙", BBS_section_list_load_interval); |
| 1263 |
press_any_key(); |
press_any_key(); |
| 1264 |
ret = 1; // Success |
ret = 1; // Success |
| 1265 |
|
|