/[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.25 by sysadm, Tue Sep 30 03:02:06 2025 UTC Revision 1.40 by sysadm, Wed Nov 5 03:17:12 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 29  Line 21 
21  #include <stdlib.h>  #include <stdlib.h>
22  #include <time.h>  #include <time.h>
23    
24  #define TITLE_INPUT_MAX_LEN 72  enum _article_post_constant_t
25  #define ARTICLE_CONTENT_MAX_LEN 1024 * 1024 * 4 // 4MB  {
26  #define ARTICLE_QUOTE_MAX_LINES 20          TITLE_INPUT_MAX_LEN = 72,
27  #define ARTICLE_QUOTE_LINE_MAX_LEN 76          ARTICLE_QUOTE_MAX_LINES = 20,
28            MODIFY_DT_MAX_LEN = 50,
29  #define MODIFY_DT_MAX_LEN 50  };
30    
31  int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new)  int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new)
32  {  {
# Line 52  int article_post(const SECTION_LIST *p_s Line 44  int article_post(const SECTION_LIST *p_s
44          int content_display_length;          int content_display_length;
45          char nickname_f[BBS_nickname_max_len * 2 + 1];          char nickname_f[BBS_nickname_max_len * 2 + 1];
46          int sign_id = 0;          int sign_id = 0;
47            int reply_note = 1;
48          long len;          long len;
49          int ch;          int ch;
50          char *p, *q;          char *p, *q;
# Line 89  int article_post(const SECTION_LIST *p_s Line 82  int article_post(const SECTION_LIST *p_s
82          {          {
83                  clearscr();                  clearscr();
84                  moveto(21, 1);                  moveto(21, 1);
85                  prints("发表文章于 %s[%s] 讨论区,类型: %s", p_section->stitle, p_section->sname, (p_article_new->transship ? "转载" : "原创"));                  prints("发表文章于 %s[%s] 讨论区,类型: %s,回复通知:%s",
86                               p_section->stitle, p_section->sname,
87                               (p_article_new->transship ? "转载" : "原创"),
88                               (reply_note ? "开启" : "关闭"));
89                  moveto(22, 1);                  moveto(22, 1);
90                  prints("标题: %s", (p_article_new->title[0] == '\0' ? "[无]" : p_article_new->title));                  prints("标题: %s", (p_article_new->title[0] == '\0' ? "[无]" : p_article_new->title));
91                  moveto(23, 1);                  moveto(23, 1);
# Line 100  int article_post(const SECTION_LIST *p_s Line 96  int article_post(const SECTION_LIST *p_s
96                          prints("    按0~3选签名档(0表示不使用)");                          prints("    按0~3选签名档(0表示不使用)");
97    
98                          moveto(24, 1);                          moveto(24, 1);
99                          prints("T改标题, C取消, Z设为转载, Y设为原创, Enter继续: ");                          prints("T改标题, C取消, Z设为%s, N%s, Enter继续: ",
100                                       (p_article_new->transship ? "原创" : "转载"),
101                                       (reply_note ? "关闭回复通知" : "开启回复通知"));
102                          iflush();                          iflush();
103                          ch = 0;                          ch = 0;
104                  }                  }
105    
106                  for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME))                  for (; !SYS_server_exit; ch = igetch_t(BBS_max_user_idle_time))
107                  {                  {
108                          switch (toupper(ch))                          switch (toupper(ch))
109                          {                          {
# Line 113  int article_post(const SECTION_LIST *p_s Line 111  int article_post(const SECTION_LIST *p_s
111                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
112                                  goto cleanup;                                  goto cleanup;
113                          case CR:                          case CR:
                                 igetch_reset();  
114                                  break;                                  break;
115                          case 'T':                          case 'T':
116                                  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);  
117                                  for (p = title_input; *p == ' '; p++)                                  for (p = title_input; *p == ' '; p++)
118                                          ;                                          ;
119                                  for (q = title_input + len; q > p && *(q - 1) == ' '; q--)                                  for (q = title_input + len; q > p && *(q - 1) == ' '; q--)
# Line 138  int article_post(const SECTION_LIST *p_s Line 133  int article_post(const SECTION_LIST *p_s
133                                  prints("取消...");                                  prints("取消...");
134                                  press_any_key();                                  press_any_key();
135                                  goto cleanup;                                  goto cleanup;
                         case 'Y':  
                                 p_article_new->transship = 0;  
                                 break;  
136                          case 'Z':                          case 'Z':
137                                  p_article_new->transship = 1;                                  p_article_new->transship = (p_article_new->transship ? 0 : 1);
138                                    break;
139                            case 'N':
140                                    reply_note = (reply_note ? 0 : 1);
141                                  break;                                  break;
142                          case '0':                          case '0':
143                          case '1':                          case '1':
# Line 171  int article_post(const SECTION_LIST *p_s Line 166  int article_post(const SECTION_LIST *p_s
166                          prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: ");                          prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: ");
167                          iflush();                          iflush();
168    
169                          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))
170                          {                          {
171                                  switch (toupper(ch))                                  switch (toupper(ch))
172                                  {                                  {
# Line 179  int article_post(const SECTION_LIST *p_s Line 174  int article_post(const SECTION_LIST *p_s
174                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
175                                          goto cleanup;                                          goto cleanup;
176                                  case CR:                                  case CR:
                                         igetch_reset();  
177                                  case 'S':                                  case 'S':
178                                          break;                                          break;
179                                  case 'C':                                  case 'C':
# Line 330  int article_post(const SECTION_LIST *p_s Line 324  int article_post(const SECTION_LIST *p_s
324          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
325                           "INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, "                           "INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, "
326                           "sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) "                           "sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) "
327                           "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)",
328                           p_section->sid, BBS_priv.uid, BBS_username, nickname_f, title_f,                           p_section->sid, BBS_priv.uid, BBS_username, nickname_f, title_f,
329                           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,
330                             reply_note, BBS_user_exp, content_display_length);
331    
332          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
333          {          {
# Line 424  int article_modify(const SECTION_LIST *p Line 419  int article_modify(const SECTION_LIST *p
419          char *content_f = NULL;          char *content_f = NULL;
420          long len_content;          long len_content;
421          int content_display_length;          int content_display_length;
422            int reply_note = 1;
423          int ch;          int ch;
424          long ret = 0;          long ret = 0;
425          time_t now;          time_t now;
# Line 456  int article_modify(const SECTION_LIST *p Line 452  int article_modify(const SECTION_LIST *p
452          }          }
453    
454          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
455                           "SELECT bbs_content.CID, bbs_content.content "                           "SELECT bbs_content.CID, bbs_content.content, reply_note "
456                           "FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID "                           "FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID "
457                           "WHERE bbs.AID = %d",                           "WHERE bbs.AID = %d",
458                           p_article->aid);                           p_article->aid);
# Line 500  int article_modify(const SECTION_LIST *p Line 496  int article_modify(const SECTION_LIST *p
496    
497                  free(content);                  free(content);
498                  content = NULL;                  content = NULL;
499    
500                    reply_note = atoi(row[2]);
501          }          }
502          mysql_free_result(rs);          mysql_free_result(rs);
503          rs = NULL;          rs = NULL;
# Line 511  int article_modify(const SECTION_LIST *p Line 509  int article_modify(const SECTION_LIST *p
509          {          {
510                  editor_display(p_editor_data);                  editor_display(p_editor_data);
511    
512                  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))  
513                  {                  {
514                            clearscr();
515                            moveto(1, 1);
516                            prints("(S)保存, (C)取消, (N)%s回复通知 or (E)再编辑? [S]: ",
517                                       (reply_note ? "关闭" : "开启"));
518                            iflush();
519    
520                            ch = igetch_t(BBS_max_user_idle_time);
521                          switch (toupper(ch))                          switch (toupper(ch))
522                          {                          {
523                          case KEY_NULL:                          case KEY_NULL:
524                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
525                                  goto cleanup;                                  goto cleanup;
526                          case CR:                          case CR:
                                 igetch_reset();  
527                          case 'S':                          case 'S':
528                                  break;                                  break;
529                          case 'C':                          case 'C':
# Line 533  int article_modify(const SECTION_LIST *p Line 532  int article_modify(const SECTION_LIST *p
532                                  prints("取消...");                                  prints("取消...");
533                                  press_any_key();                                  press_any_key();
534                                  goto cleanup;                                  goto cleanup;
535                            case 'N':
536                                    reply_note = (reply_note ? 0 : 1);
537                                    continue;
538                          case 'E':                          case 'E':
539                                  break;                                  break;
540                          default: // Invalid selection                          default: // Invalid selection
# Line 643  int article_modify(const SECTION_LIST *p Line 645  int article_modify(const SECTION_LIST *p
645    
646          // Update article          // Update article
647          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
648                           "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
649                           p_article_new->cid, content_display_length, p_article->aid);                           p_article_new->cid, content_display_length, reply_note, p_article->aid);
650    
651          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
652          {          {
# Line 721  int article_reply(const SECTION_LIST *p_ Line 723  int article_reply(const SECTION_LIST *p_
723          int content_display_length;          int content_display_length;
724          char nickname_f[BBS_nickname_max_len * 2 + 1];          char nickname_f[BBS_nickname_max_len * 2 + 1];
725          int sign_id = 0;          int sign_id = 0;
726            int reply_note = 0;
727          long len;          long len;
728          int ch;          int ch;
729          char *p, *q;          char *p, *q;
# Line 730  int article_reply(const SECTION_LIST *p_ Line 733  int article_reply(const SECTION_LIST *p_
733          long i;          long i;
734          long ret = 0;          long ret = 0;
735          int topic_locked = 0;          int topic_locked = 0;
736            char msg[BBS_msg_max_len];
737            char msg_f[BBS_msg_max_len * 2 + 1];
738            int len_msg;
739    
740          if (p_section == NULL || p_article == NULL)          if (p_section == NULL || p_article == NULL)
741          {          {
# Line 837  int article_reply(const SECTION_LIST *p_ Line 843  int article_reply(const SECTION_LIST *p_
843                  }                  }
844    
845                  // Apply LML render to content body                  // Apply LML render to content body
846                  len = lml_plain(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);
847                  content_f[len] = '\0';                  content_f[len] = '\0';
848    
849                  // Remove control sequence                  // Remove control sequence
# Line 847  int article_reply(const SECTION_LIST *p_ Line 853  int article_reply(const SECTION_LIST *p_
853                                             "\n\n【 在 %s (%s) 的大作中提到: 】\n",                                             "\n\n【 在 %s (%s) 的大作中提到: 】\n",
854                                             p_article->username, p_article->nickname);                                             p_article->username, p_article->nickname);
855    
856                  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);
857                  for (i = 0; i < quote_content_lines; i++)                  for (i = 0; i < quote_content_lines; i++)
858                  {                  {
859                          memcpy(content + len, ": ", 2); // quote line prefix                          memcpy(content + len, ": ", 2); // quote line prefix
# Line 892  int article_reply(const SECTION_LIST *p_ Line 898  int article_reply(const SECTION_LIST *p_
898          {          {
899                  clearscr();                  clearscr();
900                  moveto(21, 1);                  moveto(21, 1);
901                  prints("回复文章于 %s[%s] 讨论区", p_section->stitle, p_section->sname);                  prints("回复文章于 %s[%s] 讨论区,回复通知:%s", p_section->stitle, p_section->sname, (reply_note ? "开启" : "关闭"));
902                  moveto(22, 1);                  moveto(22, 1);
903                  prints("标题: %s", (p_article_new->title[0] == '\0' ? "[无]" : p_article_new->title));                  prints("标题: %s", (p_article_new->title[0] == '\0' ? "[无]" : p_article_new->title));
904                  moveto(23, 1);                  moveto(23, 1);
# Line 903  int article_reply(const SECTION_LIST *p_ Line 909  int article_reply(const SECTION_LIST *p_
909                          prints("    按0~3选签名档(0表示不使用)");                          prints("    按0~3选签名档(0表示不使用)");
910    
911                          moveto(24, 1);                          moveto(24, 1);
912                          prints("T改标题, C取消, Enter继续: ");                          prints("T改标题, C取消, N%s, Enter继续: ",
913                                       (reply_note ? "关闭回复通知" : "开启回复通知"));
914                          iflush();                          iflush();
915                          ch = 0;                          ch = 0;
916                  }                  }
917    
918                  for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME))                  for (; !SYS_server_exit; ch = igetch_t(BBS_max_user_idle_time))
919                  {                  {
920                          switch (toupper(ch))                          switch (toupper(ch))
921                          {                          {
# Line 916  int article_reply(const SECTION_LIST *p_ Line 923  int article_reply(const SECTION_LIST *p_
923                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
924                                  goto cleanup;                                  goto cleanup;
925                          case CR:                          case CR:
                                 igetch_reset();  
926                                  break;                                  break;
927                          case 'T':                          case 'T':
928                                  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);  
929                                  for (p = title_input; *p == ' '; p++)                                  for (p = title_input; *p == ' '; p++)
930                                          ;                                          ;
931                                  for (q = title_input + len; q > p && *(q - 1) == ' '; q--)                                  for (q = title_input + len; q > p && *(q - 1) == ' '; q--)
# Line 941  int article_reply(const SECTION_LIST *p_ Line 945  int article_reply(const SECTION_LIST *p_
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 '0':                          case '0':
952                          case '1':                          case '1':
953                          case '2':                          case '2':
# Line 968  int article_reply(const SECTION_LIST *p_ Line 975  int article_reply(const SECTION_LIST *p_
975                          prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: ");                          prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: ");
976                          iflush();                          iflush();
977    
978                          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))
979                          {                          {
980                                  switch (toupper(ch))                                  switch (toupper(ch))
981                                  {                                  {
# Line 976  int article_reply(const SECTION_LIST *p_ Line 983  int article_reply(const SECTION_LIST *p_
983                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
984                                          goto cleanup;                                          goto cleanup;
985                                  case CR:                                  case CR:
                                         igetch_reset();  
986                                  case 'S':                                  case 'S':
987                                          break;                                          break;
988                                  case 'C':                                  case 'C':
# Line 1127  int article_reply(const SECTION_LIST *p_ Line 1133  int article_reply(const SECTION_LIST *p_
1133          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
1134                           "INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, "                           "INSERT INTO bbs(SID, TID, UID, username, nickname, title, CID, transship, "
1135                           "sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) "                           "sub_dt, sub_ip, reply_note, exp, last_reply_dt, icon, length) "
1136                           "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)",
1137                           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),
1138                           BBS_priv.uid, BBS_username, nickname_f, title_f,                           BBS_priv.uid, BBS_username, nickname_f, title_f,
1139                           p_article_new->cid, hostaddr_client, BBS_user_exp, content_display_length);                           p_article_new->cid, hostaddr_client,
1140                             reply_note, BBS_user_exp, content_display_length);
1141    
1142          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
1143          {          {
# Line 1168  int article_reply(const SECTION_LIST *p_ Line 1175  int article_reply(const SECTION_LIST *p_
1175                  goto cleanup;                  goto cleanup;
1176          }          }
1177    
1178            // Notify the authors of the topic / article which is replyed.
1179            snprintf(sql, sizeof(sql),
1180                             "SELECT DISTINCT UID FROM bbs WHERE (AID = %d OR AID = %d) "
1181                             "AND visible AND reply_note AND UID <> %d",
1182                             p_article->tid, p_article->aid, BBS_priv.uid);
1183    
1184            if (mysql_query(db, sql) != 0)
1185            {
1186                    log_error("Read reply info error: %s\n", mysql_error(db));
1187                    ret = -1;
1188                    goto cleanup;
1189            }
1190            if ((rs = mysql_store_result(db)) == NULL)
1191            {
1192                    log_error("Get reply info failed\n");
1193                    ret = -1;
1194                    goto cleanup;
1195            }
1196    
1197            while ((row = mysql_fetch_row(rs)))
1198            {
1199                    // Send notification message
1200                    len_msg = snprintf(msg, BBS_msg_max_len,
1201                                                       "有人回复了您所发表/回复的文章,快来"
1202                                                       "[article %d]看看[/article]《%s》吧!\n",
1203                                                       p_article_new->aid, title_f);
1204    
1205                    mysql_real_escape_string(db, msg_f, msg, (unsigned long)len_msg);
1206    
1207                    snprintf(sql, sizeof(sql),
1208                                     "INSERT INTO bbs_msg(fromUID, toUID, content, send_dt, send_ip) "
1209                                     "VALUES(%d, %d, '%s', NOW(), '%s')",
1210                                     BBS_sys_id, atoi(row[0]), msg_f, hostaddr_client);
1211    
1212                    if (mysql_query(db, sql) != 0)
1213                    {
1214                            log_error("Insert msg error: %s\n", mysql_error(db));
1215                            ret = -1;
1216                            goto cleanup;
1217                    }
1218            }
1219            mysql_free_result(rs);
1220            rs = NULL;
1221    
1222          // Add exp          // Add exp
1223          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
1224          {          {


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

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