1: <?php
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: $plugin_is_filter = 5 | CLASS_PLUGIN;
35: $plugin_description = gettext("Allows setting language locale through the URI.");
36: $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>.');
37: $plugin_author = "Stephen Billard (sbillard)";
38: $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;
39:
40: if ($plugin_disable) {
41: enableExtension('seo_locale', 0);
42: } else {
43: zp_register_filter('load_request', 'seo_locale::load_request');
44: if (!defined('SEO_WEBPATH')) {
45: define('SEO_WEBPATH', seo_locale::localePath());
46: define('SEO_FULLWEBPATH', seo_locale::localePath(true));
47: }
48: }
49:
50: class seo_locale {
51:
52: static function load_request($allow) {
53: $uri = getRequestURI();
54: $parts = explode('?', $uri);
55: $uri = $parts[0];
56: $path = ltrim(substr($uri, strlen(WEBPATH) + 1), '/');
57: if (empty($path)) {
58: return $allow;
59: } else {
60: $rest = strpos($path, '/');
61: if ($rest === false) {
62: if (strpos($path, '?') === 0) {
63:
64: return $allow;
65: }
66: $l = $path;
67: } else {
68: $l = substr($path, 0, $rest);
69: }
70: }
71: $locale = validateLocale($l, 'seo_locale');
72: if ($locale) {
73:
74: zp_setCookie('dynamic_locale', $locale);
75: $uri = pathurlencode(preg_replace('|/' . $l . '[/$]|', '/', $uri));
76: if (isset($parts[1])) {
77: $uri .= '?' . $parts[1];
78: }
79: header("HTTP/1.0 302 Found");
80: header("Status: 302 Found");
81: header('Location: ' . $uri);
82: exitZP();
83: }
84: return $allow;
85: }
86:
87: static function localePath($full = false, $loc = NULL) {
88: global $_zp_page, $_zp_gallery_page;
89: if ($full) {
90: $path = FULLWEBPATH;
91: } else {
92: $path = WEBPATH;
93: }
94: if ($locale = zpFunctions::getLanguageText($loc)) {
95: $path .= '/' . $locale;
96: }
97: return $path;
98: }
99:
100: }
101:
102: ?>