<commit_before><?php
	#
	# $Id: missing.php,v 1.1.2.29 2006-02-14 13:04:37 dan Exp $
	#
	# Copyright (c) 2001-2003 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 = '';

	$pathname = AddSlashes(htmlentities($REQUEST_URI));

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

#	UnSet($result);

	$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);

	# Strip off the files.php extension if it's there...
	$FilesRequest = preg_replace('|^(.*)/files\.php$|', '\\1', $pathname);
	if ($FilesRequest != $pathname) {
		$pathname     = $FilesRequest;
		$FilesRequest = true;
	} else {
		$FilesRequest = false;
	}

	if ($Debug) {
		echo "pathname='" . htmlentities($pathname) . "'<br>";
		echo "FilesRequest='" . $FilesRequest . "'<br>";
	}


	if (strpos($pathname, '/') !== FALSE) {
		GLOBAL $User;

		list($category, $port, $extra) = explode('/', PATH_NAME);
		if ($Debug) echo "extra is '" . $extra . "'<br>";
		if ($extra == '' || $FilesRequest) {
			if ($Debug) echo 'checking for PortID<br>';
			$port_id = freshports_GetPortID($db, $category, $port);
			if (IsSet($port_id)) {
				if ($Debug) echo "$category/$port found by freshports_GetPortID<br>";

				if ($FilesRequest) {
					if ($Debug) echo 'going for files.php<br>';
					# extract the message ID from the URI
					parse_str($_SERVER['REDIRECT_QUERY_STRING'], $query_parts);
					$message_id = $query_parts['message_id'];

					if ($Debug) echo 'we have message_id=' . $message_id . '<br>';
					require_once($_SERVER['DOCUMENT_ROOT'] . '/include/files.php');
					require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/ports.php');
					$Port = new Port($db);
					$Port->FetchByID($port_id);
					freshports_Files($User, $Port->element_id, $message_id, $db);
					exit;
				} else {
					require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-port.php');

					freshports_PortDescriptionByPortID($db, $port_id);
					exit;
				}
			}
		}
	}

	if ($Debug) echo 'checking for ' . FRESHPORTS_PORTS_TREE_PREFIX . $pathname . '<br>';
	list($category, $extra) = explode('/', $pathname);
	if ($extra == '') {
		require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/categories.php');
		$Category = new Category($db);
		$CategoryID = $Category->IsCategoryByName($category);
		if (IsSet($CategoryID)) {
			// found that category!
			if ($Debug) echo 'found that category<br>';
			require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-category.php');
			freshports_CategoryByID($db, $CategoryID);
			exit;
		}
	}


	if ($ElementRecord->FetchByName(FRESHPORTS_PORTS_TREE_PREFIX . $pathname)) {
		if ($ElementRecord->IsCategory()) {

			require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-category.php');<commit_msg>Let's not do any database accesses until we have to.<commit_after><?php
	#
	# $Id: missing.php,v 1.1.2.30 2006-07-04 20:18:57 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 = '';

	$pathname = AddSlashes(htmlentities($REQUEST_URI));

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

#	UnSet($result);

	$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);

	# Strip off the files.php extension if it's there...
	$FilesRequest = preg_replace('|^(.*)/files\.php$|', '\\1', $pathname);
	if ($FilesRequest != $pathname) {
		$pathname     = $FilesRequest;
		$FilesRequest = true;
	} else {
		$FilesRequest = false;
	}

	if ($Debug) {
		echo "pathname='" . htmlentities($pathname) . "'<br>";
		echo "FilesRequest='" . $FilesRequest . "'<br>";
	}

	if (strpos($pathname, '/') !== FALSE) {
		GLOBAL $User;

		list($category, $port, $extra) = explode('/', PATH_NAME);
		if ($Debug) echo "extra is '" . $extra . "'<br>";
		if ($extra == '' && $port != '' || $FilesRequest) {
			if ($FilesRequest) {
				if ($Debug) echo 'going for files.php<br>';
				if ($Debug) echo 'checking for PortID<br>';
				$element_id = freshports_GetElementID($db, $category, $port);
				if (IsSet($element_id)) {
					if ($Debug) echo "$category/$port found by freshports_GetElementID<br>";
					# extract the message ID from the URI
					parse_str($_SERVER['REDIRECT_QUERY_STRING'], $query_parts);
					$message_id = $query_parts['message_id'];

					if ($Debug) echo 'we have message_id=' . $message_id . '<br>';
					require_once($_SERVER['DOCUMENT_ROOT'] . '/include/files.php');
					require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/ports.php');
					freshports_Files($User, $element_id, $message_id, $db);
					exit;
				}
			} else {
				require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-port.php');

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

	if ($Debug) echo 'checking for ' . FRESHPORTS_PORTS_TREE_PREFIX . $pathname . '<br>';
	list($category, $extra) = explode('/', $pathname);
	if ($extra == '') {
		require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/categories.php');
		$Category = new Category($db);
		$CategoryID = $Category->IsCategoryByName($category);
		if (IsSet($CategoryID)) {
			// found that category!
			if ($Debug) echo 'found that category<br>';
			require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-category.php');
			freshports_CategoryByID($db, $CategoryID);
			exit;
		}
	}


	if ($ElementRecord->FetchByName(FRESHPORTS_PORTS_TREE_PREFIX . $pathname)) {
		if ($ElementRecord->IsCategory()) {

			require_once($_SERVER['DOCUMENT_ROOT'] . '/missing-category.php');
{'fraction_non_alphanumeric': 0.18857805479054934, 'fraction_numerical': 0.011885780547905494, 'mean_word_length': 4.160807778608826, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, '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': '4722870', 'n_tokens_mistral': 2718, 'n_tokens_neox': 2376, 'n_words': 500}