<commit_before><?php
/**
 * The Phile Utility class
 */
namespace Phile\Core;

/**
 * the Registry class for implementing a registry
 *
 * @author  <NAME>
 * @link    https://philecms.com
 * @license http://opensource.org/licenses/MIT
 * @package Phile
 */
class Utility {

	/**
	 * method to get the current http protocoll
	 *
	 * @return string the current protocol
	 */
	public static function getProtocol() {
		if (PHILE_CLI_MODE) {
			return '';
		}
		$protocol = 'http';
		if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ) {
			$protocol = 'https';
		}

		return $protocol;
	}

	/**
	 * detect base url
	 *
	 * @return string
	 */
	public static function getBaseUrl() {
		if (PHILE_CLI_MODE) {
			return '';
		}
		if (Registry::isRegistered('Phile_Settings')) {
			$config = Registry::get('Phile_Settings');
			if (isset($config['base_url']) && $config['base_url']) {
				return $config['base_url'];
			}
		}

		$url         = '';
		$request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '';
		$script_url  = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : '';
		if ($request_url != $script_url) {
			$url = trim(preg_replace('/' . str_replace('/', '\/', str_replace('index.php', '', $script_url)) . '/', '', $request_url, 1), '/');
		}

		$protocol = self::getProtocol();

		return rtrim(str_replace($url, '', $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']), '/');
	}

	/**
	 * detect install path
	 *
	 * @return string
	 */
	public static function getInstallPath() {
		$path = self::getBaseUrl();
		$path = substr($path, strpos($path, '://') + 3);
		$path = substr($path, strpos($path, '/') + 1);

		return $path;
	}

	/**
	 * resolve a file path by replace the mod: prefix
	 *
	 * @param $path
	 *
	 * @return string|null the full filepath or null if file does not exists
	 */
	public static function resolveFilePath($path) {
		// resolve MOD: prefix
		if (strtoupper(substr($path, 0, 3)) === 'MOD') {
			$path = str_ireplace('mod:', PLUGINS_DIR, $path);
		}
		// check if file exists
		if (file_exists($path)) {
			return $path;
		}

		return null;
	}

	/**
	 * load files e.g. config files
	 *
	 * @param $file
	 *
	 * @return mixed|null
	 */
	public static function load($file) {
		if (file_exists($file)) {
			return include $file;
		}

		return null;
	}

	/**
	 * check if a plugin is loaded
	 *
	 * @param $plugin
	 *
	 * @return bool
	 */
	public static function isPluginLoaded($plugin) {
		$config = \Phile\Registry::get('Phile_Settings');
		return (isset($config['plugins'][$plugin]) && isset($config['plugins'][$plugin]['active']) && $config['plugins'][$plugin]['active'] === true);
	}

	/**
	 * static method to get files by directory and file filter
	 *
	 * @param        $directory
	 * @param string $filter
	 *
	 * @return array
	 */
	public static function getFiles($directory, $filter = '\Phile\FilterIterator\GeneralFileFilterIterator') {
		$files  = new $filter(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)));
		$result = array();
		foreach ($files as $file) {
			/** @var \SplFileInfo $file */
			$result[] = $file->getRealPath();
		}

		return $result;
	}<commit_msg>don't resolve symlinks in filepaths<commit_after><?php
/**
 * The Phile Utility class
 */
namespace Phile\Core;

/**
 * the Registry class for implementing a registry
 *
 * @author  <NAME>
 * @link    https://philecms.com
 * @license http://opensource.org/licenses/MIT
 * @package Phile
 */
class Utility {

	/**
	 * method to get the current http protocoll
	 *
	 * @return string the current protocol
	 */
	public static function getProtocol() {
		if (PHILE_CLI_MODE) {
			return '';
		}
		$protocol = 'http';
		if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ) {
			$protocol = 'https';
		}

		return $protocol;
	}

	/**
	 * detect base url
	 *
	 * @return string
	 */
	public static function getBaseUrl() {
		if (PHILE_CLI_MODE) {
			return '';
		}
		if (Registry::isRegistered('Phile_Settings')) {
			$config = Registry::get('Phile_Settings');
			if (isset($config['base_url']) && $config['base_url']) {
				return $config['base_url'];
			}
		}

		$url         = '';
		$request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '';
		$script_url  = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : '';
		if ($request_url != $script_url) {
			$url = trim(preg_replace('/' . str_replace('/', '\/', str_replace('index.php', '', $script_url)) . '/', '', $request_url, 1), '/');
		}

		$protocol = self::getProtocol();

		return rtrim(str_replace($url, '', $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']), '/');
	}

	/**
	 * detect install path
	 *
	 * @return string
	 */
	public static function getInstallPath() {
		$path = self::getBaseUrl();
		$path = substr($path, strpos($path, '://') + 3);
		$path = substr($path, strpos($path, '/') + 1);

		return $path;
	}

	/**
	 * resolve a file path by replace the mod: prefix
	 *
	 * @param $path
	 *
	 * @return string|null the full filepath or null if file does not exists
	 */
	public static function resolveFilePath($path) {
		// resolve MOD: prefix
		if (strtoupper(substr($path, 0, 3)) === 'MOD') {
			$path = str_ireplace('mod:', PLUGINS_DIR, $path);
		}
		// check if file exists
		if (file_exists($path)) {
			return $path;
		}

		return null;
	}

	/**
	 * load files e.g. config files
	 *
	 * @param $file
	 *
	 * @return mixed|null
	 */
	public static function load($file) {
		if (file_exists($file)) {
			return include $file;
		}

		return null;
	}

	/**
	 * check if a plugin is loaded
	 *
	 * @param $plugin
	 *
	 * @return bool
	 */
	public static function isPluginLoaded($plugin) {
		$config = \Phile\Registry::get('Phile_Settings');
		return (isset($config['plugins'][$plugin]) && isset($config['plugins'][$plugin]['active']) && $config['plugins'][$plugin]['active'] === true);
	}

	/**
	 * static method to get files by directory and file filter
	 *
	 * @param        $directory
	 * @param string $filter
	 *
	 * @return array
	 */
	public static function getFiles($directory, $filter = '\Phile\FilterIterator\GeneralFileFilterIterator') {
		$files  = new $filter(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)));
		$result = array();
		foreach ($files as $file) {
			/** @var \SplFileInfo $file */
			$result[] = $file->getPathname();
		}

		return $result;
	}
{'fraction_non_alphanumeric': 0.18633250311332503, 'fraction_numerical': 0.001556662515566625, 'mean_word_length': 3.4836008374040475, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, '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': '3798056', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2091, 'n_words': 504}