| 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) |
| 104 |
title_f[sizeof(title_f) - 1] = '\0'; |
title_f[sizeof(title_f) - 1] = '\0'; |
| 105 |
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))); |
| 106 |
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))); |
| 107 |
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); |
| 108 |
if (title_f[len] != '\0') |
if (title_f[len] != '\0') |
| 109 |
{ |
{ |
| 110 |
title_f[len] = '\0'; |
title_f[len] = '\0'; |
| 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[1;32mCtrl-P\033[0;37m] " |
"阅读[\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] %s[\033[1;32mn\033[0;37m]\033[m", |
"修改[\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 |
{ |
{ |
| 584 |
ret = article_post(p_section, &article_new); |
ret = article_post(p_section, &article_new); |
| 585 |
if (ret < 0) |
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 |
else if (ret > 0) // New article posted |
| 590 |
{ |
{ |
| 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; |
break; // No permission |
| 609 |
} |
} |
| 610 |
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
| 611 |
{ |
{ |
| 612 |
log_error("article_post(aid=%d, EDIT) error\n", p_articles[selected_index]->aid); |
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; // No permission |
| 625 |
|
} |
| 626 |
|
if (article_del(p_section, p_articles[selected_index]) < 0) |
| 627 |
|
{ |
| 628 |
|
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 |
{ |
{ |