/[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.48 by sysadm, Mon Oct 13 07:35:48 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_op.h"
19  #include "article_post.h"  #include "article_post.h"
20    #include "article_view_log.h"
21  #include "article_del.h"  #include "article_del.h"
22  #include "common.h"  #include "common.h"
23  #include "io.h"  #include "io.h"
 #include "screen.h"  
24  #include "log.h"  #include "log.h"
25  #include "user_priv.h"  #include "login.h"
26  #include "article_view_log.h"  #include "menu.h"
27    #include "menu_proc.h"
28    #include "section_list_display.h"
29    #include "section_list_loader.h"
30    #include "screen.h"
31  #include "str_process.h"  #include "str_process.h"
32    #include "user_priv.h"
33  #include <string.h>  #include <string.h>
34  #include <time.h>  #include <time.h>
35  #include <sys/param.h>  #include <sys/param.h>
36    
37    static int section_aid_locations[BBS_max_section] = {0};
38  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
39  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
40    
41  enum select_cmd_t  enum select_cmd_t
42  {  {
43          EXIT_SECTION = 0,          EXIT_SECTION = 0,
44          VIEW_ARTICLE = 1,          VIEW_ARTICLE,
45          CHANGE_PAGE = 2,          CHANGE_PAGE,
46          SHOW_HELP = 3,          SHOW_HELP,
47          CHANGE_NAME_DISPLAY = 4,          CHANGE_NAME_DISPLAY,
48          POST_ARTICLE = 5,          POST_ARTICLE,
49          EDIT_ARTICLE = 6,          EDIT_ARTICLE,
50          DELETE_ARTICLE = 7,          DELETE_ARTICLE,
51          FIRST_TOPIC_ARTICLE = 8,          QUERY_ARTICLE,
52          LAST_TOPIC_ARTICLE = 9,          FIRST_TOPIC_ARTICLE,
53            LAST_TOPIC_ARTICLE,
54            SCAN_NEW_ARTICLE,
55            VIEW_EX_DIR,
56            SHOW_TOP10,
57  };  };
58    
59  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)
60  {  {
61          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
62          struct tm tm_sub;          struct tm tm_sub;
# Line 58  static int section_list_draw_items(int p Line 65  static int section_list_draw_items(int p
65          int eol;          int eol;
66          int len;          int len;
67          int i;          int i;
68            size_t j;
69          char article_flag;          char article_flag;
70          int is_viewed;          int is_viewed;
71          time_t tm_now;          time_t tm_now;
# Line 82  static int section_list_draw_items(int p Line 90  static int section_list_draw_items(int p
90                          }                          }
91                  }                  }
92    
                 article_flag = (is_viewed ? ' ' : 'N');  
   
93                  if (p_articles[i]->excerption)                  if (p_articles[i]->excerption)
94                  {                  {
95                          article_flag = (is_viewed ? 'm' : 'M');                          article_flag = (is_viewed ? 'm' : 'M');
# Line 92  static int section_list_draw_items(int p Line 98  static int section_list_draw_items(int p
98                  {                  {
99                          article_flag = 'x';                          article_flag = 'x';
100                  }                  }
101                    else
102                    {
103                            article_flag = (is_viewed ? ' ' : 'N');
104                    }
105    
106                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);
107                  if (tm_now - p_articles[i]->sub_dt < 3600 * 24 * 365)                  if (tm_now - p_articles[i]->sub_dt < 3600 * 24 * 365)
# Line 103  static int section_list_draw_items(int p Line 113  static int section_list_draw_items(int p
113                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);
114                  }                  }
115    
116                  strncpy(title_f, (p_articles[i]->tid == 0 ? " " : ""), sizeof(title_f) - 1);                  strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);
117                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
118                  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)));
119                  strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));  
120                    // Rewrite title with "Re: Re: " prefix into "Re: ... "
121                    j = 0;
122                    if (p_articles[i]->tid != 0)
123                    {
124                            while (strncmp(p_articles[i]->title + j, "Re: ", strlen("Re: ")) == 0)
125                            {
126                                    j += strlen("Re: ");
127                            }
128                            if (j >= strlen("Re: Re: "))
129                            {
130                                    strncat(title_f, "Re: ... ", sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
131                            }
132                            else
133                            {
134                                    j = 0;
135                            }
136                    }
137                    strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
138    
139                  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);
140                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
141                  {                  {
# Line 114  static int section_list_draw_items(int p Line 143  static int section_list_draw_items(int p
143                  }                  }
144    
145                  moveto(4 + i, 1);                  moveto(4 + i, 1);
146                  prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",                  if (i >= ontop_start_offset)
147                             (p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")),                  {
148                             p_articles[i]->aid,                          prints("   \033[1;33m[提示]\033[m %c %s%*s %s %s%s\033[m",
149                             article_flag,                                     article_flag,
150                             (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
151                             (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)
152                                                                   : 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)),
153                             "",                                     "",
154                             str_time,                                     str_time,
155                             (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
156                             title_f);                                                  ? "\033[1;33m"
157                                                    : (p_articles[i]->tid == section_topic_view_tid
158                                                               ? "\033[1;36m"
159                                                               : "")),
160                                       title_f);
161                    }
162                    else
163                    {
164                            prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",
165                                       (p_articles[i]->aid == section_topic_view_tid
166                                                    ? "\033[1;33m"
167                                                    : (p_articles[i]->tid == section_topic_view_tid
168                                                               ? "\033[1;36m"
169                                                               : "")),
170                                       p_articles[i]->aid,
171                                       article_flag,
172                                       (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
173                                       (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
174                                                                             : BBS_username_max_len - str_length(p_articles[i]->username, 1)),
175                                       "",
176                                       str_time,
177                                       (p_articles[i]->aid == section_topic_view_tid
178                                                    ? "\033[1;33m"
179                                                    : (p_articles[i]->tid == section_topic_view_tid
180                                                               ? "\033[1;36m"
181                                                               : "")),
182                                       title_f);
183                    }
184          }          }
185    
186          return 0;          return 0;
# Line 132  static int section_list_draw_items(int p Line 188  static int section_list_draw_items(int p
188    
189  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)
190  {  {
191          char str_section_master[LINE_BUFFER_LEN] = "";          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";
192          char str_section_name[LINE_BUFFER_LEN];          char str_section_name[LINE_BUFFER_LEN];
193    
194          if (master_list[0] != '\0')          if (master_list[0] != '\0')
195          {          {
196                  snprintf(str_section_master, sizeof(str_section_master), "%s", master_list);                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list);
197          }          }
198          snprintf(str_section_name, sizeof(str_section_name), " [%s]", sname);          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);
199    
200          clearscr();          clearscr();
201          show_top(str_section_master, stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
202          moveto(2, 0);          moveto(2, 0);
203          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] "
204                     "Ķ[\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] "
205                     "%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",
206                     (display_nickname ? "ʾû" : "ʾdz"));                     (display_nickname ? "用户名" : "昵称"));
207          moveto(3, 0);          moveto(3, 0);
208          if (display_nickname)          if (display_nickname)
209          {          {
210                  prints("\033[44;37m  \033[1;37m     dz              ±                               \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发布者昵称           日  期  文章标题                               \033[m");
211          }          }
212          else          else
213          {          {
214                  prints("\033[44;37m  \033[1;37m            ±                                       \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文章标题                                       \033[m");
215          }          }
216    
217          return 0;          return 0;
# Line 208  static enum select_cmd_t section_list_se Line 264  static enum select_cmd_t section_list_se
264                  case Ctrl('P'):                  case Ctrl('P'):
265                          return POST_ARTICLE;                          return POST_ARTICLE;
266                  case 'E':                  case 'E':
267                          return EDIT_ARTICLE;                          if (item_count > 0)
268                            {
269                                    return EDIT_ARTICLE;
270                            }
271                            break;
272                  case 'd':                  case 'd':
273                          return DELETE_ARTICLE;                          if (item_count > 0)
274                            {
275                                    return DELETE_ARTICLE;
276                            }
277                            break;
278                    case Ctrl('Q'):
279                            if (item_count > 0)
280                            {
281                                    return QUERY_ARTICLE;
282                            }
283                            break;
284                  case KEY_HOME:                  case KEY_HOME:
285                          *p_page_id = 0;                          *p_page_id = 0;
286                  case 'P':                  case 'P':
# Line 225  static enum select_cmd_t section_list_se Line 295  static enum select_cmd_t section_list_se
295                                          (*p_page_id)--;                                          (*p_page_id)--;
296                                          *p_selected_index = BBS_article_limit_per_page - 1;                                          *p_selected_index = BBS_article_limit_per_page - 1;
297                                  }                                  }
298                                    else if (ch == KEY_UP || ch == 'k') // Rotate to the tail of section list
299                                    {
300                                            if (total_page > 0)
301                                            {
302                                                    *p_page_id = total_page - 1;
303                                            }
304                                            if (item_count > 0)
305                                            {
306                                                    *p_selected_index = item_count - 1;
307                                            }
308                                    }
309                          }                          }
310                          else                          else
311                          {                          {
# Line 252  static enum select_cmd_t section_list_se Line 333  static enum select_cmd_t section_list_se
333                                          (*p_page_id)++;                                          (*p_page_id)++;
334                                          *p_selected_index = 0;                                          *p_selected_index = 0;
335                                  }                                  }
336                                  else // end of last page                                  else if (ch == KEY_DOWN || ch == 'j') // Rotate to the head of section list
337                                  {                                  {
338                                          return CHANGE_PAGE; // force refresh pages                                          *p_page_id = 0;
339                                            *p_selected_index = 0;
340                                  }                                  }
341                          }                          }
342                          else                          else
# Line 263  static enum select_cmd_t section_list_se Line 345  static enum select_cmd_t section_list_se
345                          }                          }
346                          break;                          break;
347                  case '=':                  case '=':
348                          return FIRST_TOPIC_ARTICLE;                          if (item_count > 0)
349                            {
350                                    return FIRST_TOPIC_ARTICLE;
351                            }
352                            break;
353                  case '\\':                  case '\\':
354                          return LAST_TOPIC_ARTICLE;                          if (item_count > 0)
355                            {
356                                    return LAST_TOPIC_ARTICLE;
357                            }
358                            break;
359                    case 'S':
360                            if (item_count > 0)
361                            {
362                                    return SCAN_NEW_ARTICLE;
363                            }
364                            break;
365                  case 'h':                  case 'h':
366                          return SHOW_HELP;                          return SHOW_HELP;
367                    case 'x':
368                            return VIEW_EX_DIR;
369                    case Ctrl('H'):
370                            return SHOW_TOP10;
371                  default:                  default:
372                  }                  }
373    
# Line 314  static int display_article_key_handler(i Line 414  static int display_article_key_handler(i
414                  if (section_topic_view_mode)                  if (section_topic_view_mode)
415                  {                  {
416                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
417                                           "| [\033[32m\033[33m,\033[32mESC\033[33m] "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
418                                           "ͬĶ[\033[32m\033[33m/\033[32m\033[33m] "                                           "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] "
419                                           "л[\033[32mp\033[33m] ظ[\033[32mr\033[33m] [\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
420                  }                  }
421                  else                  else
422                  {                  {
423                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
424                                           "| [\033[32m\033[33m,\033[32mESC\033[33m] "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
425                                           "ƶ[\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] "
426                                           "л[\033[32mp\033[33m] ظ[\033[32mr\033[33m] [\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
427                  }                  }
428                  *p_key = 0;                  *p_key = 0;
429                  break;                  break;
# Line 390  static int display_article_key_handler(i Line 490  static int display_article_key_handler(i
490          return 0;          return 0;
491  }  }
492    
493  int section_list_display(const char *sname)  int section_list_display(const char *sname, int32_t aid)
494  {  {
495          static int display_nickname = 0;          static int display_nickname = 0;
496    
497          SECTION_LIST *p_section;          SECTION_LIST *p_section;
498            int64_t section_index;
499            int32_t aid_location;
500          char stitle[BBS_section_title_max_len + 1];          char stitle[BBS_section_title_max_len + 1];
501          char master_list[(BBS_username_max_len + 1) * 3 + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
502          char page_info_str[LINE_BUFFER_LEN];          char page_info_str[LINE_BUFFER_LEN];
503          ARTICLE *p_articles[BBS_article_limit_per_page];          ARTICLE *p_articles[BBS_article_limit_per_page];
504          int article_count;          int article_count;
505          int page_count;          int page_count;
506            int ontop_start_offset;
507          int page_id = 0;          int page_id = 0;
508          int selected_index = 0;          int selected_index = 0;
509          ARTICLE_CACHE cache;          ARTICLE_CACHE cache;
# Line 409  int section_list_display(const char *sna Line 512  int section_list_display(const char *sna
512          int direction;          int direction;
513          ARTICLE article_new;          ARTICLE article_new;
514          int page_id_cur;          int page_id_cur;
515            const ARTICLE *p_article_locate;
516    
517          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname, &section_index);
518          if (p_section == NULL)          if (p_section == NULL)
519          {          {
520                  log_error("Section %s not found\n", sname);                  log_error("Section %s not found\n", sname);
# Line 434  int section_list_display(const char *sna Line 538  int section_list_display(const char *sna
538                  return -2;                  return -2;
539          }          }
540    
541            if (aid == 0)
542            {
543                    aid_location = section_aid_locations[section_index];
544            }
545            else
546            {
547                    aid_location = aid;
548            }      
549    
550            // Locate at article with aid_locate
551            if (aid_location > 0)
552            {
553                    p_article_locate = article_block_find_by_aid(aid_location);
554                    if (p_article_locate == NULL)
555                    {
556                            log_error("article_block_find_by_aid(%d) error\n", aid_location);
557                            return -3;
558                    }
559    
560                    ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
561                                                                                    &page_id, &selected_index, &article_count);
562                    if (ret < 0)
563                    {
564                            log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
565                                              p_section->sid, p_article_locate->aid);
566                            return -3;
567                    }
568            }
569    
570          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
571          {          {
572                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
573                  return -2;                  return -2;
574          }          }
575    
576          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);
577          if (ret < 0)          if (ret < 0)
578          {          {
579                  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);
580                  return -3;                  return -3;
581          }          }
582    
583            section_topic_view_tid = -1;
584    
585          if (article_count == 0) // empty section          if (article_count == 0) // empty section
586          {          {
587                  selected_index = 0;                  selected_index = 0;
588          }          }
589            else if (aid > 0)
590            {
591                    // Update current topic
592                    section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
593    
594                    // Update current aid location
595                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
596            }
597    
598          while (!SYS_server_exit)          while (!SYS_server_exit)
599          {          {
600                  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);
601                  if (ret < 0)                  if (ret < 0)
602                  {                  {
603                          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 462  int section_list_display(const char *sna Line 605  int section_list_display(const char *sna
605                  }                  }
606    
607                  snprintf(page_info_str, sizeof(page_info_str),                  snprintf(page_info_str, sizeof(page_info_str),
608                                   "\033[33m[\033[36m%d\033[33m/\033[36m%d\033[33mҳ]",                                   "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",
609                                   page_id + 1, MAX(page_count, 1));                                   page_id + 1, MAX(page_count, 1));
610    
611                  show_bottom(page_info_str);                  show_bottom(page_info_str);
612                  iflush();                  iflush();
613    
614                    if (user_online_update(sname) < 0)
615                    {
616                            log_error("user_online_update(%s) error\n", sname);
617                    }
618    
619                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
620                  switch (ret)                  switch (ret)
621                  {                  {
622                  case EXIT_SECTION:                  case EXIT_SECTION:
623                          return 0;                          return 0;
624                  case CHANGE_PAGE:                  case CHANGE_PAGE:
625                          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);
626                          if (ret < 0)                          if (ret < 0)
627                          {                          {
628                                  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 648  int section_list_display(const char *sna
648                                          break;                                          break;
649                                  }                                  }
650    
651                                    if (user_online_update("VIEW_ARTICLE") < 0)
652                                    {
653                                            log_error("user_online_update(VIEW_ARTICLE) error\n");
654                                    }
655    
656                                  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,
657                                                                     display_article_key_handler, DATA_READ_HELP);                                                                     display_article_key_handler, DATA_READ_HELP);
658    
# Line 525  int section_list_display(const char *sna Line 678  int section_list_display(const char *sna
678                                                          page_id--;                                                          page_id--;
679                                                          selected_index = BBS_article_limit_per_page - 1;                                                          selected_index = BBS_article_limit_per_page - 1;
680    
681                                                          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);
682                                                          if (ret < 0)                                                          if (ret < 0)
683                                                          {                                                          {
684                                                                  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 709  int section_list_display(const char *sna
709                                                          page_id++;                                                          page_id++;
710                                                          selected_index = 0;                                                          selected_index = 0;
711    
712                                                          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);
713                                                          if (ret < 0)                                                          if (ret < 0)
714                                                          {                                                          {
715                                                                  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 745  int section_list_display(const char *sna
745                                          }                                          }
746                                          else if (ret > 0) // found                                          else if (ret > 0) // found
747                                          {                                          {
748                                                  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);
749                                                  if (ret < 0)                                                  if (ret < 0)
750                                                  {                                                  {
751                                                          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 755  int section_list_display(const char *sna
755                                          }                                          }
756                                          break;                                          break;
757                                  case 'r': // Reply article                                  case 'r': // Reply article
758                                            if (user_online_update("REPLY_ARTICLE") < 0)
759                                            {
760                                                    log_error("user_online_update(REPLY_ARTICLE) error\n");
761                                            }
762    
763                                          if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)                                          if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)
764                                          {                                          {
765                                                  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);
766                                          }                                          }
767                                          loop = 1;                                          loop = 1;
768                                          break;                                          break;
# Line 624  int section_list_display(const char *sna Line 782  int section_list_display(const char *sna
782                                          {                                          {
783                                                  if (page_id != page_id_cur) // page changed                                                  if (page_id != page_id_cur) // page changed
784                                                  {                                                  {
785                                                          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);
786                                                          if (ret < 0)                                                          if (ret < 0)
787                                                          {                                                          {
788                                                                  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 797  int section_list_display(const char *sna
797    
798                          // Update current topic                          // Update current topic
799                          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);
800    
801                            // Update current aid location
802                            section_aid_locations[section_index] = p_articles[selected_index]->aid;
803    
804                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
805                            {
806                                    log_error("section_list_draw_screen() error\n");
807                                    return -2;
808                            }
809                            break;
810                  case CHANGE_NAME_DISPLAY:                  case CHANGE_NAME_DISPLAY:
811                          display_nickname = !display_nickname;                          display_nickname = !display_nickname;
812                          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 816  int section_list_display(const char *sna
816                          }                          }
817                          break;                          break;
818                  case POST_ARTICLE:                  case POST_ARTICLE:
819                            if (user_online_update("POST_ARTICLE") < 0)
820                            {
821                                    log_error("user_online_update(POST_ARTICLE) error\n");
822                            }
823    
824                          if ((ret = article_post(p_section, &article_new)) < 0)                          if ((ret = article_post(p_section, &article_new)) < 0)
825                          {                          {
826                                  log_error("article_post(sid=%d) error\n", p_section->sid);                                  log_error("article_post(sid=%d) error\n", p_section->sid);
827                          }                          }
828                          else if (ret > 0) // New article posted                          else if (ret > 0) // New article posted
829                          {                          {
830                                  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);
831                                  if (ret < 0)                                  if (ret < 0)
832                                  {                                  {
833                                          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 846  int section_list_display(const char *sna
846                          {                          {
847                                  break; // No permission                                  break; // No permission
848                          }                          }
849    
850                            if (user_online_update("EDIT_ARTICLE") < 0)
851                            {
852                                    log_error("user_online_update() error\n");
853                            }
854    
855                          if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)                          if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)
856                          {                          {
857                                  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 874  int section_list_display(const char *sna
874                          }                          }
875                          else if (ret > 0) // Article deleted                          else if (ret > 0) // Article deleted
876                          {                          {
877                                  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);
878                                  if (ret < 0)                                  if (ret < 0)
879                                  {                                  {
880                                          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 708  int section_list_display(const char *sna Line 887  int section_list_display(const char *sna
887                                  return -2;                                  return -2;
888                          }                          }
889                          break;                          break;
890                    case QUERY_ARTICLE:
891                            if ((ret = display_article_meta(p_articles[selected_index]->aid)) < 0)
892                            {
893                                    log_error("display_article_meta(aid=%d) error\n", p_articles[selected_index]->aid);
894                            }
895                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
896                            {
897                                    log_error("section_list_draw_screen() error\n");
898                                    return -2;
899                            }
900                            break;
901                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
902                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
903                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 722  int section_list_display(const char *sna Line 912  int section_list_display(const char *sna
912                          }                          }
913                          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
914                          {                          {
915                                  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);
916                                    if (ret < 0)
917                                    {
918                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
919                                            return -3;
920                                    }
921                            }
922                            break;
923                    case SCAN_NEW_ARTICLE:
924                            ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);
925                            if (ret < 0)
926                            {
927                                    log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n",
928                                                      p_section->sid, p_articles[selected_index]->aid);
929                                    return -3;
930                            }
931                            else if (ret == 0) // not found
932                            {
933                                    break;
934                            }
935                            page_id_cur = page_id;
936                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
937                                                                                            &page_id, &selected_index, &article_count);
938                            if (ret < 0)
939                            {
940                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
941                                                      p_section->sid, p_article_locate->aid);
942                                    return -3;
943                            }
944                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
945                            {
946                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
947                                  if (ret < 0)                                  if (ret < 0)
948                                  {                                  {
949                                          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 960  int section_list_display(const char *sna
960                                  return -2;                                  return -2;
961                          }                          }
962                          break;                          break;
963                    case VIEW_EX_DIR:
964                            if (section_list_ex_dir_display(p_section) < 0)
965                            {
966                                    log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid);
967                            }
968                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
969                            {
970                                    log_error("section_list_draw_screen() error\n");
971                                    return -2;
972                            }
973                            break;
974                    case SHOW_TOP10:
975                            show_top10_menu(NULL);
976                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
977                            {
978                                    log_error("section_list_draw_screen() error\n");
979                                    return -2;
980                            }
981                            break;
982                  default:                  default:
983                          log_error("Unknown command %d\n", ret);                          log_error("Unknown command %d\n", ret);
984                  }                  }
# Line 746  int section_list_display(const char *sna Line 986  int section_list_display(const char *sna
986    
987          return 0;          return 0;
988  }  }
989    
990    int section_list_ex_dir_display(SECTION_LIST *p_section)
991    {
992            MENU_SET ex_menu_set;
993            int ch = 0;
994    
995            if (p_section == NULL)
996            {
997                    log_error("NULL pointer error\n");
998                    return -1;
999            }
1000    
1001            if (p_section->ex_menu_tm == 0) // N/A
1002            {
1003                    moveto(2, 1);
1004                    clrtoeol();
1005                    prints("该版块精华区未开放");
1006                    press_any_key();
1007                    return 0;
1008            }
1009    
1010            if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0)
1011            {
1012                    log_error("get_section_ex_menu_set(sid=%d) error\n", p_section->sid);
1013                    return -3;
1014            }
1015            if (get_menu_shm_readonly(&ex_menu_set) < 0)
1016            {
1017                    log_error("get_menu_shm_readonly(sid=%d) error\n", p_section->sid);
1018                    return -3;
1019            }
1020    
1021            clearscr();
1022            show_bottom("");
1023    
1024            if (display_menu(&ex_menu_set) == 0)
1025            {
1026                    while (!SYS_server_exit)
1027                    {
1028                            iflush();
1029                            ch = igetch(100);
1030                            switch (ch)
1031                            {
1032                            case KEY_NULL: // broken pipe
1033                                    return 0;
1034                            case KEY_TIMEOUT:
1035                                    if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
1036                                    {
1037                                            return 0;
1038                                    }
1039                                    continue;
1040                            case CR:
1041                                    igetch_reset();
1042                            default:
1043                                    switch (menu_control(&ex_menu_set, ch))
1044                                    {
1045                                    case EXITMENU:
1046                                            ch = EXITMENU;
1047                                            break;
1048                                    case REDRAW:
1049                                            clearscr();
1050                                            show_bottom("");
1051                                            display_menu(&ex_menu_set);
1052                                            break;
1053                                    case NOREDRAW:
1054                                    case UNKNOWN_CMD:
1055                                    default:
1056                                            break;
1057                                    }
1058                            }
1059    
1060                            BBS_last_access_tm = time(NULL);
1061    
1062                            if (ch == EXITMENU)
1063                            {
1064                                    break;
1065                            }
1066                    }
1067            }
1068    
1069            detach_menu_shm(&ex_menu_set);
1070    
1071            return 0;
1072    }


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

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