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: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214:
<?php
$plugin_is_filter = 10 | CLASS_PLUGIN;
$plugin_description = gettext("Allows viewers of your site to select the language translation of their choice.");
$plugin_author = "Stephen Billard (sbillard)";
$plugin_category = gettext('SEO');
$option_interface = 'dynamic_locale';
zp_register_filter('theme_head', 'dynamic_locale::dynamic_localeJS');
if (getOption('dynamic_locale_subdomain')) {
define('LOCALE_TYPE', 2);
} else if (extensionEnabled('seo_locale') && MOD_REWRITE) {
define('LOCALE_TYPE', 1);
} else {
define('LOCALE_TYPE', 0);
}
function printLanguageSelector($flags = NULL) {
$localeOption = getOption('locale');
$languages = generateLanguageList();
if (isset($_REQUEST['locale'])) {
$locale = sanitize($_REQUEST['locale']);
if ($localeOption != $locale) {
?>
<div class="errorbox">
<h2>
<?php printf(gettext('<em>%s</em> is not available.'), html_encode($locale)); ?>
<?php printf(gettext('The locale %s is not supported on your server.'), html_encode($locale)); ?>
<br />
<?php echo gettext('See the troubleshooting guide on zenphoto.org for details.'); ?>
</h2>
</div>
<?php
}
}
if (is_null($flags)) {
$flags = getOption('dynamic_locale_visual');
}
if ($flags) {
asort($languages);
?>
<ul class="flags">
<?php
$request = parse_url(getRequestURI());
$separator = '?';
if (isset($request['query'])) {
$query = explode('&', $request['query']);
$uri['query'] = '';
foreach ($query as $key => $str) {
if (preg_match('/^locale\s*=/', $str)) {
unset($query[$key]);
}
}
if (empty($query)) {
unset($request['query']);
} else {
$request['query'] = implode('&', $query);
$separator = '&';
}
}
$uri = $request['path'];
if (isset($request['query']))
$uri .= '?' . $request['query'];
foreach ($languages as $text => $lang) {
?>
<li<?php if ($lang == $localeOption) echo ' class="currentLanguage"'; ?>>
<?php
switch (LOCALE_TYPE) {
case 2:
$path = dynamic_locale::fullHostPath($lang) . $uri;
break;
case 1:
$path = seo_locale::localePath(false, $lang) . str_replace(WEBPATH, '', $uri);
break;
default:
$path = $uri . $separator . 'locale=' . $lang;
break;
}
$flag = getLanguageFlag($lang);
if ($lang != $localeOption) {
?>
<a href="<?php echo html_encode($path); ?>" >
<?php
}
?>
<img src="<?php echo $flag; ?>" alt="<?php echo $text; ?>" title="<?php echo $text; ?>" />
<?php
if ($lang != $localeOption) {
?>
</a>
<?php
}
?>
</li>
<?php
}
?>
</ul>
<?php
} else {
?>
<form action="#" method="post">
<input type="hidden" name="oldlocale" value="<?php echo $localeOption; ?>" />
<select id="dynamic-locale" class="languageselect" name="locale" onchange="this.form.submit()">
<?php
foreach ($languages as $key => $item) {
echo '<option class="languageoption" value="' . html_encode($item) . '"';
if ($item == $localeOption) {
echo ' selected="selected"';
}
echo ' >';
echo html_encode($key) . "</option>\n";
}
?>
</select>
</form>
<?php
}
}
class dynamic_locale {
function __construct() {
setOptionDefault('dynamic_locale_visual', 0);
setOptionDefault('dynamic_locale_subdomain', 0);
}
function getOptionsSupported() {
global $_common_locale_type;
$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>';
if (!$_common_locale_type) {
$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>';
}
$options = array(gettext('Use flags') => array('key' => 'dynamic_locale_visual', 'type' => OPTION_TYPE_CHECKBOX,
'order' => 0,
'desc' => gettext('Checked produces an array of flags. Not checked produces a selector.')),
gettext('Use subdomains') . '*' => array('key' => 'dynamic_locale_subdomain', 'type' => OPTION_TYPE_CHECKBOX,
'order' => 1,
'disabled' => $_common_locale_type,
'desc' => $localdesc)
);
if ($_common_locale_type) {
$options['note'] = array('key' => 'dynamic_locale_type', 'type' => OPTION_TYPE_NOTE,
'order' => 2,
'desc' => '<p class="notebox">' . $_common_locale_type . '</p>');
} else {
$_common_locale_type = gettext('* This option may be set via the <a onclick="gotoName(\'dynamic-locale\');"><em>dynamic-locale</em></a> plugin options.');
$options['note'] = array('key' => 'dynamic_locale_type',
'type' => OPTION_TYPE_NOTE,
'order' => 2,
'desc' => gettext('<p class="notebox">*<strong>Note:</strong> The setting of this option is shared with other plugins.</p>'));
}
return $options;
}
static function dynamic_localeJS() {
?>
<link type="text/css" rel="stylesheet" href="<?php echo WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER; ?>/dynamic-locale/locale.css" />
<?php
}
static function fullHostPath($lang) {
global $_locale_Subdomains;
$host = $_SERVER['HTTP_HOST'];
$matches = explode('.', $host);
if (validateLocale($matches[0], 'Dynamic Locale')) {
array_shift($matches);
$host = implode('.', $matches);
}
if ($l = $_locale_Subdomains[$lang]) {
$host = $l . '.' . $host;
}
if (SERVER_PROTOCOL == 'https') {
$host = 'https://' . $host;
} else {
$host = 'http://' . $host;
}
return $host;
}
}
?>