/[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.32 by sysadm, Fri Oct 10 12:31:15 2025 UTC Revision 1.41 by sysadm, Fri Nov 7 06:41:43 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"
11  #include "bbs.h"  #include "bbs.h"
12    #include "bwf.h"
13  #include "database.h"  #include "database.h"
14  #include "editor.h"  #include "editor.h"
15  #include "io.h"  #include "io.h"
# Line 29  Line 22 
22  #include <stdlib.h>  #include <stdlib.h>
23  #include <time.h>  #include <time.h>
24    
25  #define TITLE_INPUT_MAX_LEN 72  enum _article_post_constant_t
26  #define ARTICLE_CONTENT_MAX_LEN 1024 * 1024 * 4 // 4MB  {
27  #define ARTICLE_QUOTE_MAX_LINES 20          TITLE_INPUT_MAX_LEN = 72,
28  #define ARTICLE_QUOTE_LINE_MAX_LEN 76          ARTICLE_QUOTE_MAX_LINES = 20,
29            MODIFY_DT_MAX_LEN = 50,
30  #define MODIFY_DT_MAX_LEN 50  };
31    
32  int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new)  int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new)
33  {  {
# Line 111  int article_post(const SECTION_LIST *p_s Line 104  int article_post(const SECTION_LIST *p_s
104                          ch = 0;                          ch = 0;
105                  }                  }
106    
107                  for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME))                  while (!SYS_server_exit)
108                  {                  {
109                          switch (toupper(ch))                          switch (toupper(ch))
110                          {                          {
# Line 119  int article_post(const SECTION_LIST *p_s Line 112  int article_post(const SECTION_LIST *p_s
112                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
113                                  goto cleanup;                                  goto cleanup;
114                          case CR:                          case CR:
                                 igetch_reset();  
115                                  break;                                  break;
116                          case 'T':                          case 'T':
117                                  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);
# Line 131  int article_post(const SECTION_LIST *p_s Line 123  int article_post(const SECTION_LIST *p_s
123                                  len = q - p;                                  len = q - p;
124                                  if (*p != '\0')                                  if (*p != '\0')
125                                  {                                  {
126                                            if ((ret = check_badwords(p, '*')) < 0)
127                                            {
128                                                    log_error("check_badwords(title) error\n");
129                                            }
130                                            else if (ret > 0)
131                                            {
132                                                    memcpy(title_input, p, (size_t)len + 1);
133                                                    continue;
134                                            }
135                                          memcpy(p_article_new->title, p, (size_t)len + 1);                                          memcpy(p_article_new->title, p, (size_t)len + 1);
136                                          memcpy(title_input, p_article_new->title, (size_t)len + 1);                                          memcpy(title_input, p_article_new->title, (size_t)len + 1);
137                                  }                                  }
# Line 155  int article_post(const SECTION_LIST *p_s Line 156  int article_post(const SECTION_LIST *p_s
156                                  sign_id = ch - '0';                                  sign_id = ch - '0';
157                                  break;                                  break;
158                          default: // Invalid selection                          default: // Invalid selection
159                                    ch = igetch_t(BBS_max_user_idle_time);
160                                  continue;                                  continue;
161                          }                          }
162    
# Line 175  int article_post(const SECTION_LIST *p_s Line 177  int article_post(const SECTION_LIST *p_s
177                          prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: ");                          prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: ");
178                          iflush();                          iflush();
179    
180                          for (ch = 0; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME))                          for (ch = 0; !SYS_server_exit; ch = igetch_t(BBS_max_user_idle_time))
181                          {                          {
182                                  switch (toupper(ch))                                  switch (toupper(ch))
183                                  {                                  {
# Line 183  int article_post(const SECTION_LIST *p_s Line 185  int article_post(const SECTION_LIST *p_s
185                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
186                                          goto cleanup;                                          goto cleanup;
187                                  case CR:                                  case CR:
                                         igetch_reset();  
188                                  case 'S':                                  case 'S':
189                                          break;                                          break;
190                                  case 'C':                                  case 'C':
# Line 231  int article_post(const SECTION_LIST *p_s Line 232  int article_post(const SECTION_LIST *p_s
232                  goto cleanup;                  goto cleanup;
233          }          }
234    
235            if (check_badwords(content, '*') < 0)
236            {
237                    log_error("check_badwords(content) error\n");
238                    ret = -1;
239                    goto cleanup;
240            }
241    
242          db = db_open();          db = db_open();
243          if (db == NULL)          if (db == NULL)
244          {          {
# Line 527  int article_modify(const SECTION_LIST *p Line 535  int article_modify(const SECTION_LIST *p
535                                     (reply_note ? "关闭" : "开启"));                                     (reply_note ? "关闭" : "开启"));
536                          iflush();                          iflush();
537    
538                          ch = igetch_t(MAX_DELAY_TIME);                          ch = igetch_t(BBS_max_user_idle_time);
539                          switch (toupper(ch))                          switch (toupper(ch))
540                          {                          {
541                          case KEY_NULL:                          case KEY_NULL:
542                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
543                                  goto cleanup;                                  goto cleanup;
544                          case CR:                          case CR:
                                 igetch_reset();  
545                          case 'S':                          case 'S':
546                                  break;                                  break;
547                          case 'C':                          case 'C':
# Line 578  int article_modify(const SECTION_LIST *p Line 585  int article_modify(const SECTION_LIST *p
585                  goto cleanup;                  goto cleanup;
586          }          }
587    
588            if (check_badwords(content, '*') < 0)
589            {
590                    log_error("check_badwords(content) error\n");
591                    ret = -1;
592                    goto cleanup;
593            }
594    
595          time(&now);          time(&now);
596          localtime_r(&now, &tm_modify_dt);          localtime_r(&now, &tm_modify_dt);
597          strftime(str_modify_dt, sizeof(str_modify_dt), "%Y-%m-%d %H:%M:%S (UTC %z)", &tm_modify_dt);          strftime(str_modify_dt, sizeof(str_modify_dt), "%Y-%m-%d %H:%M:%S (UTC %z)", &tm_modify_dt);
# Line 854  int article_reply(const SECTION_LIST *p_ Line 868  int article_reply(const SECTION_LIST *p_
868                  }                  }
869    
870                  // Apply LML render to content body                  // Apply LML render to content body
871                  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);
872                  content_f[len] = '\0';                  content_f[len] = '\0';
873    
874                  // Remove control sequence                  // Remove control sequence
# Line 864  int article_reply(const SECTION_LIST *p_ Line 878  int article_reply(const SECTION_LIST *p_
878                                             "\n\n【 在 %s (%s) 的大作中提到: 】\n",                                             "\n\n【 在 %s (%s) 的大作中提到: 】\n",
879                                             p_article->username, p_article->nickname);                                             p_article->username, p_article->nickname);
880    
881                  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);
882                  for (i = 0; i < quote_content_lines; i++)                  for (i = 0; i < quote_content_lines; i++)
883                  {                  {
884                          memcpy(content + len, ": ", 2); // quote line prefix                          memcpy(content + len, ": ", 2); // quote line prefix
# Line 926  int article_reply(const SECTION_LIST *p_ Line 940  int article_reply(const SECTION_LIST *p_
940                          ch = 0;                          ch = 0;
941                  }                  }
942    
943                  for (; !SYS_server_exit; ch = igetch_t(MAX_DELAY_TIME))                  while (!SYS_server_exit)
944                  {                  {
945                          switch (toupper(ch))                          switch (toupper(ch))
946                          {                          {
# Line 934  int article_reply(const SECTION_LIST *p_ Line 948  int article_reply(const SECTION_LIST *p_
948                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
949                                  goto cleanup;                                  goto cleanup;
950                          case CR:                          case CR:
                                 igetch_reset();  
951                                  break;                                  break;
952                          case 'T':                          case 'T':
953                                  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);
# Line 946  int article_reply(const SECTION_LIST *p_ Line 959  int article_reply(const SECTION_LIST *p_
959                                  len = q - p;                                  len = q - p;
960                                  if (*p != '\0')                                  if (*p != '\0')
961                                  {                                  {
962                                            if ((ret = check_badwords(p, '*')) < 0)
963                                            {
964                                                    log_error("check_badwords(title) error\n");
965                                            }
966                                            else if (ret > 0)
967                                            {
968                                                    memcpy(title_input, p, (size_t)len + 1);
969                                                    continue;
970                                            }
971                                          memcpy(p_article_new->title, p, (size_t)len + 1);                                          memcpy(p_article_new->title, p, (size_t)len + 1);
972                                          memcpy(title_input, p_article_new->title, (size_t)len + 1);                                          memcpy(title_input, p_article_new->title, (size_t)len + 1);
973                                  }                                  }
# Line 967  int article_reply(const SECTION_LIST *p_ Line 989  int article_reply(const SECTION_LIST *p_
989                                  sign_id = ch - '0';                                  sign_id = ch - '0';
990                                  break;                                  break;
991                          default: // Invalid selection                          default: // Invalid selection
992                                    ch = igetch_t(BBS_max_user_idle_time);
993                                  continue;                                  continue;
994                          }                          }
995    
# Line 987  int article_reply(const SECTION_LIST *p_ Line 1010  int article_reply(const SECTION_LIST *p_
1010                          prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: ");                          prints("(S)发送, (C)取消, (T)更改标题 or (E)再编辑? [S]: ");
1011                          iflush();                          iflush();
1012    
1013                          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))
1014                          {                          {
1015                                  switch (toupper(ch))                                  switch (toupper(ch))
1016                                  {                                  {
# Line 995  int article_reply(const SECTION_LIST *p_ Line 1018  int article_reply(const SECTION_LIST *p_
1018                                  case KEY_TIMEOUT:                                  case KEY_TIMEOUT:
1019                                          goto cleanup;                                          goto cleanup;
1020                                  case CR:                                  case CR:
                                         igetch_reset();  
1021                                  case 'S':                                  case 'S':
1022                                          break;                                          break;
1023                                  case 'C':                                  case 'C':
# Line 1042  int article_reply(const SECTION_LIST *p_ Line 1064  int article_reply(const SECTION_LIST *p_
1064                  ret = -1;                  ret = -1;
1065                  goto cleanup;                  goto cleanup;
1066          }          }
1067    
1068            if (check_badwords(content, '*') < 0)
1069            {
1070                    log_error("check_badwords(content) error\n");
1071                    ret = -1;
1072                    goto cleanup;
1073            }
1074    
1075          db = db_open();          db = db_open();
1076          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