<commit_before><?php
	function sprintf3($str, $vars, $delim = '%') {
		$replaces = array();
		foreach($vars as $k => $v) {
			$replaces[$delim . $k . $delim] = $v;
		}
		return str_replace(array_keys($replaces),
		                   array_values($replaces), $str);
	}

	function sql_open() {
		global $sql;
		$sql = @mysql_connect(MY_SERVER, MY_USER, MY_PASSWORD) or error('Database error.');
		@mysql_select_db(MY_DATABASE, $sql) or error('Database error.');
	}
	function sql_close() {
		global $sql;
		@mysql_close($sql);
	}

	function mysql_safe_array(&$array) {
		foreach($array as &$item) {
			$item = mysql_real_escape_string($item);
		}
	}
	
	function setupBoard($array) {
		global $board;
		
		$board = Array(
		'id' => $array['id'],
		'uri' => $array['uri'],
		'name' => $array['title'],
		'title' => $array['subtitle']);
		
		$board['dir'] = sprintf(BOARD_PATH, $board['uri']);
		$board['url'] = sprintf(BOARD_ABBREVIATION, $board['uri']);
		
		if(!file_exists($board['dir'])) mkdir($board['dir'], 0777);
		if(!file_exists($board['dir'] . DIR_IMG)) @mkdir($board['dir'] . DIR_IMG, 0777) or error("Couldn't create " . DIR_IMG . ". Check permissions.", true);
		if(!file_exists($board['dir'] . DIR_THUMB)) @mkdir($board['dir'] . DIR_THUMB, 0777) or error("Couldn't create " . DIR_THUMB . ". Check permissions.", true);
		if(!file_exists($board['dir'] . DIR_RES)) @mkdir($board['dir'] . DIR_RES, 0777) or error("Couldn't create " . DIR_RES . ". Check permissions.", true);
	}
	
	function openBoard($uri) {
		global $sql;
		sql_open();
		$boards_res = mysql_query(sprintf(
			"SELECT * FROM `boards` WHERE `uri` = '%s' LIMIT 1",
				mysql_real_escape_string($uri)
		), $sql) or error(mysql_error($sql));
		
		if($_board = mysql_fetch_array($boards_res)) {
			setupBoard($_board);
			return true;
		} else return false;
	}
	
	function threadExists($id) {
		global $sql;
		$thread_res = mysql_query(sprintf(
			"SELECT 1 FROM `posts` WHERE `id` = '%d' AND `thread` IS NULL LIMIT 1",<commit_msg>listBoards() functions<commit_after><?php
	function sprintf3($str, $vars, $delim = '%') {
		$replaces = array();
		foreach($vars as $k => $v) {
			$replaces[$delim . $k . $delim] = $v;
		}
		return str_replace(array_keys($replaces),
		                   array_values($replaces), $str);
	}

	function sql_open() {
		global $sql;
		$sql = @mysql_connect(MY_SERVER, MY_USER, MY_PASSWORD) or error('Database error.');
		@mysql_select_db(MY_DATABASE, $sql) or error('Database error.');
	}
	function sql_close() {
		global $sql;
		@mysql_close($sql);
	}

	function mysql_safe_array(&$array) {
		foreach($array as &$item) {
			$item = mysql_real_escape_string($item);
		}
	}
	
	function setupBoard($array) {
		global $board;
		
		$board = Array(
		'id' => $array['id'],
		'uri' => $array['uri'],
		'name' => $array['title'],
		'title' => $array['subtitle']);
		
		$board['dir'] = sprintf(BOARD_PATH, $board['uri']);
		$board['url'] = sprintf(BOARD_ABBREVIATION, $board['uri']);
		
		if(!file_exists($board['dir'])) mkdir($board['dir'], 0777);
		if(!file_exists($board['dir'] . DIR_IMG)) @mkdir($board['dir'] . DIR_IMG, 0777) or error("Couldn't create " . DIR_IMG . ". Check permissions.", true);
		if(!file_exists($board['dir'] . DIR_THUMB)) @mkdir($board['dir'] . DIR_THUMB, 0777) or error("Couldn't create " . DIR_THUMB . ". Check permissions.", true);
		if(!file_exists($board['dir'] . DIR_RES)) @mkdir($board['dir'] . DIR_RES, 0777) or error("Couldn't create " . DIR_RES . ". Check permissions.", true);
	}
	
	function openBoard($uri) {
		global $sql;
		sql_open();
		$boards_res = mysql_query(sprintf(
			"SELECT * FROM `boards` WHERE `uri` = '%s' LIMIT 1",
				mysql_real_escape_string($uri)
		), $sql) or error(mysql_error($sql));
		
		if($_board = mysql_fetch_array($boards_res)) {
			setupBoard($_board);
			return true;
		} else return false;
	}
	
	function listBoards() {
		global $sql;
		sql_open();
		$boards_res = mysql_query("SELECT * FROM `boards`", $sql) or error(mysql_error($sql));
		
		$boards = Array();
		while($_board = mysql_fetch_array($boards_res)) {
			$boards[] = $_board;
		}
		return $boards;
	}
	
	function threadExists($id) {
		global $sql;
		$thread_res = mysql_query(sprintf(
			"SELECT 1 FROM `posts` WHERE `id` = '%d' AND `thread` IS NULL LIMIT 1",
{'fraction_non_alphanumeric': 0.1960233918128655, 'fraction_numerical': 0.00935672514619883, 'mean_word_length': 4.365119196988708, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5240775', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1553, 'n_words': 324}