/[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.22 by sysadm, Fri Jun 13 12:17:21 2025 UTC Revision 1.28 by sysadm, Mon Jun 16 03:08:29 2025 UTC
# Line 18  Line 18 
18  #include "section_list_loader.h"  #include "section_list_loader.h"
19  #include "article_cache.h"  #include "article_cache.h"
20  #include "article_post.h"  #include "article_post.h"
21    #include "article_del.h"
22  #include "common.h"  #include "common.h"
23  #include "io.h"  #include "io.h"
24  #include "screen.h"  #include "screen.h"
# Line 42  enum select_cmd_t Line 43  enum select_cmd_t
43          CHANGE_NAME_DISPLAY = 4,          CHANGE_NAME_DISPLAY = 4,
44          POST_ARTICLE = 5,          POST_ARTICLE = 5,
45          EDIT_ARTICLE = 6,          EDIT_ARTICLE = 6,
46            DELETE_ARTICLE = 7,
47            SHOW_HELP = 8,
48  };  };
49    
50  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 102  static int section_list_draw_items(int p Line 105  static int section_list_draw_items(int p
105                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
106                  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)));
107                  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)));
108                  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);
109                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
110                  {                  {
111                          title_f[len] = '\0';                          title_f[len] = '\0';
# Line 140  static int section_list_draw_screen(cons Line 143  static int section_list_draw_screen(cons
143          show_top(str_section_master, stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
144          moveto(2, 0);          moveto(2, 0);
145          prints("返回[\033[1;32m←\033[0;37m,\033[1;32mESC\033[0;37m] 选择[\033[1;32m↑\033[0;37m,\033[1;32m↓\033[0;37m] "          prints("返回[\033[1;32m←\033[0;37m,\033[1;32mESC\033[0;37m] 选择[\033[1;32m↑\033[0;37m,\033[1;32m↓\033[0;37m] "
146                     "阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 发表文章[\033[1;32mCtrl-P\033[0;37m] %s[\033[1;32mn\033[0;37m]\033[m",                     "阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 发表[\033[1;32mCtrl-P\033[0;37m] "
147                       "%s[\033[1;32mn\033[0;37m] 帮助[\033[1;32mh\033[0;37m]\033[m",
148                     (display_nickname ? "显示用户名" : "显示昵称"));                     (display_nickname ? "显示用户名" : "显示昵称"));
149          moveto(3, 0);          moveto(3, 0);
150          if (display_nickname)          if (display_nickname)
# Line 190  static enum select_cmd_t section_list_se Line 194  static enum select_cmd_t section_list_se
194                          return CHANGE_NAME_DISPLAY;                          return CHANGE_NAME_DISPLAY;
195                  case CR:                  case CR:
196                          igetch_reset();                          igetch_reset();
197                    case 'r':
198                  case KEY_RIGHT:                  case KEY_RIGHT:
199                          if (item_count > 0)                          if (item_count > 0)
200                          {                          {
# Line 200  static enum select_cmd_t section_list_se Line 205  static enum select_cmd_t section_list_se
205                          return POST_ARTICLE;                          return POST_ARTICLE;
206                  case 'E':                  case 'E':
207                          return EDIT_ARTICLE;                          return EDIT_ARTICLE;
208                    case 'd':
209                            return DELETE_ARTICLE;
210                  case KEY_HOME:                  case KEY_HOME:
211                          *p_page_id = 0;                          *p_page_id = 0;
212                    case 'P':
213                  case KEY_PGUP:                  case KEY_PGUP:
214                          *p_selected_index = 0;                          *p_selected_index = 0;
215                    case 'k':
216                  case KEY_UP:                  case KEY_UP:
217                          if (*p_selected_index <= 0)                          if (*p_selected_index <= 0)
218                          {                          {
# Line 218  static enum select_cmd_t section_list_se Line 227  static enum select_cmd_t section_list_se
227                                  (*p_selected_index)--;                                  (*p_selected_index)--;
228                          }                          }
229                          break;                          break;
230                    case '$':
231                  case KEY_END:                  case KEY_END:
232                          if (total_page > 0)                          if (total_page > 0)
233                          {                          {
234                                  *p_page_id = total_page - 1;                                  *p_page_id = total_page - 1;
235                          }                          }
236                    case 'N':
237                  case KEY_PGDN:                  case KEY_PGDN:
238                          if (item_count > 0)                          if (item_count > 0)
239                          {                          {
240                                  *p_selected_index = item_count - 1;                                  *p_selected_index = item_count - 1;
241                          }                          }
242                    case 'j':
243                  case KEY_DOWN:                  case KEY_DOWN:
244                          if (*p_selected_index + 1 >= item_count) // next page                          if (*p_selected_index + 1 >= item_count) // next page
245                          {                          {
# Line 236  static enum select_cmd_t section_list_se Line 248  static enum select_cmd_t section_list_se
248                                          (*p_page_id)++;                                          (*p_page_id)++;
249                                          *p_selected_index = 0;                                          *p_selected_index = 0;
250                                  }                                  }
251                                    else // end of last page
252                                    {
253                                            return CHANGE_PAGE; // force refresh pages
254                                    }
255                          }                          }
256                          else                          else
257                          {                          {
258                                  (*p_selected_index)++;                                  (*p_selected_index)++;
259                          }                          }
260                          break;                          break;
261                    case 'h':
262                            return SHOW_HELP;
263                  default:                  default:
264                  }                  }
265    
# Line 278  static int display_article_key_handler(i Line 296  static int display_article_key_handler(i
296          switch (*p_key)          switch (*p_key)
297          {          {
298          case 'p':          case 'p':
299            case Ctrl('X'):
300                  section_topic_view_mode = !section_topic_view_mode;                  section_topic_view_mode = !section_topic_view_mode;
301          case 0: // Set msg          case 0: // Set msg
302                  if (section_topic_view_mode)                  if (section_topic_view_mode)
303                  {                  {
304                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
305                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
306                                           "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] | "                                           "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] "
307                                           "模式[\033[32mp\033[33m] | 帮助[\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
308                  }                  }
309                  else                  else
310                  {                  {
311                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
312                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
313                                           "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | "                                           "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] "
314                                           "模式[\033[32mp\033[33m] | 帮助[\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
315                  }                  }
316                  *p_key = 0;                  *p_key = 0;
317                  break;                  break;
# Line 314  static int display_article_key_handler(i Line 333  static int display_article_key_handler(i
333                          return 1;                          return 1;
334                  }                  }
335                  break;                  break;
336            case 'k':
337                    if (section_topic_view_mode)
338                    {
339                            *p_key = KEY_PGUP;
340                    }
341                    else
342                    {
343                            *p_key = KEY_UP;
344                    }
345                    return 1;
346          case KEY_DOWN:          case KEY_DOWN:
347          case KEY_PGDN:          case KEY_PGDN:
348          case KEY_END:          case KEY_END:
# Line 330  static int display_article_key_handler(i Line 359  static int display_article_key_handler(i
359                          return 1;                          return 1;
360                  }                  }
361                  break;                  break;
362            case 'j':
363                    if (section_topic_view_mode)
364                    {
365                            *p_key = KEY_PGDN;
366                    }
367                    else
368                    {
369                            *p_key = KEY_DOWN;
370                    }
371                    return 1;
372          }          }
373    
374          return 0;          return 0;
# Line 352  int section_list_display(const char *sna Line 391  int section_list_display(const char *sna
391          int ret;          int ret;
392          int loop;          int loop;
393          int direction;          int direction;
394            ARTICLE article_new;
395    
396          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
397          if (p_section == NULL)          if (p_section == NULL)
# Line 544  int section_list_display(const char *sna Line 584  int section_list_display(const char *sna
584                                          }                                          }
585                                          break;                                          break;
586                                  case 'r': // Reply article                                  case 'r': // Reply article
587                                          if (article_reply(p_section, p_articles[selected_index]) < 0)                                          if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)
588                                          {                                          {
589                                                  log_error("article_post(aid=%d, REPLY) error\n", p_articles[selected_index]->aid);                                                  log_error("article_post(aid=%d, REPLY) error\n", p_articles[selected_index]->aid);
590                                          }                                          }
# Line 571  int section_list_display(const char *sna Line 611  int section_list_display(const char *sna
611                          }                          }
612                          break;                          break;
613                  case POST_ARTICLE:                  case POST_ARTICLE:
614                          if (article_post(p_section) < 0)                          ret = article_post(p_section, &article_new);
615                            if (ret < 0)
616                          {                          {
617                                  log_error("article_post(sid=%d, NEW) error\n", p_section->sid);                                  log_error("article_post(sid=%d) error\n", p_section->sid);
618                            }
619                            else if (ret > 0) // New article posted
620                            {
621                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
622                                    if (ret < 0)
623                                    {
624                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
625                                            return -3;
626                                    }
627                          }                          }
628                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
629                          {                          {
# Line 582  int section_list_display(const char *sna Line 632  int section_list_display(const char *sna
632                          }                          }
633                          break;                          break;
634                  case EDIT_ARTICLE:                  case EDIT_ARTICLE:
635                          if (p_articles[selected_index]->uid != BBS_priv.uid)                          if (!checkpriv(&BBS_priv, p_section->sid, S_POST) ||
636                                    p_articles[selected_index]->uid != BBS_priv.uid)
637                            {
638                                    break; // No permission
639                            }
640                            if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)
641                            {
642                                    log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);
643                            }
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 DELETE_ARTICLE:
651                            if (!checkpriv(&BBS_priv, p_section->sid, S_POST) ||
652                                    (!checkpriv(&BBS_priv, p_section->sid, S_MAN_S) && p_articles[selected_index]->uid != BBS_priv.uid))
653                          {                          {
654                                  break;                                  break; // No permission
655                          }                          }
656                          if (article_modify(p_section, p_articles[selected_index]) < 0)                          if (article_del(p_section, p_articles[selected_index]) < 0)
657                          {                          {
658                                  log_error("article_post(aid=%d, EDIT) error\n", p_articles[selected_index]->aid);                                  log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid);
659                          }                          }
660                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
661                          {                          {
662                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
663                                    return -2;
664                            }
665                            break;
666                    case SHOW_HELP:
667                            // Display help information
668                            display_file(DATA_READ_HELP, 1);
669                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
670                            {
671                                    log_error("section_list_draw_screen() error\n");
672                                  return -2;                                  return -2;
673                          }                          }
674                          break;                          break;


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

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