/[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.1 by sysadm, Wed May 28 07:30:23 2025 UTC Revision 1.36 by sysadm, Mon Jun 23 13:14:15 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "section_list_display.h"  #include "article_cache.h"
18  #include "section_list_loader.h"  #include "article_post.h"
19    #include "article_view_log.h"
20    #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 "login.h"
25    #include "section_list_display.h"
26    #include "section_list_loader.h"
27    #include "screen.h"
28  #include "str_process.h"  #include "str_process.h"
29  #include <time.h>  #include "user_priv.h"
 #define _POSIX_C_SOURCE 200809L  
30  #include <string.h>  #include <string.h>
31    #include <time.h>
32    #include <sys/param.h>
33    
34    static int section_topic_view_mode = 0;
35    static int section_topic_view_tid = -1;
36    
37  enum select_cmd_t  enum select_cmd_t
38  {  {
39          EXIT_SECTION = 0,          EXIT_SECTION = 0,
40          VIEW_ARTICLE = 1,          VIEW_ARTICLE = 1,
41          CHANGE_PAGE = 2,          CHANGE_PAGE = 2,
42          REFRESH_SCREEN = 3,          SHOW_HELP = 3,
43            CHANGE_NAME_DISPLAY = 4,
44            POST_ARTICLE = 5,
45            EDIT_ARTICLE = 6,
46            DELETE_ARTICLE = 7,
47            FIRST_TOPIC_ARTICLE = 8,
48            LAST_TOPIC_ARTICLE = 9,
49  };  };
50    
51  static int section_list_draw_items(SECTION_LIST *p_section, int page_id, ARTICLE *p_articles[], int article_count)  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)
52  {  {
53          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
54          struct tm tm_sub;          struct tm tm_sub;
# Line 42  static int section_list_draw_items(SECTI Line 57  static int section_list_draw_items(SECTI
57          int eol;          int eol;
58          int len;          int len;
59          int i;          int i;
60            char article_flag;
61            int is_viewed;
62            time_t tm_now;
63    
64            time(&tm_now);
65    
66          clrline(4, 23);          clrline(4, 23);
67    
68          for (i = 0; i < article_count; i++)          for (i = 0; i < article_count; i++)
69          {          {
70                    if (p_articles[i]->uid == BBS_priv.uid)
71                    {
72                            is_viewed = 1;
73                    }
74                    else
75                    {
76                            is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log);
77                            if (is_viewed < 0)
78                            {
79                                    log_error("article_view_log_is_viewed(aid=%d) error\n", p_articles[i]->aid);
80                                    is_viewed = 0;
81                            }
82                    }
83    
84                    if (p_articles[i]->excerption)
85                    {
86                            article_flag = (is_viewed ? 'm' : 'M');
87                    }
88                    else if (p_articles[i]->lock && is_viewed)
89                    {
90                            article_flag = 'x';
91                    }
92                    else
93                    {
94                            article_flag = (is_viewed ? ' ' : 'N');
95                    }
96    
97                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);
98                  strftime(str_time, sizeof(str_time), "%b %e", &tm_sub);                  if (tm_now - p_articles[i]->sub_dt < 3600 * 24 * 365)
99                  strncpy(title_f, p_articles[i]->title, sizeof(title_f) - 1);                  {
100                            strftime(str_time, sizeof(str_time), "%b %e ", &tm_sub);
101                    }
102                    else
103                    {
104                            strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);
105                    }
106    
107                    strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);
108                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
109                  len = split_line(title_f, (p_articles[i]->tid == 0 ? 40 : 37), &eol, &title_f_len);                  strncat(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
110                    strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
111                    len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len, 1);
112                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
113                  {                  {
114                          title_f[len] = '\0';                          title_f[len] = '\0';
115                  }                  }
116    
117                  moveto(4 + i, 1);                  moveto(4 + i, 1);
118                  prints("  %7d %s%*s %s  %s%s",                  if (i >= ontop_start_offset)
119                             p_articles[i]->aid,                  {
120                             p_articles[i]->username,                          prints("   \033[1;33m[提示]\033[m %c %s%*s %s %s%s\033[m",
121                             BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username)),                                     article_flag,
122                             "",                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
123                             str_time,                                     (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))
124                             (p_articles[i]->tid == 0 ? "● " : ""),                                                                           : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),
125                             title_f);                                     "",
126                                       str_time,
127                                       (p_articles[i]->aid == section_topic_view_tid
128                                                    ? "\033[1;33m"
129                                                    : (p_articles[i]->tid == section_topic_view_tid
130                                                               ? "\033[1;36m"
131                                                               : "")),
132                                       title_f);
133                    }
134                    else
135                    {
136                            prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",
137                                       (p_articles[i]->aid == section_topic_view_tid
138                                                    ? "\033[1;33m"
139                                                    : (p_articles[i]->tid == section_topic_view_tid
140                                                               ? "\033[1;36m"
141                                                               : "")),
142                                       p_articles[i]->aid,
143                                       article_flag,
144                                       (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
145                                       (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))
146                                                                             : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),
147                                       "",
148                                       str_time,
149                                       (p_articles[i]->aid == section_topic_view_tid
150                                                    ? "\033[1;33m"
151                                                    : (p_articles[i]->tid == section_topic_view_tid
152                                                               ? "\033[1;36m"
153                                                               : "")),
154                                       title_f);
155                    }
156          }          }
157    
158          return 0;          return 0;
159  }  }
160    
161  static int section_list_draw_screen(SECTION_LIST *p_section)  static int section_list_draw_screen(const char *sname, const char *stitle, const char *master_list, int display_nickname)
162  {  {
163          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";
164          char str_section_name[LINE_BUFFER_LEN];          char str_section_name[LINE_BUFFER_LEN];
165    
166          if (p_section->master_list[0] != '\0')          if (master_list[0] != '\0')
167          {          {
168                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", p_section->master_list);                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list);
169          }          }
170          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", p_section->sname);          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);
171    
172          clearscr();          clearscr();
173          show_top(str_section_master, p_section->stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
174          moveto(2, 0);          moveto(2, 0);
175          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] 阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m]\033[m");          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] "
176                       "阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 发表[\033[1;32mCtrl-P\033[0;37m] "
177                       "%s[\033[1;32mn\033[0;37m] 帮助[\033[1;32mh\033[0;37m]\033[m",
178                       (display_nickname ? "显示用户名" : "显示昵称"));
179          moveto(3, 0);          moveto(3, 0);
180          prints("\033[44;37m  \033[1;37m 编 号  发 布 者     日  期  文 章 标 题                                      \033[m");          if (display_nickname)
181          show_bottom("");          {
182                    prints("\033[44;37m  \033[1;37m 编  号   发布者昵称           日  期  文章标题                               \033[m");
183            }
184            else
185            {
186                    prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文章标题                                       \033[m");
187            }
188    
189          return 0;          return 0;
190  }  }
# Line 98  static enum select_cmd_t section_list_se Line 194  static enum select_cmd_t section_list_se
194          int old_page_id = *p_page_id;          int old_page_id = *p_page_id;
195          int old_selected_index = *p_selected_index;          int old_selected_index = *p_selected_index;
196          int ch;          int ch;
197            time_t last_refresh_tm = time(NULL);
         BBS_last_access_tm = time(0);  
