コード例 #1
0
ファイル: newhelp.c プロジェクト: xingskycn/kbs
static int del_help(unsigned int id)
{
    MYSQL s;
    char sql[100];

    clear();

    getdata(2,0,"确定删除? (y/N) [N]:",sql,2,DOECHO,NULL,true);
    if (sql[0] != 'y' && sql[0] != 'Y')
        return -1;

    mysql_init(&s);
    if (! my_connect_mysql(&s)) {
        prints("\n%s\n",mysql_error(&s));
        pressanykey();
        return -1;
    }

    sprintf(sql,"DELETE FROM help WHERE id=%d;",id);

    if (mysql_real_query(&s, sql, strlen(sql))) {
        prints("\n%s\n",mysql_error(&s));
        pressanykey();
        mysql_close(&s);
        return -1;
    }

    mysql_close(&s);

    return 0;
}
コード例 #2
0
ファイル: post_brdlog.c プロジェクト: wyat/kbs
int main(int argc,char **argv)
{
    char path[256];
    char title[256];
    time_t now;
    int before;

    if (argc > 1)
        before = atoi(argv[1]);
    else
        before = 0;

    chdir(BBSHOME);
    bzero(&x[0], sizeof(x));

    if (init_all()) {
        printf("init data fail\n");
        return -1;
    }

    mysql_init(&s);

    if (! my_connect_mysql(&s)) {
        printf("Mysql connect error: %s\n",mysql_error(&s));
        return 0;
    }

    now=time(0) - 86400 - 86400*before;
    localtime_r(&now, &t);

    fillboard();

    mysql_close(&s);

    qsort(x, n, sizeof(x[0]), online_cmp);
    /* generate boards usage result in xml format */
    gen_board_rank_xml();

    sprintf(path,"tmp/brdlog.%d.out",getpid());
    putout(path);

    sprintf(title, "%d年%2d月%2d日版面统计数据(在线排序)", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday);
    post_file(NULL, "", path, "SysTrace", title, 0, 1, getSession());
    unlink(path);

    qsort(x, n, sizeof(x[0]), id_cmp);

    sprintf(path,"tmp/brdlog.%d.out",getpid());
    putout(path);

    sprintf(title, "%d年%2d月%2d日版面统计数据(文章数排序)", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday);
    post_file(NULL, "", path, "SysTrace", title, 0, 1, getSession());
    unlink(path);

    return 0;
}
コード例 #3
0
ファイル: bbslogd.c プロジェクト: xingskycn/kbs
static void opennewpostlog()
{
	mysql_init (&s);

	if (! my_connect_mysql(&s) ){
		bbslog("3system","mysql connect error:%s",mysql_error(&s));
		return;
	}
	postlog_start = 1;
	mysqlclosetime=0;
	return;
}
コード例 #4
0
ファイル: newhelp.c プロジェクト: xingskycn/kbs
int count_help(int mode)
{

    MYSQL s;
    MYSQL_RES *res;
    MYSQL_ROW row;
    int i;
    char sql[600];
    char tmp[200];

    mysql_init(&s);

    if (!my_connect_mysql(&s)) {
        clear();
        prints("%s\n", mysql_error(&s));
        pressanykey();
        return -1;
    }

    sprintf(sql,"SELECT COUNT(*) FROM help WHERE modeid=%d",mode);

    if (help_search[0]) {
        char newsearch[50];
        mysql_escape_string(newsearch, help_search, strlen(help_search));
        snprintf(tmp, 199, " And ( content LIKE \"%%%s%%\" OR func LIKE \"%%%s%%\") ", newsearch, newsearch);
        strcat(sql, tmp);
    }

    if (mysql_real_query(&s, sql, strlen(sql))) {
        clear();
        prints("%s\n", mysql_error(&s));
        pressanykey();
        mysql_close(&s);
        return -1;
    }
    res = mysql_store_result(&s);
    row = mysql_fetch_row(res);

    i=0;
    if (row != NULL) {
        i=atoi(row[0]);
    }
    mysql_free_result(res);
    mysql_close(&s);

    return i;
}
コード例 #5
0
ファイル: bonlinelog.c プロジェクト: marvelliu/lilacsrc
int main(void){
	time_t now;

    chdir(BBSHOME);
	now = time(0);
	localtime_r( &now, &t);

	mysql_init(&s);
    if (!my_connect_mysql(&s) ){
        printf("Mysql connect error: %s\n",mysql_error(&s));
        return 0;
    }   
	
    resolve_boards();
    fillboard();

    mysql_close(&s);
    return 0;
}
コード例 #6
0
ファイル: newhelp.c プロジェクト: xingskycn/kbs
static int add_new_help(int mode, struct helps *pn, char *body, int num)
{
    MYSQL s;
    char newindex[21];
    char newdesc[81];
    char newbody[1001];
    char sql[1200];

    newindex[0]=0;
    newdesc[0]=0;
    newbody[0]=0;

    mysql_init(&s);
    if (! my_connect_mysql(&s)) {
        clear();
        prints("%s\n",mysql_error(&s));
        pressanykey();
        return -1;
    }

    mysql_escape_string(newindex, pn->index, strlen(pn->index));
    mysql_escape_string(newdesc, pn->desc, strlen(pn->desc));
    mysql_escape_string(newbody, body, strlen(body));

    if (num == -1) {
        sprintf(sql,"INSERT INTO help VALUES (NULL, %d, '%s', '%s', '%s');",mode, newindex, newdesc, newbody);
    } else {
        sprintf(sql,"UPDATE help SET prekey='%s', func='%s', content='%s' WHERE id=%d;", newindex, newdesc, newbody, s_help[num].id);
    }

    if (mysql_real_query(&s, sql, strlen(sql))) {
        clear();
        prints("%s\n",mysql_error(&s));
        pressanykey();
        mysql_close(&s);
        return -1;
    }

    mysql_close(&s);

    return 0;
}
コード例 #7
0
ファイル: newpoststat.c プロジェクト: marvelliu/lilacsrc
/*
create table `toplog` (
 `id` int unsigned NOT NULL auto_increment,
 `userid` char(15) NOT NULL default '',
 `bname` char(31) NOT NULL default '',
 `title` char(81) NOT NULL default '',
 `time` timestamp NOT NULL,
 `date` date NOT NULL,
 `topth` int NOT NULL default '1',
 `count` int NOT NULL default '0',
 `threadid` int unsigned NOT NULL default '0',
 PRIMARY KEY (`id`),
 KEY userid (`userid`),
 KEY bname(`bname`, `threadid`),
 KEY date(`date`),
 UNIQUE top (`date`,`topth`)
) TYPE=MyISAM COMMENT='toplog';
*/
int log_top()
{
	MYSQL s;
	char sqlbuf[500];
	char newtitle[161];
	int i;
	char newts[20];

	mysql_init (&s);

	if (! my_connect_mysql(&s) ){
		return 0;;
	}

	for(i=0;i<topnum;i++){
		
		mysql_escape_string(newtitle, top[i].title, strlen(top[i].title));

		sprintf(sqlbuf,"UPDATE toplog SET userid='%s',bname='%s',title='%s',count='%d',time='%s',threadid='%d' WHERE date=CURDATE() AND topth='%d';", top[i].userid, top[i].board, newtitle, top[i].number, tt2timestamp(top[i].date,newts), top[i].groupid, i+1);

		if( mysql_real_query( &s, sqlbuf, strlen(sqlbuf) )){
			printf("%s\n", mysql_error(&s));
			continue;
		}
		if( (int)mysql_affected_rows(&s) <= 0 ){
			sprintf(sqlbuf, "INSERT INTO toplog VALUES (NULL,'%s','%s','%s','%s',CURDATE(),'%d','%d','%d');",top[i].userid, top[i].board, newtitle, tt2timestamp(top[i].date,newts), i+1, top[i].number, top[i].groupid);
			if( mysql_real_query( &s, sqlbuf, strlen(sqlbuf) )){
				printf("%s\n", mysql_error(&s));
				continue;
			}
		}
	}

	mysql_close(&s);

	return 1;
}
コード例 #8
0
ファイル: msg_manager.c プロジェクト: xingskycn/kbs
static int set_smsg_key(struct _select_def *conf, int key)
{
    switch (key) {
        case 'd': {
            char sql[100];
            MYSQL s;
            char ans[4];

            move(2,0);
            clrtoeol();
            ans[0]=0;
            getdata(2, 0, "删除这条消息(Y/N) [N]: ", ans, 3, DOECHO, NULL, true);
            if (ans[0] != 'y' && ans[0]!='Y')
                return SHOW_REFRESH;

            mysql_init(&s);
            if (! my_connect_mysql(&s)) {
                clear();
                prints("%s\n",mysql_error(&s));
                pressanykey();
                mysql_close(&s);
                return SHOW_REFRESH;
            }

            sprintf(sql,"DELETE FROM smsmsg WHERE id=%d;",s_m[conf->pos-conf->page_pos].id);


            if (mysql_real_query(&s, sql, strlen(sql))) {
                clear();
                prints("%s\n",mysql_error(&s));
                pressanykey();
                mysql_close(&s);
                return SHOW_REFRESH;
            }

            mysql_close(&s);

            return SHOW_DIRCHANGE;
        }
        case 's': {
            char ans[40];

            clear();
            move(0,0);
            ans[0]=0;
            prints("                                 超级短信选择\n");
            prints("\033[1;31m------------------------------------------------------------------------\033[m\n");
            getdata(2, 0, "选择全部短信请按\033[1;32m1\033[m,输入条件选择请按\033[1;32m2\033[m,取消直接回车(1/2/0) [0]: ", ans, 3, DOECHO, NULL, true);
            if (ans[0] == '1') {
                conf->page_pos = 0;
                sm_dest[0]=0;
                sm_type = -1;
                sm_msgtxt[0]=0;
                return SHOW_DIRCHANGE;
            } else if (ans[0] == '2') {
                move(3,0);
                getdata(3,0,"请输入要选择的短信来源(回车选择所有):",ans,15, DOECHO,NULL,true);
                strncpy(sm_dest, ans, 13);
                sm_dest[12]=0;

                move(4,0);
                getdata(4,0,"请输入要选择的短信类别(1表示发,2表示收,回车所有) [0]:",ans,3, DOECHO,NULL,true);
                if (ans[0] == '1')
                    sm_type = 1;
                else if (ans[0] == '2')
                    sm_type = 0;
                else sm_type = -1;

                move(5,0);
                getdata(5,0,"请输入开始显示的短信序号 [0]:",ans,5, DOECHO,NULL,true);
                conf->page_pos = atoi(ans);
                if (conf->page_pos <= 0) conf->page_pos=1;
                conf->pos=conf->page_pos;

                move(6,0);
                getdata(6,0,"请输入要短信内容包含文字(回车选择所有):",ans,21, DOECHO,NULL,true);
                strncpy(sm_msgtxt, ans, 21);
                sm_msgtxt[20]=0;

                return SHOW_DIRCHANGE;
            } else {
                return SHOW_REFRESH;
            }
            break;
        }
        case 'a': {
            conf->page_pos = 0;
            sm_dest[0]=0;
            sm_type = -1;
            sm_msgtxt[0]=0;
            return SHOW_DIRCHANGE;
        }
        case 'S': {
            if (! isdigit(s_m[conf->pos-conf->page_pos].dest[0]))
                return SHOW_CONTINUE;
            clear();
            do_send_sms_func(s_m[conf->pos-conf->page_pos].dest, NULL);
            pressanykey();
            return SHOW_REFRESH;
        }
        case 'r': {
            sm_desc = ! sm_desc;
            return SHOW_DIRCHANGE;
        }
        case 'z': {
            char ans[42];

            clear();
            prints("修改短消息前缀/后缀,这些会在发送的短消息内容前/后显示,占短消息字节");

            if (getSession()->currentmemo->ud.smsprefix[0])
                strcpy(ans, getSession()->currentmemo->ud.smsprefix);
            else
                ans[0]=0;
            move(2,0);
            prints("请输入新的前缀:");
            multi_getdata(3, 0, 79, NULL, ans, 41, 6, false, 0);
            if (ans[0]) {
                strncpy(getSession()->currentmemo->ud.smsprefix, ans, 40);
                getSession()->currentmemo->ud.smsprefix[40]=0;
            } else
                getSession()->currentmemo->ud.smsprefix[0]=0;

            if (getSession()->currentmemo->ud.smsend[0])
                strcpy(ans, getSession()->currentmemo->ud.smsend);
            else
                ans[0]=0;
            move(10,0);
            prints("请输入新的后缀:");
            multi_getdata(11, 0, 79, NULL, ans, 41, 6, false, 0);
            if (ans[0]) {
                strncpy(getSession()->currentmemo->ud.smsend, ans, 40);
                getSession()->currentmemo->ud.smsend[40]=0;
            } else
                getSession()->currentmemo->ud.smsend[0]=0;

            write_userdata(getCurrentUser()->userid, &(getSession()->currentmemo->ud));

            move(18,0);
            prints("修改成功");
            pressreturn();

            return SHOW_REFRESH;
        }
        case 'h': {
            clear();
            prints("           短信管理器帮助\n\n");
            prints("   d   删除短信\n");
            prints("   s   超级选择\n");
            prints("   a   显示所有短信\n");
            prints("   S   回复短信\n");
            prints("   r   倒序排列\n");
            prints("   z   更改短信前/后缀\n");
            pressreturn();

            return SHOW_REFRESH;
        }
        default:
            break;
    }
    return SHOW_CONTINUE;
}
コード例 #9
0
ファイル: addr_manage.c プロジェクト: marvelliu/lilacsrc
static int set_al_key(struct _select_def *conf, int key)
{
	switch(key){
	case 'd':
	{
		char sql[100];
		MYSQL s;
		char ans[4];

        move(2,0);
		clrtoeol();
		ans[0]=0;
        getdata(2, 0, "删除这条记录(Y/N) [N]: ", ans, 3, DOECHO, NULL, true);
		if(ans[0] != 'y' && ans[0]!='Y')
			return SHOW_REFRESH;

		mysql_init(&s);
		if (! my_connect_mysql(&s) ){
			clear();
			prints("%s\n",mysql_error(&s));
			pressanykey();
			mysql_close(&s);
			return SHOW_REFRESH;
		}

		sprintf(sql,"DELETE FROM addr WHERE id=%d;",a_l[conf->pos-conf->page_pos].id);

		if( mysql_real_query( &s, sql, strlen(sql) ) ){
			clear();
			prints("%s\n",mysql_error(&s));
			pressanykey();
			mysql_close(&s);
			return SHOW_REFRESH;
		}

		mysql_close(&s);

		return SHOW_DIRCHANGE;
	}
	case 's':
	{
		char ans[40];

		clear();
		move(0,0);
		ans[0]=0;
		prints("                                 超级通讯录选择\n");
		prints("\033[1;31m------------------------------------------------------------------------\033[m\n");
        getdata(2, 0, "选择全部通讯录请按\033[1;32m1\033[m,输入条件选择请按\033[1;32m2\033[m,取消直接回车(1/2/0) [0]: ", ans, 3, DOECHO, NULL, true);
		if( ans[0] == '1' ){
			conf->pos = 0;
			al_dest[0]=0;
			al_group[0]=0;
			//sm_type = -1;
			al_msgtxt[0]=0;
			return SHOW_DIRCHANGE;
		}else if(ans[0] == '2'){
			move(3,0);
			getdata(3,0,"请输入要选择的通讯录姓名(回车选择所有):",ans,15, DOECHO,NULL,true);
			strncpy(al_dest, ans, 15);
			al_dest[14]=0;

			move(4,0);
			getdata(4,0,"请输入要选择的通讯录组名(回车选择所有):",ans,10, DOECHO,NULL,true);
			strncpy(al_group, ans, 10);
			al_group[9]=0;

			move(5,0);
			getdata(5,0,"请输入开始显示的通讯录序号 [0]:",ans,5, DOECHO,NULL,true);
			conf->page_pos = atoi(ans);
			if(conf->page_pos<=0)
				conf->page_pos=1;
			conf->pos=conf->page_pos;

			move(6,0);
			getdata(6,0,"请输入要通讯录备注内容包含文字(回车选择所有):",ans,21, DOECHO,NULL,true);
			strncpy(al_msgtxt, ans, 21);
			al_msgtxt[20]=0;

			return SHOW_DIRCHANGE;
		}else{
			return SHOW_REFRESH;
		}
		break;
	}
	case 'f':
	{
		conf->pos = 0;
		al_dest[0]=0;
		al_group[0]=0;
		//sm_type = -1;
		al_msgtxt[0]=0;
		return SHOW_DIRCHANGE;
	}
	case 'a':
	{
		if( conf->item_count > MAXFRIENDS ){
			clear();
			prints("您的通讯录已经达到最大容量");
			pressreturn();
			return SHOW_REFRESH;
		}
		if(add_addresslist(NULL)){
			return SHOW_DIRCHANGE;
		}
		return SHOW_REFRESH;
	}
	case 'e':
	{
		if(add_addresslist(a_l+conf->pos-conf->page_pos)){
			return SHOW_DIRCHANGE;
		}
		return SHOW_REFRESH;
	}
#ifdef SMS_SUPPORT
	case 'S':
	{
		if( (a_l+conf->pos - conf->page_pos)->mobile[0] && isdigit((a_l+conf->pos - conf->page_pos)->mobile[0]) ){
			do_send_sms_func((a_l+conf->pos - conf->page_pos)->mobile, NULL);
			return SHOW_REFRESH;
		}
		break;
	}
#endif
	case KEY_TAB:
	{
		al_order ++;
		if(al_order > AL_ORDER_COUNT)
			al_order = 0;
		return SHOW_DIRCHANGE;
	}
	case 'i':
	{
		char ans[4];

		if( conf->item_count > MAXFRIENDS ){
			clear();
			prints("您的通讯录已经达到最大容量");
			pressreturn();
			return SHOW_REFRESH;
		}

		clear();
        getdata(3, 0, "确实要导入好友名单? (Y/N) [N]: ", ans, 3, DOECHO, NULL, true);
		if(ans[0] != 'y' && ans[0] != 'Y'){
			return SHOW_REFRESH;
		}else{
			char fpath[STRLEN];
			struct friends fh;
			struct addresslist al;
			FILE *fp;
			int suc=0;

			sethomefile(fpath, getCurrentUser()->userid, "friends");

			if((fp=fopen(fpath, "r"))==NULL)
				return SHOW_REFRESH;
			while(fread(&fh, sizeof(fh), 1, fp)){
				bzero(&al,sizeof(al));
				if( fh.exp[0] )
					strncpy(al.name, fh.exp, 15);
				else
					strncpy(al.name, fh.id, 15);
				al.name[14]=0;
				strncpy(al.bbsid, fh.id, 15);
				al.bbsid[14]=0;
				strcpy(al.group,"bbs");

				move(10,0);
				clrtoeol();
				prints("正在导入用户 %s......",fh.id);
				if(add_sql_al( getCurrentUser()->userid, &al, fh.exp )){
					suc++;
					prints("成功");
				}
				else
					prints("失败");
			}
			fclose(fp);

			move(10,0);
			clrtoeol();
			prints("成功导入 %d 个好友", suc);
			pressanykey();

			return SHOW_DIRCHANGE;
		}
	}
	default:
		break;
	}
	return SHOW_CONTINUE;
}
コード例 #10
0
ファイル: newhelp.c プロジェクト: xingskycn/kbs
int get_help(struct helps * h, int mode, int start, int num)
{

    MYSQL s;
    MYSQL_RES *res;
    MYSQL_ROW row;
    int i;
    char sql[600];
    char tmp[200];

    mysql_init(&s);

    if (!my_connect_mysql(&s)) {
        clear();
        prints("%s\n", mysql_error(&s));
        pressanykey();
        return -1;
    }

    sprintf(sql,"SELECT * FROM help WHERE modeid=%d",mode);

    if (help_search[0]) {
        char newsearch[50];
        mysql_escape_string(newsearch, help_search, strlen(help_search));
        snprintf(tmp, 199, " And ( content LIKE \"%%%s%%\" OR func LIKE \"%%%s%%\") ", newsearch, newsearch);
        strcat(sql, tmp);
    }

    snprintf(tmp, 99, " ORDER BY prekey LIMIT %d,%d", start, num);
    strcat(sql, tmp);

    if (mysql_real_query(&s, sql, strlen(sql))) {
        clear();
        prints("%s\n", mysql_error(&s));
        pressanykey();
        mysql_close(&s);
        return -1;
    }
    res = mysql_store_result(&s);
    row = mysql_fetch_row(res);

    i=0;
    while (row != NULL) {
        i++;
        if (i>num)
            break;
        h[i-1].id = atoi(row[0]);
        h[i-1].modeid = mode;
        strncpy(h[i-1].index, row[2], 10);
        h[i-1].index[10]=0;
        strncpy(h[i-1].desc, row[3], 40);
        h[i-1].desc[40]=0;
        if (row[4] && strlen(row[4]) > 0) {
            h[i-1].content=(char *)malloc(strlen(row[4])+1);
            if (h[i-1].content)
                strcpy(h[i-1].content, row[4]);
        }
        row=mysql_fetch_row(res);
    }
    mysql_free_result(res);
    mysql_close(&s);

    return i;
}
コード例 #11
0
ファイル: newpoststat.c プロジェクト: marvelliu/lilacsrc
/***********
  根据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;

}
コード例 #12
0
ファイル: newpoststat.c プロジェクト: loverabbit/kbs-redis
/*
create table `toplog` (
 `id` int unsigned NOT NULL auto_increment,
 `userid` char(15) NOT NULL default '',
 `bname` char(31) NOT NULL default '',
 `title` char(81) NOT NULL default '',
 `time` timestamp NOT NULL,
 `date` date NOT NULL,
 `topth` int NOT NULL default '1',
 `count` int NOT NULL default '0',
 `threadid` int unsigned NOT NULL default '0',
 PRIMARY KEY (`id`),
 KEY userid (`userid`),
 KEY bname(`bname`, `threadid`),
 KEY date(`date`),
 UNIQUE top (`date`,`topth`)
) TYPE=MyISAM COMMENT='toplog';

create table `toplog_all` (
 `id` int unsigned NOT NULL auto_increment,
 `userid` char(15) NOT NULL default '',
 `bname` char(31) NOT NULL default '',
 `title` char(81) NOT NULL default '',
 `time` timestamp NOT NULL,
 `date` date NOT NULL,
 `topth` int NOT NULL default '1',
 `count` int NOT NULL default '0',
 `threadid` int unsigned NOT NULL default '0',
 PRIMARY KEY (`id`),
 KEY userid (`userid`),
 KEY bname(`bname`, `threadid`),
 KEY date(`date`),
) TYPE=MyISAM COMMENT='toplog_all';
*/
int log_top()
{
    MYSQL s;
    char sqlbuf[500];
    char newtitle[161];
    int i;
    char newts[20];
    time_t now;
    struct tm ptime;

    mysql_init(&s);

    if (! my_connect_mysql(&s)) {
        return 0;;
    }

    for (i=0;i<topnum;i++) {

        mysql_escape_string(newtitle, top[i].title, strlen(top[i].title));

#ifdef NEWSMTH
        MYSQL_RES *res;
        MYSQL_ROW row;
        sprintf(sqlbuf, "SELECT id FROM toplog_all WHERE date=CURDATE() AND bname='%s' AND threadid=%d; ", top[i].board, top[i].groupid);
        if (mysql_real_query(&s, sqlbuf, strlen(sqlbuf))) {
            printf("%s\n", mysql_error(&s));
        } else {
            res = mysql_store_result(&s);
            row = mysql_fetch_row(res);
            if (row==NULL) {
                char title[STRLEN],file[STRLEN];
                // auto post top10 to ShiDa
                sprintf(title, "[%s] %s", top[i].board,top[i].title);
                sprintf(file, "boards/%s/%s", top[i].board,top[i].filename);
                post_file(NULL, "", file , "ShiDa", title, 0, 1, getSession());
                // insert into toplog_all
                sprintf(sqlbuf, "INSERT INTO toplog_all VALUES (NULL,'%s','%s','%s','%s',CURDATE(),'%d','%d','%d');",top[i].userid, top[i].board, newtitle, tt2timestamp(top[i].date,newts), i+1, top[i].number, top[i].groupid);
                if (mysql_real_query(&s, sqlbuf, strlen(sqlbuf))) {
                    printf("%s\n", mysql_error(&s));
                }
            } else {
                // update toplog_all
                sprintf(sqlbuf,"UPDATE toplog_all SET userid='%s',bname='%s',title='%s',count='%d',time='%s',threadid='%d' WHERE date=CURDATE() AND bname='%s' AND threadid=%d;;", top[i].userid, top[i].board, newtitle, top[i].number, tt2timestamp(top[i].date,newts), top[i].groupid, top[i].board, top[i].groupid);
                if (mysql_real_query(&s, sqlbuf, strlen(sqlbuf))) {
                    printf("%s\n", mysql_error(&s));
                }
            }
        }
        time(&now);
        ptime = *localtime(&now);
        if (ptime.tm_hour == 23) {
            total_post_top10(top[i].groupid,top[i].board,top[i].title);
        }
#endif

        sprintf(sqlbuf,"UPDATE toplog SET userid='%s',bname='%s',title='%s',count='%d',time='%s',threadid='%d' WHERE date=CURDATE() AND topth='%d';", top[i].userid, top[i].board, newtitle, top[i].number, tt2timestamp(top[i].date,newts), top[i].groupid, i+1);

        if (mysql_real_query(&s, sqlbuf, strlen(sqlbuf))) {
            printf("%s\n", mysql_error(&s));
            continue;
        }
        if ((int)mysql_affected_rows(&s) <= 0) {
            sprintf(sqlbuf, "INSERT INTO toplog VALUES (NULL,'%s','%s','%s','%s',CURDATE(),'%d','%d','%d');",top[i].userid, top[i].board, newtitle, tt2timestamp(top[i].date,newts), i+1, top[i].number, top[i].groupid);
            if (mysql_real_query(&s, sqlbuf, strlen(sqlbuf))) {
                printf("%s\n", mysql_error(&s));
                continue;
            }
        }
    }

    mysql_close(&s);

    return 1;
}