<commit_before><?php
	#
	# $Id: missing.php,v 1.1.2.34 2006-11-09 21:47:58 dan Exp $
	#
	# Copyright (c) 2001-2006 DVL Software Limited
	#

	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/common.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/freshports.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/databaselogin.php');

	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/getvalues.php');


function freshports_Parse404URI($REQUEST_URI, $db) {
	#
	# we have a pending 404
	# if we can parse it, then do so and return 1;
	# otherwise, return 0.

	define('FRESHPORTS_PORTS_TREE_PREFIX', '/ports/');

	$Debug  = 0;
	$result = '';

	$URLParts = parse_url($_SERVER['SCRIPT_URI']);

	$pathname = $URLParts['path'];
	if ($Debug) echo "The pathname is '$pathname'<br>";

	require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/element_record.php');

	$ElementRecord = new ElementRecord($db);

	# first goal, remove leading / and leading ports/
	if (substr($pathname, 0, 1) == '/') {
		$pathname = substr($pathname, 1);
	}

	if (preg_match('|^ports/|', $pathname)) {
		$pathname = substr($pathname, 6);
	}

	define('PATH_NAME', $pathname);
	
	if ($Debug) echo "PATH_NAME='" . PATH_NAME . "'<br>";

	if ($ElementRecord->FetchByName(FRESHPORTS_PORTS_TREE_PREFIX . $pathname)) {
		if ($Debug) {
			echo 'Yes, we found an element for that path!<br>';
			echo '<pre>';
			var_dump($ElementRecord);
			echo '</pre>';
		}

		if ($ElementRecord->IsCategory()) {
			if ($Debug) echo 'This is a category<br>';
			require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-category.php');
			freshports_CategoryByElementID($db, $ElementRecord->id, 1, $User->page_size);
			exit;
		}
		
		if ($Debug) echo 'No, that cannot be a category!<br>';

		if ($ElementRecord->IsPort()) {
			# we don't use list($category, $port) so we don't have to worry
			# about extra bits
			$PathParts = explode('/', PATH_NAME);
			$category = $PathParts[0];
			$port     = $PathParts[1];
			if ($Debug) echo "Category='$category'<br>";
			if ($Debug) echo "Port='$port'<br>";

			require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-port.php');

			$Debug = 0;
			if ($Debug) echo 'This is a Port<br>';

			# if zero is returned, all is well, otherwise, we can't display that category/port.
			freshports_PortDisplay($db, $category, $port);
			exit;
		}

		if ($Debug) echo 'No, that cannot be a port either!!<br>';

		if ($Debug) echo 'This is a not a category and not a port<br>';
		# this is a non-port (e.g. /Mk/)
		require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-non-port.php');
		freshports_NonPortDescription($db, $ElementRecord);
		exit;
	} else {
		if ($Debug) echo 'not an element<br>';
		# let's see if this is a virtual category!

		$result = $REQUEST_URI;
		$PathParts = explode('/', PATH_NAME);

		if ($Debug) {
			echo '<pre>';
			var_dump($PathParts);
			echo '</pre>';
		}

		# start with nothing.
		unset($category);
		unset($port);

		# if the URL looks like /afterstep/, then we'll get two elements
		# in the array.  The second will be empty.  Hence the != ''
		#
		# grab whatever we have
		#
		if (IsSet($PathParts[0]) && $PathParts[0] != '') {
			$category = $PathParts[0];
			if ($Debug) echo "Category is '$category'<br>";
		}			
		if (IsSet($PathParts[1]) && $PathParts[1] != '') {
			$port     = $PathParts[1];
			if ($Debug) echo "Port is '$port'<br>";
		}

		if (IsSet($port)) {
			if ($Debug) echo 'This is a Port<br>';

			require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-port.php');

			# if zero is returned, all is well, otherwise, we can't display that category/port.
			freshports_PortDisplay($db, $category, $port);
			exit;
		}

		if (IsSet($category)) {
			if ($Debug) echo 'This is a category<br>';
			require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-category.php');
			freshports_CategoryByName($db, $category, 1, $User->page_size);
			exit;
		}
	}

	return $result;
}

$result = freshports_Parse404URI($_SERVER['REDIRECT_URL'], $db);

