/[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.44 by sysadm, Wed Oct 1 08:58:25 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            VIEW_EX_DIR,
53  };  };
54    
55  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 61  static int section_list_draw_items(int p
61          int eol;          int eol;
62          int len;          int len;
63          int i;          int i;
64            size_t j;
65          char article_flag;          char article_flag;
66          int is_viewed;          int is_viewed;
67          time_t tm_now;          time_t tm_now;
# Line 106  static int section_list_draw_items(int p Line 109  static int section_list_draw_items(int p
109                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);
110                  }                  }
111    
112                  strncpy(title_f, (p_articles[i]->tid == 0 ? " " : ""), sizeof(title_f) - 1);                  strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);
113                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
114                  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)));
115                  strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));  
116                    // Rewrite title with "Re: Re: " prefix into "Re: ... "
117                    j = 0;
118                    if (p_articles[i]->tid != 0)
119                    {
120                            while (strncmp(p_articles[i]->title + j, "Re: ", strlen("Re: ")) == 0)
121                            {
122                                    j += strlen("Re: ");
123                            }
124                            if (j >= strlen("Re: Re: "))
125                            {
126                                    strncat(title_f, "Re: ... ", sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
127                            }
128                            else
129                            {
130                                    j = 0;
131                            }
132                    }
133                    strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
134    
135                  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);
136                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
137                  {                  {
# Line 119  static int section_list_draw_items(int p Line 141  static int section_list_draw_items(int p
141                  moveto(4 + i, 1);                  moveto(4 + i, 1);
142                  if (i >= ontop_start_offset)                  if (i >= ontop_start_offset)
143                  {                  {
144                          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",
145                                     article_flag,                                     article_flag,
146                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
147                                     (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)
148                                                                           : 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)),
149                                     "",                                     "",
150                                     str_time,                                     str_time,
151                                     (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 166  static int section_list_draw_items(int p
166                                     p_articles[i]->aid,                                     p_articles[i]->aid,
167                                     article_flag,                                     article_flag,
168                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
169                                     (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)
170                                                                           : 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)),
171                                     "",                                     "",
172                                     str_time,                                     str_time,
173                                     (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 184  static int section_list_draw_items(int p
184    
185  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)
186  {  {
187          char str_section_master[LINE_BUFFER_LEN] = "";          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";
188          char str_section_name[LINE_BUFFER_LEN];          char str_section_name[LINE_BUFFER_LEN];
189    
190          if (master_list[0] != '\0')          if (master_list[0] != '\0')
191          {          {
192                  snprintf(str_section_master, sizeof(str_section_master), "%s", master_list);                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list);
193          }          }
194          snprintf(str_section_name, sizeof(str_section_name), " [%s]", sname);          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);
195    
196          clearscr();          clearscr();
197          show_top(str_section_master, stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
198          moveto(2, 0);          moveto(2, 0);
199          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] "
200                     "Ķ[\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] "
201                     "%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",
202                     (display_nickname ? "û" : "dz"));                     (display_nickname ? "用户名" : "昵称"));
203          moveto(3, 0);          moveto(3, 0);
204          if (display_nickname)          if (display_nickname)
205          {          {
206                  prints("\033[44;37m  \033[1;37m     dz              ±                               \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发布者昵称           日  期  文章标题                               \033[m");
207          }          }
208          else          else
209          {          {
210                  prints("\033[44;37m  \033[1;37m            ±                                       \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文章标题                                       \033[m");
211          }          }
212    
213          return 0;          return 0;
# Line 238  static enum select_cmd_t section_list_se Line 260  static enum select_cmd_t section_list_se
260                  case Ctrl('P'):                  case Ctrl('P'):
261                          return POST_ARTICLE;                          return POST_ARTICLE;
262                  case 'E':                  case 'E':
263                          return EDIT_ARTICLE;                          if (item_count > 0)
264                            {
265                                    return EDIT_ARTICLE;
266                            }
267                            break;
268                  case 'd':                  case 'd':
269                          return DELETE_ARTICLE;                          if (item_count > 0)
270                            {
271                                    return DELETE_ARTICLE;
272                            }
273                            break;
274                    case Ctrl('Q'):
275                            if (item_count > 0)
276                            {
277                                    return QUERY_ARTICLE;
278                            }
279                            break;
280                  case KEY_HOME:                  case KEY_HOME:
281                          *p_page_id = 0;                          *p_page_id = 0;
282                  case 'P':                  case 'P':
# Line 255  static enum select_cmd_t section_list_se Line 291  static enum select_cmd_t section_list_se
291                                          (*p_page_id)--;                                          (*p_page_id)--;
292                                          *p_selected_index = BBS_article_limit_per_page - 1;                                          *p_selected_index = BBS_article_limit_per_page - 1;
293                                  }                                  }
294                                    else if (ch == KEY_UP || ch == 'k') // Rotate to the tail of section list
295                                    {
296                                            if (total_page > 0)
297                                            {
298                                                    *p_page_id = total_page - 1;
299                                            }
300                                            if (item_count > 0)
301                                            {
302                                                    *p_selected_index = item_count - 1;
303                                            }
304                                    }
305                          }                          }
306                          else                          else
307                          {                          {
# Line 282  static enum select_cmd_t section_list_se Line 329  static enum select_cmd_t section_list_se
329                                          (*p_page_id)++;                                          (*p_page_id)++;
330                                          *p_selected_index = 0;                                          *p_selected_index = 0;
331                                  }                                  }
332                                  else // end of last page                                  else if (ch == KEY_DOWN || ch == 'j') // Rotate to the head of section list
333                                  {                                  {
334                                          return CHANGE_PAGE; // force refresh pages                                          *p_page_id = 0;
335                                            *p_selected_index = 0;
336                                  }                                  }
337                          }                          }
338                          else                          else
# Line 293  static enum select_cmd_t section_list_se Line 341  static enum select_cmd_t section_list_se
341                          }                          }
342                          break;                          break;
343                  case '=':                  case '=':
344                          return FIRST_TOPIC_ARTICLE;                          if (item_count > 0)
345                            {
346                                    return FIRST_TOPIC_ARTICLE;
347                            }
348                            break;
349                  case '\\':                  case '\\':
350                          return LAST_TOPIC_ARTICLE;                          if (item_count > 0)
351                            {
352                                    return LAST_TOPIC_ARTICLE;
353                            }
354                            break;
355                  case 'h':                  case 'h':
356                          return SHOW_HELP;                          return SHOW_HELP;
357                  case 'x':                  case 'x':
# Line 346  static int display_article_key_handler(i Line 402  static int display_article_key_handler(i
402                  if (section_topic_view_mode)                  if (section_topic_view_mode)
403                  {                  {
404                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
405                                           "| [\033[32m\033[33m,\033[32mESC\033[33m] "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
406                                           "ͬĶ[\033[32m\033[33m/\033[32m\033[33m] "                                           "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] "
407                                           "л[\033[32mp\033[33m] ظ[\033[32mr\033[33m] [\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
408                  }                  }
409                  else                  else
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[32mPgUp\033[33m/\033[32mPgDn\033[33m] "                                           "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\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                  *p_key = 0;                  *p_key = 0;
417                  break;                  break;
# Line 495  int section_list_display(const char *sna Line 551  int section_list_display(const char *sna
551                  }                  }
552    
553                  snprintf(page_info_str, sizeof(page_info_str),                  snprintf(page_info_str, sizeof(page_info_str),
554                                   "\033[33m[\033[36m%d\033[33m/\033[36m%d\033[33mҳ]",                                   "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",
555                                   page_id + 1, MAX(page_count, 1));                                   page_id + 1, MAX(page_count, 1));
556    
557                  show_bottom(page_info_str);                  show_bottom(page_info_str);
# Line 774  int section_list_display(const char *sna Line 830  int section_list_display(const char *sna
830                                  return -2;                                  return -2;
831                          }                          }
832                          break;                          break;
833                    case QUERY_ARTICLE:
834                            if ((ret = display_article_meta(p_articles[selected_index]->aid)) < 0)
835                            {
836                                    log_error("display_article_meta(aid=%d) error\n", p_articles[selected_index]->aid);
837                            }
838                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
839                            {
840                                    log_error("section_list_draw_screen() error\n");
841                                    return -2;
842                            }
843                            break;
844                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
845                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
846                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 835  int section_list_ex_dir_display(SECTION_ Line 902  int section_list_ex_dir_display(SECTION_
902                  return -1;                  return -1;
903          }          }
904    
905            if (p_section->ex_menu_tm == 0) // N/A
906            {
907                    moveto(2, 1);
908                    clrtoeol();
909                    prints("该版块精华区未开放");
910                    press_any_key();
911                    return 0;
912            }
913    
914          if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0)          if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0)
915          {          {
916                  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 918  int section_list_ex_dir_display(SECTION_
918          }          }
919          if (get_menu_shm_readonly(&ex_menu_set) < 0)          if (get_menu_shm_readonly(&ex_menu_set) < 0)
920          {          {
921                  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);
922                  return -3;                  return -3;
923          }          }
924    


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

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