| 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" |
| 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 |
}; |
}; |
| 48 |
|
|
| 49 |
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) |
| 142 |
show_top(str_section_master, stitle, str_section_name); |
show_top(str_section_master, stitle, str_section_name); |
| 143 |
moveto(2, 0); |
moveto(2, 0); |
| 144 |
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] " |
| 145 |
"阅读[\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] " |
| 146 |
|
"修改[\033[1;32mE\033[0;37m] 删除[\033[1;32md\033[0;37m] %s[\033[1;32mn\033[0;37m]\033[m", |
| 147 |
(display_nickname ? "显示用户名" : "显示昵称")); |
(display_nickname ? "显示用户名" : "显示昵称")); |
| 148 |
moveto(3, 0); |
moveto(3, 0); |
| 149 |
if (display_nickname) |
if (display_nickname) |
| 203 |
return POST_ARTICLE; |
return POST_ARTICLE; |
| 204 |
case 'E': |
case 'E': |
| 205 |
return EDIT_ARTICLE; |
return EDIT_ARTICLE; |
| 206 |
|
case 'd': |
| 207 |
|
return DELETE_ARTICLE; |
| 208 |
case KEY_HOME: |
case KEY_HOME: |
| 209 |
*p_page_id = 0; |
*p_page_id = 0; |
| 210 |
case KEY_PGUP: |
case KEY_PGUP: |
| 241 |
(*p_page_id)++; |
(*p_page_id)++; |
| 242 |
*p_selected_index = 0; |
*p_selected_index = 0; |
| 243 |
} |
} |
| 244 |
|
else // end of last page |
| 245 |
|
{ |
| 246 |
|
return CHANGE_PAGE; // force refresh pages |
| 247 |
|
} |
| 248 |
} |
} |
| 249 |
else |
else |
| 250 |
{ |
{ |
| 292 |
if (section_topic_view_mode) |
if (section_topic_view_mode) |
| 293 |
{ |
{ |
| 294 |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 295 |
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | " |
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] " |
| 296 |
"同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] | " |
"同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] " |
| 297 |
"模式[\033[32mp\033[33m] | 帮助[\033[32mh\033[33m] |"); |
"切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |"); |
| 298 |
} |
} |
| 299 |
else |
else |
| 300 |
{ |
{ |
| 301 |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 302 |
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | " |
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] " |
| 303 |
"移动[\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] " |
| 304 |
"模式[\033[32mp\033[33m] | 帮助[\033[32mh\033[33m] |"); |
"切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |"); |
| 305 |
} |
} |
| 306 |
*p_key = 0; |
*p_key = 0; |
| 307 |
break; |
break; |
| 361 |
int ret; |
int ret; |
| 362 |
int loop; |
int loop; |
| 363 |
int direction; |
int direction; |
| 364 |
|
ARTICLE article_new; |
| 365 |
|
|
| 366 |
p_section = section_list_find_by_name(sname); |
p_section = section_list_find_by_name(sname); |
| 367 |
if (p_section == NULL) |
if (p_section == NULL) |
| 554 |
} |
} |
| 555 |
break; |
break; |
| 556 |
case 'r': // Reply article |
case 'r': // Reply article |
| 557 |
if (article_post(p_section, p_articles[selected_index], ARTICLE_POST_REPLY) < 0) |
if (article_reply(p_section, p_articles[selected_index], &article_new) < 0) |
| 558 |
{ |
{ |
| 559 |
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); |
| 560 |
} |
} |
| 581 |
} |
} |
| 582 |
break; |
break; |
| 583 |
case POST_ARTICLE: |
case POST_ARTICLE: |
| 584 |
if (article_post(p_section, NULL, ARTICLE_POST_NEW) < 0) |
ret = article_post(p_section, &article_new); |
| 585 |
|
if (ret < 0) |
| 586 |
{ |
{ |
| 587 |
log_error("article_post(sid=%d, NEW) error\n", p_section->sid); |
log_error("article_post(sid=%d) error\n", p_section->sid); |
| 588 |
|
} |
| 589 |
|
else if (ret > 0) // New article posted |
| 590 |
|
{ |
| 591 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 592 |
|
if (ret < 0) |
| 593 |
|
{ |
| 594 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 595 |
|
return -3; |
| 596 |
|
} |
| 597 |
} |
} |
| 598 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 599 |
{ |
{ |
| 602 |
} |
} |
| 603 |
break; |
break; |
| 604 |
case EDIT_ARTICLE: |
case EDIT_ARTICLE: |
| 605 |
if (p_articles[selected_index]->uid != BBS_priv.uid) |
if (!checkpriv(&BBS_priv, p_section->sid, S_POST) || |
| 606 |
|
p_articles[selected_index]->uid != BBS_priv.uid) |
| 607 |
|
{ |
| 608 |
|
break; // No permission |
| 609 |
|
} |
| 610 |
|
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
| 611 |
|
{ |
| 612 |
|
log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid); |
| 613 |
|
} |
| 614 |
|
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 615 |
|
{ |
| 616 |
|
log_error("section_list_draw_screen() error\n"); |
| 617 |
|
return -2; |
| 618 |
|
} |
| 619 |
|
break; |
| 620 |
|
case DELETE_ARTICLE: |
| 621 |
|
if (!checkpriv(&BBS_priv, p_section->sid, S_POST) || |
| 622 |
|
(!checkpriv(&BBS_priv, p_section->sid, S_MAN_S) && p_articles[selected_index]->uid != BBS_priv.uid)) |
| 623 |
{ |
{ |
| 624 |
break; |
break; // No permission |
| 625 |
} |
} |
| 626 |
if (article_post(p_section, p_articles[selected_index], ARTICLE_POST_EDIT) < 0) |
if (article_del(p_section, p_articles[selected_index]) < 0) |
| 627 |
{ |
{ |
| 628 |
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); |
| 629 |
} |
} |
| 630 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 631 |
{ |
{ |