<commit_before><?php
/**
 * @date Thu Feb 01 21:15:12 CET 2007
 * @author INTbonjF
 */
class website_RewriteUrlAction extends f_action_BaseAction
{
	/**
	 * @param Context $context
	 * @param Request $request
	 */
	public function _execute($context, $request)
    {
    	$requestedUrl = $request->getParameter(K::URL_REWRITE_PAGE_NAME_ACCESSOR);
    	
    	// TODO: enhance. Remove parameters from get for future URL (re)generation "from scratch"
    	$request->removeParameter(K::URL_REWRITE_PAGE_NAME_ACCESSOR);
    	$request->removeParameter('module');
    	$request->removeParameter('action');
    	
    	unset($_GET[K::URL_REWRITE_PAGE_NAME_ACCESSOR]);
    	unset($_GET["module"]);
    	unset($_GET["action"]);
   
		if ($requestedUrl{0} !== '/')
		{
			$requestedUrl = '/' . $requestedUrl;
		}		
		$wsms = website_WebsiteModuleService::getInstance();
		$websiteInfo  = $wsms->getWebsiteInfos($_SERVER['HTTP_HOST']);
		if ($websiteInfo === null)
		{
			Framework::error("WEBSITE not found for host : " . $_SERVER['HTTP_HOST']);
			return View::NONE;
		}
		
		$rc = RequestContext::getInstance();
		$lang = null;
		
		if ($websiteInfo['localizebypath'])
		{
			$pattern = '/^\/('. implode('|', $websiteInfo['langs']) .')\//';
			$matches = array();
			if (preg_match($pattern, $requestedUrl, $matches))
			{
			    $lang = $matches[1];
			    $requestedUrl = str_replace($matches[0], '/', $requestedUrl);
			}
		}
		
		if ($lang === null) { $lang = $websiteInfo['langs'][0]; }
		$rc->setLang($lang);		
		$wsms->setCurrentWebsiteId($websiteInfo['id']);
		
		if ('/' == $requestedUrl)
		{
		    $context->getController()->forward(AG_DEFAULT_MODULE, AG_DEFAULT_ACTION);
    	    return View::NONE;
		}
	
		$urlService = website_UrlRewritingService::getInstance();
		$rule = $urlService->getRuleByUrl($requestedUrl);
		if ($rule instanceof website_lib_urlrewriting_Rule)
		{
			$urlService->redirect($rule, $context->getController());
			return View::NONE;
		}<commit_msg>[FIX #6734] Non prise en compte de /fr quand /fr/ [FIX #6724] Duplicate content sur localisation par chemin<commit_after><?php
/**
 * @date Thu Feb 01 21:15:12 CET 2007
 * @author INTbonjF
 */
class website_RewriteUrlAction extends f_action_BaseAction
{
	/**
	 * @param Context $context
	 * @param Request $request
	 */
	public function _execute($context, $request)
    {
    	$requestedUrl = $request->getParameter(K::URL_REWRITE_PAGE_NAME_ACCESSOR);
    	
    	// TODO: enhance. Remove parameters from get for future URL (re)generation "from scratch"
    	$request->removeParameter(K::URL_REWRITE_PAGE_NAME_ACCESSOR);
    	$request->removeParameter('module');
    	$request->removeParameter('action');
    	
    	unset($_GET[K::URL_REWRITE_PAGE_NAME_ACCESSOR]);
    	unset($_GET["module"]);
    	unset($_GET["action"]);
   
		if ($requestedUrl{0} !== '/')
		{
			$requestedUrl = '/' . $requestedUrl;
		}		
		$wsms = website_WebsiteModuleService::getInstance();
		$websiteInfo  = $wsms->getWebsiteInfos($_SERVER['HTTP_HOST']);
		if ($websiteInfo === null)
		{
			Framework::error("WEBSITE not found for host : " . $_SERVER['HTTP_HOST']);
			return View::NONE;
		}
		
		$rc = RequestContext::getInstance();
		$lang = null;
		
		if ($websiteInfo['localizebypath'])
		{
			$pattern = '/^\/('. implode('|', $websiteInfo['langs']) .')\//';
			$matches = array();
		 	if ($requestedUrl === '/'.$websiteInfo['langs'][0].'/')
			{
				 $context->getController()->redirectToUrl('/');
			}
			elseif (preg_match($pattern, $requestedUrl, $matches))
			{
			    $lang = $matches[1];
			    $requestedUrl = str_replace($matches[0], '/', $requestedUrl);
			    $websiteInfo['langs'][0];
			}
			elseif (preg_match('/^\/('. implode('|', $websiteInfo['langs']) .')$/', $requestedUrl, $matches))
			{
				$lang = $matches[1];
				if ($lang === $websiteInfo['langs'][0])
				{
					$context->getController()->redirectToUrl('/');
				}
				else
				{
					$context->getController()->redirectToUrl($requestedUrl.'/');
				}
				return View::NONE;
			}
		}
		
		if ($lang === null) { $lang = $websiteInfo['langs'][0]; }
		$rc->setLang($lang);		
		$wsms->setCurrentWebsiteId($websiteInfo['id']);
		
		if ('/' == $requestedUrl)
		{
		    $context->getController()->forward(AG_DEFAULT_MODULE, AG_DEFAULT_ACTION);
    	    return View::NONE;
		}
	
		$urlService = website_UrlRewritingService::getInstance();
		$rule = $urlService->getRuleByUrl($requestedUrl);
		if ($rule instanceof website_lib_urlrewriting_Rule)
		{
			$urlService->redirect($rule, $context->getController());
			return View::NONE;
		}
{'fraction_non_alphanumeric': 0.18369589101296419, 'fraction_numerical': 0.00966820479015601, 'mean_word_length': 3.921081081081081, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '6795313', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1514, 'n_words': 254}