コード例 #1
0
ファイル: post.c プロジェクト: fbbs/fbbs
static char *generate_content(const post_request_t *pr, const char *uname,
		const char *nick, const char *ip, bool anony, size_t length)
{
	UTF8_BUFFER(nick, NAMELEN);
	convert_g2u(nick, utf8_nick);

	char header[512];
	snprintf(header, sizeof(header),
			"发信人: %s (%s), 信区: %s\n标  题: %s\n发信站: %s (%s)\n\n",
			uname, utf8_nick, pr->board->name, pr->title, BBSNAME_UTF8,
			format_time(fb_time(), TIME_FORMAT_UTF8_ZH));
	int header_len = strlen(header);

	int content_len = length ? length : strlen(pr->content);
	if (pr->convert_type != CONVERT_NONE)
		content_len *= 2;

	char signature[MAXSIGLINES * SIGNATURE_LINE_LEN + 5];
	char utf8_signature[sizeof(signature) * 2 + 1];
	if (!anony && pr->sig > 0) {
		read_signature_legacy(uname, pr->sig, signature, sizeof(signature));
		convert_g2u(signature, utf8_signature);
	} else {
		strlcpy(utf8_signature, "\n--", sizeof(utf8_signature));
	}
	int signature_len = strlen(utf8_signature);

	char source[256] = { '\0' };
	if (ip) {
		char utf8_ip[80];
		convert_g2u(ip, utf8_ip);
		snprintf(source, sizeof(source), "\033[m\033[1;%2dm※ %s:·"BBSNAME_UTF8
				" "BBSHOST"·%s[FROM: %s]\033[m\n", 31 + rand() % 7,
				pr->crosspost ? "转载" : "来源", pr->web ? "HTTP " : "",
				utf8_ip);
	}
	int source_len = strlen(source);

	int total_len = header_len + content_len + signature_len + source_len + 2;
	char *content = malloc(total_len);

	memcpy(content, header, header_len);
	if (pr->convert_type != CONVERT_NONE)
		convert(pr->convert_type, pr->content, CONVERT_ALL,
				content + header_len, total_len - header_len, NULL, NULL);
	else
		strlcpy(content + header_len, pr->content, total_len - header_len);

	int len = strlen(content);
	if (len < total_len)
		memcpy(content + len, utf8_signature, total_len - len);
	len += signature_len;
	if (content[len - 1] != '\n' && len < total_len) {
		content[len++] = '\n';
	}
	if (len < total_len)
		memcpy(content + len, source, total_len - len);
	content[len + source_len] = '\0';
	return content;
}
コード例 #2
0
ファイル: tui.c プロジェクト: fbbs/fbbs
void tui_update_status_line(void)
{
	extern time_t login_start_time; //main.c

	char date[STRLEN];

	screen_move_clear(-1);

	if (!DEFINE(DEF_ENDLINE))
		return;

	fb_time_t now = fb_time();
	int cur_sec = now % 10;

	if (cur_sec < 5) {
		strlcpy(date, format_time(now, TIME_FORMAT_UTF8_ZH), sizeof(date));
	} else {
		if (resolve_boards() >= 0)
			convert_g2u(brdshm->date, date);
		else
			date[0] = '\0';
	}

	if (cur_sec >= 5 && is_birth(&currentuser)) {
		screen_printf("\033[0;1;33;44m[\033[36m                      "
				"啦啦~~生日快乐!记得要请客哟 :P"
				"                       \033[33m]\033[m");
	} else {
		int stay = (now - login_start_time) / 60;
		char stay_str[20];
		describe_stay(stay, stay_str, sizeof(stay_str));

		char notice[128];
		notice_string(notice, sizeof(notice));
		int notice_width = screen_display_width(notice, true);

		screen_printf("\033[1;44;33m[\033[36m%29s\033[33m]"
			"[\033[36m%5d\033[33m人\033[36m%3d\033[33m友]",
			date, session_count_online(),
			session_count_online_followed(!HAS_PERM(PERM_SEECLOAK)));
		// 剩下35列
		if (notice_width) {
			int space = 33 - notice_width;
			if (space > 0)
				tui_repeat_char(' ', space);
			screen_printf("[\033[%d;36m%s\033[m\033[1;33;44m]\033[m",
					_suppress_notice ? 1 : 5, notice);
		} else {
			int space = 27 - strlen(currentuser.userid);
			tui_repeat_char(' ', space);
			prints("[\033[36m%s\033[33m]%s\033[m", currentuser.userid,
					stay_str);
		}
	}
}
コード例 #3
0
ファイル: friend.c プロジェクト: fbbs/fbbs
static int tui_edit_followed_note(user_id_t followed, const char *orig)
{
	char note[FOLLOW_NOTE_CCHARS * 2 + 1], utf8_note[FOLLOW_NOTE_CCHARS * 4 + 1];
	//% getdata(-1, 0, "请输入备注: ", note, sizeof(note), DOECHO, YEA);
	getdata(-1, 0, "\xc7\xeb\xca\xe4\xc8\xeb\xb1\xb8\xd7\xa2: ", note, sizeof(note), DOECHO, YEA);
	convert_g2u(note, utf8_note);

	if (!*utf8_note || streq(orig, utf8_note))
		return DONOTHING;

	edit_followed_note(session_get_user_id(), followed, utf8_note);
	return FULLUPDATE;
}
コード例 #4
0
ファイル: friend.c プロジェクト: fbbs/fbbs
static int tui_follow(void)
{
	char buf[IDLEN + 1];
	//% "请输入要关注的人: "
	getdata(-1, 0, "\xc7\xeb\xca\xe4\xc8\xeb\xd2\xaa\xb9\xd8\xd7\xa2"
			"\xb5\xc4\xc8\xcb: ", buf, IDLEN, DOECHO, YEA);
	if (!*buf)
		return 0;
	GBK_UTF8_BUFFER(note, FOLLOW_NOTE_CCHARS);
	//% "请输入备注: "
	getdata(-1, 0, "\xc7\xeb\xca\xe4\xc8\xeb\xb1\xb8\xd7\xa2: ",
			gbk_note, sizeof(gbk_note), DOECHO, YEA);
	convert_g2u(gbk_note, utf8_note);
	return follow(session_get_user_id(), buf, utf8_note);
}
コード例 #5
0
ファイル: prop.c プロジェクト: caidongyun/fbbs
static int buy_title(int item, const char *title)
{
	xml_header(NULL);
	printf("<bbsbuyprop>");
	print_session();
	if (title && *title) {
		UTF8_BUFFER(title, TITLE_CCHARS);
		convert_g2u(title, utf8_title);
		if (string_validate_utf8(utf8_title, TITLE_CCHARS, false) > 0
				&& title_submit_request(item, session_uid(), utf8_title, 0)) {
			printf("<success/>");
		}
	} else {
		printf("<inputs item='%d'>"
				//% "<label for='title'>请输入自定义身份</label>"
				"<label for='title'>\xc7\xeb\xca\xe4\xc8\xeb\xd7\xd4\xb6\xa8\xd2\xe5\xc9\xed\xb7\xdd</label>"
				"<input name='title' type='text' width='%d'></input>"
				"</inputs>", item, TITLE_CCHARS);
	}
	printf("</bbsbuyprop>");
	return 0;
}
コード例 #6
0
ファイル: friend.c プロジェクト: fbbs/fbbs
int bbsfadd_main(void)
{
	if (!session_get_id())
		return BBS_ELGNREQ;

	const char *uname = web_get_param("id");
	const char *note = web_get_param("desc");

	if (*uname) {
		UTF8_BUFFER(note, FOLLOW_NOTE_CCHARS);
		convert_g2u(note, utf8_note);

		follow(session_get_user_id(), uname, utf8_note);

		printf("Location: fall\n\n");
		return 0;
	}
	xml_header(NULL);
	printf("<bbsfadd>");
	print_session();
	printf("%s</bbsfadd>", uname);
	return 0;
}