📄 personal_corp.c
字号:
// pc_dir_start = 0; if (pc_dirmode == 4) { int ret; unsigned long retnid; if (pc_fav_dir == 0) { ret = pc_get_fav_root(&retnid); if (ret < 0) return 0; if (ret == 0) { pc_add_fav_root(); ret = pc_get_fav_root(&retnid); if (ret <= 0) return 0; } pc_fav_dir = retnid; } } if (first) { pc_n = (struct pc_nodes *) malloc(sizeof(struct pc_nodes) * BBS_PAGESIZE); if (pc_n == NULL) return 0; } bzero(&group_conf, sizeof(struct _select_def)); pts = (POINT *) malloc(sizeof(POINT) * BBS_PAGESIZE); for (i = 0; i < BBS_PAGESIZE; i++) { pts[i].x = 2; pts[i].y = i + 3; } group_conf.item_per_page = BBS_PAGESIZE; group_conf.flag = LF_VSCROLL | LF_BELL | LF_MULTIPAGE | LF_LOOP; group_conf.prompt = "◆"; group_conf.item_pos = pts; group_conf.title_pos.x = 0; group_conf.title_pos.y = 0; group_conf.pos = 1; group_conf.page_pos = 1; group_conf.show_data = pc_dir_show; group_conf.show_title = pc_dir_title; group_conf.pre_key_command = pc_dir_prekey; group_conf.on_select = pc_dir_select; group_conf.get_data = pc_dir_getdata; group_conf.key_command = pc_dir_key; bzero(pc_n, sizeof(struct pc_nodes) * BBS_PAGESIZE); group_conf.item_count = count_pc_nodes(pc_u->uid, pc_fav_dir, -1, pc_dirmode - 1); i = get_pc_nodes(pc_n, pc_u->uid, pc_fav_dir, -1, pc_dirmode - 1, 0, BBS_PAGESIZE, 0); if (i < 0) { free(pts); if (first) free(pc_n); if (pc_dirmode == 4) pc_fav_dir = 0; return -1; } if (i == 0) { if (!pc_is_owner(pc_u->username)) { clear(); move(7, 0); prints("暂时没有文章"); pressanykey(); free(pts); if (first) free(pc_n); if (pc_dirmode == 4) pc_fav_dir = 0; return -1; } clear(); move(7, 0); prints("本区暂时没有文章,增加新文章"); if (!pc_add_a_node(0)) { free(pts); if (first) free(pc_n); if (pc_dirmode == 4) pc_fav_dir = 0; return -1; } i = get_pc_nodes(pc_n, pc_u->uid, pc_fav_dir, -1, pc_dirmode - 1, 0, BBS_PAGESIZE, 0); group_conf.item_count = i; } if (i <= 0) { free(pts); if (first) free(pc_n); if (pc_dirmode == 4) pc_fav_dir = 0; return -1; } clear(); list_select_loop(&group_conf); free(pts); if (first) { free(pc_n); pc_n = NULL; } //pc_dir_start=0; if (pc_dirmode == 4) { pc_fav_dir = 0; } return 0;}/*************************************************************** * * * * * 以下是评论的select * * * * * ***************************************************************/struct pc_comments *pc_c = NULL;//int pc_com_start=0;static int pc_can_com(int comlevel , unsigned long pcuid ){ if (comlevel == 0) return 0; if (comlevel == 1 && !strcmp(getCurrentUser()->userid, "guest")) return 0; if (pc_in_blacklist( getCurrentUser()->userid , pcuid ) ) return 0; return 1;}/******* * nid==0 : 增加 * nid > 0: 修改 * nid为序号 */static int pc_add_a_com(unsigned long nid){ struct pc_comments pn; char ans[201]; char fpath[STRLEN]; int ret; bzero(&pn, sizeof(pn)); if (nid) { if (get_pc_a_com(&pn, nid) <= 0) return 0; } move(t_lines - 1, 0); clrtoeol(); if (nid) { strncpy(ans, pn.subject, 200); ans[200] = 0; } else ans[0] = 0; getdata(t_lines - 1, 0, "标题:", ans, 200, DOECHO, NULL, false); if (!ans[0]) return 0; strncpy(pn.subject, ans, 200); pn.subject[200] = 0; gettmpfilename(fpath, "pc.comments"); unlink(fpath); if (nid && pn.body) { pc_conv_body_to_file(pn.body, fpath); free(pn.body); pn.body = NULL; } else unlink(fpath); if (vedit(fpath, 0, NULL, NULL, 0) == -1) return 0; pn.body = NULL; if (!pc_conv_file_to_body(&(pn.body), fpath)) { unlink(fpath); return 0; } unlink(fpath); strncpy(pn.hostname, uinfo.from, 20); pn.hostname[20] = 0; pn.changed = time(0); if (!nid) pn.created = pn.changed; pn.uid = pc_u->uid; pn.nid = pc_n[pc_now_node_ent].nid; strncpy(pn.username, getCurrentUser()->userid, 20); pn.username[20] = 0; ret = add_pc_comments(&pn); if (pn.body) free(pn.body); return ret;}static int pc_com_title(struct _select_def *conf){ int chkmailflag; chkmailflag = chkmail(); clear(); move(0, 0); if (chkmailflag == 2) { prints("\033[0;1;5;44m [您的信箱超过容量,不能再收信!] \033[m"); } else if (chkmailflag) { prints("\033[0;1;5;44m [您有信件] \033[m"); } else { prints("\033[0;1;44m %s的个人文集评论 -- %-42s ", pc_u->username, pc_u->corpusname); switch (pc_dirmode) { case 2: prints("[好友区]\033[m"); break; case 3: prints("[私人区]\033[m"); break; case 4: prints("[收藏区]\033[m"); break; case 5: prints("[删除区]\033[m"); break; default: prints("[公开区]\033[m"); break; } } move(1, 0); prints(" 退出[\033[1;32mq\033[m] 增加[\033[1;32ma\033[m] 删除[\033[1;32md\033[m] 修改[\033[1;32me\033[m]"); move(2, 0); prints("\033[0;1;44m %-4s %-13s %-40s %-15s\033[m", "序号", "作者", "标题", "时间"); update_endline(); return SHOW_CONTINUE;}static int pc_com_show(struct _select_def *conf, int i){ char newts[20]; prints(" %-3d %-13s %-40s %-15s", i, pc_c[i - conf->page_pos].username, pc_c[i - conf->page_pos].subject, tt2timestamp(pc_c[i - conf->page_pos].created, newts)); return SHOW_CONTINUE;}static int pc_com_prekey(struct _select_def *conf, int *key){ switch (*key) { case 'q': *key = KEY_LEFT; break; case 'p': case 'k': *key = KEY_UP; break; case 'n': case 'j': *key = KEY_DOWN; break; } return SHOW_CONTINUE;}static int pc_com_key(struct _select_def *conf, int key){ switch (key) { case 'a': if (!pc_can_com(pc_n[pc_now_node_ent].comment , pc_n[pc_now_node_ent].uid)) return SHOW_CONTINUE; if (pc_add_a_com(0)) return SHOW_DIRCHANGE; return SHOW_REFRESH; break; case 'd': if (!pc_is_admin(pc_u->username) && strcasecmp(getCurrentUser()->userid, pc_c[conf->pos - conf->page_pos].username)) return SHOW_CONTINUE; if (del_pc_comments(pc_n[pc_now_node_ent].nid, pc_c[conf->pos - conf->page_pos].cid)) { return SHOW_DIRCHANGE; } return SHOW_REFRESH; break; case 'e': if (strcasecmp(getCurrentUser()->userid, pc_c[conf->pos - conf->page_pos].username)) return SHOW_CONTINUE; if (pc_add_a_com(pc_c[conf->pos - conf->page_pos].cid)) return SHOW_DIRCHANGE; return SHOW_REFRESH; break; case 'v': i_read_mail(); return SHOW_REFRESH; break; } return SHOW_CONTINUE;}static int pc_com_getdata(struct _select_def *conf, int pos, int len){ int i; for (i = 0; i < BBS_PAGESIZE; i++) { if (pc_c[i].body) free(pc_c[i].body); } bzero(pc_c, sizeof(struct pc_comments) * BBS_PAGESIZE); if (conf->item_count - conf->page_pos < BBS_PAGESIZE) conf->item_count = count_pc_comments(pc_n[pc_now_node_ent].nid); i = get_pc_comments(pc_c, pc_n[pc_now_node_ent].nid, conf->page_pos - 1, BBS_PAGESIZE, 0); if (i < 0) return SHOW_QUIT; if (i == 0) { conf->pos = 1; i = get_pc_comments(pc_c, pc_n[pc_now_node_ent].nid, 0, BBS_PAGESIZE, 0); if (i <= 0) return SHOW_QUIT; } return SHOW_CONTINUE;}static int pc_com_select(struct _select_def *conf){ char fpath[STRLEN]; clear(); /***先显示文章正文*****/ gettmpfilename(fpath, "pc.comments"); unlink(fpath); if (!pc_conv_com_to_file(pc_c[conf->pos - conf->page_pos].cid, fpath)) { move(3, 0); prints("评论没有内容"); pressanykey(); return SHOW_REFRESH; } ansimore(fpath, true); unlink(fpath); return SHOW_REFRESH;}int pc_read_comment(){ struct _select_def group_conf; POINT *pts; int i; if (pc_now_node_ent < 0 || pc_now_node_ent >= BBS_PAGESIZE) return 0; pc_c = (struct pc_comments *) malloc(sizeof(struct pc_comments) * BBS_PAGESIZE); if (pc_c == NULL) return 0; bzero(&group_conf, sizeof(struct _select_def)); pts = (POINT *) malloc(sizeof(POINT) * BBS_PAGESIZE); for (i = 0; i < BBS_PAGESIZE; i++) { pts[i].x = 2; pts[i].y = i + 3; } group_conf.item_per_page = BBS_PAGESIZE; group_conf.flag = LF_VSCROLL | LF_BELL | LF_MULTIPAGE | LF_LOOP; group_conf.prompt = "◆"; group_conf.item_pos = pts; group_conf.title_pos.x = 0; group_conf.title_pos.y = 0; group_conf.pos = 1; group_conf.page_pos = 1; group_conf.show_data = pc_com_show; group_conf.key_command = pc_com_key; group_conf.get_data = pc_com_getdata; group_conf.show_title = pc_com_title; group_conf.pre_key_command = pc_com_prekey; group_conf.on_select = pc_com_select; bzero(pc_c, sizeof(struct pc_comments) * BBS_PAGESIZE); group_conf.item_count = count_pc_comments(pc_n[pc_now_node_ent].nid); i = get_pc_comments(pc_c, pc_n[pc_now_node_ent].nid, 0, BBS_PAGESIZE, 0); if (i < 0) { free(pts); free(pc_c); return -1; } if (i == 0) { char ans[3]; if (!pc_can_com(pc_n[pc_now_node_ent].comment , pc_n[pc_now_node_ent].uid)) { clear(); move(7, 0); prints("暂时没有评论"); pressanykey(); free(pts); free(pc_c); return -1; } clear(); getdata(7, 0, "本文暂时没有评论,增加新评论吗? (Y/N) [N]:", ans, 3, DOECHO, NULL, true); if ((ans[0] != 'y' && ans[0] != 'Y') || !pc_add_a_com(0)) { free(pts); free(pc_c); return -1; } i = get_pc_comments(pc_c, pc_n[pc_now_node_ent].nid, 0, BBS_PAGESIZE, 0); group_conf.item_count = i; } if (i <= 0) { free(pts); free(pc_c); return -1; } clear(); list_select_loop(&group_conf); free(pts); free(pc_c); pc_c = NULL; return 0;}int import_to_pc(int ent, struct fileheader *fileinfo, char *direct){ struct pc_users pu; struct pc_nodes pn; char fpath[STRLEN]; int ret; char buf1[512]; char *t; if (!(getCurrentUser()->flags & PCORP_FLAG)) return DONOTHING; bzero(&pu, sizeof(pu)); if (get_pc_users(&pu, getCurrentUser()->userid) <= 0) return FULLUPDATE; bzero(&pn, sizeof(pn)); strncpy(pn.subject, fileinfo->title, ARTICLE_TITLE_LEN - 1); pn.subject[ARTICLE_TITLE_LEN - 1] = 0; strcpy(buf1, direct); if ((t = strrchr(buf1, '/')) != NULL) *t = '\0'; snprintf(fpath, 512, "%s/%s", buf1, fileinfo->filename); pn.body = NULL; if (!pc_conv_file_to_body(&(pn.body), fpath)) { return DONOTHING; } strncpy(pn.hostname, uinfo.from, 20); pn.hostname[20] = 0; pn.created = time(0); pn.changed = pn.created; pn.uid = pu.uid; pn.comment = 1; pn.access = 3 - 1; ret = add_pc_nodes(&pn); if (pn.body) free(pn.body); { char buf[4]; move(t_lines - 1, 0); clrtoeol(); if (ret) getdata(t_lines - 1, 0, "收录到个人文集成功,按回车继续<<", buf, 3, NOECHO, NULL, true); else getdata(t_lines - 1, 0, "收录到个人文集失败,按回车继续<<", buf, 3, NOECHO, NULL, true); } return FULLUPDATE;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -