int fillbcache(void *fptr1,int idx,void* arg) { char sql[256]; FILE *fp; MYSQL_RES *res; MYSQL_ROW row; struct boardheader *fptr = (struct boardheader *)fptr1; if (fptr->filename[0]==0 || !normal_board(fptr->filename)) return 0; if (fptr->flag & BOARD_GROUP) return 0; sprintf(sql, "SELECT MIN(nowid),MAX(nowid),AVG(users) FROM bonline WHERE bdate=\"%d-%d-%d\" AND bname LIKE '%s' ;", t.tm_year+1900, t.tm_mon+1, t.tm_mday, fptr->filename); if (mysql_real_query(&s, sql, strlen(sql))) printf("%s\n",mysql_error(&s)); else { res = mysql_store_result(&s); if (res == NULL) { printf("%s\n",sql); return 0; } row = mysql_fetch_row(res); if (row && row[0] && row[0][0]) { x[n].yesid=atoi(row[0]); x[n].nowid=atoi(row[1]); x[n].online=atoi(row[2]); } else return 0; mysql_free_result(res); } strcpy(x[n].filename, fptr->filename); strcpy(x[n].title, fptr->title+13); n++; sprintf(sql,"%s/boards/%s.all",BONLINE_LOGDIR, fptr->filename); if ((fp=fopen(sql,"a"))!=NULL) { fprintf(fp,"%d-%d-%d\t%d\t%d\n", t.tm_year+1900, t.tm_mon+1, t.tm_mday, x[n-1].online, x[n-1].nowid-x[n-1].yesid); fclose(fp); } else printf("error open:%s\n", sql); return 0; }
/*********** 根据type得到十大列表,已经经过排序等一系列检查,可以直接输出 type!=4的时候还得到分区十大 *******/ int get_top(int type) { MYSQL s; MYSQL_RES *res; MYSQL_ROW row; char sqlbuf[500]; char cmptime[200]; int start=0; int i,secid; int threadid; char title[81]; char userid[IDLEN+1]; int m,n; #ifdef BLESS_BOARD const struct boardheader *bh; #endif topnum = 0; if(type < 0 || type > 4) return 0; mysql_init (&s); if (! my_connect_mysql(&s) ){ return 0;; } if(type==0 || type==4){ //sprintf(cmptime,"YEAR(time)=YEAR(CURDATE()) AND MONTH(time)=MONTH(CURDATE()) AND DAYOFMONTH(time)=DAYOFMONTH(CURDATE())"); sprintf(cmptime,"time>curdate()"); }else if(type==1){ sprintf(cmptime,"YEAR(date)=YEAR(CURDATE()) AND WEEK(date)=WEEK(CURDATE())"); }else if(type==2){ sprintf(cmptime,"YEAR(date)=YEAR(CURDATE()) AND MONTH(date)=MONTH(CURDATE())"); }else if(type==3){ sprintf(cmptime,"YEAR(date)=YEAR(CURDATE())"); } bzero(top, TOPCOUNT * sizeof(struct postrec)); bzero(sectop, SECNUM * SECTOPCOUNT * sizeof(struct postrec)); for(i=0;i<SECNUM;i++) sectopnum[i]=0; sectopnumtotal=0; while(1){ if(type==4){ if(topnum>=mytop[type]) break; }else if(type==0){ if(topnum>=mytop[type] && sectopnumtotal>=SECNUM*SECTOPCOUNT) break; }else{ if(topnum >= mytop[type]) break; } if(start > MAXCMP) break; if(type==0 || type==4) sprintf(sqlbuf,"SELECT bname,threadid,MAX(UNIX_TIMESTAMP(time)) AS maxtime,count(DISTINCT userid) AS count FROM postlog WHERE %s GROUP BY bname,threadid ORDER BY count desc LIMIT %d,%d;", cmptime, start, INTERVAL); else sprintf(sqlbuf,"SELECT bname,threadid,UNIX_TIMESTAMP(time),count,title,userid FROM toplog WHERE %s ORDER BY count desc LIMIT %d,%d",cmptime,start, INTERVAL); if( mysql_real_query( &s, sqlbuf, strlen(sqlbuf) )){ printf("%s\n", mysql_error(&s)); mysql_close(&s); return topnum; } res = mysql_store_result(&s); while(1){ row = mysql_fetch_row(res); if(row==NULL) break; /***检查是否该计算十大***/ bh = getbcache(row[0]); if(bh==NULL || bh->flag & BOARD_POSTSTAT){ continue; } if(!normal_board(bh->filename)) continue; #ifdef BLESS_BOARD if(type==0){ if ( ! strcasecmp(row[0], BLESS_BOARD) ){ continue; } }else if(type==4){ if ( strcasecmp(row[0], BLESS_BOARD) ){ continue; } } #endif secid= get_seccode_index(bh->title[0]); if(topnum >= mytop[type] && ( secid==-1 || sectopnum[secid] >= SECTOPCOUNT)) continue; threadid = atoi(row[1]); if(type==0 || type==4){ if(get_file_title(row[0], threadid, title, userid) == NULL){ continue; } }else{ strncpy(title, row[4], 80); title[80]=0; strncpy(userid, row[5], IDLEN); userid[IDLEN]=0; } /**一个版面最多3个十大**/ if(type==0){ m = 0; for (n = 0; n < topnum; n++) { if (!strcmp(row[0], top[n].board)) m++; } if(m>0) continue; /***分区十大里一个版面也最多3个***/ if(secid!=-1){ m = 0; for (n = 0; n < sectopnum[secid]; n++) { if (!strcmp(row[0], sectop[secid][n].board)) m++; } if(m>0) continue; } } /***先记录正常十大的值***/ if(topnum < mytop[type]){ strncpy(top[topnum].board, row[0], BOARDNAMELEN); top[topnum].board[BOARDNAMELEN-1]='\0'; top[topnum].groupid = threadid; strncpy(top[topnum].title, title, 80); top[topnum].title[80]='\0'; strncpy(top[topnum].userid, userid, IDLEN); top[topnum].userid[IDLEN]='\0'; top[topnum].date = atol(row[2]); top[topnum].number = atoi(row[3]); topnum++; } /***计算分区十大***/ if(type==0){ i=secid; if(i!=-1){ if( sectopnum[i] < SECTOPCOUNT){ strncpy(sectop[i][sectopnum[i]].board, row[0], BOARDNAMELEN); sectop[i][sectopnum[i]].board[BOARDNAMELEN-1]='\0'; sectop[i][sectopnum[i]].groupid = threadid; strncpy(sectop[i][sectopnum[i]].title, title, 80); sectop[i][sectopnum[i]].title[80]='\0'; strncpy(sectop[i][sectopnum[i]].userid, userid, IDLEN); sectop[i][sectopnum[i]].userid[IDLEN]='\0'; sectop[i][sectopnum[i]].date = atol(row[2]); sectop[i][sectopnum[i]].number = atoi(row[3]); sectopnum[i]++; sectopnumtotal++; } } }//type==0 if(type==4){ if(topnum>=mytop[type]) break; }else if(type==0){ if(topnum >= mytop[type] && sectopnumtotal >= SECNUM*SECTOPCOUNT) break; }else{ if(topnum >= mytop[type]) break; } } mysql_free_result(res); start += INTERVAL; } mysql_close(&s); return topnum; }