/[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.33 by sysadm, Fri Oct 17 01:25:08 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    
13  #include "article_cache.h"  #include "article_cache.h"
14  #include "article_post.h"  #include "article_post.h"
15  #include "bbs.h"  #include "bbs.h"
16    #include "bwf.h"
17  #include "database.h"  #include "database.h"
18  #include "editor.h"  #include "editor.h"
19  #include "io.h"  #include "io.h"
# Line 29  Line 26 
26  #include <stdlib.h>  #include <stdlib.h>
27  #include <time.h>  #include <time.h>
28    
29  #define TITLE_INPUT_MAX_LEN 72  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 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,回复通知:%s",                  prints("发表文章于 %s[%s] 讨论区,类型: %s,回复通知: %s",
91                             p_section->stitle, p_section->sname,                             p_section->stitle, p_section->sname,
92                             (p_article_new->transship ? "转载" : "原创"),                             (p_article_new->transship ? "转载" : "原创"),
93                             (reply_note ? "开启" : "关闭"));                             (reply_note ? "开启" : "关闭"));
# Line 111  int article_post(const SECTION_LIST *p_s Line 108  int article_post(const SECTION_LIST *p_s
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 130  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 154  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 174  int article_post(const SECTION_LIST *p_s Line 181  int article_post(const SECTION_LIST *p_s
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 229  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 525  int article_modify(const SECTION_LIST *p Line 539  int article_modify(const SECTION_LIST *p
539                                     (reply_note ? "关闭" : "开启"));                                     (reply_note ? "关闭" : "开启"));
540                          iflush();                          iflush();
541    
542                          ch = igetch_t(MAX_DELAY_TIME);                          ch = igetch_t(BBS_max_user_idle_time);
543                          switch (toupper(ch))                          switch (toupper(ch))
544                          {                          {
545                          case KEY_NULL:                          case KEY_NULL:
# Line 575  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);
# Line 719  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 732  int article_reply(const SECTION_LIST *p_ Line 753  int article_reply(const SECTION_LIST *p_
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;          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 851  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_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);
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, NULL);  
                 for (i = 0; i < quote_content_lines; i++)  
                 {  
                         memcpy(content + len, ": ", 2); // quote line prefix  
                         len += 2;  
                         memcpy(content + len, content_f + line_offsets[i], (size_t)(line_offsets[i + 1] - line_offsets[i]));  
                         len += (line_offsets[i + 1] - line_offsets[i]);  
                         if (content[len - 1] != '\n') // Appennd \n if not exist  
                         {  
                                 content[len] = '\n';  
                                 len++;  
                         }  
                 }  
                 if (content[len - 1] != '\n') // Appennd \n if not exist  
                 {  
                         content[len] = '\n';  
                         len++;  
                 }  
                 content[len] = '\0';  
   
                 free(content_f);  
                 content_f = NULL;  
   
                 p_editor_data = editor_data_load(content);  
                 if (p_editor_data == NULL)  
                 {  
                         log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0]));  
                         ret = -1;  
                         goto cleanup;  
                 }  
   
                 free(content);  
                 content = NULL;  
881          }          }
882          mysql_free_result(rs);          mysql_free_result(rs);
883          rs = NULL;          rs = NULL;
# Line 906  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] 讨论区,回复通知:%s", p_section->stitle, p_section->sname, (reply_note ? "开启" : "关闭"));                  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);
# Line 917  int article_reply(const SECTION_LIST *p_ Line 904  int article_reply(const SECTION_LIST *p_
904                          prints("    按0~3选签名档(0表示不使用)");                          prints("    按0~3选签名档(0表示不使用)");
905    
906                          moveto(24, 1);                          moveto(24, 1);
907                          prints("T改标题, C取消, N%s, Enter继续: ",                          prints("T改标题, C取消, N%s, Q%s, Enter继续: ",
908                                     (reply_note ? "关闭回复通知" : "开启回复通知"));                                     (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 942  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 956  int article_reply(const SECTION_LIST *p_ Line 952  int article_reply(const SECTION_LIST *p_
952                          case 'N':                          case 'N':
953                                  reply_note = (reply_note ? 0 : 1);                                  reply_note = (reply_note ? 0 : 1);
954                                  break;                                  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 963  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 974  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);
# Line 983  int article_reply(const SECTION_LIST *p_ Line 1024  int article_reply(const SECTION_LIST *p_
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 1037  int article_reply(const SECTION_LIST *p_ Line 1078  int article_reply(const SECTION_LIST *p_
1078                  ret = -1;                  ret = -1;
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)


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

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