<commit_before><?php
/**
 * URL rewriting functions
 *
 * @package urleditor
 * @version 0.9.0
 * @author Trustmaster
 * @copyright Copyright (c) Cotonti Team 2008-2011
 * @license BSD
 */

defined('COT_CODE') or die('Wrong URL');

require_once cot_langfile('urleditor', 'plug');

/**
 * Applies Handly URLs rewrite to current script parameters
 * @global array $cfg 
 */
function cot_apply_rwr()
{
	global $cfg, $structure;
	if (isset($_GET['rwr']) && !empty($_GET['rwr']) && preg_match('`^[\w\p{L}/\-_]+?$`u', $_GET['rwr']))
	{
		// Ignore ending slash and split the path into parts
		$path = explode('/', (mb_strrpos($_GET['rwr'], '/') == mb_strlen($_GET['rwr']) - 1) ? mb_substr($_GET['rwr'], 0, -1) : $_GET['rwr']);
		$count = count($path);
		
		if ($count == 1)
		{
			if (isset($structure['page'][$path[0]]))
			{
				// Is a category
				$_GET['e'] = 'page';
				$_GET['c'] = $path[0];
			}
			elseif (file_exists($cfg['modules_dir'] . '/' . $path[0]) || file_exists($cfg['plugins_dir'] . '/' . $path[0]))
			{
				// Is an extension
				$_GET['e'] = $path[0];
			}
			else
			{
				// Maybe it is a system page, if not 404 will be given
				$_GET['e'] = 'page';
				$_GET['c'] = 'system';
				$_GET['al'] = $path[0];
			}
		}
		else
		{
			// Special shortcut for user profiles
			if ($path[0] == 'users' && $count == 2 && !isset($_GET['m']))
			{
				$_GET['e'] = 'users';
				$_GET['m'] = 'details';
				$_GET['u'] = $path[1];
				return;
			}
			$last = $count - 1;
			$ext = (isset($structure['page'][$path[0]])) ? 'page' : $path[0];
			$_GET['e'] = $ext;
			if (isset($structure[$ext][$path[$last]]))
			{
				// Is a category
				$_GET['c'] = $path[$last];
			}
			else
			{
				// Is a page/item
				if ($ext == 'page' || $count > 2)
				{
					$_GET['c'] = $path[$last - 1];
				}
				if (is_numeric($path[$last]))
				{
					$_GET['id'] = $path[$last];
				}
				else
				{
					$_GET['al'] = $path[$last];
				}
			}
		}
	}
}<commit_msg>Added support for spaces and special characters in SEF URLs aliases.<commit_after><?php
/**
 * URL rewriting functions
 *
 * @package urleditor
 * @version 0.9.0
 * @author Trustmaster
 * @copyright Copyright (c) Cotonti Team 2008-2011
 * @license BSD
 */

defined('COT_CODE') or die('Wrong URL');

require_once cot_langfile('urleditor', 'plug');

/**
 * Applies Handly URLs rewrite to current script parameters
 * @global array $cfg 
 */
function cot_apply_rwr()
{
	global $cfg, $structure;
	if (isset($_GET['rwr']) && !empty($_GET['rwr']) && preg_match('`^[\w\p{L}/\-_\ \+]+?$`u', $_GET['rwr']))
	{
		// Ignore ending slash and split the path into parts
		$path = explode('/', (mb_strrpos($_GET['rwr'], '/') == mb_strlen($_GET['rwr']) - 1) ? mb_substr($_GET['rwr'], 0, -1) : $_GET['rwr']);
		$count = count($path);
		
		if ($count == 1)
		{
			if (isset($structure['page'][$path[0]]))
			{
				// Is a category
				$_GET['e'] = 'page';
				$_GET['c'] = $path[0];
			}
			elseif (file_exists($cfg['modules_dir'] . '/' . $path[0]) || file_exists($cfg['plugins_dir'] . '/' . $path[0]))
			{
				// Is an extension
				$_GET['e'] = $path[0];
			}
			else
			{
				// Maybe it is a system page, if not 404 will be given
				$_GET['e'] = 'page';
				$_GET['c'] = 'system';
				$_GET['al'] = urldecode($path[0]);
			}
		}
		else
		{
			// Special shortcut for user profiles
			if ($path[0] == 'users' && $count == 2 && !isset($_GET['m']))
			{
				$_GET['e'] = 'users';
				$_GET['m'] = 'details';
				$_GET['u'] = urldecode($path[1]);
				return;
			}
			$last = $count - 1;
			$ext = (isset($structure['page'][$path[0]])) ? 'page' : $path[0];
			$_GET['e'] = $ext;
			if (isset($structure[$ext][$path[$last]]))
			{
				// Is a category
				$_GET['c'] = $path[$last];
			}
			else
			{
				// Is a page/item
				if ($ext == 'page' || $count > 2)
				{
					$_GET['c'] = $path[$last - 1];
				}
				if (is_numeric($path[$last]))
				{
					$_GET['id'] = $path[$last];
				}
				else
				{
					$_GET['al'] = urldecode($path[$last]);
				}
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.24225774225774227, 'fraction_numerical': 0.015984015984015984, 'mean_word_length': 2.869565217391304, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7580388', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1534, 'n_words': 333}