/[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.7 by sysadm, Thu May 29 02:45:23 2025 UTC Revision 1.35 by sysadm, Mon Jun 23 08:38:01 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 "user_priv.h"
30    #include <string.h>
31  #include <time.h>  #include <time.h>
32  #include <sys/param.h>  #include <sys/param.h>
33  #define _POSIX_C_SOURCE 200809L  
34  #include <string.h>  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(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)
# Line 45  static int section_list_draw_items(int p Line 58  static int section_list_draw_items(int p
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 53  static int section_list_draw_items(int p Line 67  static int section_list_draw_items(int p
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                  if (p_articles[i]->excerption)                  if (p_articles[i]->excerption)
85                  {                  {
86                          article_flag = 'm';                          article_flag = (is_viewed ? 'm' : 'M');
87                  }                  }
88                  else if (p_articles[i]->lock)                  else if (p_articles[i]->lock && is_viewed)
89                  {                  {
90                          article_flag = 'x';                          article_flag = 'x';
91                  }                  }
92                    else
93                    {
94                            article_flag = (is_viewed ? ' ' : 'N');
95                    }
96    
97                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);
98                  if (tm_now - p_articles[i]->sub_dt < 3600 * 24 * 365)                  if (tm_now - p_articles[i]->sub_dt < 3600 * 24 * 365)
# Line 78  static int section_list_draw_items(int p Line 108  static int section_list_draw_items(int p
108                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
109                  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)));
110                  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)));
111                  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);
112                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
113                  {                  {
114                          title_f[len] = '\0';                          title_f[len] = '\0';
115                  }                  }
116    
117                  moveto(4 + i, 1);                  moveto(4 + i, 1);
118                  prints("  %7d %c %s%*s %s %s",                  prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",
119                               (p_articles[i]->ontop
120                                            ? "\033[47;30m"
121                                            : (p_articles[i]->aid == section_topic_view_tid
122                                                       ? "\033[1;33m"
123                                                       : (p_articles[i]->tid == section_topic_view_tid
124                                                                      ? "\033[1;36m"
125                                                                      : ""))),
126                             p_articles[i]->aid,                             p_articles[i]->aid,
127                             article_flag,                             article_flag,
128                             (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                             (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
# Line 93  static int section_list_draw_items(int p Line 130  static int section_list_draw_items(int p
130                                                                   : 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))),
131                             "",                             "",
132                             str_time,                             str_time,
133                               (p_articles[i]->aid == section_topic_view_tid
134                                            ? "\033[1;33m"
135                                            : (p_articles[i]->tid == section_topic_view_tid
136                                                       ? "\033[1;36m"
137                                                       : "")),
138                             title_f);                             title_f);
139          }          }
140    
# Line 113  static int section_list_draw_screen(cons Line 155  static int section_list_draw_screen(cons
155          clearscr();          clearscr();
156          show_top(str_section_master, stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
157          moveto(2, 0);          moveto(2, 0);
158          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] "
159                       "阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 发表[\033[1;32mCtrl-P\033[0;37m] "
160                       "%s[\033[1;32mn\033[0;37m] 帮助[\033[1;32mh\033[0;37m]\033[m",
161                       (display_nickname ? "显示用户名" : "显示昵称"));
162          moveto(3, 0);          moveto(3, 0);
163          if (display_nickname)          if (display_nickname)
164          {          {
165                  prints("\033[44;37m  \033[1;37m 编  号   发 布 者 昵 称       日  期  文 章 标 题                            \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发布者昵称           日  期  文章标题                               \033[m");
166          }          }
167          else          else
168          {          {
169                  prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文 章 标 题                                    \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文章标题                                       \033[m");
170          }          }
171    
172          return 0;          return 0;
# Line 132  static enum select_cmd_t section_list_se Line 177  static enum select_cmd_t section_list_se
177          int old_page_id = *p_page_id;          int old_page_id = *p_page_id;
178          int old_selected_index = *p_selected_index;          int old_selected_index = *p_selected_index;
179          int ch;          int ch;
180            time_t last_refresh_tm = time(NULL);
         BBS_last_access_tm = time(0);  
181    
182          if (item_count > 0 && *p_selected_index >= 0)          if (item_count > 0 && *p_selected_index >= 0)
183          {          {
# Line 148  static enum select_cmd_t section_list_se Line 192  static enum select_cmd_t section_list_se
192    
193                  switch (ch)                  switch (ch)
194                  {                  {
                 case KEY_NULL: // broken pipe  
195                  case KEY_ESC:                  case KEY_ESC:
196                  case KEY_LEFT:                  case KEY_LEFT:
197                            BBS_last_access_tm = time(NULL);
198                    case KEY_NULL:                   // broken pipe
199                          return EXIT_SECTION; // exit section                          return EXIT_SECTION; // exit section
200                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
201                          if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
202                          {                          {
203                                  return EXIT_SECTION; // exit section                                  return EXIT_SECTION; // exit section
204                          }                          }
205                          continue;                          continue;
206                  case 'n':                  case 'n':
207                            BBS_last_access_tm = time(NULL);
208                          return CHANGE_NAME_DISPLAY;                          return CHANGE_NAME_DISPLAY;
209                  case CR:                  case CR:
210                          igetch_reset();                          igetch_reset();
211                    case 'r':
212                  case KEY_RIGHT:                  case KEY_RIGHT:
213                          if (item_count > 0)                          if (item_count > 0)
214                          {                          {
215                                    BBS_last_access_tm = time(NULL);
216                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
217                          }                          }
218                          break;                          break;
219                    case Ctrl('P'):
220                            return POST_ARTICLE;
221                    case 'E':
222                            return EDIT_ARTICLE;
223                    case 'd':
224                            return DELETE_ARTICLE;
225                  case KEY_HOME:                  case KEY_HOME:
226                          *p_page_id = 0;                          *p_page_id = 0;
227                    case 'P':
228                  case KEY_PGUP:                  case KEY_PGUP:
229                          *p_selected_index = 0;                          *p_selected_index = 0;
230                    case 'k':
231                  case KEY_UP:                  case KEY_UP:
232                          if (*p_selected_index <= 0)                          if (*p_selected_index <= 0)
233                          {                          {
# Line 186  static enum select_cmd_t section_list_se Line 242  static enum select_cmd_t section_list_se
242                                  (*p_selected_index)--;                                  (*p_selected_index)--;
243                          }                          }
244                          break;                          break;
245                    case '$':
246                  case KEY_END:                  case KEY_END:
247                          if (total_page > 0)                          if (total_page > 0)
248                          {                          {
249                                  *p_page_id = total_page - 1;                                  *p_page_id = total_page - 1;
250                          }                          }
251                    case 'N':
252                  case KEY_PGDN:                  case KEY_PGDN:
253                          if (item_count > 0)                          if (item_count > 0)
254                          {                          {
255                                  *p_selected_index = item_count - 1;                                  *p_selected_index = item_count - 1;
256                          }                          }
257                    case 'j':
258                  case KEY_DOWN:                  case KEY_DOWN:
259                          if (*p_selected_index + 1 >= item_count) // next page                          if (*p_selected_index + 1 >= item_count) // next page
260                          {                          {
# Line 204  static enum select_cmd_t section_list_se Line 263  static enum select_cmd_t section_list_se
263                                          (*p_page_id)++;                                          (*p_page_id)++;
264                                          *p_selected_index = 0;                                          *p_selected_index = 0;
265                                  }                                  }
266                                    else // end of last page
267                                    {
268                                            return CHANGE_PAGE; // force refresh pages
269                                    }
270                          }                          }
271                          else                          else
272                          {                          {
273                                  (*p_selected_index)++;                                  (*p_selected_index)++;
274                          }                          }
275                          break;                          break;
276                    case '=':
277                            return FIRST_TOPIC_ARTICLE;
278                    case '\\':
279                            return LAST_TOPIC_ARTICLE;
280                    case 'h':
281                            return SHOW_HELP;
282                  default:                  default:
283                  }                  }
284    
# Line 235  static enum select_cmd_t section_list_se Line 304  static enum select_cmd_t section_list_se
304                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
305                  }                  }
306    
307                  BBS_last_access_tm = time(0);                  BBS_last_access_tm = time(NULL);
308                    if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)
309                    {
310                            return CHANGE_PAGE; // force section list refresh
311                    }
312          }          }
313    
314          return EXIT_SECTION;          return EXIT_SECTION;
315  }  }
316    
317    static int display_article_key_handler(int *p_key, DISPLAY_CTX *p_ctx)
318    {
319            switch (*p_key)
320            {
321            case 'p':
322            case Ctrl('X'):
323                    section_topic_view_mode = !section_topic_view_mode;
324            case 0: // Set msg
325                    if (section_topic_view_mode)
326                    {
327                            snprintf(p_ctx->msg, sizeof(p_ctx->msg),
328                                             "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
329                                             "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] "
330                                             "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
331                    }
332                    else
333                    {
334                            snprintf(p_ctx->msg, sizeof(p_ctx->msg),
335                                             "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
336                                             "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] "
337                                             "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
338                    }
339                    *p_key = 0;
340                    break;
341            case 'r': // Reply article
342                    return 1;
343            case '=': // First topic article
344                    return 1;
345            case '\\': // Last topic article
346                    return 1;
347            case KEY_UP:
348            case KEY_PGUP:
349            case KEY_HOME:
350                    if (p_ctx->reach_begin)
351                    {
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                    }
362                    break;
363            case 'k':
364                    if (section_topic_view_mode)
365                    {
366                            *p_key = KEY_PGUP;
367                    }
368                    else
369                    {
370                            *p_key = KEY_UP;
371                    }
372                    return 1;
373            case KEY_DOWN:
374            case KEY_PGDN:
375            case KEY_END:
376                    if (p_ctx->reach_end)
377                    {
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                    break;
389            case 'j':
390                    if (section_topic_view_mode)
391                    {
392                            *p_key = KEY_PGDN;
393                    }
394                    else
395                    {
396                            *p_key = KEY_DOWN;
397                    }
398                    return 1;
399            }
400    
401            return 0;
402    }
403    
404  int section_list_display(const char *sname)  int section_list_display(const char *sname)
405  {  {
406          static int display_nickname = 0;          static int display_nickname = 0;
# Line 254  int section_list_display(const char *sna Line 414  int section_list_display(const char *sna
414          int page_count;          int page_count;
415          int page_id = 0;          int page_id = 0;
416          int selected_index = 0;          int selected_index = 0;
417            ARTICLE_CACHE cache;
418          int ret;          int ret;
419            int loop;
420            int direction;
421            ARTICLE article_new;
422            int page_id_cur;
423    
424          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
425          if (p_section == NULL)          if (p_section == NULL)
# Line 310  int section_list_display(const char *sna Line 475  int section_list_display(const char *sna
475                  snprintf(page_info_str, sizeof(page_info_str),                  snprintf(page_info_str, sizeof(page_info_str),
476                                   "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",                                   "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",
477                                   page_id + 1, MAX(page_count, 1));                                   page_id + 1, MAX(page_count, 1));
478                    
479                  show_bottom(page_info_str);                  show_bottom(page_info_str);
480                  iflush();                  iflush();
481    
482                    if (user_online_update(sname) < 0)
483                    {
484                            log_error("user_online_update(%s) error\n", sname);
485                    }
486    
487                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
488                  switch (ret)                  switch (ret)
489                  {                  {
# Line 336  int section_list_display(const char *sna Line 506  int section_list_display(const char *sna
506                          }                          }
507                          break;                          break;
508                  case VIEW_ARTICLE:                  case VIEW_ARTICLE:
509                          log_std("Debug: article %d selected\n", p_articles[selected_index]->aid);                          do
510                  case REFRESH_SCREEN:                          {
511                                    loop = 0;
512    
513                                    if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_articles[selected_index]) < 0)
514                                    {
515                                            log_error("article_cache_load(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid);
516                                            break;
517                                    }
518    
519                                    if (user_online_update("VIEW_ARTICLE") < 0)
520                                    {
521                                            log_error("user_online_update(VIEW_ARTICLE) error\n");
522                                    }
523    
524                                    ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,
525                                                                       display_article_key_handler, DATA_READ_HELP);
526    
527                                    if (article_cache_unload(&cache) < 0)
528                                    {
529                                            log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid);
530                                            break;
531                                    }
532    
533                                    // Update article_view_log
534                                    if (article_view_log_set_viewed(p_articles[selected_index]->aid, &BBS_article_view_log) < 0)
535                                    {
536                                            log_error("article_view_log_set_viewed(aid=%d) error\n", p_articles[selected_index]->aid);
537                                    }
538    
539                                    switch (ret)
540                                    {
541                                    case KEY_UP:
542                                            if (selected_index <= 0)
543                                            {
544                                                    if (page_id > 0)
545                                                    {
546                                                            page_id--;
547                                                            selected_index = BBS_article_limit_per_page - 1;
548    
549                                                            ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
550                                                            if (ret < 0)
551                                                            {
552                                                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
553                                                                    return -3;
554                                                            }
555    
556                                                            if (article_count != BBS_article_limit_per_page) // page is not full
557                                                            {
558                                                                    selected_index = MAX(0, article_count - 1);
559                                                            }
560                                                            else
561                                                            {
562                                                                    loop = 1;
563                                                            }
564                                                    }
565                                            }
566                                            else
567                                            {
568                                                    selected_index--;
569                                                    loop = 1;
570                                            }
571                                            break;
572                                    case KEY_DOWN:
573                                            if (selected_index + 1 >= article_count) // next page
574                                            {
575                                                    if (page_id + 1 < page_count)
576                                                    {
577                                                            page_id++;
578                                                            selected_index = 0;
579    
580                                                            ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
581                                                            if (ret < 0)
582                                                            {
583                                                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
584                                                                    return -3;
585                                                            }
586    
587                                                            if (article_count == 0) // empty page
588                                                            {
589                                                                    selected_index = 0;
590                                                            }
591                                                            else
592                                                            {
593                                                                    loop = 1;
594                                                            }
595                                                    }
596                                            }
597                                            else
598                                            {
599                                                    selected_index++;
600                                                    loop = 1;
601                                            }
602                                            break;
603                                    case KEY_PGUP:
604                                    case KEY_PGDN:
605                                            direction = (ret == KEY_PGUP ? -1 : 1);
606                                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, 1,
607                                                                                                            &page_id, &selected_index, &article_count);
608                                            if (ret < 0)
609                                            {
610                                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error\n",
611                                                                      p_section->sid, p_articles[selected_index]->aid, direction);
612                                                    return -3;
613                                            }
614                                            else if (ret > 0) // found
615                                            {
616                                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
617                                                    if (ret < 0)
618                                                    {
619                                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
620                                                            return -3;
621                                                    }
622                                                    loop = 1;
623                                            }
624                                            break;
625                                    case 'r': // Reply article
626                                            if (user_online_update("REPLY_ARTICLE") < 0)
627                                            {
628                                                    log_error("user_online_update(REPLY_ARTICLE) error\n");
629                                            }
630    
631                                            if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)
632                                            {
633                                                    log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid);
634                                            }
635                                            loop = 1;
636                                            break;
637                                    case '=':  // First topic article
638                                    case '\\': // Last topic article
639                                            page_id_cur = page_id;
640                                            direction = (ret == '=' ? -1 : 1);
641                                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section,
642                                                                                                            &page_id, &selected_index, &article_count);
643                                            if (ret < 0)
644                                            {
645                                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n",
646                                                                      p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);
647                                                    return -3;
648                                            }
649                                            else if (ret > 0) // found
650                                            {
651                                                    if (page_id != page_id_cur) // page changed
652                                                    {
653                                                            ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
654                                                            if (ret < 0)
655                                                            {
656                                                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
657                                                                    return -3;
658                                                            }
659                                                    }
660                                                    loop = 1;
661                                            }
662                                            break;
663                                    }
664                            } while (loop);
665    
666                            // Update current topic
667                            section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
668    
669                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
670                          {                          {
671                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 349  int section_list_display(const char *sna Line 677  int section_list_display(const char *sna
677                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
678                          {                          {
679                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
680                                    return -2;
681                            }
682                            break;
683                    case POST_ARTICLE:
684                            if (user_online_update("POST_ARTICLE") < 0)
685                            {
686                                    log_error("user_online_update(POST_ARTICLE) error\n");
687                            }
688    
689                            if ((ret = article_post(p_section, &article_new)) < 0)
690                            {
691                                    log_error("article_post(sid=%d) error\n", p_section->sid);
692                            }
693                            else if (ret > 0) // New article posted
694                            {
695                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
696                                    if (ret < 0)
697                                    {
698                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
699                                            return -3;
700                                    }
701                            }
702                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
703                            {
704                                    log_error("section_list_draw_screen() error\n");
705                                    return -2;
706                            }
707                            break;
708                    case EDIT_ARTICLE:
709                            if (!checkpriv(&BBS_priv, p_section->sid, S_POST) ||
710                                    p_articles[selected_index]->uid != BBS_priv.uid)
711                            {
712                                    break; // No permission
713                            }
714    
715                            if (user_online_update("EDIT_ARTICLE") < 0)
716                            {
717                                    log_error("user_online_update() error\n");
718                            }
719    
720                            if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)
721                            {
722                                    log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);
723                            }
724                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
725                            {
726                                    log_error("section_list_draw_screen() error\n");
727                                    return -2;
728                            }
729                            break;
730                    case DELETE_ARTICLE:
731                            if (!checkpriv(&BBS_priv, p_section->sid, S_POST) ||
732                                    (!checkpriv(&BBS_priv, p_section->sid, S_MAN_S) && p_articles[selected_index]->uid != BBS_priv.uid))
733                            {
734                                    break; // No permission
735                            }
736                            if ((ret = article_del(p_section, p_articles[selected_index])) < 0)
737                            {
738                                    log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid);
739                            }
740                            else if (ret > 0) // Article deleted
741                            {
742                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
743                                    if (ret < 0)
744                                    {
745                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
746                                            return -3;
747                                    }
748                            }
749                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
750                            {
751                                    log_error("section_list_draw_screen() error\n");
752                                    return -2;
753                            }
754                            break;
755                    case FIRST_TOPIC_ARTICLE:
756                    case LAST_TOPIC_ARTICLE:
757                            page_id_cur = page_id;
758                            direction = (ret == FIRST_TOPIC_ARTICLE ? -1 : 1);
759                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section,
760                                                                                            &page_id, &selected_index, &article_count);
761                            if (ret < 0)
762                            {
763                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n",
764                                                      p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);
765                                    return -3;
766                            }
767                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
768                            {
769                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
770                                    if (ret < 0)
771                                    {
772                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
773                                            return -3;
774                                    }
775                            }
776                            break;
777                    case SHOW_HELP:
778                            // Display help information
779                            display_file(DATA_READ_HELP, 1);
780                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
781                            {
782                                    log_error("section_list_draw_screen() error\n");
783                                  return -2;                                  return -2;
784                          }                          }
785                          break;                          break;


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

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