<commit_before><?php
	/**
	 * Created by JetBrains PhpStorm.
	 * User: degola
	 * Date: 24.02.13
	 * Time: 16:08
	 * To change this template use File | Settings | File Templates.
	 */

	namespace slc\MVC;

	class Router_Driver_TidyURL extends Router_Driver {
		protected function parseRoute() {
			if(preg_match('/^([a-zA-Z0-9\/\-_]{1,})(|\?(.*))$/', $this->getQueryString(), $matchResult)) {
				$arguments = array_pop($matchResult);
				$QueryStringArray = array();
				parse_str($arguments, $QueryStringArray);

				$Route = preg_replace('/\//', '::', $matchResult[1]);
				if (!$Route || $Route == '::') {
					$Route = Base::Factory()->getConfig('Application', 'DefaultRoute');
				}
				$Route = trim($Route, '::');
				$this->StartRoute = $Route;
				if ($result = $this->findControllerAndViewByRouteString($Route)) {
					$this->setController($result->FilePath, $result->Class);
					$this->setView((object)array(
						'View' => $result->View,
						'Path' => $result->ViewPath
					));
					$QueryStringArray['__AdditionalViewParameters'] = $result->AdditionalViewParameters;
					$this->setViewArguments($QueryStringArray);

					return true;
				}
			}
			return false;
		}
		public function link($link, array $arguments = null, $includeDomain = false) {
			foreach(Router::Factory()->getHooks('onBeforeLink') AS $hookId => $hookFunction) {
				$link = $hookFunction($link, $arguments, $includeDomain);
			}
			$prefix = '';
			if($includeDomain)
				$prefix = ((isset($_SERVER['SSL'])&&$_SERVER['SSL'])||(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS'])?'https://':'http://').(isset($_SERVER['HOST'])?$_SERVER['HOST']:$_SERVER['HTTP_HOST']);
			$args = array();
			if(is_array($arguments)) {
				foreach ($arguments AS $key => $value) {
					$args[] = urlencode($key) . '=' . urlencode($value);
				}
			}
			return $prefix.'/'.implode('/', explode('::', $link)).(sizeof($arguments)>0?'?'.implode('&', $args):'');
		}

	}

	?><commit_msg>fixed the tidy url parsing for sub directories<commit_after><?php
	/**
	 * Created by JetBrains PhpStorm.
	 * User: degola
	 * Date: 24.02.13
	 * Time: 16:08
	 * To change this template use File | Settings | File Templates.
	 */

	namespace slc\MVC;

	class Router_Driver_TidyURL extends Router_Driver {
		protected function parseRoute() {
			$queryString = $this->getQueryString();
			if($_SERVER['SCRIPT_NAME'] != '/') {
				$regex = '/^'.addcslashes(dirname($_SERVER['SCRIPT_NAME']), '+-.,[]/\\').'/';
				$queryString = preg_replace($regex, '', $queryString);
			}
			if(preg_match('/^([a-zA-Z0-9\/\-_]{1,})(|\?(.*))$/', $queryString, $matchResult)) {
				$arguments = array_pop($matchResult);
				$QueryStringArray = array();
				parse_str($arguments, $QueryStringArray);

				$Route = preg_replace('/\//', '::', $matchResult[1]);
				if (!$Route || $Route == '::') {
					$Route = Base::Factory()->getConfig('Application', 'DefaultRoute');
				}
				$Route = trim($Route, '::');
				$this->StartRoute = $Route;
				if ($result = $this->findControllerAndViewByRouteString($Route)) {
					$this->setController($result->FilePath, $result->Class);
					$this->setView((object)array(
						'View' => $result->View,
						'Path' => $result->ViewPath
					));
					$QueryStringArray['__AdditionalViewParameters'] = $result->AdditionalViewParameters;
					$this->setViewArguments($QueryStringArray);

					return true;
				}
			}
			return false;
		}
		public function link($link, array $arguments = null, $includeDomain = false) {
			foreach(Router::Factory()->getHooks('onBeforeLink') AS $hookId => $hookFunction) {
				$link = $hookFunction($link, $arguments, $includeDomain);
			}
			$prefix = '';
			if($includeDomain)
				$prefix = ((isset($_SERVER['SSL'])&&$_SERVER['SSL'])||(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS'])?'https://':'http://').(isset($_SERVER['HOST'])?$_SERVER['HOST']:$_SERVER['HTTP_HOST']);
			$args = array();
			if(is_array($arguments)) {
				foreach ($arguments AS $key => $value) {
					$args[] = urlencode($key) . '=' . urlencode($value);
				}
			}
			return $prefix.'/'.implode('/', explode('::', $link)).(sizeof($arguments)>0?'?'.implode('&', $args):'');
		}

	}

	?>
{'fraction_non_alphanumeric': 0.22388419782870927, 'fraction_numerical': 0.007237635705669481, 'mean_word_length': 4.105911330049261, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 2, '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': '1757550', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1344, 'n_words': 223}