Beispiel #1
0
	function filter($url, array $params = null) {
		$this->_rivety_plugin = RivetyCore_Plugin::getInstance();
		$out_url = $url;

		// LOCALIZATION
		if (RivetyCore_Registry::get('enable_localization') == '1') {
			if (stripos($url, "/") === 0) {
				// for virtual URLs
				$locale_code = $params['locale_code'];
				if (!is_null($locale_code)) {
					// localize the URL by injecting the locale code at the root
					if (RivetyCore_Translate::validateLocaleCode($locale_code)) {
						$out_url = "/".$locale_code.$url;
					}
				}
			} else {
				// TODO - add other cases, such as absolute and relative URLs
			}
		}

		// SSL
		if (RivetyCore_Registry::get('enable_ssl') == '1') {
			$secure_urls = RivetyCore_Registry::get('secure_urls');
			if (!empty($secure_urls)) {
				$secure_urls = explode('|', $secure_urls);
				if (stripos($url, "/") === 0) {
					// for virtual URLs
					// $tmp_url = '/'.trim('/', $url); // get rid of the last slash
					if (in_array($url, $secure_urls)) {
						$out_url = str_replace('http://', 'https://', RivetyCore_Registry::get('site_url').$out_url);
					} 
				} else {
					// TODO - add other cases, such as absolute and relative URLs
				}
			}
		}

		// FORCE ABSOLUTE URL
		if (array_key_exists('absolute', $params) || in_array('absolute', $params)) {
			if (stripos($url, "/") === 0) {
				$out_url = RivetyCore_Registry::get('site_url').$out_url;
			} else {
				$out_url = RivetyCore_Registry::get('site_url').'/'.$out_url;
			}
		}
		$params = array('url' => $out_url);
		$params = $this->_rivety_plugin->doFilter('url_post_filter', $params); // FILTER HOOK
		return $params['url'];
	}
Beispiel #2
0
function smarty_block_url($params, $content, $smarty, $repeat) {
	$tpl_vars = $smarty->_tpl_vars;
    // only output on the closing tag
    if (!$repeat) {
        if (isset($content)) {
			$urlparams = array();
			$locale_code = $tpl_vars['locale_code'];
			$request_locale = $tpl_vars['request_locale'];
			if($request_locale && $locale_code != $request_locale) {
				$urlparams['locale_code'] = strtolower($request_locale);
			} elseif (!is_null($locale_code) && RivetyCore_Translate::validateLocaleCode($locale_code)) {
				$urlparams['locale_code'] = strtolower($locale_code);
			}
			$url_filter = new RivetyCore_Url_Filter();
			return $url_filter->filter($content, $urlparams);
		}
	}
}
Beispiel #3
0
	function setcookieAction() {
		// TODO maybe? - prevent people from viewing this page if localization is not enabled
		$request = new RivetyCore_Request($this->getRequest());
		if ($request->has("code") && $request->code != "") {
			$locale_code = $request->code;
			$time = RivetyCore_Registry::get('locale_cache_lifetime');
			if (RivetyCore_Translate::validateLocaleCode($locale_code)) {
				setcookie("locale_code", $locale_code, time() + $time , "/");
				if ($request->has("return_url")) {
					$url_filter = new RivetyCore_Url_Filter();
					header("Location: ".$url_filter->filter($request->return_url, array('locale_code' => $locale_code)));
				} else {
					header("Location: /".$locale_code);
				}
			}
		} else {
			$this->_redirect("/default/locale/choose/");
		}
	}