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