| 17 |
#include "section_list_display.h" |
#include "section_list_display.h" |
| 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" |
| 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" |
| 25 |
#include "log.h" |
#include "log.h" |
| 26 |
|
#include "user_priv.h" |
| 27 |
#include "article_view_log.h" |
#include "article_view_log.h" |
| 28 |
#include "str_process.h" |
#include "str_process.h" |
| 29 |
#include <time.h> |
#include <time.h> |
| 41 |
CHANGE_PAGE = 2, |
CHANGE_PAGE = 2, |
| 42 |
REFRESH_SCREEN = 3, |
REFRESH_SCREEN = 3, |
| 43 |
CHANGE_NAME_DISPLAY = 4, |
CHANGE_NAME_DISPLAY = 4, |
| 44 |
|
POST_ARTICLE = 5, |
| 45 |
|
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) |
| 66 |
|
|
| 67 |
for (i = 0; i < article_count; i++) |
for (i = 0; i < article_count; i++) |
| 68 |
{ |
{ |
| 69 |
is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log); |
if (p_articles[i]->uid == BBS_priv.uid) |
|
if (is_viewed < 0) |
|
| 70 |
{ |
{ |
| 71 |
log_error("article_view_log_is_viewed(aid=%d) error\n", p_articles[i]->aid); |
is_viewed = 1; |
| 72 |
is_viewed = 0; |
} |
| 73 |
|
else |
| 74 |
|
{ |
| 75 |
|
is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log); |
| 76 |
|
if (is_viewed < 0) |
| 77 |
|
{ |
| 78 |
|
log_error("article_view_log_is_viewed(aid=%d) error\n", p_articles[i]->aid); |
| 79 |
|
is_viewed = 0; |
| 80 |
|
} |
| 81 |
} |
} |
| 82 |
|
|
| 83 |
article_flag = (is_viewed ? ' ' : 'N'); |
article_flag = (is_viewed ? ' ' : 'N'); |
| 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'; |
| 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[m %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) |
| 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 |
{ |
{ |
| 201 |
return VIEW_ARTICLE; |
return VIEW_ARTICLE; |
| 202 |
} |
} |
| 203 |
break; |
break; |
| 204 |
|
case Ctrl('P'): |
| 205 |
|
return POST_ARTICLE; |
| 206 |
|
case 'E': |
| 207 |
|
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 |
{ |
{ |
| 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 |
{ |
{ |
| 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 |
|
|
| 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; |
| 318 |
|
case 'r': // Reply article |
| 319 |
|
return 1; |
| 320 |
case KEY_UP: |
case KEY_UP: |
| 321 |
case KEY_PGUP: |
case KEY_PGUP: |
| 322 |
case KEY_HOME: |
case KEY_HOME: |
| 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: |
| 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; |
| 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) |
| 483 |
break; |
break; |
| 484 |
} |
} |
| 485 |
|
|
| 486 |
ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 1, 0, |
ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0, |
| 487 |
display_article_key_handler, DATA_READ_HELP); |
display_article_key_handler, DATA_READ_HELP); |
| 488 |
|
|
| 489 |
if (article_cache_unload(&cache) < 0) |
if (article_cache_unload(&cache) < 0) |
| 583 |
loop = 1; |
loop = 1; |
| 584 |
} |
} |
| 585 |
break; |
break; |
| 586 |
|
case 'r': // Reply article |
| 587 |
|
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); |
| 590 |
|
} |
| 591 |
|
loop = 1; |
| 592 |
|
break; |
| 593 |
} |
} |
| 594 |
} while (loop); |
} while (loop); |
| 595 |
|
|
| 607 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 608 |
{ |
{ |
| 609 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error\n"); |
| 610 |
|
return -2; |
| 611 |
|
} |
| 612 |
|
break; |
| 613 |
|
case POST_ARTICLE: |
| 614 |
|
ret = article_post(p_section, &article_new); |
| 615 |
|
if (ret < 0) |
| 616 |
|
{ |
| 617 |
|
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) |
| 629 |
|
{ |
| 630 |
|
log_error("section_list_draw_screen() error\n"); |
| 631 |
|
return -2; |
| 632 |
|
} |
| 633 |
|
break; |
| 634 |
|
case EDIT_ARTICLE: |
| 635 |
|
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; // No permission |
| 655 |
|
} |
| 656 |
|
if (article_del(p_section, p_articles[selected_index]) < 0) |
| 657 |
|
{ |
| 658 |
|
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) |
| 661 |
|
{ |
| 662 |
|
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; |