/[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.30 by sysadm, Tue Jun 17 02:22:45 2025 UTC Revision 1.34 by sysadm, Sat Jun 21 02:15:18 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
 #define _POSIX_C_SOURCE 200809L  
   
 #include "section_list_display.h"  
 #include "section_list_loader.h"  
17  #include "article_cache.h"  #include "article_cache.h"
18  #include "article_post.h"  #include "article_post.h"
19    #include "article_view_log.h"
20  #include "article_del.h"  #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 "user_priv.h"  #include "login.h"
25  #include "article_view_log.h"  #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>  #include <string.h>
31  #include <time.h>  #include <time.h>
32  #include <sys/param.h>  #include <sys/param.h>
# Line 45  enum select_cmd_t Line 44  enum select_cmd_t
44          POST_ARTICLE = 5,          POST_ARTICLE = 5,
45          EDIT_ARTICLE = 6,          EDIT_ARTICLE = 6,
46          DELETE_ARTICLE = 7,          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 260  static enum select_cmd_t section_list_se Line 261  static enum select_cmd_t section_list_se
261                                  (*p_selected_index)++;                                  (*p_selected_index)++;
262                          }                          }
263                          break;                          break;
264                    case '=':
265                            return FIRST_TOPIC_ARTICLE;
266                    case '\\':
267                            return LAST_TOPIC_ARTICLE;
268                  case 'h':                  case 'h':
269                          return SHOW_HELP;                          return SHOW_HELP;
270                  default:                  default:
# Line 323  static int display_article_key_handler(i Line 328  static int display_article_key_handler(i
328                  break;                  break;
329          case 'r': // Reply article          case 'r': // Reply article
330                  return 1;                  return 1;
331            case '=': // First topic article
332                    return 1;
333            case '\\': // Last topic article
334                    return 1;
335          case KEY_UP:          case KEY_UP:
336          case KEY_PGUP:          case KEY_PGUP:
337          case KEY_HOME:          case KEY_HOME:
# Line 398  int section_list_display(const char *sna Line 407  int section_list_display(const char *sna
407          int loop;          int loop;
408          int direction;          int direction;
409          ARTICLE article_new;          ARTICLE article_new;
410            int page_id_cur;
411    
412          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
413          if (p_section == NULL)          if (p_section == NULL)
# Line 457  int section_list_display(const char *sna Line 467  int section_list_display(const char *sna
467                  show_bottom(page_info_str);                  show_bottom(page_info_str);
468                  iflush();                  iflush();
469    
470                    if (user_online_update(sname) < 0)
471                    {
472                            log_error("user_online_update(%s) error\n", sname);
473                    }
474    
475                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
476                  switch (ret)                  switch (ret)
477                  {                  {
# Line 489  int section_list_display(const char *sna Line 504  int section_list_display(const char *sna
504                                          break;                                          break;
505                                  }                                  }
506    
507                                    if (user_online_update("VIEW_ARTICLE") < 0)
508                                    {
509                                            log_error("user_online_update(VIEW_ARTICLE) error\n");
510                                    }
511    
512                                  ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,                                  ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,
513                                                                     display_article_key_handler, DATA_READ_HELP);                                                                     display_article_key_handler, DATA_READ_HELP);
514    
# Line 571  int section_list_display(const char *sna Line 591  int section_list_display(const char *sna
591                                  case KEY_PGUP:                                  case KEY_PGUP:
592                                  case KEY_PGDN:                                  case KEY_PGDN:
593                                          direction = (ret == KEY_PGUP ? -1 : 1);                                          direction = (ret == KEY_PGUP ? -1 : 1);
594                                          ret = locate_article_in_section(p_section, p_articles[selected_index], direction, &page_id, &selected_index, &page_count);                                          ret = locate_article_in_section(p_section, p_articles[selected_index], direction, 1,
595                                                                                                            &page_id, &selected_index, &article_count);
596                                          if (ret < 0)                                          if (ret < 0)
597                                          {                                          {
598                                                  log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d) error\n",                                                  log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error\n",
599                                                                    p_section->sid, p_articles[selected_index]->aid, direction);                                                                    p_section->sid, p_articles[selected_index]->aid, direction);
600                                                  return -3;                                                  return -3;
601                                          }                                          }
602                                          else if (ret > 0)                                          else if (ret > 0) // found
603                                          {                                          {
604                                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);                                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
605                                                  if (ret < 0)                                                  if (ret < 0)
# Line 590  int section_list_display(const char *sna Line 611  int section_list_display(const char *sna
611                                          }                                          }
612                                          break;                                          break;
613                                  case 'r': // Reply article                                  case 'r': // Reply article
614                                            if (user_online_update("REPLY_ARTICLE") < 0)
615                                            {
616                                                    log_error("user_online_update(REPLY_ARTICLE) error\n");
617                                            }
618    
619                                          if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)                                          if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)
620                                          {                                          {
621                                                  log_error("article_post(aid=%d, REPLY) error\n", p_articles[selected_index]->aid);                                                  log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid);
622                                          }                                          }
623                                          loop = 1;                                          loop = 1;
624                                          break;                                          break;
625                                    case '=':  // First topic article
626                                    case '\\': // Last topic article
627                                            page_id_cur = page_id;
628                                            direction = (ret == '=' ? -1 : 1);
629                                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section,
630                                                                                                            &page_id, &selected_index, &article_count);
631                                            if (ret < 0)
632                                            {
633                                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n",
634                                                                      p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);
635                                                    return -3;
636                                            }
637                                            else if (ret > 0) // found
638                                            {
639                                                    if (page_id != page_id_cur) // page changed
640                                                    {
641                                                            ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
642                                                            if (ret < 0)
643                                                            {
644                                                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
645                                                                    return -3;
646                                                            }
647                                                    }
648                                                    loop = 1;
649                                            }
650                                            break;
651                                  }                                  }
652                          } while (loop);                          } while (loop);
653    
# Line 610  int section_list_display(const char *sna Line 662  int section_list_display(const char *sna
662                          }                          }
663                          break;                          break;
664                  case POST_ARTICLE:                  case POST_ARTICLE:
665                            if (user_online_update("POST_ARTICLE") < 0)
666                            {
667                                    log_error("user_online_update(POST_ARTICLE) error\n");
668                            }
669    
670                          if ((ret = article_post(p_section, &article_new)) < 0)                          if ((ret = article_post(p_section, &article_new)) < 0)
671                          {                          {
672                                  log_error("article_post(sid=%d) error\n", p_section->sid);                                  log_error("article_post(sid=%d) error\n", p_section->sid);
# Line 635  int section_list_display(const char *sna Line 692  int section_list_display(const char *sna
692                          {                          {
693                                  break; // No permission                                  break; // No permission
694                          }                          }
695    
696                            if (user_online_update("EDIT_ARTICLE") < 0)
697                            {
698                                    log_error("user_online_update() error\n");
699                            }
700    
701                          if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)                          if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)
702                          {                          {
703                                  log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);                                  log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);
# Line 670  int section_list_display(const char *sna Line 733  int section_list_display(const char *sna
733                                  return -2;                                  return -2;
734                          }                          }
735                          break;                          break;
736                    case FIRST_TOPIC_ARTICLE:
737                    case LAST_TOPIC_ARTICLE:
738                            page_id_cur = page_id;
739                            direction = (ret == FIRST_TOPIC_ARTICLE ? -1 : 1);
740                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section,
741                                                                                            &page_id, &selected_index, &article_count);
742                            if (ret < 0)
743                            {
744                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n",
745                                                      p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);
746                                    return -3;
747                            }
748                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
749                            {
750                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
751                                    if (ret < 0)
752                                    {
753                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
754                                            return -3;
755                                    }
756                            }
757                            break;
758                  case SHOW_HELP:                  case SHOW_HELP:
759                          // Display help information                          // Display help information
760                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);


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

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