/[LeafOK_CVS]/lbbs/src/article_post.c
ViewVC logotype

Diff of /lbbs/src/article_post.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.20 by sysadm, Mon Jun 16 01:36:56 2025 UTC Revision 1.43 by sysadm, Tue Nov 11 00:28:05 2025 UTC
# Line 1  Line 1 
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     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
 #define _POSIX_C_SOURCE 200809L  
   
 #include "article_post.h"  
13  #include "article_cache.h"  #include "article_cache.h"
14  #include "editor.h"  #include "article_post.h"
 #include "screen.h"  
15  #include "bbs.h"  #include "bbs.h"
16  #include "log.h"  #include "bwf.h"
17    #include "database.h"
18    #include "editor.h"
19  #include "io.h"  #include "io.h"
20    #include "log.h"
21  #include "lml.h"  #include "lml.h"
22  #include "database.h"  #include "screen.h"
23  #include "user_priv.h"  #include "user_priv.h"
24  #include <ctype.h>  #include <ctype.h>
25  #include <string.h>  #include <string.h>
26  #include <stdlib.h>  #include <stdlib.h>
27  #include <time.h>  #include <time.h>
28    
29  #define TITLE_INPUT_MAX_LEN 74  enum _article_post_constant_t
30  #define ARTICLE_CONTENT_MAX_LEN 1024 * 1024 * 4 // 4MB  {
31  #define ARTICLE_QUOTE_MAX_LINES 20          TITLE_INPUT_MAX_LEN = 72,
32  #define ARTICLE_QUOTE_LINE_MAX_LEN 76          ARTICLE_QUOTE_DEFAULT_LINES = 20,
33            MODIFY_DT_MAX_LEN = 50,
34  #define MODIFY_DT_MAX_LEN 50  };
35    
36  int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new)  int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new)
37  {  {
# Line 46  int article_post(const SECTION_LIST *p_s Line 41  int article_post(const SECTION_LIST *p_s
41          char sql[SQL_BUFFER_LEN];          char sql[SQL_BUFFER_LEN];
42          char *sql_content = NULL;          char *sql_content = NULL;
43          EDITOR_DATA *p_editor_data = NULL;          EDITOR_DATA *p_editor_data = NULL;
44          char title_input[TITLE_INPUT_MAX_LEN + 1];          char title_input[BBS_article_title_max_len + 1];
45          char title_f[BBS_article_title_max_len * 2 + 1];          char title_f[BBS_article_title_max_len * 2 + 1];
46          char *content = NULL;          char *content = NULL;
47          char *content_f = NULL;          char *content_f = NULL;
48          long len_content;          long len_content;
49            int content_display_length;
50          char nickname_f[BBS_nickname_max_len * 2 + 1];          char nickname_f[BBS_nickname_max_len * 2 + 1];
51          int sign_id = 0;          int sign_id = 0;
52            int reply_note = 1;
53          long len;          long len;
54          int ch;          int ch;
55          char *p, *q;          char *p, *q;
# Line 67  int article_post(const SECTION_LIST *p_s Line 64  int article_post(const SECTION_LIST *p_s
64          {          {
65                  clearscr();                  clearscr();
66                  moveto(1, 1);                  moveto(1, 1);
67                  prints("您没有权限在本版块发表文章\n");                  prints("鎮ㄦ病鏈夋潈闄愬湪鏈増鍧楀彂琛ㄦ枃绔燶n");
68                  press_any_key();                  press_any_key();
69    
70                  return 0;                  return 0;
# Line 90  int article_post(const SECTION_LIST *p_s Line 87  int article_post(const SECTION_LIST *p_s
87          {          {
88                  clearscr();                  clearscr();
89                  moveto(21, 1);                  moveto(21, 1);
90                  prints("发表文章于 %s[%s] 讨论区,类型: %s", p_section->stitle, p_section->sname, (p_article_new->transship ? "转载" : "原创"));                  prints("鍙戣〃鏂囩珷浜 %s[%s] 璁ㄨ鍖猴紝绫诲瀷: %s锛屽洖澶嶉氱煡: %s",
91                               p_section->stitle, p_section->sname,
92                               (p_article_new->transship ? "杞浇" : "鍘熷垱"),
93                               (reply_note ? "寮鍚" : "鍏抽棴"));
94                  moveto(22, 1);                  moveto(22, 1);
95                  prints("标题: %s", (p_article_new->title[0] == '\0' ? "[无]" : p_article_new->title));                  prints("鏍囬: %s", (p_article_new->title[0] == '\0' ? "[鏃燷" : p_article_new->title));
96                  moveto(23, 1);                  moveto(23, 1);
97                  prints("使用第 %d 个签名", sign_id);                  prints("浣跨敤绗 %d 涓鍚", sign_id);
98    
99                  if (toupper(ch) != 'T')                  if (toupper(ch) != 'T')
100                  {                  {
101                          prints("    按0~3选签名档(0表示不使用)");                          prints("    鎸0~3閫夌鍚嶆。(0琛ㄧず涓嶄娇鐢)");
102    
103                          moveto(24, 1);                          moveto(24, 1);
104                          prints("T改标题, C取消, Z设为转载, Y设为原创, Enter继续: ");                          prints("T鏀规爣棰, C鍙栨秷, Z璁句负%s, N%s, Enter缁х画: ",
105                                       (p_article_new->transship ? "鍘熷垱" : "杞浇"),
106                                       (reply_note ? "鍏抽棴鍥炲閫氱煡" : "寮鍚洖澶嶉氱煡"));
107                          iflush();                          iflush();
108                          ch = 0;                          ch = 0;
109                  }                  }
110    
111                  for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME))                  while (!SYS_server_exit)
112                  {                  {
113                          switch (toupper(ch))                          switch (toupper(ch))
114                          {                          {
# Line 114  int article_post(const SECTION_LIST *p_s Line 116  int article_post(const SECTION_LIST *p_s
116                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
117                                  goto cleanup;                                  goto cleanup;
118                          case CR:                          case CR:
                                 igetch_reset();  
119                                  break;                                  break;
120                          case 'T':                          case 'T':
121                                  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);  
122                                  for (p = title_input; *p == ' '; p++)                                  for (p = title_input; *p == ' '; p++)
123                                          ;                                          ;
124                                  for (q = title_input + len; q > p && *(q - 1) == ' '; q--)                                  for (q = title_input + len; q > p && *(q - 1) == ' '; q--)
# Line 128  int article_post(const SECTION_LIST *p_s Line 127  int article_post(const SECTION_LIST *p_s
127                                  len = q - p;                                  len = q - p;
128                                  if (*p != '\0')                                  if (*p != '\0')
129                                  {                                  {
130                                            if ((ret = check_badwords(p, '*')) < 0)
131                                            {
132                                                    log_error("check_badwords(title) error\n");
133                                            }
134                                            else if (ret > 0)
135                                            {
136                                                    memcpy(title_input, p, (size_t)len + 1);
137                                                    continue;
138                                            }
139                                          memcpy(p_article_new->title, p, (size_t)len + 1);                                          memcpy(p_article_new->title, p, (size_t)len + 1);
140                                          memcpy(title_input, p_article_new->title, (size_t)len + 1);                                          memcpy(title_input, p_article_new->title, (size_t)len + 1);
141                                  }                                  }
# Line 136  int article_post(const SECTION_LIST *p_s Line 144  int article_post(const SECTION_LIST *p_s
144                          case 'C':                          case 'C':
145                                  clearscr();                                  clearscr();
146                                  moveto(1, 1);                                  moveto(1, 1);
147                                  prints("取消...");                                  prints("鍙栨秷...");
148                                  press_any_key();                                  press_any_key();
149                                  goto cleanup;                                  goto cleanup;
                         case 'Y':  
                                 p_article_new->transship = 0;  
                                 break;  
150                          case 'Z':                          case 'Z':
151                                  p_article_new->transship = 1;                                  p_article_new->transship = (p_article_new->transship ? 0 : 1);
152                                    break;
153                            case 'N':
154                                    reply_note = (reply_note ? 0 : 1);
155                                  break;                                  break;
156                          case '0':                          case '0':
157                          case '1':                          case '1':
# Line 152  int article_post(const SECTION_LIST *p_s Line 160  int article_post(const SECTION_LIST *p_s
160                                  sign_id = ch - '0';                                  sign_id = ch - '0';
161                                  break;                                  break;
162                          default: // Invalid selection                          default: // Invalid selection
163                                    ch = igetch_t(BBS_max_user_idle_time);
164                                  continue;                                  continue;
165                          }                          }
166    
# Line 169  int article_post(const SECTION_LIST *p_s Line 178  int article_post(const SECTION_LIST *p_s
178    
179                          clearscr();                          clearscr();
180                          moveto(1, 1);                          moveto(1, 1);
181                          prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: ");                          prints("(S)鍙戦, (C)鍙栨秷, (T)鏇存敼鏍囬 or (E)鍐嶇紪杈? [S]: ");
182                          iflush();                          iflush();
183    
184                          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))
185                          {                          {
186                                  switch (toupper(ch))                                  switch (toupper(ch))
187                                  {                                  {
# Line 180  int article_post(const SECTION_LIST *p_s Line 189  int article_post(const SECTION_LIST *p_s
189                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
190                                          goto cleanup;                                          goto cleanup;
191                                  case CR:                                  case CR:
                                         igetch_reset();  
192                                  case 'S':                                  case 'S':
193                                          break;                                          break;
194                                  case 'C':                                  case 'C':
195                                          clearscr();                                          clearscr();
196                                          moveto(1, 1);                                          moveto(1, 1);
197                                          prints("取消...");                                          prints("鍙栨秷...");
198                                          press_any_key();                                          press_any_key();
199                                          goto cleanup;                                          goto cleanup;
200                                  case 'T':                                  case 'T':
# Line 228  int article_post(const SECTION_LIST *p_s Line 236  int article_post(const SECTION_LIST *p_s
236                  goto cleanup;                  goto cleanup;
237          }          }
238    
239            if (check_badwords(content, '*') < 0)
240            {
241                    log_error("check_badwords(content) error\n");
242                    ret = -1;
243                    goto cleanup;
244            }
245    
246          db = db_open();          db = db_open();
247          if (db == NULL)          if (db == NULL)
248          {          {
# Line 265  int article_post(const SECTION_LIST *p_s Line 280  int article_post(const SECTION_LIST *p_s
280                  rs = NULL;                  rs = NULL;
281          }          }
282    
283            // Calculate display length of content
284            content_display_length = str_length(content, 1);
285    
286          // Begin transaction          // Begin transaction
287          if (mysql_query(db, "SET autocommit=0") != 0)          if (mysql_query(db, "SET autocommit=0") != 0)
288          {          {
# Line 328  int article_post(const SECTION_LIST *p_s Line 346  int article_post(const SECTION_LIST *p_s
346          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
347                           "INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, "                           "INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, "
348                           "sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) "                           "sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) "
349                           "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)",
350                           p_section->sid, BBS_priv.uid, BBS_username, nickname_f, title_f,                           p_section->sid, BBS_priv.uid, BBS_username, nickname_f, title_f,
351                           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,
352                             reply_note, BBS_user_exp, content_display_length);
353    
354          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
355          {          {
# Line 394  int article_post(const SECTION_LIST *p_s Line 413  int article_post(const SECTION_LIST *p_s
413    
414          clearscr();          clearscr();
415          moveto(1, 1);          moveto(1, 1);
416          prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval);          prints("鍙戦佸畬鎴愶紝鏂版枃绔犻氬父浼氬湪%d绉掑悗鍙", BBS_section_list_load_interval);
417          press_any_key();          press_any_key();
418          ret = 1; // Success          ret = 1; // Success
419    
# Line 421  int article_modify(const SECTION_LIST *p Line 440  int article_modify(const SECTION_LIST *p
440          char *content = NULL;          char *content = NULL;
441          char *content_f = NULL;          char *content_f = NULL;
442          long len_content;          long len_content;
443            int content_display_length;
444            int reply_note = 1;
445          int ch;          int ch;
446          long ret = 0;          long ret = 0;
447          time_t now;          time_t now;
# Line 438  int article_modify(const SECTION_LIST *p Line 459  int article_modify(const SECTION_LIST *p
459          {          {
460                  clearscr();                  clearscr();
461                  moveto(1, 1);                  moveto(1, 1);
462                  prints("该文章无法被编辑,请联系版主。");                  prints("璇ユ枃绔犳棤娉曡缂栬緫锛岃鑱旂郴鐗堜富銆");
463                  press_any_key();                  press_any_key();
464    
465                  return 0;                  return 0;
# Line 453  int article_modify(const SECTION_LIST *p Line 474  int article_modify(const SECTION_LIST *p
474          }          }
475    
476          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
477                           "SELECT bbs_content.CID, bbs_content.content "                           "SELECT bbs_content.CID, bbs_content.content, reply_note "
478                           "FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID "                           "FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID "
479                           "WHERE bbs.AID = %d",                           "WHERE bbs.AID = %d",
480                           p_article->aid);                           p_article->aid);
# Line 497  int article_modify(const SECTION_LIST *p Line 518  int article_modify(const SECTION_LIST *p
518    
519                  free(content);                  free(content);
520                  content = NULL;                  content = NULL;
521    
522                    reply_note = atoi(row[2]);
523          }          }
524          mysql_free_result(rs);          mysql_free_result(rs);
525          rs = NULL;          rs = NULL;
# Line 508  int article_modify(const SECTION_LIST *p Line 531  int article_modify(const SECTION_LIST *p
531          {          {
532                  editor_display(p_editor_data);                  editor_display(p_editor_data);
533    
534                  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))  
535                  {                  {
536                            clearscr();
537                            moveto(1, 1);
538                            prints("(S)淇濆瓨, (C)鍙栨秷, (N)%s鍥炲閫氱煡 or (E)鍐嶇紪杈? [S]: ",
539                                       (reply_note ? "鍏抽棴" : "寮鍚"));
540                            iflush();
541    
542                            ch = igetch_t(BBS_max_user_idle_time);
543                          switch (toupper(ch))                          switch (toupper(ch))
544                          {                          {
545                          case KEY_NULL:                          case KEY_NULL:
546                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
547                                  goto cleanup;                                  goto cleanup;
548                          case CR:                          case CR:
                                 igetch_reset();  
549                          case 'S':                          case 'S':
550                                  break;                                  break;
551                          case 'C':                          case 'C':
552                                  clearscr();                                  clearscr();
553                                  moveto(1, 1);                                  moveto(1, 1);
554                                  prints("取消...");                                  prints("鍙栨秷...");
555                                  press_any_key();                                  press_any_key();
556                                  goto cleanup;                                  goto cleanup;
557                            case 'N':
558                                    reply_note = (reply_note ? 0 : 1);
559                                    continue;
560                          case 'E':                          case 'E':
561                                  break;                                  break;
562                          default: // Invalid selection                          default: // Invalid selection
# Line 562  int article_modify(const SECTION_LIST *p Line 589  int article_modify(const SECTION_LIST *p
589                  goto cleanup;                  goto cleanup;
590          }          }
591    
592            if (check_badwords(content, '*') < 0)
593            {
594                    log_error("check_badwords(content) error\n");
595                    ret = -1;
596                    goto cleanup;
597            }
598    
599          time(&now);          time(&now);
600          localtime_r(&now, &tm_modify_dt);          localtime_r(&now, &tm_modify_dt);
601          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);
602    
603          len_content += snprintf(content + len_content, LINE_BUFFER_LEN,          len_content += snprintf(content + len_content, LINE_BUFFER_LEN,
604                                                          "\n--\n※ 作者已于 %s 修改本文※\n",                                                          "\n--\n鈥 浣滆呭凡浜 %s 淇敼鏈枃鈥籠n",
605                                                          str_modify_dt);                                                          str_modify_dt);
606    
607            // Calculate display length of content
608            content_display_length = str_length(content, 1);
609    
610          db = db_open();          db = db_open();
611          if (db == NULL)          if (db == NULL)
612          {          {
# Line 637  int article_modify(const SECTION_LIST *p Line 674  int article_modify(const SECTION_LIST *p
674    
675          // Update article          // Update article
676          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
677                           "UPDATE bbs SET CID = %d, length = %ld, 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
678                           p_article_new->cid, len_content, p_article->aid);                           p_article_new->cid, content_display_length, reply_note, p_article->aid);
679    
680          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
681          {          {
# Line 680  int article_modify(const SECTION_LIST *p Line 717  int article_modify(const SECTION_LIST *p
717    
718          clearscr();          clearscr();
719          moveto(1, 1);          moveto(1, 1);
720          prints("修改完成,新内容通常会在%d秒后可见", BBS_section_list_load_interval);          prints("淇敼瀹屾垚锛屾柊鍐呭閫氬父浼氬湪%d绉掑悗鍙", BBS_section_list_load_interval);
721          press_any_key();          press_any_key();
722          ret = 1; // Success          ret = 1; // Success
723    
# Line 703  int article_reply(const SECTION_LIST *p_ Line 740  int article_reply(const SECTION_LIST *p_
740          MYSQL *db = NULL;          MYSQL *db = NULL;
741          MYSQL_RES *rs = NULL;          MYSQL_RES *rs = NULL;
742          MYSQL_ROW row;          MYSQL_ROW row;
743          long line_offsets[ARTICLE_QUOTE_MAX_LINES + 1];          long line_offsets[MAX_EDITOR_DATA_LINES + 1];
744          char sql[SQL_BUFFER_LEN];          char sql[SQL_BUFFER_LEN];
745          char *sql_content = NULL;          char *sql_content = NULL;
746          EDITOR_DATA *p_editor_data = NULL;          EDITOR_DATA *p_editor_data = NULL;
# Line 712  int article_reply(const SECTION_LIST *p_ Line 749  int article_reply(const SECTION_LIST *p_
749          char *content = NULL;          char *content = NULL;
750          char *content_f = NULL;          char *content_f = NULL;
751          long len_content;          long len_content;
752            int content_display_length;
753          char nickname_f[BBS_nickname_max_len * 2 + 1];          char nickname_f[BBS_nickname_max_len * 2 + 1];
754          int sign_id = 0;          int sign_id = 0;
755            int reply_note = 0;
756            int full_quote = 0;
757          long len;          long len;
758          int ch;          int ch;
759          char *p, *q;          char *p, *q;
# Line 723  int article_reply(const SECTION_LIST *p_ Line 763  int article_reply(const SECTION_LIST *p_
763          long i;          long i;
764          long ret = 0;          long ret = 0;
765          int topic_locked = 0;          int topic_locked = 0;
766            char msg[BBS_msg_max_len];
767            char msg_f[BBS_msg_max_len * 2 + 1];
768            int len_msg;
769    
770          if (p_section == NULL || p_article == NULL)          if (p_section == NULL || p_article == NULL)
771          {          {
# Line 733  int article_reply(const SECTION_LIST *p_ Line 776  int article_reply(const SECTION_LIST *p_
776          {          {
777                  clearscr();                  clearscr();
778                  moveto(1, 1);                  moveto(1, 1);
779                  prints("您没有权限在本版块发表文章\n");                  prints("鎮ㄦ病鏈夋潈闄愬湪鏈増鍧楀彂琛ㄦ枃绔燶n");
780                  press_any_key();                  press_any_key();
781    
782                  return 0;                  return 0;
# Line 786  int article_reply(const SECTION_LIST *p_ Line 829  int article_reply(const SECTION_LIST *p_
829    
830                  clearscr();                  clearscr();
831                  moveto(1, 1);                  moveto(1, 1);
832                  prints("该主题谢绝回复");                  prints("璇ヤ富棰樿阿缁濆洖澶");
833                  press_any_key();                  press_any_key();
834    
835                  goto cleanup;                  goto cleanup;
# Line 830  int article_reply(const SECTION_LIST *p_ Line 873  int article_reply(const SECTION_LIST *p_
873                  }                  }
874    
875                  // Apply LML render to content body                  // Apply LML render to content body
876                  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);
877                  content_f[len] = '\0';                  content_f[len] = '\0';
878    
879                  // Remove control sequence                  // Remove control sequence
880                  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);  
                 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;  
881          }          }
882          mysql_free_result(rs);          mysql_free_result(rs);
883          rs = NULL;          rs = NULL;
# Line 885  int article_reply(const SECTION_LIST *p_ Line 890  int article_reply(const SECTION_LIST *p_
890          {          {
891                  clearscr();                  clearscr();
892                  moveto(21, 1);                  moveto(21, 1);
893                  prints("回复文章于 %s[%s] 讨论区", p_section->stitle, p_section->sname);                  prints("鍥炲鏂囩珷浜 %s[%s] 璁ㄨ鍖, 鍥炲閫氱煡: %s, 寮曠敤妯″紡: %s",
894                               p_section->stitle, p_section->sname,
895                               (reply_note ? "寮鍚" : "鍏抽棴"),
896                               (full_quote ? "瀹屾暣" : "绮剧畝"));
897                  moveto(22, 1);                  moveto(22, 1);
898                  prints("标题: %s", (p_article_new->title[0] == '\0' ? "[无]" : p_article_new->title));                  prints("鏍囬: %s", (p_article_new->title[0] == '\0' ? "[鏃燷" : p_article_new->title));
899                  moveto(23, 1);                  moveto(23, 1);
900                  prints("使用第 %d 个签名", sign_id);                  prints("浣跨敤绗 %d 涓鍚", sign_id);
901    
902                  if (toupper(ch) != 'T')                  if (toupper(ch) != 'T')
903                  {                  {
904                          prints("    按0~3选签名档(0表示不使用)");                          prints("    鎸0~3閫夌鍚嶆。(0琛ㄧず涓嶄娇鐢)");
905    
906                          moveto(24, 1);                          moveto(24, 1);
907                          prints("T改标题, C取消, Enter继续: ");                          prints("T鏀规爣棰, C鍙栨秷, N%s, Q%s, Enter缁х画: ",
908                                       (reply_note ? "鍏抽棴鍥炲閫氱煡" : "寮鍚洖澶嶉氱煡"), (full_quote ? "绮剧畝寮曠敤" : "瀹屾暣寮曠敤"));
909                          iflush();                          iflush();
910                          ch = 0;                          ch = 0;
911                  }                  }
912    
913                  for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME))                  while (!SYS_server_exit)
914                  {                  {
915                          switch (toupper(ch))                          switch (toupper(ch))
916                          {                          {
# Line 909  int article_reply(const SECTION_LIST *p_ Line 918  int article_reply(const SECTION_LIST *p_
918                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
919                                  goto cleanup;                                  goto cleanup;
920                          case CR:                          case CR:
                                 igetch_reset();  
921                                  break;                                  break;
922                          case 'T':                          case 'T':
923                                  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);  
924                                  for (p = title_input; *p == ' '; p++)                                  for (p = title_input; *p == ' '; p++)
925                                          ;                                          ;
926                                  for (q = title_input + len; q > p && *(q - 1) == ' '; q--)                                  for (q = title_input + len; q > p && *(q - 1) == ' '; q--)
# Line 923  int article_reply(const SECTION_LIST *p_ Line 929  int article_reply(const SECTION_LIST *p_
929                                  len = q - p;                                  len = q - p;
930                                  if (*p != '\0')                                  if (*p != '\0')
931                                  {                                  {
932                                            if ((ret = check_badwords(p, '*')) < 0)
933                                            {
934                                                    log_error("check_badwords(title) error\n");
935                                            }
936                                            else if (ret > 0)
937                                            {
938                                                    memcpy(title_input, p, (size_t)len + 1);
939                                                    continue;
940                                            }
941                                          memcpy(p_article_new->title, p, (size_t)len + 1);                                          memcpy(p_article_new->title, p, (size_t)len + 1);
942                                          memcpy(title_input, p_article_new->title, (size_t)len + 1);                                          memcpy(title_input, p_article_new->title, (size_t)len + 1);
943                                  }                                  }
# Line 931  int article_reply(const SECTION_LIST *p_ Line 946  int article_reply(const SECTION_LIST *p_
946                          case 'C':                          case 'C':
947                                  clearscr();                                  clearscr();
948                                  moveto(1, 1);                                  moveto(1, 1);
949                                  prints("取消...");                                  prints("鍙栨秷...");
950                                  press_any_key();                                  press_any_key();
951                                  goto cleanup;                                  goto cleanup;
952                            case 'N':
953                                    reply_note = (reply_note ? 0 : 1);
954                                    break;
955                            case 'Q':
956                                    full_quote = (full_quote ? 0 : 1);
957                                    break;
958                          case '0':                          case '0':
959                          case '1':                          case '1':
960                          case '2':                          case '2':
# Line 941  int article_reply(const SECTION_LIST *p_ Line 962  int article_reply(const SECTION_LIST *p_
962                                  sign_id = ch - '0';                                  sign_id = ch - '0';
963                                  break;                                  break;
964                          default: // Invalid selection                          default: // Invalid selection
965                                    ch = igetch_t(BBS_max_user_idle_time);
966                                  continue;                                  continue;
967                          }                          }
968    
# Line 952  int article_reply(const SECTION_LIST *p_ Line 974  int article_reply(const SECTION_LIST *p_
974                          continue;                          continue;
975                  }                  }
976    
977                    len = snprintf(content, ARTICLE_CONTENT_MAX_LEN,
978                                               "\n\n銆 鍦 %s (%s) 鐨勫ぇ浣滀腑鎻愬埌: 銆慭n",
979                                               p_article->username, p_article->nickname);
980    
981                    quote_content_lines = split_data_lines(content_f,
982                                                                                               MAX_EDITOR_DATA_LINE_LENGTH - 2, line_offsets,
983                                                                                               (full_quote ? MAX_EDITOR_DATA_LINES : ARTICLE_QUOTE_DEFAULT_LINES) + 1,
984                                                                                               0, NULL);
985                    for (i = 0; i < quote_content_lines; i++)
986                    {
987                            memcpy(content + len, ": ", 2); // quote line prefix
988                            len += 2;
989                            memcpy(content + len, content_f + line_offsets[i], (size_t)(line_offsets[i + 1] - line_offsets[i]));
990                            len += (line_offsets[i + 1] - line_offsets[i]);
991                            if (content[len - 1] != '\n') // Appennd \n if not exist
992                            {
993                                    content[len] = '\n';
994                                    len++;
995                            }
996                    }
997                    if (content[len - 1] != '\n') // Appennd \n if not exist
998                    {
999                            content[len] = '\n';
1000                            len++;
1001                    }
1002                    content[len] = '\0';
1003    
1004                    free(content_f);
1005                    content_f = NULL;
1006    
1007                    p_editor_data = editor_data_load(content);
1008                    if (p_editor_data == NULL)
1009                    {
1010                            log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0]));
1011                            ret = -1;
1012                            goto cleanup;
1013                    }
1014    
1015                    free(content);
1016                    content = NULL;
1017    
1018                  for (ch = 'E'; !SYS_server_exit && toupper(ch) == 'E';)                  for (ch = 'E'; !SYS_server_exit && toupper(ch) == 'E';)
1019                  {                  {
1020                          editor_display(p_editor_data);                          editor_display(p_editor_data);
1021    
1022                          clearscr();                          clearscr();
1023                          moveto(1, 1);                          moveto(1, 1);
1024                          prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: ");                          prints("(S)鍙戦, (C)鍙栨秷, (T)鏇存敼鏍囬 or (E)鍐嶇紪杈? [S]: ");
1025                          iflush();                          iflush();
1026    
1027                          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))
1028                          {                          {
1029                                  switch (toupper(ch))                                  switch (toupper(ch))
1030                                  {                                  {
# Line 969  int article_reply(const SECTION_LIST *p_ Line 1032  int article_reply(const SECTION_LIST *p_
1032                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
1033                                          goto cleanup;                                          goto cleanup;
1034                                  case CR:                                  case CR:
                                         igetch_reset();  
1035                                  case 'S':                                  case 'S':
1036                                          break;                                          break;
1037                                  case 'C':                                  case 'C':
1038                                          clearscr();                                          clearscr();
1039                                          moveto(1, 1);                                          moveto(1, 1);
1040                                          prints("取消...");                                          prints("鍙栨秷...");
1041                                          press_any_key();                                          press_any_key();
1042                                          goto cleanup;                                          goto cleanup;
1043                                  case 'T':                                  case 'T':
# Line 1017  int article_reply(const SECTION_LIST *p_ Line 1079  int article_reply(const SECTION_LIST *p_
1079                  goto cleanup;                  goto cleanup;
1080          }          }
1081    
1082            if (check_badwords(content, '*') < 0)
1083            {
1084                    log_error("check_badwords(content) error\n");
1085                    ret = -1;
1086                    goto cleanup;
1087            }
1088    
1089          db = db_open();          db = db_open();
1090          if (db == NULL)          if (db == NULL)
1091          {          {
# Line 1054  int article_reply(const SECTION_LIST *p_ Line 1123  int article_reply(const SECTION_LIST *p_
1123                  rs = NULL;                  rs = NULL;
1124          }          }
1125    
1126            // Calculate display length of content
1127            content_display_length = str_length(content, 1);
1128    
1129          // Begin transaction          // Begin transaction
1130          if (mysql_query(db, "SET autocommit=0") != 0)          if (mysql_query(db, "SET autocommit=0") != 0)
1131          {          {
# Line 1117  int article_reply(const SECTION_LIST *p_ Line 1189  int article_reply(const SECTION_LIST *p_
1189          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
1190                           "INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, "                           "INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, "
1191                           "sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) "                           "sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) "
1192                           "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)",
1193                           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),
1194                           BBS_priv.uid, BBS_username, nickname_f, title_f,                           BBS_priv.uid, BBS_username, nickname_f, title_f,
1195                           p_article_new->cid, hostaddr_client, BBS_user_exp, len_content);                           p_article_new->cid, hostaddr_client,
1196                             reply_note, BBS_user_exp, content_display_length);
1197    
1198          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
1199          {          {
# Line 1158  int article_reply(const SECTION_LIST *p_ Line 1231  int article_reply(const SECTION_LIST *p_
1231                  goto cleanup;                  goto cleanup;
1232          }          }
1233    
1234            // Notify the authors of the topic / article which is replyed.
1235            snprintf(sql, sizeof(sql),
1236                             "SELECT DISTINCT UID FROM bbs WHERE (AID = %d OR AID = %d) "
1237                             "AND visible AND reply_note AND UID <> %d",
1238                             p_article->tid, p_article->aid, BBS_priv.uid);
1239    
1240            if (mysql_query(db, sql) != 0)
1241            {
1242                    log_error("Read reply info error: %s\n", mysql_error(db));
1243                    ret = -1;
1244                    goto cleanup;
1245            }
1246            if ((rs = mysql_store_result(db)) == NULL)
1247            {
1248                    log_error("Get reply info failed\n");
1249                    ret = -1;
1250                    goto cleanup;
1251            }
1252    
1253            while ((row = mysql_fetch_row(rs)))
1254            {
1255                    // Send notification message
1256                    len_msg = snprintf(msg, BBS_msg_max_len,
1257                                                       "鏈変汉鍥炲浜嗘偍鎵鍙戣〃/鍥炲鐨勬枃绔狅紝蹇潵"
1258                                                       "[article %d]鐪嬬湅[/article]銆%s銆嬪惂锛乗n",
1259                                                       p_article_new->aid, title_f);
1260    
1261                    mysql_real_escape_string(db, msg_f, msg, (unsigned long)len_msg);
1262    
1263                    snprintf(sql, sizeof(sql),
1264                                     "INSERT INTO bbs_msg(fromUID, toUID, content, send_dt, send_ip) "
1265                                     "VALUES(%d, %d, '%s', NOW(), '%s')",
1266                                     BBS_sys_id, atoi(row[0]), msg_f, hostaddr_client);
1267    
1268                    if (mysql_query(db, sql) != 0)
1269                    {
1270                            log_error("Insert msg error: %s\n", mysql_error(db));
1271                            ret = -1;
1272                            goto cleanup;
1273                    }
1274            }
1275            mysql_free_result(rs);
1276            rs = NULL;
1277    
1278          // Add exp          // Add exp
1279          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
1280          {          {
# Line 1199  int article_reply(const SECTION_LIST *p_ Line 1316  int article_reply(const SECTION_LIST *p_
1316    
1317          clearscr();          clearscr();
1318          moveto(1, 1);          moveto(1, 1);
1319          prints("发送完成,新文章通常会在%d秒后可见", BBS_section_list_load_interval);          prints("鍙戦佸畬鎴愶紝鏂版枃绔犻氬父浼氬湪%d绉掑悗鍙", BBS_section_list_load_interval);
1320          press_any_key();          press_any_key();
1321          ret = 1; // Success          ret = 1; // Success
1322    


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1