forked from Gnucash/gnucash-htdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewdoc.phtml
185 lines (167 loc) · 5.95 KB
/
viewdoc.phtml
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
<?php
# Determine which documentation to show based on 3 parameters:
# - language (lang)
# - help or guide (doc)
# - doc version (rev)
include("lang.php");
// Fixme: It is not trivial to reorder the components to get proper metatags
$title = T_("View document");
$page = basename($_SERVER['SCRIPT_NAME']);
include("externals/header.phtml");
include("externals/menu.phtml");
# Some base parameters used later on
# The helpdoc path applies to the 5.0 branch and is adjusted for
# earlier versions below.
$basepath = \DEFAULT_URL."docs";
$helpdoc = "gnucash-manual/index.html";
$tcdoc = "gnucash-guide/index.html";
$current_stable = $major_stable;
# Show current stable helpdoc, in overall set language by default
$showdoc = $tcdoc;
$req_doc_ok = true;
$showrev = $current_stable;
$req_rev_ok = true;
$showlang = 'C';
$doc_languages = array('de', 'it', 'ja', 'pt', 'zh');
$get_lang = filter_input(INPUT_GET, 'lang', FILTER_SANITIZE_STRING);
if (in_array($get_lang, $doc_languages, true)) {
$showlang = $get_lang;
} elseif ($locale) {
$showlang = $locale;
}
# Parse requested version
$rev_to_show = filter_input(INPUT_GET, 'rev', FILTER_SANITIZE_STRING);
if ($rev_to_show) {
switch ($rev_to_show) {
case "1.8":
$showrev = "1.8";
break;
case "2.0":
$showrev = "2.0";
break;
case "2.2":
$showrev = "2.2";
break;
case "2.4":
$showrev = "2.4";
break;
case "2.6":
$showrev = "2.6";
break;
case "3":
$showrev = "3";
break;
case "4":
$showrev = "4";
break;
case "5":
$showrev = "5";
break;
case "current":
$showrev = $current_stable;
break;
case "maint":
$showrev = "maint";
break;
case "nightly":
$showrev = "maint";
break;
default: /* unknown version requested, will current stable by default */
$req_rev_ok = false;
break;
}
# Adjust name of gnucash-manual start page for older versions
switch ($rev_to_show) {
case "1.8":
case "2.0":
case "2.2":
case "2.4":
case "2.6":
case "3":
$helpdoc = "gnucash-help/help.html";
break;
case "4":
$helpdoc = "gnucash-help/index.html";
break;
}
}
# Parse requested document
$doc_to_show = filter_input(INPUT_GET, 'doc', FILTER_SANITIZE_STRING);
if ($doc_to_show) {
switch ($doc_to_show) {
case "help":
$showdoc = $helpdoc;
break;
case "guide":
$showdoc = $tcdoc;
break;
default: /* unknown document requested, will present guide by default */
$req_doc_ok = false;
break;
}
}
# Now check if the requested combination of doc, revision and language actually exists
# If not, try the default C locale instead.
# Web locales may have a country code but the documentation doesn't at the moment
# So test both the full locale and the version stripped down to language code only.
if (strpos($showlang, "_")) {
list($shortlang,$rest) = explode ("_", $showlang);
} else {
$shortlang = $showlang;
}
$reqlangs = array ($showlang);
# First evaluate the nightly builds, they are located on a different server
# To avoid network traffic, the available languages are hard-coded here and should be
# updated if list of languages in which the documentation is available changes
if ($showrev == "maint") {
$req_lang_ok = false;
$basepath = "https://lists.gnucash.org/docs";
$trunk_langs = array ( $helpdoc => array( "C", "de", "it", "pt"),
$tcdoc => array( "C", "de", "it", "ja", "pt", "zh"));
if (in_array ($showlang, $trunk_langs[$showdoc])) {
$req_lang_ok = true;
}
else if (in_array ($shortlang, $trunk_langs[$showdoc])) {
$req_lang_ok = true;
$showlang = $shortlang;
array_push ($reqlangs, $showlang);
} else {
$showlang = "C";
}
$showurl=$basepath."/".$showlang."/".$showdoc;
} else {
# For the stable versions, we can simply check file availability because we're
# on the same server
$req_lang_ok = true;
$checkpath="docs/v".$showrev."/".$showlang."/".$showdoc;
if (!file_exists ($checkpath)) {
# Try Lang only codes
$showlang = $shortlang;
array_push ($reqlangs, $showlang);
if ($showlang == "en") $showlang = "C";
$checkpath="docs/v".$showrev."/".$showlang."/".$showdoc;
if (!file_exists ($checkpath)) {
$showlang = "C";
$req_lang_ok = false;
}
}
$showurl=$basepath."/v".$showrev."/".$showlang."/".$showdoc;
}
?>
<div id="content">
<?php if (! $req_doc_ok ) { ?>
<p style="color: red;"><?= T_("The document requested is not available. The tutorial and concepts guide will be displayed instead.")?></p>
<?php } ?>
<?php if (! $req_rev_ok ) {?>
<p style="color: red;"><?php printf (T_("The document requested is not available for version %s. Version %s will be displayed instead."),
$rev_to_show, $showrev); ?></p>
<?php } ?>
<?php if (! $req_lang_ok ) { ?>
<p style="color: red;"><?php printf (T_("The document requested is not available in the requested language (tried [%s]). The English version will be displayed instead."),
join(",", $reqlangs)); ?></p>
<?php } ?>
<iframe src="<?php echo $showurl; ?>" style="border-width: 0px; width: 100%; min-width: 700px; height: 80em;">
<?php printf (T_("It seems your browser doesn't support iframes. To view the requested page in a separate window, please <a href=\"%s\" target=\"_blank\">click here</a>."), $showurl); ?>
</iframe>
</div>
<?php include("externals/footer.phtml"); ?>