phpbbs.post.c
来自「linux/unix环境下的建站系统」· C语言 代码 · 共 1,270 行 · 第 1/3 页
C
1,270 行
fp = fopen(filepath, "w"); write_header(fp, getCurrentUser(), 0, board, title, anony, (local_save ? 1 : 2), getSession()); if (clen > 0) { f_append(fp, unix_string(content)); } if (!anony) { getCurrentUser()->signature = sig; if (sig < 0) { struct userdata ud; read_userdata(getCurrentUser()->userid, &ud); if (ud.signum > 0) { sig = 1 + (int) (((double)ud.signum) * rand() / (RAND_MAX + 1.0)); //(rand() % ud.signum) + 1; } else sig = 0; } addsignature(fp, getCurrentUser(), sig); } if (sig == 0) { fputs("\n--\n", fp); } else { fprintf(fp, "\n"); } color = (getCurrentUser()->numlogins % 7) + 31; /* 颜色随机变化 */ if (!strcmp(board, "Announce")) fprintf(fp, "\033[m\033[%2dm※ 来源:·%s http://%s·[FROM: %s]\033[m\n", color, BBS_FULL_NAME, BBS_FULL_NAME, BBS_FULL_NAME); else fprintf(fp, "\n\033[m\033[%2dm※ 来源:·%s http://%s·[FROM: %s]\033[m\n", color, BBS_FULL_NAME, NAME_BBS_ENGLISH, (anony) ? NAME_ANONYMOUS_FROM : SHOW_USERIP(getCurrentUser(), getSession()->fromhost)); if (brd->flag&BOARD_ATTACH) { upload_post_append(fp, &post_file, getSession()); } fclose(fp); post_file.eff_size = get_effsize(filepath); strnzhcpy(post_file.title, title, ARTICLE_TITLE_LEN); if (local_save) { /* local save */ post_file.innflag[1] = 'L'; post_file.innflag[0] = 'L'; } else { post_file.innflag[1] = 'S'; post_file.innflag[0] = 'S'; outgo_post(&post_file, board, title, getSession()); } if (mailback) post_file.accessed[1] |= FILE_MAILBACK; if (is_tex) post_file.accessed[1] |= FILE_TEX; /* * 在boards版版主发文自动添加文章标记 Bigman:2000.8.12 */ if (!strcmp(board, "Board") && !HAS_PERM(getCurrentUser(), PERM_OBOARDS) && HAS_PERM(getCurrentUser(), PERM_BOARDS)) { post_file.accessed[0] |= FILE_SIGN; }#ifdef HAVE_BRC_CONTROL brc_initial(getCurrentUser()->userid, board, getSession());#endif retvalue = after_post(getCurrentUser(), &post_file, board, oldx, !anony, getSession()); if (retvalue > 0) {#ifdef WWW_GENERATE_STATIC generate_static(DIR_MODE_NORMAL,&post_file,board,oldx);#endif } if (!junkboard(board)) { getCurrentUser()->numposts++; } if (retvalue == -1) { RETURN_LONG(-9); } else if (retvalue == -2) { RETURN_LONG(-10); } else { RETURN_LONG(retvalue); }}/** * del board article * prototype: * int bbs_delpost(string board, int id); * * @return the result * 0 -- success * -1 -- no perm * -2 -- failed * @author pig2532 */PHP_FUNCTION(bbs_delpost){ const boardheader_t *brd; struct fileheader f; char* board; int ent; long id; int board_len; int ac = ZEND_NUM_ARGS(); if (ac != 2 || zend_parse_parameters(2 TSRMLS_CC, "sl", &board, &board_len,&id) == FAILURE) { WRONG_PARAM_COUNT; } brd = getbcache(board); if (brd == 0) RETURN_LONG(-2); ent = get_ent_from_id_ext(DIR_MODE_NORMAL, id, brd->filename, &f); if(ent < 0) { RETURN_LONG(-2); } if(del_post(ent, &f, brd) != 0) { RETURN_LONG(-2); } else { RETURN_LONG(0); }}PHP_FUNCTION(bbs_article_deny_modify){ const boardheader_t *brd; struct fileheader f; char* board; int ent,ret; long id; int board_len; int ac = ZEND_NUM_ARGS(); if (ac != 2 || zend_parse_parameters(2 TSRMLS_CC, "sl", &board, &board_len,&id) == FAILURE) { WRONG_PARAM_COUNT; } brd = getbcache(board); if (!brd) RETURN_ERROR(BOARD_NONEXIST); ent = get_ent_from_id_ext(DIR_MODE_NORMAL, id, brd->filename, &f); if (ent < 0) { RETURN_ERROR(POST_NONEXIST); } ret = deny_modify_article(brd, &f, DIR_MODE_NORMAL, getSession()); if (!ret) RETURN_LONG(0); switch(ret) { case -1: RETURN_ERROR(GENERAL); break; case -2: RETURN_ERROR(BOARD_DENYPOST); break; case -3: RETURN_ERROR(GENERAL); break; case -4: RETURN_ERROR(GENERAL); break; case -5: RETURN_ERROR(BOARD_READONLY); break; case -6: RETURN_ERROR(BOARD_DENYMOD); break; default: RETURN_ERROR(GENERAL); break; }}PHP_FUNCTION(bbs_article_modify){}/* function bbs_updatearticle(string boardName, string filename ,string text) * 更新编辑文章 * */PHP_FUNCTION(bbs_updatearticle){ char *boardName, *filename, *content; int blen, flen, clen; FILE *fin; FILE *fout; char infile[80], outfile[80]; char buf2[256]; int i; const boardheader_t *bp; int asize; /*int filtered = 0;*/ int ac = ZEND_NUM_ARGS(); /* * getting arguments */ if (ac != 3 || zend_parse_parameters(3 TSRMLS_CC, "sss/", &boardName, &blen, &filename, &flen, &content, &clen) == FAILURE) { WRONG_PARAM_COUNT; } if ( (bp=getbcache(boardName))==0) { RETURN_LONG(-1); } if (clen == 0) content = ""; else content = unix_string(content);#ifdef FILTER if (check_badword_str(content, strlen(content),getSession())) { RETURN_LONG(-1); //修改文章失败,文章可能含有不恰当内容. }#endif setbfile(infile, bp->filename, filename); sprintf(outfile, "tmp/%s.%d.editpost", getCurrentUser()->userid, getpid()); if ((fin = fopen(infile, "r")) == NULL) RETURN_LONG(-10); if ((fout = fopen(outfile, "w")) == NULL) { fclose(fin); RETURN_LONG(-10); } for (i = 0; i < 4; i++) { fgets(buf2, sizeof(buf2), fin); if ((i==0) && (strncmp(buf2,"发信人",6)!=0)) { break; } fprintf(fout, "%s", buf2); } /* 解决很猪的问题之一 by pig2532 */ if (clen>0) { fprintf(fout, "%s", content); if(content[clen-1] != '\n') fprintf(fout, "\n"); } while ((asize = -attach_fgets(buf2, sizeof(buf2), fin)) != 0) { if (asize <= 0) { if (Origin2(buf2)) { fprintf(fout, "%s", buf2); } } else { put_attach(fin, fout, asize); } } fclose(fin); fclose(fout); f_cp(outfile, infile, O_TRUNC); unlink(outfile); add_edit_mark(infile, 0, NULL, getSession()); RETURN_LONG(0);}/* * function bbs_edittitle(string boardName , int id , string newTitle , int dirMode) * 修改文章标题 * @author: windinsn apr 28,2004 * return 0 : 成功 * -1: 版面错误 * -2: 该版不能修改文章 * -3: 只读讨论区 * -4: 文件错误 * -5: 封禁中 * -6: 无权修改 * -7: 被过滤掉 * -8: 当前模式不能编辑标题 * -9: 标题过长或为空 * -10:system error */PHP_FUNCTION(bbs_edittitle){ char *board,*title; int board_len,title_len; long id , mode; char path[STRLEN]; char dirpath[STRLEN]; struct fileheader f; struct fileheader xfh; const struct boardheader *brd; int bid,ent,i=0; int fd,ret; bool find; int ac = ZEND_NUM_ARGS(); if (ac != 4 || zend_parse_parameters(4 TSRMLS_CC, "sls/l", &board, &board_len, &id , &title, &title_len , &mode) == FAILURE) WRONG_PARAM_COUNT; if (title_len == 0) RETURN_LONG(-9); bid = getbid(board, &brd); if (bid==0) RETURN_LONG(-1); //版面名称错误 if (brd->flag&BOARD_GROUP) RETURN_LONG(-1); //二级目录版 if (mode != DIR_MODE_ZHIDING) mode = DIR_MODE_NORMAL; setbdir(mode, dirpath, brd->filename); if ((fd = open(dirpath, O_RDWR, 0644)) < 0) RETURN_LONG(-10); if (mode == DIR_MODE_ZHIDING) /* find "zhiding" record, by pig2532 */ { ent = 0; find = 0; while (1) { if (read(fd, &f, sizeof(struct fileheader)) <= 0) break; ent++; if(f.id == id) { find = 1; break; } } if (!find) { close(fd); RETURN_LONG(-4); } } else if (!get_records_from_id(fd,id,&f,1,&ent)) { close(fd); RETURN_LONG(-4); //无法取得文件记录 } close(fd); ret = deny_modify_article(brd, &f, mode, getSession()); if (ret) { switch(ret) { case -1: RETURN_LONG(-10); break; case -4: RETURN_LONG(-8); break; case -3: RETURN_LONG(-2); //不允许修改文章 break; case -5: RETURN_LONG(-3); //只读讨论区 break; case -2: RETURN_LONG(-5); break; case -6: RETURN_LONG(-6); //他人文章 break; default: RETURN_LONG(-10); break; } } if (title_len > 256) { title[256] = '\0'; } process_control_chars(title,NULL); if (!strcmp(title,f.title)) //无需修改 RETURN_LONG(0);#ifdef FILTER if (check_badword_str(title, strlen(title), getSession())) RETURN_LONG(-7);#endif setbfile(path, brd->filename, f.filename); if (add_edit_mark(path, 2, title, getSession()) != 1) RETURN_LONG(-10); /* update .DIR START */ strnzhcpy(f.title, title, ARTICLE_TITLE_LEN); setbdir(mode, dirpath, brd->filename); fd = open(dirpath, O_RDONLY, 0); if (fd!=-1) { for (i = ent; i > 0; i--) { if (0 == get_record_handle(fd, &xfh, sizeof(xfh), i)) { if (0 == strcmp(xfh.filename, f.filename)) { ent = i; break; } } } if (i!=0) { substitute_record(dirpath, &f, sizeof(f), ent); if (mode == DIR_MODE_ZHIDING) board_update_toptitle(bid, true); } close(fd); } if (0 == i) RETURN_LONG(-10); if (f.id == f.groupid) { if( setboardorigin(board, -1) ) { board_regenspecial(brd->filename,DIR_MODE_ORIGIN,NULL); } else { char olddirect[PATHLEN]; setbdir(DIR_MODE_ORIGIN, olddirect, brd->filename); if ((fd = open(olddirect, O_RDWR, 0644)) >= 0) { struct fileheader tmpfh; if (get_records_from_id(fd, f.id, &tmpfh, 1, &ent) == 0) { close(fd); } else { close(fd); substitute_record(olddirect, &f, sizeof(f), ent); } } } } setboardtitle(brd->filename, 1); /* update .DIR END */ RETURN_LONG(0);}PHP_FUNCTION(bbs_doforward){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?