⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 personal_corp.c

📁 KBSBBS系统Blog外挂程序 可以在KBSBBS上支持SMTH Blog系统 技术在不断完善
💻 C
📖 第 1 页 / 共 4 页
字号:
#include "bbs.h"#ifdef PERSONAL_CORP#include "read.h"//#include "mysql.h"struct pc_users *pc_u = NULL;/******* * pc_dirmode:  *   1: 公开区 *   2: 好友 *   3: 私人 *   4: 收藏 *   5: 删除 */int pc_dirmode = 0;//收藏夹当前路径,0表示未进入收藏夹unsigned long pc_fav_dir = 0;int pc_choose_user(){    pc_sec();    return 0;}static int pc_sel_user(){    char ans[20];    clear();    getdata(5, 0, "你要查看谁的个人文集? [回车查看自己的个人文集]:", ans, 20, DOECHO, NULL, true);    if (ans[0] == 0 || ans[0] == '\n' || ans[0] == '\r') {        pc_read(getCurrentUser()->userid);    } else        pc_read(ans);    return 0;}int pc_add_user(){    char ans[201];    char sql[100];    struct userec *lookupuser;    struct pc_users pu;    clear();    move(0, 0);    prints("[个人文集管理]");    move(1, 0);    prints("请输入待处理用户id:");    usercomplete(NULL, ans);    if (ans[0] == 0 || ans[0] == '\n' || ans[0] == '\r')        return 0;    if (getuser(ans, &lookupuser) != 0) {        if (!HAS_PERM(lookupuser, PERM_BASIC)) {            move(7, 0);            prints("此用户尚无基本权限,无法开启个人文集");            pressanykey();            return 0;        }    } else {        move(7, 0);        prints("此用户不存在");        pressanykey();        return 0;    }    bzero(&pu, sizeof(pu));    if (get_pc_users(&pu, lookupuser->userid)) {        getdata(4, 0, "该用户已经拥有个人文集, [1]修改 [2]删除 [0] 返回, [0]:", ans, 3, DOECHO, NULL, true);        if (ans[0] == '2') {            move(6, 0);            prints("\033[1;31m删除个人文集操作将丢失该用户所有个人文集,不可恢复\033[m");            getdata(7, 0, "你确定要删除吗? (Y/N) [N]:", ans, 3, DOECHO, NULL, true);            if (ans[0] != 'y' && ans[0] != 'Y')                return 0;            if (del_pc_users(&pu)) {                char buf1[256];                lookupuser->flags &= ~PCORP_FLAG;                move(10, 0);                prints("删除成功");                pressanykey();                sprintf(buf1, "%s 取消 %s 的个人文集", getCurrentUser()->userid, lookupuser->userid);                securityreport(buf1, lookupuser, NULL);                return 1;            } else {                move(10, 0);                prints("删除失败");                pressanykey();                return 0;            }        } else if (ans[0] != '1')            return 0;    } else {        move(4, 0);        prints("该用户尚没有个人文集,添加进行中,不输入个人文集名称自动取消");    }    strncpy(pu.username, lookupuser->userid, IDLEN + 2);    pu.username[IDLEN + 1] = 0;    if (pu.uid) {        strncpy(ans, pu.corpusname, 40);        ans[40] = 0;    } else        ans[0] = 0;    getdata(5, 0, "请输入个人文集名称:", ans, 40, DOECHO, NULL, false);    if (ans[0]) {        strncpy(pu.corpusname, ans, 40);        pu.corpusname[40] = 0;    } else {        if (!pu.uid)            return 0;    }    if (pu.uid) {        strncpy(ans, pu.description, 200);        ans[200] = 0;    } else        ans[0] = 0;    move(6, 0);    prints("请输入个人文集描述:");    multi_getdata(7, 0, 79, NULL, ans, 200, 4, false, 0);    if (ans[0]) {        strncpy(pu.description, ans, 200);        pu.description[200] = 0;    }    if (pu.uid) {        strncpy(ans, pu.theme, 10);        ans[10] = 0;    } else        ans[0] = 0;    getdata(12, 0, "请输入主题:", ans, 10, DOECHO, NULL, false);    if (ans[0]) {        strncpy(pu.theme, ans, 10);        pu.theme[10] = 0;    }    if (pu.uid)        sprintf(ans, "%d", pu.nodelimit);    else        sprintf(ans, "%d", PC_DEFAULT_NODELIMIT);    sprintf(sql, "个人文集允许最多文章数 [%s]:", ans);    getdata(13, 0, sql, ans, 5, DOECHO, NULL, false);    if (ans[0]) {        pu.nodelimit = atoi(ans);        if (pu.nodelimit <= 0)            pu.nodelimit = PC_DEFAULT_NODELIMIT;    }    if (pu.uid)        sprintf(ans, "%d", pu.dirlimit);    else        sprintf(ans, "%d", PC_DEFAULT_DIRLIMIT);    sprintf(sql, "个人文集允许最多目录数 [%s]:", ans);    getdata(14, 0, sql, ans, 5, DOECHO, NULL, false);    if (ans[0]) {        pu.dirlimit = atoi(ans);        if (pu.dirlimit <= 0)            pu.dirlimit = PC_DEFAULT_DIRLIMIT;    }    if (pu.uid)        getdata(15, 0, "确定修改? (Y/N) [N]:", ans, 3, DOECHO, NULL, true);    else        getdata(15, 0, "确定开启? (Y/N) [N]:", ans, 3, DOECHO, NULL, true);    if (ans[0] != 'y' && ans[0] != 'Y')        return 0;    if (pu.uid == 0)        pu.createtime = time(0);    if (add_pc_users(&pu)) {        char buf1[256];        lookupuser->flags |= PCORP_FLAG;        move(18, 0);        if (pu.uid)            prints("修改成功", lookupuser->userid);        else            prints("添加成功,用户%s已经拥有个人文集", lookupuser->userid);        pressanykey();        sprintf(buf1, "%s 增加 %s 的个人文集", getCurrentUser()->userid, lookupuser->userid);        securityreport(buf1, lookupuser, NULL);        return 1;    } else {        move(18, 0);        prints("系统错误......", lookupuser->userid);        pressanykey();        return 0;    }}static int pc_add_friend(char *uident, char *fpath, int echo){    int seek;    int id;    struct userec *lookupuser;    if (!(id = getuser(uident, &lookupuser))) {        if (echo) {            move(3, 0);            prints("Invalid User Id");            clrtoeol();            pressreturn();            clear();        }        return 0;    }    strcpy(uident, lookupuser->userid);    seek = seek_in_file(fpath, uident);    if (seek) {        if (echo) {            move(2, 0);            prints("输入的ID 已经存在!");            pressreturn();        }        return -1;    }    seek = addtofile(fpath, uident);;    return 1;}static int pc_del_friend(char *uident, char *fpath){    struct userec *lookupuser;    int id;    if (!(id = getuser(uident, &lookupuser))) {        move(3, 0);        prints("Invalid User Id");        clrtoeol();        pressreturn();        clear();        return 0;    }    strcpy(uident, lookupuser->userid);    del_from_file(fpath, uident);;    return 1;}static int pc_change_friend(){    char buf[STRLEN];    int count;    char ans[20];    char uident[STRLEN];    sethomefile(buf, getCurrentUser()->userid, "pc_friend");    while (1) {        clear();        prints("设定个人文集好友名单\n");        count = listfilecontent(buf);        if (count)            getdata(1, 0, "(A)增加 (D)删除or (E)离开[E]", ans, 7, DOECHO, NULL, true);        else            getdata(1, 0, "(A)增加 or (E)离开 [E]: ", ans, 7, DOECHO, NULL, true);        if (*ans == 'A' || *ans == 'a') {            move(1, 0);            usercomplete("增加个人文集好友成员: ", uident);            if (*uident != '\0') {                pc_add_friend(uident, buf, 1);            }        } else if ((*ans == 'D' || *ans == 'd') && count) {            move(1, 0);            namecomplete("删除个人文集好友成员: ", uident);            if (uident[0] != '\0') {                pc_del_friend(uident, buf);            }        } else            break;    }    return 1;}/****************************** * * * 选择分区 * * **********************/static int pc_sec_prekey(struct _select_def *conf, int *key){    if (*key >= 'a' && *key <= 'z') {        conf->new_pos = *key - 'a' + 3;        return SHOW_SELCHANGE;    }    if (*key >= 'A' && *key <= 'Z') {        conf->new_pos = *key - 'A' + 3;        return SHOW_SELCHANGE;    }    switch (*key) {    case '*':        conf->new_pos = 1;        return SHOW_SELCHANGE;    case KEY_RIGHT:        if (conf->pos < 15) {            conf->new_pos += 14;            return SHOW_SELCHANGE;        } else {            *key = '\n';        }        break;    case KEY_LEFT:        if (conf->pos > 14) {            conf->new_pos -= 14;            return SHOW_SELCHANGE;        }        break;    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_sec_title(struct _select_def *conf){    clear();    move(1, 0);    prints(" 请选择个人文集");    return SHOW_CONTINUE;}static int pc_sec_show(struct _select_def *conf, int i){    if (i > 2)        prints("%c", 'A' + i - 3);    else if (i == 1)        prints("*)自己的个人文集");    else if (i == 2)        prints("直接选择个人文集");    return SHOW_CONTINUE;}static int pc_sec_select(struct _select_def *conf){    if (conf->pos > 2)        pc_selusr('A' + conf->pos - 3);    else if (conf->pos == 1)        pc_read(getCurrentUser()->userid);    else if (conf->pos == 2)        pc_sel_user();    return SHOW_REFRESH;}int pc_sec(){    struct _select_def group_conf;    POINT *pts;    int i;    clear();    bzero(&group_conf, sizeof(struct _select_def));    pts = (POINT *) malloc(sizeof(POINT) * 28);    for (i = 0; i < 28; i++) {        pts[i].x = 5 + (i > 13 ? 30 : 0);        pts[i].y = i % 14 + 3;    }    group_conf.item_per_page = 28;    group_conf.flag = LF_VSCROLL | LF_BELL | 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.item_count = 28;    group_conf.show_data = pc_sec_show;    group_conf.show_title = pc_sec_title;    group_conf.pre_key_command = pc_sec_prekey;    group_conf.on_select = pc_sec_select;    list_select_loop(&group_conf);    free(pts);    return 0;}/*************************************************** * * * * * 选择具体用户 * * * * ***************************************************/struct _pc_selusr *pc_s;static int pc_seldir_prekey(struct _select_def *conf, int *key){    switch (*key) {    case KEY_RIGHT:        *key = '\n';        break;    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_selusr_title(struct _select_def *conf){    clear();    docmdtitle("[个人文集选择]", "退出[\033[1;32mq\033[m]");    move(2, 0);    prints("\033[0;1;44m  %-4s %-13s %-40s %-15s\033[m", "序号", "用户", "个人文集名字", "开启时间");    update_endline();    return SHOW_CONTINUE;}static int pc_selusr_show(struct _select_def *conf, int i){    char newts[20];    prints("%-4d %-13s %-40s %-15s", i, pc_s[i - 1].userid, pc_s[i - 1].corpusname, tt2timestamp(pc_s[i - 1].createtime, newts));    return SHOW_CONTINUE;}static int pc_selusr_select(struct _select_def *conf){    pc_read(pc_s[conf->pos - 1].userid);    return SHOW_REFRESH;}int pc_selusr(char prefix){    struct _select_def group_conf;    POINT *pts;    int i, ret;    clear();    ret = pc_load_usr(&pc_s, prefix);    if (ret <= 0) {        move(3, 0);        prints("数据错误或者尚未有该字母开头的用户个人文集");        pressanykey();        return -1;    }    bzero(&group_conf, sizeof(struct _select_def));    //TODO: 窗口大小动态改变的情况?这里有bug    pts = (POINT *) malloc(sizeof(POINT) * BBS_PAGESIZE);    for (i = 0; i < BBS_PAGESIZE; i++) {        pts[i].x = 3;        pts[i].y = i + 3;    }    group_conf.item_per_page = BBS_PAGESIZE;    group_conf.flag = LF_VSCROLL | LF_BELL | 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.item_count = ret;    group_conf.show_title = pc_selusr_title;    group_conf.show_data = pc_selusr_show;    group_conf.pre_key_command = pc_seldir_prekey;    group_conf.on_select = pc_selusr_select;    list_select_loop(&group_conf);    free(pts);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -