| 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> |
| 48 |
LAST_TOPIC_ARTICLE = 9, |
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, int ontop_start_offset) |
| 52 |
{ |
{ |
| 53 |
char str_time[LINE_BUFFER_LEN]; |
char str_time[LINE_BUFFER_LEN]; |
| 54 |
struct tm tm_sub; |
struct tm tm_sub; |
| 81 |
} |
} |
| 82 |
} |
} |
| 83 |
|
|
|
article_flag = (is_viewed ? ' ' : 'N'); |
|
|
|
|
| 84 |
if (p_articles[i]->excerption) |
if (p_articles[i]->excerption) |
| 85 |
{ |
{ |
| 86 |
article_flag = (is_viewed ? 'm' : 'M'); |
article_flag = (is_viewed ? 'm' : 'M'); |
| 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) |
| 115 |
} |
} |
| 116 |
|
|
| 117 |
moveto(4 + i, 1); |
moveto(4 + i, 1); |
| 118 |
prints(" %s%7d\033[m %c %s%*s %s %s%s\033[m", |
if (i >= ontop_start_offset) |
| 119 |
(p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")), |
{ |
| 120 |
p_articles[i]->aid, |
prints(" \033[1;33m[ΜαΚΎ]\033[m %c %s%*s %s %s%s\033[m", |
| 121 |
article_flag, |
article_flag, |
| 122 |
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
| 123 |
(display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname)) |
(display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname)) |
| 124 |
: 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))), |
| 125 |
"", |
"", |
| 126 |
str_time, |
str_time, |
| 127 |
(p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")), |
(p_articles[i]->aid == section_topic_view_tid |
| 128 |
title_f); |
? "\033[1;33m" |
| 129 |
|
: (p_articles[i]->tid == section_topic_view_tid |
| 130 |
|
? "\033[1;36m" |
| 131 |
|
: "")), |
| 132 |
|
title_f); |
| 133 |
|
} |
| 134 |
|
else |
| 135 |
|
{ |
| 136 |
|
prints(" %s%7d\033[m %c %s%*s %s %s%s\033[m", |
| 137 |
|
(p_articles[i]->aid == section_topic_view_tid |
| 138 |
|
? "\033[1;33m" |
| 139 |
|
: (p_articles[i]->tid == section_topic_view_tid |
| 140 |
|
? "\033[1;36m" |
| 141 |
|
: "")), |
| 142 |
|
p_articles[i]->aid, |
| 143 |
|
article_flag, |
| 144 |
|
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
| 145 |
|
(display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname)) |
| 146 |
|
: BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))), |
| 147 |
|
"", |
| 148 |
|
str_time, |
| 149 |
|
(p_articles[i]->aid == section_topic_view_tid |
| 150 |
|
? "\033[1;33m" |
| 151 |
|
: (p_articles[i]->tid == section_topic_view_tid |
| 152 |
|
? "\033[1;36m" |
| 153 |
|
: "")), |
| 154 |
|
title_f); |
| 155 |
|
} |
| 156 |
} |
} |
| 157 |
|
|
| 158 |
return 0; |
return 0; |
| 429 |
ARTICLE *p_articles[BBS_article_limit_per_page]; |
ARTICLE *p_articles[BBS_article_limit_per_page]; |
| 430 |
int article_count; |
int article_count; |
| 431 |
int page_count; |
int page_count; |
| 432 |
|
int ontop_start_offset; |
| 433 |
int page_id = 0; |
int page_id = 0; |
| 434 |
int selected_index = 0; |
int selected_index = 0; |
| 435 |
ARTICLE_CACHE cache; |
ARTICLE_CACHE cache; |
| 469 |
return -2; |
return -2; |
| 470 |
} |
} |
| 471 |
|
|
| 472 |
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, &ontop_start_offset); |
| 473 |
if (ret < 0) |
if (ret < 0) |
| 474 |
{ |
{ |
| 475 |
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); |
| 483 |
|
|
| 484 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 485 |
{ |
{ |
| 486 |
ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname); |
ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname, ontop_start_offset); |
| 487 |
if (ret < 0) |
if (ret < 0) |
| 488 |
{ |
{ |
| 489 |
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); |
| 497 |
show_bottom(page_info_str); |
show_bottom(page_info_str); |
| 498 |
iflush(); |
iflush(); |
| 499 |
|
|
| 500 |
|
if (user_online_update(sname) < 0) |
| 501 |
|
{ |
| 502 |
|
log_error("user_online_update(%s) error\n", sname); |
| 503 |
|
} |
| 504 |
|
|
| 505 |
ret = section_list_select(page_count, article_count, &page_id, &selected_index); |
ret = section_list_select(page_count, article_count, &page_id, &selected_index); |
| 506 |
switch (ret) |
switch (ret) |
| 507 |
{ |
{ |
| 508 |
case EXIT_SECTION: |
case EXIT_SECTION: |
| 509 |
return 0; |
return 0; |
| 510 |
case CHANGE_PAGE: |
case CHANGE_PAGE: |
| 511 |
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, &ontop_start_offset); |
| 512 |
if (ret < 0) |
if (ret < 0) |
| 513 |
{ |
{ |
| 514 |
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); |
| 534 |
break; |
break; |
| 535 |
} |
} |
| 536 |
|
|
| 537 |
|
if (user_online_update("VIEW_ARTICLE") < 0) |
| 538 |
|
{ |
| 539 |
|
log_error("user_online_update(VIEW_ARTICLE) error\n"); |
| 540 |
|
} |
| 541 |
|
|
| 542 |
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, |
| 543 |
display_article_key_handler, DATA_READ_HELP); |
display_article_key_handler, DATA_READ_HELP); |
| 544 |
|
|
| 564 |
page_id--; |
page_id--; |
| 565 |
selected_index = BBS_article_limit_per_page - 1; |
selected_index = BBS_article_limit_per_page - 1; |
| 566 |
|
|
| 567 |
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, &ontop_start_offset); |
| 568 |
if (ret < 0) |
if (ret < 0) |
| 569 |
{ |
{ |
| 570 |
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); |
| 595 |
page_id++; |
page_id++; |
| 596 |
selected_index = 0; |
selected_index = 0; |
| 597 |
|
|
| 598 |
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, &ontop_start_offset); |
| 599 |
if (ret < 0) |
if (ret < 0) |
| 600 |
{ |
{ |
| 601 |
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); |
| 631 |
} |
} |
| 632 |
else if (ret > 0) // found |
else if (ret > 0) // found |
| 633 |
{ |
{ |
| 634 |
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, &ontop_start_offset); |
| 635 |
if (ret < 0) |
if (ret < 0) |
| 636 |
{ |
{ |
| 637 |
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); |
| 641 |
} |
} |
| 642 |
break; |
break; |
| 643 |
case 'r': // Reply article |
case 'r': // Reply article |
| 644 |
|
if (user_online_update("REPLY_ARTICLE") < 0) |
| 645 |
|
{ |
| 646 |
|
log_error("user_online_update(REPLY_ARTICLE) error\n"); |
| 647 |
|
} |
| 648 |
|
|
| 649 |
if (article_reply(p_section, p_articles[selected_index], &article_new) < 0) |
if (article_reply(p_section, p_articles[selected_index], &article_new) < 0) |
| 650 |
{ |
{ |
| 651 |
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); |
| 652 |
} |
} |
| 653 |
loop = 1; |
loop = 1; |
| 654 |
break; |
break; |
| 668 |
{ |
{ |
| 669 |
if (page_id != page_id_cur) // page changed |
if (page_id != page_id_cur) // page changed |
| 670 |
{ |
{ |
| 671 |
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, &ontop_start_offset); |
| 672 |
if (ret < 0) |
if (ret < 0) |
| 673 |
{ |
{ |
| 674 |
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); |
| 683 |
|
|
| 684 |
// Update current topic |
// Update current topic |
| 685 |
section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid); |
section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid); |
| 686 |
|
|
| 687 |
|
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 688 |
|
{ |
| 689 |
|
log_error("section_list_draw_screen() error\n"); |
| 690 |
|
return -2; |
| 691 |
|
} |
| 692 |
|
break; |
| 693 |
case CHANGE_NAME_DISPLAY: |
case CHANGE_NAME_DISPLAY: |
| 694 |
display_nickname = !display_nickname; |
display_nickname = !display_nickname; |
| 695 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 699 |
} |
} |
| 700 |
break; |
break; |
| 701 |
case POST_ARTICLE: |
case POST_ARTICLE: |
| 702 |
|
if (user_online_update("POST_ARTICLE") < 0) |
| 703 |
|
{ |
| 704 |
|
log_error("user_online_update(POST_ARTICLE) error\n"); |
| 705 |
|
} |
| 706 |
|
|
| 707 |
if ((ret = article_post(p_section, &article_new)) < 0) |
if ((ret = article_post(p_section, &article_new)) < 0) |
| 708 |
{ |
{ |
| 709 |
log_error("article_post(sid=%d) error\n", p_section->sid); |
log_error("article_post(sid=%d) error\n", p_section->sid); |
| 710 |
} |
} |
| 711 |
else if (ret > 0) // New article posted |
else if (ret > 0) // New article posted |
| 712 |
{ |
{ |
| 713 |
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, &ontop_start_offset); |
| 714 |
if (ret < 0) |
if (ret < 0) |
| 715 |
{ |
{ |
| 716 |
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); |
| 729 |
{ |
{ |
| 730 |
break; // No permission |
break; // No permission |
| 731 |
} |
} |
| 732 |
|
|
| 733 |
|
if (user_online_update("EDIT_ARTICLE") < 0) |
| 734 |
|
{ |
| 735 |
|
log_error("user_online_update() error\n"); |
| 736 |
|
} |
| 737 |
|
|
| 738 |
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
| 739 |
{ |
{ |
| 740 |
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); |
| 757 |
} |
} |
| 758 |
else if (ret > 0) // Article deleted |
else if (ret > 0) // Article deleted |
| 759 |
{ |
{ |
| 760 |
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, &ontop_start_offset); |
| 761 |
if (ret < 0) |
if (ret < 0) |
| 762 |
{ |
{ |
| 763 |
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); |
| 784 |
} |
} |
| 785 |
else if (ret > 0 && page_id != page_id_cur) // found and page changed |
else if (ret > 0 && page_id != page_id_cur) // found and page changed |
| 786 |
{ |
{ |
| 787 |
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, &ontop_start_offset); |
| 788 |
if (ret < 0) |
if (ret < 0) |
| 789 |
{ |
{ |
| 790 |
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); |