[go: up one dir, main page]

Menu

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

Download this file

98 lines (96 with data), 2.3 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
<?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 'es':
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="es"';
if ($lang == 'es')
{
print ' selected="1"';
}
print '>Español</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);
?>