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

Diff of /lbbs/src/section_list_display.c

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

Revision 1.38 by sysadm, Tue Jun 24 12:32:16 2025 UTC Revision 1.45 by sysadm, Sat Oct 4 03:21:59 2025 UTC
# Line 15  Line 15 
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "article_cache.h"  #include "article_cache.h"
18    #include "article_op.h"
19  #include "article_post.h"  #include "article_post.h"
20  #include "article_view_log.h"  #include "article_view_log.h"
21  #include "article_del.h"  #include "article_del.h"
# Line 38  static int section_topic_view_tid = -1; Line 39  static int section_topic_view_tid = -1;
39  enum select_cmd_t  enum select_cmd_t
40  {  {
41          EXIT_SECTION = 0,          EXIT_SECTION = 0,
42          VIEW_ARTICLE = 1,          VIEW_ARTICLE,
43          CHANGE_PAGE = 2,          CHANGE_PAGE,
44          SHOW_HELP = 3,          SHOW_HELP,
45          CHANGE_NAME_DISPLAY = 4,          CHANGE_NAME_DISPLAY,
46          POST_ARTICLE = 5,          POST_ARTICLE,
47          EDIT_ARTICLE = 6,          EDIT_ARTICLE,
48          DELETE_ARTICLE = 7,          DELETE_ARTICLE,
49          FIRST_TOPIC_ARTICLE = 8,          QUERY_ARTICLE,
50          LAST_TOPIC_ARTICLE = 9,          FIRST_TOPIC_ARTICLE,
51          VIEW_EX_DIR = 10,          LAST_TOPIC_ARTICLE,
52            SCAN_NEW_ARTICLE,
53            VIEW_EX_DIR,
54  };  };
55    
56  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)
# Line 59  static int section_list_draw_items(int p Line 62  static int section_list_draw_items(int p
62          int eol;          int eol;
63          int len;          int len;
64          int i;          int i;
65            size_t j;
66          char article_flag;          char article_flag;
67          int is_viewed;          int is_viewed;
68          time_t tm_now;          time_t tm_now;
# Line 106  static int section_list_draw_items(int p Line 110  static int section_list_draw_items(int p
110                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);
111                  }                  }
112    
113                  strncpy(title_f, (p_articles[i]->tid == 0 ? " " : ""), sizeof(title_f) - 1);                  strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);
114                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
115                  strncat(title_f, (p_articles[i]->transship ? "[ת]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));                  strncat(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
116                  strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));  
117                    // Rewrite title with "Re: Re: " prefix into "Re: ... "
118                    j = 0;
119                    if (p_articles[i]->tid != 0)
120                    {
121                            while (strncmp(p_articles[i]->title + j, "Re: ", strlen("Re: ")) == 0)
122                            {
123                                    j += strlen("Re: ");
124                            }
125                            if (j >= strlen("Re: Re: "))
126                            {
127                                    strncat(title_f, "Re: ... ", sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
128                            }
129                            else
130                            {
131                                    j = 0;
132                            }
133                    }
134                    strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
135    
136                  len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len, 1);                  len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len, 1);
137                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
138                  {                  {
# Line 119  static int section_list_draw_items(int p Line 142  static int section_list_draw_items(int p
142                  moveto(4 + i, 1);                  moveto(4 + i, 1);
143                  if (i >= ontop_start_offset)                  if (i >= ontop_start_offset)
144                  {                  {
145                          prints("   \033[1;33m[ʾ]\033[m %c %s%*s %s %s%s\033[m",                          prints("   \033[1;33m[提示]\033[m %c %s%*s %s %s%s\033[m",
146                                     article_flag,                                     article_flag,
147                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
148                                     (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
149                                                                           : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),                                                                           : BBS_username_max_len - str_length(p_articles[i]->username, 1)),
150                                     "",                                     "",
151                                     str_time,                                     str_time,
152                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
# Line 144  static int section_list_draw_items(int p Line 167  static int section_list_draw_items(int p
167                                     p_articles[i]->aid,                                     p_articles[i]->aid,
168                                     article_flag,                                     article_flag,
169                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
170                                     (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
171                                                                           : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),                                                                           : BBS_username_max_len - str_length(p_articles[i]->username, 1)),
172                                     "",                                     "",
173                                     str_time,                                     str_time,
174                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
# Line 162  static int section_list_draw_items(int p Line 185  static int section_list_draw_items(int p
185    
186  static int section_list_draw_screen(const char *sname, const char *stitle, const char *master_list, int display_nickname)  static int section_list_draw_screen(const char *sname, const char *stitle, const char *master_list, int display_nickname)
187  {  {
188          char str_section_master[LINE_BUFFER_LEN] = "";          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";
189          char str_section_name[LINE_BUFFER_LEN];          char str_section_name[LINE_BUFFER_LEN];
190    
191          if (master_list[0] != '\0')          if (master_list[0] != '\0')
192          {          {
193                  snprintf(str_section_master, sizeof(str_section_master), "%s", master_list);                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list);
194          }          }
195          snprintf(str_section_name, sizeof(str_section_name), " [%s]", sname);          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);
196    
197          clearscr();          clearscr();
198          show_top(str_section_master, stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
199          moveto(2, 0);          moveto(2, 0);
200          prints("[\033[1;32m\033[0;37m,\033[1;32mESC\033[0;37m] ѡ[\033[1;32m\033[0;37m,\033[1;32m\033[0;37m] "          prints("返回[\033[1;32m←\033[0;37m,\033[1;32mESC\033[0;37m] 选择[\033[1;32m↑\033[0;37m,\033[1;32m↓\033[0;37m] "
201                     "Ķ[\033[1;32m\033[0;37m,\033[1;32mENTER\033[0;37m] [\033[1;32mCtrl-P\033[0;37m] "                     "阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 发表[\033[1;32mCtrl-P\033[0;37m] "
202                     "%s[\033[1;32mn\033[0;37m] [\033[1;32mx\033[0;37m] [\033[1;32mh\033[0;37m]\033[m",                     "%s[\033[1;32mn\033[0;37m] 精华区[\033[1;32mx\033[0;37m] 帮助[\033[1;32mh\033[0;37m]\033[m",
203                     (display_nickname ? "û" : "dz"));                     (display_nickname ? "用户名" : "昵称"));
204          moveto(3, 0);          moveto(3, 0);
205          if (display_nickname)          if (display_nickname)
206          {          {
207                  prints("\033[44;37m  \033[1;37m     dz              ±                               \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发布者昵称           日  期  文章标题                               \033[m");
208          }          }
209          else          else
210          {          {
211                  prints("\033[44;37m  \033[1;37m            ±                                       \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文章标题                                       \033[m");
212          }          }
213    
214          return 0;          return 0;
# Line 238  static enum select_cmd_t section_list_se Line 261  static enum select_cmd_t section_list_se
261                  case Ctrl('P'):                  case Ctrl('P'):
262                          return POST_ARTICLE;                          return POST_ARTICLE;
263                  case 'E':                  case 'E':
264                          return EDIT_ARTICLE;                          if (item_count > 0)
265                            {
266                                    return EDIT_ARTICLE;
267                            }
268                            break;
269                  case 'd':                  case 'd':
270                          return DELETE_ARTICLE;                          if (item_count > 0)
271                            {
272                                    return DELETE_ARTICLE;
273                            }
274                            break;
275                    case Ctrl('Q'):
276                            if (item_count > 0)
277                            {
278                                    return QUERY_ARTICLE;
279                            }
280                            break;
281                  case KEY_HOME:                  case KEY_HOME:
282                          *p_page_id = 0;                          *p_page_id = 0;
283                  case 'P':                  case 'P':
# Line 255  static enum select_cmd_t section_list_se Line 292  static enum select_cmd_t section_list_se
292                                          (*p_page_id)--;                                          (*p_page_id)--;
293                                          *p_selected_index = BBS_article_limit_per_page - 1;                                          *p_selected_index = BBS_article_limit_per_page - 1;
294                                  }                                  }
295                                    else if (ch == KEY_UP || ch == 'k') // Rotate to the tail of section list
296                                    {
297                                            if (total_page > 0)
298                                            {
299                                                    *p_page_id = total_page - 1;
300                                            }
301                                            if (item_count > 0)
302                                            {
303                                                    *p_selected_index = item_count - 1;
304                                            }
305                                    }
306                          }                          }
307                          else                          else
308                          {                          {
# Line 282  static enum select_cmd_t section_list_se Line 330  static enum select_cmd_t section_list_se
330                                          (*p_page_id)++;                                          (*p_page_id)++;
331                                          *p_selected_index = 0;                                          *p_selected_index = 0;
332                                  }                                  }
333                                  else // end of last page                                  else if (ch == KEY_DOWN || ch == 'j') // Rotate to the head of section list
334                                  {                                  {
335                                          return CHANGE_PAGE; // force refresh pages                                          *p_page_id = 0;
336                                            *p_selected_index = 0;
337                                  }                                  }
338                          }                          }
339                          else                          else
# Line 293  static enum select_cmd_t section_list_se Line 342  static enum select_cmd_t section_list_se
342                          }                          }
343                          break;                          break;
344                  case '=':                  case '=':
345                          return FIRST_TOPIC_ARTICLE;                          if (item_count > 0)
346                            {
347                                    return FIRST_TOPIC_ARTICLE;
348                            }
349                            break;
350                  case '\\':                  case '\\':
351                          return LAST_TOPIC_ARTICLE;                          if (item_count > 0)
352                            {
353                                    return LAST_TOPIC_ARTICLE;
354                            }
355                            break;
356                    case 'S':
357                            if (item_count > 0)
358                            {
359                                    return SCAN_NEW_ARTICLE;
360                            }
361                            break;
362                  case 'h':                  case 'h':
363                          return SHOW_HELP;                          return SHOW_HELP;
364                  case 'x':                  case 'x':
# Line 346  static int display_article_key_handler(i Line 409  static int display_article_key_handler(i
409                  if (section_topic_view_mode)                  if (section_topic_view_mode)
410                  {                  {
411                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
412                                           "| [\033[32m\033[33m,\033[32mESC\033[33m] "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
413                                           "ͬĶ[\033[32m\033[33m/\033[32m\033[33m] "                                           "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] "
414                                           "л[\033[32mp\033[33m] ظ[\033[32mr\033[33m] [\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
415                  }                  }
416                  else                  else
417                  {                  {
418                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
419                                           "| [\033[32m\033[33m,\033[32mESC\033[33m] "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
420                                           "ƶ[\033[32m\033[33m/\033[32m\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] "                                           "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] "
421                                           "л[\033[32mp\033[33m] ظ[\033[32mr\033[33m] [\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
422                  }                  }
423                  *p_key = 0;                  *p_key = 0;
424                  break;                  break;
# Line 442  int section_list_display(const char *sna Line 505  int section_list_display(const char *sna
505          int direction;          int direction;
506          ARTICLE article_new;          ARTICLE article_new;
507          int page_id_cur;          int page_id_cur;
508            const ARTICLE *p_article_unread;
509    
510          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
511          if (p_section == NULL)          if (p_section == NULL)
# Line 495  int section_list_display(const char *sna Line 559  int section_list_display(const char *sna
559                  }                  }
560    
561                  snprintf(page_info_str, sizeof(page_info_str),                  snprintf(page_info_str, sizeof(page_info_str),
562                                   "\033[33m[\033[36m%d\033[33m/\033[36m%d\033[33mҳ]",                                   "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",
563                                   page_id + 1, MAX(page_count, 1));                                   page_id + 1, MAX(page_count, 1));
564    
565                  show_bottom(page_info_str);                  show_bottom(page_info_str);
# Line 774  int section_list_display(const char *sna Line 838  int section_list_display(const char *sna
838                                  return -2;                                  return -2;
839                          }                          }
840                          break;                          break;
841                    case QUERY_ARTICLE:
842                            if ((ret = display_article_meta(p_articles[selected_index]->aid)) < 0)
843                            {
844                                    log_error("display_article_meta(aid=%d) error\n", p_articles[selected_index]->aid);
845                            }
846                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
847                            {
848                                    log_error("section_list_draw_screen() error\n");
849                                    return -2;
850                            }
851                            break;
852                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
853                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
854                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 796  int section_list_display(const char *sna Line 871  int section_list_display(const char *sna
871                                  }                                  }
872                          }                          }
873                          break;                          break;
874                    case SCAN_NEW_ARTICLE:
875                            ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_unread);
876                            if (ret < 0)
877                            {
878                                    log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n",
879                                                      p_section->sid, p_articles[selected_index]->aid);
880                                    return -3;
881                            }
882                            else if (ret == 0) // not found
883                            {
884                                    break;
885                            }
886                            page_id_cur = page_id;
887                            ret = locate_article_in_section(p_section, p_article_unread, 0, 0,
888                                                                                            &page_id, &selected_index, &article_count);
889                            if (ret < 0)
890                            {
891                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
892                                                      p_section->sid, p_article_unread->aid);
893                                    return -3;
894                            }
895                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
896                            {
897                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
898                                    if (ret < 0)
899                                    {
900                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
901                                            return -3;
902                                    }
903                            }
904                            break;
905                  case SHOW_HELP:                  case SHOW_HELP:
906                          // Display help information                          // Display help information
907                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
# Line 835  int section_list_ex_dir_display(SECTION_ Line 941  int section_list_ex_dir_display(SECTION_
941                  return -1;                  return -1;
942          }          }
943    
944            if (p_section->ex_menu_tm == 0) // N/A
945            {
946                    moveto(2, 1);
947                    clrtoeol();
948                    prints("该版块精华区未开放");
949                    press_any_key();
950                    return 0;
951            }
952    
953          if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0)          if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0)
954          {          {
955                  log_error("get_section_ex_menu_set(sid=%d) error\n", p_section->sid);                  log_error("get_section_ex_menu_set(sid=%d) error\n", p_section->sid);
# Line 842  int section_list_ex_dir_display(SECTION_ Line 957  int section_list_ex_dir_display(SECTION_
957          }          }
958          if (get_menu_shm_readonly(&ex_menu_set) < 0)          if (get_menu_shm_readonly(&ex_menu_set) < 0)
959          {          {
960                  log_error("set_menu_shm_readonly(sid=%d) error\n", p_section->sid);                  log_error("get_menu_shm_readonly(sid=%d) error\n", p_section->sid);
961                  return -3;                  return -3;
962          }          }
963    


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

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