1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100:
<?php
$plugin_is_filter = 5 | CLASS_PLUGIN;
$plugin_description = gettext("Allows setting language locale through the URI.");
$plugin_notice = gettext('<strong>Note:</strong> This plugin is not activated for <em>back‑end</em> (administrative) URLs. However, once activated, the language is remembered, even for the <em>back‑end</em>.');
$plugin_author = "Stephen Billard (sbillard)";
$plugin_disable = ((!MOD_REWRITE) ? gettext('<em>mod_rewrite</em> must be enabled for this plugin to function.') : (getOption('dynamic_locale_subdomain') && extensionEnabled('dynamic-locale'))) ? gettext('This plugin is not compatible with the <code>dynamic locale</code> <em>Use subdomains</em> option') : false;
$plugin_category = gettext('SEO');
if ($plugin_disable) {
enableExtension('seo_locale', 0);
} else {
zp_register_filter('load_request', 'seo_locale::load_request');
if (!defined('SEO_WEBPATH')) {
define('SEO_WEBPATH', seo_locale::localePath());
define('SEO_FULLWEBPATH', seo_locale::localePath(true));
}
}
class seo_locale {
static function load_request($allow) {
$uri = getRequestURI();
$parts = explode('?', $uri);
$uri = $parts[0];
$path = ltrim(substr($uri, strlen(WEBPATH) + 1), '/');
if (empty($path)) {
return $allow;
} else {
$rest = strpos($path, '/');
if ($rest === false) {
if (strpos($path, '?') === 0) {
return $allow;
}
$l = $path;
} else {
$l = substr($path, 0, $rest);
}
}
$locale = validateLocale($l, 'seo_locale');
if ($locale) {
zp_setCookie('dynamic_locale', $locale);
$uri = pathurlencode(preg_replace('|/' . $l . '[/$]|', '/', $uri));
if (isset($parts[1])) {
$uri .= '?' . $parts[1];
}
redirectURL($uri, '302');
}
return $allow;
}
static function localePath($full = false, $loc = NULL) {
global $_zp_page, $_zp_gallery_page;
if ($full) {
$path = FULLWEBPATH;
} else {
$path = WEBPATH;
}
if ($locale = getLanguageText($loc)) {
$path .= '/' . $locale;
}
return $path;
}
}
?>