[go: up one dir, main page]

Menu

[451024]: / Help / index.php  Maximize  Restore  History

Download this file

126 lines (124 with data), 3.1 kB

  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
<?php
/* index.php for ROXTerm. Adds a language selection menu to the online version
* of the web pages.
* Copyright (c) 2010 Tony Houghton <h@realh.co.uk>.
* Licence: GPL v3 or later.
* This script is for uploading to the project web pages,
* not for distribution with the package.
*/
function make_filename($lang, $page)
{
return str_replace('index.php', "$lang/$page.html",
$_SERVER['SCRIPT_FILENAME']);
}
if (isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 'index';
}
if (isset($_GET['lang']))
{
$lang = $_GET['lang'];
setcookie('roxterm_lang', $lang);
}
elseif (isset($_COOKIE['roxterm_lang']))
{
$lang = $_COOKIE['roxterm_lang'];
}
else
{
$lang = 'en';
}
switch ($page)
{
case 'guide':
case 'index':
case 'installation':
case 'news':
break;
default:
$page = 'index';
}
switch ($lang)
{
case 'en':
case 'pt_BR':
case 'fr':
case 'es':
case 'ru':
case 'uk':
break;
default:
$lang = 'en';
}
$filename = make_filename($lang, $page);
$file = fopen($filename, 'r');
if (!$file)
{
/* Redirect should cause a generic 404 */
header('Location: http://' . $_SERVER['HTTP_HOST'] . '/' .
dirname($_SERVER['PHP_SELF']) . "/$lang/$page.html");
exit();
}
while (!feof($file))
{
$line = fgets($file);
$line = str_replace('../lib/' , 'lib/', $line);
$line = preg_replace('/href="(guide|index|installation|news)\.html"/',
"href=\"index.php?page=\\1&lang=$lang\"", $line);
if (trim($line) == '<!-- PHP PLACEHOLDER -->')
{
print '<form id="LangForm" method="GET" action="http://' .
$_SERVER['HTTP_HOST'] . '/' . $_SERVER['PHP_SELF'] . '">';
print '<select name="lang" >;
print '<option value="en"';
if ($lang == 'en')
{
print ' selected="1"';
}
print '>English</option>';
print '<option value="pt_BR"';
if ($lang == 'pt_BR')
{
print ' selected="1"';
}
print '>Português (Brasil)</option>';
print '<option value="es"';
if ($lang == 'es')
{
print ' selected="1"';
}
print '>Español</option>';
print '<option value="fr"';
if ($lang == 'fr')
{
print ' selected="1"';
}
print '>Français</option>';
print '<option value="ru"';
if ($lang == 'ru')
{
print ' selected="1"';
}
print '>Русский</option>';
print '<option value="uk"';
if ($lang == 'uk')
{
print ' selected="1"';
}
print '>Український</option>';
print '</select>';
print '<noscript><button id="LangButton">&#187;</button></noscript>';
print '<input type="hidden" name="page" value="' . $page . '"/>';
print "</form>\n";
}
else
{
print $line;
}
}
fclose($file);
?>