<commit_before><?php

if(!$_SERVER['QUERY_STRING']) {
	die('Must specify a ticket to view!');
}

require dirname(__FILE__).'/include/config.php';

// XXX Should come up with a way of escaping so that tickets can be in folders
$ticket = explode("\n\n",file_get_contents(REPOSITORY_PATH.'/.tickets/'.basename($_SERVER['QUERY_STRING'])),2);

$id = null;
$meta = explode("\n", $ticket[0]);
if(count($meta)) {
	echo "<dl>\n";
	foreach($meta as $line) {
		$line = preg_split('/:\s*/', $line, 2);
		if($line[0] && $line[1]) {
			if(strtolower($line[0]) == 'message-id') {
				$id = $line[1];
			}
			if(strtolower($line[0]) == 'from') {
				$line[1] = preg_replace('/@[^<>]+/','',$line[1]);
			}
			$k = htmlspecialchars($line[0]);
			$v = htmlspecialchars($line[1]);
			echo "\t<dt>$k</dt>\n\t\t<dd>$v<\dd>\n";
		}
	}
	echo "</dl>\n";
}

echo "\n<p>".str_replace("\n\n","</p>\n\n<p>",$ticket[1])."</p>\n";

if($id) {
	$id = escapeshellarg('^In-Reply-To: '.$id);
	$comments = explode("\n",shell_exec("cd '".REPOSITORY_PATH."/.tickets'; grep -il $id *"));
	if(count($comments)) {
		echo "\n<ul>\n";
		foreach($comments as $comment) {
			if(!$comment) continue;
			$comment = explode("\n\n",file_get_contents(REPOSITORY_PATH.'/.tickets/'.$comment));
			$comment[0] = explode("\n", $comment[0]);
			foreach($comment[0] as $meta) {
				if(!$meta) continue;
				$meta = preg_split('/:\s*/', $meta, 2);
				if(strtolower($meta[0]) == 'from') $from = preg_replace('/@[^<>]+/','',$meta[1]);
				if(strtolower($meta[0]) == 'date') $date = $meta[1];
			}
			echo "\t<li>\n";
			echo "\n\t\t<dl>\n";
			echo "\t\t\t<dt>From</dt>\n";
			echo "\t\t\t\t<dd>".htmlspecialchars($from)."</dd>\n";
			echo "\t\t\t<dt>Date</dt>\n";
			echo "\t\t\t\t<dd>".htmlspecialchars($date)."</dd>\n";
			echo "\t\t</dl>\n";
			echo "\n\t\t<p>".str_replace("\n\n","</p>\n\n\t\t<p>",$comment[1])."</p>\n";
			echo "\t</li>\n";
		}
		echo "</ul>\n";
	}
}


?><commit_msg>Update web to use git ticket list<commit_after><?php

if(!$_SERVER['QUERY_STRING']) {
	die('Must specify a ticket to view!');
}

require dirname(__FILE__).'/include/config.php';

// XXX Should come up with a way of escaping so that tickets can be in folders
$ticket = explode("\n\n",file_get_contents(REPOSITORY_PATH.'/.tickets/'.basename($_SERVER['QUERY_STRING'])),2);

$meta = explode("\n", $ticket[0]);
if(count($meta)) {
	echo "<dl>\n";
	foreach($meta as $line) {
		$line = preg_split('/:\s*/', $line, 2);
		if($line[0] && $line[1]) {
			if(strtolower($line[0]) == 'from') {
				$line[1] = preg_replace('/@[^<>]+/','',$line[1]);
			}
			$k = htmlspecialchars($line[0]);
			$v = htmlspecialchars($line[1]);
			echo "\t<dt>$k</dt>\n\t\t<dd>$v<\dd>\n";
		}
	}
	echo "</dl>\n";
}

echo "\n<p>".str_replace("\n\n","</p>\n\n<p>",$ticket[1])."</p>\n";

// XXX support threaded comments
$comments = explode("\n",shell_exec("cd '".REPOSITORY_PATH."/.tickets'; git ticket list comments '".basename($_SERVER['QUERY_STRING'])."'"));
if(count($comments)) {
	echo "\n<ul>\n";
	foreach($comments as $comment) {
		if(!$comment) continue;
		$comment = explode("\n\n",file_get_contents(REPOSITORY_PATH.'/.tickets/'.$comment));
		$comment[0] = explode("\n", $comment[0]);
		foreach($comment[0] as $meta) {
			if(!$meta) continue;
			$meta = preg_split('/:\s*/', $meta, 2);
			if(strtolower($meta[0]) == 'from') $from = preg_replace('/@[^<>]+/','',$meta[1]);
			if(strtolower($meta[0]) == 'date') $date = $meta[1];
		}
		echo "\t<li>\n";
		echo "\n\t\t<dl>\n";
		echo "\t\t\t<dt>From</dt>\n";
		echo "\t\t\t\t<dd>".htmlspecialchars($from)."</dd>\n";
		echo "\t\t\t<dt>Date</dt>\n";
		echo "\t\t\t\t<dd>".htmlspecialchars($date)."</dd>\n";
		echo "\t\t</dl>\n";
		echo "\n\t\t<p>".str_replace("\n\n","</p>\n\n\t\t<p>",$comment[1])."</p>\n";
		echo "\t</li>\n";
	}
	echo "</ul>\n";
}


?>
{'fraction_non_alphanumeric': 0.2975532754538279, 'fraction_numerical': 0.011049723756906077, 'mean_word_length': 3.989501312335958, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 65, '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': '7077313', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1597, 'n_words': 248}