Ejemplo n.º 1
0
void gen_board_rank_xml()
{
    int i;
    FILE *fp;
    char xmlfile[STRLEN];
    char xml_buf[256];
    char url_buf[256];
    const struct boardheader *bp;
    int sec_id;

    snprintf(xmlfile, sizeof(xmlfile), BBSHOME "/xml/board.xml");
    if ((fp = fopen(xmlfile, "w")) == NULL)
        return;
    fprintf(fp, "<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
    fprintf(fp, "<BoardList Desc=\"%s\">\n",encode_url(url_buf,"讨论区使用状况统计",sizeof(url_buf)));
    for (i = 0; i < n; i++) {
        bp = getbcache(x[i].filename);
        if (bp == NULL || (bp->flag & BOARD_GROUP))
            continue;
        if ((sec_id = get_seccode_index(bp->title[0])) < 0)
            continue;
        fprintf(fp, "<Board>\n");
        fprintf(fp, "<EnglishName>%s</EnglishName>\n",
                encode_url(url_buf,encode_xml(xml_buf, x[i].filename, sizeof(xml_buf)),sizeof(url_buf)));
        fprintf(fp, "<ChineseName>%s</ChineseName>\n",
                encode_url(url_buf,encode_xml(xml_buf, x[i].title, sizeof(xml_buf)),sizeof(url_buf)));
        fprintf(fp, "<Online>%d</Online>\n", x[i].online);
        fprintf(fp, "<Articles>%d</Articles>\n", x[i].nowid-x[i].yesid);
        fprintf(fp, "<SecId>%d</SecId>\n", sec_id);
        fprintf(fp, "</Board>\n");
    }
    fprintf(fp, "</BoardList>\n");
    fclose(fp);
}
Ejemplo n.º 2
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;

}