| 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 |
|
|
| 9 |
#include "article_cache.h" |
#include "article_cache.h" |
| 10 |
#include "article_post.h" |
#include "article_post.h" |
| 11 |
#include "bbs.h" |
#include "bbs.h" |
| 12 |
|
#include "bwf.h" |
| 13 |
#include "database.h" |
#include "database.h" |
| 14 |
#include "editor.h" |
#include "editor.h" |
| 15 |
#include "io.h" |
#include "io.h" |
| 22 |
#include <stdlib.h> |
#include <stdlib.h> |
| 23 |
#include <time.h> |
#include <time.h> |
| 24 |
|
|
| 25 |
#define TITLE_INPUT_MAX_LEN 72 |
enum _article_post_constant_t |
| 26 |
#define ARTICLE_CONTENT_MAX_LEN 1024 * 1024 * 4 // 4MB |
{ |
| 27 |
#define ARTICLE_QUOTE_MAX_LINES 20 |
TITLE_INPUT_MAX_LEN = 72, |
| 28 |
#define ARTICLE_QUOTE_LINE_MAX_LEN 76 |
ARTICLE_QUOTE_DEFAULT_LINES = 20, |
| 29 |
|
MODIFY_DT_MAX_LEN = 50, |
| 30 |
#define MODIFY_DT_MAX_LEN 50 |
}; |
| 31 |
|
|
| 32 |
int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) |
int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) |
| 33 |
{ |
{ |
| 45 |
int content_display_length; |
int content_display_length; |
| 46 |
char nickname_f[BBS_nickname_max_len * 2 + 1]; |
char nickname_f[BBS_nickname_max_len * 2 + 1]; |
| 47 |
int sign_id = 0; |
int sign_id = 0; |
| 48 |
|
int reply_note = 1; |
| 49 |
long len; |
long len; |
| 50 |
int ch; |
int ch; |
| 51 |
char *p, *q; |
char *p, *q; |
| 83 |
{ |
{ |
| 84 |
clearscr(); |
clearscr(); |
| 85 |
moveto(21, 1); |
moveto(21, 1); |
| 86 |
prints("发表文章于 %s[%s] 讨论区,类型: %s", p_section->stitle, p_section->sname, (p_article_new->transship ? "转载" : "原创")); |
prints("发表文章于 %s[%s] 讨论区,类型: %s,回复通知: %s", |
| 87 |
|
p_section->stitle, p_section->sname, |
| 88 |
|
(p_article_new->transship ? "转载" : "原创"), |
| 89 |
|
(reply_note ? "开启" : "关闭")); |
| 90 |
moveto(22, 1); |
moveto(22, 1); |
| 91 |
prints("标题: %s", (p_article_new->title[0] == '\0' ? "[无]" : p_article_new->title)); |
prints("标题: %s", (p_article_new->title[0] == '\0' ? "[无]" : p_article_new->title)); |
| 92 |
moveto(23, 1); |
moveto(23, 1); |
| 97 |
prints(" 按[1;32m0[m~[1;32m3[m选签名档(0表示不使用)"); |
prints(" 按[1;32m0[m~[1;32m3[m选签名档(0表示不使用)"); |
| 98 |
|
|
| 99 |
moveto(24, 1); |
moveto(24, 1); |
| 100 |
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继续: ", |
| 101 |
|
(p_article_new->transship ? "原创" : "转载"), |
| 102 |
|
(reply_note ? "关闭回复通知" : "开启回复通知")); |
| 103 |
iflush(); |
iflush(); |
| 104 |
ch = 0; |
ch = 0; |
| 105 |
} |
} |
| 106 |
|
|
| 107 |
for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) |
while (!SYS_server_exit) |
| 108 |
{ |
{ |
| 109 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 110 |
{ |
{ |
| 112 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 113 |
goto cleanup; |
goto cleanup; |
| 114 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 115 |
break; |
break; |
| 116 |
case 'T': |
case 'T': |
| 117 |
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, sizeof(title_input), TITLE_INPUT_MAX_LEN, DOECHO); |
|
| 118 |
for (p = title_input; *p == ' '; p++) |
for (p = title_input; *p == ' '; p++) |
| 119 |
; |
; |
| 120 |
for (q = title_input + len; q > p && *(q - 1) == ' '; q--) |
for (q = title_input + len; q > p && *(q - 1) == ' '; q--) |
| 123 |
len = q - p; |
len = q - p; |
| 124 |
if (*p != '\0') |
if (*p != '\0') |
| 125 |
{ |
{ |
| 126 |
|
if ((ret = check_badwords(p, '*')) < 0) |
| 127 |
|
{ |
| 128 |
|
log_error("check_badwords(title) error\n"); |
| 129 |
|
} |
| 130 |
|
else if (ret > 0) |
| 131 |
|
{ |
| 132 |
|
memcpy(title_input, p, (size_t)len + 1); |
| 133 |
|
continue; |
| 134 |
|
} |
| 135 |
memcpy(p_article_new->title, p, (size_t)len + 1); |
memcpy(p_article_new->title, p, (size_t)len + 1); |
| 136 |
memcpy(title_input, p_article_new->title, (size_t)len + 1); |
memcpy(title_input, p_article_new->title, (size_t)len + 1); |
| 137 |
} |
} |
| 143 |
prints("取消..."); |
prints("取消..."); |
| 144 |
press_any_key(); |
press_any_key(); |
| 145 |
goto cleanup; |
goto cleanup; |
|
case 'Y': |
|
|
p_article_new->transship = 0; |
|
|
break; |
|
| 146 |
case 'Z': |
case 'Z': |
| 147 |
p_article_new->transship = 1; |
p_article_new->transship = (p_article_new->transship ? 0 : 1); |
| 148 |
|
break; |
| 149 |
|
case 'N': |
| 150 |
|
reply_note = (reply_note ? 0 : 1); |
| 151 |
break; |
break; |
| 152 |
case '0': |
case '0': |
| 153 |
case '1': |
case '1': |
| 156 |
sign_id = ch - '0'; |
sign_id = ch - '0'; |
| 157 |
break; |
break; |
| 158 |
default: // Invalid selection |
default: // Invalid selection |
| 159 |
|
ch = igetch_t(BBS_max_user_idle_time); |
| 160 |
continue; |
continue; |
| 161 |
} |
} |
| 162 |
|
|
| 177 |
prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: "); |
prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: "); |
| 178 |
iflush(); |
iflush(); |
| 179 |
|
|
| 180 |
for (ch = 0; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) |
for (ch = 0; !SYS_server_exit; ch = igetch_t(BBS_max_user_idle_time)) |
| 181 |
{ |
{ |
| 182 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 183 |
{ |
{ |
| 185 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 186 |
goto cleanup; |
goto cleanup; |
| 187 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 188 |
case 'S': |
case 'S': |
| 189 |
break; |
break; |
| 190 |
case 'C': |
case 'C': |
| 232 |
goto cleanup; |
goto cleanup; |
| 233 |
} |
} |
| 234 |
|
|
| 235 |
|
if (check_badwords(content, '*') < 0) |
| 236 |
|
{ |
| 237 |
|
log_error("check_badwords(content) error\n"); |
| 238 |
|
ret = -1; |
| 239 |
|
goto cleanup; |
| 240 |
|
} |
| 241 |
|
|
| 242 |
db = db_open(); |
db = db_open(); |
| 243 |
if (db == NULL) |
if (db == NULL) |
| 244 |
{ |
{ |
| 342 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 343 |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
| 344 |
"sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) " |
"sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) " |
| 345 |
"VALUES(%d, 0, %d, '%s', '%s', '%s', %d, %d, NOW(), '%s', 1, %d, NOW(), 1, %d)", |
"VALUES(%d, 0, %d, '%s', '%s', '%s', %d, %d, NOW(), '%s', %d, %d, NOW(), 1, %d)", |
| 346 |
p_section->sid, BBS_priv.uid, BBS_username, nickname_f, title_f, |
p_section->sid, BBS_priv.uid, BBS_username, nickname_f, title_f, |
| 347 |
p_article_new->cid, p_article_new->transship, hostaddr_client, BBS_user_exp, content_display_length); |
p_article_new->cid, p_article_new->transship, hostaddr_client, |
| 348 |
|
reply_note, BBS_user_exp, content_display_length); |
| 349 |
|
|
| 350 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 351 |
{ |
{ |
| 437 |
char *content_f = NULL; |
char *content_f = NULL; |
| 438 |
long len_content; |
long len_content; |
| 439 |
int content_display_length; |
int content_display_length; |
| 440 |
|
int reply_note = 1; |
| 441 |
int ch; |
int ch; |
| 442 |
long ret = 0; |
long ret = 0; |
| 443 |
time_t now; |
time_t now; |
| 470 |
} |
} |
| 471 |
|
|
| 472 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 473 |
"SELECT bbs_content.CID, bbs_content.content " |
"SELECT bbs_content.CID, bbs_content.content, reply_note " |
| 474 |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
"FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID " |
| 475 |
"WHERE bbs.AID = %d", |
"WHERE bbs.AID = %d", |
| 476 |
p_article->aid); |
p_article->aid); |
| 514 |
|
|
| 515 |
free(content); |
free(content); |
| 516 |
content = NULL; |
content = NULL; |
| 517 |
|
|
| 518 |
|
reply_note = atoi(row[2]); |
| 519 |
} |
} |
| 520 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 521 |
rs = NULL; |
rs = NULL; |
| 527 |
{ |
{ |
| 528 |
editor_display(p_editor_data); |
editor_display(p_editor_data); |
| 529 |
|
|
| 530 |
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)) |
|
| 531 |
{ |
{ |
| 532 |
|
clearscr(); |
| 533 |
|
moveto(1, 1); |
| 534 |
|
prints("(S)保存, (C)取消, (N)%s回复通知 or (E)再编辑? [S]: ", |
| 535 |
|
(reply_note ? "关闭" : "开启")); |
| 536 |
|
iflush(); |
| 537 |
|
|
| 538 |
|
ch = igetch_t(BBS_max_user_idle_time); |
| 539 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 540 |
{ |
{ |
| 541 |
case KEY_NULL: |
case KEY_NULL: |
| 542 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 543 |
goto cleanup; |
goto cleanup; |
| 544 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 545 |
case 'S': |
case 'S': |
| 546 |
break; |
break; |
| 547 |
case 'C': |
case 'C': |
| 550 |
prints("取消..."); |
prints("取消..."); |
| 551 |
press_any_key(); |
press_any_key(); |
| 552 |
goto cleanup; |
goto cleanup; |
| 553 |
|
case 'N': |
| 554 |
|
reply_note = (reply_note ? 0 : 1); |
| 555 |
|
continue; |
| 556 |
case 'E': |
case 'E': |
| 557 |
break; |
break; |
| 558 |
default: // Invalid selection |
default: // Invalid selection |
| 585 |
goto cleanup; |
goto cleanup; |
| 586 |
} |
} |
| 587 |
|
|
| 588 |
|
if (check_badwords(content, '*') < 0) |
| 589 |
|
{ |
| 590 |
|
log_error("check_badwords(content) error\n"); |
| 591 |
|
ret = -1; |
| 592 |
|
goto cleanup; |
| 593 |
|
} |
| 594 |
|
|
| 595 |
time(&now); |
time(&now); |
| 596 |
localtime_r(&now, &tm_modify_dt); |
localtime_r(&now, &tm_modify_dt); |
| 597 |
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); |
| 670 |
|
|
| 671 |
// Update article |
// Update article |
| 672 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 673 |
"UPDATE bbs SET CID = %d, length = %d, excerption = 0 WHERE AID = %d", // Set excerption = 0 explictly in case of rare condition |
"UPDATE bbs SET CID = %d, length = %d, reply_note = %d, excerption = 0 WHERE AID = %d", // Set excerption = 0 explictly in case of rare condition |
| 674 |
p_article_new->cid, content_display_length, p_article->aid); |
p_article_new->cid, content_display_length, reply_note, p_article->aid); |
| 675 |
|
|
| 676 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 677 |
{ |
{ |
| 736 |
MYSQL *db = NULL; |
MYSQL *db = NULL; |
| 737 |
MYSQL_RES *rs = NULL; |
MYSQL_RES *rs = NULL; |
| 738 |
MYSQL_ROW row; |
MYSQL_ROW row; |
| 739 |
long line_offsets[ARTICLE_QUOTE_MAX_LINES + 1]; |
long line_offsets[MAX_EDITOR_DATA_LINES + 1]; |
| 740 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 741 |
char *sql_content = NULL; |
char *sql_content = NULL; |
| 742 |
EDITOR_DATA *p_editor_data = NULL; |
EDITOR_DATA *p_editor_data = NULL; |
| 748 |
int content_display_length; |
int content_display_length; |
| 749 |
char nickname_f[BBS_nickname_max_len * 2 + 1]; |
char nickname_f[BBS_nickname_max_len * 2 + 1]; |
| 750 |
int sign_id = 0; |
int sign_id = 0; |
| 751 |
|
int reply_note = 0; |
| 752 |
|
int full_quote = 0; |
| 753 |
long len; |
long len; |
| 754 |
int ch; |
int ch; |
| 755 |
char *p, *q; |
char *p, *q; |
| 759 |
long i; |
long i; |
| 760 |
long ret = 0; |
long ret = 0; |
| 761 |
int topic_locked = 0; |
int topic_locked = 0; |
| 762 |
|
char msg[BBS_msg_max_len]; |
| 763 |
|
char msg_f[BBS_msg_max_len * 2 + 1]; |
| 764 |
|
int len_msg; |
| 765 |
|
|
| 766 |
if (p_section == NULL || p_article == NULL) |
if (p_section == NULL || p_article == NULL) |
| 767 |
{ |
{ |
| 869 |
} |
} |
| 870 |
|
|
| 871 |
// Apply LML render to content body |
// Apply LML render to content body |
| 872 |
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); |
| 873 |
content_f[len] = '\0'; |
content_f[len] = '\0'; |
| 874 |
|
|
| 875 |
// Remove control sequence |
// Remove control sequence |
| 876 |
len = str_filter(content_f, 0); |
len = str_filter(content_f, 0); |
|
|
|
|
len = snprintf(content, ARTICLE_CONTENT_MAX_LEN, |
|
|
"\n\n【 在 %s (%s) 的大作中提到: 】\n", |
|
|
p_article->username, p_article->nickname); |
|
|
|
|
|
quote_content_lines = split_data_lines(content_f, ARTICLE_QUOTE_LINE_MAX_LEN, line_offsets, ARTICLE_QUOTE_MAX_LINES + 1, 0, NULL); |
|
|
for (i = 0; i < quote_content_lines; i++) |
|
|
{ |
|
|
memcpy(content + len, ": ", 2); // quote line prefix |
|
|
len += 2; |
|
|
memcpy(content + len, content_f + line_offsets[i], (size_t)(line_offsets[i + 1] - line_offsets[i])); |
|
|
len += (line_offsets[i + 1] - line_offsets[i]); |
|
|
if (content[len - 1] != '\n') // Appennd \n if not exist |
|
|
{ |
|
|
content[len] = '\n'; |
|
|
len++; |
|
|
} |
|
|
} |
|
|
if (content[len - 1] != '\n') // Appennd \n if not exist |
|
|
{ |
|
|
content[len] = '\n'; |
|
|
len++; |
|
|
} |
|
|
content[len] = '\0'; |
|
|
|
|
|
free(content_f); |
|
|
content_f = NULL; |
|
|
|
|
|
p_editor_data = editor_data_load(content); |
|
|
if (p_editor_data == NULL) |
|
|
{ |
|
|
log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0])); |
|
|
ret = -1; |
|
|
goto cleanup; |
|
|
} |
|
|
|
|
|
free(content); |
|
|
content = NULL; |
|
| 877 |
} |
} |
| 878 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 879 |
rs = NULL; |
rs = NULL; |
| 886 |
{ |
{ |
| 887 |
clearscr(); |
clearscr(); |
| 888 |
moveto(21, 1); |
moveto(21, 1); |
| 889 |
prints("回复文章于 %s[%s] 讨论区", p_section->stitle, p_section->sname); |
prints("回复文章于 %s[%s] 讨论区, 回复通知: %s, 引用模式: %s", |
| 890 |
|
p_section->stitle, p_section->sname, |
| 891 |
|
(reply_note ? "开启" : "关闭"), |
| 892 |
|
(full_quote ? "完整" : "精简")); |
| 893 |
moveto(22, 1); |
moveto(22, 1); |
| 894 |
prints("标题: %s", (p_article_new->title[0] == '\0' ? "[无]" : p_article_new->title)); |
prints("标题: %s", (p_article_new->title[0] == '\0' ? "[无]" : p_article_new->title)); |
| 895 |
moveto(23, 1); |
moveto(23, 1); |
| 900 |
prints(" 按[1;32m0[m~[1;32m3[m选签名档(0表示不使用)"); |
prints(" 按[1;32m0[m~[1;32m3[m选签名档(0表示不使用)"); |
| 901 |
|
|
| 902 |
moveto(24, 1); |
moveto(24, 1); |
| 903 |
prints("[1;32mT[m改标题, [1;32mC[m取消, [1;32mEnter[m继续: "); |
prints("[1;32mT[m改标题, [1;32mC[m取消, [1;32mN[m%s, [1;32mQ[m%s, [1;32mEnter[m继续: ", |
| 904 |
|
(reply_note ? "关闭回复通知" : "开启回复通知"), (full_quote ? "精简引用" : "完整引用")); |
| 905 |
iflush(); |
iflush(); |
| 906 |
ch = 0; |
ch = 0; |
| 907 |
} |
} |
| 908 |
|
|
| 909 |
for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) |
while (!SYS_server_exit) |
| 910 |
{ |
{ |
| 911 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 912 |
{ |
{ |
| 914 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 915 |
goto cleanup; |
goto cleanup; |
| 916 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 917 |
break; |
break; |
| 918 |
case 'T': |
case 'T': |
| 919 |
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, sizeof(title_input), TITLE_INPUT_MAX_LEN, DOECHO); |
|
| 920 |
for (p = title_input; *p == ' '; p++) |
for (p = title_input; *p == ' '; p++) |
| 921 |
; |
; |
| 922 |
for (q = title_input + len; q > p && *(q - 1) == ' '; q--) |
for (q = title_input + len; q > p && *(q - 1) == ' '; q--) |
| 925 |
len = q - p; |
len = q - p; |
| 926 |
if (*p != '\0') |
if (*p != '\0') |
| 927 |
{ |
{ |
| 928 |
|
if ((ret = check_badwords(p, '*')) < 0) |
| 929 |
|
{ |
| 930 |
|
log_error("check_badwords(title) error\n"); |
| 931 |
|
} |
| 932 |
|
else if (ret > 0) |
| 933 |
|
{ |
| 934 |
|
memcpy(title_input, p, (size_t)len + 1); |
| 935 |
|
continue; |
| 936 |
|
} |
| 937 |
memcpy(p_article_new->title, p, (size_t)len + 1); |
memcpy(p_article_new->title, p, (size_t)len + 1); |
| 938 |
memcpy(title_input, p_article_new->title, (size_t)len + 1); |
memcpy(title_input, p_article_new->title, (size_t)len + 1); |
| 939 |
} |
} |
| 945 |
prints("取消..."); |
prints("取消..."); |
| 946 |
press_any_key(); |
press_any_key(); |
| 947 |
goto cleanup; |
goto cleanup; |
| 948 |
|
case 'N': |
| 949 |
|
reply_note = (reply_note ? 0 : 1); |
| 950 |
|
break; |
| 951 |
|
case 'Q': |
| 952 |
|
full_quote = (full_quote ? 0 : 1); |
| 953 |
|
break; |
| 954 |
case '0': |
case '0': |
| 955 |
case '1': |
case '1': |
| 956 |
case '2': |
case '2': |
| 958 |
sign_id = ch - '0'; |
sign_id = ch - '0'; |
| 959 |
break; |
break; |
| 960 |
default: // Invalid selection |
default: // Invalid selection |
| 961 |
|
ch = igetch_t(BBS_max_user_idle_time); |
| 962 |
continue; |
continue; |
| 963 |
} |
} |
| 964 |
|
|
| 970 |
continue; |
continue; |
| 971 |
} |
} |
| 972 |
|
|
| 973 |
|
len = snprintf(content, ARTICLE_CONTENT_MAX_LEN, |
| 974 |
|
"\n\n【 在 %s (%s) 的大作中提到: 】\n", |
| 975 |
|
p_article->username, p_article->nickname); |
| 976 |
|
|
| 977 |
|
quote_content_lines = split_data_lines(content_f, |
| 978 |
|
MAX_EDITOR_DATA_LINE_LENGTH - 2, line_offsets, |
| 979 |
|
(full_quote ? MAX_EDITOR_DATA_LINES : ARTICLE_QUOTE_DEFAULT_LINES) + 1, |
| 980 |
|
0, NULL); |
| 981 |
|
for (i = 0; i < quote_content_lines; i++) |
| 982 |
|
{ |
| 983 |
|
memcpy(content + len, ": ", 2); // quote line prefix |
| 984 |
|
len += 2; |
| 985 |
|
memcpy(content + len, content_f + line_offsets[i], (size_t)(line_offsets[i + 1] - line_offsets[i])); |
| 986 |
|
len += (line_offsets[i + 1] - line_offsets[i]); |
| 987 |
|
if (content[len - 1] != '\n') // Appennd \n if not exist |
| 988 |
|
{ |
| 989 |
|
content[len] = '\n'; |
| 990 |
|
len++; |
| 991 |
|
} |
| 992 |
|
} |
| 993 |
|
if (content[len - 1] != '\n') // Appennd \n if not exist |
| 994 |
|
{ |
| 995 |
|
content[len] = '\n'; |
| 996 |
|
len++; |
| 997 |
|
} |
| 998 |
|
content[len] = '\0'; |
| 999 |
|
|
| 1000 |
|
free(content_f); |
| 1001 |
|
content_f = NULL; |
| 1002 |
|
|
| 1003 |
|
p_editor_data = editor_data_load(content); |
| 1004 |
|
if (p_editor_data == NULL) |
| 1005 |
|
{ |
| 1006 |
|
log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0])); |
| 1007 |
|
ret = -1; |
| 1008 |
|
goto cleanup; |
| 1009 |
|
} |
| 1010 |
|
|
| 1011 |
|
free(content); |
| 1012 |
|
content = NULL; |
| 1013 |
|
|
| 1014 |
for (ch = 'E'; !SYS_server_exit && toupper(ch) == 'E';) |
for (ch = 'E'; !SYS_server_exit && toupper(ch) == 'E';) |
| 1015 |
{ |
{ |
| 1016 |
editor_display(p_editor_data); |
editor_display(p_editor_data); |
| 1020 |
prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: "); |
prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: "); |
| 1021 |
iflush(); |
iflush(); |
| 1022 |
|
|
| 1023 |
for (ch = 0; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME)) |
for (ch = 0; !SYS_server_exit; ch = igetch_t(BBS_max_user_idle_time)) |
| 1024 |
{ |
{ |
| 1025 |
switch (toupper(ch)) |
switch (toupper(ch)) |
| 1026 |
{ |
{ |
| 1028 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 1029 |
goto cleanup; |
goto cleanup; |
| 1030 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 1031 |
case 'S': |
case 'S': |
| 1032 |
break; |
break; |
| 1033 |
case 'C': |
case 'C': |
| 1075 |
goto cleanup; |
goto cleanup; |
| 1076 |
} |
} |
| 1077 |
|
|
| 1078 |
|
if (check_badwords(content, '*') < 0) |
| 1079 |
|
{ |
| 1080 |
|
log_error("check_badwords(content) error\n"); |
| 1081 |
|
ret = -1; |
| 1082 |
|
goto cleanup; |
| 1083 |
|
} |
| 1084 |
|
|
| 1085 |
db = db_open(); |
db = db_open(); |
| 1086 |
if (db == NULL) |
if (db == NULL) |
| 1087 |
{ |
{ |
| 1185 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 1186 |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
"INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, " |
| 1187 |
"sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) " |
"sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) " |
| 1188 |
"VALUES(%d, %d, %d, '%s', '%s', '%s', %d, 0, NOW(), '%s', 1, %d, NOW(), 1, %d)", |
"VALUES(%d, %d, %d, '%s', '%s', '%s', %d, 0, NOW(), '%s', %d, %d, NOW(), 1, %d)", |
| 1189 |
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), |
| 1190 |
BBS_priv.uid, BBS_username, nickname_f, title_f, |
BBS_priv.uid, BBS_username, nickname_f, title_f, |
| 1191 |
p_article_new->cid, hostaddr_client, BBS_user_exp, content_display_length); |
p_article_new->cid, hostaddr_client, |
| 1192 |
|
reply_note, BBS_user_exp, content_display_length); |
| 1193 |
|
|
| 1194 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 1195 |
{ |
{ |
| 1227 |
goto cleanup; |
goto cleanup; |
| 1228 |
} |
} |
| 1229 |
|
|
| 1230 |
|
// Notify the authors of the topic / article which is replyed. |
| 1231 |
|
snprintf(sql, sizeof(sql), |
| 1232 |
|
"SELECT DISTINCT UID FROM bbs WHERE (AID = %d OR AID = %d) " |
| 1233 |
|
"AND visible AND reply_note AND UID <> %d", |
| 1234 |
|
p_article->tid, p_article->aid, BBS_priv.uid); |
| 1235 |
|
|
| 1236 |
|
if (mysql_query(db, sql) != 0) |
| 1237 |
|
{ |
| 1238 |
|
log_error("Read reply info error: %s\n", mysql_error(db)); |
| 1239 |
|
ret = -1; |
| 1240 |
|
goto cleanup; |
| 1241 |
|
} |
| 1242 |
|
if ((rs = mysql_store_result(db)) == NULL) |
| 1243 |
|
{ |
| 1244 |
|
log_error("Get reply info failed\n"); |
| 1245 |
|
ret = -1; |
| 1246 |
|
goto cleanup; |
| 1247 |
|
} |
| 1248 |
|
|
| 1249 |
|
while ((row = mysql_fetch_row(rs))) |
| 1250 |
|
{ |
| 1251 |
|
// Send notification message |
| 1252 |
|
len_msg = snprintf(msg, BBS_msg_max_len, |
| 1253 |
|
"有人回复了您所发表/回复的文章,快来" |
| 1254 |
|
"[article %d]看看[/article]《%s》吧!\n", |
| 1255 |
|
p_article_new->aid, title_f); |
| 1256 |
|
|
| 1257 |
|
mysql_real_escape_string(db, msg_f, msg, (unsigned long)len_msg); |
| 1258 |
|
|
| 1259 |
|
snprintf(sql, sizeof(sql), |
| 1260 |
|
"INSERT INTO bbs_msg(fromUID, toUID, content, send_dt, send_ip) " |
| 1261 |
|
"VALUES(%d, %d, '%s', NOW(), '%s')", |
| 1262 |
|
BBS_sys_id, atoi(row[0]), msg_f, hostaddr_client); |
| 1263 |
|
|
| 1264 |
|
if (mysql_query(db, sql) != 0) |
| 1265 |
|
{ |
| 1266 |
|
log_error("Insert msg error: %s\n", mysql_error(db)); |
| 1267 |
|
ret = -1; |
| 1268 |
|
goto cleanup; |
| 1269 |
|
} |
| 1270 |
|
} |
| 1271 |
|
mysql_free_result(rs); |
| 1272 |
|
rs = NULL; |
| 1273 |
|
|
| 1274 |
// Add exp |
// Add exp |
| 1275 |
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 |
| 1276 |
{ |
{ |