/[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.27 by sysadm, Thu Oct 9 12:20:31 2025 UTC Revision 1.39 by sysadm, Wed Nov 5 01:04: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     */
 /***************************************************************************  
  *                                                                         *  
  *   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"
# Line 32  Line 24 
24  #define TITLE_INPUT_MAX_LEN 72  #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    
# Line 52  int article_post(const SECTION_LIST *p_s Line 43  int article_post(const SECTION_LIST *p_s
43          int content_display_length;          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;
# Line 89  int article_post(const SECTION_LIST *p_s Line 81  int article_post(const SECTION_LIST *p_s
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);
# Line 100  int article_post(const SECTION_LIST *p_s Line 95  int article_post(const SECTION_LIST *p_s
95                          prints("    按0~3选签名档(0表示不使用)");                          prints("    按0~3选签名档(0表示不使用)");
96    
97                          moveto(24, 1);                          moveto(24, 1);
98                          prints("T改标题, C取消, Z设为转载, Y设为原创, Enter继续: ");                          prints("T改标题, C取消, Z设为%s, N%s, Enter继续: ",
99                                       (p_article_new->transship ? "原创" : "转载"),
100                                       (reply_note ? "关闭回复通知" : "开启回复通知"));
101                          iflush();                          iflush();
102                          ch = 0;                          ch = 0;
103                  }                  }
104    
105                  for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME))                  for (; !SYS_server_exit; ch = igetch_t(BBS_max_user_idle_time))
106                  {                  {
107                          switch (toupper(ch))                          switch (toupper(ch))
108                          {                          {
# Line 113  int article_post(const SECTION_LIST *p_s Line 110  int article_post(const SECTION_LIST *p_s
110                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
111                                  goto cleanup;                                  goto cleanup;
112                          case CR:                          case CR:
                                 igetch_reset();  
113                                  break;                                  break;
114                          case 'T':                          case 'T':
                                 moveto(24, 1);  
                                 clrtoeol();  
115                                  len = get_data(24, 1, "标题: ", title_input, sizeof(title_input), TITLE_INPUT_MAX_LEN);                                  len = get_data(24, 1, "标题: ", title_input, sizeof(title_input), TITLE_INPUT_MAX_LEN);
116                                  for (p = title_input; *p == ' '; p++)                                  for (p = title_input; *p == ' '; p++)
117                                          ;                                          ;
# Line 138  int article_post(const SECTION_LIST *p_s Line 132  int article_post(const SECTION_LIST *p_s
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':
# Line 171  int article_post(const SECTION_LIST *p_s Line 165  int article_post(const SECTION_LIST *p_s
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(BBS_max_user_idle_time))
169                          {                          {
170                                  switch (toupper(ch))                                  switch (toupper(ch))
171                                  {                                  {
# Line 179  int article_post(const SECTION_LIST *p_s Line 173  int article_post(const SECTION_LIST *p_s
173                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
174                                          goto cleanup;                                          goto cleanup;
175                                  case CR:                                  case CR:
                                         igetch_reset();  
176                                  case 'S':                                  case 'S':
177                                          break;                                          break;
178                                  case 'C':                                  case 'C':
# Line 330  int article_post(const SECTION_LIST *p_s Line 323  int article_post(const SECTION_LIST *p_s
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, %d)",                           "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, content_display_length);                           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          {          {
# Line 424  int article_modify(const SECTION_LIST *p Line 418  int article_modify(const SECTION_LIST *p
418          char *content_f = NULL;          char *content_f = NULL;
419          long len_content;          long len_content;
420          int content_display_length;          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;
# Line 456  int article_modify(const SECTION_LIST *p Line 451  int article_modify(const SECTION_LIST *p
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);
# Line 500  int article_modify(const SECTION_LIST *p Line 495  int article_modify(const SECTION_LIST *p
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;
# Line 511  int article_modify(const SECTION_LIST *p Line 508  int article_modify(const SECTION_LIST *p
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(BBS_max_user_idle_time);
520                          switch (toupper(ch))                          switch (toupper(ch))
521                          {                          {
522                          case KEY_NULL:                          case KEY_NULL:
523                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
524                                  goto cleanup;                                  goto cleanup;
525                          case CR:                          case CR:
                                 igetch_reset();  
526                          case 'S':                          case 'S':
527                                  break;                                  break;
528                          case 'C':                          case 'C':
# Line 533  int article_modify(const SECTION_LIST *p Line 531  int article_modify(const SECTION_LIST *p
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
# Line 643  int article_modify(const SECTION_LIST *p Line 644  int article_modify(const SECTION_LIST *p
644    
645          // Update article          // Update article
646          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
647                           "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
648                           p_article_new->cid, content_display_length, 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          {          {
# Line 721  int article_reply(const SECTION_LIST *p_ Line 722  int article_reply(const SECTION_LIST *p_
722          int content_display_length;          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;
# Line 730  int article_reply(const SECTION_LIST *p_ Line 732  int article_reply(const SECTION_LIST *p_
732          long i;          long i;
733          long ret = 0;          long ret = 0;
734          int topic_locked = 0;          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          {          {
# Line 837  int article_reply(const SECTION_LIST *p_ Line 842  int article_reply(const SECTION_LIST *p_
842                  }                  }
843    
844                  // Apply LML render to content body                  // Apply LML render to content body
845                  len = lml_render(row[1], content_f, ARTICLE_CONTENT_MAX_LEN, 0);                  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
# Line 847  int article_reply(const SECTION_LIST *p_ Line 852  int article_reply(const SECTION_LIST *p_
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, 0, NULL);                  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
# Line 892  int article_reply(const SECTION_LIST *p_ Line 897  int article_reply(const SECTION_LIST *p_
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);
# Line 903  int article_reply(const SECTION_LIST *p_ Line 908  int article_reply(const SECTION_LIST *p_
908                          prints("    按0~3选签名档(0表示不使用)");                          prints("    按0~3选签名档(0表示不使用)");
909    
910                          moveto(24, 1);                          moveto(24, 1);
911                          prints("T改标题, C取消, Enter继续: ");                          prints("T改标题, C取消, N%s, Enter继续: ",
912                                       (reply_note ? "关闭回复通知" : "开启回复通知"));
913                          iflush();                          iflush();
914                          ch = 0;                          ch = 0;
915                  }                  }
916    
917                  for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME))                  for (; !SYS_server_exit; ch = igetch_t(BBS_max_user_idle_time))
918                  {                  {
919                          switch (toupper(ch))                          switch (toupper(ch))
920                          {                          {
# Line 916  int article_reply(const SECTION_LIST *p_ Line 922  int article_reply(const SECTION_LIST *p_
922                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
923                                  goto cleanup;                                  goto cleanup;
924                          case CR:                          case CR:
                                 igetch_reset();  
925                                  break;                                  break;
926                          case 'T':                          case 'T':
                                 moveto(24, 1);  
                                 clrtoeol();  
927                                  len = get_data(24, 1, "标题: ", title_input, sizeof(title_input), TITLE_INPUT_MAX_LEN);                                  len = get_data(24, 1, "标题: ", title_input, sizeof(title_input), TITLE_INPUT_MAX_LEN);
928                                  for (p = title_input; *p == ' '; p++)                                  for (p = title_input; *p == ' '; p++)
929                                          ;                                          ;
# Line 941  int article_reply(const SECTION_LIST *p_ Line 944  int article_reply(const SECTION_LIST *p_
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':
# Line 968  int article_reply(const SECTION_LIST *p_ Line 974  int article_reply(const SECTION_LIST *p_
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(BBS_max_user_idle_time))
978                          {                          {
979                                  switch (toupper(ch))                                  switch (toupper(ch))
980                                  {                                  {
# Line 976  int article_reply(const SECTION_LIST *p_ Line 982  int article_reply(const SECTION_LIST *p_
982                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
983                                          goto cleanup;                                          goto cleanup;
984                                  case CR:                                  case CR:
                                         igetch_reset();  
985                                  case 'S':                                  case 'S':
986                                          break;                                          break;
987                                  case 'C':                                  case 'C':
# Line 1127  int article_reply(const SECTION_LIST *p_ Line 1132  int article_reply(const SECTION_LIST *p_
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, %d)",                           "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, content_display_length);                           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          {          {
# Line 1168  int article_reply(const SECTION_LIST *p_ Line 1174  int article_reply(const SECTION_LIST *p_
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          {          {


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

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