作者itoc.bbs@cpu.tfcis.org (核心動力) 看板: itoc
標題Re: [問題]功能-文章編輯時無法加分
時間動力核心 (2007/04/05 Thu 23:18:34)
post_edit() 裡的 vedit() 前/後,加上/移除 POST_EDITING 旗標
post_score() 在評分前,若發現有 POST_EDITING 旗標,則禁止評分
若作者或站長編輯到一半斷線,那麼該文章將一直無法評分 :p
此時,只要作者或站長再去 Edit 一次,正常離開編輯即可 (不管有無儲存都可以)
如果作者開二個視窗同時 Edit 同一篇文章
那麼其中一個視窗離開 Edit 後,就可以開始評分了
反正目前也沒管「作者開二個視窗同時 Edit 同一篇文章時,晚儲存會覆蓋先儲存」
所以也不打算寫此情況下的禁止評分檢查
: hdr.h
- #define POST_3 0x00000004
+ #define POST_EDITING 0x00000004
: post.c:post_edit()
if (HAS_PERM(PERM_ALLBOARD)) /* 站長修改 */
{
...
...
+ do_editing(xo, 1);
vedit(fpath, 0);
+ do_editing(xo, 0);
}
else if (cuser.userlevel && !strcmp(hdr->owner, cuser.userid))
{
+ do_editing(xo, 1);
if (!vedit(fpath, 0))
{
...
...
}
+ do_editing(xo, 0);
}
: post.c:do_editing() 新增此函式在 post_edit() 前面
static void
do_editing(xo, flag)
XO *xo;
int flag;
{
HDR *hdr;
int pos, xmode;
pos = xo->pos;
hdr = (HDR *) xo_pool + (pos - xo->top);
xmode = hdr->xmode;
if (flag)
hdr->xmode = xmode | POST_EDITING;
else
hdr->xmode = xmode & ~POST_EDITING;
currchrono = hdr->chrono;
rec_put(xo->dir, hdr, sizeof(HDR), xo->key == XZ_XPOST ?
hdr->xid : pos, cmpchrono);
}
: post.c:post_score()
pos = xo->pos;
cur = pos - xo->top;
hdr = (HDR *) xo_pool + cur;
+ if (is_editing(xo->dir, hdr))
+ {
+ vmsg("目前作者或站長正編輯此文章中,暫時禁止評分");
+ return XO_FOOT;
+ }
: post.c:is_editing() 新增此函式在 post_score() 前面
static int
is_editing(folder, hdr)
char *folder;
HDR *hdr;
{
HDR hdd;
int fd;
int rc = 0;
time_t chrono;
chrono = hdr->chrono;
/* 由於使用者手上的 xo_pool[] 可能是舊的 (即使用者已經在板內,
這時作者才編輯該文章),所以直接去找硬碟最正確的 */
if ((fd = open(folder, O_RDONLY)) >= 0)
{
while (read(fd, &hdd, sizeof(HDR)) == sizeof(hdd))
{
if (chrono == hdd.chrono)
{
rc = (hdd.xmode & POST_EDITING);
break;
}
}
close(fd);
}
return rc;
}
--
=[﹎:�摃�◣��:﹎ Origin ]|[ ���O���� cpu.tfcis.org ]|[�搟說�﹎:]=
=[﹊:�摃�╱��:﹊ Author ]|[218-168-186-195.dynamic.hi]|[���插�﹊:]=