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: $plugin_is_filter = 10 | CLASS_PLUGIN;
29: $plugin_description = gettext("Allows viewers of your site to select the language translation of their choice.");
30: $plugin_author = "Stephen Billard (sbillard)";
31:
32: $option_interface = 'dynamic_locale';
33:
34: zp_register_filter('theme_head', 'dynamic_locale::dynamic_localeJS');
35:
36: if (getOption('dynamic_locale_subdomain')) {
37: define('LOCALE_TYPE', 2);
38: } else if (extensionEnabled('seo_locale') && MOD_REWRITE) {
39: define('LOCALE_TYPE', 1);
40: } else {
41: define('LOCALE_TYPE', 0);
42: }
43:
44: 45: 46: 47: 48:
49: function printLanguageSelector($flags = NULL) {
50: $localeOption = getOption('locale');
51: $languages = generateLanguageList();
52: if (isset($_REQUEST['locale'])) {
53: $locale = sanitize($_REQUEST['locale']);
54: if ($localeOption != $locale) {
55: ?>
56: <div class="errorbox">
57: <h2>
58: <?php printf(gettext('<em>%s</em> is not available.'), html_encode($locale)); ?>
59: <?php printf(gettext('The locale %s is not supported on your server.'), html_encode($locale)); ?>
60: <br />
61: <?php echo gettext('See the troubleshooting guide on zenphoto.org for details.'); ?>
62: </h2>
63: </div>
64: <?php
65: }
66: }
67: if (is_null($flags)) {
68: $flags = getOption('dynamic_locale_visual');
69: }
70: if ($flags) {
71: asort($languages);
72: ?>
73: <ul class="flags">
74: <?php
75: $request = parse_url(getRequestURI());
76: $separator = '?';
77: if (isset($request['query'])) {
78: $query = explode('&', $request['query']);
79: $uri['query'] = '';
80: foreach ($query as $key => $str) {
81: if (preg_match('/^locale\s*=/', $str)) {
82: unset($query[$key]);
83: }
84: }
85: if (empty($query)) {
86: unset($request['query']);
87: } else {
88: $request['query'] = implode('&', $query);
89: $separator = '&';
90: }
91: }
92: $uri = $request['path'];
93: if (isset($request['query']))
94: $uri .= '?' . $request['query'];
95: foreach ($languages as $text => $lang) {
96: ?>
97: <li<?php if ($lang == $localeOption) echo ' class="currentLanguage"'; ?>>
98: <?php
99: switch (LOCALE_TYPE) {
100: case 2:
101: $path = dynamic_locale::fullHostPath($lang) . html_encode($uri);
102: break;
103: case 1:
104: $path = seo_locale::localePath(false, $lang) . str_replace(WEBPATH, '', html_encode($uri));
105: break;
106: default:
107: $path = $uri . $separator . 'locale=' . $lang;
108: break;
109: }
110: $flag = getLanguageFlag($lang);
111: if ($lang != $localeOption) {
112: ?>
113: <a href="<?php echo $path; ?>" >
114: <?php
115: }
116: ?>
117: <img src="<?php echo $flag; ?>" alt="<?php echo $text; ?>" title="<?php echo $text; ?>" />
118: <?php
119: if ($lang != $localeOption) {
120: ?>
121: </a>
122: <?php
123: }
124: ?>
125: </li>
126: <?php
127: }
128: ?>
129: </ul>
130: <?php
131: } else {
132: ?>
133: <form action="#" method="post">
134: <input type="hidden" name="oldlocale" value="<?php echo $localeOption; ?>" />
135: <select id="dynamic-locale" class="languageselect" name="locale" onchange="this.form.submit()">
136: <?php
137: foreach ($languages as $key => $item) {
138: echo '<option class="languageoption" value="' . html_encode($item) . '"';
139: if ($item == $localeOption) {
140: echo ' selected="selected"';
141: }
142: echo ' >';
143: echo html_encode($key) . "</option>\n";
144: }
145: ?>
146: </select>
147: </form>
148: <?php
149: }
150: }
151:
152: class dynamic_locale {
153:
154: function __construct() {
155: setOptionDefault('dynamic_locale_visual', 0);
156: setOptionDefault('dynamic_locale_subdomain', 0);
157: }
158:
159: function getOptionsSupported() {
160: global $_common_locale_type;
161: $localdesc = '<p>' . gettext('If checked links to the alternative languages will be in the form <code><em>language</em>.domain</code> where <code><em>language</em></code> is the language code, e.g. <code><em>fr</em></code> for French.') . '</p>';
162: if (!$_common_locale_type) {
163: $localdesc .= '<p>' . gettext('This requires that you have created the appropriate subdomains pointing to your Zenphoto installation. That is <code>fr.mydomain.com/zenphoto/</code> must point to the same location as <code>mydomain.com/zenphoto/</code>. (Some providers will automatically redirect undefined subdomains to the main domain. If your provider does this, no subdomain creation is needed.)') . '</p>';
164: }
165: $options = array(gettext('Use flags') => array('key' => 'dynamic_locale_visual', 'type' => OPTION_TYPE_CHECKBOX,
166: 'order' => 0,
167: 'desc' => gettext('Checked produces an array of flags. Not checked produces a selector.')),
168: gettext('Use subdomains') . '*' => array('key' => 'dynamic_locale_subdomain', 'type' => OPTION_TYPE_CHECKBOX,
169: 'order' => 1,
170: 'disabled' => $_common_locale_type,
171: 'desc' => $localdesc)
172: );
173: if ($_common_locale_type) {
174: $options['note'] = array('key' => 'dynamic_locale_type', 'type' => OPTION_TYPE_NOTE,
175: 'order' => 2,
176: 'desc' => '<p class="notebox">' . $_common_locale_type . '</p>');
177: } else {
178: $_common_locale_type = gettext('* This option may be set via the <a onclick="gotoName(\'dynamic-locale\');"><em>dynamic-locale</em></a> plugin options.');
179: $options['note'] = array('key' => 'dynamic_locale_type',
180: 'type' => OPTION_TYPE_NOTE,
181: 'order' => 2,
182: 'desc' => gettext('<p class="notebox">*<strong>Note:</strong> The setting of this option is shared with other plugins.</p>'));
183: }
184: return $options;
185: }
186:
187: static function dynamic_localeJS() {
188: ?>
189: <link type="text/css" rel="stylesheet" href="<?php echo WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER; ?>/dynamic-locale/locale.css" />
190: <?php
191: }
192:
193: static function fullHostPath($lang) {
194: global $_locale_Subdomains;
195: $host = $_SERVER['HTTP_HOST'];
196: $matches = explode('.', $host);
197: if (validateLocale($matches[0], 'Dynamic Locale')) {
198: array_shift($matches);
199: $host = implode('.', $matches);
200: }
201: if ($l = $_locale_Subdomains[$lang]) {
202: $host = $l . '.' . $host;
203: }
204: if (SERVER_PROTOCOL == 'https') {
205: $host = 'https://' . $host;
206: } else {
207: $host = 'http://' . $host;
208: }
209: return $host;
210: }
211:
212: }
213: ?>
214: