<commit_before><?php

define('NL', "\n");
function _print_r($a) { echo '<pre>'; print_r($a); echo '</pre>'; }
function debug($var, $key) { echo '<div style="border: 3px solid red;"><strong>'.$key.':</strong> '.$var.'</div>'; }

function linkTo($title, $url, $query) {
	$title = highlight($title, $query);
	return '<li><a href="'.$url.'">'.$title.'</a></li>'.NL;
}
function highlight($text, $keyword) {
	$searchText = strtolower($text);
	$start = strpos($searchText, $keyword);
	#debug($start, '$start');
	if ($start !== false) {
		$end = $start + strlen($keyword) + strlen('<span class="highlight">');
		$text = substr_replace($text, '<span class="highlight">', $start, 0);
		$text = substr_replace($text, '</span>', $end, 0);
	}
	return $text;
}
function sqlGetResults($query, $handle) {
	$resultSet = $handle->query($query);
	$results = array();
	while($result = $resultSet->fetch_assoc()) {
		$results[] = $result;
	}
	return $results;
}

function skipHiddenWorlds($world_results, $worlds) {
	$new_results = array();
	foreach ($world_results as $key => $world) {
		$uni['mysql']['handle'] = new mysqli($worlds['mysql']['host'], $worlds['mysql']['user'], $worlds['mysql']['pass'], 'aw_universe');
		$uni['mysql']['query'] = "SELECT Name, Hidden FROM awu_license WHERE Name LIKE '".$world['Name']."';";
		$world_info = sqlGetResults($uni['mysql']['query'], $uni['mysql']['handle']);
		if ($world_info[0]['Hidden'] != 1) {
			$new_results[$key] = $world;
		}
	}
	
	return $new_results;
}

$query = '';
if (!empty($_GET['q'])) {
	$query = $_GET['q'];
	$query = preg_replace('|[^a-zA-Z0-9 ]|', '', $query);
	
	// log
	@file_put_contents('./keywords.log', date('Y/m/d', time())."\t".$query.NL, FILE_APPEND);
	
	// worlds
	$worlds['mysql']['host'] = 'localhost';
	$worlds['mysql']['user'] = 'aw';
	$worlds['mysql']['pass'] = base64_decode('c2VkcnU1dCZzUDImckVfZQ==');
	
	$worlds['worldservers'] = array(
		'school1', 'l3d', 'intern', 'school2', 'speciaal',
	);
	$worlds['resultsName'] = array();
	$worlds['resultsKeywords'] = array();
	foreach ($worlds['worldservers'] as $worldserver) {
		$worlds['mysql']['name'] = 'aw_w'.$worldserver;
		$worlds['mysql']['handle'] = new mysqli($worlds['mysql']['host'], $worlds['mysql']['user'], $worlds['mysql']['pass'], $worlds['mysql']['name']);
		$worlds['mysql']['arg']['q'] = $worlds['mysql']['handle']->real_escape_string($query);
		$worlds['mysql']['query'] = "SELECT ID, Name FROM aws_world WHERE Enabled = '1' AND Name LIKE '%".$worlds['mysql']['arg']['q']."%';";
		$worlds['resultsName'] = array_merge($worlds['resultsName'], sqlGetResults($worlds['mysql']['query'], $worlds['mysql']['handle']));
		$worlds['mysql']['query'] = "SELECT Name, Value FROM aws_world, aws_attrib WHERE aws_world.Enabled = '1' AND aws_world.ID = aws_attrib.World AND aws_attrib.ID = '58' AND Value LIKE '%".$worlds['mysql']['arg']['q']."%';";
		$worlds['resultsKeywords'] = array_merge($worlds['resultsKeywords'], sqlGetResults($worlds['mysql']['query'], $worlds['mysql']['handle']));
	}
	
	// don't show hidden worlds<commit_msg>remove old passwords, allow to reuse<commit_after><?php

define('NL', "\n");
function _print_r($a) { echo '<pre>'; print_r($a); echo '</pre>'; }
function debug($var, $key) { echo '<div style="border: 3px solid red;"><strong>'.$key.':</strong> '.$var.'</div>'; }

function linkTo($title, $url, $query) {
	$title = highlight($title, $query);
	return '<li><a href="'.$url.'">'.$title.'</a></li>'.NL;
}
function highlight($text, $keyword) {
	$searchText = strtolower($text);
	$start = strpos($searchText, $keyword);
	#debug($start, '$start');
	if ($start !== false) {
		$end = $start + strlen($keyword) + strlen('<span class="highlight">');
		$text = substr_replace($text, '<span class="highlight">', $start, 0);
		$text = substr_replace($text, '</span>', $end, 0);
	}
	return $text;
}
function sqlGetResults($query, $handle) {
	$resultSet = $handle->query($query);
	$results = array();
	while($result = $resultSet->fetch_assoc()) {
		$results[] = $result;
	}
	return $results;
}

function skipHiddenWorlds($world_results, $worlds) {
	$new_results = array();
	foreach ($world_results as $key => $world) {
		$uni['mysql']['handle'] = new mysqli($worlds['mysql']['host'], $worlds['mysql']['user'], $worlds['mysql']['pass'], 'aw_universe');
		$uni['mysql']['query'] = "SELECT Name, Hidden FROM awu_license WHERE Name LIKE '".$world['Name']."';";
		$world_info = sqlGetResults($uni['mysql']['query'], $uni['mysql']['handle']);
		if ($world_info[0]['Hidden'] != 1) {
			$new_results[$key] = $world;
		}
	}
	
	return $new_results;
}

$query = '';
if (!empty($_GET['q'])) {
	$query = $_GET['q'];
	$query = preg_replace('|[^a-zA-Z0-9 ]|', '', $query);
	
	// log
	@file_put_contents('./keywords.log', date('Y/m/d', time())."\t".$query.NL, FILE_APPEND);
	
	// worlds
	$worlds['mysql']['host'] = 'localhost';
	$worlds['mysql']['user'] = 'aw';
	$worlds['mysql']['pass'] = '...';
	
	$worlds['worldservers'] = array(
		'school1', 'l3d', 'intern', 'school2', 'speciaal',
	);
	$worlds['resultsName'] = array();
	$worlds['resultsKeywords'] = array();
	foreach ($worlds['worldservers'] as $worldserver) {
		$worlds['mysql']['name'] = 'aw_w'.$worldserver;
		$worlds['mysql']['handle'] = new mysqli($worlds['mysql']['host'], $worlds['mysql']['user'], $worlds['mysql']['pass'], $worlds['mysql']['name']);
		$worlds['mysql']['arg']['q'] = $worlds['mysql']['handle']->real_escape_string($query);
		$worlds['mysql']['query'] = "SELECT ID, Name FROM aws_world WHERE Enabled = '1' AND Name LIKE '%".$worlds['mysql']['arg']['q']."%';";
		$worlds['resultsName'] = array_merge($worlds['resultsName'], sqlGetResults($worlds['mysql']['query'], $worlds['mysql']['handle']));
		$worlds['mysql']['query'] = "SELECT Name, Value FROM aws_world, aws_attrib WHERE aws_world.Enabled = '1' AND aws_world.ID = aws_attrib.World AND aws_attrib.ID = '58' AND Value LIKE '%".$worlds['mysql']['arg']['q']."%';";
		$worlds['resultsKeywords'] = array_merge($worlds['resultsKeywords'], sqlGetResults($worlds['mysql']['query'], $worlds['mysql']['handle']));
	}
	
	// don't show hidden worlds
{'fraction_non_alphanumeric': 0.2661409561360276, 'fraction_numerical': 0.005257105306390669, 'mean_word_length': 6.525339925834364, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 37, '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': '1106800', 'n_tokens_mistral': 2218, 'n_tokens_neox': 2152, 'n_words': 403}