198    
199          if (item_count > 0 && *p_selected_index >= 0)          if (item_count > 0 && *p_selected_index >= 0)
200          {          {
# Line 114  static enum select_cmd_t section_list_se Line 209  static enum select_cmd_t section_list_se
209    
210                  switch (ch)                  switch (ch)
211                  {                  {
                 case KEY_NULL: // broken pipe  
212                  case KEY_ESC:                  case KEY_ESC:
213                  case KEY_LEFT:                  case KEY_LEFT:
214                            BBS_last_access_tm = time(NULL);
215                    case KEY_NULL:                   // broken pipe
216                          return EXIT_SECTION; // exit section                          return EXIT_SECTION; // exit section
217                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
218                          if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
219                          {                          {
220                                  return EXIT_SECTION; // exit section                                  return EXIT_SECTION; // exit section
221                          }                          }
222                          continue;                          continue;
223                    case 'n':
224                            BBS_last_access_tm = time(NULL);
225                            return CHANGE_NAME_DISPLAY;
226                  case CR:                  case CR:
227                          igetch_reset();                          igetch_reset();
228                    case 'r':
229                  case KEY_RIGHT:                  case KEY_RIGHT:
230                          if (item_count > 0)                          if (item_count > 0)
231                          {                          {
232                                    BBS_last_access_tm = time(NULL);
233                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
234                          }                          }
235                          break;                          break;
236                    case Ctrl('P'):
237                            return POST_ARTICLE;
238                    case 'E':
239                            return EDIT_ARTICLE;
240                    case 'd':
241                            return DELETE_ARTICLE;
242                  case KEY_HOME:                  case KEY_HOME:
243                          *p_page_id = 0;                          *p_page_id = 0;
244                    case 'P':
245                  case KEY_PGUP:                  case KEY_PGUP:
246                          *p_selected_index = 0;                          *p_selected_index = 0;
247                    case 'k':
248                  case KEY_UP:                  case KEY_UP:
249                          if (*p_selected_index <= 0)                          if (*p_selected_index <= 0)
250                          {                          {
# Line 150  static enum select_cmd_t section_list_se Line 259  static enum select_cmd_t section_list_se
259                                  (*p_selected_index)--;                                  (*p_selected_index)--;
260                          }                          }
261                          break;                          break;
262                    case '$':
263                  case KEY_END:                  case KEY_END:
264                          if (total_page > 0)                          if (total_page > 0)
265                          {                          {
266                                  *p_page_id = total_page - 1;                                  *p_page_id = total_page - 1;
267                          }                          }
268                    case 'N':
269                  case KEY_PGDN:                  case KEY_PGDN:
270                          if (item_count > 0)                          if (item_count > 0)
271                          {                          {
272                                  *p_selected_index = item_count - 1;                                  *p_selected_index = item_count - 1;
273                          }                          }
274                    case 'j':
275                  case KEY_DOWN:                  case KEY_DOWN:
276                          if (*p_selected_index + 1 >= item_count) // next page                          if (*p_selected_index + 1 >= item_count) // next page
277                          {                          {
# Line 168  static enum select_cmd_t section_list_se Line 280  static enum select_cmd_t section_list_se
280                                          (*p_page_id)++;                                          (*p_page_id)++;
281                                          *p_selected_index = 0;                                          *p_selected_index = 0;
282                                  }                                  }
283                                    else // end of last page
284                                    {
285                                            return CHANGE_PAGE; // force refresh pages
286                                    }
287                          }                          }
288                          else                          else
289                          {                          {
290                                  (*p_selected_index)++;                                  (*p_selected_index)++;
291                          }                          }
292                          break;                          break;
293                    case '=':
294                            return FIRST_TOPIC_ARTICLE;
295                    case '\\':
296                            return LAST_TOPIC_ARTICLE;
297                    case 'h':
298                            return SHOW_HELP;
299                  default:                  default:
300                  }                  }
301    
# Line 199  static enum select_cmd_t section_list_se Line 321  static enum select_cmd_t section_list_se
321                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
322                  }                  }
323    
324                  BBS_last_access_tm = time(0);                  BBS_last_access_tm = time(NULL);
325                    if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)
326                    {
327                            return CHANGE_PAGE; // force section list refresh
328                    }
329          }          }
330    
331          return EXIT_SECTION;          return EXIT_SECTION;
332  }  }
333    
334    static int display_article_key_handler(int *p_key, DISPLAY_CTX *p_ctx)
335    {
336            switch (*p_key)
337            {
338            case 'p':
339            case Ctrl('X'):
340                    section_topic_view_mode = !section_topic_view_mode;
341            case 0: // Set msg
342                    if (section_topic_view_mode)
343                    {
344                            snprintf(p_ctx->msg, sizeof(p_ctx->msg),
345                                             "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
346                                             "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] "
347                                             "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
348                    }
349                    else
350                    {
351                            snprintf(p_ctx->msg, sizeof(p_ctx->msg),
352                                             "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
353                                             "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] "
354                                             "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
355                    }
356                    *p_key = 0;
357                    break;
358            case 'r': // Reply article
359                    return 1;
360            case '=': // First topic article
361                    return 1;
362            case '\\': // Last topic article
363                    return 1;
364            case KEY_UP:
365            case KEY_PGUP:
366            case KEY_HOME:
367                    if (p_ctx->reach_begin)
368                    {
369                            if (section_topic_view_mode)
370                            {
371                                    *p_key = KEY_PGUP;
372                            }
373                            else
374                            {
375                                    *p_key = KEY_UP;
376                            }
377                            return 1;
378                    }
379                    break;
380            case 'k':
381                    if (section_topic_view_mode)
382                    {
383                            *p_key = KEY_PGUP;
384                    }
385                    else
386                    {
387                            *p_key = KEY_UP;
388                    }
389                    return 1;
390            case KEY_DOWN:
391            case KEY_PGDN:
392            case KEY_END:
393                    if (p_ctx->reach_end)
394                    {
395                            if (section_topic_view_mode)
396                            {
397                                    *p_key = KEY_PGDN;
398                            }
399                            else
400                            {
401                                    *p_key = KEY_DOWN;
402                            }
403                            return 1;
404                    }
405                    break;
406            case 'j':
407                    if (section_topic_view_mode)
408                    {
409                            *p_key = KEY_PGDN;
410                    }
411                    else
412                    {
413                            *p_key = KEY_DOWN;
414                    }
415                    return 1;
416            }
417    
418            return 0;
419    }
420    
421  int section_list_display(const char *sname)  int section_list_display(const char *sname)
422  {  {
423            static int display_nickname = 0;
424    
425          SECTION_LIST *p_section;          SECTION_LIST *p_section;
426            char stitle[BBS_section_title_max_len + 1];
427            char master_list[(BBS_username_max_len + 1) * 3 + 1];
428            char page_info_str[LINE_BUFFER_LEN];
429          ARTICLE *p_articles[BBS_article_limit_per_page];          ARTICLE *p_articles[BBS_article_limit_per_page];
430          int article_count;          int article_count;
431            int page_count;
432            int ontop_start_offset;
433          int page_id = 0;          int page_id = 0;
434          int selected_index = 0;          int selected_index = 0;
435            ARTICLE_CACHE cache;
436          int ret;          int ret;
437            int loop;
438            int direction;
439            ARTICLE article_new;
440            int page_id_cur;
441    
442          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
443          if (p_section == NULL)          if (p_section == NULL)
# Line 221  int section_list_display(const char *sna Line 446  int section_list_display(const char *sna
446                  return -1;                  return -1;
447          }          }
448    
449          if (section_list_draw_screen(p_section) < 0)          if ((ret = section_list_rd_lock(p_section)) < 0)
450            {
451                    log_error("section_list_rd_lock(sid = 0) error\n");
452                    return -2;
453            }
454    
455            strncpy(stitle, p_section->stitle, sizeof(stitle) - 1);
456            stitle[sizeof(stitle) - 1] = '\0';
457            strncpy(master_list, p_section->master_list, sizeof(master_list) - 1);
458            master_list[sizeof(master_list) - 1] = '\0';
459    
460            if ((ret = section_list_rd_unlock(p_section)) < 0)
461            {
462                    log_error("section_list_rd_unlock(sid = 0) error\n");
463                    return -2;
464            }
465    
466            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
467          {          {
468                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
469                  return -2;                  return -2;
470          }          }
471    
472          if (p_section->visible_article_count > 0)          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
473            if (ret < 0)
474          {          {
475                  ret = query_section_articles(p_section, page_id, p_articles, &article_count);                  log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
476                  if (ret < 0)                  return -3;
                 {  
                         log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);  
                         return -3;  
                 }  
477          }          }
478          else // empty section  
479            if (article_count == 0) // empty section
480          {          {
                 article_count = 0;  
481                  selected_index = 0;                  selected_index = 0;
482          }          }
483    
484          while (!SYS_server_exit)          while (!SYS_server_exit)
485          {          {
486                  ret = section_list_draw_items(p_section, page_id, p_articles, article_count);                  ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname, ontop_start_offset);
487                  if (ret < 0)                  if (ret < 0)
488                  {                  {
489                          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);
490                          return -4;                          return -4;
491                  }                  }
492    
493                    snprintf(page_info_str, sizeof(page_info_str),
494                                     "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",
495                                     page_id + 1, MAX(page_count, 1));
496    
497                    show_bottom(page_info_str);
498                  iflush();                  iflush();
499    
500                  ret = section_list_select(p_section->page_count, article_count, &page_id, &selected_index);                  if (user_online_update(sname) < 0)
501                    {
502                            log_error("user_online_update(%s) error\n", sname);
503                    }
504    
505                    ret = section_list_select(page_count, article_count, &page_id, &selected_index);
506                  switch (ret)                  switch (ret)
507                  {                  {
508                  case EXIT_SECTION:                  case EXIT_SECTION:
509                          return 0;                          return 0;
510                  case CHANGE_PAGE:                  case CHANGE_PAGE:
511                          if (p_section->visible_article_count > 0)                          ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
512                            if (ret < 0)
513                            {
514                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
515                                    return -3;
516                            }
517                            if (article_count == 0) // empty section
518                          {                          {
519                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count);                                  selected_index = 0;
520                            }
521                            else if (selected_index >= article_count)
522                            {
523                                    selected_index = article_count - 1;
524                            }
525                            break;
526                    case VIEW_ARTICLE:
527                            do
528                            {
529                                    loop = 0;
530    
531                                    if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_articles[selected_index]) < 0)
532                                    {
533                                            log_error("article_cache_load(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid);
534                                            break;
535                                    }
536    
537                                    if (user_online_update("VIEW_ARTICLE") < 0)
538                                    {
539                                            log_error("user_online_update(VIEW_ARTICLE) error\n");
540                                    }
541    
542                                    ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,
543                                                                       display_article_key_handler, DATA_READ_HELP);
544    
545                                    if (article_cache_unload(&cache) < 0)
546                                    {
547                                            log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid);
548                                            break;
549                                    }
550    
551                                    // Update article_view_log
552                                    if (article_view_log_set_viewed(p_articles[selected_index]->aid, &BBS_article_view_log) < 0)
553                                    {
554                                            log_error("article_view_log_set_viewed(aid=%d) error\n", p_articles[selected_index]->aid);
555                                    }
556    
557                                    switch (ret)
558                                    {
559                                    case KEY_UP:
560                                            if (selected_index <= 0)
561                                            {
562                                                    if (page_id > 0)
563                                                    {
564                                                            page_id--;
565                                                            selected_index = BBS_article_limit_per_page - 1;
566    
567                                                            ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
568                                                            if (ret < 0)
569                                                            {
570                                                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
571                                                                    return -3;
572                                                            }
573    
574                                                            if (article_count != BBS_article_limit_per_page) // page is not full
575                                                            {
576                                                                    selected_index = MAX(0, article_count - 1);
577                                                            }
578                                                            else
579                                                            {
580                                                                    loop = 1;
581                                                            }
582                                                    }
583                                            }
584                                            else
585                                            {
586                                                    selected_index--;
587                                                    loop = 1;
588                                            }
589                                            break;
590                                    case KEY_DOWN:
591                                            if (selected_index + 1 >= article_count) // next page
592                                            {
593                                                    if (page_id + 1 < page_count)
594                                                    {
595                                                            page_id++;
596                                                            selected_index = 0;
597    
598                                                            ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
599                                                            if (ret < 0)
600                                                            {
601                                                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
602                                                                    return -3;
603                                                            }
604    
605                                                            if (article_count == 0) // empty page
606                                                            {
607                                                                    selected_index = 0;
608                                                            }
609                                                            else
610                                                            {
611                                                                    loop = 1;
612                                                            }
613                                                    }
614                                            }
615                                            else
616                                            {
617                                                    selected_index++;
618                                                    loop = 1;
619                                            }
620                                            break;
621                                    case KEY_PGUP:
622                                    case KEY_PGDN:
623                                            direction = (ret == KEY_PGUP ? -1 : 1);
624                                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, 1,
625                                                                                                            &page_id, &selected_index, &article_count);
626                                            if (ret < 0)
627                                            {
628                                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error\n",
629                                                                      p_section->sid, p_articles[selected_index]->aid, direction);
630                                                    return -3;
631                                            }
632                                            else if (ret > 0) // found
633                                            {
634                                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
635                                                    if (ret < 0)
636                                                    {
637                                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
638                                                            return -3;
639                                                    }
640                                                    loop = 1;
641                                            }
642                                            break;
643                                    case 'r': // Reply article
644                                            if (user_online_update("REPLY_ARTICLE") < 0)
645                                            {
646                                                    log_error("user_online_update(REPLY_ARTICLE) error\n");
647                                            }
648    
649                                            if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)
650                                            {
651                                                    log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid);
652                                            }
653                                            loop = 1;
654                                            break;
655                                    case '=':  // First topic article
656                                    case '\\': // Last topic article
657                                            page_id_cur = page_id;
658                                            direction = (ret == '=' ? -1 : 1);
659                                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section,
660                                                                                                            &page_id, &selected_index, &article_count);
661                                            if (ret < 0)
662                                            {
663                                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n",
664                                                                      p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);
665                                                    return -3;
666                                            }
667                                            else if (ret > 0) // found
668                                            {
669                                                    if (page_id != page_id_cur) // page changed
670                                                    {
671                                                            ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
672                                                            if (ret < 0)
673                                                            {
674                                                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
675                                                                    return -3;
676                                                            }
677                                                    }
678                                                    loop = 1;
679                                            }
680                                            break;
681                                    }
682                            } while (loop);
683    
684                            // Update current topic
685                            section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
686    
687                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
688                            {
689                                    log_error("section_list_draw_screen() error\n");
690                                    return -2;
691                            }
692                            break;
693                    case CHANGE_NAME_DISPLAY:
694                            display_nickname = !display_nickname;
695                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
696                            {
697                                    log_error("section_list_draw_screen() error\n");
698                                    return -2;
699                            }
700                            break;
701                    case POST_ARTICLE:
702                            if (user_online_update("POST_ARTICLE") < 0)
703                            {
704                                    log_error("user_online_update(POST_ARTICLE) error\n");
705                            }
706    
707                            if ((ret = article_post(p_section, &article_new)) < 0)
708                            {
709                                    log_error("article_post(sid=%d) error\n", p_section->sid);
710                            }
711                            else if (ret > 0) // New article posted
712                            {
713                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
714                                  if (ret < 0)                                  if (ret < 0)
715                                  {                                  {
716                                          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);
717                                          return -3;                                          return -3;
718                                  }                                  }
719                          }                          }
720                          else // empty section                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
721                          {                          {
722                                  article_count = 0;                                  log_error("section_list_draw_screen() error\n");
723                                  selected_index = 0;                                  return -2;
724                          }                          }
725                          if (selected_index >= article_count)                          break;
726                    case EDIT_ARTICLE:
727                            if (!checkpriv(&BBS_priv, p_section->sid, S_POST) ||
728                                    p_articles[selected_index]->uid != BBS_priv.uid)
729                          {                          {
730                                  selected_index = article_count - 1;                                  break; // No permission
731                            }
732    
733                            if (user_online_update("EDIT_ARTICLE") < 0)
734                            {
735                                    log_error("user_online_update() error\n");
736                            }
737    
738                            if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)
739                            {
740                                    log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);
741                            }
742                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
743                            {
744                                    log_error("section_list_draw_screen() error\n");
745                                    return -2;
746                          }                          }
747                          break;                          break;
748                  case VIEW_ARTICLE:                  case DELETE_ARTICLE:
749                          log_std("Debug: article %d selected\n", p_articles[selected_index]->aid);                          if (!checkpriv(&BBS_priv, p_section->sid, S_POST) ||
750                  case REFRESH_SCREEN:                                  (!checkpriv(&BBS_priv, p_section->sid, S_MAN_S) && p_articles[selected_index]->uid != BBS_priv.uid))
751                          if (section_list_draw_screen(p_section) < 0)                          {
752                                    break; // No permission
753                            }
754                            if ((ret = article_del(p_section, p_articles[selected_index])) < 0)
755                            {
756                                    log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid);
757                            }
758                            else if (ret > 0) // Article deleted
759                            {
760                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
761                                    if (ret < 0)
762                                    {
763                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
764                                            return -3;
765                                    }
766                            }
767                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
768                            {
769                                    log_error("section_list_draw_screen() error\n");
770                                    return -2;
771                            }
772                            break;
773                    case FIRST_TOPIC_ARTICLE:
774                    case LAST_TOPIC_ARTICLE:
775                            page_id_cur = page_id;
776                            direction = (ret == FIRST_TOPIC_ARTICLE ? -1 : 1);
777                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section,
778                                                                                            &page_id, &selected_index, &article_count);
779                            if (ret < 0)
780                            {
781                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n",
782                                                      p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);
783                                    return -3;
784                            }
785                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
786                            {
787                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
788                                    if (ret < 0)
789                                    {
790                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
791                                            return -3;
792                                    }
793                            }
794                            break;
795                    case SHOW_HELP:
796                            // Display help information
797                            display_file(DATA_READ_HELP, 1);
798                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
799                          {                          {
800                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
801                                  return -2;                                  return -2;


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

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