if ($result) {

	#
	# this is a true 404

	$Title = 'Document not found';
	freshports_Start($Title,
					$FreshPortsTitle . ' - new ports, applications',
					'FreeBSD, index, applications, ports');

?>

<?php echo freshports_MainTable(); ?>
<TR>
<TD WIDTH="100%" VALIGN="top">
<?php echo freshports_MainContentTable(); ?>
<TR>
    <TD BGCOLOR="<?php echo BACKGROUND_COLOUR; ?>" HEIGHT="29"><FONT COLOR="#FFFFFF"><BIG><BIG>
<?
   echo "$FreshPortsTitle -- $Title";
?>
</BIG></BIG></FONT></TD>
</TR>

<TR>
<TD WIDTH="100%" VALIGN="top"><commit_msg>Reorganize so there is only one place invoking port, category, and non-port displays.  This should be easier to maintain.<commit_after><?php
	#
	# $Id: missing.php,v 1.1.2.35 2006-11-10 03:37:02 dan Exp $
	#
	# Copyright (c) 2001-2006 DVL Software Limited
	#

	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/common.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/freshports.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/databaselogin.php');

	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/getvalues.php');


function freshports_Parse404URI($REQUEST_URI, $db) {
	#
	# we have a pending 404
	# if we can parse it, then do so and return 1;
	# otherwise, return 0.
	
	$Debug  = 0;
	$result = '';

	$IsPort     = false;
	$IsCatgory  = false;
	$IsElement  = false;

	$CategoryID = 0;

	define('FRESHPORTS_PORTS_TREE_PREFIX', '/ports/');

	$URLParts = parse_url($_SERVER['SCRIPT_URI']);

	$pathname = $URLParts['path'];
	if ($Debug) echo "The pathname is '$pathname'<br>";

	require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/element_record.php');

	$ElementRecord = new ElementRecord($db);

	# first goal, remove leading / and leading ports/
	if (substr($pathname, 0, 1) == '/') {
		$pathname = substr($pathname, 1);
	}

	if (preg_match('|^ports/|', $pathname)) {
		$pathname = substr($pathname, 6);
	}

	define('PATH_NAME', $pathname);
	
	if ($Debug) echo "PATH_NAME='" . PATH_NAME . "'<br>";

	if ($ElementRecord->FetchByName(FRESHPORTS_PORTS_TREE_PREFIX . $pathname)) {
		$IsElement = true;
		if ($Debug) {
			echo 'Yes, we found an element for that path!<br>';
			echo '<pre>';
			var_dump($ElementRecord);
			echo '</pre>';
		}

		if ($ElementRecord->IsCategory()) {
			$IsCategory = true;
			if ($Debug) echo 'This is a category<br>';

			require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/categories.php');
			$Category = new Category($db);
			$CategoryID = $Category->FetchByElementID($ElementRecord->id);
		}
		
		if ($Debug) echo 'No, that cannot be a category!<br>';

		if ($ElementRecord->IsPort()) {
			$IsPort = true;
			# we don't use list($category, $port) so we don't have to worry
			# about extra bits
			$PathParts = explode('/', PATH_NAME);
			$category = $PathParts[0];
			$port     = $PathParts[1];
			if ($Debug) echo "Category='$category'<br>";
			if ($Debug) echo "Port='$port'<br>";

			require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-port.php');

			$Debug = 0;
			if ($Debug) echo 'This is a Port<br>';
		}
	} else {
		if ($Debug) echo 'not an element<br>';
		# let's see if this is a virtual category!

		$result = $REQUEST_URI;
		$PathParts = explode('/', PATH_NAME);

		if ($Debug) {
			echo '<pre>';
			var_dump($PathParts);
			echo '</pre>';
		}

		# start with nothing.
		unset($category);
		unset($port);

		# if the URL looks like /afterstep/, then we'll get two elements
		# in the array.  The second will be empty.  Hence the != ''
		#
		# grab whatever we have
		#
		if (IsSet($PathParts[0]) && $PathParts[0] != '') {
			$category = $PathParts[0];
			if ($Debug) echo "Category is '$category'<br>";
		}

		if (IsSet($PathParts[1]) && $PathParts[1] != '') {
			$port = $PathParts[1];
			if ($Debug) echo "Port is '$port'<br>";
		}

		if (IsSet($port)) {
			$IsPort = true;

			if ($Debug) echo 'This is a Port<br>';
		}

		if (IsSet($category) && !$IsPort) {
			$IsCategory = true;
			if ($Debug) echo 'This is a category<br>';

			require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/categories.php');
			$Category = new Category($db);
			$CategoryID = $Category->FetchByName($category);
		}
	}

	if ($IsPort) {
		require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-port.php');

		# if zero is returned, all is well, otherwise, we can't display that category/port.
		freshports_PortDisplay($db, $category, $port);
		exit;
	}

	if ($IsCategory) {
		if ($Debug) echo 'This is a category<br>';
		require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-category.php');
		freshports_CategoryByID($db, $CategoryID, 1, $User->page_size);
		exit;
	}

	if ($IsElement) {
		require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-non-port.php');
		freshports_NonPortDescription($db, $ElementRecord);
		exit;
	}
				
	return $result;
}

$result = freshports_Parse404URI($_SERVER['REDIRECT_URL'], $db);

if ($result) {

	#
	# this is a true 404

	$Title = 'Document not found';
	freshports_Start($Title,
					$FreshPortsTitle . ' - new ports, applications',
					'FreeBSD, index, applications, ports');

?>

<?php echo freshports_MainTable(); ?>
<TR>
<TD WIDTH="100%" VALIGN="top">
<?php echo freshports_MainContentTable(); ?>
<TR>
    <TD BGCOLOR="<?php echo BACKGROUND_COLOUR; ?>" HEIGHT="29"><FONT COLOR="#FFFFFF"><BIG><BIG>
<?
   echo "$FreshPortsTitle -- $Title";
?>
</BIG></BIG></FONT></TD>
</TR>

<TR>
<TD WIDTH="100%" VALIGN="top">
{'fraction_non_alphanumeric': 0.1859415305245056, 'fraction_numerical': 0.013972484952708513, 'mean_word_length': 4.027012425715829, 'pattern_counts': {'":': 0, '<': 78, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '7042211', 'n_tokens_mistral': 3735, 'n_tokens_neox': 3254, 'n_words': 821}