/[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.48 by sysadm, Mon Oct 13 07:35:48 2025 UTC Revision 1.58 by sysadm, Wed Oct 29 01:48:46 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"  #include "article_op.h"
20  #include "article_post.h"  #include "article_post.h"
21  #include "article_view_log.h"  #include "article_view_log.h"
# Line 29  Line 30 
30  #include "section_list_loader.h"  #include "section_list_loader.h"
31  #include "screen.h"  #include "screen.h"
32  #include "str_process.h"  #include "str_process.h"
33    #include "user_info_display.h"
34  #include "user_priv.h"  #include "user_priv.h"
35  #include <string.h>  #include <string.h>
36  #include <time.h>  #include <time.h>
# Line 49  enum select_cmd_t Line 51  enum select_cmd_t
51          EDIT_ARTICLE,          EDIT_ARTICLE,
52          DELETE_ARTICLE,          DELETE_ARTICLE,
53          QUERY_ARTICLE,          QUERY_ARTICLE,
54            QUERY_USER,
55            SET_FAVOR_ARTICLE,
56            UNSET_FAVOR_ARTICLE,
57          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
58          LAST_TOPIC_ARTICLE,          LAST_TOPIC_ARTICLE,
59          SCAN_NEW_ARTICLE,          SCAN_NEW_ARTICLE,
# Line 68  static int section_list_draw_items(int p Line 73  static int section_list_draw_items(int p
73          size_t j;          size_t j;
74          char article_flag;          char article_flag;
75          int is_viewed;          int is_viewed;
76            int is_favor;
77          time_t tm_now;          time_t tm_now;
78    
79          time(&tm_now);          time(&tm_now);
# Line 90  static int section_list_draw_items(int p Line 96  static int section_list_draw_items(int p
96                          }                          }
97                  }                  }
98    
99                    if (p_articles[i]->tid == 0)
100                    {
101                            is_favor = article_favor_check(p_articles[i]->aid, &BBS_article_favor);
102                            if (is_favor < 0)
103                            {
104                                    log_error("article_favor_check(aid=%d) error\n", p_articles[i]->aid);
105                                    is_favor = 0;
106                            }
107                    }
108                    else
109                    {
110                            is_favor = 0;
111                    }
112    
113                  if (p_articles[i]->excerption)                  if (p_articles[i]->excerption)
114                  {                  {
115                          article_flag = (is_viewed ? 'm' : 'M');                          article_flag = (is_viewed ? 'm' : 'M');
# Line 136  static int section_list_draw_items(int p Line 156  static int section_list_draw_items(int p
156                  }                  }
157                  strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));                  strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
158    
159                  len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len, 1);                  len = split_line(title_f, 59 - (display_nickname ? BBS_nickname_max_len / 2 : BBS_username_max_len), &eol, &title_f_len, 1);
160                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
161                  {                  {
162                          title_f[len] = '\0';                          title_f[len] = '\0';
# Line 145  static int section_list_draw_items(int p Line 165  static int section_list_draw_items(int p
165                  moveto(4 + i, 1);                  moveto(4 + i, 1);
166                  if (i >= ontop_start_offset)                  if (i >= ontop_start_offset)
167                  {                  {
168                          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",
169                                       (is_favor ? '@' : ' '),
170                                     article_flag,                                     article_flag,
171                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
172                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
# Line 161  static int section_list_draw_items(int p Line 182  static int section_list_draw_items(int p
182                  }                  }
183                  else                  else
184                  {                  {
185                          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",
186                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
187                                                  ? "\033[1;33m"                                                  ? "\033[1;33m"
188                                                  : (p_articles[i]->tid == section_topic_view_tid                                                  : (p_articles[i]->tid == section_topic_view_tid
189                                                             ? "\033[1;36m"                                                             ? "\033[1;36m"
190                                                             : "")),                                                             : "")),
191                                     p_articles[i]->aid,                                     p_articles[i]->aid,
192                                       (is_favor ? '@' : ' '),
193                                     article_flag,                                     article_flag,
194                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
195                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
# Line 235  static enum select_cmd_t section_list_se Line 257  static enum select_cmd_t section_list_se
257          {          {
258                  ch = igetch(100);                  ch = igetch(100);
259    
260                  switch (ch)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
261                  {                  {
                 case KEY_ESC:  
                 case KEY_LEFT:  
262                          BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
263                  case KEY_NULL:                   // broken pipe                  }
264                          return EXIT_SECTION; // exit section  
265                    switch (ch)
266                    {
267                    case KEY_NULL: // broken pipe
268                            log_error("KEY_NULL\n");
269                            return EXIT_SECTION;
270                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
271                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
272                          {                          {
273                                  return EXIT_SECTION; // exit section                                  log_error("User input timeout\n");
274                                    return EXIT_SECTION;
275                          }                          }
276                          continue;                          continue;
277                    case KEY_ESC:
278                    case KEY_LEFT:
279                            return EXIT_SECTION;
280                  case 'n':                  case 'n':
                         BBS_last_access_tm = time(NULL);  
281                          return CHANGE_NAME_DISPLAY;                          return CHANGE_NAME_DISPLAY;
282                  case CR:                  case CR:
                         igetch_reset();  
283                  case 'r':                  case 'r':
284                  case KEY_RIGHT:                  case KEY_RIGHT:
285                          if (item_count > 0)                          if (item_count > 0)
286                          {                          {
                                 BBS_last_access_tm = time(NULL);  
287                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
288                          }                          }
289                          break;                          break;
# Line 281  static enum select_cmd_t section_list_se Line 307  static enum select_cmd_t section_list_se
307                                  return QUERY_ARTICLE;                                  return QUERY_ARTICLE;
308                          }                          }
309                          break;                          break;
310                    case Ctrl('A'):
311                            if (item_count > 0)
312                            {
313                                    return QUERY_USER;
314                            }
315                            break;
316                    case 'F':
317                            if (item_count > 0)
318                            {
319                                    return SET_FAVOR_ARTICLE;
320                            }
321                            break;
322                    case '-':
323                            if (item_count > 0)
324                            {
325                                    return UNSET_FAVOR_ARTICLE;
326                            }
327                            break;
328                  case KEY_HOME:                  case KEY_HOME:
329                          *p_page_id = 0;                          *p_page_id = 0;
330                  case 'P':                  case 'P':
# Line 366  static enum select_cmd_t section_list_se Line 410  static enum select_cmd_t section_list_se
410                          return SHOW_HELP;                          return SHOW_HELP;
411                  case 'x':                  case 'x':
412                          return VIEW_EX_DIR;                          return VIEW_EX_DIR;
413                  case Ctrl('H'):                  case 'H':
414                          return SHOW_TOP10;                          return SHOW_TOP10;
415                  default:                  default:
416                            break;
417                  }                  }
418    
419                  if (old_page_id != *p_page_id)                  if (old_page_id != *p_page_id)
# Line 393  static enum select_cmd_t section_list_se Line 438  static enum select_cmd_t section_list_se
438                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
439                  }                  }
440    
                 BBS_last_access_tm = time(NULL);  
441                  if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)                  if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)
442                  {                  {
443                          return CHANGE_PAGE; // force section list refresh                          return CHANGE_PAGE; // force section list refresh
# Line 513  int section_list_display(const char *sna Line 557  int section_list_display(const char *sna
557          ARTICLE article_new;          ARTICLE article_new;
558          int page_id_cur;          int page_id_cur;
559          const ARTICLE *p_article_locate;          const ARTICLE *p_article_locate;
560            USER_INFO user_info;
561    
562          p_section = section_list_find_by_name(sname, &section_index);          p_section = section_list_find_by_name(sname);
563          if (p_section == NULL)          if (p_section == NULL)
564          {          {
565                  log_error("Section %s not found\n", sname);                  log_error("Section %s not found\n", sname);
566                  return -1;                  return -1;
567          }          }
568    
569          if ((ret = section_list_rd_lock(p_section)) < 0)          if (!checkpriv(&BBS_priv, p_section->sid, S_LIST))
570          {          {
571                  log_error("section_list_rd_lock(sid = 0) error\n");                  log_error("Forbid access to unauthorized section, sid=%d, uid=%d\n",
572                  return -2;                                    p_section->sid, BBS_priv.uid);
573                    return -1;
574          }          }
575    
576          strncpy(stitle, p_section->stitle, sizeof(stitle) - 1);          section_index = get_section_index(p_section);
         stitle[sizeof(stitle) - 1] = '\0';  
         strncpy(master_list, p_section->master_list, sizeof(master_list) - 1);  
         master_list[sizeof(master_list) - 1] = '\0';  
577    
578          if ((ret = section_list_rd_unlock(p_section)) < 0)          if (get_section_info(p_section, NULL, stitle, master_list) < 0)
579          {          {
580                  log_error("section_list_rd_unlock(sid = 0) error\n");                  log_error("get_section_info(sid=%d) error\n", p_section->sid);
581                  return -2;                  return -4;
582          }          }
583    
584          if (aid == 0)          if (aid == 0)
# Line 545  int section_list_display(const char *sna Line 588  int section_list_display(const char *sna
588          else          else
589          {          {
590                  aid_location = aid;                  aid_location = aid;
591          }                }
592    
593          // Locate at article with aid_locate          // Locate at article with aid_locate
594          if (aid_location > 0)          if (aid_location > 0)
# Line 898  int section_list_display(const char *sna Line 941  int section_list_display(const char *sna
941                                  return -2;                                  return -2;
942                          }                          }
943                          break;                          break;
944                    case QUERY_USER:
945                            if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info)) < 0)
946                            {
947                                    log_error("query_user_info_by_uid(uid=%d) error\n", p_articles[selected_index]->uid);
948                                    return -2;
949                            }
950                            else if (ret == 0)
951                            {
952                                    clearscr();
953                                    prints("该用户已升天");
954                                    press_any_key();
955                            }
956                            else if (user_info_display(&user_info) < 0) // && ret > 0
957                            {
958                                    log_error("user_info_display(uid=%d) error\n", p_articles[selected_index]->uid);
959                            }
960    
961                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
962                            {
963                                    log_error("section_list_draw_screen() error\n");
964                                    return -2;
965                            }
966                            break;
967                    case SET_FAVOR_ARTICLE:
968                            ret = article_favor_set(p_articles[selected_index]->tid == 0
969                                                                                    ? p_articles[selected_index]->aid
970                                                                                    : p_articles[selected_index]->tid,
971                                                                            &BBS_article_favor, 1);
972                            if (ret < 0)
973                            {
974                                    log_error("article_favor_set(aid=%d, 1) error\n",
975                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
976                            }
977                            break;
978                    case UNSET_FAVOR_ARTICLE:
979                            ret = article_favor_set(p_articles[selected_index]->tid == 0
980                                                                                    ? p_articles[selected_index]->aid
981                                                                                    : p_articles[selected_index]->tid,
982                                                                            &BBS_article_favor, 0);
983                            if (ret < 0)
984                            {
985                                    log_error("article_favor_set(aid=%d, 0) error\n",
986                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
987                            }
988                            break;
989                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
990                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
991                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 1027  int section_list_ex_dir_display(SECTION_ Line 1115  int section_list_ex_dir_display(SECTION_
1115                  {                  {
1116                          iflush();                          iflush();
1117                          ch = igetch(100);                          ch = igetch(100);
1118    
1119                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
1120                            {
1121                                    BBS_last_access_tm = time(NULL);
1122                            }
1123    
1124                          switch (ch)                          switch (ch)
1125                          {                          {
1126                          case KEY_NULL: // broken pipe                          case KEY_NULL: // broken pipe
1127                                    log_error("KEY_NULL\n");
1128                                  return 0;                                  return 0;
1129                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
1130                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
1131                                  {                                  {
1132                                            log_error("User input timeout\n");
1133                                          return 0;                                          return 0;
1134                                  }                                  }
1135                                  continue;                                  continue;
1136                          case CR:                          case CR:
                                 igetch_reset();  
1137                          default:                          default:
1138                                  switch (menu_control(&ex_menu_set, ch))                                  switch (menu_control(&ex_menu_set, ch))
1139                                  {                                  {
# Line 1057  int section_list_ex_dir_display(SECTION_ Line 1152  int section_list_ex_dir_display(SECTION_
1152                                  }                                  }
1153                          }                          }
1154    
                         BBS_last_access_tm = time(NULL);  
   
1155                          if (ch == EXITMENU)                          if (ch == EXITMENU)
1156                          {                          {
1157                                  break;                                  break;


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

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