/[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.31 by sysadm, Tue Jun 17 07:00:32 2025 UTC Revision 1.37 by sysadm, Tue Jun 24 10:01:24 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
 #define _POSIX_C_SOURCE 200809L  
   
 #include "section_list_display.h"  
 #include "section_list_loader.h"  
17  #include "article_cache.h"  #include "article_cache.h"
18  #include "article_post.h"  #include "article_post.h"
19    #include "article_view_log.h"
20  #include "article_del.h"  #include "article_del.h"
21  #include "common.h"  #include "common.h"
22  #include "io.h"  #include "io.h"
 #include "screen.h"  
23  #include "log.h"  #include "log.h"
24  #include "user_priv.h"  #include "login.h"
25  #include "article_view_log.h"  #include "menu.h"
26    #include "section_list_display.h"
27    #include "section_list_loader.h"
28    #include "screen.h"
29  #include "str_process.h"  #include "str_process.h"
30    #include "user_priv.h"
31  #include <string.h>  #include <string.h>
32  #include <time.h>  #include <time.h>
33  #include <sys/param.h>  #include <sys/param.h>
# Line 47  enum select_cmd_t Line 47  enum select_cmd_t
47          DELETE_ARTICLE = 7,          DELETE_ARTICLE = 7,
48          FIRST_TOPIC_ARTICLE = 8,          FIRST_TOPIC_ARTICLE = 8,
49          LAST_TOPIC_ARTICLE = 9,          LAST_TOPIC_ARTICLE = 9,
50            VIEW_EX_DIR = 10,
51  };  };
52    
53  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname)  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)
54  {  {
55          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
56          struct tm tm_sub;          struct tm tm_sub;
# Line 82  static int section_list_draw_items(int p Line 83  static int section_list_draw_items(int p
83                          }                          }
84                  }                  }
85    
                 article_flag = (is_viewed ? ' ' : 'N');  
   
