<commit_before><?php
/**
 * Util_Rewrite class
 *
 * Contains rewrite utils
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

namespace Skeleton\Core;

class Util {

	/**
	 * Reverse rewrite
	 *
	 * @access public
	 * @param string $html
	 * @return string $html_with_reverse_rewrite
	 */
	public static function rewrite_reverse_html($html) {
		$html = preg_replace_callback('@\<([^>]*) (href|src|action)="/([^"]*)?"@iU', 'self::rewrite_reverse_html_callback', $html);
		return $html;
	}

	/**
	 * Reverse rewrite callback for regexp
	 *
	 * @access private
	 * @param array $data
	 * @return string $string
	 */
	public static function rewrite_reverse_html_callback($data) {
		if (!isset($data[3])) {
			return $data[0];
		}

		$application = Application::Get();

		$new_link = Util::rewrite_reverse_link($data[3]);

		if (isset($application->config->base_uri) and $application->config->base_uri !== null) {
			$new_link = trim($application->config->base_uri, '/') . '/' . $new_link;
		}

		return str_replace($data[3], $new_link, $data[0]);
	}

	/**
	 * Do a reverse rewrite of a link
	 *
	 * @access public
	 * @param string $url
	 * @return string $reverse_rewrite
	 */
	public static function rewrite_reverse_link($url_raw) {
		$url = parse_url($url_raw);

		$params = [];
		if (isset($url['query'])) {
			// Allow &amp; instead of &
			$url['query'] = str_replace('&amp;', '&', $url['query']);
			parse_str($url['query'], $params);
		}

		$application = \Skeleton\Core\Application::Get();
		$language = $application->language;
		$routes = $application->config->routes;

		/**
		 * Add language to the known parameters
		 */
		$params['language'] = $language->name_short;
<commit_msg>Don't add superfluous forward slash<commit_after><?php
/**
 * Util_Rewrite class
 *
 * Contains rewrite utils
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

namespace Skeleton\Core;

class Util {

	/**
	 * Reverse rewrite
	 *
	 * @access public
	 * @param string $html
	 * @return string $html_with_reverse_rewrite
	 */
	public static function rewrite_reverse_html($html) {
		$html = preg_replace_callback('@\<([^>]*) (href|src|action)="/([^"]*)?"@iU', 'self::rewrite_reverse_html_callback', $html);
		return $html;
	}

	/**
	 * Reverse rewrite callback for regexp
	 *
	 * @access private
	 * @param array $data
	 * @return string $string
	 */
	public static function rewrite_reverse_html_callback($data) {
		if (!isset($data[3])) {
			return $data[0];
		}

		$application = Application::Get();

		$new_link = Util::rewrite_reverse_link($data[3]);

		if (isset($application->config->base_uri) and $application->config->base_uri !== null) {
			$new_link = trim($application->config->base_uri, '/') . '/' . $new_link;
			$new_link = trim($new_link, '/');
		}

		return str_replace($data[3], $new_link, $data[0]);
	}

	/**
	 * Do a reverse rewrite of a link
	 *
	 * @access public
	 * @param string $url
	 * @return string $reverse_rewrite
	 */
	public static function rewrite_reverse_link($url_raw) {
		$url = parse_url($url_raw);

		$params = [];
		if (isset($url['query'])) {
			// Allow &amp; instead of &
			$url['query'] = str_replace('&amp;', '&', $url['query']);
			parse_str($url['query'], $params);
		}

		$application = \Skeleton\Core\Application::Get();
		$language = $application->language;
		$routes = $application->config->routes;

		/**
		 * Add language to the known parameters
		 */
		$params['language'] = $language->name_short;

{'fraction_non_alphanumeric': 0.18614718614718614, 'fraction_numerical': 0.002886002886002886, 'mean_word_length': 4.045123726346434, 'pattern_counts': {'":': 0, '<': 19, '<?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': '2197431', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1142, 'n_words': 248}