xref: /web-php/my.php (revision cdf59074)
1<?php
2
3use phpweb\I18n\Languages;
4use phpweb\UserPreferences;
5
6$_SERVER['BASE_PAGE'] = 'my.php';
7include_once __DIR__ . '/include/prepend.inc';
8
9// Try to make this page non-cached
10header_nocache();
11
12// Languages array copy and options to list
13$langs = Languages::ACTIVE_ONLINE_LANGUAGES;
14$options = [];
15
16// We have post data, and it is an available language
17if (isset($_POST['my_lang'], $langs[$_POST['my_lang']])) {
18
19    // Set the language preference
20    $userPreferences->languageCode = $_POST['my_lang'];
21
22    // Add this as first option, selected
23    $options[] = '<option value="' . $_POST['my_lang'] . '" selected>' .
24                 $langs[$_POST['my_lang']] . "</option>\n";
25
26    // Remove, so it is not listed two times
27    unset($langs[$_POST['my_lang']]);
28}
29
30// We have received a cookie and it is an available language
31elseif (isset($langs[$userPreferences->languageCode])) {
32
33    // Add this as first option, selected
34    $options[] = '<option value="' . $userPreferences->languageCode . '" selected>' .
35                 $langs[$userPreferences->languageCode] . "</option>\n";
36
37    // Remove, so it is not listed two times
38    unset($langs[$userPreferences->languageCode]);
39}
40
41// We have no cookie and no form submitted
42else {
43    // Add this as first option, selected
44    $options[] = "<option value=\"not_set\" selected=\"selected\">Not Set</option>\n";
45}
46
47// Add all other languages
48foreach ($langs as $code => $name) {
49    $options[] = '<option value="' . $code . '">' . $name . "</option>\n";
50}
51
52// Assemble form from collected data
53$langpref = "<select id=\"form-my_lang\" name=\"my_lang\">\n" .
54            implode("", $options) . "</select>\n";
55
56// Save URL shortcut fallback setting
57if (isset($_POST['urlsearch'])) {
58    $userPreferences->setUrlSearchType($_POST['urlsearch']);
59}
60
61if (isset($_POST["showug"])) {
62    $userPreferences->setIsUserGroupTipsEnabled($_POST["showug"] === "enable");
63}
64
65// Prepare mirror array
66$mirror_sites = $MIRRORS;
67$mirror_sites["NONE"] = [7 => MIRROR_OK];
68
69$userPreferences->save();
70
71site_header("My PHP.net", ["current" => "community"]);
72?>
73
74<form action="/my.php" method="post">
75<h1>My PHP.net</h1>
76
77<p>
78 This page allows you to customize the PHP.net site.
79</p>
80
81<?php if (!is_official_mirror()) { ?>
82<p class="warn">
83 This is not an official PHP.net mirror site, and therefore the settings
84 you set and see here will <strong>not</strong> be effective on any
85 official PHP.net mirror site. The settings you specify here are only
86 going to be active for this URL, and only if you have cookies enabled.
87</p>
88<?php } else { ?>
89<p>
90 These settings are cookie-based and will work on all official PHP.net
91 mirror sites.
92</p>
93<?php } ?>
94
95<h2>Preferred language</h2>
96
97<p>
98 If you use a shortcut or search for a function, the language used
99 is determined by checking for the following settings. The list is
100 in priority order, the first is the most important. Normally you don't
101 need to set your preferred language, as your browser's language preferences
102 are detected automatically using the Accept-Language header.
103</p>
104
105<div class="indent">
106<table border="0" cellpadding="3" cellspacing="2" class="standard">
107<?php
108
109// Data for the language settings table
110$langinfo = [
111
112    "<label for=\"form-my_lang\">Your preferred language</label>" =>
113    $langpref,
114
115    "Your Accept-Language browser setting" =>
116    (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? htmlentities($_SERVER['HTTP_ACCEPT_LANGUAGE'], ENT_QUOTES | ENT_IGNORE, 'UTF-8') : "None"),
117
118    "The mirror's default language" =>
119    default_language(),
120
121    "Default" => "en",
122];
123
124// Write a row for all settings
125foreach ($langinfo as $lin => $lid) {
126    echo " <tr>\n  <td class=\"sub\">" . $lin . "</td>\n";
127    echo "  <td>" . $lid . "</td>\n </tr>\n";
128}
129
130?>
131</table>
132</div>
133
134<p>
135 These settings are only overridden in case you have passed a language
136 setting URL parameter or POST data to a page or you are viewing a manual
137 page in a particular language. In these cases, the explicit specification
138 overrides the language selected from the above list.
139</p>
140
141<p>
142 The language setting is honored when you use a
143 <a href="/urlhowto.php">URL shortcut</a>, when you start
144 a function list search on a non-manual page, when you visit
145 the <a href="/download-docs.php">manual download</a> or
146 <a href="/docs.php">language selection</a> pages, etc.
147</p>
148
149<h2>Your country</h2>
150
151<p>
152 The PHP.net site tries to detect your country
153 using the <a href="http://www.directi.com/?site=ip-to-country">Directi
154 Ip-to-Country Database</a>. This information is used to mark
155 the events in your country specially.
156</p>
157
158<div class="indent">
159<?php
160if (i2c_valid_country()) {
161    echo "We detected that you are from <b>" . $COUNTRIES[$COUNTRY] . "</b>";
162} else {
163    echo "We were unable to detect your country";
164}
165?>
166</div>
167
168<h2>URL search fallback</h2>
169
170<p>
171 When you try to access a PHP.net page via a URL shortcut, and
172 the site is unable to find that particular page, it falls back
173 to a documentation search, or a function list lookup, depending on
174 your choice. The default is a function list lookup, as most of
175 the URL shortcut users try to access function documentation pages.
176</p>
177
178<div class="indent">
179 Your setting: <input id="form-urlsearch-quickref" type="radio" name="urlsearch" value="quickref"
180<?php
181$type = $userPreferences->searchType;
182if ($type === UserPreferences::URL_NONE || $type === UserPreferences::URL_FUNC) {
183    echo ' checked="checked"';
184}
185echo '> <label for="form-urlsearch-quickref">Function list search</label> <input id="form-urlsearch-manual" type="radio" name="urlsearch" value="manual"';
186if ($type === UserPreferences::URL_MANUAL) {
187    echo ' checked="checked"';
188}
189?>
190> <label for="form-urlsearch-manual">PHP Documentation search</label>
191</div>
192
193<br>
194<h2>User Group tips</h2>
195
196<p>
197We are experimenting with listing nearby user groups. This feature is highly experimental
198and will very likely change a lot and be broken at times.
199</p>
200<label for="showugenable">Enable UG tips</label> <input type="radio" name="showug" id="showugenable" value="enable" <?php echo $userPreferences->isUserGroupTipsEnabled ? "checked=checked" : "" ?>><br>
201<label for="showugdisable">Disable UG tips</label> <input type="radio" name="showug" id="showugdisable" value="disable" <?php echo $userPreferences->isUserGroupTipsEnabled ? "" : "checked=checked" ?>>
202
203<p class="center">
204 <input type="submit" value="Set All Preferences">
205</p>
206</form>
207
208<?php site_footer(); ?>
209