86                  if (p_articles[i]->excerption)                  if (p_articles[i]->excerption)
87                  {                  {
88                          article_flag = (is_viewed ? 'm' : 'M');                          article_flag = (is_viewed ? 'm' : 'M');
# Line 92  static int section_list_draw_items(int p Line 91  static int section_list_draw_items(int p
91                  {                  {
92                          article_flag = 'x';                          article_flag = 'x';
93                  }                  }
94                    else
95                    {
96                            article_flag = (is_viewed ? ' ' : 'N');
97                    }
98    
99                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);
100                  if (tm_now - p_articles[i]->sub_dt < 3600 * 24 * 365)                  if (tm_now - p_articles[i]->sub_dt < 3600 * 24 * 365)
# Line 114  static int section_list_draw_items(int p Line 117  static int section_list_draw_items(int p
117                  }                  }
118    
119                  moveto(4 + i, 1);                  moveto(4 + i, 1);
120                  prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",                  if (i >= ontop_start_offset)
121                             (p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")),                  {
122                             p_articles[i]->aid,                          prints("   \033[1;33m[提示]\033[m %c %s%*s %s %s%s\033[m",
123                             article_flag,                                     article_flag,
124                             (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
125                             (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))                                     (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))
126                                                                   : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),                                                                           : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),
127                             "",                                     "",
128                             str_time,                                     str_time,
129                             (p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")),                                     (p_articles[i]->aid == section_topic_view_tid
130                             title_f);                                                  ? "\033[1;33m"
131                                                    : (p_articles[i]->tid == section_topic_view_tid
132                                                               ? "\033[1;36m"
133                                                               : "")),
134                                       title_f);
135                    }
136                    else
137                    {
138                            prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",
139                                       (p_articles[i]->aid == section_topic_view_tid
140                                                    ? "\033[1;33m"
141                                                    : (p_articles[i]->tid == section_topic_view_tid
142                                                               ? "\033[1;36m"
143                                                               : "")),
144                                       p_articles[i]->aid,
145                                       article_flag,
146                                       (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))
148                                                                             : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),
149                                       "",
150                                       str_time,
151                                       (p_articles[i]->aid == section_topic_view_tid
152                                                    ? "\033[1;33m"
153                                                    : (p_articles[i]->tid == section_topic_view_tid
154                                                               ? "\033[1;36m"
155                                                               : "")),
156                                       title_f);
157                    }
158          }          }
159    
160          return 0;          return 0;
# Line 146  static int section_list_draw_screen(cons Line 176  static int section_list_draw_screen(cons
176          moveto(2, 0);          moveto(2, 0);
177          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] "
178                     "阅读[\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] "
179                     "%s[\033[1;32mn\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",
180                     (display_nickname ? "显示用户名" : "显示昵称"));                     (display_nickname ? "用户名" : "昵称"));
181          moveto(3, 0);          moveto(3, 0);
182          if (display_nickname)          if (display_nickname)
183          {          {
# Line 268  static enum select_cmd_t section_list_se Line 298  static enum select_cmd_t section_list_se
298                          return LAST_TOPIC_ARTICLE;                          return LAST_TOPIC_ARTICLE;
299                  case 'h':                  case 'h':
300                          return SHOW_HELP;                          return SHOW_HELP;
301                    case 'x':
302                            return VIEW_EX_DIR;
303                  default:                  default:
304                  }                  }
305    
# Line 401  int section_list_display(const char *sna Line 433  int section_list_display(const char *sna
433          ARTICLE *p_articles[BBS_article_limit_per_page];          ARTICLE *p_articles[BBS_article_limit_per_page];
434          int article_count;          int article_count;
435          int page_count;          int page_count;
436            int ontop_start_offset;
437          int page_id = 0;          int page_id = 0;
438          int selected_index = 0;          int selected_index = 0;
439          ARTICLE_CACHE cache;          ARTICLE_CACHE cache;
# Line 440  int section_list_display(const char *sna Line 473  int section_list_display(const char *sna
473                  return -2;                  return -2;
474          }          }
475    
476          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
477          if (ret < 0)          if (ret < 0)
478          {          {
479                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
# Line 454  int section_list_display(const char *sna Line 487  int section_list_display(const char *sna
487    
488          while (!SYS_server_exit)          while (!SYS_server_exit)
489          {          {
490                  ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname);                  ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname, ontop_start_offset);
491                  if (ret < 0)                  if (ret < 0)
492                  {                  {
493                          log_error("section_list_draw_items(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                          log_error("section_list_draw_items(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
# Line 468  int section_list_display(const char *sna Line 501  int section_list_display(const char *sna
501                  show_bottom(page_info_str);                  show_bottom(page_info_str);
502                  iflush();                  iflush();
503    
504                    if (user_online_update(sname) < 0)
505                    {
506                            log_error("user_online_update(%s) error\n", sname);
507                    }
508    
509                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
510                  switch (ret)                  switch (ret)
511                  {                  {
512                  case EXIT_SECTION:                  case EXIT_SECTION:
513                          return 0;                          return 0;
514                  case CHANGE_PAGE:                  case CHANGE_PAGE:
515                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
516                          if (ret < 0)                          if (ret < 0)
517                          {                          {
518                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
# Line 500  int section_list_display(const char *sna Line 538  int section_list_display(const char *sna
538                                          break;                                          break;
539                                  }                                  }
540    
541                                    if (user_online_update("VIEW_ARTICLE") < 0)
542                                    {
543                                            log_error("user_online_update(VIEW_ARTICLE) error\n");
544                                    }
545    
546                                  ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,                                  ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,
547                                                                     display_article_key_handler, DATA_READ_HELP);                                                                     display_article_key_handler, DATA_READ_HELP);
548    
# Line 525  int section_list_display(const char *sna Line 568  int section_list_display(const char *sna
568                                                          page_id--;                                                          page_id--;
569                                                          selected_index = BBS_article_limit_per_page - 1;                                                          selected_index = BBS_article_limit_per_page - 1;
570    
571                                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);                                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
572                                                          if (ret < 0)                                                          if (ret < 0)
573                                                          {                                                          {
574                                                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
# Line 556  int section_list_display(const char *sna Line 599  int section_list_display(const char *sna
599                                                          page_id++;                                                          page_id++;
600                                                          selected_index = 0;                                                          selected_index = 0;
601    
602                                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);                                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
603                                                          if (ret < 0)                                                          if (ret < 0)
604                                                          {                                                          {
605                                                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
# Line 592  int section_list_display(const char *sna Line 635  int section_list_display(const char *sna
635                                          }                                          }
636                                          else if (ret > 0) // found                                          else if (ret > 0) // found
637                                          {                                          {
638                                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);                                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
639                                                  if (ret < 0)                                                  if (ret < 0)
640                                                  {                                                  {
641                                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
# Line 602  int section_list_display(const char *sna Line 645  int section_list_display(const char *sna
645                                          }                                          }
646                                          break;                                          break;
647                                  case 'r': // Reply article                                  case 'r': // Reply article
648                                            if (user_online_update("REPLY_ARTICLE") < 0)
649                                            {
650                                                    log_error("user_online_update(REPLY_ARTICLE) error\n");
651                                            }
652    
653                                          if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)                                          if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)
654                                          {                                          {
655                                                  log_error("article_post(aid=%d, REPLY) error\n", p_articles[selected_index]->aid);                                                  log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid);
656                                          }                                          }
657                                          loop = 1;                                          loop = 1;
658                                          break;                                          break;
# Line 624  int section_list_display(const char *sna Line 672  int section_list_display(const char *sna
672                                          {                                          {
673                                                  if (page_id != page_id_cur) // page changed                                                  if (page_id != page_id_cur) // page changed
674                                                  {                                                  {
675                                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);                                                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
676                                                          if (ret < 0)                                                          if (ret < 0)
677                                                          {                                                          {
678                                                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                                                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
# Line 639  int section_list_display(const char *sna Line 687  int section_list_display(const char *sna
687    
688                          // Update current topic                          // Update current topic
689                          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);
690    
691                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
692                            {
693                                    log_error("section_list_draw_screen() error\n");
694                                    return -2;
695                            }
696                            break;
697                  case CHANGE_NAME_DISPLAY:                  case CHANGE_NAME_DISPLAY:
698                          display_nickname = !display_nickname;                          display_nickname = !display_nickname;
699                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
# Line 648  int section_list_display(const char *sna Line 703  int section_list_display(const char *sna
703                          }                          }
704                          break;                          break;
705                  case POST_ARTICLE:                  case POST_ARTICLE:
706                            if (user_online_update("POST_ARTICLE") < 0)
707                            {
708                                    log_error("user_online_update(POST_ARTICLE) error\n");
709                            }
710    
711                          if ((ret = article_post(p_section, &article_new)) < 0)                          if ((ret = article_post(p_section, &article_new)) < 0)
712                          {                          {
713                                  log_error("article_post(sid=%d) error\n", p_section->sid);                                  log_error("article_post(sid=%d) error\n", p_section->sid);
714                          }                          }
715                          else if (ret > 0) // New article posted                          else if (ret > 0) // New article posted
716                          {                          {
717                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
718                                  if (ret < 0)                                  if (ret < 0)
719                                  {                                  {
720                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
# Line 673  int section_list_display(const char *sna Line 733  int section_list_display(const char *sna
733                          {                          {
734                                  break; // No permission                                  break; // No permission
735                          }                          }
736    
737                            if (user_online_update("EDIT_ARTICLE") < 0)
738                            {
739                                    log_error("user_online_update() error\n");
740                            }
741    
742                          if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)                          if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)
743                          {                          {
744                                  log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);                                  log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);
# Line 695  int section_list_display(const char *sna Line 761  int section_list_display(const char *sna
761                          }                          }
762                          else if (ret > 0) // Article deleted                          else if (ret > 0) // Article deleted
763                          {                          {
764                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
765                                  if (ret < 0)                                  if (ret < 0)
766                                  {                                  {
767                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
# Line 722  int section_list_display(const char *sna Line 788  int section_list_display(const char *sna
788                          }                          }
789                          else if (ret > 0 && page_id != page_id_cur) // found and page changed                          else if (ret > 0 && page_id != page_id_cur) // found and page changed
790                          {                          {
791                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
792                                  if (ret < 0)                                  if (ret < 0)
793                                  {                                  {
794                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);                                          log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
# Line 739  int section_list_display(const char *sna Line 805  int section_list_display(const char *sna
805                                  return -2;                                  return -2;
806                          }                          }
807                          break;                          break;
808                    case VIEW_EX_DIR:
809                            if (section_list_ex_dir_display(p_section) < 0)
810                            {
811                                    log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid);
812                            }
813                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
814                            {
815                                    log_error("section_list_draw_screen() error\n");
816                                    return -2;
817                            }
818                            break;
819                  default:                  default:
820                          log_error("Unknown command %d\n", ret);                          log_error("Unknown command %d\n", ret);
821                  }                  }
# Line 746  int section_list_display(const char *sna Line 823  int section_list_display(const char *sna
823    
824          return 0;          return 0;
825  }  }
826    
827    int section_list_ex_dir_display(SECTION_LIST *p_section)
828    {
829            char str_section_name[LINE_BUFFER_LEN];
830            MENU_SET ex_menu_set;
831            int ch = 0;
832    
833            if (p_section == NULL)
834            {
835                    log_error("NULL pointer error\n");
836                    return -1;
837            }
838    
839            if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0)
840            {
841                    log_error("get_section_ex_menu_set(sid=%d) error\n", p_section->sid);
842                    return -3;
843            }
844            if (get_menu_shm_readonly(&ex_menu_set) < 0)
845            {
846                    log_error("set_menu_shm_readonly(sid=%d) error\n", p_section->sid);
847                    return -3;
848            }
849    
850            snprintf(str_section_name, sizeof(str_section_name), "[%s | 精华区]", p_section->sname);
851    
852            clearscr();
853            show_bottom(str_section_name);
854    
855            if (display_menu(&ex_menu_set) == 0)
856            {
857                    while (!SYS_server_exit)
858                    {
859                            iflush();
860                            ch = igetch(100);
861                            switch (ch)
862                            {
863                            case KEY_NULL: // broken pipe
864                                    return 0;
865                            case KEY_TIMEOUT:
866                                    if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
867                                    {
868                                            return 0;
869                                    }
870                                    continue;
871                            case CR:
872                                    igetch_reset();
873                            default:
874                                    switch (menu_control(&ex_menu_set, ch))
875                                    {
876                                    case EXITMENU:
877                                            ch = EXITMENU;
878                                            break;
879                                    case REDRAW:
880                                            clearscr();
881                                            show_bottom(str_section_name);
882                                            display_menu(&ex_menu_set);
883                                            break;
884                                    case NOREDRAW:
885                                    case UNKNOWN_CMD:
886                                    default:
887                                            break;
888                                    }
889                            }
890    
891                            BBS_last_access_tm = time(NULL);
892    
893                            if (ch == EXITMENU)
894                            {
895                                    break;
896                            }
897                    }
898            }
899    
900            detach_menu_shm(&ex_menu_set);
901    
902            return 0;
903    }


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

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