/[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.40 by sysadm, Wed Jul 2 04:17:33 2025 UTC Revision 1.53 by sysadm, Wed Oct 15 01:05:18 2025 UTC
# Line 15  Line 15 
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "article_cache.h"  #include "article_cache.h"
18    #include "article_favor.h"
19    #include "article_op.h"
20  #include "article_post.h"  #include "article_post.h"
21  #include "article_view_log.h"  #include "article_view_log.h"
22  #include "article_del.h"  #include "article_del.h"
# Line 23  Line 25 
25  #include "log.h"  #include "log.h"
26  #include "login.h"  #include "login.h"
27  #include "menu.h"  #include "menu.h"
28    #include "menu_proc.h"
29  #include "section_list_display.h"  #include "section_list_display.h"
30  #include "section_list_loader.h"  #include "section_list_loader.h"
31  #include "screen.h"  #include "screen.h"
# Line 32  Line 35 
35  #include <time.h>  #include <time.h>
36  #include <sys/param.h>  #include <sys/param.h>
37    
38    static int section_aid_locations[BBS_max_section] = {0};
39  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
40  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
41    
42  enum select_cmd_t  enum select_cmd_t
43  {  {
44          EXIT_SECTION = 0,          EXIT_SECTION = 0,
45          VIEW_ARTICLE = 1,          VIEW_ARTICLE,
46          CHANGE_PAGE = 2,          CHANGE_PAGE,
47          SHOW_HELP = 3,          SHOW_HELP,
48          CHANGE_NAME_DISPLAY = 4,          CHANGE_NAME_DISPLAY,
49          POST_ARTICLE = 5,          POST_ARTICLE,
50          EDIT_ARTICLE = 6,          EDIT_ARTICLE,
51          DELETE_ARTICLE = 7,          DELETE_ARTICLE,
52          FIRST_TOPIC_ARTICLE = 8,          QUERY_ARTICLE,
53          LAST_TOPIC_ARTICLE = 9,          SET_FAVOR_ARTICLE,
54          VIEW_EX_DIR = 10,          UNSET_FAVOR_ARTICLE,
55            FIRST_TOPIC_ARTICLE,
56            LAST_TOPIC_ARTICLE,
57            SCAN_NEW_ARTICLE,
58            VIEW_EX_DIR,
59            SHOW_TOP10,
60  };  };
61    
62  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 68  static int section_list_draw_items(int p
68          int eol;          int eol;
69          int len;          int len;
70          int i;          int i;
71            size_t j;
72          char article_flag;          char article_flag;
73          int is_viewed;          int is_viewed;
74            int is_favor;
75          time_t tm_now;          time_t tm_now;
76    
77          time(&tm_now);          time(&tm_now);
# Line 83  static int section_list_draw_items(int p Line 94  static int section_list_draw_items(int p
94                          }                          }
95                  }                  }
96    
97                    if (p_articles[i]->tid == 0)
98                    {
99                            is_favor = article_favor_check(p_articles[i]->aid, &BBS_article_favor);
100                            if (is_favor < 0)
101                            {
102                                    log_error("article_favor_check(aid=%d) error\n", p_articles[i]->aid);
103                                    is_favor = 0;
104                            }
105                    }
106                    else
107                    {
108                            is_favor = 0;
109                    }
110    
111                  if (p_articles[i]->excerption)                  if (p_articles[i]->excerption)
112                  {                  {
113                          article_flag = (is_viewed ? 'm' : 'M');                          article_flag = (is_viewed ? 'm' : 'M');
# Line 109  static int section_list_draw_items(int p Line 134  static int section_list_draw_items(int p
134                  strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);                  strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);
135                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
136                  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)));
137                  strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));  
138                  len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len, 1);                  // Rewrite title with "Re: Re: " prefix into "Re: ... "
139                    j = 0;
140                    if (p_articles[i]->tid != 0)
141                    {
142                            while (strncmp(p_articles[i]->title + j, "Re: ", strlen("Re: ")) == 0)
143                            {
144                                    j += strlen("Re: ");
145                            }
146                            if (j >= strlen("Re: Re: "))
147                            {
148                                    strncat(title_f, "Re: ... ", sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
149                            }
150                            else
151                            {
152                                    j = 0;
153                            }
154                    }
155                    strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
156    
157                    len = split_line(title_f, 59 - (display_nickname ? BBS_nickname_max_len / 2 : BBS_username_max_len), &eol, &title_f_len, 1);
158                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
159                  {                  {
160                          title_f[len] = '\0';                          title_f[len] = '\0';
# Line 119  static int section_list_draw_items(int p Line 163  static int section_list_draw_items(int p
163                  moveto(4 + i, 1);                  moveto(4 + i, 1);
164                  if (i >= ontop_start_offset)                  if (i >= ontop_start_offset)
165                  {                  {
166                          prints("   \033[1;33m[提示]\033[m %c %s%*s %s %s%s\033[m",                          prints("   \033[1;33m[提示]\033[m%c%c %s%*s %s %s%s\033[m",
167                                       (is_favor ? '@' : ' '),
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 135  static int section_list_draw_items(int p Line 180  static int section_list_draw_items(int p
180                  }                  }
181                  else                  else
182                  {                  {
183                          prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",                          prints("  %s%7d\033[m%c%c %s%*s %s %s%s\033[m",
184                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
185                                                  ? "\033[1;33m"                                                  ? "\033[1;33m"
186                                                  : (p_articles[i]->tid == section_topic_view_tid                                                  : (p_articles[i]->tid == section_topic_view_tid
187                                                             ? "\033[1;36m"                                                             ? "\033[1;36m"
188                                                             : "")),                                                             : "")),
189                                     p_articles[i]->aid,                                     p_articles[i]->aid,
190                                       (is_favor ? '@' : ' '),
191                                     article_flag,                                     article_flag,
192                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
193                                     (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)
194                                                                           : 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)),
195                                     "",                                     "",
196                                     str_time,                                     str_time,
197                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
# Line 238  static enum select_cmd_t section_list_se Line 284  static enum select_cmd_t section_list_se
284                  case Ctrl('P'):                  case Ctrl('P'):
285                          return POST_ARTICLE;                          return POST_ARTICLE;
286                  case 'E':                  case 'E':
287                          return EDIT_ARTICLE;                          if (item_count > 0)
288                            {
289                                    return EDIT_ARTICLE;
290                            }
291                            break;
292                  case 'd':                  case 'd':
293                          return DELETE_ARTICLE;                          if (item_count > 0)
294                            {
295                                    return DELETE_ARTICLE;
296                            }
297                            break;
298                    case Ctrl('Q'):
299                            if (item_count > 0)
300                            {
301                                    return QUERY_ARTICLE;
302                            }
303                            break;
304                    case 'F':
305                            if (item_count > 0)
306                            {
307                                    return SET_FAVOR_ARTICLE;
308                            }
309                            break;
310                    case '-':
311                            if (item_count > 0)
312                            {
313                                    return UNSET_FAVOR_ARTICLE;
314                            }
315                            break;
316                  case KEY_HOME:                  case KEY_HOME:
317                          *p_page_id = 0;                          *p_page_id = 0;
318                  case 'P':                  case 'P':
# Line 255  static enum select_cmd_t section_list_se Line 327  static enum select_cmd_t section_list_se
327                                          (*p_page_id)--;                                          (*p_page_id)--;
328                                          *p_selected_index = BBS_article_limit_per_page - 1;                                          *p_selected_index = BBS_article_limit_per_page - 1;
329                                  }                                  }
330                                    else if (ch == KEY_UP || ch == 'k') // Rotate to the tail of section list
331                                    {
332                                            if (total_page > 0)
333                                            {
334                                                    *p_page_id = total_page - 1;
335                                            }
336                                            if (item_count > 0)
337                                            {
338                                                    *p_selected_index = item_count - 1;
339                                            }
340                                    }
341                          }                          }
342                          else                          else
343                          {                          {
# Line 282  static enum select_cmd_t section_list_se Line 365  static enum select_cmd_t section_list_se
365                                          (*p_page_id)++;                                          (*p_page_id)++;
366                                          *p_selected_index = 0;                                          *p_selected_index = 0;
367                                  }                                  }
368                                  else // end of last page                                  else if (ch == KEY_DOWN || ch == 'j') // Rotate to the head of section list
369                                  {                                  {
370                                          return CHANGE_PAGE; // force refresh pages                                          *p_page_id = 0;
371                                            *p_selected_index = 0;
372                                  }                                  }
373                          }                          }
374                          else                          else
# Line 293  static enum select_cmd_t section_list_se Line 377  static enum select_cmd_t section_list_se
377                          }                          }
378                          break;                          break;
379                  case '=':                  case '=':
380                          return FIRST_TOPIC_ARTICLE;                          if (item_count > 0)
381                            {
382                                    return FIRST_TOPIC_ARTICLE;
383                            }
384                            break;
385                  case '\\':                  case '\\':
386                          return LAST_TOPIC_ARTICLE;                          if (item_count > 0)
387                            {
388                                    return LAST_TOPIC_ARTICLE;
389                            }
390                            break;
391                    case 'S':
392                            if (item_count > 0)
393                            {
394                                    return SCAN_NEW_ARTICLE;
395                            }
396                            break;
397                  case 'h':                  case 'h':
398                          return SHOW_HELP;                          return SHOW_HELP;
399                  case 'x':                  case 'x':
400                          return VIEW_EX_DIR;                          return VIEW_EX_DIR;
401                    case 'H':
402                            return SHOW_TOP10;
403                  default:                  default:
404                  }                  }
405    
# Line 422  static int display_article_key_handler(i Line 522  static int display_article_key_handler(i
522          return 0;          return 0;
523  }  }
524    
525  int section_list_display(const char *sname)  int section_list_display(const char *sname, int32_t aid)
526  {  {
527          static int display_nickname = 0;          static int display_nickname = 0;
528    
529          SECTION_LIST *p_section;          SECTION_LIST *p_section;
530            int64_t section_index;
531            int32_t aid_location;
532          char stitle[BBS_section_title_max_len + 1];          char stitle[BBS_section_title_max_len + 1];
533          char master_list[(BBS_username_max_len + 1) * 3 + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
534          char page_info_str[LINE_BUFFER_LEN];          char page_info_str[LINE_BUFFER_LEN];
# Line 442  int section_list_display(const char *sna Line 544  int section_list_display(const char *sna
544          int direction;          int direction;
545          ARTICLE article_new;          ARTICLE article_new;
546          int page_id_cur;          int page_id_cur;
547            const ARTICLE *p_article_locate;
548    
549          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
550          if (p_section == NULL)          if (p_section == NULL)
# Line 450  int section_list_display(const char *sna Line 553  int section_list_display(const char *sna
553                  return -1;                  return -1;
554          }          }
555    
556            if (!checkpriv(&BBS_priv, p_section->sid, S_LIST))
557            {
558                    log_error("Forbid access to unauthorized section, sid=%d, uid=%d\n",
559                                      p_section->sid, BBS_priv.uid);
560                    return -1;
561            }
562    
563            section_index = get_section_index(p_section);
564    
565          if ((ret = section_list_rd_lock(p_section)) < 0)          if ((ret = section_list_rd_lock(p_section)) < 0)
566          {          {
567                  log_error("section_list_rd_lock(sid = 0) error\n");                  log_error("section_list_rd_lock(sid = 0) error\n");
# Line 467  int section_list_display(const char *sna Line 579  int section_list_display(const char *sna
579                  return -2;                  return -2;
580          }          }
581    
582            if (aid == 0)
583            {
584                    aid_location = section_aid_locations[section_index];
585            }
586            else
587            {
588                    aid_location = aid;
589            }
590    
591            // Locate at article with aid_locate
592            if (aid_location > 0)
593            {
594                    p_article_locate = article_block_find_by_aid(aid_location);
595                    if (p_article_locate == NULL)
596                    {
597                            log_error("article_block_find_by_aid(%d) error\n", aid_location);
598                            return -3;
599                    }
600    
601                    ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
602                                                                                    &page_id, &selected_index, &article_count);
603                    if (ret < 0)
604                    {
605                            log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
606                                              p_section->sid, p_article_locate->aid);
607                            return -3;
608                    }
609            }
610    
611          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
612          {          {
613                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
# Line 480  int section_list_display(const char *sna Line 621  int section_list_display(const char *sna
621                  return -3;                  return -3;
622          }          }
623    
624            section_topic_view_tid = -1;
625    
626          if (article_count == 0) // empty section          if (article_count == 0) // empty section
627          {          {
628                  selected_index = 0;                  selected_index = 0;
629          }          }
630            else if (aid > 0)
631            {
632                    // Update current topic
633                    section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
634    
635                    // Update current aid location
636                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
637            }
638    
639          while (!SYS_server_exit)          while (!SYS_server_exit)
640          {          {
# Line 688  int section_list_display(const char *sna Line 839  int section_list_display(const char *sna
839                          // Update current topic                          // Update current topic
840                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
841    
842                            // Update current aid location
843                            section_aid_locations[section_index] = p_articles[selected_index]->aid;
844    
845                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
846                          {                          {
847                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 774  int section_list_display(const char *sna Line 928  int section_list_display(const char *sna
928                                  return -2;                                  return -2;
929                          }                          }
930                          break;                          break;
931                    case QUERY_ARTICLE:
932                            if ((ret = display_article_meta(p_articles[selected_index]->aid)) < 0)
933                            {
934                                    log_error("display_article_meta(aid=%d) error\n", p_articles[selected_index]->aid);
935                            }
936                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
937                            {
938                                    log_error("section_list_draw_screen() error\n");
939                                    return -2;
940                            }
941                            break;
942                    case SET_FAVOR_ARTICLE:
943                            ret = article_favor_set(p_articles[selected_index]->tid == 0
944                                                                                    ? p_articles[selected_index]->aid
945                                                                                    : p_articles[selected_index]->tid,
946                                                                            &BBS_article_favor, 1);
947                            if (ret < 0)
948                            {
949                                    log_error("article_favor_set(aid=%d, 1) error\n",
950                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
951                            }
952                            break;
953                    case UNSET_FAVOR_ARTICLE:
954                            ret = article_favor_set(p_articles[selected_index]->tid == 0
955                                                                                    ? p_articles[selected_index]->aid
956                                                                                    : p_articles[selected_index]->tid,
957                                                                            &BBS_article_favor, 0);
958                            if (ret < 0)
959                            {
960                                    log_error("article_favor_set(aid=%d, 0) error\n",
961                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
962                            }
963                            break;
964                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
965                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
966                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 796  int section_list_display(const char *sna Line 983  int section_list_display(const char *sna
983                                  }                                  }
984                          }                          }
985                          break;                          break;
986                    case SCAN_NEW_ARTICLE:
987                            ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);
988                            if (ret < 0)
989                            {
990                                    log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n",
991                                                      p_section->sid, p_articles[selected_index]->aid);
992                                    return -3;
993                            }
994                            else if (ret == 0) // not found
995                            {
996                                    break;
997                            }
998                            page_id_cur = page_id;
999                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1000                                                                                            &page_id, &selected_index, &article_count);
1001                            if (ret < 0)
1002                            {
1003                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1004                                                      p_section->sid, p_article_locate->aid);
1005                                    return -3;
1006                            }
1007                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1008                            {
1009                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1010                                    if (ret < 0)
1011                                    {
1012                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1013                                            return -3;
1014                                    }
1015                            }
1016                            break;
1017                  case SHOW_HELP:                  case SHOW_HELP:
1018                          // Display help information                          // Display help information
1019                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
# Line 813  int section_list_display(const char *sna Line 1031  int section_list_display(const char *sna
1031                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1032                          {                          {
1033                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
1034                                    return -2;
1035                            }
1036                            break;
1037                    case SHOW_TOP10:
1038                            show_top10_menu(NULL);
1039                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1040                            {
1041                                    log_error("section_list_draw_screen() error\n");
1042                                  return -2;                                  return -2;
1043                          }                          }
1044                          break;                          break;


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

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