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