| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
| 17 |
|
#define _POSIX_C_SOURCE 200809L |
| 18 |
|
|
| 19 |
#include "section_list_display.h" |
#include "section_list_display.h" |
| 20 |
#include "section_list_loader.h" |
#include "section_list_loader.h" |
| 21 |
|
#include "article_cache.h" |
| 22 |
|
#include "article_post.h" |
| 23 |
|
#include "article_del.h" |
| 24 |
#include "common.h" |
#include "common.h" |
| 25 |
#include "io.h" |
#include "io.h" |
| 26 |
#include "screen.h" |
#include "screen.h" |
| 27 |
#include "log.h" |
#include "log.h" |
| 28 |
|
#include "user_priv.h" |
| 29 |
|
#include "article_view_log.h" |
| 30 |
#include "str_process.h" |
#include "str_process.h" |
|
#include <time.h> |
|
|
#define _POSIX_C_SOURCE 200809L |
|
| 31 |
#include <string.h> |
#include <string.h> |
| 32 |
|
#include <time.h> |
| 33 |
|
#include <sys/param.h> |
| 34 |
|
|
| 35 |
|
static int section_topic_view_mode = 0; |
| 36 |
|
static int section_topic_view_tid = -1; |
| 37 |
|
|
| 38 |
enum select_cmd_t |
enum select_cmd_t |
| 39 |
{ |
{ |
| 40 |
EXIT_SECTION = 0, |
EXIT_SECTION = 0, |
| 41 |
VIEW_ARTICLE = 1, |
VIEW_ARTICLE = 1, |
| 42 |
CHANGE_PAGE = 2, |
CHANGE_PAGE = 2, |
| 43 |
REFRESH_SCREEN = 3, |
SHOW_HELP = 3, |
| 44 |
CHANGE_NAME_DISPLAY = 4, |
CHANGE_NAME_DISPLAY = 4, |
| 45 |
|
POST_ARTICLE = 5, |
| 46 |
|
EDIT_ARTICLE = 6, |
| 47 |
|
DELETE_ARTICLE = 7, |
| 48 |
}; |
}; |
| 49 |
|
|
| 50 |
static int section_list_draw_items(SECTION_LIST *p_section, 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) |
| 51 |
{ |
{ |
| 52 |
char str_time[LINE_BUFFER_LEN]; |
char str_time[LINE_BUFFER_LEN]; |
| 53 |
struct tm tm_sub; |
struct tm tm_sub; |
| 57 |
int len; |
int len; |
| 58 |
int i; |
int i; |
| 59 |
char article_flag; |
char article_flag; |
| 60 |
|
int is_viewed; |
| 61 |
time_t tm_now; |
time_t tm_now; |
| 62 |
|
|
| 63 |
time(&tm_now); |
time(&tm_now); |
| 66 |
|
|
| 67 |
for (i = 0; i < article_count; i++) |
for (i = 0; i < article_count; i++) |
| 68 |
{ |
{ |
| 69 |
article_flag = ' '; |
if (p_articles[i]->uid == BBS_priv.uid) |
| 70 |
|
{ |
| 71 |
|
is_viewed = 1; |
| 72 |
|
} |
| 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'); |
| 84 |
|
|
| 85 |
if (p_articles[i]->excerption) |
if (p_articles[i]->excerption) |
| 86 |
{ |
{ |
| 87 |
article_flag = 'm'; |
article_flag = (is_viewed ? 'm' : 'M'); |
| 88 |
} |
} |
| 89 |
else if (p_articles[i]->lock) |
else if (p_articles[i]->lock && is_viewed) |
| 90 |
{ |
{ |
| 91 |
article_flag = 'x'; |
article_flag = 'x'; |
| 92 |
} |
} |
| 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'; |
| 112 |
} |
} |
| 113 |
|
|
| 114 |
moveto(4 + i, 1); |
moveto(4 + i, 1); |
| 115 |
prints(" %7d %c %s%*s %s %s", |
prints(" %s%7d\033[m %c %s%*s %s %s%s\033[m", |
| 116 |
|
(p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")), |
| 117 |
p_articles[i]->aid, |
p_articles[i]->aid, |
| 118 |
article_flag, |
article_flag, |
| 119 |
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
| 121 |
: 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))), |
| 122 |
"", |
"", |
| 123 |
str_time, |
str_time, |
| 124 |
|
(p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")), |
| 125 |
title_f); |
title_f); |
| 126 |
} |
} |
| 127 |
|
|
| 128 |
return 0; |
return 0; |
| 129 |
} |
} |
| 130 |
|
|
| 131 |
static int section_list_draw_screen(SECTION_LIST *p_section, int display_nickname) |
static int section_list_draw_screen(const char *sname, const char *stitle, const char *master_list, int display_nickname) |
| 132 |
{ |
{ |
| 133 |
char str_section_master[LINE_BUFFER_LEN] = "诚征版主中"; |
char str_section_master[LINE_BUFFER_LEN] = "诚征版主中"; |
| 134 |
char str_section_name[LINE_BUFFER_LEN]; |
char str_section_name[LINE_BUFFER_LEN]; |
| 135 |
|
|
| 136 |
if (p_section->master_list[0] != '\0') |
if (master_list[0] != '\0') |
| 137 |
{ |
{ |
| 138 |
snprintf(str_section_master, sizeof(str_section_master), "版主:%s", p_section->master_list); |
snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list); |
| 139 |
} |
} |
| 140 |
snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", p_section->sname); |
snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname); |
| 141 |
|
|
| 142 |
clearscr(); |
clearscr(); |
| 143 |
show_top(str_section_master, p_section->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] 阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m]\033[m 昵称[\033[1;32mn\033[0;37m]\033[m"); |
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[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 ? "显示用户名" : "显示昵称")); |
| 149 |
moveto(3, 0); |
moveto(3, 0); |
| 150 |
if (display_nickname) |
if (display_nickname) |
| 151 |
{ |
{ |
| 152 |
prints("\033[44;37m \033[1;37m 编 号 发 布 者 昵 称 日 期 文 章 标 题 \033[m"); |
prints("\033[44;37m \033[1;37m 编 号 发布者昵称 日 期 文章标题 \033[m"); |
| 153 |
} |
} |
| 154 |
else |
else |
| 155 |
{ |
{ |
| 156 |
prints("\033[44;37m \033[1;37m 编 号 发 布 者 日 期 文 章 标 题 \033[m"); |
prints("\033[44;37m \033[1;37m 编 号 发 布 者 日 期 文章标题 \033[m"); |
| 157 |
} |
} |
|
show_bottom(""); |
|
| 158 |
|
|
| 159 |
return 0; |
return 0; |
| 160 |
} |
} |
| 164 |
int old_page_id = *p_page_id; |
int old_page_id = *p_page_id; |
| 165 |
int old_selected_index = *p_selected_index; |
int old_selected_index = *p_selected_index; |
| 166 |
int ch; |
int ch; |
| 167 |
|
time_t last_refresh_tm = time(NULL); |
|
BBS_last_access_tm = time(0); |
|
| 168 |
|
|
| 169 |
if (item_count > 0 && *p_selected_index >= 0) |
if (item_count > 0 && *p_selected_index >= 0) |
| 170 |
{ |
{ |
| 179 |
|
|
| 180 |
switch (ch) |
switch (ch) |
| 181 |
{ |
{ |
|
case KEY_NULL: // broken pipe |
|
| 182 |
case KEY_ESC: |
case KEY_ESC: |
| 183 |
case KEY_LEFT: |
case KEY_LEFT: |
| 184 |
|
BBS_last_access_tm = time(NULL); |
| 185 |
|
case KEY_NULL: // broken pipe |
| 186 |
return EXIT_SECTION; // exit section |
return EXIT_SECTION; // exit section |
| 187 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 188 |
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 189 |
{ |
{ |
| 190 |
return EXIT_SECTION; // exit section |
return EXIT_SECTION; // exit section |
| 191 |
} |
} |
| 192 |
continue; |
continue; |
| 193 |
case 'n': |
case 'n': |
| 194 |
|
BBS_last_access_tm = time(NULL); |
| 195 |
return CHANGE_NAME_DISPLAY; |
return CHANGE_NAME_DISPLAY; |
| 196 |
case CR: |
case CR: |
| 197 |
igetch_reset(); |
igetch_reset(); |
| 198 |
|
case 'r': |
| 199 |
case KEY_RIGHT: |
case KEY_RIGHT: |
| 200 |
if (item_count > 0) |
if (item_count > 0) |
| 201 |
{ |
{ |
| 202 |
|
BBS_last_access_tm = time(NULL); |
| 203 |
return VIEW_ARTICLE; |
return VIEW_ARTICLE; |
| 204 |
} |
} |
| 205 |
break; |
break; |
| 206 |
|
case Ctrl('P'): |
| 207 |
|
return POST_ARTICLE; |
| 208 |
|
case 'E': |
| 209 |
|
return EDIT_ARTICLE; |
| 210 |
|
case 'd': |
| 211 |
|
return DELETE_ARTICLE; |
| 212 |
case KEY_HOME: |
case KEY_HOME: |
| 213 |
*p_page_id = 0; |
*p_page_id = 0; |
| 214 |
|
case 'P': |
| 215 |
case KEY_PGUP: |
case KEY_PGUP: |
| 216 |
*p_selected_index = 0; |
*p_selected_index = 0; |
| 217 |
|
case 'k': |
| 218 |
case KEY_UP: |
case KEY_UP: |
| 219 |
if (*p_selected_index <= 0) |
if (*p_selected_index <= 0) |
| 220 |
{ |
{ |
| 229 |
(*p_selected_index)--; |
(*p_selected_index)--; |
| 230 |
} |
} |
| 231 |
break; |
break; |
| 232 |
|
case '$': |
| 233 |
case KEY_END: |
case KEY_END: |
| 234 |
if (total_page > 0) |
if (total_page > 0) |
| 235 |
{ |
{ |
| 236 |
*p_page_id = total_page - 1; |
*p_page_id = total_page - 1; |
| 237 |
} |
} |
| 238 |
|
case 'N': |
| 239 |
case KEY_PGDN: |
case KEY_PGDN: |
| 240 |
if (item_count > 0) |
if (item_count > 0) |
| 241 |
{ |
{ |
| 242 |
*p_selected_index = item_count - 1; |
*p_selected_index = item_count - 1; |
| 243 |
} |
} |
| 244 |
|
case 'j': |
| 245 |
case KEY_DOWN: |
case KEY_DOWN: |
| 246 |
if (*p_selected_index + 1 >= item_count) // next page |
if (*p_selected_index + 1 >= item_count) // next page |
| 247 |
{ |
{ |
| 250 |
(*p_page_id)++; |
(*p_page_id)++; |
| 251 |
*p_selected_index = 0; |
*p_selected_index = 0; |
| 252 |
} |
} |
| 253 |
|
else // end of last page |
| 254 |
|
{ |
| 255 |
|
return CHANGE_PAGE; // force refresh pages |
| 256 |
|
} |
| 257 |
} |
} |
| 258 |
else |
else |
| 259 |
{ |
{ |
| 260 |
(*p_selected_index)++; |
(*p_selected_index)++; |
| 261 |
} |
} |
| 262 |
break; |
break; |
| 263 |
|
case 'h': |
| 264 |
|
return SHOW_HELP; |
| 265 |
default: |
default: |
| 266 |
} |
} |
| 267 |
|
|
| 287 |
old_selected_index = *p_selected_index; |
old_selected_index = *p_selected_index; |
| 288 |
} |
} |
| 289 |
|
|
| 290 |
BBS_last_access_tm = time(0); |
BBS_last_access_tm = time(NULL); |
| 291 |
|
if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval) |
| 292 |
|
{ |
| 293 |
|
return CHANGE_PAGE; // force section list refresh |
| 294 |
|
} |
| 295 |
} |
} |
| 296 |
|
|
| 297 |
return EXIT_SECTION; |
return EXIT_SECTION; |
| 298 |
} |
} |
| 299 |
|
|
| 300 |
|
static int display_article_key_handler(int *p_key, DISPLAY_CTX *p_ctx) |
| 301 |
|
{ |
| 302 |
|
switch (*p_key) |
| 303 |
|
{ |
| 304 |
|
case 'p': |
| 305 |
|
case Ctrl('X'): |
| 306 |
|
section_topic_view_mode = !section_topic_view_mode; |
| 307 |
|
case 0: // Set msg |
| 308 |
|
if (section_topic_view_mode) |
| 309 |
|
{ |
| 310 |
|
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 311 |
|
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] " |
| 312 |
|
"同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] " |
| 313 |
|
"切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |"); |
| 314 |
|
} |
| 315 |
|
else |
| 316 |
|
{ |
| 317 |
|
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 318 |
|
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] " |
| 319 |
|
"移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] " |
| 320 |
|
"切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |"); |
| 321 |
|
} |
| 322 |
|
*p_key = 0; |
| 323 |
|
break; |
| 324 |
|
case 'r': // Reply article |
| 325 |
|
return 1; |
| 326 |
|
case KEY_UP: |
| 327 |
|
case KEY_PGUP: |
| 328 |
|
case KEY_HOME: |
| 329 |
|
if (p_ctx->reach_begin) |
| 330 |
|
{ |
| 331 |
|
if (section_topic_view_mode) |
| 332 |
|
{ |
| 333 |
|
*p_key = KEY_PGUP; |
| 334 |
|
} |
| 335 |
|
else |
| 336 |
|
{ |
| 337 |
|
*p_key = KEY_UP; |
| 338 |
|
} |
| 339 |
|
return 1; |
| 340 |
|
} |
| 341 |
|
break; |
| 342 |
|
case 'k': |
| 343 |
|
if (section_topic_view_mode) |
| 344 |
|
{ |
| 345 |
|
*p_key = KEY_PGUP; |
| 346 |
|
} |
| 347 |
|
else |
| 348 |
|
{ |
| 349 |
|
*p_key = KEY_UP; |
| 350 |
|
} |
| 351 |
|
return 1; |
| 352 |
|
case KEY_DOWN: |
| 353 |
|
case KEY_PGDN: |
| 354 |
|
case KEY_END: |
| 355 |
|
if (p_ctx->reach_end) |
| 356 |
|
{ |
| 357 |
|
if (section_topic_view_mode) |
| 358 |
|
{ |
| 359 |
|
*p_key = KEY_PGDN; |
| 360 |
|
} |
| 361 |
|
else |
| 362 |
|
{ |
| 363 |
|
*p_key = KEY_DOWN; |
| 364 |
|
} |
| 365 |
|
return 1; |
| 366 |
|
} |
| 367 |
|
break; |
| 368 |
|
case 'j': |
| 369 |
|
if (section_topic_view_mode) |
| 370 |
|
{ |
| 371 |
|
*p_key = KEY_PGDN; |
| 372 |
|
} |
| 373 |
|
else |
| 374 |
|
{ |
| 375 |
|
*p_key = KEY_DOWN; |
| 376 |
|
} |
| 377 |
|
return 1; |
| 378 |
|
} |
| 379 |
|
|
| 380 |
|
return 0; |
| 381 |
|
} |
| 382 |
|
|
| 383 |
int section_list_display(const char *sname) |
int section_list_display(const char *sname) |
| 384 |
{ |
{ |
| 385 |
static int display_nickname = 0; |
static int display_nickname = 0; |
| 386 |
|
|
| 387 |
SECTION_LIST *p_section; |
SECTION_LIST *p_section; |
| 388 |
|
char stitle[BBS_section_title_max_len + 1]; |
| 389 |
|
char master_list[(BBS_username_max_len + 1) * 3 + 1]; |
| 390 |
|
char page_info_str[LINE_BUFFER_LEN]; |
| 391 |
ARTICLE *p_articles[BBS_article_limit_per_page]; |
ARTICLE *p_articles[BBS_article_limit_per_page]; |
| 392 |
int article_count; |
int article_count; |
| 393 |
|
int page_count; |
| 394 |
int page_id = 0; |
int page_id = 0; |
| 395 |
int selected_index = 0; |
int selected_index = 0; |
| 396 |
|
ARTICLE_CACHE cache; |
| 397 |
int ret; |
int ret; |
| 398 |
|
int loop; |
| 399 |
|
int direction; |
| 400 |
|
ARTICLE article_new; |
| 401 |
|
|
| 402 |
p_section = section_list_find_by_name(sname); |
p_section = section_list_find_by_name(sname); |
| 403 |
if (p_section == NULL) |
if (p_section == NULL) |
| 406 |
return -1; |
return -1; |
| 407 |
} |
} |
| 408 |
|
|
| 409 |
if (section_list_draw_screen(p_section, display_nickname) < 0) |
if ((ret = section_list_rd_lock(p_section)) < 0) |
| 410 |
|
{ |
| 411 |
|
log_error("section_list_rd_lock(sid = 0) error\n"); |
| 412 |
|
return -2; |
| 413 |
|
} |
| 414 |
|
|
| 415 |
|
strncpy(stitle, p_section->stitle, sizeof(stitle) - 1); |
| 416 |
|
stitle[sizeof(stitle) - 1] = '\0'; |
| 417 |
|
strncpy(master_list, p_section->master_list, sizeof(master_list) - 1); |
| 418 |
|
master_list[sizeof(master_list) - 1] = '\0'; |
| 419 |
|
|
| 420 |
|
if ((ret = section_list_rd_unlock(p_section)) < 0) |
| 421 |
|
{ |
| 422 |
|
log_error("section_list_rd_unlock(sid = 0) error\n"); |
| 423 |
|
return -2; |
| 424 |
|
} |
| 425 |
|
|
| 426 |
|
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 427 |
{ |
{ |
| 428 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error\n"); |
| 429 |
return -2; |
return -2; |
| 430 |
} |
} |
| 431 |
|
|
| 432 |
if (p_section->visible_article_count > 0) |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 433 |
|
if (ret < 0) |
| 434 |
{ |
{ |
| 435 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count); |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 436 |
if (ret < 0) |
return -3; |
|
{ |
|
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
|
|
return -3; |
|
|
} |
|
| 437 |
} |
} |
| 438 |
else // empty section |
|
| 439 |
|
if (article_count == 0) // empty section |
| 440 |
{ |
{ |
|
article_count = 0; |
|
| 441 |
selected_index = 0; |
selected_index = 0; |
| 442 |
} |
} |
| 443 |
|
|
| 444 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 445 |
{ |
{ |
| 446 |
ret = section_list_draw_items(p_section, page_id, p_articles, article_count, display_nickname); |
ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname); |
| 447 |
if (ret < 0) |
if (ret < 0) |
| 448 |
{ |
{ |
| 449 |
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); |
| 450 |
return -4; |
return -4; |
| 451 |
} |
} |
| 452 |
|
|
| 453 |
|
snprintf(page_info_str, sizeof(page_info_str), |
| 454 |
|
"\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]", |
| 455 |
|
page_id + 1, MAX(page_count, 1)); |
| 456 |
|
|
| 457 |
|
show_bottom(page_info_str); |
| 458 |
iflush(); |
iflush(); |
| 459 |
|
|
| 460 |
ret = section_list_select(p_section->page_count, article_count, &page_id, &selected_index); |
ret = section_list_select(page_count, article_count, &page_id, &selected_index); |
| 461 |
switch (ret) |
switch (ret) |
| 462 |
{ |
{ |
| 463 |
case EXIT_SECTION: |
case EXIT_SECTION: |
| 464 |
return 0; |
return 0; |
| 465 |
case CHANGE_PAGE: |
case CHANGE_PAGE: |
| 466 |
if (p_section->visible_article_count > 0) |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 467 |
|
if (ret < 0) |
| 468 |
|
{ |
| 469 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 470 |
|
return -3; |
| 471 |
|
} |
| 472 |
|
if (article_count == 0) // empty section |
| 473 |
|
{ |
| 474 |
|
selected_index = 0; |
| 475 |
|
} |
| 476 |
|
else if (selected_index >= article_count) |
| 477 |
|
{ |
| 478 |
|
selected_index = article_count - 1; |
| 479 |
|
} |
| 480 |
|
break; |
| 481 |
|
case VIEW_ARTICLE: |
| 482 |
|
do |
| 483 |
|
{ |
| 484 |
|
loop = 0; |
| 485 |
|
|
| 486 |
|
if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_articles[selected_index]) < 0) |
| 487 |
|
{ |
| 488 |
|
log_error("article_cache_load(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
| 489 |
|
break; |
| 490 |
|
} |
| 491 |
|
|
| 492 |
|
ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0, |
| 493 |
|
display_article_key_handler, DATA_READ_HELP); |
| 494 |
|
|
| 495 |
|
if (article_cache_unload(&cache) < 0) |
| 496 |
|
{ |
| 497 |
|
log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
| 498 |
|
break; |
| 499 |
|
} |
| 500 |
|
|
| 501 |
|
// Update article_view_log |
| 502 |
|
if (article_view_log_set_viewed(p_articles[selected_index]->aid, &BBS_article_view_log) < 0) |
| 503 |
|
{ |
| 504 |
|
log_error("article_view_log_set_viewed(aid=%d) error\n", p_articles[selected_index]->aid); |
| 505 |
|
} |
| 506 |
|
|
| 507 |
|
switch (ret) |
| 508 |
|
{ |
| 509 |
|
case KEY_UP: |
| 510 |
|
if (selected_index <= 0) |
| 511 |
|
{ |
| 512 |
|
if (page_id > 0) |
| 513 |
|
{ |
| 514 |
|
page_id--; |
| 515 |
|
selected_index = BBS_article_limit_per_page - 1; |
| 516 |
|
|
| 517 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 518 |
|
if (ret < 0) |
| 519 |
|
{ |
| 520 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 521 |
|
return -3; |
| 522 |
|
} |
| 523 |
|
|
| 524 |
|
if (article_count != BBS_article_limit_per_page) // page is not full |
| 525 |
|
{ |
| 526 |
|
selected_index = MAX(0, article_count - 1); |
| 527 |
|
} |
| 528 |
|
else |
| 529 |
|
{ |
| 530 |
|
loop = 1; |
| 531 |
|
} |
| 532 |
|
} |
| 533 |
|
} |
| 534 |
|
else |
| 535 |
|
{ |
| 536 |
|
selected_index--; |
| 537 |
|
loop = 1; |
| 538 |
|
} |
| 539 |
|
break; |
| 540 |
|
case KEY_DOWN: |
| 541 |
|
if (selected_index + 1 >= article_count) // next page |
| 542 |
|
{ |
| 543 |
|
if (page_id + 1 < page_count) |
| 544 |
|
{ |
| 545 |
|
page_id++; |
| 546 |
|
selected_index = 0; |
| 547 |
|
|
| 548 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 549 |
|
if (ret < 0) |
| 550 |
|
{ |
| 551 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 552 |
|
return -3; |
| 553 |
|
} |
| 554 |
|
|
| 555 |
|
if (article_count == 0) // empty page |
| 556 |
|
{ |
| 557 |
|
selected_index = 0; |
| 558 |
|
} |
| 559 |
|
else |
| 560 |
|
{ |
| 561 |
|
loop = 1; |
| 562 |
|
} |
| 563 |
|
} |
| 564 |
|
} |
| 565 |
|
else |
| 566 |
|
{ |
| 567 |
|
selected_index++; |
| 568 |
|
loop = 1; |
| 569 |
|
} |
| 570 |
|
break; |
| 571 |
|
case KEY_PGUP: |
| 572 |
|
case KEY_PGDN: |
| 573 |
|
direction = (ret == KEY_PGUP ? -1 : 1); |
| 574 |
|
ret = locate_article_in_section(p_section, p_articles[selected_index], direction, &page_id, &selected_index, &page_count); |
| 575 |
|
if (ret < 0) |
| 576 |
|
{ |
| 577 |
|
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d) error\n", |
| 578 |
|
p_section->sid, p_articles[selected_index]->aid, direction); |
| 579 |
|
return -3; |
| 580 |
|
} |
| 581 |
|
else if (ret > 0) |
| 582 |
|
{ |
| 583 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 584 |
|
if (ret < 0) |
| 585 |
|
{ |
| 586 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 587 |
|
return -3; |
| 588 |
|
} |
| 589 |
|
loop = 1; |
| 590 |
|
} |
| 591 |
|
break; |
| 592 |
|
case 'r': // Reply article |
| 593 |
|
if (article_reply(p_section, p_articles[selected_index], &article_new) < 0) |
| 594 |
|
{ |
| 595 |
|
log_error("article_post(aid=%d, REPLY) error\n", p_articles[selected_index]->aid); |
| 596 |
|
} |
| 597 |
|
loop = 1; |
| 598 |
|
break; |
| 599 |
|
} |
| 600 |
|
} while (loop); |
| 601 |
|
|
| 602 |
|
// Update current topic |
| 603 |
|
section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid); |
| 604 |
|
case CHANGE_NAME_DISPLAY: |
| 605 |
|
display_nickname = !display_nickname; |
| 606 |
|
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 607 |
{ |
{ |
| 608 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count); |
log_error("section_list_draw_screen() error\n"); |
| 609 |
|
return -2; |
| 610 |
|
} |
| 611 |
|
break; |
| 612 |
|
case POST_ARTICLE: |
| 613 |
|
if ((ret = article_post(p_section, &article_new)) < 0) |
| 614 |
|
{ |
| 615 |
|
log_error("article_post(sid=%d) error\n", p_section->sid); |
| 616 |
|
} |
| 617 |
|
else if (ret > 0) // New article posted |
| 618 |
|
{ |
| 619 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 620 |
if (ret < 0) |
if (ret < 0) |
| 621 |
{ |
{ |
| 622 |
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); |
| 623 |
return -3; |
return -3; |
| 624 |
} |
} |
| 625 |
} |
} |
| 626 |
else // empty section |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 627 |
{ |
{ |
| 628 |
article_count = 0; |
log_error("section_list_draw_screen() error\n"); |
| 629 |
selected_index = 0; |
return -2; |
| 630 |
} |
} |
| 631 |
if (selected_index >= article_count) |
break; |
| 632 |
|
case EDIT_ARTICLE: |
| 633 |
|
if (!checkpriv(&BBS_priv, p_section->sid, S_POST) || |
| 634 |
|
p_articles[selected_index]->uid != BBS_priv.uid) |
| 635 |
{ |
{ |
| 636 |
selected_index = article_count - 1; |
break; // No permission |
| 637 |
|
} |
| 638 |
|
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
| 639 |
|
{ |
| 640 |
|
log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid); |
| 641 |
|
} |
| 642 |
|
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 643 |
|
{ |
| 644 |
|
log_error("section_list_draw_screen() error\n"); |
| 645 |
|
return -2; |
| 646 |
} |
} |
| 647 |
break; |
break; |
| 648 |
case VIEW_ARTICLE: |
case DELETE_ARTICLE: |
| 649 |
log_std("Debug: article %d selected\n", p_articles[selected_index]->aid); |
if (!checkpriv(&BBS_priv, p_section->sid, S_POST) || |
| 650 |
case REFRESH_SCREEN: |
(!checkpriv(&BBS_priv, p_section->sid, S_MAN_S) && p_articles[selected_index]->uid != BBS_priv.uid)) |
| 651 |
if (section_list_draw_screen(p_section, display_nickname) < 0) |
{ |
| 652 |
|
break; // No permission |
| 653 |
|
} |
| 654 |
|
if ((ret = article_del(p_section, p_articles[selected_index])) < 0) |
| 655 |
|
{ |
| 656 |
|
log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid); |
| 657 |
|
} |
| 658 |
|
else if (ret > 0) // Article deleted |
| 659 |
|
{ |
| 660 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 661 |
|
if (ret < 0) |
| 662 |
|
{ |
| 663 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 664 |
|
return -3; |
| 665 |
|
} |
| 666 |
|
} |
| 667 |
|
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 668 |
{ |
{ |
| 669 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error\n"); |
| 670 |
return -2; |
return -2; |
| 671 |
} |
} |
| 672 |
break; |
break; |
| 673 |
case CHANGE_NAME_DISPLAY: |
case SHOW_HELP: |
| 674 |
display_nickname = !display_nickname; |
// Display help information |
| 675 |
if (section_list_draw_screen(p_section, display_nickname) < 0) |
display_file(DATA_READ_HELP, 1); |
| 676 |
|
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 677 |
{ |
{ |
| 678 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error\n"); |
| 679 |
return -2; |
return -2; |