<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 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();
		
		$query = prepare("SELECT * FROM `boards` WHERE `uri` = :uri LIMIT 1");
		$query->bindValue(':uri', $uri);
		$query->execute() or error(db_error($query));
		
		if($board = $query->fetch()) {
			setupBoard($board);
			return true;
		} else return false;
	}
	
	function listBoards() {
		$query = query("SELECT * FROM `boards`") or error(db_error());
		$boards = $query->fetchAll();
		return $boards;
	}
	
	function threadExists($id) {
		global $board;
		
		$query = prepare(sprintf("SELECT 1 FROM `posts_%s` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri']));
		$query->bindValue(':id', $id, PDO::PARAM_INT);
		$query->execute() or error(db_error());
		
		if($query->rowCount()) {
			return true;
		} else return false;
	}
	
	function post($post, $OP) {
		global $pdo, $board;
		
		$query = prepare(sprintf("INSERT INTO `posts_%s` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :body, :time, :time, :thumb, :thumbwidth, :thumbheight, :file, :width, :height, :filesize, :filename, :filehash, :password, :ip, :sticky)", $board['uri']));
		
		// Basic stuff
		$query->bindValue(':subject', $post['subject']);
		$query->bindValue(':email', $post['email']);
		$query->bindValue(':name', $post['name']);
		$query->bindValue(':trip', $post['trip']);
		$query->bindValue(':body', $post['body']);
		$query->bindValue(':time', time(), PDO::PARAM_INT);
		$query->bindValue(':password', $post['password']);		
		$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
		$query->bindValue(':sticky', 0, PDO::PARAM_INT);
		
		if($OP) {
			// No parent thread, image
			$query->bindValue(':thread', null, PDO::PARAM_NULL);
		} else {
			$query->bindValue(':thread', $post['thread'], PDO::PARAM_INT);
		}
		
		if($post['has_file']) {
			$query->bindValue(':thumb', $post['thumb']);
			$query->bindValue(':thumbwidth', $post['thumbwidth'], PDO::PARAM_INT);
			$query->bindValue(':thumbheight', $post['thumbheight'], PDO::PARAM_INT);
			$query->bindValue(':file', $post['file']);
			$query->bindValue(':width', $post['width'], PDO::PARAM_INT);
			$query->bindValue(':height', $post['height'], PDO::PARAM_INT);
			$query->bindValue(':filesize', $post['filesize'], PDO::PARAM_INT);
			$query->bindValue(':filename', $post['filesize']);
			$query->bindValue(':filehash', $post['filesize']);
		} else {
			$query->bindValue(':thumb', null, PDO::PARAM_NULL);
			$query->bindValue(':thumbwidth', null, PDO::PARAM_NULL);
			$query->bindValue(':thumbheight', null, PDO::PARAM_NULL);
			$query->bindValue(':file', null, PDO::PARAM_NULL);
			$query->bindValue(':width', null, PDO::PARAM_NULL);
			$query->bindValue(':height', null, PDO::PARAM_NULL);
			$query->bindValue(':filesize', null, PDO::PARAM_NULL);
			$query->bindValue(':filename', null, PDO::PARAM_NULL);
			$query->bindValue(':filehash', null, PDO::PARAM_NULL);
		}
		
		$query->execute() or error(db_error($query));
		
		return $pdo->lastInsertId();
	}
	
	function bumpThread($id) {
		global $board;
		$query = prepare(sprintf("UPDATE `posts_%s` SET `bump` = :time WHERE `id` = :id AND `thread` IS NULL", $board['uri']));
		$query->bindValue(':time', time(), PDO::PARAM_INT);
		$query->bindValue(':id', $id, PDO::PARAM_INT);
		$query->execute() or error(db_error($query));
	}

	function index($page, $mod=false) {<commit_msg>Fixed filename in image posting<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 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();
		
		$query = prepare("SELECT * FROM `boards` WHERE `uri` = :uri LIMIT 1");
		$query->bindValue(':uri', $uri);
		$query->execute() or error(db_error($query));
		
		if($board = $query->fetch()) {
			setupBoard($board);
			return true;
		} else return false;
	}
	
	function listBoards() {
		$query = query("SELECT * FROM `boards`") or error(db_error());
		$boards = $query->fetchAll();
		return $boards;
	}
	
	function threadExists($id) {
		global $board;
		
		$query = prepare(sprintf("SELECT 1 FROM `posts_%s` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri']));
		$query->bindValue(':id', $id, PDO::PARAM_INT);
		$query->execute() or error(db_error());
		
		if($query->rowCount()) {
			return true;
		} else return false;
	}
	
	function post($post, $OP) {
		global $pdo, $board;
		
		$query = prepare(sprintf("INSERT INTO `posts_%s` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :body, :time, :time, :thumb, :thumbwidth, :thumbheight, :file, :width, :height, :filesize, :filename, :filehash, :password, :ip, :sticky)", $board['uri']));
		
		// Basic stuff
		$query->bindValue(':subject', $post['subject']);
		$query->bindValue(':email', $post['email']);
		$query->bindValue(':name', $post['name']);
		$query->bindValue(':trip', $post['trip']);
		$query->bindValue(':body', $post['body']);
		$query->bindValue(':time', time(), PDO::PARAM_INT);
		$query->bindValue(':password', $post['password']);		
		$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
		$query->bindValue(':sticky', 0, PDO::PARAM_INT);
		
		if($OP) {
			// No parent thread, image
			$query->bindValue(':thread', null, PDO::PARAM_NULL);
		} else {
			$query->bindValue(':thread', $post['thread'], PDO::PARAM_INT);
		}
		
		if($post['has_file']) {
			$query->bindValue(':thumb', $post['thumb']);
			$query->bindValue(':thumbwidth', $post['thumbwidth'], PDO::PARAM_INT);
			$query->bindValue(':thumbheight', $post['thumbheight'], PDO::PARAM_INT);
			$query->bindValue(':file', $post['file']);
			$query->bindValue(':width', $post['width'], PDO::PARAM_INT);
			$query->bindValue(':height', $post['height'], PDO::PARAM_INT);
			$query->bindValue(':filesize', $post['filesize'], PDO::PARAM_INT);
			$query->bindValue(':filename', $post['filename']);
			$query->bindValue(':filehash', $post['filesize']);
		} else {
			$query->bindValue(':thumb', null, PDO::PARAM_NULL);
			$query->bindValue(':thumbwidth', null, PDO::PARAM_NULL);
			$query->bindValue(':thumbheight', null, PDO::PARAM_NULL);
			$query->bindValue(':file', null, PDO::PARAM_NULL);
			$query->bindValue(':width', null, PDO::PARAM_NULL);
			$query->bindValue(':height', null, PDO::PARAM_NULL);
			$query->bindValue(':filesize', null, PDO::PARAM_NULL);
			$query->bindValue(':filename', null, PDO::PARAM_NULL);
			$query->bindValue(':filehash', null, PDO::PARAM_NULL);
		}
		
		$query->execute() or error(db_error($query));
		
		return $pdo->lastInsertId();
	}
	
	function bumpThread($id) {
		global $board;
		$query = prepare(sprintf("UPDATE `posts_%s` SET `bump` = :time WHERE `id` = :id AND `thread` IS NULL", $board['uri']));
		$query->bindValue(':time', time(), PDO::PARAM_INT);
		$query->bindValue(':id', $id, PDO::PARAM_INT);
		$query->execute() or error(db_error($query));
	}

	function index($page, $mod=false) {
{'fraction_non_alphanumeric': 0.23325842696629215, 'fraction_numerical': 0.004719101123595505, 'mean_word_length': 5.142857142857143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 95, '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': '5728188', 'n_tokens_mistral': 3542, 'n_tokens_neox': 3159, 'n_words': 608}